Browse code

usrloc: do keepalive mode checks before expire processing

(cherry picked from commit e67b588434a08c828548c79b6cc5f4c2a7240dc9)

Daniel-Constantin Mierla authored on 23/09/2020 15:31:04
Showing 1 changed files
... ...
@@ -126,10 +126,22 @@ int ul_ka_urecord(urecord_t *ur)
126 126
 		if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
127 127
 			continue;
128 128
 		}
129
+		if(ul_ka_mode & ULKA_NAT) {
130
+			/* keepalive for natted contacts only */
131
+			if (ul_nat_bflag == 0) {
132
+				continue;
133
+			}
134
+			if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
135
+				continue;
136
+			}
137
+		}
138
+
129 139
 		if(ul_keepalive_timeout>0 && uc->last_keepalive>0) {
130 140
 			if(uc->last_keepalive+ul_keepalive_timeout < tnow) {
131 141
 				/* set contact as expired in 10s */
132
-				LM_DBG("set expired contact on keepalive - aor: %.*s c: %.*s\n",
142
+				LM_DBG("set expired contact on keepalive (%u + %u < %u)"
143
+						" - aor: %.*s c: %.*s\n", (unsigned int)uc->last_keepalive,
144
+						(unsigned int)ul_keepalive_timeout, (unsigned int)tnow,
133 145
 						ur->aor.len, ur->aor.s, uc->c.len, uc->c.s);
134 146
 				if(uc->expires > tnow + 10) {
135 147
 					uc->expires = tnow + 10;
... ...
@@ -137,16 +149,6 @@ int ul_ka_urecord(urecord_t *ur)
137 149
 				}
138 150
 			}
139 151
 		}
140
-
141
-		if(ul_ka_mode & ULKA_NAT) {
142
-			/* keepalive for natted contacts only */
143
-			if (ul_nat_bflag == 0) {
144
-				continue;
145
-			}
146
-			if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
147
-				continue;
148
-			}
149
-		}
150 152
 		if(uc->received.len > 0) {
151 153
 			sdst = uc->received;
152 154
 		} else {