]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9162 Include external IP address in SDP if include_external_ip is set
authorDan Edwards <dedwards@vertical.com>
Mon, 16 Jan 2017 15:42:00 +0000 (10:42 -0500)
committerDan Edwards <dedwards@vertical.com>
Tue, 17 Jan 2017 20:21:27 +0000 (15:21 -0500)
src/switch_core_media.c

index 0c787e6aa50c9a9e3d9c230d5280379419e819aa..23679b9413ad05d8cc016d6b43ba432663e7611e 100644 (file)
@@ -8814,6 +8814,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
        const char *local_sdp_audio_zrtp_hash;
        switch_media_handle_t *smh;
        switch_rtp_engine_t *a_engine;
+       int include_external;
 
        switch_assert(session);
 
@@ -8829,6 +8830,8 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
        switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "m=audio %d %s", port, 
                                        get_media_profile_name(session, secure || a_engine->crypto_type != CRYPTO_INVALID));
 
+       include_external = switch_channel_var_true(session->channel, "include_external_ip");
+
        for (i = 0; i < smh->mparams->num_codecs; i++) {
                const switch_codec_implementation_t *imp = smh->codecs[i];
                int this_ptime = (imp->microseconds_per_packet / 1000);
@@ -8987,6 +8990,7 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
        if (a_engine->ice_out.cands[0][0].ready) {
                char tmp1[11] = "";
                char tmp2[11] = "";
+               char tmp3[11] = "";
                uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
                uint32_t c2 = c1 - 1;
 
@@ -8997,8 +9001,10 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
 
                tmp1[10] = '\0';
                tmp2[10] = '\0';
+               tmp3[10] = '\0';
                switch_stun_random_string(tmp1, 10, "0123456789");
                switch_stun_random_string(tmp2, 10, "0123456789");
+               switch_stun_random_string(tmp3, 10, "0123456789");
 
                gen_ice(session, SWITCH_MEDIA_TYPE_AUDIO, NULL, 0);
 
@@ -9019,6 +9025,13 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
                                                ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
                                                );
 
+               if (include_external && !zstr(smh->mparams->extsipip)) {
+                       switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\n",
+                               tmp3, ice_out->cands[0][0].transport, c1,
+                               smh->mparams->extsipip, ice_out->cands[0][0].con_port
+                               );
+               }
+
                if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) && 
                        strcmp(a_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
                        && a_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
@@ -9038,6 +9051,13 @@ static void generate_m(switch_core_session_t *session, char *buf, size_t buflen,
                                                        ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
                                                        );
                        
+                       if (include_external && !zstr(smh->mparams->extsipip)) {
+                               switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\n",
+                                       tmp3, ice_out->cands[0][0].transport, c1,
+                                       smh->mparams->extsipip, ice_out->cands[0][0].con_port
+                                       );
+                       }
+
                        if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][1].con_addr) && 
                                strcmp(a_engine->local_sdp_ip, ice_out->cands[0][1].con_addr)
                                && a_engine->local_sdp_port != ice_out->cands[0][1].con_port) {
@@ -9266,6 +9286,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
        int bw = 256;
        uint8_t fir = 0, nack = 0, pli = 0, tmmbr = 0, has_vid = 0;
        const char *use_rtcp_mux = NULL;
+       int include_external;
 
        switch_assert(session);
 
@@ -9277,6 +9298,8 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
        v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
        t_engine = &smh->engines[SWITCH_MEDIA_TYPE_TEXT];
 
+       include_external = switch_channel_var_true(session->channel, "include_external_ip");
+
        use_rtcp_mux = switch_channel_get_variable(session->channel, "rtcp_mux");
 
        if (use_rtcp_mux && switch_false(use_rtcp_mux)) {
@@ -9704,6 +9727,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                if (a_engine->ice_out.cands[0][0].ready) {
                        char tmp1[11] = "";
                        char tmp2[11] = "";
+                       char tmp3[11] = "";
                        uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
                        //uint32_t c2 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 2);
                        //uint32_t c3 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 1);
@@ -9715,8 +9739,10 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
 
                        tmp1[10] = '\0';
                        tmp2[10] = '\0';
+                       tmp3[10] = '\0';
                        switch_stun_random_string(tmp1, 10, "0123456789");
                        switch_stun_random_string(tmp2, 10, "0123456789");
+                       switch_stun_random_string(tmp3, 10, "0123456789");
 
                        ice_out = &a_engine->ice_out;
                        
@@ -9730,6 +9756,13 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                                        ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
                                                        );
 
+                       if (include_external && !zstr(smh->mparams->extsipip)) {
+                               switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\n",
+                                       tmp3, ice_out->cands[0][0].transport, c1,
+                                       smh->mparams->extsipip, ice_out->cands[0][0].con_port
+                                       );
+                       }
+
                        if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) && 
                                strcmp(a_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
                                && a_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
@@ -9749,6 +9782,12 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                                                ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
                                                                );
                                
