Browse code

siptrace: send_sock_name - new parameter to specify send socket by name

Daniel-Constantin Mierla authored on 08/04/2020 12:51:46
Showing 3 changed files
... ...
@@ -170,6 +170,7 @@ int trace_xheaders_write = 0;
170 170
 int trace_xheaders_read = 0;
171 171
 
172 172
 str trace_send_sock_str = {0, 0};
173
+str trace_send_sock_name_str = {0, 0};
173 174
 sip_uri_t *trace_send_sock_uri = 0;
174 175
 socket_info_t *trace_send_sock_info = 0;
175 176
 
... ...
@@ -244,6 +245,8 @@ static param_export_t params[] = {
244 245
 	{"xheaders_read", INT_PARAM, &trace_xheaders_read},
245 246
 	{"hep_mode_on", INT_PARAM, &hep_mode_on},
246 247
 	{"force_send_sock", PARAM_STR, &trace_send_sock_str},
248
+	{"send_sock_addr", PARAM_STR, &trace_send_sock_str},
249
+	{"send_sock_name", PARAM_STR, &trace_send_sock_name_str},
247 250
 	{"hep_version", INT_PARAM, &hep_version},
248 251
 	{"hep_capture_id", INT_PARAM, &hep_capture_id},
249 252
 	{"trace_delayed", INT_PARAM, &trace_delayed},
... ...
@@ -346,7 +349,11 @@ static int mod_init(void)
346 349
 		}
347 350
 	}
348 351
 
349
-	if(trace_send_sock_str.s != 0) {
352
+	if(trace_send_sock_name_str.s != 0) {
353
+		trace_send_sock_info = ksr_get_socket_by_name(&trace_send_sock_name_str);
354
+		trace_send_sock_str.s = NULL;
355
+		trace_send_sock_str.len = 0;
356
+	} else if(trace_send_sock_str.s != 0) {
350 357
 		trace_send_sock_str.len = strlen(trace_send_sock_str.s);
351 358
 		trace_send_sock_uri = (sip_uri_t*)pkg_malloc(sizeof(sip_uri_t));
352 359
 		if(trace_send_sock_uri == 0) {
... ...
@@ -43,6 +43,7 @@ extern int hep_vendor_id;
43 43
 extern str hep_auth_key_str;
44 44
 extern str trace_send_sock_str;
45 45
 extern sip_uri_t *trace_send_sock_uri;
46
+extern str trace_send_sock_name_str;
46 47
 extern socket_info_t *trace_send_sock_info;
47 48
 extern str trace_dup_uri_str;
48 49
 extern sip_uri_t *trace_dup_uri;
... ...
@@ -535,7 +536,6 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
535 536
 	struct timezone tz;
536 537
 	struct dest_info dst;
537 538
 	struct proxy_l *p = NULL;
538
-	struct socket_info *si;
539 539
 
540 540
 	if(!correlationid) {
541 541
 		if(msg->callid == NULL && ((parse_headers(msg, HDR_CALLID_F, 0) == -1)
... ...
@@ -587,22 +587,24 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
587 587
 	free_proxy(p); /* frees only p content, not p itself */
588 588
 	pkg_free(p);
589 589
 
590
-	if(trace_send_sock_str.s) {
591
-		LM_DBG("send sock activated, grep for the sock_info\n");
590
+	if(trace_send_sock_name_str.s) {
591
+		dst.send_sock = trace_send_sock_info;
592
+	} else if(trace_send_sock_str.s) {
593
+		LM_DBG("send sock activated - find the sock info\n");
592 594
 		if(trace_send_sock_info) {
593
-			si = trace_send_sock_info;
595
+			dst.send_sock = trace_send_sock_info;
594 596
 		} else {
595
-			si = grep_sock_info(&trace_send_sock_uri->host,
597
+			dst.send_sock = grep_sock_info(&trace_send_sock_uri->host,
596 598
 					trace_send_sock_uri->port_no,
597 599
 					trace_send_sock_uri->proto);
598 600
 		}
599
-		if(!si) {
601
+		if(!dst.send_sock) {
600 602
 			LM_WARN("local socket not found for: [%.*s]\n",
601 603
 					trace_send_sock_str.len, trace_send_sock_str.s);
602 604
 		} else {
603
-			LM_DBG("using local send socket: [%.*s] [%.*s]\n", si->name.len,
604
-					si->name.s, si->address_str.len, si->address_str.s);
605
-			dst.send_sock = si;
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);
606 608
 		}
607 609
 	}
608 610
 
... ...
@@ -41,6 +41,7 @@ extern int trace_xheaders_read;
41 41
 extern str trace_dup_uri_str;
42 42
 extern sip_uri_t *trace_dup_uri;
43 43
 extern str trace_send_sock_str;
44
+extern str trace_send_sock_name_str;
44 45
 extern sip_uri_t *trace_send_sock_uri;
45 46
 extern socket_info_t *trace_send_sock_info;
46 47
 
... ...
@@ -315,7 +316,9 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2)
315 316
 	}
316 317
 
317 318
 	if(pdst->send_sock == NULL) {
318
-		if(trace_send_sock_str.s) {
319
+		if(trace_send_sock_name_str.s) {
320
+			pdst->send_sock = trace_send_sock_info;
321
+		} else if(trace_send_sock_str.s) {
319 322
 			LM_DBG("send sock activated, grep for the sock_info\n");
320 323
 			if(trace_send_sock_info) {
321 324
 				pdst->send_sock = trace_send_sock_info;