[Asterisk-code-review] Add support for older name resolving version libraries like ... (asterisk[14])

Anonymous Coward asteriskteam at digium.com
Tue Nov 22 11:51:32 CST 2016


Anonymous Coward #1000019 has submitted this change and it was merged. ( https://gerrit.asterisk.org/4480 )

Change subject: Add support for older name resolving version libraries like openBSD
......................................................................


Add support for older name resolving version libraries like openBSD

Fix support of OS's like openBSD that use an older nameser.h,
this change reverts the defines to the older style which on other
systems is found in nameser_compat.h

Tested on openBSD 6.0, Debian 8

ASTERISK-26608 #close

Change-Id: Iffb36caab8c5aa9dece0ce2d009041f7b56cc86a
---
M main/dns.c
M main/dns_core.c
M main/dns_naptr.c
M main/dns_srv.c
M res/res_pjsip/pjsip_resolver.c
5 files changed, 39 insertions(+), 38 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/main/dns.c b/main/dns.c
index fa94089..1a95afd 100644
--- a/main/dns.c
+++ b/main/dns.c
@@ -557,7 +557,7 @@
 
 	if (dns_response_len < 0) {
 		ast_debug(1, "DNS search failed for %s\n", dname);
-		response_handler(context, (unsigned char *)"", 0, ns_r_nxdomain);
+		response_handler(context, (unsigned char *)"", 0, NXDOMAIN);
 		return AST_DNS_SEARCH_FAILURE;
 	}
 
diff --git a/main/dns_core.c b/main/dns_core.c
index cfce8ef..762b3cc 100644
--- a/main/dns_core.c
+++ b/main/dns_core.c
@@ -114,7 +114,7 @@
 	int ttl = 0;
 	const struct ast_dns_record *record;
 
-	if (ast_dns_result_get_rcode(result) == ns_r_nxdomain) {
+	if (ast_dns_result_get_rcode(result) == NXDOMAIN) {
 		return 0;
 	}
 
@@ -197,7 +197,7 @@
 	if (ast_strlen_zero(name)) {
 		ast_log(LOG_WARNING, "Could not perform asynchronous resolution, no name provided\n");
 		return NULL;
-	} else if (rr_type > ns_t_max) {
+	} else if (rr_type > 65536) {
 		ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
 			name, rr_type);
 		return NULL;
@@ -205,7 +205,7 @@
 		ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', invalid resource record type '%d'\n",
 			name, rr_type);
 		return NULL;
-	} else if (rr_class > ns_c_max) {
+	} else if (rr_class > 65536) {
 		ast_log(LOG_WARNING, "Could not perform asynchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
 			name, rr_class);
 		return NULL;
@@ -319,7 +319,7 @@
 	if (ast_strlen_zero(name)) {
 		ast_log(LOG_WARNING, "Could not perform synchronous resolution, no name provided\n");
 		return -1;
-	} else if (rr_type > ns_t_max) {
+	} else if (rr_type > 65536) {
 		ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record type '%d' exceeds maximum\n",
 			name, rr_type);
 		return -1;
@@ -327,7 +327,7 @@
 		ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', invalid resource record type '%d'\n",
 			name, rr_type);
 		return -1;
