[Freeswitch-svn] [commit] r13629 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/endpoints/mod_sofia mod/event_handlers/mod_event_socket
FreeSWITCH SVN
mrene at freeswitch.org
Thu Jun 4 19:30:44 PDT 2009
Author: mrene
Date: Thu Jun 4 21:30:44 2009
New Revision: 13629
Log:
add an external port output parameter to switch_nat_add_mapping and use it in sofia_glue_tech_choose_port
Modified:
freeswitch/trunk/src/include/switch_nat.h
freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
freeswitch/trunk/src/switch_nat.c
Modified: freeswitch/trunk/src/include/switch_nat.h
==============================================================================
--- freeswitch/trunk/src/include/switch_nat.h (original)
+++ freeswitch/trunk/src/include/switch_nat.h Thu Jun 4 21:30:44 2009
@@ -59,9 +59,22 @@
\note Generally called by the core_init
*/
SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool);
+/*!
+ \brief Shuts down the NAT Traversal System
+*/
SWITCH_DECLARE(void) switch_nat_shutdown(void);
-SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto);
+/*!
+ \brief Maps a port through the NAT Traversal System
+ \param port Internal port to map
+ \param proto Protocol
+ \param external_port [out] Mapped external port
+*/
+SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port);
+/*!
+ \brief Deletes a NAT mapping
+ \param proto Protocol
+*/
SWITCH_DECLARE(switch_status_t) switch_nat_del_mapping(switch_port_t port, switch_nat_ip_proto_t proto);
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Thu Jun 4 21:30:44 2009
@@ -49,6 +49,7 @@
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 @@
}
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])) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Thu Jun 4 21:30:44 2009
@@ -762,13 +762,13 @@
);
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);
}
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Thu Jun 4 21:30:44 2009
@@ -630,6 +630,7 @@
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 @@
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 @@
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 @@
}
}
- 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);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Thu Jun 4 21:30:44 2009
@@ -2291,7 +2291,7 @@
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;
Modified: freeswitch/trunk/src/switch_nat.c
==============================================================================
--- freeswitch/trunk/src/switch_nat.c (original)
+++ freeswitch/trunk/src/switch_nat.c Thu Jun 4 21:30:44 2009
@@ -170,7 +170,7 @@
}
}
-static switch_status_t switch_nat_add_mapping_pmp(switch_port_t port, switch_nat_ip_proto_t proto)
+static switch_status_t switch_nat_add_mapping_pmp(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port)
{
switch_status_t status = SWITCH_STATUS_FALSE;
natpmpresp_t response;
@@ -198,6 +198,16 @@
response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
(response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"),
response.pnu.newportmapping.privateport);
+ if (external_port) {
+ *external_port = response.pnu.newportmapping.mappedpublicport;
+ } else if (response.pnu.newportmapping.mappedpublicport != response.pnu.newportmapping.privateport) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "External port %hu protocol %s was not available, it was instead mapped to %hu",
+ response.pnu.newportmapping.privateport,
+ response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
+ (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"),
+ response.pnu.newportmapping.mappedpublicport);
+ }
+
status = SWITCH_STATUS_SUCCESS;
}
@@ -285,16 +295,20 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto)
+SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch (nat_globals.nat_type) {
case SWITCH_NAT_TYPE_PMP:
- status = switch_nat_add_mapping_pmp(port, proto);
+ status = switch_nat_add_mapping_pmp(port, proto, external_port);
break;
case SWITCH_NAT_TYPE_UPNP:
- status = switch_nat_add_mapping_upnp(port, proto);
+ if ((status = switch_nat_add_mapping_upnp(port, proto)) && status == SWITCH_STATUS_SUCCESS) {
+ if (external_port) {
+ *external_port = port;
+ }
+ }
break;
default:
break;
More information about the Freeswitch-svn
mailing list