Browse code

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

Stefan Mititelu authored on 28/02/2020 13:16:42
Showing 4 changed files
... ...
@@ -40,7 +40,8 @@ struct cfg_group_registrar	default_registrar_cfg = {
40 40
 		0,	/* retry_after */
41 41
 		0,	/* case_sensitive */
42 42
 		Q_UNSPECIFIED,	/* default_q */
43
-		1	/* append_branches */
43
+		1,	/* append_branches */
44
+		0	/* use_expired_contacts */
44 45
 	};
45 46
 
46 47
 void	*registrar_cfg = &default_registrar_cfg;
... ...
@@ -68,5 +69,7 @@ cfg_def_t	registrar_cfg_def[] = {
68 69
 		"The parameter represents default q value for new contacts."}, /* Q_UNSPECIFIED is -1 */
69 70
 	{"append_branches",	CFG_VAR_INT ,			0, 0, 0, 0,
70 71
 		"If set to 1(default), lookup will put all contacts found in msg structure"},
72
+	{"use_expired_contacts",CFG_VAR_INT ,			0, 0, 0, 0,
73
+		"Toggles using expired contacts as if they were active."},
71 74
 	{0, 0, 0, 0, 0, 0}
72 75
 };
... ...
@@ -36,6 +36,7 @@ struct cfg_group_registrar {
36 36
 	unsigned int	case_sensitive;
37 37
 	qvalue_t	default_q;
38 38
 	unsigned int	append_branches;
39
+	unsigned int	use_expired_contacts;
39 40
 };
40 41
 
41 42
 extern struct cfg_group_registrar	default_registrar_cfg;
... ...
@@ -304,7 +304,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
304 304
 		ret = -1;
305 305
 		/* look first for an un-expired and suported contact */
306 306
 		while (ptr) {
307
-			if(VALID_CONTACT(ptr,act_time)) {
307
+			if(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) {
308 308
 				if(allowed_method(_m,ptr)) {
309 309
 					/* match on instance, if pub-gruu */
310 310
 					if(inst.len>0) {
... ...
@@ -346,7 +346,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
346 346
 		aor = *ptr->aor;
347 347
 		/* test if not expired and contact with suported method */
348 348
 		if(ptr) {
349
-			if(!(VALID_CONTACT(ptr,act_time))) {
349
+			if(!(VALID_CONTACT(ptr,act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) {
350 350
 				goto done;
351 351
 			} else if(!allowed_method(_m,ptr)) {
352 352
 				ret=-2;
... ...
@@ -485,7 +485,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
485 485
 	if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done;
486 486
 
487 487
 	for( ; ptr ; ptr = ptr->next ) {
488
-		if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)
488
+		if ((VALID_CONTACT(ptr, act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts)) && allowed_method(_m, ptr)
489 489
 				&& reg_lookup_filter_match(ptr)) {
490 490
 			path_dst.len = 0;
491 491
 			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,
847 847
 
848 848
 		get_act_time();
849 849
 		for (ptr = r->contacts; ptr; ptr = ptr->next) {
850
-			if(!VALID_CONTACT(ptr, act_time)) continue;
850
+			if(!(VALID_CONTACT(ptr, act_time) || cfg_get(registrar,registrar_cfg,use_expired_contacts))) continue;
851 851
 			if (match_callid.s && /* optionally enforce tighter matching w/ Call-ID */
852 852
 				match_callid.len > 0 &&
853 853
 				(match_callid.len != ptr->callid.len ||
... ...
@@ -248,6 +248,7 @@ static param_export_t params[] = {
248 248
 	{"event_callback",     PARAM_STR, &reg_event_callback				},
249 249
 	{"lookup_filter_mode", INT_PARAM, &reg_lookup_filter_mode			},
250 250
 	{"min_expires_mode",   PARAM_INT, &reg_min_expires_mode				},
251
+	{"use_expired_contacts",  INT_PARAM, &default_registrar_cfg.use_expired_contacts	 },
251 252
 	{0, 0, 0}
252 253
 };
253 254