From 56f10fb3c622ebe99b11013abb7a9f6ba5d24656 Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 2 Dec 2009 01:58:05 +0000 Subject: [PATCH] Well I'll be a son of a monkey's bitch, it was that bug git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15748 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia.c | 41 ++++++++++++++++++++----- src/mod/endpoints/mod_sofia/sofia_reg.c | 3 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index be40f13a04..75ca4249ad 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2148,7 +2148,11 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else if (!strcasecmp(var, "context")) { profile->context = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "local-network-acl")) { - profile->local_network = switch_core_strdup(profile->pool, val); + if (!strcasecmp(var, "none")) { + profile->local_network = NULL; + } else { + profile->local_network = switch_core_strdup(profile->pool, val); + } } else if (!strcasecmp(var, "force-register-domain")) { profile->reg_domain = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-subscription-domain")) { @@ -2429,6 +2433,19 @@ switch_status_t config_sofia(int reload, char *profile_name) sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER); sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS); + profile->local_network = "localnet.auto"; + + if (switch_core_get_variable("nat_type")) { + const char *ip = switch_core_get_variable("nat_public_addr"); + if (ip) { + profile->extrtpip = switch_core_strdup(profile->pool, ip); + profile->extsipip = switch_core_strdup(profile->pool, ip); + sofia_set_pflag(profile, PFLAG_AUTO_NAT); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "NAT detected setting external ip to %s\n", ip); + } + } + + for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -2579,12 +2596,14 @@ switch_status_t config_sofia(int reload, char *profile_name) if (!strcmp(val, "0.0.0.0")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); } else if (!strcasecmp(val, "auto-nat")) { - ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; + ip = NULL; } else { ip = strcasecmp(val, "auto") ? val : mod_sofia_globals.guess_ip; + sofia_clear_pflag(profile, PFLAG_AUTO_NAT); + } + if (ip) { + profile->extrtpip = switch_core_strdup(profile->pool, ip); } - sofia_set_pflag(profile, PFLAG_AUTO_NAT); - profile->extrtpip = switch_core_strdup(profile->pool, ip); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ext-rtp-ip\n"); } @@ -2617,22 +2636,28 @@ switch_status_t config_sofia(int reload, char *profile_name) if (!strcasecmp(val, "0.0.0.0")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip); } else if (!strcasecmp(val, "auto-nat")) { - ip = mod_sofia_globals.auto_nat ? switch_core_get_variable("nat_public_addr") : mod_sofia_globals.guess_ip; + ip = NULL; } else if (strcasecmp(val, "auto")) { switch_port_t port = 0; if (sofia_glue_ext_address_lookup(profile, NULL, &myip, &port, val, profile->pool) == SWITCH_STATUS_SUCCESS) { ip = myip; + sofia_clear_pflag(profile, PFLAG_AUTO_NAT); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to get external ip.\n"); } } - sofia_set_pflag(profile, PFLAG_AUTO_NAT); - profile->extsipip = switch_core_strdup(profile->pool, ip); + if (ip) { + profile->extsipip = switch_core_strdup(profile->pool, ip); + } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ext-sip-ip\n"); } } else if (!strcasecmp(var, "local-network-acl")) { - profile->local_network = switch_core_strdup(profile->pool, val); + if (!strcasecmp(var, "none")) { + profile->local_network = NULL; + } else { + profile->local_network = switch_core_strdup(profile->pool, val); + } } else if (!strcasecmp(var, "force-register-domain")) { profile->reg_domain = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "force-register-db-domain")) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index f68befee34..9515a8768a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1363,7 +1363,8 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h goto end; } - if (is_nat && !sofia_glue_check_nat(profile, network_ip)) { + if (is_nat && profile->local_network && switch_check_network_list_ip(network_ip, profile->local_network)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s is on local network, not seting NAT mode.\n", network_ip); is_nat = NULL; }