From: Brian West Date: Tue, 23 Nov 2010 15:54:50 +0000 (-0600) Subject: FS-535: additional checks and use the right contact for registers inside and outside... X-Git-Tag: v1.2-rc1~247^2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38f994206f075acf461b399f0e512ec5795b0083;p=thirdparty%2Ffreeswitch.git FS-535: additional checks and use the right contact for registers inside and outside of nat --- diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 32d25d0ad6..4d992b0ea1 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2156,6 +2156,30 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) sipip = profile->sipip; } + gateway->extension = switch_core_strdup(gateway->pool, extension); + + + if (!strncasecmp(proxy, "sip:", 4)) { + gateway->register_proxy = switch_core_strdup(gateway->pool, proxy); + gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4); + } else { + gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy); + gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy); + } + + /* This checks to make sure we provide the right contact on register for targets behind nat with us. */ + if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) { + char *register_host = NULL; + + register_host = sofia_glue_get_register_host(gateway->register_proxy); + + if (register_host && !sofia_glue_check_nat(profile, register_host)) { + sipip = profile->sipip; + } + + switch_safe_free(register_host); + } + if (extension_in_contact) { format = strchr(sipip, ':') ? "" : ""; gateway->register_contact = switch_core_sprintf(gateway->pool, format, extension, @@ -2170,16 +2194,6 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) profile->tls_sip_port : profile->sip_port, params); } - gateway->extension = switch_core_strdup(gateway->pool, extension); - - if (!strncasecmp(proxy, "sip:", 4)) { - gateway->register_proxy = switch_core_strdup(gateway->pool, proxy); - gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4); - } else { - gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy); - gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy); - } - gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds); if ((gateway->freq = atoi(gateway->expires_str)) < 5) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 14a7bfdd2c..7390378fc8 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -152,7 +152,7 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now) register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy); /* check for NAT and place a Via header if necessary (hostname or non-local IP) */ - if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) { + if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) { user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport); } @@ -295,7 +295,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy); /* check for NAT and place a Via header if necessary (hostname or non-local IP) */ - if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) { + if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) { user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport); } @@ -358,7 +358,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy); /* check for NAT and place a Via header if necessary (hostname or non-local IP) */ - if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) { + if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) { user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport); }