[sr-dev] git:master: topoh: allow server ip to be used as mask ip

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 10 20:17:20 CEST 2014


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Wed Sep 10 20:11:36 2014 +0200

topoh: allow server ip to be used as mask ip

---

 modules/topoh/th_msg.c    |   46 ++++++++++++++++++++++++--------------------
 modules/topoh/topoh_mod.c |   36 +++++++++++++++++++++++++++-------
 2 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/modules/topoh/th_msg.c b/modules/topoh/th_msg.c
index d572f00..3a68f3f 100644
--- a/modules/topoh/th_msg.c
+++ b/modules/topoh/th_msg.c
@@ -57,6 +57,7 @@ extern str th_vparam_name;
 extern str th_vparam_prefix;
 
 extern int th_param_mask_callid;
+extern int th_mask_addr_myself;
 
 int th_skip_rw(char *s, int len)
 {
@@ -126,34 +127,37 @@ int th_get_uri_type(str *uri, int *mode, str *value)
 	if(parse_uri(uri->s, uri->len, &puri)<0)
 		return -1;
 
-	LM_DBG("+++++++++++ PARAMS [%.*s]\n", puri.params.len, puri.params.s);
+	LM_DBG("PARAMS [%.*s]\n", puri.params.len, puri.params.s);
 	if(puri.host.len==th_ip.len
 			&& strncasecmp(puri.host.s, th_ip.s, th_ip.len)==0)
 	{
 		/* host matches TH ip */
 		ret = th_get_param_value(&puri.params, &th_uparam_name, value);
 		if(ret<0)
+			return -1; /* eroor parsing parameters */
+		if(ret==0)
+			return 2; /* param found - decode */
+		if(th_mask_addr_myself==0)
+			return 0; /* param not found - skip */
+	}
+
+	if(check_self(&puri.host, puri.port_no, 0)==1)
+	{
+		/* myself -- matched on all protos */
+		ret = th_get_param_value(&puri.params, &r2, value);
+		if(ret<0)
 			return -1;
-		return 2; /* decode */
-	} else {
-		if(check_self(&puri.host, (puri.port_no)?puri.port_no:0, 0)==1)
-		{
-			/* myself -- matched on all protos */
-			ret = th_get_param_value(&puri.params, &r2, value);
-			if(ret<0)
-				return -1;
-			if(ret==1) /* not found */
-				return 0; /* skip */
-			LM_DBG("+++++++++++++++++++************ [%.*s]\n",
-					value->len, value->s);
-			if(value->len==2 && strncasecmp(value->s, "on", 2)==0)
-				*mode = 1;
-			memset(value, 0, sizeof(str));
+		if(ret==1) /* not found */
 			return 0; /* skip */
-		} else {
-			return 1; /* encode */
-		}
+		LM_DBG("VALUE [%.*s]\n",
+				value->len, value->s);
+		if(value->len==2 && strncasecmp(value->s, "on", 2)==0)
+			*mode = 1;
+		memset(value, 0, sizeof(str));
+		return 0; /* skip */
 	}
+	/* not myself & not mask ip */
+	return 1; /* encode */
 }
 
 int th_mask_via(sip_msg_t *msg)
@@ -903,7 +907,7 @@ int th_add_hdr_cookie(sip_msg_t *msg)
 		pkg_free(h.s);
 		return -1;
 	}
-	LM_DBG("+++++++++++++ added cookie header [%s]\n", h.s);
+	LM_DBG("added cookie header [%s]\n", h.s);
 	return 0;
 }
 
