From 7a921c608bc4fa6dbd7eb1c8113922fc1057663e Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 5 Aug 2019 21:28:26 +0400 Subject: [PATCH 1/8] version bump --- build/next-release.txt | 2 +- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/next-release.txt b/build/next-release.txt index a01185b4d67..ba177fe9fd2 100644 --- a/build/next-release.txt +++ b/build/next-release.txt @@ -1 +1 @@ -1.10.0-dev +1.10.0-release diff --git a/configure.ac b/configure.ac index a0aae4efef2..d2ae91b75c4 100644 --- a/configure.ac +++ b/configure.ac @@ -3,10 +3,10 @@ # Must change all of the below together # For a release, set revision for that tagged release as well and uncomment -AC_INIT([freeswitch], [1.10.0-dev], bugs@freeswitch.org) +AC_INIT([freeswitch], [1.10.0-release], bugs@freeswitch.org) AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [10]) -AC_SUBST(SWITCH_VERSION_MICRO, [0-dev]) +AC_SUBST(SWITCH_VERSION_MICRO, [0-release]) AC_SUBST(SWITCH_VERSION_REVISION, []) AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, []) From df518933e8fe14b29494ce4bf04ff2c28ea777e7 Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 12:20:28 +0000 Subject: [PATCH 2/8] WIP - Changing ICE candidate based on BINDING_RESPONSE --- src/include/switch_rtp.h | 23 +++++++ src/switch_core_media.c | 9 +++ src/switch_rtp.c | 141 ++++++++++++++++++++++++--------------- 3 files changed, 118 insertions(+), 55 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index ca915cf77a2..72299ffe21d 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -103,6 +103,8 @@ typedef struct icand_s { switch_port_t rport; char *generation; uint8_t ready; + switch_time_t last_binding_response; + switch_sockaddr_t *addr; } icand_t; #define MAX_CAND 50 @@ -118,6 +120,27 @@ typedef struct ice_s { } ice_t; +typedef struct { + char *ice_user; + char *user_ice; + char *luser_ice; + char *pass; + char *rpass; + switch_sockaddr_t *addr; + uint32_t funny_stun; + switch_time_t next_run; + switch_core_media_ice_type_t type; + ice_t *ice_params; + ice_proto_t proto; + uint8_t sending; + uint8_t ready; + uint8_t rready; + uint8_t init; + int missed_count; + char last_sent_id[13]; + switch_time_t last_ok; +} switch_rtp_ice_t; + typedef enum { /* RTCP Control Packet types (PT) http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 */ _RTCP_PT_FIR = 192, /* [RFC 2032] RTP Payload Format for H.261 Video Streams. types 192 (FIR) section 5.2.1 */ _RTCP_PT_IJ = 195, /* IJ: Extended inter-arrival jitter report RFC5450*/ diff --git a/src/switch_core_media.c b/src/switch_core_media.c index d1397a833e8..146a914372c 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -4367,6 +4367,15 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].priority = atol(fields[3]); engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_addr = switch_core_session_strdup(smh->session, con_addr); engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_port = (switch_port_t)atoi(fields[5]); + engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].last_binding_response = 0; + engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].last_binding_response = 0; + + switch_sockaddr_new( + &engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].addr, + engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_addr, + engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_port, + smh->session->pool + ); j = 6; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index e9f2c53c81b..48cd9f807c9 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -251,27 +251,6 @@ struct switch_rtp_rfc2833_data { uint8_t in_digit_queued; }; -typedef struct { - char *ice_user; - char *user_ice; - char *luser_ice; - char *pass; - char *rpass; - switch_sockaddr_t *addr; - uint32_t funny_stun; - switch_time_t next_run; - switch_core_media_ice_type_t type; - ice_t *ice_params; - ice_proto_t proto; - uint8_t sending; - uint8_t ready; - uint8_t rready; - uint8_t init; - int missed_count; - char last_sent_id[13]; - switch_time_t last_ok; -} switch_rtp_ice_t; - struct switch_rtp; static void switch_rtp_dtls_init(); @@ -816,7 +795,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags); -static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) +static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, icand_t *cand) { uint8_t buf[256] = { 0 }; switch_stun_packet_t *packet; @@ -826,17 +805,25 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) //switch_sockaddr_t *remote_addr = rtp_session->remote_addr; switch_socket_t *sock_output = rtp_session->sock_output; switch_time_t now = switch_micro_time_now(); + switch_sockaddr_t *addr; if (ice->type & ICE_LITE) { // no connectivity checks for ICE-Lite return SWITCH_STATUS_BREAK; } - if (ice->next_run && ice->next_run > now) { + if (!cand && ice->next_run && ice->next_run > now) { return SWITCH_STATUS_BREAK; } - ice->next_run = now + RTP_STUN_FREQ; + if (!cand) { + cand = &ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto]; + addr = ice->addr; + ice->next_run = now + RTP_STUN_FREQ; + } else { + addr = cand->addr; + } + if (ice == &rtp_session->rtcp_ice && rtp_session->rtcp_sock_output) { sock_output = rtp_session->rtcp_sock_output; @@ -874,7 +861,7 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) if ((ice->type & ICE_VANILLA)) { char sw[128] = ""; - switch_stun_packet_attribute_add_priority(packet, ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].priority); + switch_stun_packet_attribute_add_priority(packet, cand->priority); switch_snprintf(sw, sizeof(sw), "FreeSWITCH (%s)", switch_version_revision_human()); switch_stun_packet_attribute_add_software(packet, sw, (uint16_t)strlen(sw)); @@ -890,15 +877,17 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice) switch_stun_packet_attribute_add_fingerprint(packet); } - bytes = switch_stun_packet_length(packet); #ifdef DEBUG_EXTRA switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "%s send %s stun\n", rtp_session_name(rtp_session), rtp_type(rtp_session)); #endif - switch_socket_sendto(sock_output, ice->addr, 0, (void *) packet, &bytes); + + switch_socket_sendto(sock_output, addr, 0, (void *) packet, &bytes); ice->sending = 3; + if(cand) + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "sending BINDING_REQUEST to %s:%d\n", cand->con_addr, cand->con_port); // end: READ_DEC(rtp_session); @@ -915,6 +904,27 @@ int icecmp(const char *them, switch_rtp_ice_t *ice) return strcmp(them, ice->luser_ice); } +static icand_t *locate_candidate(switch_rtp_ice_t *ice, switch_sockaddr_t *from_addr) +{ + const char *host = NULL; + switch_port_t port = 0; + char buf[80] = ""; + int i; + + host = switch_get_addr(buf, sizeof(buf), from_addr); + port = switch_sockaddr_get_port(from_addr); + for (i = 0; i < MAX_CAND; i++) { + if (!ice->ice_params->cands[i][ice->proto].con_addr) { + continue; + } + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host) && ice->ice_params->cands[i][ice->proto].con_port == port) { + return &ice->ice_params->cands[i][ice->proto]; + } + } + + return NULL; +} + static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *data, switch_size_t len) { switch_stun_packet_t *packet; @@ -930,6 +940,11 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d uint32_t elapsed; switch_time_t ref_point; + icand_t *cand = locate_candidate(ice, rtp_session->from_addr); + if (cand) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "ICE packed from candidate %s:%d\n", cand->con_addr, cand->con_port); + } + //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { // switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s CALL\n", rtp_type(rtp_session)); //} @@ -1067,6 +1082,44 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d if (!ok) ok = !memcmp(packet->header.id, ice->last_sent_id, 12); if (packet->header.type == SWITCH_STUN_BINDING_RESPONSE) { + int chosen_idx = ice->ice_params->chosen[ice->proto]; + if (cand) { + cand->last_binding_response = switch_micro_time_now(); + + if (!ice->ice_params->cands[chosen_idx][ice->proto].last_binding_response) { + int i; + int cur_idx = -1; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "BINDING_RESPONSE from candidate %s:%d\n", cand->con_addr, cand->con_port); + + for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "%s:%d -> %s:%d", ice->ice_params->cands[i][ice->proto].con_addr,ice->ice_params->cands[i][ice->proto].con_port, cand->con_addr, cand->con_port); + if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, cand->con_addr) && ice->ice_params->cands[i][ice->proto].con_port == cand->con_port) { + cur_idx = i; + break; + } + } + + if (cur_idx > -1) { + ice->ice_params->chosen[ice->proto] = cur_idx; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, + "Auto Changing %s stun/%s/dtls port from %s:%u lr:%ld idx:%d to %s:%u lr:%ld idx:%d\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", + ice->ice_params->cands[chosen_idx][ice->proto].con_addr, ice->ice_params->cands[chosen_idx][ice->proto].con_port, ice->ice_params->cands[chosen_idx][ice->proto].last_binding_response, chosen_idx, + cand->con_addr, cand->con_port, cand->last_binding_response, cur_idx); + + switch_rtp_change_ice_dest(rtp_session, ice, cand->con_addr, cand->con_port); + } + } + } else { + const char *__host = NULL; + switch_port_t __port = 0; + char __buf[80] = ""; + + __host = switch_get_addr(__buf, sizeof(__buf), rtp_session->from_addr); + __port = switch_sockaddr_get_port(rtp_session->from_addr); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "BINDING_RESPONSE from unknown candidate %s:%d\n", __host, __port); + } + ok = 1; if (!ice->rready) { if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { @@ -1205,10 +1258,9 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d //} if (ok) { - const char *host = NULL, *host2 = NULL; - switch_port_t port = 0, port2 = 0; + const char *host = NULL; + switch_port_t port = 0; char buf[80] = ""; - char buf2[80] = ""; if (packet->header.type == SWITCH_STUN_BINDING_REQUEST) { uint8_t stunbuf[512]; @@ -1221,7 +1273,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d uint8_t do_adj = 0; switch_time_t now = switch_micro_time_now(); int cmp = 0; - int cur_idx = -1;//, is_relay = 0; int i; if (is_rtcp) { @@ -1253,8 +1304,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d host = switch_get_addr(buf, sizeof(buf), from_addr); port = switch_sockaddr_get_port(from_addr); - host2 = switch_get_addr(buf2, sizeof(buf2), ice->addr); - port2 = switch_sockaddr_get_port(ice->addr); cmp = switch_cmp_addr(from_addr, ice->addr, SWITCH_FALSE); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, @@ -1289,7 +1338,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host)) { - cur_idx = i; + //cur_idx = i; //if (!strcasecmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) { // is_relay = 1; //} @@ -1302,27 +1351,9 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d do_adj++; } } - - if ((ice->type & ICE_VANILLA) && ice->ice_params && do_adj) { - ice->missed_count = 0; - ice->rready = 1; - if (cur_idx > -1) { - ice->ice_params->chosen[ice->proto] = cur_idx; - } - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, - "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u idx:%d\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp", - host2, port2, - host, port, cur_idx); - - switch_rtp_change_ice_dest(rtp_session, ice, host, port); - ice->last_ok = now; - rtp_session->wrong_addrs = 0; - } - //if (cmp) { switch_socket_sendto(sock_output, from_addr, 0, (void *) rpacket, &bytes); - //} + ice_out(rtp_session, ice, cand); } } else if (packet->header.type == SWITCH_STUN_BINDING_ERROR_RESPONSE) { @@ -2592,7 +2623,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session) } if (rtp_session->ice.ice_user) { - if (ice_out(rtp_session, &rtp_session->ice) == SWITCH_STATUS_GENERR) { + if (ice_out(rtp_session, &rtp_session->ice, NULL) == SWITCH_STATUS_GENERR) { ret = -1; goto end; } @@ -2600,7 +2631,7 @@ static int check_rtcp_and_ice(switch_rtp_t *rtp_session) if (!rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) { if (rtp_session->rtcp_ice.ice_user) { - if (ice_out(rtp_session, &rtp_session->rtcp_ice) == SWITCH_STATUS_GENERR) { + if (ice_out(rtp_session, &rtp_session->rtcp_ice, NULL) == SWITCH_STATUS_GENERR) { ret = -1; goto end; } From 83df50636c844207d9f6780e37351ad5f3affa2f Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 13:22:54 +0000 Subject: [PATCH 3/8] WIP - Removing not used code and updating candidate address struct --- src/switch_rtp.c | 89 +++++++----------------------------------------- 1 file changed, 12 insertions(+), 77 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 48cd9f807c9..2ef47c16aba 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -542,6 +542,9 @@ static void switch_rtp_change_ice_dest(switch_rtp_t *rtp_session, switch_rtp_ice ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr = switch_core_strdup(rtp_session->pool, host); ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port = port; + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].addr->hostname = switch_core_strdup(rtp_session->pool, host); + ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].addr->port = port; + ice->missed_count = 0; if (is_rtcp) { @@ -886,8 +889,6 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, switch_socket_sendto(sock_output, addr, 0, (void *) packet, &bytes); ice->sending = 3; - if(cand) - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG, "sending BINDING_REQUEST to %s:%d\n", cand->con_addr, cand->con_port); // end: READ_DEC(rtp_session); @@ -904,7 +905,7 @@ int icecmp(const char *them, switch_rtp_ice_t *ice) return strcmp(them, ice->luser_ice); } -static icand_t *locate_candidate(switch_rtp_ice_t *ice, switch_sockaddr_t *from_addr) +static int locate_candidate(switch_rtp_ice_t *ice, switch_sockaddr_t *from_addr, icand_t **cand) { const char *host = NULL; switch_port_t port = 0; @@ -918,11 +919,12 @@ static icand_t *locate_candidate(switch_rtp_ice_t *ice, switch_sockaddr_t *from_ continue; } if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host) && ice->ice_params->cands[i][ice->proto].con_port == port) { - return &ice->ice_params->cands[i][ice->proto]; + *cand = &ice->ice_params->cands[i][ice->proto]; + return i; } } - return NULL; + return -1; } static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *data, switch_size_t len) @@ -939,10 +941,12 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d int is_rtcp = ice == &rtp_session->rtcp_ice; uint32_t elapsed; switch_time_t ref_point; + int cur_idx = -1; + icand_t *cand = NULL; - icand_t *cand = locate_candidate(ice, rtp_session->from_addr); + cur_idx = locate_candidate(ice, rtp_session->from_addr, &cand); if (cand) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "ICE packed from candidate %s:%d\n", cand->con_addr, cand->con_port); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, "ICE packed from candidate %s:%d\n", cand->con_addr, cand->con_port); } //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { @@ -1087,18 +1091,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d cand->last_binding_response = switch_micro_time_now(); if (!ice->ice_params->cands[chosen_idx][ice->proto].last_binding_response) { - int i; - int cur_idx = -1; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_INFO, "BINDING_RESPONSE from candidate %s:%d\n", cand->con_addr, cand->con_port); - - for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, "%s:%d -> %s:%d", ice->ice_params->cands[i][ice->proto].con_addr,ice->ice_params->cands[i][ice->proto].con_port, cand->con_addr, cand->con_port); - if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, cand->con_addr) && ice->ice_params->cands[i][ice->proto].con_port == cand->con_port) { - cur_idx = i; - break; - } - } - + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, "BINDING_RESPONSE from candidate %s:%d\n", cand->con_addr, cand->con_port); if (cur_idx > -1) { ice->ice_params->chosen[ice->proto] = cur_idx; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE, @@ -1258,10 +1251,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d //} if (ok) { - const char *host = NULL; - switch_port_t port = 0; - char buf[80] = ""; - if (packet->header.type == SWITCH_STUN_BINDING_REQUEST) { uint8_t stunbuf[512]; switch_stun_packet_t *rpacket; @@ -1270,10 +1259,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d char ipbuf[50]; switch_sockaddr_t *from_addr = rtp_session->from_addr; switch_socket_t *sock_output = rtp_session->sock_output; - uint8_t do_adj = 0; - switch_time_t now = switch_micro_time_now(); - int cmp = 0; - int i; if (is_rtcp) { from_addr = rtp_session->rtcp_from_addr; @@ -1302,56 +1287,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d bytes = switch_stun_packet_length(rpacket); - host = switch_get_addr(buf, sizeof(buf), from_addr); - port = switch_sockaddr_get_port(from_addr); - cmp = switch_cmp_addr(from_addr, ice->addr, SWITCH_FALSE); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, - "STUN from %s:%d %s\n", host, port, cmp ? "EXPECTED" : "IGNORED"); - - if (ice->init && !cmp && switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) { - do_adj++; - rtp_session->ice_adj++; - rtp_session->wrong_addrs = 0; - ice->init = 0; - } - - if (cmp) { - ice->last_ok = now; - rtp_session->wrong_addrs = 0; - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG10, "ICE %d dt:%d i:%d i2:%d w:%d cmp:%d adj:%d\n", elapsed, (rtp_session->dtls && rtp_session->dtls->state != DS_READY), !ice->ready, !ice->rready, rtp_session->wrong_addrs, switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE), rtp_session->ice_adj); - - if ((rtp_session->dtls && rtp_session->dtls->state != DS_READY) || - ((!ice->ready || !ice->rready) && (rtp_session->wrong_addrs > 2 || switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) && - rtp_session->ice_adj < 10)) { - do_adj++; - rtp_session->ice_adj++; - rtp_session->wrong_addrs = 0; - } else if (rtp_session->wrong_addrs > 10 || elapsed >= 5000) { - do_adj++; - } - - if (!do_adj) { - rtp_session->wrong_addrs++; - } - - for (i = 0; i < ice->ice_params->cand_idx[ice->proto]; i++) { - if (!strcmp(ice->ice_params->cands[i][ice->proto].con_addr, host)) { - //cur_idx = i; - //if (!strcasecmp(ice->ice_params->cands[i][ice->proto].cand_type, "relay")) { - // is_relay = 1; - //} - } - } - - - if (ice->ice_params && ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type && - !strcasecmp(ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].cand_type, "relay")) { - do_adj++; - } - } - switch_socket_sendto(sock_output, from_addr, 0, (void *) rpacket, &bytes); ice_out(rtp_session, ice, cand); } From 33f374b04cd2cebdc7ee764338bd232f7695153a Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 14:16:35 +0000 Subject: [PATCH 4/8] Adding unknown candidate into cands list --- src/switch_core_media.c | 1 - src/switch_rtp.c | 45 ++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 146a914372c..8adb989b4b5 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -4368,7 +4368,6 @@ static switch_status_t check_ice(switch_media_handle_t *smh, switch_media_type_t engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_addr = switch_core_session_strdup(smh->session, con_addr); engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].con_port = (switch_port_t)atoi(fields[5]); engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].last_binding_response = 0; - engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].last_binding_response = 0; switch_sockaddr_new( &engine->ice_in.cands[engine->ice_in.cand_idx[cid]][cid].addr, diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 2ef47c16aba..cbd85ca58dc 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -943,10 +943,12 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_time_t ref_point; int cur_idx = -1; icand_t *cand = NULL; + uint32_t priority = 0; + uint8_t use_cand = 0; cur_idx = locate_candidate(ice, rtp_session->from_addr, &cand); if (cand) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, "ICE packed from candidate %s:%d\n", cand->con_addr, cand->con_port); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, "ICE packet from candidate %s:%d idx %d\n", cand->con_addr, cand->con_port, cur_idx); } //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) { @@ -1007,6 +1009,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d case SWITCH_STUN_ATTR_USE_CAND: { ice->rready = 1; + use_cand = 1; } break; case SWITCH_STUN_ATTR_ERROR_CODE: @@ -1058,7 +1061,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d case SWITCH_STUN_ATTR_PRIORITY: { - uint32_t priority = 0; pri = (uint32_t *) attr->value; priority = ntohl(*pri); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %u\n", priority); @@ -1074,6 +1076,37 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d xlen += 4 + switch_stun_attribute_padded_length(attr); } while (xlen <= packet->header.length); + if (!cand && use_cand) { + const char *__host = NULL; + switch_port_t __port = 0; + char __buf[80] = ""; + int cid = ice->proto; + int next_idx = ice->ice_params->cand_idx[ice->proto]; + + __host = switch_get_addr(__buf, sizeof(__buf), rtp_session->from_addr); + __port = switch_sockaddr_get_port(rtp_session->from_addr); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2, "ICE packet from unknown candidate %s:%d - Updating candidate list idx %d\n", __host, __port, next_idx); + //should we check for ACL? + + //ice->ice_params->cands[next_idx][cid].foundation = switch_core_session_strdup(smh->session, fields[0]); + ice->ice_params->cands[next_idx][cid].transport = "udp"; //switch_core_session_strdup(smh->session, fields[2]); + + ice->ice_params->cands[next_idx][cid].component_id = ice->proto; + ice->ice_params->cands[next_idx][cid].priority = priority; + ice->ice_params->cands[next_idx][cid].con_addr = switch_core_session_strdup(rtp_session->session, __host); + ice->ice_params->cands[next_idx][cid].con_port = __port; + ice->ice_params->cands[next_idx][cid].last_binding_response = 0; + + switch_sockaddr_new( + &ice->ice_params->cands[next_idx][cid].addr, + ice->ice_params->cands[next_idx][cid].con_addr, + ice->ice_params->cands[next_idx][cid].con_port, + rtp_session->pool + ); + ice->ice_params->cand_idx[ice->proto]++; + } + if ((ice->type & ICE_GOOGLE_JINGLE) && ok) { ok = !strcmp(ice->user_ice, username); } @@ -1103,14 +1136,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d } } } else { - const char *__host = NULL; - switch_port_t __port = 0; - char __buf[80] = ""; - - __host = switch_get_addr(__buf, sizeof(__buf), rtp_session->from_addr); - __port = switch_sockaddr_get_port(rtp_session->from_addr); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_ERROR, "BINDING_RESPONSE from unknown candidate %s:%d\n", __host, __port); } ok = 1; From 60d3e9b6e38778003fabdc1346260d84aa54f318 Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 16:57:50 +0000 Subject: [PATCH 5/8] updating cand variable --- src/switch_rtp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index cbd85ca58dc..a933178c833 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1104,6 +1104,8 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d ice->ice_params->cands[next_idx][cid].con_port, rtp_session->pool ); + cand = &ice->ice_params->cands[next_idx][cid]; + ice->ice_params->cand_idx[ice->proto]++; } From cc10c4057104fcc2f98684c22db6f3b6b6a4592f Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 17:40:54 +0000 Subject: [PATCH 6/8] removing use cand check --- src/switch_rtp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index a933178c833..a165398c28f 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -944,7 +944,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d int cur_idx = -1; icand_t *cand = NULL; uint32_t priority = 0; - uint8_t use_cand = 0; cur_idx = locate_candidate(ice, rtp_session->from_addr, &cand); if (cand) { @@ -1009,7 +1008,6 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d case SWITCH_STUN_ATTR_USE_CAND: { ice->rready = 1; - use_cand = 1; } break; case SWITCH_STUN_ATTR_ERROR_CODE: @@ -1076,7 +1074,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d xlen += 4 + switch_stun_attribute_padded_length(attr); } while (xlen <= packet->header.length); - if (!cand && use_cand) { + if (!cand) { const char *__host = NULL; switch_port_t __port = 0; char __buf[80] = ""; From f45c05a2240f2bbab557848d7798235946048c78 Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 19:08:16 +0000 Subject: [PATCH 7/8] Reverting switch_rtp.h change --- src/include/switch_rtp.h | 21 --------------------- src/switch_rtp.c | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 72299ffe21d..3ecc9746be3 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -120,27 +120,6 @@ typedef struct ice_s { } ice_t; -typedef struct { - char *ice_user; - char *user_ice; - char *luser_ice; - char *pass; - char *rpass; - switch_sockaddr_t *addr; - uint32_t funny_stun; - switch_time_t next_run; - switch_core_media_ice_type_t type; - ice_t *ice_params; - ice_proto_t proto; - uint8_t sending; - uint8_t ready; - uint8_t rready; - uint8_t init; - int missed_count; - char last_sent_id[13]; - switch_time_t last_ok; -} switch_rtp_ice_t; - typedef enum { /* RTCP Control Packet types (PT) http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-4 */ _RTCP_PT_FIR = 192, /* [RFC 2032] RTP Payload Format for H.261 Video Streams. types 192 (FIR) section 5.2.1 */ _RTCP_PT_IJ = 195, /* IJ: Extended inter-arrival jitter report RFC5450*/ diff --git a/src/switch_rtp.c b/src/switch_rtp.c index a165398c28f..d2f365d6884 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -251,6 +251,27 @@ struct switch_rtp_rfc2833_data { uint8_t in_digit_queued; }; +typedef struct { + char *ice_user; + char *user_ice; + char *luser_ice; + char *pass; + char *rpass; + switch_sockaddr_t *addr; + uint32_t funny_stun; + switch_time_t next_run; + switch_core_media_ice_type_t type; + ice_t *ice_params; + ice_proto_t proto; + uint8_t sending; + uint8_t ready; + uint8_t rready; + uint8_t init; + int missed_count; + char last_sent_id[13]; + switch_time_t last_ok; +} switch_rtp_ice_t; + struct switch_rtp; static void switch_rtp_dtls_init(); From 4f1590fc6235474c40e3867db8b622b73a4c4c52 Mon Sep 17 00:00:00 2001 From: Sergio Filipe Date: Tue, 3 Jan 2023 19:09:48 +0000 Subject: [PATCH 8/8] Reverting not wanted changes --- build/next-release.txt | 2 +- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/next-release.txt b/build/next-release.txt index 4856655de67..924b6af8078 100644 --- a/build/next-release.txt +++ b/build/next-release.txt @@ -1 +1 @@ -1.10.8-release +1.10.8-dev diff --git a/configure.ac b/configure.ac index f09196bdfd2..52b0a3cd98b 100644 --- a/configure.ac +++ b/configure.ac @@ -3,10 +3,10 @@ # Must change all of the below together # For a release, set revision for that tagged release as well and uncomment -AC_INIT([freeswitch], [1.10.8-release], bugs@freeswitch.org) +AC_INIT([freeswitch], [1.10.8-dev], bugs@freeswitch.org) AC_SUBST(SWITCH_VERSION_MAJOR, [1]) AC_SUBST(SWITCH_VERSION_MINOR, [10]) -AC_SUBST(SWITCH_VERSION_MICRO, [8-release]) +AC_SUBST(SWITCH_VERSION_MICRO, [8-dev]) AC_SUBST(SWITCH_VERSION_REVISION, []) AC_SUBST(SWITCH_VERSION_REVISION_HUMAN, [])