-	} else if (rr_class > ns_c_max) {
+	} else if (rr_class > 65536) {
 		ast_log(LOG_WARNING, "Could not perform synchronous resolution of '%s', resource record class '%d' exceeds maximum\n",
 			name, rr_class);
 		return -1;
@@ -445,8 +445,8 @@
 typedef struct ast_dns_record *(*dns_alloc_fn)(struct ast_dns_query *query, const char *data, const size_t size);
 
 static dns_alloc_fn dns_alloc_table [] = {
-	[ns_t_naptr] = dns_naptr_alloc,
-	[ns_t_srv] = dns_srv_alloc,
+	[T_NAPTR] = dns_naptr_alloc,
+	[T_SRV] = dns_srv_alloc,
 };
 
 static struct ast_dns_record *allocate_dns_record(int rr_type, struct ast_dns_query *query, const char *data, const size_t size)
@@ -464,7 +464,7 @@
 		ast_debug(2, "Query '%p': Could not add record, invalid resource record type '%d'\n",
 			query, rr_type);
 		return -1;
-	} else if (rr_type > ns_t_max) {
+	} else if (rr_type > 65536) {
 		ast_debug(2, "Query '%p': Could not add record, resource record type '%d' exceeds maximum\n",
 			query, rr_type);
 		return -1;
@@ -472,7 +472,7 @@
 		ast_debug(2, "Query '%p': Could not add record, invalid resource record class '%d'\n",
 			query, rr_class);
 		return -1;
-	} else if (rr_class > ns_c_max) {
+	} else if (rr_class > 65536) {
 		ast_debug(2, "Query '%p': Could not add record, resource record class '%d' exceeds maximum\n",
 			query, rr_class);
 		return -1;
@@ -509,8 +509,8 @@
 typedef void (*dns_sort_fn)(struct ast_dns_result *result);
 
 static dns_sort_fn dns_sort_table [] = {
-	[ns_t_naptr] = dns_naptr_sort,
-	[ns_t_srv] = dns_srv_sort,
+	[T_NAPTR] = dns_naptr_sort,
+	[T_SRV] = dns_srv_sort,
 };
 
 static void sort_result(int rr_type, struct ast_dns_result *result)
diff --git a/main/dns_naptr.c b/main/dns_naptr.c
index 4d5a5f9..4b1bd75 100644
--- a/main/dns_naptr.c
+++ b/main/dns_naptr.c
@@ -32,6 +32,7 @@
 ASTERISK_REGISTER_FILE()
 
 #include <arpa/nameser.h>
+#include <netinet/in.h>
 #include <resolv.h>
 #include <regex.h>
 
@@ -592,7 +593,7 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->flags;
 }
 
@@ -600,7 +601,7 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->service;
 }
 
@@ -608,7 +609,7 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->regexp;
 }
 
@@ -616,7 +617,7 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->replacement;
 }
 
@@ -624,7 +625,7 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->order;
 }
 
@@ -632,6 +633,6 @@
 {
 	struct ast_dns_naptr_record *naptr = (struct ast_dns_naptr_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_naptr);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_NAPTR);
 	return naptr->preference;
 }
diff --git a/main/dns_srv.c b/main/dns_srv.c
index e4a3d8b..0a4c878 100644
--- a/main/dns_srv.c
+++ b/main/dns_srv.c
@@ -185,7 +185,7 @@
 {
 	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_SRV);
 	return srv->host;
 }
 
@@ -193,7 +193,7 @@
 {
 	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_SRV);
 	return srv->priority;
 }
 
@@ -201,7 +201,7 @@
 {
 	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_SRV);
 	return srv->weight;
 }
 
@@ -209,6 +209,6 @@
 {
 	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
 
-	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	ast_assert(ast_dns_record_get_rr_type(record) == T_SRV);
 	return srv->port;
 }
diff --git a/res/res_pjsip/pjsip_resolver.c b/res/res_pjsip/pjsip_resolver.c
index 5a90246..d6646d5 100644
--- a/res/res_pjsip/pjsip_resolver.c
+++ b/res/res_pjsip/pjsip_resolver.c
@@ -253,7 +253,7 @@
 		return -1;
 	}
 
-	return sip_resolve_add(resolve, ast_dns_naptr_get_replacement(record), ns_t_srv, ns_c_in,
+	return sip_resolve_add(resolve, ast_dns_naptr_get_replacement(record), T_SRV, C_IN,
 		transport, 0);
 }
 
