From c9065a85b6ac92ef3318df2abe30395df1f3c99f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 2 Jun 2015 21:20:03 -0500 Subject: [PATCH] FS-7602 add some of 3b2d00f3e65061393da10a4ba286ac72cdb3c16e from verto to sip and refactor some code to keep sip working like verto --- src/include/switch_core_media.h | 1 + src/include/switch_stun.h | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.c | 11 ++++++++++- src/mod/endpoints/mod_sofia/mod_sofia.h | 3 +++ src/mod/endpoints/mod_sofia/sofia.c | 20 +++++++++++++++----- src/mod/endpoints/mod_sofia/sofia_glue.c | 22 +++++++++++++++++++--- src/switch_core_media.c | 17 ++--------------- src/switch_core_state_machine.c | 4 ++++ src/switch_rtp.c | 10 +++++++++- src/switch_stun.c | 1 + 10 files changed, 66 insertions(+), 25 deletions(-) diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index bc25817225..31bf08387b 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -332,6 +332,7 @@ SWITCH_DECLARE(switch_media_flow_t) switch_core_session_media_flow(switch_core_s SWITCH_DECLARE(switch_status_t) switch_core_media_get_vid_params(switch_core_session_t *session, switch_vid_params_t *vid_params); SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw); SWITCH_DECLARE(switch_bool_t) switch_core_session_in_video_thread(switch_core_session_t *session); +SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t *session); SWITCH_END_EXTERN_C #endif diff --git a/src/include/switch_stun.h b/src/include/switch_stun.h index eb4274457b..9db0aadd84 100644 --- a/src/include/switch_stun.h +++ b/src/include/switch_stun.h @@ -197,6 +197,8 @@ SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_p \return true or false */ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port); +SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_xor_mapped_address(switch_stun_packet_attribute_t *attribute, uint32_t cookie, char *ipstr, uint16_t *port); + /*! \brief Extract a username from a packet attribute diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 4917cd8824..f80318f459 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2676,9 +2676,15 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t stream->write_function(stream, "Dialplan \t%s\n", switch_str_nil(profile->dialplan)); stream->write_function(stream, "Context \t%s\n", switch_str_nil(profile->context)); stream->write_function(stream, "Challenge Realm \t%s\n", zstr(profile->challenge_realm) ? "auto_to" : profile->challenge_realm); + for (x = 0; x < profile->rtpip_index; x++) { stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip[x])); } + + for (x = 0; x < profile->rtpip_index6; x++) { + stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip6[x])); + } + if (profile->extrtpip) { stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip); } @@ -2980,6 +2986,9 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl for (x = 0; x < profile->rtpip_index; x++) { stream->write_function(stream, " %s\n", switch_str_nil(profile->rtpip[x])); } + for (x = 0; x < profile->rtpip_index6; x++) { + stream->write_function(stream, " %s\n", switch_str_nil(profile->rtpip6[x])); + } if (profile->extrtpip) { stream->write_function(stream, " %s\n", profile->extrtpip); } @@ -5467,7 +5476,7 @@ static void general_event_handler(switch_event_t *event) } if (!strcmp(profile->rtpip[x], old_ip6)) { - profile->rtpip[x] = switch_core_strdup(profile->pool, new_ip6); + profile->rtpip6[x] = switch_core_strdup(profile->pool, new_ip6); rb++; } } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 864eff79ac..df52655ab2 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -575,11 +575,14 @@ struct sofia_profile { char *shutdown_type; char *extrtpip; char *rtpip[MAX_RTPIP]; + char *rtpip6[MAX_RTPIP]; char *jb_msec; switch_payload_t te; switch_payload_t recv_te; uint32_t rtpip_index; uint32_t rtpip_next; + uint32_t rtpip_index6; + uint32_t rtpip_next6; char *rtcp_audio_interval_msec; char *rtcp_video_interval_msec; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index cf461262d3..b6b597f61e 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4219,6 +4219,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->ob_failed_calls = 0; profile->shutdown_type = "false"; profile->rtpip_index = 0; + profile->rtpip_index6 = 0; if (xprofiledomain) { profile->domain_name = switch_core_strdup(profile->pool, xprofiledomain); @@ -4717,10 +4718,19 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } else { ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip; } - if (profile->rtpip_index < MAX_RTPIP) { - profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, ip); + + if (strchr(ip, ':')) { + if (profile->rtpip_index < MAX_RTPIP) { + profile->rtpip6[profile->rtpip_index6++] = switch_core_strdup(profile->pool, ip); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name); + } } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name); + if (profile->rtpip_index6 < MAX_RTPIP) { + profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, ip); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Max IPs configured for profile %s.\n", profile->name); + } } } else if (!strcasecmp(var, "sip-ip")) { char *ip = mod_sofia_globals.guess_ip; @@ -5455,7 +5465,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->sipip = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip); } - if (!profile->rtpip[0]) { + if (!profile->rtpip[0] && !profile->rtpip6[0]) { profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip); } @@ -5488,7 +5498,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->sdp_username = switch_core_strdup(profile->pool, "FreeSWITCH"); } - if (!profile->rtpip[0]) { + if (!profile->rtpip[0] && !profile->rtpip6[0]) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Setting ip to '127.0.0.1'\n"); profile->rtpip[profile->rtpip_index++] = switch_core_strdup(profile->pool, "127.0.0.1"); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index cfa01c34f2..52b8b5256f 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -92,9 +92,25 @@ void sofia_glue_attach_private(switch_core_session_t *session, sofia_profile_t * tech_pvt->profile = profile; - tech_pvt->mparams.rtpip = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next++]); - if (profile->rtpip_next >= profile->rtpip_index) { - profile->rtpip_next = 0; + if (!zstr(profile->rtpip[profile->rtpip_next])) { + tech_pvt->mparams.rtpip4 = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next++]); + tech_pvt->mparams.rtpip = tech_pvt->mparams.rtpip4; + + if (profile->rtpip_next >= profile->rtpip_index) { + profile->rtpip_next = 0; + } + } + + if (!zstr(profile->rtpip[profile->rtpip_next6])) { + tech_pvt->mparams.rtpip6 = switch_core_session_strdup(session, profile->rtpip[profile->rtpip_next6++]); + + if (zstr(tech_pvt->mparams.rtpip)) { + tech_pvt->mparams.rtpip = tech_pvt->mparams.rtpip6; + } + + if (profile->rtpip_next6 >= profile->rtpip_index6) { + profile->rtpip_next6 = 0; + } } profile->inuse++; diff --git a/src/switch_core_media.c b/src/switch_core_media.c index bd0b1c23a1..cd725ab3db 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -216,8 +216,6 @@ struct switch_media_handle_s { }; -static switch_bool_t check_dtls(switch_core_session_t *session); - static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID] = { { "AEAD_AES_256_GCM_8", AEAD_AES_256_GCM_8, 44}, { "AEAD_AES_128_GCM_8", AEAD_AES_128_GCM_8, 28}, @@ -6589,13 +6587,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi end: - switch_channel_clear_flag(session->channel, CF_REINVITE); switch_core_recovery_track(session); - - return status; } @@ -8649,7 +8644,7 @@ static int check_engine(switch_rtp_engine_t *engine) return 1; } -static switch_bool_t check_dtls(switch_core_session_t *session) +SWITCH_DECLARE(switch_bool_t) switch_core_media_check_dtls(switch_core_session_t *session) { switch_media_handle_t *smh; switch_rtp_engine_t *a_engine, *v_engine; @@ -8661,7 +8656,7 @@ static switch_bool_t check_dtls(switch_core_session_t *session) return SWITCH_FALSE; } - if (switch_channel_down(session->channel)) { + if (!switch_channel_media_up(session->channel)) { return SWITCH_FALSE; } @@ -8715,14 +8710,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se } break; - case SWITCH_MESSAGE_INDICATE_ANSWER: - case SWITCH_MESSAGE_INDICATE_PROGRESS: - case SWITCH_MESSAGE_ANSWER_EVENT: - case SWITCH_MESSAGE_PROGRESS_EVENT: - { - check_dtls(session); - } - break; case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ: { if (v_engine->rtp_session) { diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index c066cd00b7..26750ff58e 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -486,6 +486,10 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) } } } + + if (state > CS_INIT && switch_channel_media_up(session->channel)) { + switch_core_media_check_dtls(session); + } switch (state) { case CS_NEW: /* Just created, Waiting for first instructions */ diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3905e57cb6..b0b9f2f9e6 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -887,7 +887,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "STUN PACKET TYPE: %s\n", switch_stun_value_to_name(SWITCH_STUN_TYPE_PACKET_TYPE, packet->header.type)); do { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|---: STUN ATTR %s\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|---: STUN ATTR %d %x %s\n", attr->type, attr->type, switch_stun_value_to_name(SWITCH_STUN_TYPE_ATTRIBUTE, attr->type)); switch (attr->type) { @@ -928,6 +928,14 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port); } break; + case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS: + if (attr->type) { + char ip[16]; + uint16_t port; + switch_stun_packet_attribute_get_xor_mapped_address(attr, packet->header.cookie, ip, &port); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG8, "|------: %s:%d\n", ip, port); + } + break; case SWITCH_STUN_ATTR_USERNAME: if (attr->type) { switch_stun_packet_attribute_get_username(attr, username, sizeof(username)); diff --git a/src/switch_stun.c b/src/switch_stun.c index 1dd35d9bc5..d1f43c3244 100644 --- a/src/switch_stun.c +++ b/src/switch_stun.c @@ -60,6 +60,7 @@ static const struct value_mapping PACKET_TYPES[] = { static const struct value_mapping ATTR_TYPES[] = { {SWITCH_STUN_ATTR_MAPPED_ADDRESS, "MAPPED_ADDRESS"}, + {SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS, "XOR_MAPPED_ADDRESS"}, {SWITCH_STUN_ATTR_RESPONSE_ADDRESS, "RESPONSE_ADDRESS"}, {SWITCH_STUN_ATTR_CHANGE_REQUEST, "CHANGE_REQUEST"}, {SWITCH_STUN_ATTR_SOURCE_ADDRESS, "SOURCE_ADDRESS"},