Module: kamailio
Branch: master
Commit: 6045c62f4ebaf861cf725ea7c1e560b22f7a5379
URL:
https://github.com/kamailio/kamailio/commit/6045c62f4ebaf861cf725ea7c1e560b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-05-11T15:16:36+02:00
siputils: added optional mode parameter to is_first_hop()
- if set to 1, skip checking for loops
- exported to kemi as is_first_hop_mode(int mode)
---
Modified: src/modules/siputils/sipops.c
Modified: src/modules/siputils/sipops.h
Modified: src/modules/siputils/siputils.c
---
Diff:
https://github.com/kamailio/kamailio/commit/6045c62f4ebaf861cf725ea7c1e560b…
Patch:
https://github.com/kamailio/kamailio/commit/6045c62f4ebaf861cf725ea7c1e560b…
---
diff --git a/src/modules/siputils/sipops.c b/src/modules/siputils/sipops.c
index 95b1baa5d0..fb1040c6ba 100644
--- a/src/modules/siputils/sipops.c
+++ b/src/modules/siputils/sipops.c
@@ -140,12 +140,12 @@ int w_is_supported(sip_msg_t *msg, char *_option, char *p2)
}
-int is_first_hop(sip_msg_t *msg)
+int is_first_hop_mode(sip_msg_t *msg, int mode)
{
int ret;
rr_t* r = NULL;
sip_uri_t puri;
- struct ip_addr *ip;
+ struct ip_addr *ip = NULL;
if(msg==NULL)
return -1;
@@ -180,10 +180,12 @@ int is_first_hop(sip_msg_t *msg)
LM_DBG("failed to parse uri in first record-route header\n");
return -1;
}
- if (((ip = str2ip(&(puri.host))) == NULL)
- && ((ip = str2ip6(&(puri.host))) == NULL)) {
- LM_DBG("uri host is not an ip address\n");
- return -1;
+ if(mode==0) {
+ if (((ip = str2ip(&(puri.host))) == NULL)
+ && ((ip = str2ip6(&(puri.host))) == NULL)) {
+ LM_DBG("uri host is not an ip address\n");
+ return -1;
+ }
}
ret = check_self(&puri.host, (puri.port.s)?puri.port_no:0,
(puri.transport_val.s)?puri.proto:0);
@@ -191,13 +193,15 @@ int is_first_hop(sip_msg_t *msg)
LM_DBG("top record route uri is not myself\n");
return -1;
}
- if (ip_addr_cmp(ip, &(msg->rcv.src_ip))
- && ((msg->rcv.src_port == puri.port_no)
- || ((puri.port.len == 0) && (msg->rcv.src_port == 5060)))
- && (puri.proto==msg->rcv.proto
- || (puri.proto==0 && msg->rcv.proto==PROTO_UDP)) ) {
- LM_DBG("source address matches top record route uri - loop\n");
- return -1;
+ if(mode==0) {
+ if (ip_addr_cmp(ip, &(msg->rcv.src_ip))
+ && ((msg->rcv.src_port == puri.port_no)
+ || ((puri.port.len == 0) && (msg->rcv.src_port == 5060)))
+ && (puri.proto==msg->rcv.proto
+ || (puri.proto==0 && msg->rcv.proto==PROTO_UDP)) ) {
+ LM_DBG("source address matches top record route uri - loop\n");
+ return -1;
+ }
}
/* todo - check spirals */
return 1;
@@ -206,6 +210,23 @@ int is_first_hop(sip_msg_t *msg)
}
}
+int w_is_first_hop_mode(sip_msg_t *msg, char *p1mode, char *p2)
+{
+ int mode = 0;
+
+ if(fixup_get_ivalue(msg, (gparam_t*)p1mode, &mode)<0) {
+ LM_ERR("failed to get mode parameter\n");
+ return -1;
+ }
+
+ return is_first_hop_mode(msg, mode);
+}
+
+int is_first_hop(sip_msg_t *msg)
+{
+ return is_first_hop_mode(msg, 0);
+}
+
int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2)
{
return is_first_hop(msg);
diff --git a/src/modules/siputils/sipops.h b/src/modules/siputils/sipops.h
index 27ac0c035e..97d885c71c 100644
--- a/src/modules/siputils/sipops.h
+++ b/src/modules/siputils/sipops.h
@@ -40,5 +40,7 @@ int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2);
int w_is_supported(sip_msg_t *msg, char *_option, char *p2);
int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2);
int is_first_hop(sip_msg_t *msg);
+int w_is_first_hop_mode(sip_msg_t *msg, char *p1mode, char *p2);
+int is_first_hop_mode(sip_msg_t *msg, int mode);
#endif
diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c
index 33a3c40a61..57ae9fb262 100644
--- a/src/modules/siputils/siputils.c
+++ b/src/modules/siputils/siputils.c
@@ -185,6 +185,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"is_first_hop", (cmd_function)w_is_first_hop, 0, 0,
0, ANY_ROUTE},
+ {"is_first_hop", (cmd_function)w_is_first_hop, 1, fixup_igp_null,
+ fixup_free_igp_null, ANY_ROUTE},
{"is_tel_number", (cmd_function)is_tel_number, 1, fixup_spve_null,
0, ANY_ROUTE},
{"is_numeric", (cmd_function)is_numeric, 1, fixup_spve_null,
@@ -571,6 +573,11 @@ static sr_kemi_t sr_kemi_siputils_exports[] = {
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("siputils"), str_init("is_first_hop_mode"),
+ SR_KEMIP_INT, is_first_hop_mode,
+ { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("siputils"), str_init("is_uri"),
SR_KEMIP_INT, ki_is_uri,
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,