+                               if (include_external && !zstr(smh->mparams->extsipip)) {
+                                       switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\n",
+                                               tmp3, ice_out->cands[0][0].transport, c2,
+                                               smh->mparams->extsipip, ice_out->cands[0][0].con_port + (a_engine->rtcp_mux > 0 ? 0 : 1)
+                                               );
+                               }
 
                                
                                if (!zstr(a_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) && 
@@ -10231,6 +10270,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                if (v_engine->ice_out.cands[0][0].ready) {
                                        char tmp1[11] = "";
                                        char tmp2[11] = "";
+                                       char tmp3[11] = "";
                                        uint32_t c1 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 1);
                                        //uint32_t c2 = (2^24)*126 + (2^8)*65535 + (2^0)*(256 - 2);
                                        //uint32_t c3 = (2^24)*126 + (2^8)*65534 + (2^0)*(256 - 1);
@@ -10242,8 +10282,10 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                
                                        tmp1[10] = '\0';
                                        tmp2[10] = '\0';
+                                       tmp3[10] = '\0';
                                        switch_stun_random_string(tmp1, 10, "0123456789");
                                        switch_stun_random_string(tmp2, 10, "0123456789");
+                                       switch_stun_random_string(tmp3, 10, "0123456789");
 
                                        ice_out = &v_engine->ice_out;
                                        
@@ -10264,6 +10306,13 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                                                        ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port
                                                                        );
 
+                                       if (include_external && !zstr(smh->mparams->extsipip)) {
+                                               switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 1 %s %u %s %d typ host generation 0\n",
+                                                       tmp3, ice_out->cands[0][0].transport, c1,
+                                                       smh->mparams->extsipip, ice_out->cands[0][0].con_port
+                                                       );
+                                       }
+
                                        if (!zstr(v_engine->local_sdp_ip) && !zstr(ice_out->cands[0][0].con_addr) && 
                                                strcmp(v_engine->local_sdp_ip, ice_out->cands[0][0].con_addr)
                                                && v_engine->local_sdp_port != ice_out->cands[0][0].con_port) {
@@ -10283,7 +10332,14 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
                                                                                ice_out->cands[0][0].con_addr, ice_out->cands[0][0].con_port + (v_engine->rtcp_mux > 0 ? 0 : 1)
                                                                                );
                                        
-                                       
+                                       if (include_external && !zstr(smh->mparams->extsipip)) {
+                                                       switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=candidate:%s 2 %s %u %s %d typ host generation 0\n",
+                                                               tmp3, ice_out->cands[0][0].transport, c2,
+                                                               smh->mparams->extsipip, ice_out->cands[0][0].con_port + (v_engine->rtcp_mux > 0 ? 0 : 1)
+                                                               );
+                                               }
+
+
                                                if (!zstr(v_engine->local_sdp_ip) && !zstr(ice_out->cands[0][1].con_addr) && 
                                                        strcmp(v_engine->local_sdp_ip, ice_out->cands[0][1].con_addr)
                                                        && v_engine->local_sdp_port != ice_out->cands[0][1].con_port) {