usrloc: do keepalive mode checks before expire processing
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 23 Sep 2020 15:31:04 +0000 (17:31 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 23 Sep 2020 15:32:17 +0000 (17:32 +0200)
(cherry picked from commit e67b588434a08c828548c79b6cc5f4c2a7240dc9)

src/modules/usrloc/ul_keepalive.c

index 105e32a..a1070f3 100644 (file)
@@ -126,10 +126,22 @@ int ul_ka_urecord(urecord_t *ur)
                if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
                        continue;
                }
+               if(ul_ka_mode & ULKA_NAT) {
+                       /* keepalive for natted contacts only */
+                       if (ul_nat_bflag == 0) {
+                               continue;
+                       }
+                       if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
+                               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",
+                               LM_DBG("set expired contact on keepalive (%u + %u < %u)"
+                                               " - aor: %.*s c: %.*s\n", (unsigned int)uc->last_keepalive,
+                                               (unsigned int)ul_keepalive_timeout, (unsigned int)tnow,
                                                ur->aor.len, ur->aor.s, uc->c.len, uc->c.s);
                                if(uc->expires > tnow + 10) {
                                        uc->expires = tnow + 10;
@@ -137,16 +149,6 @@ int ul_ka_urecord(urecord_t *ur)
                                }
                        }
                }
-
-               if(ul_ka_mode & ULKA_NAT) {
-                       /* keepalive for natted contacts only */
-                       if (ul_nat_bflag == 0) {
-                               continue;
-                       }
-                       if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
-                               continue;
-                       }
-               }
                if(uc->received.len > 0) {
                        sdst = uc->received;
                } else {