Module: kamailio Branch: master Commit: ed8486de52c29996f64496dcce0f44941cff49d3 URL: https://github.com/kamailio/kamailio/commit/ed8486de52c29996f64496dcce0f4494...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-08-21T09:23:14+02:00
corex: new function forward_uac()
- send out with only one Via, the one added by Kamailio, simulating a request sent by the initial UAC - useful when the reply is not wanted to be sent back (e.g., it was sent back from Kamailio)
---
Modified: src/modules/corex/corex_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/ed8486de52c29996f64496dcce0f4494... Patch: https://github.com/kamailio/kamailio/commit/ed8486de52c29996f64496dcce0f4494...
---
diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c index de2fb03b5fd..2b06231f734 100644 --- a/src/modules/corex/corex_mod.c +++ b/src/modules/corex/corex_mod.c @@ -37,6 +37,7 @@ #include "../../core/onsend.h" #include "../../core/forward.h" #include "../../core/dns_cache.h" +#include "../../core/data_lump.h" #include "../../core/parser/parse_uri.h" #include "../../core/parser/parse_param.h"
@@ -49,6 +50,7 @@ MODULE_VERSION
static int nio_intercept = 0; +static int w_forward_uac(sip_msg_t *msg, char *p1, char *p2); static int w_forward_reply(sip_msg_t *msg, char *p1, char *p2); static int w_append_branch(sip_msg_t *msg, char *su, char *sq); static int w_send_udp(sip_msg_t *msg, char *su, char *sq); @@ -113,6 +115,8 @@ static tr_export_t mod_trans[] = { };
static cmd_export_t cmds[] = { + {"forward_uac", (cmd_function)w_forward_uac, 0, + 0, 0, REQUEST_ROUTE}, {"forward_reply", (cmd_function)w_forward_reply, 0, 0, 0, CORE_ONREPLY_ROUTE}, {"append_branch", (cmd_function)w_append_branch, 0, @@ -267,6 +271,61 @@ static void mod_destroy(void) { }
+/** + * forward request like initial uac sender, with only one via + */ +static int w_forward_uac(sip_msg_t *msg, char *p1, char *p2) +{ + int ret; + dest_info_t dst; + sip_uri_t *u; + sip_uri_t next_hop; + sr_lump_t *anchor; + hdr_field_t *hf; + + if(msg == NULL) { + LM_WARN("invalid msg parameter\n"); + return -1; + } + + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { + LM_ERR("error while parsing message\n"); + return -1; + } + /* remove incoming Via headers */ + for(hf = msg->headers; hf; hf = hf->next) { + if(hf->type != HDR_VIA_T) { + continue; + } + anchor = del_lump(msg, hf->name.s - msg->buf, hf->len, 0); + if(anchor == 0) { + LM_ERR("cannot remove Via header\n"); + return -1; + } + } + + init_dest_info(&dst); + if(msg->dst_uri.len) { + ret = parse_uri(msg->dst_uri.s, msg->dst_uri.len, &next_hop); + u = &next_hop; + } else { + ret = parse_sip_msg_uri(msg); + u = &msg->parsed_uri; + } + if(ret < 0) { + LM_ERR("forward - bad uri dropping packet\n"); + return -1; + } + dst.proto = u->proto; + ret = forward_request_mode( + msg, &u->host, u->port_no, &dst, BUILD_NO_VIA1_UPDATE); + if(ret >= 0) { + return 1; + } + + return -1; +} + /** * forward reply based on via */