siptrace: send_sock_name - new parameter to specify send socket by name
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 8 Apr 2020 12:51:46 +0000 (14:51 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 8 Apr 2020 12:59:09 +0000 (14:59 +0200)
src/modules/siptrace/siptrace.c
src/modules/siptrace/siptrace_hep.c
src/modules/siptrace/siptrace_send.c

index 1b8613a..5a8d153 100644 (file)
@@ -170,6 +170,7 @@ int trace_xheaders_write = 0;
 int trace_xheaders_read = 0;
 
 str trace_send_sock_str = {0, 0};
+str trace_send_sock_name_str = {0, 0};
 sip_uri_t *trace_send_sock_uri = 0;
 socket_info_t *trace_send_sock_info = 0;
 
@@ -244,6 +245,8 @@ static param_export_t params[] = {
        {"xheaders_read", INT_PARAM, &trace_xheaders_read},
        {"hep_mode_on", INT_PARAM, &hep_mode_on},
        {"force_send_sock", PARAM_STR, &trace_send_sock_str},
+       {"send_sock_addr", PARAM_STR, &trace_send_sock_str},
+       {"send_sock_name", PARAM_STR, &trace_send_sock_name_str},
        {"hep_version", INT_PARAM, &hep_version},
        {"hep_capture_id", INT_PARAM, &hep_capture_id},
        {"trace_delayed", INT_PARAM, &trace_delayed},
@@ -346,7 +349,11 @@ static int mod_init(void)
                }
        }
 
-       if(trace_send_sock_str.s != 0) {
+       if(trace_send_sock_name_str.s != 0) {
+               trace_send_sock_info = ksr_get_socket_by_name(&trace_send_sock_name_str);
+               trace_send_sock_str.s = NULL;
+               trace_send_sock_str.len = 0;
+       } else if(trace_send_sock_str.s != 0) {
                trace_send_sock_str.len = strlen(trace_send_sock_str.s);
                trace_send_sock_uri = (sip_uri_t*)pkg_malloc(sizeof(sip_uri_t));
                if(trace_send_sock_uri == 0) {
index dbd3661..412eb8a 100644 (file)
@@ -43,6 +43,7 @@ extern int hep_vendor_id;
 extern str hep_auth_key_str;
 extern str trace_send_sock_str;
 extern sip_uri_t *trace_send_sock_uri;
+extern str trace_send_sock_name_str;
 extern socket_info_t *trace_send_sock_info;
 extern str trace_dup_uri_str;
 extern sip_uri_t *trace_dup_uri;
@@ -535,7 +536,6 @@ int hlog(struct sip_msg *msg, str *correlationid, str *message)
        struct timezone tz;
        struct dest_info dst;
        struct proxy_l *p = NULL;
-       struct socket_info *si;
 
        if(!correlationid) {
                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)
        free_proxy(p); /* frees only p content, not p itself */
        pkg_free(p);
 
-       if(trace_send_sock_str.s) {
-               LM_DBG("send sock activated, grep for the sock_info\n");
+       if(trace_send_sock_name_str.s) {
+               dst.send_sock = trace_send_sock_info;
+       } else if(trace_send_sock_str.s) {
+               LM_DBG("send sock activated - find the sock info\n");
                if(trace_send_sock_info) {
-                       si = trace_send_sock_info;
+                       dst.send_sock = trace_send_sock_info;
                } else {
-                       si = grep_sock_info(&trace_send_sock_uri->host,
+                       dst.send_sock = grep_sock_info(&trace_send_sock_uri->host,
                                        trace_send_sock_uri->port_no,
                                        trace_send_sock_uri->proto);
                }
-               if(!si) {
+               if(!dst.send_sock) {
                        LM_WARN("local socket not found for: [%.*s]\n",
                                        trace_send_sock_str.len, trace_send_sock_str.s);
                } else {
-                       LM_DBG("using local send socket: [%.*s] [%.*s]\n", si->name.len,
-                                       si->name.s, si->address_str.len, si->address_str.s);
-                       dst.send_sock = si;
+                       LM_DBG("using local send socket: [%.*s] [%.*s]\n",
+                                       dst.send_sock->name.len, dst.send_sock->name.s,
+                                       dst.send_sock->address_str.len, dst.send_sock->address_str.s);
                }
        }
 
index 8c10bd5..63fdd5c 100644 (file)
@@ -41,6 +41,7 @@ extern int trace_xheaders_read;
 extern str trace_dup_uri_str;
 extern sip_uri_t *trace_dup_uri;
 extern str trace_send_sock_str;
+extern str trace_send_sock_name_str;
 extern sip_uri_t *trace_send_sock_uri;
 extern socket_info_t *trace_send_sock_info;
 
@@ -315,7 +316,9 @@ int trace_send_duplicate(char *buf, int len, dest_info_t *dst2)
        }
 
        if(pdst->send_sock == NULL) {
-               if(trace_send_sock_str.s) {
+               if(trace_send_sock_name_str.s) {
+                       pdst->send_sock = trace_send_sock_info;
+               } else if(trace_send_sock_str.s) {
                        LM_DBG("send sock activated, grep for the sock_info\n");
                        if(trace_send_sock_info) {
                                pdst->send_sock = trace_send_sock_info;