mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 20:51:58 +00:00
add an external port output parameter to switch_nat_add_mapping and use it in sofia_glue_tech_choose_port
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13629 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -49,6 +49,7 @@ SWITCH_STANDARD_API(nat_map_function)
|
||||
int argc;
|
||||
char *mydata = NULL, *argv[4];
|
||||
switch_nat_ip_proto_t proto = SWITCH_NAT_UDP;
|
||||
switch_port_t external_port = 0;
|
||||
|
||||
if (!cmd) {
|
||||
goto error;
|
||||
@@ -70,8 +71,8 @@ SWITCH_STANDARD_API(nat_map_function)
|
||||
}
|
||||
|
||||
if (argv[0] && switch_stristr("add", argv[0])) {
|
||||
if (switch_nat_add_mapping((switch_port_t)atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "true");
|
||||
if (switch_nat_add_mapping((switch_port_t)atoi(argv[1]), proto, &external_port) == SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "%d", (int)external_port);
|
||||
goto ok;
|
||||
}
|
||||
} else if (argv[0] && switch_stristr("del", argv[0])) {
|
||||
|
||||
@@ -762,13 +762,13 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
);
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
|
||||
}
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port);
|
||||
}
|
||||
if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
|
||||
if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,6 +630,7 @@ switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int forc
|
||||
switch_port_t sdp_port;
|
||||
char tmp[50];
|
||||
const char *use_ip = NULL;
|
||||
switch_port_t external_port = 0;
|
||||
|
||||
if (!force) {
|
||||
if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) ||
|
||||
@@ -667,12 +668,12 @@ switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int forc
|
||||
|
||||
if (tech_pvt->profile->extrtpip && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
|
||||
tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port);
|
||||
} else {
|
||||
tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip);
|
||||
}
|
||||
|
||||
tech_pvt->adv_sdp_audio_port = sdp_port;
|
||||
tech_pvt->adv_sdp_audio_port = external_port != 0 ? external_port : sdp_port;
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port);
|
||||
switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
|
||||
@@ -686,6 +687,7 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, in
|
||||
char *ip = tech_pvt->profile->rtpip;
|
||||
switch_port_t sdp_port;
|
||||
char tmp[50];
|
||||
switch_port_t external_port = 0;
|
||||
|
||||
if (!force) {
|
||||
if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)
|
||||
@@ -712,11 +714,11 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, in
|
||||
}
|
||||
}
|
||||
|
||||
tech_pvt->adv_sdp_video_port = sdp_port;
|
||||
|
||||
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port);
|
||||
}
|
||||
|
||||
tech_pvt->adv_sdp_video_port = external_port != 0 ? external_port : sdp_port;
|
||||
|
||||
switch_snprintf(tmp, sizeof(tmp), "%d", sdp_port);
|
||||
switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
|
||||
|
||||
@@ -2291,7 +2291,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
|
||||
|
||||
if (prefs.nat_map) {
|
||||
switch_nat_add_mapping(prefs.port, SWITCH_NAT_TCP);
|
||||
switch_nat_add_mapping(prefs.port, SWITCH_NAT_TCP, NULL);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user