Merge pull request #2279 from kamailio/grumvalski/dlg_briefing_ext
authorFederico Cabiddu <federico.cabiddu@gmail.com>
Thu, 9 Apr 2020 03:14:47 +0000 (05:14 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Apr 2020 03:14:47 +0000 (05:14 +0200)
dialog: add dialog init, start end end timestamps to the output of dl…

.github/CONTRIBUTING.md
src/modules/dispatcher/dispatch.c
src/modules/dispatcher/dispatch.h
src/modules/dispatcher/dispatcher.c
src/modules/dispatcher/doc/dispatcher.xml
src/modules/dispatcher/doc/dispatcher_admin.xml
src/modules/siptrace/README
src/modules/siptrace/doc/siptrace_admin.xml
src/modules/siptrace/siptrace.c
src/modules/siptrace/siptrace_hep.c
src/modules/siptrace/siptrace_send.c

index 1fc1b63..68fa7f5 100644 (file)
@@ -237,8 +237,8 @@ replaced with tokens like a.b.c.d, f.g.h.j).
 Kamailio Main License: *GPLv2*.
 
 Each source code file refers to the license and copyright details in the top
-of the file. Most of the code is licensed under GPLv2, some parts of the code
-are licensed under BSD.
+of the file. Most of the code is licensed under GPLv2 (with the "any later
+version" clause), some parts of the code are licensed under BSD.
 
 ### License Of New Code Contributions ###
 
index b62d4c8..6ded012 100644 (file)
@@ -324,6 +324,9 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
                } else if(pit->name.len == 9
                                && strncasecmp(pit->name.s, "ping_from", 9) == 0) {
                        dest->attrs.ping_from = pit->body;
+               } else if(pit->name.len == 7 
+                                 && strncasecmp(pit->name.s, "obproxy", 7) == 0) {
+                       dest->attrs.obproxy = pit->body;
                }
        }
        if(params_list)
@@ -3295,6 +3298,7 @@ void ds_ping_set(ds_set_t *node)
        uac_req_t uac_r;
        int i, j;
        str ping_from;
+       str obproxy;
 
        if(!node)
                return;
@@ -3342,10 +3346,20 @@ void ds_ping_set(ds_set_t *node)
                                LM_DBG("Default ping_from: %.*s\n", ping_from.len, ping_from.s);
                        }
 
+                       if(node->dlist[j].attrs.obproxy.s != NULL
+                                       && node->dlist[j].attrs.obproxy.len > 0) {
+                               obproxy = node->dlist[j].attrs.obproxy;
+                               LM_DBG("outbound proxy: %.*s\n", obproxy.len, obproxy.s);
+                       }
+                       else {
+                               obproxy = ds_outbound_proxy;
+                               LM_DBG("Default outbound proxy: %.*s\n", ds_outbound_proxy.len, ds_outbound_proxy.s);
+                       }
+
                        gettimeofday(&node->dlist[j].latency_stats.start, NULL);
 
                        if(tmb.t_request(&uac_r, &node->dlist[j].uri, &node->dlist[j].uri,
-                                          &ping_from, &ds_outbound_proxy)
+                                          &ping_from, &obproxy)
                                        < 0) {
                                LM_ERR("unable to ping [%.*s]\n", node->dlist[j].uri.len,
                                                node->dlist[j].uri.s);
index e067d30..6c167a9 100644 (file)
@@ -188,6 +188,7 @@ typedef struct _ds_attrs {
        int rweight;
        int congestion_control;
        str ping_from;
+       str obproxy;
 } ds_attrs_t;
 
 typedef struct _ds_latency_stats {
index 06e96da..6ac01bb 100644 (file)
@@ -1573,7 +1573,7 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle)
                                rpc->fault(ctx, 500, "Internal error creating dest struct");
                                return -1;
                        }
