Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtpengine module added receive-from option to flags to managing rtpengine by a kamailio node behind dispatcher #3230

Merged
merged 7 commits into from Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/modules/rtpengine/doc/rtpengine_admin.xml
Expand Up @@ -2423,6 +2423,11 @@ rtpengine_offer();
of ignoring endpoint addresses in the &sdp; body.
</para></listitem>
<listitem><para>
<emphasis>received-from=IP</emphasis> - Configure the SIP-source-address IP
explicitly, which will be useful when two kamailio is cascaded where first kamailio
is handling NAT and second kamailio RTPEngine.
</para></listitem>
<listitem><para>
<emphasis>replace-origin</emphasis> - flags that IP from the origin
description (o=) should be also changed.
</para></listitem>
Expand Down
48 changes: 38 additions & 10 deletions src/modules/rtpengine/rtpengine.c
Expand Up @@ -120,7 +120,7 @@ enum {
struct ng_flags_parse {
int via, to, packetize, transport, directional;
bencode_item_t *dict, *flags, *direction, *replace, *rtcp_mux, *sdes,
*t38,
*t38,*received_from,
*codec, *codec_strip, *codec_offer, *codec_transcode, *codec_mask,
*codec_set, *codec_except;
str call_id, from_tag, to_tag;
Expand Down Expand Up @@ -2241,8 +2241,8 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
{
char *e;
const char *err;
str key, val, s;

str key, val, s , s1;
int ip_af = AF_UNSPEC;
if (!flags_str)
return 0;

Expand Down Expand Up @@ -2276,6 +2276,27 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
bencode_list_add_str(ng_flags->replace, &s);
goto next;
}
if (str_key_val_prefix(&key, "received-from", &val, &s)) {
ip_af = get_ip_type(s.s);
if (ip_af == AF_INET)
{
s1.s="IP4";
s1.len=3;
bencode_list_add_str(ng_flags->received_from, &s1);
bencode_list_add_str(ng_flags->received_from, &s);

}else if (ip_af == AF_INET6)
{
s1.s="IP6";
s1.len=3;
bencode_list_add_str(ng_flags->received_from, &s1);
bencode_list_add_str(ng_flags->received_from, &s);

}


goto next;
}
if (str_key_val_prefix(&key, "SDES", &val, &s)) {
bencode_list_add_str(ng_flags->sdes, &s);
goto next;
Expand Down Expand Up @@ -2442,6 +2463,7 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
else if (str_eq(&key, "delete-delay") && val.s)
bencode_dictionary_add_integer(ng_flags->dict, "delete delay", atoi(val.s));
break;


case 16:
if (str_eq(&key, "UDP/TLS/RTP/SAVP") && !val.s)
Expand Down Expand Up @@ -2529,6 +2551,7 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_

body.s = NULL;
ng_flags.flags = bencode_list(bencbuf);
ng_flags.received_from = bencode_list(bencbuf);

if (op == OP_OFFER || op == OP_ANSWER) {
ng_flags.direction = bencode_list(bencbuf);
Expand Down Expand Up @@ -2649,13 +2672,18 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
bencode_dictionary_add_str(ng_flags.dict, "via-branch", &viabranch);
}

item = bencode_list(bencbuf);
bencode_dictionary_add(ng_flags.dict, "received-from", item);
bencode_list_add_string(item, (msg->rcv.src_ip.af == AF_INET) ? "IP4" : (
(msg->rcv.src_ip.af == AF_INET6) ? "IP6" :
"?"
) );
bencode_list_add_string(item, ip_addr2a(&msg->rcv.src_ip));
if (ng_flags.received_from && ng_flags.received_from->child) {
bencode_dictionary_add(ng_flags.dict, "received-from", ng_flags.received_from);
}
else {
//item = bencode_list(bencbuf);
bencode_dictionary_add(ng_flags.dict, "received-from", ng_flags.received_from);
bencode_list_add_string(ng_flags.received_from, (msg->rcv.src_ip.af == AF_INET) ? "IP4" : (
(msg->rcv.src_ip.af == AF_INET6) ? "IP6" :
"?"
) );
bencode_list_add_string(ng_flags.received_from, ip_addr2a(&msg->rcv.src_ip));
}

if (op == OP_BLOCK_DTMF || op == OP_BLOCK_MEDIA || op == OP_UNBLOCK_DTMF
|| op == OP_UNBLOCK_MEDIA || op == OP_START_FORWARDING || op == OP_STOP_FORWARDING
Expand Down