next chapter in the never-ending nat saga

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8502 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-05-21 16:46:48 +00:00
parent 281cfd6552
commit b02971fea7
5 changed files with 32 additions and 25 deletions

View File

@ -145,7 +145,8 @@ typedef enum {
PFLAG_WORKER_RUNNING = (1 << 17), PFLAG_WORKER_RUNNING = (1 << 17),
PFLAG_UNREG_OPTIONS_FAIL = (1 << 18), PFLAG_UNREG_OPTIONS_FAIL = (1 << 18),
PFLAG_DISABLE_TIMER = (1 << 19), PFLAG_DISABLE_TIMER = (1 << 19),
PFLAG_DISABLE_100REL = (1 << 20) PFLAG_DISABLE_100REL = (1 << 20),
PFLAG_AGGRESSIVE_NAT_DETECTION = (1 << 21)
} PFLAGS; } PFLAGS;
typedef enum { typedef enum {

View File

@ -1117,6 +1117,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
switch_set_flag(profile, TFLAG_LATE_NEGOTIATION); switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
} else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) { } else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) {
switch_set_flag(profile, TFLAG_PROXY_MEDIA); 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")) { } else if (!strcasecmp(var, "rfc2833-pt")) {
profile->te = (switch_payload_t) atoi(val); profile->te = (switch_payload_t) atoi(val);
} else if (!strcasecmp(var, "cng-pt")) { } else if (!strcasecmp(var, "cng-pt")) {
@ -2647,7 +2649,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
int is_auth = 0, calling_myself = 0; int is_auth = 0, calling_myself = 0;
su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua));
int network_port = 0; int network_port = 0;
char *sticky = NULL, *is_nat = NULL; char *is_nat = NULL;
if (sess_count >= sess_max || !(profile->pflags & PFLAG_RUNNING)) { if (sess_count >= sess_max || !(profile->pflags & PFLAG_RUNNING)) {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
@ -2660,11 +2662,23 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
return; return;
} }
get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr); 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); 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; uint32_t x = 0;
int ok = 1; int ok = 1;
char *last_acl = NULL; char *last_acl = NULL;
@ -2688,7 +2702,6 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
} }
} }
if (profile->acl_count) { if (profile->acl_count) {
uint32_t x = 0; uint32_t x = 0;
int ok = 1; int ok = 1;
@ -2719,7 +2732,6 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
} }
} }
if (!is_auth && if (!is_auth &&
((profile->pflags & PFLAG_AUTH_CALLS) || (!(profile->pflags & PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) { ((profile->pflags & PFLAG_AUTH_CALLS) || (!(profile->pflags & PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) {
if (!strcmp(network_ip, profile->sipip) && network_port == profile->sip_port) { if (!strcmp(network_ip, profile->sipip) && network_port == profile->sip_port) {
@ -2729,22 +2741,18 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (v_event) { if (v_event) {
switch_event_destroy(&v_event); switch_event_destroy(&v_event);
} }
switch_safe_free(sticky);
return; return;
} }
switch_safe_free(sticky);
} }
is_auth++; is_auth++;
} }
if (!(sip->sip_contact && sip->sip_contact->m_url)) { if (!(sip->sip_contact && sip->sip_contact->m_url)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
nua_respond(nh, 400, "Missing Contact Header", TAG_END()); nua_respond(nh, 400, "Missing Contact Header", TAG_END());
return; return;
} }
if (!sofia_endpoint_interface || !(session = switch_core_session_request(sofia_endpoint_interface, NULL))) { 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()); nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
return; return;
@ -2756,6 +2764,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
switch_core_session_destroy(&session); switch_core_session_destroy(&session);
return; return;
} }
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); 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); tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip);
@ -3189,7 +3199,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_
if (is_nat) { if (is_nat) {
switch_set_flag(tech_pvt, TFLAG_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"); switch_channel_set_variable(channel, "sip_nat_detected", "true");
} }

View File

@ -868,7 +868,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
uint32_t session_timeout = 0; uint32_t session_timeout = 0;
const char *val; const char *val;
const char *rep; const char *rep;
char *sticky; char *sticky = NULL;
rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER); rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
@ -1002,18 +1002,14 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_END()); TAG_END());
if (switch_test_flag(tech_pvt, TFLAG_NAT) || if (strstr(tech_pvt->dest, ";nat") || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
(val = switch_channel_get_variable(channel, "sip-force-contact")) || switch_set_flag(tech_pvt, TFLAG_NAT);
((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str); tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str);
sticky = tech_pvt->record_route; sticky = tech_pvt->record_route;
session_timeout = SOFIA_NAT_SESSION_TIMEOUT; session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
switch_channel_set_variable(channel, "sip_nat_detected", "true"); 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 */ /* 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)) { if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NAME)) {
priv = "name"; priv = "name";
@ -1104,7 +1100,6 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
sofia_glue_tech_patch_sdp(tech_pvt); sofia_glue_tech_patch_sdp(tech_pvt);
} }
nua_invite(tech_pvt->nh, nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0), NUTAG_AUTOANSWER(0),
NUTAG_SESSION_TIMER(session_timeout), NUTAG_SESSION_TIMER(session_timeout),
@ -1112,6 +1107,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)), 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(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), 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_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1), SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1), SOATAG_ORDERED_USER(1),

View File

@ -529,10 +529,10 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") || if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) { !strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
if (contact->m_url->url_params) { 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); display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params);
} else { } 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")) { if (strstr(v_contact_str, "tls")) {
reg_desc = "Registered(TLSHACK)"; reg_desc = "Registered(TLSHACK)";