[sr-dev] git:master:2ce1a324: pike: new function pike_check_ip(ipaddr)

Daniel-Constantin Mierla miconda at gmail.com
Tue Oct 13 15:35:45 CEST 2020


Module: kamailio
Branch: master
Commit: 2ce1a3247fd5a05e0f32c7a591d5377f0e52bdd1
URL: https://github.com/kamailio/kamailio/commit/2ce1a3247fd5a05e0f32c7a591d5377f0e52bdd1

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-10-13T15:28:40+02:00

pike: new function pike_check_ip(ipaddr)

- check the parameter ipaddr in the pike tree
- old pike_check_req() is same as pike_check_ip("$si")

---

Modified: src/modules/pike/pike.c
Modified: src/modules/pike/pike_funcs.c
Modified: src/modules/pike/pike_funcs.h

---

Diff:  https://github.com/kamailio/kamailio/commit/2ce1a3247fd5a05e0f32c7a591d5377f0e52bdd1.diff
Patch: https://github.com/kamailio/kamailio/commit/2ce1a3247fd5a05e0f32c7a591d5377f0e52bdd1.patch

---

diff --git a/src/modules/pike/pike.c b/src/modules/pike/pike.c
index 7a85d826d9..33dcfd6420 100644
--- a/src/modules/pike/pike.c
+++ b/src/modules/pike/pike.c
@@ -36,6 +36,7 @@
 #include "../../core/timer.h"
 #include "../../core/locking.h"
 #include "../../core/kemi.h"
+#include "../../core/mod_fix.h"
 #include "ip_tree.h"
 #include "timer.h"
 #include "pike_funcs.h"
@@ -63,7 +64,10 @@ pike_list_link_t *pike_timer = 0;
 
 
 static cmd_export_t cmds[]={
-	{"pike_check_req", (cmd_function)w_pike_check_req,  0,  0, 0, REQUEST_ROUTE},
+	{"pike_check_req",    (cmd_function)w_pike_check_req,  0,
+		0, 0, REQUEST_ROUTE|ONREPLY_ROUTE},
+	{"pike_check_ip", (cmd_function)w_pike_check_ip,       1,
+		fixup_spve_null, fixup_free_spve_null, REQUEST_ROUTE|ONREPLY_ROUTE},
 	{0,0,0,0,0,0}
 };
 
@@ -177,6 +181,11 @@ static sr_kemi_t sr_kemi_pike_exports[] = {
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("pike"), str_init("pike_check_ip"),
+		SR_KEMIP_INT, pike_check_ip,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };
diff --git a/src/modules/pike/pike_funcs.c b/src/modules/pike/pike_funcs.c
index 804ebb6ec0..42fc5172e4 100644
--- a/src/modules/pike/pike_funcs.c
+++ b/src/modules/pike/pike_funcs.c
@@ -32,6 +32,7 @@
 #include "../../core/ip_addr.h"
 #include "../../core/resolve.h"
 #include "../../core/counters.h"
+#include "../../core/mod_fix.h"
 #include "ip_tree.h"
 #include "pike_funcs.h"
 #include "timer.h"
@@ -53,28 +54,11 @@ void pike_counter_init()
 
 
 
-int pike_check_req(sip_msg_t *msg)
+int pike_check_ipaddr(sip_msg_t *msg, ip_addr_t* ip)
 {
 	pike_ip_node_t *node;
 	pike_ip_node_t *father;
 	unsigned char flags;
-	struct ip_addr* ip;
-
-
-#ifdef _test
-	/* get the ip address from second via */
-	if (parse_headers(msg, HDR_VIA1_F, 0)!=0 )
-		return -1;
-	if (msg->via1==0 )
-		return -1;
-	/* convert from string to ip_addr */
-	ip = str2ip( &msg->via1->host );
-	if (ip==0)
-		return -1;
-#else
-	ip = &(msg->rcv.src_ip);
-#endif
-
 
 	/* first lock the proper tree branch and mark the IP with one more hit*/
 	lock_tree_branch( ip->u.addr[0] );
@@ -159,11 +143,61 @@ int pike_check_req(sip_msg_t *msg)
 }
 
 
-int w_pike_check_req(struct sip_msg *msg, char *foo, char *bar)
+int pike_check_req(sip_msg_t *msg)
+{
+	ip_addr_t* ip;
+
+
+#ifdef _test
+	/* get the ip address from second via */
+	if (parse_headers(msg, HDR_VIA1_F, 0)!=0 )
+		return -1;
+	if (msg->via1==0 )
+		return -1;
+	/* convert from string to ip_addr */
+	ip = str2ip( &msg->via1->host );
+	if (ip==0)
+		return -1;
+#else
+	ip = &(msg->rcv.src_ip);
+#endif
+
+	return pike_check_ipaddr(msg, ip);
+}
+
+int w_pike_check_req(sip_msg_t *msg, char *foo, char *bar)
 {
 	return pike_check_req(msg);
 }
 
+int pike_check_ip(sip_msg_t *msg, str *strip)
+{
+	ip_addr_t* ip;
+
+	if(strip==NULL || strip->len<=0) {
+		return -1;
+	}
+
+	ip = str2ip(strip);
+	if (ip==0) {
+		LM_ERR("failed to parse ip address: %.*s\n", strip->len, strip->s);
+		return -1;
+	}
+
+	return pike_check_ipaddr(msg, ip);
+}
+
+int w_pike_check_ip(sip_msg_t *msg, char *pip, char *bar)
+{
+	str strip;
+
+	if(fixup_get_svalue(msg, (gparam_t*)pip, &strip)<0) {
+		LM_ERR("failed to get the ip parameter\n");
+		return -1;
+	}
+	return pike_check_ip(msg, &strip);
+}
+
 void clean_routine(unsigned int ticks , void *param)
 {
 	static unsigned char mask[32];  /* 256 positions mask */
diff --git a/src/modules/pike/pike_funcs.h b/src/modules/pike/pike_funcs.h
index c41aa7b3f0..5e83c2381b 100644
--- a/src/modules/pike/pike_funcs.h
+++ b/src/modules/pike/pike_funcs.h
@@ -28,7 +28,9 @@
 
 void pike_counter_init(void);
 int  pike_check_req(sip_msg_t *msg);
+int  pike_check_ip(sip_msg_t *msg, str *strip);
 int  w_pike_check_req(sip_msg_t *msg, char *foo, char *bar);
+int  w_pike_check_ip(sip_msg_t *msg, char *pip, char *bar);
 void clean_routine(unsigned int, void*);
 void swap_routine(unsigned int, void*);
 




More information about the sr-dev mailing list