Browse code

Merge c7a7b39d7c53f978e9573bd8347773fceb63d9bb into e4527941b9d16b476a60b19bd15307cdac4b530b

Dmitry Wagin authored on 18/06/2021 12:16:28 • GitHub committed on 18/06/2021 12:16:28
Showing 1 changed files
... ...
@@ -1650,13 +1650,12 @@ static int is_rfc1918_f(struct sip_msg *msg, char *str1, char *str2)
1650 1650
 #define AOLDMEDPRT_LEN (sizeof(AOLDMEDPRT) - 1)
1651 1651
 
1652 1652
 
1653
-/* replace ip addresses in SDP and return umber of replacements */
1653
+/* replace ip addresses in SDP and return number of replacements */
1654 1654
 static inline int replace_sdp_ip(
1655
-		struct sip_msg *msg, str *org_body, char *line, str *ip, int linelen)
1655
+		struct sip_msg *msg, str *org_body, char *line, str *ip, int linelen, int can_omit)
1656 1656
 {
1657 1657
 	str body1, oldip, newip;
1658 1658
 	str body = *org_body;
1659
-	unsigned hasreplaced = 0;
1660 1659
 	int pf, pf1 = 0;
1661 1660
 	str body2;
1662 1661
 	char *bodylimit = body.s + body.len;
... ...
@@ -1672,10 +1671,17 @@ static inline int replace_sdp_ip(
1672 1671
 	}
1673 1672
 	body1 = body;
1674 1673
 	for(;;) {
1675
-		if(nh_extract_mediaip(&body1, &oldip, &pf, line, linelen) == -1)
1674
+		ret = nh_extract_mediaip(&body1, &oldip, &pf, line, linelen);
1675
+		if(ret == 0)
1676 1676
 			break;
1677
-		if(pf != AF_INET) {
1678
-			LM_ERR("not an IPv4 address in '%s' SDP\n", line);
1677
+		if(ret == -1) {
1678
+			if(can_omit) {
1679
+				body2.s = body1.s + linelen;
1680
+				body2.len = bodylimit - body2.s;
1681
+				body1 = body2;
1682
+				continue;
1683
+			}
1684
+			LM_ERR("no `IP[4|6]' in `%s' field\n", line);
1679 1685
 			return -1;
1680 1686
 		}
1681 1687
 		if(!pf1)
... ...
@@ -1693,13 +1699,8 @@ static inline int replace_sdp_ip(
1693 1699
 			return -1;
1694 1700
 		}
1695 1701
 		count += ret;
1696
-		hasreplaced = 1;
1697 1702
 		body1 = body2;
1698 1703
 	}
1699
-	if(!hasreplaced && linelen>=6 && memcmp("a=rtcp", line, 6)!=0) {
1700
-		LM_ERR("can't extract '%s' IP from the SDP\n", line);
1701
-		return -1;
1702
-	}
1703 1704
 
1704 1705
 	return count;
1705 1706
 }
... ...
@@ -1778,15 +1779,14 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
1778 1779
 	if(level & (FIX_MEDIP | FIX_ORGIP)) {
1779 1780
 
1780 1781
 		/* Iterate all a=rtcp and replace ips in them. rfc3605 */
1781
-		ret = replace_sdp_ip(msg, &body, "a=rtcp", (ip && ip->len>0) ? ip : 0, 6);
1782
+		ret = replace_sdp_ip(msg, &body, "a=rtcp", (ip && ip->len>0) ? ip : 0, 6, 1);
1782 1783
 		if(ret == -1)
1783
-			LM_DBG("a=rtcp parameter does not exist. nothing to do.\n");
1784
-		else 
1785
-			count += ret;
1784
+			return -1;
1785
+		count += ret;
1786 1786
 
1787 1787
 		if(level & FIX_MEDIP) {
1788 1788
 			/* Iterate all c= and replace ips in them. */
1789
-			ret = replace_sdp_ip(msg, &body, "c=", (ip && ip->len>0) ? ip : 0, 2);
1789
+			ret = replace_sdp_ip(msg, &body, "c=", (ip && ip->len>0) ? ip : 0, 2, 0);
1790 1790
 			if(ret == -1)
1791 1791
 				return -1;
1792 1792
 			count += ret;
... ...
@@ -1794,7 +1794,7 @@ static int ki_fix_nated_sdp_ip(sip_msg_t *msg, int level, str *ip)
1794 1794
 
1795 1795
 		if(level & FIX_ORGIP) {
1796 1796
 			/* Iterate all o= and replace ips in them. */
1797
-			ret = replace_sdp_ip(msg, &body, "o=",  (ip && ip->len>0) ? ip : 0, 2);
1797
+			ret = replace_sdp_ip(msg, &body, "o=",  (ip && ip->len>0) ? ip : 0, 2, 0);
1798 1798
 			if(ret == -1)
1799 1799
 				return -1;
1800 1800
 			count += ret;
... ...
@@ -1841,7 +1841,7 @@ static int nh_extract_mediaip(str *body, str *mediaip, int *pf, char *line,
1841 1841
 		cp = cp1 + linelen;
1842 1842
 	}
1843 1843
 	if(cp1 == NULL)
1844
-		return -1;
1844
+		return 0;
1845 1845
 
1846 1846
 	mediaip->s = cp1 + linelen;
1847 1847
 	mediaip->len =
... ...
@@ -1876,7 +1876,6 @@ static int nh_extract_mediaip(str *body, str *mediaip, int *pf, char *line,
1876 1876
 		cp = eat_space_end(cp + len, mediaip->s + mediaip->len);
1877 1877
 	}
1878 1878
 	if(nextisip != 2 || mediaip->len == 0) {
1879
-		LM_ERR("no `IP[4|6]' in `%s' field\n", line);
1880 1879
 		return -1;
1881 1880
 	}
1882 1881
 	return 1;