diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 8c0fe09bf2..016b48989a 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -270,6 +270,9 @@ typedef enum { PFLAG_MESSAGES_RESPOND_200_OK, PFLAG_SUBSCRIBE_RESPOND_200_OK, PFLAG_PARSE_ALL_INVITE_HEADERS, + PFLAG_TCP_UNREG_ON_SOCKET_CLOSE, + PFLAG_TLS_ALWAYS_NAT, + PFLAG_TCP_ALWAYS_NAT, /* No new flags below this line */ PFLAG_MAX } PFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index fe3dd14463..9a83370261 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4103,6 +4103,24 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_MWI_USE_REG_CALLID); } + } else if (!strcasecmp(var, "tcp-unreg-on-socket-close")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_TCP_UNREG_ON_SOCKET_CLOSE); + } else { + sofia_clear_pflag(profile, PFLAG_TCP_UNREG_ON_SOCKET_CLOSE); + } + } else if (!strcasecmp(var, "tcp-always-nat")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_TCP_ALWAYS_NAT); + } else { + sofia_clear_pflag(profile, PFLAG_TCP_ALWAYS_NAT); + } + } else if (!strcasecmp(var, "tls-always-nat")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_TCP_ALWAYS_NAT); + } else { + sofia_clear_pflag(profile, PFLAG_TCP_ALWAYS_NAT); + } } else if (!strcasecmp(var, "presence-proto-lookup")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_PRESENCE_MAP); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index f2fec6254a..ba9c8cf2f8 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2180,8 +2180,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) } - test_sql = switch_mprintf("delete from sip_registrations where (sub_host is null or contact like '%%TCP%%' " - "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " + test_sql = switch_mprintf("delete from sip_registrations where sub_host is null " + "and hostname='%q' " "and network_ip like '%%' and network_port like '%%' and sip_username " "like '%%' and mwi_user like '%%' and mwi_host like '%%' " "and orig_server_host like '%%' and orig_hostname like '%%'", mod_sofia_globals.hostname); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 4ebb4055b4..e2447f45a1 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1187,10 +1187,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand if (sip && sip->sip_via && (vproto = sip->sip_via->v_protocol)) { if (!strcasecmp(vproto, "sip/2.0/ws")) { is_ws = 1; - is_nat++; + is_nat = "ws"; } else if (!strcasecmp(vproto, "sip/2.0/wss")) { is_wss = 1; - is_nat++; + is_nat = "wss"; if (uparams && (p = switch_stristr("transport=ws", uparams))) { if (p[12] != 's') { @@ -1269,24 +1269,29 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand if (uparams && switch_stristr("transport=tls", uparams)) { is_tls += 1; - is_nat++; + if (sofia_test_pflag(profile, PFLAG_TLS_ALWAYS_NAT)) { + is_nat = "tls"; + } } if (!is_wss && !is_ws && uparams && switch_stristr("transport=ws", uparams)) { - is_nat++; + is_nat = "ws"; is_ws += 1; } if (sip->sip_contact->m_url->url_type == url_sips) { proto = "sips"; is_tls += 2; - is_nat++; + if (sofia_test_pflag(profile, PFLAG_TLS_ALWAYS_NAT)) { + is_nat = "tls"; + } } - if (uparams && switch_stristr("transport=tcp", uparams)) { is_tcp = 1; - is_nat++; + if (sofia_test_pflag(profile, PFLAG_TCP_ALWAYS_NAT)) { + is_nat = "tcp"; + } } display = contact->m_display; @@ -1737,9 +1742,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand switch_safe_free(url); switch_safe_free(contact); - - - if ((is_wss || is_ws || is_tcp || is_tls) && !sofia_private && call_id) { + if ((is_wss || is_ws || (sofia_test_pflag(profile, PFLAG_TCP_UNREG_ON_SOCKET_CLOSE) && (is_tcp || is_tls))) && !sofia_private && call_id) { char key[256] = ""; nua_handle_t *hnh; switch_snprintf(key, sizeof(key), "%s%s%s", call_id, network_ip, network_port_c);