[Asterisk-code-review] res pjsip: Perform resolution when explicit IPv6 transport i... (asterisk[14])

Joshua Colp asteriskteam at digium.com
Wed Nov 9 15:37:24 CST 2016


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/4358 )

Change subject: res_pjsip: Perform resolution when explicit IPv6 transport is used.
......................................................................

res_pjsip: Perform resolution when explicit IPv6 transport is used.

This change fixes the SIP resolver such that if an IPv6 transport
is explicitly used it will resolve NAPTR, SRV, and AAAA records.

You can explicitly use one by specifying it on an endpoint.

ASTERISK-26571

Change-Id: I2ed3ce81b43a6a8a937c0ebc1b8ed2da5ac2ef36
---
M res/res_pjsip/pjsip_resolver.c
1 file changed, 36 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/4358/1

diff --git a/res/res_pjsip/pjsip_resolver.c b/res/res_pjsip/pjsip_resolver.c
index 4d4d36e..bd122f2 100644
--- a/res/res_pjsip/pjsip_resolver.c
+++ b/res/res_pjsip/pjsip_resolver.c
@@ -232,7 +232,7 @@
 	}
 
 	if (!sip_transport_is_available(transport) &&
-		!sip_transport_is_available(transport + PJSIP_TRANSPORT_IPV6)) {
+		(!(transport & PJSIP_TRANSPORT_IPV6) && !sip_transport_is_available(transport + PJSIP_TRANSPORT_IPV6))) {
 		ast_debug(2, "[%p] NAPTR service %s skipped as transport is unavailable\n",
 			resolve, service);
 		return -1;
@@ -343,13 +343,19 @@
 				/* SRV records just create new queries for AAAA+A, nothing fancy */
 				ast_debug(2, "[%p] SRV record received on target '%s'\n", resolve, ast_dns_query_get_name(query));
 
-				if (sip_transport_is_available(target->transport + PJSIP_TRANSPORT_IPV6)) {
+				/* If an explicit IPv6 target transport has been requested look for only AAAA records */
+				if (target->transport & PJSIP_TRANSPORT_IPV6) {
+					sip_resolve_add(resolve, ast_dns_srv_get_host(record), ns_t_aaaa, ns_c_in, target->transport,
+						ast_dns_srv_get_port(record));
+					have_srv = 1;
+				} else if (sip_transport_is_available(target->transport + PJSIP_TRANSPORT_IPV6)) {
 					sip_resolve_add(resolve, ast_dns_srv_get_host(record), ns_t_aaaa, ns_c_in, target->transport + PJSIP_TRANSPORT_IPV6,
 						ast_dns_srv_get_port(record));
 					have_srv = 1;
 				}
 
-				if (sip_transport_is_available(target->transport)) {
+				if (!(target->transport & PJSIP_TRANSPORT_IPV6) &&
+					sip_transport_is_available(target->transport)) {
 					sip_resolve_add(resolve, ast_dns_srv_get_host(record), ns_t_a, ns_c_in, target->transport,
 						ast_dns_srv_get_port(record));
 					have_srv = 1;
@@ -365,14 +371,20 @@
 					continue;
 				}
 
-				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_UDP) {
-					added = sip_resolve_handle_naptr(resolve, record, "sip+d2u", PJSIP_TRANSPORT_UDP);
+				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_UDP ||
+					target->transport == PJSIP_TRANSPORT_UDP6) {
+					added = sip_resolve_handle_naptr(resolve, record, "sip+d2u",
+						target->transport == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP : target->transport);
 				}
-				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_TCP) {
-					added = sip_resolve_handle_naptr(resolve, record, "sip+d2t", PJSIP_TRANSPORT_TCP);
+				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_TCP ||
+					target->transport == PJSIP_TRANSPORT_TCP6) {
+					added = sip_resolve_handle_naptr(resolve, record, "sip+d2t",
+						target->transport == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TCP : target->transport);
 				}
-				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_TLS) {
-					added = sip_resolve_handle_naptr(resolve, record, "sips+d2t", PJSIP_TRANSPORT_TLS);
+				if (target->transport == PJSIP_TRANSPORT_UNSPECIFIED || target->transport == PJSIP_TRANSPORT_TLS ||
+					target->transport == PJSIP_TRANSPORT_TLS6) {
+					added = sip_resolve_handle_naptr(resolve, record, "sips+d2t",
+						target->transport == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TLS : target->transport);
 				}
 
 				/* If this record was successfully handled then we need to limit ourselves to this order */
@@ -535,23 +547,26 @@
 
 		res |= sip_resolve_add(resolve, host, ns_t_naptr, ns_c_in, type, 0);
 
-		if ((type == PJSIP_TRANSPORT_TLS || type == PJSIP_TRANSPORT_UNSPECIFIED) &&
-			(sip_transport_is_available(PJSIP_TRANSPORT_TLS) ||
-				sip_transport_is_available(PJSIP_TRANSPORT_TLS6))) {
+		if (type == PJSIP_TRANSPORT_UNSPECIFIED ||
+			(type == PJSIP_TRANSPORT_TLS && sip_transport_is_available(PJSIP_TRANSPORT_TLS)) ||
+			(type == PJSIP_TRANSPORT_TLS6 && sip_transport_is_available(PJSIP_TRANSPORT_TLS6))) {
 			snprintf(srv, sizeof(srv), "_sips._tcp.%s", host);
-			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in, PJSIP_TRANSPORT_TLS, 0);
+			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in,
+				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TLS : type, 0);
 		}
-		if ((type == PJSIP_TRANSPORT_TCP || type == PJSIP_TRANSPORT_UNSPECIFIED) &&
-			(sip_transport_is_available(PJSIP_TRANSPORT_TCP) ||
-				sip_transport_is_available(PJSIP_TRANSPORT_TCP6))) {
+		if (type == PJSIP_TRANSPORT_UNSPECIFIED ||
+			(type == PJSIP_TRANSPORT_TCP && sip_transport_is_available(PJSIP_TRANSPORT_TCP)) ||
+			(type == PJSIP_TRANSPORT_TCP6 && sip_transport_is_available(PJSIP_TRANSPORT_TCP6))) {
 			snprintf(srv, sizeof(srv), "_sip._tcp.%s", host);
-			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in, PJSIP_TRANSPORT_TCP, 0);
+			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in,
+				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TCP : type, 0);
 		}
-		if ((type == PJSIP_TRANSPORT_UDP || type == PJSIP_TRANSPORT_UNSPECIFIED) &&
-			(sip_transport_is_available(PJSIP_TRANSPORT_UDP) ||
-				sip_transport_is_available(PJSIP_TRANSPORT_UDP6))) {
+		if (type == PJSIP_TRANSPORT_UNSPECIFIED ||
+			(type == PJSIP_TRANSPORT_UDP && sip_transport_is_available(PJSIP_TRANSPORT_UDP)) ||
+			(type == PJSIP_TRANSPORT_UDP6 && sip_transport_is_available(PJSIP_TRANSPORT_UDP6))) {
 			snprintf(srv, sizeof(srv), "_sip._udp.%s", host);
-			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in, PJSIP_TRANSPORT_UDP, 0);
+			res |= sip_resolve_add(resolve, srv, ns_t_srv, ns_c_in,
+				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP : type, 0);
 		}
 	}
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ed3ce81b43a6a8a937c0ebc1b8ed2da5ac2ef36
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list