From 79b1e1f50cd7e4e48f8e781f09a81ca0c1f8474a Mon Sep 17 00:00:00 2001 From: Alfonso Pinto Date: Tue, 13 Feb 2024 13:22:35 +0100 Subject: [PATCH] TEL-5929: Improve race condition between REGISTER/INVITE (#255) Set GW as SOFIA_GATEWAY_UP as soon as 200 OK is received for REGISTER Add new REG CPS for shutdown --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 6 ++++-- src/mod/endpoints/mod_sofia/sofia_reg.c | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 66d5d65d201..1bf5b82bda4 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -733,6 +733,7 @@ struct sofia_profile { sofia_gateway_t *gateways; sofia_gateway_t *next_check_gateway_ptr; unsigned int gateway_reg_max_cps; + unsigned int gateway_shutdown_reg_max_cps; unsigned int gateway_unreg_max_yield_ms; //su_home_t *home; switch_hash_t *chat_hash; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c4954ce22ee..102debe37ad 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3672,7 +3672,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void /* Mark all gateways as deleted and set REG_STATE_UNREGISTER state on REG gateways */ sofia_glue_del_every_gateway(profile); /* This prevent doing batch request for reg check */ - profile->gateway_reg_max_cps = 0; + profile->gateway_reg_max_cps = profile->gateway_shutdown_reg_max_cps; /* First call will unregister and set state to DOWN so a gateway is ready for deletion */ sofia_reg_check_gateway(profile, switch_epoch_time_now(NULL)); sofia_sub_check_gateway(profile, switch_epoch_time_now(NULL)); @@ -3981,7 +3981,7 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag, switch_mutex_lock(mod_sofia_globals.hash_mutex); if ((gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, name)) && (gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, pkey)) && !gp->deleted) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", name); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", name); switch_mutex_unlock(mod_sofia_globals.hash_mutex); free(pkey); goto skip; @@ -5860,6 +5860,8 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->max_auth_validity = atoi(val); } else if (!strcasecmp(var, "gateway-reg-max-cps")) { profile->gateway_reg_max_cps = atoi(val); + } else if (!strcasecmp(var, "gateway-shutdown-reg-max-cps")) { + profile->gateway_shutdown_reg_max_cps = atoi(val); } else if (!strcasecmp(var, "auth-require-user")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_AUTH_REQUIRE_USER); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 87f7fac5229..4afa70e7931 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -2747,6 +2747,10 @@ void sofia_reg_handle_sip_r_register(int status, if (!sofia_test_flag(gateway, REG_FLAG_REGISTERED)) { sofia_set_flag(gateway, REG_FLAG_REGISTERED); } + if (gateway->status != SOFIA_GATEWAY_UP) { + gateway->status = SOFIA_GATEWAY_UP; + gateway->uptime = switch_time_now(); + } gateway->state = REG_STATE_REGISTER; break; case 100: