[Asterisk-code-review] res rtp asterisk: ICE server-reflexive candidates (srflx) wi... (asterisk[13])

Joshua Colp asteriskteam at digium.com
Thu Nov 23 09:12:43 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/7332 )

Change subject: res_rtp_asterisk: ICE server-reflexive candidates (srflx) with Dual-Stack.
......................................................................

res_rtp_asterisk: ICE server-reflexive candidates (srflx) with Dual-Stack.

Previously, Asterisk sent srflx only when configured exclusively for IPv4. Now,
srflx is gathered and sent via SDP, even when Asterisk is enabled for
Dual Stack (IPv4+IPv6) and an IPv4 interface is available/used.

ASTERISK-27437

Change-Id: Ie07d8e2bfa7b6fe06fcdc73d390a7a9a4d8c0bc1
---
M res/res_rtp_asterisk.c
1 file changed, 31 insertions(+), 18 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index a9bdf68..fc31967 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -2910,8 +2910,8 @@
 	}
 
 	/* If configured to use a STUN server to get our external mapped address do so */
-	if (stunaddr.sin_addr.s_addr && count && ast_sockaddr_is_ipv4(addr)
-		&& !stun_address_is_blacklisted(addr)) {
+	if (count && stunaddr.sin_addr.s_addr && !stun_address_is_blacklisted(addr) &&
+		(ast_sockaddr_is_ipv4(addr) || ast_sockaddr_is_any(addr))) {
 		struct sockaddr_in answer;
 		int rsp;
 
@@ -2925,27 +2925,40 @@
 		ao2_lock(instance);
 		if (!rsp) {
 			pj_sockaddr base;
-			pj_sockaddr ext;
-			pj_str_t mapped = pj_str(ast_strdupa(ast_inet_ntoa(answer.sin_addr)));
-			int srflx = 1;
 
-			/* Use the first local host candidate as the base */
-			pj_sockaddr_cp(&base, &address[basepos]);
-
-			pj_sockaddr_init(pj_AF_INET(), &ext, &mapped, ntohs(answer.sin_port));
-
-			/* If the returned address is the same as one of our host candidates, don't send the srflx */
-			for (pos = 0; pos < count; pos++) {
-				if ((pj_sockaddr_cmp(&address[pos], &ext) == 0) && !rtp_address_is_ice_blacklisted(&address[pos])) {
-					srflx = 0;
+			/* Use the first local IPv4 host candidate as the base */
+			for (pos = basepos; pos < count; pos++) {
+				if (address[pos].addr.sa_family == PJ_AF_INET &&
+					!rtp_address_is_ice_blacklisted(&address[pos])) {
+					pj_sockaddr_cp(&base, &address[pos]);
 					break;
 				}
 			}
 
-			if (srflx) {
-				ast_rtp_ice_add_cand(instance, rtp, component, transport,
-					PJ_ICE_CAND_TYPE_SRFLX, 65535, &ext, &base, &base,
-					pj_sockaddr_get_len(&ext));
+			if (pos < count) {
+				pj_sockaddr ext;
+				pj_str_t mapped = pj_str(ast_strdupa(ast_inet_ntoa(answer.sin_addr)));
+				int srflx = 1;
+
+				pj_sockaddr_init(pj_AF_INET(), &ext, &mapped, ntohs(answer.sin_port));
+
+				/*
+				 * If the returned address is the same as one of our host
+				 * candidates, don't send the srflx
+				 */
+				for (pos = 0; pos < count; pos++) {
+					if (pj_sockaddr_cmp(&address[pos], &ext) == 0 &&
+						!rtp_address_is_ice_blacklisted(&address[pos])) {
+						srflx = 0;
+						break;
+					}
+				}
+
+				if (srflx) {
+					ast_rtp_ice_add_cand(instance, rtp, component, transport,
+						PJ_ICE_CAND_TYPE_SRFLX, 65535, &ext, &base, &base,
+						pj_sockaddr_get_len(&ext));
+				}
 			}
 		}
 	}

-- 
To view, visit https://gerrit.asterisk.org/7332
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie07d8e2bfa7b6fe06fcdc73d390a7a9a4d8c0bc1
Gerrit-Change-Number: 7332
Gerrit-PatchSet: 2
Gerrit-Owner: Alexander Traud <pabstraud at compuserve.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171123/cce179e1/attachment.html>


More information about the asterisk-code-review mailing list