[Freeswitch-svn] [commit] r8502 - freeswitch/trunk/src/mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Wed May 21 12:46:49 EDT 2008
Author: anthm
Date: Wed May 21 12:46:48 2008
New Revision: 8502
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Log:
next chapter in the never-ending nat saga
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed May 21 12:46:48 2008
@@ -1856,7 +1856,7 @@
tech_pvt->dest_to = switch_core_session_sprintf(nsession, "sip:%s@%s", dest_to, host);
}
}
-
+
if (!tech_pvt->dest_to) {
tech_pvt->dest_to = tech_pvt->dest;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed May 21 12:46:48 2008
@@ -145,7 +145,8 @@
PFLAG_WORKER_RUNNING = (1 << 17),
PFLAG_UNREG_OPTIONS_FAIL = (1 << 18),
PFLAG_DISABLE_TIMER = (1 << 19),
- PFLAG_DISABLE_100REL = (1 << 20)
+ PFLAG_DISABLE_100REL = (1 << 20),
+ PFLAG_AGGRESSIVE_NAT_DETECTION = (1 << 21)
} PFLAGS;
typedef enum {
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 Wed May 21 12:46:48 2008
@@ -1117,6 +1117,8 @@
switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
} else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) {
switch_set_flag(profile, TFLAG_PROXY_MEDIA);
+ } else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) {
+ profile->pflags |= PFLAG_AGGRESSIVE_NAT_DETECTION;
} else if (!strcasecmp(var, "rfc2833-pt")) {
profile->te = (switch_payload_t) atoi(val);
} else if (!strcasecmp(var, "cng-pt")) {
@@ -2647,7 +2649,7 @@
int is_auth = 0, calling_myself = 0;
su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
int network_port = 0;
- char *sticky = NULL, *is_nat = NULL;
+ char *is_nat = NULL;
if (sess_count >= sess_max || !(profile->pflags & PFLAG_RUNNING)) {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
@@ -2659,12 +2661,24 @@
nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END());
return;
}
-
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
-
- if (profile->nat_acl_count) {
+
+ if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) {
+ if (sip && sip->sip_via) {
+ const char *port = sip->sip_via->v_port;
+ const char *host = sip->sip_via->v_host;
+
+ if (host && strcmp(network_ip, host)) {
+ is_nat = "via host";
+ } else if (port && atoi(port) != network_port) {
+ is_nat = "via port";
+ }
+ }
+ }
+
+ if (!is_nat && profile->nat_acl_count) {
uint32_t x = 0;
int ok = 1;
char *last_acl = NULL;
@@ -2687,7 +2701,6 @@
}
}
}
-
if (profile->acl_count) {
uint32_t x = 0;
@@ -2718,7 +2731,6 @@
}
}
}
-
if (!is_auth &&
((profile->pflags & PFLAG_AUTH_CALLS) || (!(profile->pflags & PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) {
@@ -2729,22 +2741,18 @@
if (v_event) {
switch_event_destroy(&v_event);
}
- switch_safe_free(sticky);
return;
}
- switch_safe_free(sticky);
}
is_auth++;
}
-
if (!(sip->sip_contact && sip->sip_contact->m_url)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
nua_respond(nh, 400, "Missing Contact Header", TAG_END());
return;
}
-
if (!sofia_endpoint_interface || !(session = switch_core_session_request(sofia_endpoint_interface, NULL))) {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
return;
@@ -2756,6 +2764,8 @@
switch_core_session_destroy(&session);
return;
}
+
+
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip);
@@ -3189,7 +3199,7 @@
if (is_nat) {
switch_set_flag(tech_pvt, TFLAG_NAT);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting NAT mode based on acl %s\n", is_nat);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting NAT mode based on %s\n", is_nat);
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
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 Wed May 21 12:46:48 2008
@@ -868,7 +868,7 @@
uint32_t session_timeout = 0;
const char *val;
const char *rep;
- char *sticky;
+ char *sticky = NULL;
rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
@@ -1001,19 +1001,15 @@
SIPTAG_CONTACT_STR(invite_contact),
TAG_END());
-
- if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
- (val = switch_channel_get_variable(channel, "sip-force-contact")) ||
- ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
+
+ if (strstr(tech_pvt->dest, ";nat") || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
+ switch_set_flag(tech_pvt, TFLAG_NAT);
tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str);
sticky = tech_pvt->record_route;
session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
-
-
-
-
+
/* TODO: We should use the new tags for making an rpid and add profile options to turn this on/off */
if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NAME)) {
priv = "name";
@@ -1104,7 +1100,6 @@
sofia_glue_tech_patch_sdp(tech_pvt);
}
-
nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0),
NUTAG_SESSION_TIMER(session_timeout),
@@ -1112,6 +1107,7 @@
TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
+ TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed May 21 12:46:48 2008
@@ -529,10 +529,10 @@
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
if (contact->m_url->url_params) {
- switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>",
+ switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>;nat",
display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params);
} else {
- switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>", display, contact->m_url->url_user, network_ip, network_port);
+ switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>;nat", display, contact->m_url->url_user, network_ip, network_port);
}
if (strstr(v_contact_str, "tls")) {
reg_desc = "Registered(TLSHACK)";
More information about the Freeswitch-svn
mailing list