diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 6a9e4ce620..6978e34ffc 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -414,6 +414,7 @@ struct sofia_gateway { time_t expires; time_t retry; time_t ping; + time_t reg_timeout; int pinging; sofia_gateway_status_t status; uint32_t ping_freq; @@ -422,6 +423,7 @@ struct sofia_gateway { int ping_min; uint8_t flags[REG_FLAG_MAX]; int32_t retry_seconds; + int32_t reg_timeout_seconds; int32_t failure_status; reg_state_t state; switch_memory_pool_t *pool; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ac1251daa9..c29c35185f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1874,6 +1874,7 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) *context = profile->context, *expire_seconds = "3600", *retry_seconds = "30", + *timeout_seconds = "60", *from_user = "", *from_domain = NULL, *outbound_proxy = NULL, *register_proxy = NULL, *contact_host = NULL, *contact_params = NULL, *params = NULL, *register_transport = NULL; @@ -1982,6 +1983,8 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) expire_seconds = val; } else if (!strcmp(var, "retry-seconds")) { retry_seconds = val; + } else if (!strcmp(var, "timeout-seconds")) { + timeout_seconds = val; } else if (!strcmp(var, "retry_seconds")) { // support typo for back compat retry_seconds = val; } else if (!strcmp(var, "from-user")) { @@ -2081,13 +2084,22 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) } gateway->retry_seconds = atoi(retry_seconds); - + if (gateway->retry_seconds < 5) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid retry-seconds of %d on gateway %s, using the value of 30 instead.\n", gateway->retry_seconds, name); gateway->retry_seconds = 30; } + gateway->reg_timeout_seconds = atoi(timeout_seconds); + + if (gateway->retry_seconds < 5) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid timeout-seconds of %d on gateway %s, using the value of 60 instead.\n", + gateway->reg_timeout_seconds, name); + gateway->reg_timeout_seconds = 30; + } + + gateway->register_scheme = switch_core_strdup(gateway->pool, scheme); gateway->register_context = switch_core_strdup(gateway->pool, context); gateway->register_realm = switch_core_strdup(gateway->pool, realm); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 2614bd6e15..67641ae616 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -363,7 +363,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) NUTAG_REGISTRAR(gateway_ptr->register_proxy), NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL()); } - gateway_ptr->retry = now + gateway_ptr->retry_seconds; + gateway_ptr->reg_timeout = now + gateway_ptr->reg_timeout_seconds; gateway_ptr->state = REG_STATE_TRYING; switch_safe_free(user_via); user_via = NULL; @@ -408,7 +408,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now) } break; case REG_STATE_TRYING: - if (!gateway_ptr->retry || now >= gateway_ptr->retry) { + if (now >= gateway_ptr->reg_timeout) { gateway_ptr->state = REG_STATE_TIMEOUT; } break;