Browse code

siptrace: use socket name for hep mirroring

- manual backport of 89fa86703adfdf6e30dc43c191d7327800270574

(cherry picked from commit 67ffd91e4c0f44b09a472dba2e71b059ce9580a7)

Daniel-Constantin Mierla authored on 15/09/2022 10:54:15
Showing 1 changed files
... ...
@@ -187,15 +187,29 @@ int trace_send_hep3_duplicate(str *body, str *from, str *to,
187 187
 		dst_fin = dst2;
188 188
 	}
189 189
 
190
-	if(trace_send_sock_str.s) {
191
-		LM_DBG("send sock activated, grep for the sock_info\n");
192
-		si = grep_sock_info(&trace_send_sock_uri->host,
193
-				trace_send_sock_uri->port_no,
194
-				trace_send_sock_uri->proto);
190
+	si = NULL;
191
+	if(trace_send_sock_name_str.s) {
192
+		LM_DBG("send sock name activated - find the sock info\n");
193
+		if(trace_send_sock_info) {
194
+			si = trace_send_sock_info;
195
+		} else {
196
+			si = ksr_get_socket_by_name(&trace_send_sock_name_str);
197
+		}
198
+	} else if(trace_send_sock_str.s) {
199
+		LM_DBG("send sock addr activated - find the sock_info\n");
200
+		if(trace_send_sock_info) {
201
+			si = trace_send_sock_info;
202
+		} else {
203
+			si = grep_sock_info(&trace_send_sock_uri->host,
204
+					trace_send_sock_uri->port_no,
205
+					trace_send_sock_uri->proto);
206
+		}
207
+	}
208
+	if(trace_send_sock_name_str.s || trace_send_sock_str.s) {
195 209
 		if(!si) {
196
-			LM_WARN("cannot grep socket info\n");
210
+			LM_WARN("cannot find send socket info\n");
197 211
 		} else {
198
-			LM_DBG("found socket while grep: [%.*s] [%.*s]\n", si->name.len,
212
+			LM_DBG("found send socket: [%.*s] [%.*s]\n", si->name.len,
199 213
 					si->name.s, si->address_str.len, si->address_str.s);
200 214
 			dst_fin->send_sock = si;
201 215
 		}
... ...
@@ -304,15 +318,29 @@ int trace_send_hep2_duplicate(
304 318
 		dst_fin = dst2;
305 319
 	}
306 320
 
307
-	if(trace_send_sock_str.s) {
308
-		LM_DBG("send sock activated, grep for the sock_info\n");
309
-		si = grep_sock_info(&trace_send_sock_uri->host,
310
-				trace_send_sock_uri->port_no,
311
-				trace_send_sock_uri->proto);
321
+	si = NULL;
322
+	if(trace_send_sock_name_str.s) {
323
+		LM_DBG("send sock name activated - find the sock info\n");
324
+		if(trace_send_sock_info) {
325
+			si = trace_send_sock_info;
326
+		} else {
327
+			si = ksr_get_socket_by_name(&trace_send_sock_name_str);
328
+		}
329
+	} else if(trace_send_sock_str.s) {
330
+		LM_DBG("send sock addr activated - find the sock info\n");
331
+		if(trace_send_sock_info) {
332
+			si = trace_send_sock_info;
333
+		} else {
334
+			si = grep_sock_info(&trace_send_sock_uri->host,
335
+					trace_send_sock_uri->port_no,
336
+					trace_send_sock_uri->proto);
337
+		}
338
+	}
339
+	if(trace_send_sock_name_str.s || trace_send_sock_str.s) {
312 340
 		if(!si) {
313
-			LM_WARN("cannot grep socket info\n");
341
+			LM_WARN("cannot find send socket info\n");
314 342
 		} else {
315
-			LM_DBG("found socket while grep: [%.*s] [%.*s]\n", si->name.len,
343
+			LM_DBG("found send socket: [%.*s] [%.*s]\n", si->name.len,
316 344
 					si->name.s, si->address_str.len, si->address_str.s);
317 345
 			dst_fin->send_sock = si;
318 346
 		}
... ...
@@ -536,6 +564,7 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
536 564
 	struct timezone tz;
537 565
 	struct dest_info dst;
538 566
 	struct proxy_l *p = NULL;
567
+	struct socket_info *si;
539 568
 
540 569
 	if(!correlationid) {
541 570
 		if(msg->callid == NULL && ((parse_headers(msg, HDR_CALLID_F, 0) == -1)
... ...
@@ -587,24 +616,31 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
587 616
 	free_proxy(p); /* frees only p content, not p itself */
588 617
 	pkg_free(p);
589 618
 
619
+	si = NULL;
590 620
 	if(trace_send_sock_name_str.s) {
591
-		dst.send_sock = trace_send_sock_info;
621
+		LM_DBG("send sock name activated - find the sock info\n");
622
+		if(trace_send_sock_info) {
623
+			si = trace_send_sock_info;
624
+		} else {
625
+			si = ksr_get_socket_by_name(&trace_send_sock_name_str);
626
+		}
592 627
 	} else if(trace_send_sock_str.s) {
593
-		LM_DBG("send sock activated - find the sock info\n");
628
+		LM_DBG("send sock addr activated - find the sock info\n");
594 629
 		if(trace_send_sock_info) {
595
-			dst.send_sock = trace_send_sock_info;
630
+			si = trace_send_sock_info;
596 631
 		} else {
597
-			dst.send_sock = grep_sock_info(&trace_send_sock_uri->host,
632
+			si = grep_sock_info(&trace_send_sock_uri->host,
598 633
 					trace_send_sock_uri->port_no,
599 634
 					trace_send_sock_uri->proto);
600 635
 		}
601
-		if(!dst.send_sock) {
602
-			LM_WARN("local socket not found for: [%.*s]\n",
603
-					trace_send_sock_str.len, trace_send_sock_str.s);
636
+	}
637
+	if(trace_send_sock_name_str.s || trace_send_sock_str.s) {
638
+		if(!si) {
639
+			LM_WARN("cannot find send socket info\n");
604 640
 		} else {
605
-			LM_DBG("using local send socket: [%.*s] [%.*s]\n",
606
-					dst.send_sock->name.len, dst.send_sock->name.s,
607
-					dst.send_sock->address_str.len, dst.send_sock->address_str.s);
641
+			LM_DBG("found send socket: [%.*s] [%.*s]\n", si->name.len,
642
+					si->name.s, si->address_str.len, si->address_str.s);
643
+			dst.send_sock = si;
608 644
 		}
609 645
 	}
610 646