[sr-dev] git:5.4:f14111e9: usrloc: do keepalive-based contact expire on internal callback

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 23 17:32:53 CEST 2020


Module: kamailio
Branch: 5.4
Commit: f14111e9ba0139e79a2bf7b7c0c5bc98c47cf220
URL: https://github.com/kamailio/kamailio/commit/f14111e9ba0139e79a2bf7b7c0c5bc98c47cf220

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-09-23T17:32:10+02:00

usrloc: do keepalive-based contact expire on internal callback

- the one used by nathelper is not triggered automatically

(cherry picked from commit 5c1e07dc2efc46fe078263c76ce0388f09949539)

---

Modified: src/modules/usrloc/ul_keepalive.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f14111e9ba0139e79a2bf7b7c0c5bc98c47cf220.diff
Patch: https://github.com/kamailio/kamailio/commit/f14111e9ba0139e79a2bf7b7c0c5bc98c47cf220.patch

---

diff --git a/src/modules/usrloc/ul_keepalive.c b/src/modules/usrloc/ul_keepalive.c
index 6d93717db5..105e32a2cf 100644
--- a/src/modules/usrloc/ul_keepalive.c
+++ b/src/modules/usrloc/ul_keepalive.c
@@ -40,6 +40,8 @@
 
 #include "ul_keepalive.h"
 
+extern int ul_keepalive_timeout;
+
 static int ul_ka_send(str *kamsg, dest_info_t *kadst);
 
 /**
@@ -102,11 +104,13 @@ int ul_ka_urecord(urecord_t *ur)
 	int aortype = 0;
 	int i;
 	struct timeval tv;
+	time_t tnow = 0;
 
 	if (ul_ka_mode == ULKA_NONE) {
 		return 0;
 	}
 	LM_DBG("keepalive for aor: %.*s\n", ur->aor.len, ur->aor.s);
+	tnow = time(NULL);
 
 	for(i=0; i<ur->aor.len; i++) {
 		if(ur->aor.s[i] == '@') {
@@ -122,6 +126,18 @@ int ul_ka_urecord(urecord_t *ur)
 		if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
 			continue;
 		}
+		if(ul_keepalive_timeout>0 && uc->last_keepalive>0) {
+			if(uc->last_keepalive+ul_keepalive_timeout < tnow) {
+				/* set contact as expired in 10s */
+				LM_DBG("set expired contact on keepalive - aor: %.*s c: %.*s\n",
+						ur->aor.len, ur->aor.s, uc->c.len, uc->c.s);
+				if(uc->expires > tnow + 10) {
+					uc->expires = tnow + 10;
+					continue;
+				}
+			}
+		}
+
 		if(ul_ka_mode & ULKA_NAT) {
 			/* keepalive for natted contacts only */
 			if (ul_nat_bflag == 0) {




More information about the sr-dev mailing list