[sr-dev] git:master: siptrace: added force_send_sock

Lucian Balaceanu lucian.balaceanu at 1and1.ro
Mon Aug 11 13:12:30 CEST 2014


Module: sip-router
Branch: master
Commit: 651fd496f106792558c3d28f60a3d5ac3f834042
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=651fd496f106792558c3d28f60a3d5ac3f834042

Author: lucian balanceanu <lucian.balanceanu at 1and1.ro>
Committer: lucian balanceanu <lucian.balanceanu at 1and1.ro>
Date:   Mon Aug 11 14:09:57 2014 +0300

siptrace: added force_send_sock

- the local interface in form of SIP uri from where to send
  the duplicated traffic. In the absence of this parameter
  kamailio automatically picks an interface.

  Credit goes to the 1&1 team.

---

 modules/siptrace/README                 |   19 +++++++++++++-
 modules/siptrace/doc/siptrace_admin.xml |   18 +++++++++++++-
 modules/siptrace/siptrace.c             |   40 +++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/modules/siptrace/README b/modules/siptrace/README
index 0f00005..66f398a 100644
--- a/modules/siptrace/README
+++ b/modules/siptrace/README
@@ -49,6 +49,7 @@ Daniel-Constantin Mierla
               3.14. hep_version (integer)
               3.15. hep_capture_id (integer)
               3.16. trace_delayed (integer)
+              3.17. force_send_sock (str)
 
         4. Functions
 
@@ -83,7 +84,8 @@ Daniel-Constantin Mierla
    1.14. Set hep_version parameter
    1.15. Set hep_capture_id parameter
    1.16. Set trace_delayed parameter
-   1.17. sip_trace() usage
+   1.17. Set force_send_sock parameter
+   1.18. sip_trace() usage
 
 Chapter 1. Admin Guide
 
@@ -113,6 +115,7 @@ 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)
 
    4. Functions
 
@@ -186,6 +189,7 @@ 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.1. db_url (str)
 
@@ -404,6 +408,17 @@ modparam("siptrace", "hep_capture_id", 234)
 modparam("siptrace", "trace_delayed", 1)
 ...
 
+3.17. force_send_sock (str)
+
+   The local interface in 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
+...
+modparam("siptrace", "force_send_sock", "sip:10.1.1.2:5000")
+...
+
 4. Functions
 
    4.1. sip_trace([address])
@@ -422,7 +437,7 @@ modparam("siptrace", "trace_delayed", 1)
    ONREPLY_ROUTE, BRANCH_ROUTE.
    Default value is "NULL".
 
-   Example 1.17. sip_trace() usage
+   Example 1.18. sip_trace() usage
 ...
 sip_trace();
 ...
diff --git a/modules/siptrace/doc/siptrace_admin.xml b/modules/siptrace/doc/siptrace_admin.xml
index e35a5cb..e318b39 100644
--- a/modules/siptrace/doc/siptrace_admin.xml
+++ b/modules/siptrace/doc/siptrace_admin.xml
@@ -450,7 +450,23 @@ modparam("siptrace", "trace_delayed", 1)
 </programlisting>
                 </example>
         </section>
-
+<section>
+                <title><varname>force_send_sock</varname> (str)</title>
+                <para>
+				The local interface in 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>
+                <programlisting format="linespecific">
+...
+modparam("siptrace", "force_send_sock", "sip:10.1.1.2:5000")
+...
+</programlisting>
+                </example>
+        </section>
 	</section>
 	
 	<section>
diff --git a/modules/siptrace/siptrace.c b/modules/siptrace/siptrace.c
index 7fc43a4..6378293 100644
--- a/modules/siptrace/siptrace.c
+++ b/modules/siptrace/siptrace.c
@@ -141,6 +141,9 @@ int hep_capture_id = 1;
 int xheaders_write = 0;
 int xheaders_read = 0;
 
+str force_send_sock_str = {0, 0};
+struct sip_uri * force_send_sock_uri = 0;
+
 str    dup_uri_str      = {0, 0};
 struct sip_uri *dup_uri = 0;
 
@@ -202,6 +205,7 @@ static param_export_t params[] = {
 	{"xheaders_write",     INT_PARAM, &xheaders_write       },
 	{"xheaders_read",      INT_PARAM, &xheaders_read        },
 	{"hep_mode_on",        INT_PARAM, &hep_mode_on          },	 
+    {"force_send_sock",    PARAM_STR, &force_send_sock_str	},
 	{"hep_version",        INT_PARAM, &hep_version          },
 	{"hep_capture_id",     INT_PARAM, &hep_capture_id       },	        
 	{"trace_delayed",      INT_PARAM, &trace_delayed        },
@@ -290,6 +294,11 @@ static int mod_init(void)
 
 	*trace_to_database_flag = trace_to_database;
 
+	if(hep_version != 1 && hep_version != 2) {
+	    LM_ERR("unsupported version of HEP");
+	    return -1;
+	}
+
 	/* Find a database module if needed */
 	if(trace_to_database_flag!=NULL && *trace_to_database_flag!=0) {
 		if (db_bind_mod(&db_url, &db_funcs))
@@ -378,6 +387,23 @@ static int mod_init(void)
 		}
 	}
 
+	if(force_send_sock_str.s!=0)
+	{
+	    force_send_sock_str.len = strlen(force_send_sock_str.s);
+	    force_send_sock_uri = (struct sip_uri *)pkg_malloc(sizeof(struct sip_uri));
+	    if(force_send_sock_uri==0)
+	    {
+	        LM_ERR("no more pkg memory left\n");
+	        return -1;
+	    }
+	    memset(force_send_sock_uri, 0, sizeof(struct sip_uri));
+	    if(parse_uri(force_send_sock_str.s, force_send_sock_str.len, force_send_sock_uri)<0)
+	    {
+	        LM_ERR("bad dup uri\n");
+	        return -1;
+	    }
+	}
+
 	if(traced_user_avp_str.s && traced_user_avp_str.len > 0)
 	{
 		if (pv_parse_spec(&traced_user_avp_str, &avp_spec)==0
@@ -1564,6 +1590,7 @@ error:
 static int trace_send_hep_duplicate(str *body, str *from, str *to, struct dest_info * dst2)
 {
 	struct dest_info dst;
+	struct socket_info *si;
 	struct dest_info* dst_fin = NULL;
 	struct proxy_l * p=NULL /* make gcc happy */;
 	void* buffer = NULL;
@@ -1628,6 +1655,19 @@ static int trace_send_hep_duplicate(str *body, str *from, str *to, struct dest_i
         dst_fin = dst2;
     }
 
+    if (force_send_sock_str.s) {
+        LM_DBG("force_send_sock activated, grep for the sock_info\n");
+        si = grep_sock_info(&force_send_sock_uri->host,
+                (force_send_sock_uri->port_no)?force_send_sock_uri->port_no:SIP_PORT,
+                PROTO_UDP);
+        if (!si) {
+             LM_WARN("cannot grep socket info\n");
+        } 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_fin->send_sock = si;
+        }
+    }
+
     if (dst_fin->send_sock == 0) {
         dst_fin->send_sock=get_send_socket(0, &dst_fin->to, dst_fin->proto);
         if (dst_fin->send_sock == 0) {




More information about the sr-dev mailing list