TT#124752 nathelper: fix_nated_sdp added ignoring RFC3605-param if omitted

there was a regression at
c9a2bca78a

solved by
c7a7b39d7c

Change-Id: I0c2f034322d8f0adaa86a141659081ff3bbc42ac
mr9.5.3
Victor Seva 4 years ago
parent e463bdfc46
commit d24f46d416

@ -41,6 +41,7 @@ upstream/pv_headers-pvh_set_header-remove-values-to-set-null-.patch
upstream/pv_headers-don-t-try-to-replace-header.patch
upstream/permissions-don-t-remove-old-data-at-the-end-of-the-.patch
upstream/permissions-trusted_cleanup_interval.patch
upstream/nathelper-fix_nated_sdp-added-ignoring-RFC3605-param.patch
### relevant for upstream
sipwise/pua_dialoginfo-refresh_pubruri_avps_flag.patch
sipwise/pua_dialoginfo-local_identity_dlg_var.patch

@ -0,0 +1,112 @@
From: Dmitry Wagin <dmitry.wagin@ya.ru>
Date: Tue, 15 Jun 2021 15:58:12 +0300
Subject: nathelper: fix_nated_sdp added ignoring RFC3605-param if omitted
- doesn't throw an error while "a=rtcp" param is omitted (RFC1889 behavior) or address is omitted
- replace_sdp_ip() returns 0 on omitted IP-address
- added param can_omit to replace_sdp_ip()
---
src/modules/nathelper/nathelper.c | 37 ++++++++++++++++++-------------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c
index 1392a0a..9e45a61 100644
--- a/src/modules/nathelper/nathelper.c
+++ b/src/modules/nathelper/nathelper.c
@@ -1609,13 +1609,12 @@ static int is_rfc1918_f(struct sip_msg *msg, char *str1, char *str2)
#define AOLDMEDPRT_LEN (sizeof(AOLDMEDPRT) - 1)
-/* replace ip addresses in SDP and return umber of replacements */
+/* replace ip addresses in SDP and return number of replacements */
static inline int replace_sdp_ip(
- struct sip_msg *msg, str *org_body, char *line, str *ip, int linelen)
+ struct sip_msg *msg, str *org_body, char *line, str *ip, int linelen, int can_omit)
{
str body1, oldip, newip;
str body = *org_body;
- unsigned hasreplaced = 0;
int pf, pf1 = 0;
str body2;
char *bodylimit = body.s + body.len;
@@ -1631,10 +1630,17 @@ static inline int replace_sdp_ip(
}
body1 = body;
for(;;) {
- if(nh_extract_mediaip(&body1, &oldip, &pf, line, linelen) == -1)
+ ret = nh_extract_mediaip(&body1, &oldip, &pf, line, linelen);
+ if(ret == 0)
break;
- if(pf != AF_INET) {
- LM_ERR("not an IPv4 address in '%s' SDP\n", line);
+ if(ret == -1) {
+ if(can_omit) {
+ body2.s = body1.s + linelen;
+ body2.len = bodylimit - body2.s;
+ body1 = body2;
+ continue;
+ }
+ LM_ERR("no `IP[4|6]' in `%s' field\n", line);
return -1;
}
if(!pf1)
@@ -1652,13 +1658,8 @@ static inline int replace_sdp_ip(
return -1;
}
count += ret;
- hasreplaced = 1;
body1 = body2;
}
- if(!hasreplaced && linelen>=6 && memcmp("a=rtcp", line, 6)!=0) {
- LM_ERR("can't extract '%s' IP from the SDP\n", line);
- return -1;
- }
return count;
}
@@ -1737,15 +1738,14 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
if(level & (FIX_MEDIP | FIX_ORGIP)) {
/* Iterate all a=rtcp and replace ips in them. rfc3605 */
- ret = replace_sdp_ip(msg, &body, "a=rtcp", (ip && ip->len>0) ? ip : 0, 6);
+ ret = replace_sdp_ip(msg, &body, "a=rtcp", (ip && ip->len>0) ? ip : 0, 6, 1);
if(ret == -1)
- LM_DBG("a=rtcp parameter does not exist. nothing to do.\n");
- else
- count += ret;
+ return -1;
+ count += ret;
if(level & FIX_MEDIP) {
/* Iterate all c= and replace ips in them. */
- ret = replace_sdp_ip(msg, &body, "c=", (ip && ip->len>0) ? ip : 0, 2);
+ ret = replace_sdp_ip(msg, &body, "c=", (ip && ip->len>0) ? ip : 0, 2, 0);
if(ret == -1)
return -1;
count += ret;
@@ -1753,7 +1753,7 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
if(level & FIX_ORGIP) {
/* Iterate all o= and replace ips in them. */
- ret = replace_sdp_ip(msg, &body, "o=", (ip && ip->len>0) ? ip : 0, 2);
+ ret = replace_sdp_ip(msg, &body, "o=", (ip && ip->len>0) ? ip : 0, 2, 0);
if(ret == -1)
return -1;
count += ret;
@@ -1800,7 +1800,7 @@ static int nh_extract_mediaip(str *body, str *mediaip, int *pf, char *line,
cp = cp1 + linelen;
}
if(cp1 == NULL)
- return -1;
+ return 0;
mediaip->s = cp1 + linelen;
mediaip->len =
@@ -1835,7 +1835,6 @@ static int nh_extract_mediaip(str *body, str *mediaip, int *pf, char *line,
cp = eat_space_end(cp + len, mediaip->s + mediaip->len);
}
if(nextisip != 2 || mediaip->len == 0) {
- LM_ERR("no `IP[4|6]' in `%s' field\n", line);
return -1;
}
return 1;
Loading…
Cancel
Save