From bd72cd9cc1d7d2769b369c666383f6967738ccc2 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Thu, 20 Feb 2014 15:59:38 +0000 Subject: [PATCH] Allow setting late margin on register expirations When an endpoint registers to us we internally mark the expiration as some seconds longer than the actual registration. Previously this value was fixed at 60 seconds. Some people need this value to be shorter so they can meet their SLA by taking a different action when a device doesn't re-register when expected. This commit adds a SIP profile parameter sip-expires-late-margin which allows setting the margin value we apply here. FS-6101 --resolve Thanks-to: Emmanuel Schmidbauer --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 8 ++++++++ src/mod/endpoints/mod_sofia/sofia_reg.c | 10 +++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 966301001d..b600822bd3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -685,6 +685,7 @@ struct sofia_profile { su_strlst_t *tls_verify_in_subjects; uint32_t sip_force_expires; uint32_t sip_expires_max_deviation; + uint32_t sip_expires_late_margin; uint32_t sip_subscription_max_deviation; int ireg_seconds; sofia_paid_type_t paid_type; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 499c718a85..a3db892176 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3765,6 +3765,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) profile->rtp_digit_delay = 40; profile->sip_force_expires = 0; profile->sip_expires_max_deviation = 0; + profile->sip_expires_late_margin = 60; profile->sip_subscription_max_deviation = 0; profile->tls_ciphers = "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"; profile->tls_version = SOFIA_TLS_VERSION_TLSv1; @@ -4769,6 +4770,13 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_OPTIONS_RESPOND_503_ON_BUSY); } + } else if (!strcasecmp(var, "sip-expires-late-margin")) { + int32_t sip_expires_late_margin = atoi(val); + if (sip_expires_late_margin >= 0) { + profile->sip_expires_late_margin = sip_expires_late_margin; + } else { + profile->sip_expires_late_margin = 60; + } } else if (!strcasecmp(var, "sip-force-expires")) { int32_t sip_force_expires = atoi(val); if (sip_force_expires >= 0) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index a4048767c8..5f600aca00 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -1731,7 +1731,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand contact = sofia_glue_get_url_from_contact(contact_str, 1); url = switch_mprintf("sofia/%q/%s:%q", profile->name, proto, sofia_glue_strip_proto(contact)); - switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + 60, + switch_core_add_registration(to_user, reg_host, call_id, url, (long) reg_time + (long) exptime + profile->sip_expires_late_margin, network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta); switch_safe_free(url); @@ -1777,7 +1777,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand "mwi_user,mwi_host, orig_server_host, orig_hostname, sub_host) " "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q','%q','%q','%q','%q','%q','%q','%q')", call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : "", - contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + 60, + contact_str, reg_desc, rpid, (long) reg_time + (long) exptime + profile->sip_expires_late_margin, agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c, username, realm, mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname, sub_host); } else { @@ -1789,7 +1789,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand call_id, sub_host, network_ip, network_port_c, profile->presence_hosts ? profile->presence_hosts : "", guess_ip4, guess_ip4, mod_sofia_globals.hostname, mod_sofia_globals.hostname, - (long) reg_time + (long) exptime + 60, + (long) reg_time + (long) exptime + profile->sip_expires_late_margin, to_user, username, reg_host, contact_str); } @@ -1808,9 +1808,9 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand if (multi_reg) { if (multi_reg_contact) { - sql = switch_mprintf("delete from sip_registrations where contact='%q' and expires!=%ld", contact_str, (long) reg_time + (long) exptime + 60); + sql = switch_mprintf("delete from sip_registrations where contact='%q' and expires!=%ld", contact_str, (long) reg_time + (long) exptime + profile->sip_expires_late_margin); } else { - sql = switch_mprintf("delete from sip_registrations where call_id='%q' and expires!=%ld", call_id, (long) reg_time + (long) exptime + 60); + sql = switch_mprintf("delete from sip_registrations where call_id='%q' and expires!=%ld", call_id, (long) reg_time + (long) exptime + profile->sip_expires_late_margin); } sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);