mirror of
https://github.com/coturn/coturn.git
synced 2025-10-27 04:51:28 +01:00
merge bug fixes 126, 137 from rfc5766-turn-server
This commit is contained in:
parent
7e7ee8b868
commit
a138db3ae9
@ -508,11 +508,20 @@ static int send_socket_to_relay(turnserver_id id, u64bits cid, stun_tid *tid, io
|
||||
switch (rmt) {
|
||||
case(RMT_CB_SOCKET): {
|
||||
|
||||
sm.m.cb_sm.id = id;
|
||||
sm.m.cb_sm.connection_id = (tcp_connection_id)cid;
|
||||
stun_tid_cpy(&(sm.m.cb_sm.tid),tid);
|
||||
sm.m.cb_sm.s = s;
|
||||
sm.m.cb_sm.message_integrity = message_integrity;
|
||||
if(nd && nd->nbh) {
|
||||
sm.m.cb_sm.id = id;
|
||||
sm.m.cb_sm.connection_id = (tcp_connection_id)cid;
|
||||
stun_tid_cpy(&(sm.m.cb_sm.tid),tid);
|
||||
sm.m.cb_sm.s = s;
|
||||
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;
|
||||
}
|
||||
@ -562,6 +571,9 @@ static int send_socket_to_relay(turnserver_id id, u64bits cid, stun_tid *tid, io
|
||||
if(rmt == RMT_MOBILE_SOCKET) {
|
||||
ioa_network_buffer_delete(NULL, sm.m.sm.nd.nbh);
|
||||
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:
|
||||
|
||||
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;
|
||||
case RMT_MOBILE_SOCKET: {
|
||||
|
||||
@ -90,6 +90,7 @@ struct cb_socket_message {
|
||||
stun_tid tid;
|
||||
ioa_socket_handle s;
|
||||
int message_integrity;
|
||||
ioa_net_data nd;
|
||||
};
|
||||
|
||||
struct relay_server {
|
||||
|
||||
@ -47,6 +47,31 @@
|
||||
int TURN_MAX_ALLOCATE_TIMEOUT = 60;
|
||||
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);
|
||||
@ -1986,7 +2011,7 @@ static int handle_turn_connection_bind(turn_turnserver *server,
|
||||
if(s) {
|
||||
ioa_socket_handle new_s = detach_ioa_socket(s,1);
|
||||
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;
|
||||
*reason = (const u08bits *)"Wrong connection id";
|
||||
}
|
||||
@ -2019,7 +2044,7 @@ static int handle_turn_connection_bind(turn_turnserver *server,
|
||||
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)
|
||||
return -1;
|
||||
@ -2030,10 +2055,13 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
||||
ts_ur_super_session *ss = NULL;
|
||||
|
||||
int err_code = 0;
|
||||
const u08bits *reason = NULL;
|
||||
|
||||
if(tcid && tid && s) {
|
||||
|
||||
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)) {
|
||||
err_code = 400;
|
||||
} else {
|
||||
@ -2042,9 +2070,18 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
||||
err_code = 500;
|
||||
} else {
|
||||
ss = (ts_ur_super_session*)(a->owner);
|
||||
if(!check_username_hash(s,ss->username,(u08bits*)ss->realm_options.name)) {
|
||||
err_code = 401;
|
||||
} else {
|
||||
|
||||
//Check security:
|
||||
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->client_s = s;
|
||||
set_ioa_socket_session(s,ss);
|
||||
@ -2060,16 +2097,16 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
||||
}
|
||||
}
|
||||
|
||||
ioa_network_buffer_handle nbh = ioa_network_buffer_allocate(server->e);
|
||||
|
||||
if(!err_code) {
|
||||
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);
|
||||
ioa_network_buffer_set_size(nbh,len);
|
||||
} else {
|
||||
size_t len = ioa_network_buffer_get_size(nbh);
|
||||
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);
|
||||
if(!resp_constructed) {
|
||||
if(!err_code) {
|
||||
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);
|
||||
ioa_network_buffer_set_size(nbh,len);
|
||||
} else {
|
||||
size_t len = ioa_network_buffer_get_size(nbh);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@ -2092,6 +2129,10 @@ int turnserver_accept_tcp_client_data_connection(turn_turnserver *server, tcp_co
|
||||
ioa_network_buffer_set_size(nbh, len);
|
||||
}
|
||||
|
||||
if(server->verbose) {
|
||||
log_method(ss, "CONNECTION_BIND", err_code, reason);
|
||||
}
|
||||
|
||||
if(ss && !err_code) {
|
||||
send_data_from_ioa_socket_nbh(s, NULL, nbh, TTL_IGNORE, TOS_IGNORE);
|
||||
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)
|
||||
{
|
||||
|
||||
@ -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(!(*(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;
|
||||
check_stun_auth(server, ss, &tid, resp_constructed, &err_code, &reason, in_buffer, nbh, method, &message_integrity, &postpone_reply, can_resume);
|
||||
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,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user