Browse code

usrloc: re-use TCP connections for keepalive

- Fixes GH #3178. Sets TCP connection id for keepalive based on the value in the database
If unset, tcpconn_id will remain 0 and keepalives will work the same as they do today
- Update documentation to clarify when it will use received vs AOR for keepalive

Andy Brezinsky authored on 16/08/2022 16:20:20 • Daniel-Constantin Mierla committed on 17/08/2022 08:33:50
Showing 3 changed files
... ...
@@ -114,6 +114,7 @@ int ul_ka_db_records(int partidx)
114 114
 	keys2[5] = &ul_ruid_col;
115 115
 	keys2[6] = &ul_user_col;
116 116
 	keys2[7] = &ul_domain_col;
117
+	keys2[8] = &ul_con_id_col;
117 118
 
118 119
 	/* where fields */
119 120
 	keys1[0] = &ul_expires_col;
... ...
@@ -256,6 +257,9 @@ int ul_ka_db_records(int partidx)
256 257
 			ur.aorhash = ul_get_aorhash(&ur.aor);
257 258
 			ur.contacts = &uc;
258 259
 
260
+			/* tcpconn_id */
261
+			uc.tcpconn_id = VAL_INT(ROW_VALUES(row)+8);
262
+
259 263
 			ul_ka_urecord(&ur);
260 264
 		} /* row cycle */
261 265
 
... ...
@@ -1317,11 +1317,17 @@ modparam("usrloc", "version_table", 0)
1317 1317
 		contact records stored in memory.
1318 1318
 		</para>
1319 1319
 		<para>
1320
-		Note: it is recommeder to set 'timer_procs' parameter in order to have
1320
+		Note: it is recommended to set 'timer_procs' parameter in order to have
1321 1321
 		dedicated timer processes for usrloc module and off-load the keepalive
1322 1322
 		sending process from the core timers.
1323 1323
 		</para>
1324 1324
 		<para>
1325
+		Note: Keepalives will be sent to the IP and port using the transport
1326
+		defined in the “received” column.  If not set, then keepalives will be sent
1327
+		to the AOR using UDP as a default transport.  If available, the TCP
1328
+		connection will be re-used for WS, TCP and TLS.
1329
+		</para>
1330
+		<para>
1325 1331
 		Default value is <quote>0 (keepalive disabled)</quote>.
1326 1332
 		</para>
1327 1333
 		<example>
... ...
@@ -1780,4 +1786,3 @@ modparam("usrloc", "db_clean_tcp", 1)
1780 1786
 
1781 1787
 
1782 1788
 </chapter>
1783
-
... ...
@@ -200,6 +200,7 @@ int ul_ka_urecord(urecord_t *ur)
200 200
 		}
201 201
 		idst.proto = dproto;
202 202
 		idst.send_sock = ssock;
203
+		idst.id = uc->tcpconn_id;
203 204
 
204 205
 		if(ssock->useinfo.name.len > 0) {
205 206
 			if (ssock->useinfo.address.af == AF_INET6) {
... ...
@@ -270,19 +271,16 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst)
270 271
 #ifdef USE_TCP
271 272
 	else if(kadst->proto == PROTO_WS || kadst->proto == PROTO_WSS) {
272 273
 		/*ws-wss*/
273
-		kadst->id=0;
274 274
 		return wss_send(kadst, kamsg->s, kamsg->len);
275 275
 	}
276 276
 	else if(kadst->proto == PROTO_TCP) {
277 277
 		/*tcp*/
278
-		kadst->id=0;
279 278
 		return tcp_send(kadst, 0, kamsg->s, kamsg->len);
280 279
 	}
281 280
 #endif
282 281
 #ifdef USE_TLS
283 282
 	else if(kadst->proto == PROTO_TLS) {
284 283
 		/*tls*/
285
-		kadst->id=0;
286 284
 		return tcp_send(kadst, 0, kamsg->s, kamsg->len);
287 285
 	}
288 286
 #endif