mirror of
https://github.com/coturn/coturn.git
synced 2025-10-27 21:10:59 +01:00
merge bug fixes 126, 137 from rfc5766-turn-server
This commit is contained in:
parent
7e7ee8b868
commit
a138db3ae9
@ -508,12 +508,21 @@ static int send_socket_to_relay(turnserver_id id, u64bits cid, stun_tid *tid, io
|
|||||||
switch (rmt) {
|
switch (rmt) {
|
||||||
case(RMT_CB_SOCKET): {
|
case(RMT_CB_SOCKET): {
|
||||||
|
|
||||||
|
if(nd && nd->nbh) {
|
||||||
sm.m.cb_sm.id = id;
|
sm.m.cb_sm.id = id;
|
||||||
sm.m.cb_sm.connection_id = (tcp_connection_id)cid;
|
sm.m.cb_sm.connection_id = (tcp_connection_id)cid;
|
||||||
stun_tid_cpy(&(sm.m.cb_sm.tid),tid);
|
stun_tid_cpy(&(sm.m.cb_sm.tid),tid);
|
||||||
sm.m.cb_sm.s = s;
|
sm.m.cb_sm.s = s;
|
||||||
sm.m.cb_sm.message_integrity = message_integrity;
|
sm.m.cb_sm.message_integrity = message_integrity;
|
||||||
|
|
||||||
|
addr_cpy(&(sm.m.cb_sm.nd.src_addr),&(nd->src_addr));
|
||||||
|
sm.m.cb_sm.nd.recv_tos = nd->recv_tos;
|
||||||
|
sm.m.cb_sm.nd.recv_ttl = nd->recv_ttl;
|
||||||
|
sm.m.cb_sm.nd.nbh = nd->nbh;
|
||||||
|
|
||||||
|
nd->nbh = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (RMT_MOBILE_SOCKET): {
|
case (RMT_MOBILE_SOCKET): {
|
||||||
@ -562,6 +571,9 @@ static int send_socket_to_relay(turnserver_id id, u64bits cid, stun_tid *tid, io
|
|||||||
if(rmt == RMT_MOBILE_SOCKET) {
|
if(rmt == RMT_MOBILE_SOCKET) {
|
||||||
ioa_network_buffer_delete(NULL, sm.m.sm.nd.nbh);
|
ioa_network_buffer_delete(NULL, sm.m.sm.nd.nbh);
|
||||||
sm.m.sm.nd.nbh = NULL;
|
sm.m.sm.nd.nbh = NULL;
|
||||||
|
} else if(rmt == RMT_CB_SOCKET) {
|
||||||
|
ioa_network_buffer_delete(NULL, sm.m.cb_sm.nd.nbh);
|
||||||
|
sm.m.cb_sm.nd.nbh = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,7 +620,10 @@ static int handle_relay_message(relay_server_handle rs, struct message_to_relay
|
|||||||
case RMT_CB_SOCKET:
|
case RMT_CB_SOCKET:
|
||||||
|
|
||||||
turnserver_accept_tcp_client_data_connection(&(rs->server), sm->m.cb_sm.connection_id,
|
turnserver_accept_tcp_client_data_connection(&(rs->server), sm->m.cb_sm.connection_id,
|
||||||
&(sm->m.cb_sm.tid), sm->m.cb_sm.s, sm->m.cb_sm.message_integrity);
|
&(sm->m.cb_sm.tid), sm->m.cb_sm.s, sm->m.cb_sm.message_integrity, &(sm->m.cb_sm.nd));
|
||||||
|
|
||||||
|
ioa_network_buffer_delete(rs->ioa_eng, sm->m.cb_sm.nd.nbh);
|
||||||
|
sm->m.cb_sm.nd.nbh = NULL;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case RMT_MOBILE_SOCKET: {
|
case RMT_MOBILE_SOCKET: {
|
||||||
|
|||||||
@ -90,6 +90,7 @@ struct cb_socket_message {
|
|||||||
stun_tid tid;
|
stun_tid tid;
|
||||||
ioa_socket_handle s;
|
ioa_socket_handle s;
|
||||||
int message_integrity;
|
int message_integrity;
|
||||||
|
ioa_net_data nd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct relay_server {
|
struct relay_server {
|
||||||
|
|||||||
@ -47,6 +47,31 @@
|
|||||||
int TURN_MAX_ALLOCATE_TIMEOUT = 60;
|
int TURN_MAX_ALLOCATE_TIMEOUT = 60;
|
||||||
int TURN_MAX_ALLOCATE_TIMEOUT_STUN_ONLY = 3;
|
int TURN_MAX_ALLOCATE_TIMEOUT_STUN_ONLY = 3;
|
||||||
|
|
||||||
|
#define log_method(ss, method, err_code, reason) \
|
||||||
|
{\
|
||||||
|
if(!(err_code)) {\
|
||||||
|
if(ss->origin[0]) {\
|
||||||
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
||||||
|
"session %018llu: origin <%s> realm <%s> user <%s>: incoming packet " method " processed, success\n",\
|
||||||
|
(unsigned long long)(ss->id), (const char*)(ss->origin),(const char*)(ss->realm_options.name),(const char*)(ss->username));\
|
||||||
|
} else {\
|
||||||
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
||||||
|
"session %018llu: realm <%s> user <%s>: incoming packet " method " processed, success\n",\
|
||||||
|
(unsigned long long)(ss->id), (const char*)(ss->realm_options.name),(const char*)(ss->username));\
|
||||||
|
}\
|
||||||
|
} else {\
|
||||||
|
if(ss->origin[0]) {\
|
||||||
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
||||||
|
"session %018llu: origin <%s> realm <%s> user <%s>: incoming packet " method " processed, error %d: %s\n",\
|
||||||
|
(unsigned long long)(ss->id), (const char*)(ss->origin),(const char*)(ss->realm_options.name),(const char*)(ss->username), (err_code), (reason));\
|
||||||
|
} else {\
|
||||||
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
||||||
|
"session %018llu: realm <%s> user <%s>: incoming packet " method " processed, error %d: %s\n",\
|
||||||
|
(unsigned long long)(ss->id), (const char*)(ss->realm_options.name),(const char*)(ss->username), (err_code), (reason));\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
|
|
||||||
static int attach_socket_to_session(turn_turnserver* server, ioa_socket_handle s, ts_ur_super_session* ss);
|
static int attach_socket_to_session(turn_turnserver* server, ioa_socket_handle s, ts_ur_super_session* ss);
|
||||||
@ -1986,7 +2011,7 @@ static int handle_turn_connection_bind(turn_turnserver *server,
|
|||||||
if(s) {
|
if(s) {
|
||||||
ioa_socket_handle new_s = detach_ioa_socket(s,1);
|
ioa_socket_handle new_s = detach_ioa_socket(s,1);
|
||||||
if(new_s) {
|
if(new_s) {
|
||||||
if(server->send_socket_to_relay(sid, id, tid, new_s, message_integrity, RMT_CB_SOCKET, NULL)<0) {
|
if(server->send_socket_to_relay(sid, id, tid, new_s, message_integrity, RMT_CB_SOCKET, in_buffer)<0) {
|
||||||
*err_code = 400;
|
*err_code = 400;
|
||||||
*reason = (const u08bits *)"Wrong connection id";
|
*reason = (const u08bits *)"Wrong connection id";
|
||||||
}
|
}
|
||||||
@ -2019,7 +2044,7 @@ static int handle_turn_connection_bind(turn_turnserver *server,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_connection_id tcid, stun_tid *tid, ioa_socket_handle s, int message_integrity)
|
int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_connection_id tcid, stun_tid *tid, ioa_socket_handle s, int message_integrity, ioa_net_data *in_buffer)
|
||||||
{
|
{
|
||||||
if(!server)
|
if(!server)
|
||||||
return -1;
|
return -1;
|
||||||
@ -2030,10 +2055,13 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
|||||||
ts_ur_super_session *ss = NULL;
|
ts_ur_super_session *ss = NULL;
|
||||||
|
|
||||||
int err_code = 0;
|
int err_code = 0;
|
||||||
|
const u08bits *reason = NULL;
|
||||||
|
|
||||||
if(tcid && tid && s) {
|
if(tcid && tid && s) {
|
||||||
|
|
||||||
tc = get_and_clean_tcp_connection_by_id(server->tcp_relay_connections, tcid);
|
tc = get_and_clean_tcp_connection_by_id(server->tcp_relay_connections, tcid);
|
||||||
|
ioa_network_buffer_handle nbh = ioa_network_buffer_allocate(server->e);
|
||||||
|
int resp_constructed = 0;
|
||||||
if(!tc || (tc->state == TC_STATE_READY) || (tc->client_s)) {
|
if(!tc || (tc->state == TC_STATE_READY) || (tc->client_s)) {
|
||||||
err_code = 400;
|
err_code = 400;
|
||||||
} else {
|
} else {
|
||||||
@ -2042,9 +2070,18 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
|||||||
err_code = 500;
|
err_code = 500;
|
||||||
} else {
|
} else {
|
||||||
ss = (ts_ur_super_session*)(a->owner);
|
ss = (ts_ur_super_session*)(a->owner);
|
||||||
if(!check_username_hash(s,ss->username,(u08bits*)ss->realm_options.name)) {
|
|
||||||
err_code = 401;
|
//Check security:
|
||||||
} else {
|
int postpone_reply = 0;
|
||||||
|
check_stun_auth(server, ss, tid, &resp_constructed, &err_code, &reason, in_buffer, nbh,
|
||||||
|
STUN_METHOD_CONNECTION_BIND, &message_integrity, &postpone_reply, 0);
|
||||||
|
|
||||||
|
if(postpone_reply) {
|
||||||
|
|
||||||
|
ioa_network_buffer_delete(server->e, nbh);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} else if(!err_code) {
|
||||||
tc->state = TC_STATE_READY;
|
tc->state = TC_STATE_READY;
|
||||||
tc->client_s = s;
|
tc->client_s = s;
|
||||||
set_ioa_socket_session(s,ss);
|
set_ioa_socket_session(s,ss);
|
||||||
@ -2060,8 +2097,7 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ioa_network_buffer_handle nbh = ioa_network_buffer_allocate(server->e);
|
if(!resp_constructed) {
|
||||||
|
|
||||||
if(!err_code) {
|
if(!err_code) {
|
||||||
size_t len = ioa_network_buffer_get_size(nbh);
|
size_t len = ioa_network_buffer_get_size(nbh);
|
||||||
stun_init_success_response_str(STUN_METHOD_CONNECTION_BIND, ioa_network_buffer_data(nbh), &len, tid);
|
stun_init_success_response_str(STUN_METHOD_CONNECTION_BIND, ioa_network_buffer_data(nbh), &len, tid);
|
||||||
@ -2071,6 +2107,7 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
|||||||
stun_init_error_response_str(STUN_METHOD_CONNECTION_BIND, ioa_network_buffer_data(nbh), &len, err_code, NULL, tid);
|
stun_init_error_response_str(STUN_METHOD_CONNECTION_BIND, ioa_network_buffer_data(nbh), &len, err_code, NULL, tid);
|
||||||
ioa_network_buffer_set_size(nbh,len);
|
ioa_network_buffer_set_size(nbh,len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
static const u08bits *field = (const u08bits *) TURN_SOFTWARE;
|
static const u08bits *field = (const u08bits *) TURN_SOFTWARE;
|
||||||
@ -2092,6 +2129,10 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
|||||||
ioa_network_buffer_set_size(nbh, len);
|
ioa_network_buffer_set_size(nbh, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(server->verbose) {
|
||||||
|
log_method(ss, "CONNECTION_BIND", err_code, reason);
|
||||||
|
}
|
||||||
|
|
||||||
if(ss && !err_code) {
|
if(ss && !err_code) {
|
||||||
send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE);
|
send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE);
|
||||||
tcp_deliver_delayed_buffer(&(tc->ub_to_client),s,ss);
|
tcp_deliver_delayed_buffer(&(tc->ub_to_client),s,ss);
|
||||||
@ -3106,31 +3147,6 @@ static void set_alternate_server(turn_server_addrs_list_t *asl, const ioa_addr *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define log_method(ss, method, err_code, reason) \
|
|
||||||
{\
|
|
||||||
if(!(err_code)) {\
|
|
||||||
if(ss->origin[0]) {\
|
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
|
||||||
"session %018llu: origin <%s> realm <%s> user <%s>: incoming packet " method " processed, success\n",\
|
|
||||||
(unsigned long long)(ss->id), (const char*)(ss->origin),(const char*)(ss->realm_options.name),(const char*)(ss->username));\
|
|
||||||
} else {\
|
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
|
||||||
"session %018llu: realm <%s> user <%s>: incoming packet " method " processed, success\n",\
|
|
||||||
(unsigned long long)(ss->id), (const char*)(ss->realm_options.name),(const char*)(ss->username));\
|
|
||||||
}\
|
|
||||||
} else {\
|
|
||||||
if(ss->origin[0]) {\
|
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
|
||||||
"session %018llu: origin <%s> realm <%s> user <%s>: incoming packet " method " processed, error %d: %s\n",\
|
|
||||||
(unsigned long long)(ss->id), (const char*)(ss->origin),(const char*)(ss->realm_options.name),(const char*)(ss->username), (err_code), (reason));\
|
|
||||||
} else {\
|
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,\
|
|
||||||
"session %018llu: realm <%s> user <%s>: incoming packet " method " processed, error %d: %s\n",\
|
|
||||||
(unsigned long long)(ss->id), (const char*)(ss->realm_options.name),(const char*)(ss->username), (err_code), (reason));\
|
|
||||||
}\
|
|
||||||
}\
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss, ioa_net_data *in_buffer, ioa_network_buffer_handle nbh, int *resp_constructed, int can_resume)
|
static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss, ioa_net_data *in_buffer, ioa_network_buffer_handle nbh, int *resp_constructed, int can_resume)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3225,7 +3241,9 @@ static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!err_code && !(*resp_constructed) && !no_response) {
|
if(!err_code && !(*resp_constructed) && !no_response) {
|
||||||
if(!(*(server->mobility)) || (method != STUN_METHOD_REFRESH) || is_allocation_valid(get_allocation_ss(ss))) {
|
if(method == STUN_METHOD_CONNECTION_BIND) {
|
||||||
|
;
|
||||||
|
} else if(!(*(server->mobility)) || (method != STUN_METHOD_REFRESH) || is_allocation_valid(get_allocation_ss(ss))) {
|
||||||
int postpone_reply = 0;
|
int postpone_reply = 0;
|
||||||
check_stun_auth(server, ss, &tid, resp_constructed, &err_code, &reason, in_buffer, nbh, method, &message_integrity, &postpone_reply, can_resume);
|
check_stun_auth(server, ss, &tid, resp_constructed, &err_code, &reason, in_buffer, nbh, method, &message_integrity, &postpone_reply, can_resume);
|
||||||
if(postpone_reply)
|
if(postpone_reply)
|
||||||
@ -3270,7 +3288,7 @@ static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss,
|
|||||||
handle_turn_connection_bind(server, ss, &tid, resp_constructed, &err_code, &reason,
|
handle_turn_connection_bind(server, ss, &tid, resp_constructed, &err_code, &reason,
|
||||||
unknown_attrs, &ua_num, in_buffer, nbh, message_integrity);
|
unknown_attrs, &ua_num, in_buffer, nbh, message_integrity);
|
||||||
|
|
||||||
if(server->verbose) {
|
if(server->verbose && err_code) {
|
||||||
log_method(ss, "CONNECTION_BIND", err_code, reason);
|
log_method(ss, "CONNECTION_BIND", err_code, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -202,7 +202,7 @@ int open_client_connection_session(turn_turnserver* server, struct socket_messag
|
|||||||
int shutdown_client_connection(turn_turnserver *server, ts_ur_super_session *ss, int force, const char* reason);
|
int shutdown_client_connection(turn_turnserver *server, ts_ur_super_session *ss, int force, const char* reason);
|
||||||
void set_disconnect_cb(turn_turnserver* server, int (*disconnect)(ts_ur_super_session*));
|
void set_disconnect_cb(turn_turnserver* server, int (*disconnect)(ts_ur_super_session*));
|
||||||
|
|
||||||
int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_connection_id tcid, stun_tid *tid, ioa_socket_handle s, int message_integrity);
|
int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_connection_id tcid, stun_tid *tid, ioa_socket_handle s, int message_integrity, ioa_net_data *nd);
|
||||||
|
|
||||||
int report_turn_session_info(turn_turnserver *server, ts_ur_super_session *ss, int force_invalid);
|
int report_turn_session_info(turn_turnserver *server, ts_ur_super_session *ss, int force_invalid);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user