]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7602 add some of 3b2d00f3e65061393da10a4ba286ac72cdb3c16e from verto to sip and...
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 3 Jun 2015 02:20:03 +0000 (21:20 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 3 Jun 2015 02:20:03 +0000 (21:20 -0500)
src/include/switch_core_media.h
src/include/switch_stun.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/switch_core_media.c
src/switch_core_state_machine.c
src/switch_rtp.c
src/switch_stun.c

index bc258172252e22b9ff7379134dd26be037e848a9..31bf08387bdfa312414085d34d433cdc2dcd0b3e 100644 (file)
@@ -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
index eb4274457b108c3dc69fbe228b98392a3dd4c741..9db0aadd840177753cd1a077698ceaca553928cc 100644 (file)
@@ -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
index 4917cd8824f311ca3e1da1865e09177149dbc100..f80318f4598c8817e9af07e27113cc24f5d466d6 100644 (file)
@@ -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, "    <rtp-ip>%s</rtp-ip>\n", switch_str_nil(profile->rtpip[x]));
                                        }
+                                       for (x = 0; x < profile->rtpip_index6; x++) {
+                                               stream->write_function(stream, "    <rtp-ip>%s</rtp-ip>\n", switch_str_nil(profile->rtpip6[x]));
+                                       }
                                        if (profile->extrtpip) {
                                                stream->write_function(stream, "    <ext-rtp-ip>%s</ext-rtp-ip>\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++;
                                                                }
                                                        }
index 864eff79ac30777d39e3dce58e43459a28dc722b..df52655ab234bf868ea446a3dd5a749f81212544 100644 (file)
@@ -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;
 
index cf461262d35cc3155185f1bc0970ebbdee0995e2..b6b597f61e7ec5cc915ed7ff82d5ad1710afed97 100644 (file)
@@ -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");
                                }
index cfa01c34f2ca1c744d9f2f9c917511a2ba56e08f..52b8b5256f9a27b02c6f7549044b16fe23595035 100644 (file)
@@ -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++;
index bd0b1c23a1017743bec6536e353d655c7146b3cb..cd725ab3db2a461e297a8bdc4346781f408a6914 100644 (file)
@@ -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) {
index c066cd00b7ebd29241a9a7c0c2d675cb383e8118..26750ff58efa9a174ab69783f969b313db317f01 100644 (file)
@@ -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 */
index 3905e57cb6a532c6548de82baa4e1271488bb98f..b0b9f2f9e6c5e0a41a72116cb6142bf34f60ca42 100644 (file)
@@ -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));
index 1dd35d9bc599f565212d5c4a0232ff81afa96e95..d1f43c32440f65986e558bb742990413be0d086b 100644 (file)
@@ -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"},