Skip to content

Commit 152fd63

Browse files
authored
Add rtpp_bind_local support for the offer/answer/engage. (#3794)
When this AVP is set, its value would be provided to the rtpproxy with "l" modifier, allowing proper address to be selected for the session.
1 parent 210225e commit 152fd63

3 files changed

Lines changed: 87 additions & 2 deletions

File tree

modules/rtpproxy/README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rtpproxy Module
3030
1.5.13. generated_sdp_port_min (integer)
3131
1.5.14. generated_sdp_port_max (integer)
3232
1.5.15. generated_sdp_media_ip (string)
33+
1.5.16. rtpp_bind_local_avp (string)
3334

3435
1.6. Exported Functions
3536

@@ -470,6 +471,15 @@ modparam("rtpproxy", "generated_sdp_port_max", 30000)
470471
modparam("rtpproxy", "generated_sdp_media_ip", "10.0.0.1")
471472
...
472473

474+
1.5.16. rtpp_bind_local_avp (string)
475+
476+
The pseudo-variable used to read the local bind value which is
477+
appended as l<value> to the RTPProxy U/L command when set. For
478+
example, use "$socket_out(ip)" to bind based on the outbound
479+
socket.
480+
481+
Default value is “$avp(rtpp_bind_local)”.
482+
473483
1.6. Exported Functions
474484

475485
1.6.1. rtpproxy_engage([[flags][, [ip_address][, [set_id][,
@@ -604,6 +614,11 @@ if (is_method("INVITE") && has_totag()) {
604614
returns the resulted body in it. If not used, the message's
605615
body is used, and the outgoing body is changed.
606616

617+
If the pseudo-variable set by rtpp_bind_local_avp is set to a string, its
618+
value is appended as l<value> to the RTPProxy U/L command (for
619+
example, "[1:2:3]" for IPv6). This applies to both
620+
rtpproxy_offer() and rtpproxy_answer().
621+
607622
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
608623
FAILURE_ROUTE, BRANCH_ROUTE.
609624

modules/rtpproxy/doc/rtpproxy_admin.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,27 @@ modparam("rtpproxy", "generated_sdp_port_max", 30000)
547547
<programlisting format="linespecific">
548548
...
549549
modparam("rtpproxy", "generated_sdp_media_ip", "10.0.0.1")
550+
...
551+
</programlisting>
552+
</example>
553+
</section>
554+
555+
<section id="param_rtpp_bind_local_avp" xreflabel="rtpp_bind_local_avp">
556+
<title><varname>rtpp_bind_local_avp</varname> (string)</title>
557+
<para>
558+
The pseudo-variable used to read the local bind value which is
559+
appended as <emphasis>l&lt;value&gt;</emphasis> to the RTPProxy U/L
560+
command when set.
561+
</para>
562+
563+
<para>
564+
<emphasis>Default value is <quote>$avp(rtpp_bind_local)</quote>.</emphasis>
565+
</para>
566+
<example>
567+
<title>Set <varname>rtpp_bind_local_avp</varname> parameter</title>
568+
<programlisting format="linespecific">
569+
...
570+
modparam("rtpproxy", "rtpp_bind_local_avp", "$socket_out(ip)")
550571
...
551572
</programlisting>
552573
</example>
@@ -740,6 +761,14 @@ if (is_method("INVITE") &amp;&amp; has_totag()) {
740761
and returns the resulted body in it. If not used, the message's
741762
body is used, and the outgoing body is changed.
742763
</para>
764+
<para>
765+
If the pseudo-variable set by <varname>rtpp_bind_local_avp</varname>
766+
is set to a string, its value is appended as
767+
<emphasis>l&lt;value&gt;</emphasis> to the RTPProxy U/L command
768+
(for example, "[1:2:3]" for IPv6). This applies to both
769+
<function>rtpproxy_offer()</function> and
770+
<function>rtpproxy_answer()</function>.
771+
</para>
743772
<para>
744773
This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
745774
FAILURE_ROUTE, BRANCH_ROUTE.
@@ -1276,4 +1305,3 @@ $ opensips-cli -x mi rtpproxy:reload
12761305
</section>
12771306

12781307
</chapter>
1279-

modules/rtpproxy/rtpproxy.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ static str param3_name = str_init("rtpproxy_3");
228228
str param3_bavp_name = str_init("$bavp(5589967)");
229229
pv_spec_t param3_spec;
230230
static str late_name = str_init("late_negotiation");
231+
static str rtpp_bind_local_avp_name = str_init("$avp(rtpp_bind_local)");
232+
static pv_spec_t rtpp_bind_local_spec;
233+
static int rtpp_bind_local_avp_ok = 0;
231234

232235
/* parameters name for event signaling */
233236
static str event_name = str_init("E_RTPPROXY_STATUS");
@@ -525,6 +528,7 @@ static const param_export_t params[] = {
525528
{"generated_sdp_port_min",INT_PARAM, &rtpproxy_port_min },
526529
{"generated_sdp_port_max",INT_PARAM, &rtpproxy_port_max },
527530
{"generated_sdp_media_ip",STR_PARAM, &rtpproxy_media_ip.s },
531+
{"rtpp_bind_local_avp", STR_PARAM, &rtpp_bind_local_avp_name.s },
528532
{0, 0, 0}
529533
};
530534

@@ -1304,6 +1308,18 @@ mod_init(void)
13041308
parse_bavp(&param3_bavp_name, &param3_spec) < 0)
13051309
LM_DBG("cannot parse bavps\n");
13061310

1311+
if (rtpp_bind_local_avp_name.s && rtpp_bind_local_avp_name.s[0] != '\0') {
1312+
rtpp_bind_local_avp_name.len = strlen(rtpp_bind_local_avp_name.s);
1313+
if (pv_parse_spec(&rtpp_bind_local_avp_name, &rtpp_bind_local_spec) != NULL) {
1314+
rtpp_bind_local_avp_ok = 1;
1315+
} else {
1316+
LM_ERR("malformed rtpp_bind_local pvar definition\n");
1317+
return -1;
1318+
}
1319+
} else {
1320+
rtpp_bind_local_avp_ok = 0;
1321+
}
1322+
13071323
if(rtpp_notify_socket.s) {
13081324
if (strncmp("tcp:", rtpp_notify_socket.s, 4) == 0) {
13091325
rtpp_notify_socket_un = 0;
@@ -3583,12 +3599,13 @@ static int rtpproxy_offer_answer(struct sip_msg *msg, struct rtpp_args *args,
35833599
char medianum_buf[20];
35843600
char buf[32], dbuf[128];
35853601
int medianum, media_multi;
3586-
str medianum_str, tmpstr1;
3602+
str medianum_str, tmpstr1, bind_local_val;
35873603
int c1p_altered;
35883604
int enable_dtmf_catch = 0;
35893605
int node_has_notification, node_has_dtmf_catch = 0;
35903606
int vcnt;
35913607
pv_value_t val;
3608+
pv_value_t bind_val;
35923609
char *adv_address = NULL;
35933610
struct dlg_cell * dlg;
35943611
str dtmf_tag = {0, 0}, timeout_tag = {0, 0};
@@ -3817,6 +3834,24 @@ static int rtpproxy_offer_answer(struct sip_msg *msg, struct rtpp_args *args,
38173834
medianum = 0;
38183835

38193836
opts.s.s[0] = (create == 0) ? 'L' : 'U';
3837+
3838+
bind_local_val.len = 0;
3839+
if (msg && rtpp_bind_local_avp_ok) {
3840+
if (pv_get_spec_value(msg, &rtpp_bind_local_spec, &bind_val) < 0) {
3841+
LM_ERR("cannot get rtpp_bind_local avp value\n");
3842+
goto exit;
3843+
} else if (!(bind_val.flags & PV_VAL_NULL)) {
3844+
if (bind_val.flags & PV_VAL_STR) {
3845+
bind_local_val = bind_val.rs;
3846+
} else if (bind_val.flags & PV_VAL_INT) {
3847+
bind_local_val.s = int2str(bind_val.ri, &bind_local_val.len);
3848+
} else {
3849+
LM_ERR("rtpp_bind_local avp has unsupported value type\n");
3850+
goto exit;
3851+
}
3852+
}
3853+
}
3854+
38203855
STR2IOVEC(args->callid, vup.vu[5]);
38213856
STR2IOVEC(args->from_tag, vup.vu[11]);
38223857
STR2IOVEC(args->to_tag, vup.vu[15]);
@@ -3994,6 +4029,13 @@ static int rtpproxy_offer_answer(struct sip_msg *msg, struct rtpp_args *args,
39944029
goto error;
39954030
}
39964031
}
4032+
if (bind_local_val.len > 0) {
4033+
if (append_opts(&m_opts, 'l') == -1 ||
4034+
append_opts_str(&m_opts, &bind_local_val) == -1) {
4035+
LM_ERR("out of pkg memory\n");
4036+
goto error;
4037+
}
4038+
}
39974039
STR2IOVEC(newip, vup.vu[7]);
39984040
STR2IOVEC(oldport, vup.vu[9]);
39994041
if (1 || media_multi) /* XXX netch: can't choose now*/

0 commit comments

Comments
 (0)