[Asterisk-code-review] dns.c: Load IPv6 DNS resolvers if configured. (asterisk[19])

Kevin Harwell asteriskteam at digium.com
Wed Sep 8 18:18:19 CDT 2021


Kevin Harwell has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16415 )

Change subject: dns.c: Load IPv6 DNS resolvers if configured.
......................................................................

dns.c: Load IPv6 DNS resolvers if configured.

IPv6 nameserver addresses are stored in different part of the
__res_state structure, so look there if we appear to have support for
it.

ASTERISK-28004 #close

Change-Id: I67067077d8a406ee996664518d9c8fbf11f6977d
---
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M main/dns.c
4 files changed, 32 insertions(+), 2 deletions(-)

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



diff --git a/configure b/configure
index 7d45eb8..d6ae579 100755
--- a/configure
+++ b/configure
@@ -18657,6 +18657,17 @@
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+	ac_fn_c_check_member "$LINENO" "struct __res_state" "_u._ext.nsaddrs" "ac_cv_member_struct___res_state__u__ext_nsaddrs" "#include <resolv.h>
+"
+if test "x$ac_cv_member_struct___res_state__u__ext_nsaddrs" = xyes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT___RES_STATE__U__EXT_NSADDRS 1
+_ACEOF
+
+
+fi
+
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
diff --git a/configure.ac b/configure.ac
index ea6080d..e61a96f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1459,7 +1459,8 @@
 		AC_MSG_RESULT(yes)
 		AC_DEFINE([HAVE_RES_CLOSE], 1, [Define to 1 if your system has the close resolver function.]),
 		AC_MSG_RESULT(no)
-	),
+	)
+	AC_CHECK_MEMBERS([struct __res_state._u._ext.nsaddrs], [], [], [[#include <resolv.h>]]),
 	AC_MSG_RESULT(no)
 )
 
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index fc3a9bd..776074d 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -1052,6 +1052,9 @@
 /* Define to 1 if `uid' is a member of `struct ucred'. */
 #undef HAVE_STRUCT_UCRED_UID
 
+/* Define to 1 if `_u._ext.nsaddrs' is a member of `struct __res_state'. */
+#undef HAVE_STRUCT___RES_STATE__U__EXT_NSADDRS
+
 /* Define to 1 if you have the `swapctl' function. */
 #undef HAVE_SWAPCTL
 
diff --git a/main/dns.c b/main/dns.c
index 782d4a8..9cf0cf4 100644
--- a/main/dns.c
+++ b/main/dns.c
@@ -605,7 +605,22 @@
 #endif
 
 	for (i = 0; i < state->nscount; i++) {
-		ast_str_container_add(nameservers, ast_inet_ntoa(state->nsaddr_list[i].sin_addr));
+		char addr[INET6_ADDRSTRLEN];
+		const char *addrp = NULL;
+
+		/* glibc sets sin_family to 0 when the nameserver is an IPv6 address */
+		if (state->nsaddr_list[i].sin_family) {
+			addrp = inet_ntop(AF_INET, &state->nsaddr_list[i].sin_addr, addr, sizeof(addr));
+#if defined(HAVE_RES_NINIT) && defined(HAVE_STRUCT___RES_STATE__U__EXT_NSADDRS)
+		} else if (state->_u._ext.nsaddrs[i]) {
+			addrp = inet_ntop(AF_INET6, &state->_u._ext.nsaddrs[i]->sin6_addr, addr, sizeof(addr));
+#endif
+		}
+
+		if (addrp) {
+			ast_debug(1, "Discovered nameserver: %s\n", addrp);
+			ast_str_container_add(nameservers, addrp);
+		}
 	}
 
 #ifdef HAVE_RES_NINIT

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16415
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I67067077d8a406ee996664518d9c8fbf11f6977d
Gerrit-Change-Number: 16415
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210908/e6af4741/attachment.html>


More information about the asterisk-code-review mailing list