hi
the attached patch adds support for updating the RTCP
attribute in SDP, based on the info from rtpproxy.
The RTCP attribute is defined in RFC 3605, and is used
to signal explicit RTCP port to the peer. Currently the
SER nathelper module does not modify this attribute,
if the media goes via RTP-proxy. The patch adds support
for this, and will modify the SDP attribute to contain
port+1 from rtpproxy.
Is this something that we want in SER v2.1 ?
any review comments are appreciated :)
/alfred
Index: modules/nathelper/nathelper.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/nathelper/nathelper.c,v
retrieving revision 1.126
diff -u -r1.126 nathelper.c
--- modules/nathelper/nathelper.c 29 May 2008 02:43:36 -0000 1.126
+++ modules/nathelper/nathelper.c 13 Jun 2008 08:50:29 -0000
@@ -1255,6 +1255,31 @@
}
static int
+extract_rtcp(str *body, str *rtcpport)
+{
+ char *cp, *cp1;
+ int len;
+
+ cp1 = NULL;
+ for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
+ cp1 = ser_memmem(cp, "a=rtcp:", len, 7);
+ if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
+ break;
+ cp = cp1 + 7;
+ }
+
+ if (cp1 == NULL)
+ return -1;
+
+ rtcpport->s = cp1 + 7; /* skip `a=rtcp:' */
+ rtcpport->len = eat_line(rtcpport->s, body->s + body->len -
+ rtcpport->s) - rtcpport->s;
+ trim_len(rtcpport->len, rtcpport->s, *rtcpport);
+
+ return 0;
+}
+
+static int
alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf,
str *newip, int newpf, int preserve)
{
@@ -1444,6 +1469,40 @@
return 0;
}
+static int
+alter_rtcp(struct sip_msg *msg, str *body, str *oldport, str *newport)
+{
+ char *buf;
+ int offset;
+ struct lump* anchor;
+
+ /* check that updating rtcpport is really necessary */
+ if (newport->len == oldport->len &&
+ memcmp(newport->s, oldport->s, newport->len) == 0)
+ return 0;
+
+ buf = pkg_malloc(newport->len);
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: alter_rtcp: out of memory\n");
+ return -1;
+ }
+ offset = oldport->s - msg->buf;
+ anchor = del_lump(msg, offset, oldport->len, 0);
+ if (anchor == NULL) {
+ LOG(L_ERR, "ERROR: alter_rtcp: del_lump failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ memcpy(buf, newport->s, newport->len);
+ if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) {
+ LOG(L_ERR, "ERROR: alter_rtcp: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+
+ return 0;
+}
+
static char *
gencookie()
{
@@ -1979,7 +2038,7 @@
force_rtp_proxy(struct sip_msg *msg, char *param1, char *param2, int offer)
{
str body, body1, oldport, oldip, newport, newip, str1, str2, s;
- str callid, from_tag, to_tag, tmp, c1_oldip;
+ str callid, from_tag, to_tag, tmp, c1_oldip, oldrtcp, newrtcp;
int create, port, len, asymmetric, flookup, argc, proxied, real, i;
int oidx, pf, pf1, force, c1_pf, rep_oidx;
unsigned int node_idx, oldport_i;
@@ -2242,6 +2301,13 @@
" extract media port from the message\n");
return -1;
}
+ /* Extract rtcp attribute */
+ tmpstr1.s = m1p;
+ tmpstr1.len = m2p - m1p;
+ oldrtcp.s = NULL;
+ oldrtcp.len = 0;
+ extract_rtcp(&tmpstr1, &oldrtcp);
+
++medianum;
if (asymmetric != 0 || real != 0) {
newip = oldip;
@@ -2362,6 +2428,19 @@
body1.s = m1p;
body1.len = bodylimit - body1.s;
if (alter_mediaport(msg, &body1, &oldport,
&newport, 0) == -1)
+ return -1;
+ }
+ /*
+ * Alter RTCP attribute if present. Inserting RTP port
+ 1 (as allocated
+ * by RTP proxy). No IP-address is needed in the new
RTCP attribute as the
+ * 'c' attribute (altered below) will contain the RTP
proxy IP address.
+ */
+ if (oldrtcp.s && oldrtcp.len) {
+ newrtcp.s = int2str(port+1, &newrtcp.len); /*
beware static buffer */
+ /* Alter port. */
+ body1.s = m1p;
+ body1.len = bodylimit - body1.s;
+ if (alter_rtcp(msg, &body1, &oldrtcp, &newrtcp)
== -1)
return -1;
}
/*
_______________________________________________
Serdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/serdev