diff --git a/modules/topoh/topoh_mod.c b/modules/topoh/topoh_mod.c
index 8340f19..ff64b6c 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -1,6 +1,4 @@
 /**
- * $Id$
- *
  * Copyright (C) 2009 SIP-Router.org
  *
  * This file is part of Extensible SIP Router, a free SIP server.
@@ -44,7 +42,9 @@
 #include "../../tcp_options.h"
 #include "../../ut.h"
 #include "../../forward.h"
+#include "../../config.h"
 #include "../../parser/msg_parser.h"
+#include "../../parser/parse_uri.h"
 #include "../../parser/parse_to.h"
 #include "../../parser/parse_from.h"
 
@@ -60,7 +60,7 @@ MODULE_VERSION
 str _th_key = str_init("aL9.n8~Hm]Z");
 str th_cookie_name = str_init("TH"); /* lost parameter? */
 str th_cookie_value = {0, 0};        /* lost parameter? */
-str th_ip = str_init("10.1.1.10");
+str th_ip = str_init("127.0.0.8");
 str th_uparam_name = str_init("line");
 str th_uparam_prefix = str_init("sr-");
 str th_vparam_name = str_init("branch");
@@ -74,6 +74,7 @@ int th_param_mask_callid = 0;
 
 int th_sanity_checks = 0;
 sanity_api_t scb;
+int th_mask_addr_myself = 0;
 
 int th_msg_received(void *data);
 int th_msg_sent(void *data);
@@ -84,13 +85,13 @@ static int mod_init(void);
 static param_export_t params[]={
 	{"mask_key",		PARAM_STR, &_th_key},
 	{"mask_ip",			PARAM_STR, &th_ip},
-	{"mask_callid",		INT_PARAM, &th_param_mask_callid},
+	{"mask_callid",		PARAM_INT, &th_param_mask_callid},
 	{"uparam_name",		PARAM_STR, &th_uparam_name},
 	{"uparam_prefix",	PARAM_STR, &th_uparam_prefix},
 	{"vparam_name",		PARAM_STR, &th_vparam_name},
 	{"vparam_prefix",	PARAM_STR, &th_vparam_prefix},
 	{"callid_prefix",	PARAM_STR, &th_callid_prefix},
-	{"sanity_checks",	INT_PARAM, &th_sanity_checks},
+	{"sanity_checks",	PARAM_INT, &th_sanity_checks},
 	{0,0,0}
 };
 
@@ -116,6 +117,9 @@ struct module_exports exports= {
  */
 static int mod_init(void)
 {
+	sip_uri_t puri;
+	char buri[MAX_URI_SIZE];
+
 	if(th_sanity_checks!=0)
 	{
 		if(sanity_load_api(&scb)<0)
@@ -129,11 +133,25 @@ static int mod_init(void)
 		LM_ERR("mask IP parameter is invalid\n");
 		goto error;
 	}
-	if(check_self(&th_ip, 0, 0)==1)
-	{
-		LM_ERR("mask IP must be different than SIP server local IP\n");
+
+	if(th_ip.len + 32 >= MAX_URI_SIZE) {
+		LM_ERR("mask address is too long\n");
+		goto error;
+	}
+	memcpy(buri, "sip:", 4);
+	memcpy(buri+4, th_ip.s, th_ip.len);
+	buri[th_ip.len+8] = '\0';
+
+	if(parse_uri(buri, th_ip.len+4, &puri)<0) {
+		LM_ERR("mask uri is invalid\n");
 		goto error;
 	}
+	if(check_self(&puri.host, puri.port_no, 0)==1)
+	{
+		th_mask_addr_myself = 1;
+		LM_INFO("mask address matches myself [%.*s]\n",
+				th_ip.len, th_ip.s);
+	}
 
 	/* 'SIP/2.0/UDP ' + ip + ';' + param + '=' + prefix (+ '\0') */
 	th_via_prefix.len = 12 + th_ip.len + 1 + th_vparam_name.len + 1
@@ -328,6 +346,8 @@ int th_msg_received(void *data)
 		th_cookie_value.len = 2;
 	}
 
+	LM_DBG("adding cookie: %.*s\n", th_cookie_value.len, th_cookie_value.s);
+
 	th_add_cookie(&msg);
 	nbuf = th_msg_update(&msg, (unsigned int*)&obuf->len);
 




More information about the sr-dev mailing list