From 252d18a032d5c6efbb709b75c0f17cdbd20ac58b Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Fri, 28 Feb 2020 15:16:42 +0200 Subject: [PATCH 1/2] registrar: add use_expired_contacts config param Allow/Disallow the usage of the expired contacts. Useful when some problems happen with new REGISTERs; allow the usage of old REGISTERed contacts. Default value is 0 meaning "disallow the usage of the expired contacts". (no changes to existing behavior) Value can be set dinamically via: kamcmd cfg.set_now_int registrar use_expired_contacts 1 --- src/modules/registrar/config.c | 5 ++++- src/modules/registrar/config.h | 1 + src/modules/registrar/lookup.c | 8 ++++---- src/modules/registrar/registrar.c | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/registrar/config.c b/src/modules/registrar/config.c index 937b9ea736e..8a082072169 100644 --- a/src/modules/registrar/config.c +++ b/src/modules/registrar/config.c @@ -40,7 +40,8 @@ struct cfg_group_registrar default_registrar_cfg = { 0, /* retry_after */ 0, /* case_sensitive */ Q_UNSPECIFIED, /* default_q */ - 1 /* append_branches */ + 1, /* append_branches */ + 0 /* use_expired_contacts */ }; void *registrar_cfg = &default_registrar_cfg; @@ -68,5 +69,7 @@ cfg_def_t registrar_cfg_def[] = { "The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */ {"append_branches", CFG_VAR_INT , 0, 0, 0, 0, "If set to 1(default), lookup will put all contacts found in msg structure"}, + {"use_expired_contacts",CFG_VAR_INT , 0, 0, 0, 0, + "Toggles using expired contacts as if they were active."}, {0, 0, 0, 0, 0, 0} }; diff --git a/src/modules/registrar/config.h b/src/modules/registrar/config.h index a6d1076ec12..43f5606bc23 100644 --- a/src/modules/registrar/config.h +++ b/src/modules/registrar/config.h @@ -36,6 +36,7 @@ struct cfg_group_registrar { unsigned int case_sensitive; qvalue_t default_q; unsigned int append_branches; + unsigned int use_expired_contacts; }; extern struct cfg_group_registrar default_registrar_cfg; diff --git a/src/modules/registrar/lookup.c b/src/modules/registrar/lookup.c index 97dd635b383..81f9b7afd96 100644 --- a/src/modules/registrar/lookup.c +++ b/src/modules/registrar/lookup.c @@ -304,7 +304,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode) ret = -1; /* look first for an un-expired and suported contact */ while (ptr) { - if(VALID_CONTACT(ptr,act_time)) { + if(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) { if(allowed_method(_m,ptr)) { /* match on instance, if pub-gruu */ if(inst.len>0) { @@ -346,7 +346,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode) aor = *ptr->aor; /* test if not expired and contact with suported method */ if(ptr) { - if(!(VALID_CONTACT(ptr,act_time))) { + if(!(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) { goto done; } else if(!allowed_method(_m,ptr)) { ret=-2; @@ -485,7 +485,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode) if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done; for( ; ptr ; ptr = ptr->next ) { - if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr) + if ((VALID_CONTACT(ptr, act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) && allowed_method(_m, ptr) && reg_lookup_filter_match(ptr)) { path_dst.len = 0; if(ptr->path.s && ptr->path.len) { @@ -847,7 +847,7 @@ int registered4(struct sip_msg* _m, udomain_t* _d, str* _uri, int match_flag, get_act_time(); for (ptr = r->contacts; ptr; ptr = ptr->next) { - if(!VALID_CONTACT(ptr, act_time)) continue; + if(!(VALID_CONTACT(ptr, act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) continue; if (match_callid.s && /* optionally enforce tighter matching w/ Call-ID */ match_callid.len > 0 && (match_callid.len != ptr->callid.len || diff --git a/src/modules/registrar/registrar.c b/src/modules/registrar/registrar.c index 7f1aa78bd7c..11ebbdc8b94 100644 --- a/src/modules/registrar/registrar.c +++ b/src/modules/registrar/registrar.c @@ -248,6 +248,7 @@ static param_export_t params[] = { {"event_callback", PARAM_STR, ®_event_callback }, {"lookup_filter_mode", INT_PARAM, ®_lookup_filter_mode }, {"min_expires_mode", PARAM_INT, ®_min_expires_mode }, + {"use_expired_contacts", INT_PARAM, &default_registrar_cfg.use_expired_contacts }, {0, 0, 0} }; From 03289ce36d12d9397b5d9879e75d56b8baac10fa Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Fri, 28 Feb 2020 15:42:33 +0200 Subject: [PATCH 2/2] registrar: update doc for use_expired_contacts --- src/modules/registrar/doc/registrar_admin.xml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/modules/registrar/doc/registrar_admin.xml b/src/modules/registrar/doc/registrar_admin.xml index 4575bbaf9bf..e3140965d43 100644 --- a/src/modules/registrar/doc/registrar_admin.xml +++ b/src/modules/registrar/doc/registrar_admin.xml @@ -1100,6 +1100,46 @@ request_route { + + +
+ <varname>use_expired_contacts</varname> (int) + + + Allow/Disallow the usage of the expired contacts. + + + + + + 0 Disallow the usage of the expired contacts. + + + + + 1 Allow the usage of the expired contacts. + + + + + + + Default value is 0 (Disallow). + + + + + Set <varname>use_expired_contacts</varname> parameter + +... +modparam("registrar", "use_expired_contacts", 1) +... + +kamcmd cfg.set_now_int registrar use_expired_contacts 1 +kamcmd cfg.set_now_int registrar use_expired_contacts 0 + + +