[sr-dev] git:master:13e876e4: core: kemi - added KSR.to_UDP() - return true if target is over UDP

Daniel-Constantin Mierla miconda at gmail.com
Mon Jun 14 13:24:56 CEST 2021


Module: kamailio
Branch: master
Commit: 13e876e45ad34a9d567d41293450307816bdf107
URL: https://github.com/kamailio/kamailio/commit/13e876e45ad34a9d567d41293450307816bdf107

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-14T13:22:35+02:00

core: kemi - added KSR.to_UDP() - return true if target is over UDP

- uses the R-URI/D-URI for requests (no DNS query done if transport is missing)
and 2nd Via for replies

---

Modified: src/core/kemi.c

---

Diff:  https://github.com/kamailio/kamailio/commit/13e876e45ad34a9d567d41293450307816bdf107.diff
Patch: https://github.com/kamailio/kamailio/commit/13e876e45ad34a9d567d41293450307816bdf107.patch

---

diff --git a/src/core/kemi.c b/src/core/kemi.c
index 065eba9c2c..76bfdbcc29 100644
--- a/src/core/kemi.c
+++ b/src/core/kemi.c
@@ -1536,6 +1536,57 @@ static int sr_kemi_core_route(sip_msg_t *msg, str *route)
 	return ret;
 }
 
+/**
+ *
+ */
+static int sr_kemi_core_to_proto_helper(sip_msg_t *msg)
+{
+	sip_uri_t parsed_uri;
+	str uri;
+
+	if(msg==NULL) {
+		return -1;
+	}
+	if(msg->first_line.type == SIP_REPLY) {
+		/* REPLY doesnt have r/d-uri - use second Via */
+		if(parse_headers( msg, HDR_VIA2_F, 0)==-1) {
+			LM_DBG("no 2nd via parsed\n");
+			return -1;
+		}
+		if((msg->via2==0) || (msg->via2->error!=PARSE_OK)) {
+			return -1;
+		}
+		return (int)msg->via2->proto;
+	}
+	if (msg->dst_uri.s != NULL && msg->dst_uri.len>0) {
+		uri = msg->dst_uri;
+	} else {
+		if (msg->new_uri.s!=NULL && msg->new_uri.len>0)
+		{
+			uri = msg->new_uri;
+		} else {
+			uri = msg->first_line.u.request.uri;
+		}
+	}
+	if(parse_uri(uri.s, uri.len, &parsed_uri)!=0) {
+		LM_ERR("failed to parse nh uri [%.*s]\n", uri.len, uri.s);
+		return -1;
+	}
+	return (int)parsed_uri.proto;
+}
+
+/**
+ *
+ */
+static int sr_kemi_core_to_proto_udp(sip_msg_t *msg)
+{
+	int proto;
+
+	proto = sr_kemi_core_to_proto_helper(msg);
+	return (proto == PROTO_UDP)?SR_KEMI_TRUE:SR_KEMI_FALSE;
+}
+
+
 /**
  *
  */
@@ -1925,6 +1976,11 @@ static sr_kemi_t _sr_kemi_core[] = {
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init(""), str_init("to_UDP"),
+		SR_KEMIP_BOOL, sr_kemi_core_to_proto_udp,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 	{ str_init(""), str_init("is_src_port"),
 		SR_KEMIP_BOOL, sr_kemi_core_is_src_port,
 		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,




More information about the sr-dev mailing list