-                       if(rpc->struct_add(wh, "SSdddSS",
+                       if(rpc->struct_add(wh, "SSdddSSS",
                                                "BODY", &(node->dlist[j].attrs.body),
                                                "DUID", (node->dlist[j].attrs.duid.s)
                                                                        ? &(node->dlist[j].attrs.duid) : &data,
@@ -1583,7 +1583,9 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle)
                                                "SOCKET", (node->dlist[j].attrs.socket.s)
                                                                        ? &(node->dlist[j].attrs.socket) : &data,
                                                "SOCKNAME", (node->dlist[j].attrs.sockname.s)
-                                                                       ? &(node->dlist[j].attrs.sockname) : &data)
+                                                                       ? &(node->dlist[j].attrs.sockname) : &data,
+                                               "OBPROXY", (node->dlist[j].attrs.obproxy.s)
+                                                                       ? &(node->dlist[j].attrs.obproxy) : &data)
                                        < 0) {
                                rpc->fault(ctx, 500, "Internal error creating attrs struct");
                                return -1;
index 8502aec..b64151d 100644 (file)
                 <surname>Chavanton</surname>
                 <email>jchavanton@gmail.com</email>
             </editor>
+            <editor>
+                <firstname>Federico</firstname>
+                <surname>Cabiddu</surname>
+                <email>federico.cabiddu@gmail.com</email>
+            </editor>
        </authorgroup>
        <copyright>
            <year>2004</year>
             <year>2017, 2018</year>
             <holder>Julien chavanton, Flowroute</holder>
         </copyright>
+       <copyright>
+        <year>2020</year>
+        <holder>Federico Cabiddu, Libon</holder>
+   </copyright>
    </bookinfo>
     <toc></toc>
     
index ae8102b..30cd6a5 100644 (file)
@@ -1316,6 +1316,7 @@ DEST: {
                RWEIGHT: 50
                SOCKET: 
                SOCKNAME: 
+               OBPROXY: 
        }
        LATENCY: {
                AVG: 20.104000
@@ -2055,6 +2056,10 @@ DEST: {
                                        'ping_from' - used to set the From URI in OPTIONS keepalives.
                                        It overwrites the general ds_ping_from parameter.
                                </listitem>
+                               <listitem>
+                                       'obproxy' - SIP URI of outbound proxy to be used when sending pings.
+                                       It overwrites the general ds_outbound_proxy parameter.
+                               </listitem>
                        </itemizedlist>
                </para>
                </section>
index f1a24c8..d83fdd3 100644 (file)
@@ -55,10 +55,12 @@ Camille Oudot
               3.14. hep_version (integer)
               3.15. hep_capture_id (integer)
               3.16. trace_delayed (integer)
-              3.17. force_send_sock (str)
-              3.18. trace_init_mode (integer)
-              3.19. trace_mode (integer)
-              3.20. auth_key (integer)
+              3.17. send_sock_name (str)
+              3.18. send_sock_addr (str)
+              3.19. force_send_sock (str)
+              3.20. trace_init_mode (integer)
+              3.21. trace_mode (integer)
+              3.22. auth_key (integer)
 
         4. Functions
 
@@ -91,14 +93,15 @@ Camille Oudot
    1.14. Set hep_version parameter
    1.15. Set hep_capture_id parameter
    1.16. Set trace_delayed parameter
-   1.17. Set force_send_sock parameter
-   1.18. Set trace_init_mode parameter
-   1.19. Set trace_mode parameter
-   1.20. Set auth_key parameter
-   1.21. sip_trace() usage
-   1.22. sip_trace_mode() usage
-   1.23. hlog() usage
-   1.24. Send relayed ACK message
+   1.17. Set send_sock_name parameter
+   1.18. Set send_sock_addr parameter
+   1.19. Set trace_init_mode parameter
+   1.20. Set trace_mode parameter
+   1.21. Set auth_key parameter
+   1.22. sip_trace() usage
+   1.23. sip_trace_mode() usage
+   1.24. hlog() usage
+   1.25. Send relayed ACK message
 
 Chapter 1. Admin Guide
 
@@ -128,10 +131,12 @@ Chapter 1. Admin Guide
         3.14. hep_version (integer)
         3.15. hep_capture_id (integer)
         3.16. trace_delayed (integer)
-        3.17. force_send_sock (str)
-        3.18. trace_init_mode (integer)
-        3.19. trace_mode (integer)
-        3.20. auth_key (integer)
+        3.17. send_sock_name (str)
+        3.18. send_sock_addr (str)
+        3.19. force_send_sock (str)
+        3.20. trace_init_mode (integer)
+        3.21. trace_mode (integer)
+        3.22. auth_key (integer)
 
    4. Functions
 
@@ -204,10 +209,12 @@ Chapter 1. Admin Guide
    3.14. hep_version (integer)
    3.15. hep_capture_id (integer)
    3.16. trace_delayed (integer)
-   3.17. force_send_sock (str)
-   3.18. trace_init_mode (integer)
-   3.19. trace_mode (integer)
-   3.20. auth_key (integer)
+   3.17. send_sock_name (str)
+   3.18. send_sock_addr (str)
+   3.19. force_send_sock (str)
+   3.20. trace_init_mode (integer)
+   3.21. trace_mode (integer)
+   3.22. auth_key (integer)
 
 3.1. db_url (str)
 
@@ -426,18 +433,36 @@ modparam("siptrace", "hep_capture_id", 234)
 modparam("siptrace", "trace_delayed", 1)
 ...
 
-3.17. force_send_sock (str)
+3.17. send_sock_name (str)
+
+   The name of the local listen socket from where to send the duplicated
+   traffic via SIP or HEP. In the absence of this parameter Kamailio
+   automatically picks an interface. It has priority over 'send_sock_addr'
+   parameter.
+
+   Example 1.17. Set send_sock_name parameter
+...
+modparam("siptrace", "send_sock_name", "sock1")
+...
+
+3.18. send_sock_addr (str)
 
    The local interface in the form of SIP URI from where to send the
    duplicated traffic. In the absence of this parameter Kamailio
    automatically picks an interface.
 
-   Example 1.17. Set force_send_sock parameter
+   Example 1.18. Set send_sock_addr parameter
 ...
-modparam("siptrace", "force_send_sock", "sip:10.1.1.2:5000")
+modparam("siptrace", "send_sock_addr", "sip:10.1.1.2:5000")
 ...
 
-3.18. trace_init_mode (integer)
+3.19. force_send_sock (str)
+
+   It is the same as 'send_sock_addr' parameter, this being kept for
+   backward compatibility when 'send_sock_name' and 'send_sock_addr' were
+   introduced.
+
+3.20. trace_init_mode (integer)
 
    Control what tracing modes are initialized.
 
@@ -450,12 +475,12 @@ modparam("siptrace", "force_send_sock", "sip:10.1.1.2:5000")
 
    Default value is 0.
 
-   Example 1.18. Set trace_init_mode parameter
+   Example 1.19. Set trace_init_mode parameter
 ...
 modparam("siptrace", "trace_init_mode", 1)
 ...
 
-3.19. trace_mode (integer)
+3.21. trace_mode (integer)
 
    If not set to 0, the module uses core events triggered when receiving
    or sending SIP traffic to store it to database or mirror it to a SIP
@@ -476,7 +501,7 @@ modparam("siptrace", "trace_init_mode", 1)
 
    Default value is 0.
 
-   Example 1.19. Set trace_mode parameter
+   Example 1.20. Set trace_mode parameter
 ...
 modparam("siptrace", "trace_on", 1)
 modparam("siptrace", "trace_mode", 1)
@@ -484,13 +509,13 @@ modparam("siptrace", "trace_mode", 1)
 modparam("siptrace", "trace_mode", 3)
 ...
 
-3.20. auth_key (integer)
+3.22. auth_key (integer)
 
    A string with an authorization key. Supported on HEPv3 only.
 
    Default value is empty.
 
-   Example 1.20. Set auth_key parameter
+   Example 1.21. Set auth_key parameter
 ...
 modparam("siptrace", "auth_key", "spoihepuirthpeuia")
 ...
@@ -523,7 +548,7 @@ modparam("siptrace", "auth_key", "spoihepuirthpeuia")
    ONREPLY_ROUTE, BRANCH_ROUTE.
    Default value is "NULL".
 
-   Example 1.21. sip_trace() usage
+   Example 1.22. sip_trace() usage
 ...
 sip_trace();
 ...
@@ -549,7 +574,7 @@ sip_trace("sip:10.1.1.2:5085", "$ci-abc", "d");
 
    This function can be used in ANY_ROUTE.
 
-   Example 1.22. sip_trace_mode() usage
+   Example 1.23. sip_trace_mode() usage
 ...
 sip_trace_mode("t");
 ...
@@ -566,7 +591,7 @@ sip_trace_mode("t");
      * message - The text to send to Homer as log event. (This parameter
        may contain PVs)
 
-   Example 1.23. hlog() usage
+   Example 1.24. hlog() usage
 ...
 hlog("[cfg:$cfg(line)] This is a log from kamailio to Homer");
 ...
@@ -619,7 +644,7 @@ kamcmd siptrace.status check
    this name will result in overlapping internal avp used by the module
    therefore causing unknown consequences.
 
-   Example 1.24. Send relayed ACK message
+   Example 1.25. Send relayed ACK message
 ...
 onsend_route {
     if (is_method("ACK")) {
index 24e3055..cc6ead1 100644 (file)
@@ -449,22 +449,46 @@ modparam("siptrace", "trace_delayed", 1)
 </programlisting>
                 </example>
         </section>
-       <section id="siptrace.p.force_send_sock">
-                <title><varname>force_send_sock</varname> (str)</title>
+       <section id="siptrace.p.send_sock_name">
+                <title><varname>send_sock_name</varname> (str)</title>
+                <para>
+                       The name of the local listen socket from where to send
+                       the duplicated traffic via SIP or HEP. In the absence of this parameter
+                       &kamailio; automatically picks an interface. It has priority over
+                       'send_sock_addr' parameter.
+                </para>
+                <example>
+                <title>Set <varname>send_sock_name</varname> parameter</title>
+                <programlisting format="linespecific">
+...
+modparam("siptrace", "send_sock_name", "sock1")
+...
+</programlisting>
+                </example>
+        </section>
+       <section id="siptrace.p.send_sock_addr">
+                <title><varname>send_sock_addr</varname> (str)</title>
                 <para>
                        The local interface in the form of SIP URI from where to send
                        the duplicated traffic. In the absence of this parameter
                        &kamailio; automatically picks an interface.
                 </para>
                 <example>
-                <title>Set <varname>force_send_sock</varname> parameter</title>
+                <title>Set <varname>send_sock_addr</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
-modparam("siptrace", "force_send_sock", "sip:10.1.1.2:5000")
+modparam("siptrace", "send_sock_addr", "sip:10.1.1.2:5000")
 ...
 </programlisting>
                 </example>
         </section>
+       <section id="siptrace.p.force_send_sock">
+                <title><varname>force_send_sock</varname> (str)</title>
+                               <para>It is the same as 'send_sock_addr' parameter, this being
+                               kept for backward compatibility when 'send_sock_name' and
+                               'send_sock_addr' were introduced.</para>
+        </section>
+
        <section id="siptrace.p.trace_init_mode">
                 <title><varname>trace_init_mode</varname> (integer)</title>
                                <para>
index c3876c9..dd50837 100644 (file)
@@ -170,7 +170,9 @@ 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;
 
 str trace_dup_uri_str = {0, 0};
 sip_uri_t *trace_dup_uri = 0;
@@ -243,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},
@@ -345,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) {
@@ -365,6 +373,9 @@ static int mod_init(void)
                if(!trace_send_sock_uri->port_no) {
                        trace_send_sock_uri->port_no = SIP_PORT;
                }
+               trace_send_sock_info = grep_sock_info(&trace_send_sock_uri->host,
+                               trace_send_sock_uri->port_no,
+                               trace_send_sock_uri->proto);
        }
 
        if(_siptrace_init_mode==SIPTRACE_INIT_MODE_ALL
@@ -874,16 +885,18 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri,
                        orig_t = tmb.t_gett();
                        if(tmb.t_lookup_request(msg,0,&canceled)) {
                                t_invite = tmb.t_gett();
-                               if (t_invite->uas.request->msg_flags & FL_SIPTRACE) {
-                                       LM_DBG("Transaction is already been traced, skipping.\n");
-                                       ret = 1;
+                               if (t_invite!=T_NULL_CELL) {
+                                       if (t_invite->uas.request->msg_flags & FL_SIPTRACE) {
+                                               LM_DBG("Transaction is already been traced, skipping.\n");
+                                               ret = 1;
+                                       }
+                                       tmb.t_release_transaction( t_invite );
+                                       tmb.t_unref(msg);
                                }
-                               tmb.t_release_transaction( t_invite );
-                               tmb.t_unref(msg);
-                               tmb.t_sett(orig_t, T_BR_UNDEFINED);
-                               if (ret)
-                                       return 1;
                        }
+                       tmb.t_sett(orig_t, T_BR_UNDEFINED);
+                       if (ret)
+                               return 1;
                }
 
                if (trace_type == SIPTRACE_DIALOG && dlgb.get_dlg == NULL) {
index 267edf8..412eb8a 100644 (file)
@@ -43,6 +43,8 @@ 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;
 
@@ -534,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)
@@ -586,17 +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");
-               si = grep_sock_info(&trace_send_sock_uri->host,
-                               trace_send_sock_uri->port_no,
-                               trace_send_sock_uri->proto);
-               if(!si) {
-                       LM_WARN("cannot grep socket 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) {
+                       dst.send_sock = trace_send_sock_info;
                } else {
-                       LM_DBG("found socket while grep: [%.*s] [%.*s]\n", si->name.len,
-                                       si->name.s, si->address_str.len, si->address_str.s);
-                       dst.send_sock = si;
+                       dst.send_sock = grep_sock_info(&trace_send_sock_uri->host,
+                                       trace_send_sock_uri->port_no,
+                                       trace_send_sock_uri->proto);
+               }
+               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",
+                                       dst.send_sock->name.len, dst.send_sock->name.s,
+                                       dst.send_sock->address_str.len, dst.send_sock->address_str.s);
                }
        }
 
index d0694b1..63fdd5c 100644 (file)
@@ -41,7 +41,9 @@ 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;
 
 /**
  *
@@ -314,15 +316,22 @@ 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");
-                       pdst->send_sock = grep_sock_info(&trace_send_sock_uri->host,
-                                       trace_send_sock_uri->port_no,
-                                       trace_send_sock_uri->proto);
+                       if(trace_send_sock_info) {
+                               pdst->send_sock = trace_send_sock_info;
+                       } else {
+                               pdst->send_sock = grep_sock_info(&trace_send_sock_uri->host,
+                                               trace_send_sock_uri->port_no,
+                                               trace_send_sock_uri->proto);
+                       }
                        if(!pdst->send_sock) {
-                               LM_WARN("cannot grep socket info\n");
+                               LM_WARN("local socket not found for: [%.*s]\n",
+                                               trace_send_sock_str.len, trace_send_sock_str.s);
                        } else {
-                               LM_DBG("found socket while grep: [%.*s] [%.*s]\n",
+                               LM_DBG("using local send socket: [%.*s] [%.*s]\n",
                                                pdst->send_sock->name.len,
                                                pdst->send_sock->name.s, pdst->send_sock->address_str.len,
                                                pdst->send_sock->address_str.s);