From 84d741892fa279d6c390ebd8ffb1086bfd0c6a4f Mon Sep 17 00:00:00 2001 From: Dmitry Wagin Date: Tue, 18 May 2021 13:12:02 +0300 Subject: [PATCH] nathelper: fix_nated_sdp added ignoring RFC3605-param if omitted - doesn't throw an error while "a=rtcp" param is omitted (RFC1889 behavior) - replace_sdp_ip() returns 0 on omitted IP-address --- src/modules/nathelper/nathelper.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c index baae1dbb6be..55235e969e0 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) { 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,11 @@ 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) { + LM_ERR("can't extract '%s' IP from the SDP\n", line); return -1; } if(!pf1) @@ -1652,13 +1652,8 @@ static inline int replace_sdp_ip( return -1; } count += ret; - hasreplaced = 1; body1 = body2; } - if(!hasreplaced) { - LM_ERR("can't extract '%s' IP from the SDP\n", line); - return -1; - } return count; } @@ -1739,9 +1734,8 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip) /* 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); 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. */ @@ -1800,7 +1794,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 =