@@ -304,12 +304,12 @@
 		target = AST_VECTOR_GET_ADDR(&resolving, idx);
 		for (record = ast_dns_result_get_records(result); record; record = ast_dns_record_get_next(record)) {
 
-			if (ast_dns_record_get_rr_type(record) == ns_t_a ||
-				ast_dns_record_get_rr_type(record) == ns_t_aaaa) {
+			if (ast_dns_record_get_rr_type(record) == T_A ||
+				ast_dns_record_get_rr_type(record) == T_AAAA) {
 				/* If NAPTR or SRV records exist the subsequent results from them take preference */
 				if (have_naptr || have_srv) {
 					ast_debug(2, "[%p] %s record being skipped on target '%s' because NAPTR or SRV record exists\n",
-						resolve, ast_dns_record_get_rr_type(record) == ns_t_a ? "A" : "AAAA",
+						resolve, ast_dns_record_get_rr_type(record) == T_A ? "A" : "AAAA",
 						ast_dns_query_get_name(query));
 					continue;
 				}
@@ -322,7 +322,7 @@
 				resolve->addresses.entry[address_count].type = target->transport;
 
 				/* Populate address information for the new address entry */
-				if (ast_dns_record_get_rr_type(record) == ns_t_a) {
+				if (ast_dns_record_get_rr_type(record) == T_A) {
 					ast_debug(2, "[%p] A record received on target '%s'\n", resolve, ast_dns_query_get_name(query));
 					resolve->addresses.entry[address_count].addr_len = sizeof(pj_sockaddr_in);
 					pj_sockaddr_init(pj_AF_INET(), &resolve->addresses.entry[address_count].addr, NULL,
@@ -338,7 +338,7 @@
 				}
 
 				address_count++;
-			} else if (ast_dns_record_get_rr_type(record) == ns_t_srv) {
+			} else if (ast_dns_record_get_rr_type(record) == T_SRV) {
 				if (have_naptr) {
 					ast_debug(2, "[%p] SRV record being skipped on target '%s' because NAPTR record exists\n",
 						resolve, ast_dns_query_get_name(query));
@@ -350,22 +350,22 @@
 
 				/* 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,
+					sip_resolve_add(resolve, ast_dns_srv_get_host(record), T_AAAA, 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,
+					sip_resolve_add(resolve, ast_dns_srv_get_host(record), T_AAAA, C_IN, target->transport + PJSIP_TRANSPORT_IPV6,
 						ast_dns_srv_get_port(record));
 					have_srv = 1;
 				}
 
 				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,
+					sip_resolve_add(resolve, ast_dns_srv_get_host(record), T_A, C_IN, target->transport,
 						ast_dns_srv_get_port(record));
 					have_srv = 1;
 				}
-			} else if (ast_dns_record_get_rr_type(record) == ns_t_naptr) {
+			} else if (ast_dns_record_get_rr_type(record) == T_NAPTR) {
 				int added = -1;
 
 				ast_debug(2, "[%p] NAPTR record received on target '%s'\n", resolve, ast_dns_query_get_name(query));
@@ -561,39 +561,39 @@
 		 * explicitly and only looks for IPv6 records.
 		 */
 
-		res |= sip_resolve_add(resolve, host, ns_t_naptr, ns_c_in, type, 0);
+		res |= sip_resolve_add(resolve, host, T_NAPTR, C_IN, type, 0);
 
 		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,
+			res |= sip_resolve_add(resolve, srv, T_SRV, C_IN,
 				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TLS : type, 0);
 		}
 		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,
+			res |= sip_resolve_add(resolve, srv, T_SRV, C_IN,
 				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_TCP : type, 0);
 		}
 		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,
+			res |= sip_resolve_add(resolve, srv, T_SRV, C_IN,
 				type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP : type, 0);
 		}
 	}
 
 	if ((type == PJSIP_TRANSPORT_UNSPECIFIED && sip_transport_is_available(PJSIP_TRANSPORT_UDP6)) ||
 		sip_transport_is_available(type + PJSIP_TRANSPORT_IPV6)) {
-		res |= sip_resolve_add(resolve, host, ns_t_aaaa, ns_c_in, (type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP6 : type + PJSIP_TRANSPORT_IPV6), target->addr.port);
+		res |= sip_resolve_add(resolve, host, T_AAAA, C_IN, (type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP6 : type + PJSIP_TRANSPORT_IPV6), target->addr.port);
 	}
 
 	if ((type == PJSIP_TRANSPORT_UNSPECIFIED && sip_transport_is_available(PJSIP_TRANSPORT_UDP)) ||
 		sip_transport_is_available(type)) {
-		res |= sip_resolve_add(resolve, host, ns_t_a, ns_c_in, (type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP : type), target->addr.port);
+		res |= sip_resolve_add(resolve, host, T_A, C_IN, (type == PJSIP_TRANSPORT_UNSPECIFIED ? PJSIP_TRANSPORT_UDP : type), target->addr.port);
 	}
 
 	if (res) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iffb36caab8c5aa9dece0ce2d009041f7b56cc86a
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: snuffy <snuffy22 at gmail.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list