[sr-dev] git:5.3:4c17c00b: nathelper: fix_nated_sdp added support for a=rtcp param RFC3605

Daniel-Constantin Mierla miconda at gmail.com
Mon Oct 12 10:37:37 CEST 2020


Module: kamailio
Branch: 5.3
Commit: 4c17c00ba53275308490cd7f6994c8f1785d3a53
URL: https://github.com/kamailio/kamailio/commit/4c17c00ba53275308490cd7f6994c8f1785d3a53

Author: Arsen Semenov <arsperger at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-10-12T10:32:09+02:00

nathelper: fix_nated_sdp added support for a=rtcp param RFC3605

- GH #2459

(cherry picked from commit 088738ce16e73339e4c1b78c11f6ad6f8f3394cf)
(cherry picked from commit fd4dd36319599867e590098d86dc37186595cfad)

---

Modified: src/modules/nathelper/nathelper.c

---

Diff:  https://github.com/kamailio/kamailio/commit/4c17c00ba53275308490cd7f6994c8f1785d3a53.diff
Patch: https://github.com/kamailio/kamailio/commit/4c17c00ba53275308490cd7f6994c8f1785d3a53.patch

---

diff --git a/src/modules/nathelper/nathelper.c b/src/modules/nathelper/nathelper.c
index 7d326508c8..2c5de3b2cf 100644
--- a/src/modules/nathelper/nathelper.c
+++ b/src/modules/nathelper/nathelper.c
@@ -115,7 +115,7 @@ static int pv_get_rr_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
 static int pv_get_rr_top_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
 static int fix_nated_sdp_f(struct sip_msg *, char *, char *);
 static int is_rfc1918_f(struct sip_msg *, char *, char *);
-static int extract_mediaip(str *, str *, int *, char *);
+static int extract_mediaip(str *, str *, int *, char *, int);
 static int alter_mediaip(struct sip_msg *, str *, str *, int, str *, int, int);
 static int fix_nated_register_f(struct sip_msg *, char *, char *);
 static int fixup_fix_nated_register(void **param, int param_no);
@@ -1569,7 +1569,7 @@ static int is_rfc1918_f(struct sip_msg *msg, char *str1, char *str2)
 
 /* replace ip addresses in SDP and return umber of replacements */
 static inline int replace_sdp_ip(
-		struct sip_msg *msg, str *org_body, char *line, str *ip)
+		struct sip_msg *msg, str *org_body, char *line, str *ip, int linelen)
 {
 	str body1, oldip, newip;
 	str body = *org_body;
@@ -1589,7 +1589,7 @@ static inline int replace_sdp_ip(
 	}
 	body1 = body;
 	for(;;) {
-		if(extract_mediaip(&body1, &oldip, &pf, line) == -1)
+		if(extract_mediaip(&body1, &oldip, &pf, line, linelen) == -1)
 			break;
 		if(pf != AF_INET) {
 			LM_ERR("not an IPv4 address in '%s' SDP\n", line);
@@ -1692,20 +1692,31 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
 		}
 	}
 
-	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);
-		if(ret == -1)
-			return -1;
-		count += ret;
-	}
+	if(level & (FIX_MEDIP | FIX_ORGIP)) {
 
-	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);
+		/* 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)
-			return -1;
-		count += ret;
+			LM_DBG("a=rtcp parameter does not exist. nothing to do.\n");
+		else 
+			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);
+			if(ret == -1)
+				return -1;
+			count += ret;
+		}
+
+		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);
+			if(ret == -1)
+				return -1;
+			count += ret;
+		}
+
 	}
 
 	return count > 0 ? 1 : 2;
@@ -1733,22 +1744,22 @@ static int fix_nated_sdp_f(struct sip_msg *msg, char *str1, char *str2)
 	return ki_fix_nated_sdp_ip(msg, level, &ip);
 }
 
-static int extract_mediaip(str *body, str *mediaip, int *pf, char *line)
+static int extract_mediaip(str *body, str *mediaip, int *pf, char *line, int linelen)
 {
 	char *cp, *cp1;
 	int len, nextisip;
 
 	cp1 = NULL;
 	for(cp = body->s; (len = body->s + body->len - cp) > 0;) {
-		cp1 = ser_memmem(cp, line, len, 2);
+		cp1 = ser_memmem(cp, line, len, linelen);
 		if(cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
 			break;
-		cp = cp1 + 2;
+		cp = cp1 + linelen;
 	}
 	if(cp1 == NULL)
 		return -1;
 
-	mediaip->s = cp1 + 2;
+	mediaip->s = cp1 + linelen;
 	mediaip->len =
 			eat_line(mediaip->s, body->s + body->len - mediaip->s) - mediaip->s;
 	trim_len(mediaip->len, mediaip->s, *mediaip);




More information about the sr-dev mailing list