ssahani / rpms / freeradius

Forked from rpms/freeradius 5 years ago
Clone
Blob Blame History Raw
From a23dbf402ad466bf41c95da82e58dedc7b615f99 Mon Sep 17 00:00:00 2001
From: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
Date: Mon, 1 Dec 2014 14:15:45 -0500
Subject: [PATCH 1/2] Resolve to all families on ip_hton fallback

If we're doing fallback resolution we need to set the address family to
AF_UNSPEC to get both IPv6 and IPv4 addresses

The af that was passed in, is then used to set the preference
---
 src/lib/misc.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/lib/misc.c b/src/lib/misc.c
index d0ccd6c..ad27057 100644
--- a/src/lib/misc.c
+++ b/src/lib/misc.c
@@ -845,7 +845,15 @@ int ip_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
 	int rcode;
 	struct addrinfo hints, *ai = NULL, *alt = NULL, *res = NULL;
 
+	/*
+	 *	Avoid malloc for IP addresses.  This helps us debug
+	 *	memory errors when using talloc.
+	 */
+#ifdef TALLOC_DEBUG
+	if (true) {
+#else
 	if (!fr_hostname_lookups) {
+#endif
 #ifdef HAVE_STRUCT_SOCKADDR_IN6
 		if (af == AF_UNSPEC) {
 			char const *p;
@@ -872,22 +880,15 @@ int ip_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
 	}
 
 	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = af;
 
-#ifdef TALLOC_DEBUG
 	/*
-	 *	Avoid malloc for IP addresses.  This helps us debug
-	 *	memory errors when using talloc.
+	 *	If we're falling back we need both IPv4 and IPv6 records
 	 */
-	if (af == AF_INET) {
-		/*
-		 *	If it's all numeric, avoid getaddrinfo()
-		 */
-		if (inet_pton(af, hostname, &out->ipaddr.ip4addr) == 1) {
-			return 0;
-		}
+	if (fallback) {
+		hints.ai_family = AF_UNSPEC;
+	} else {
+		hints.ai_family = af;
 	}
-#endif
 
 	if ((rcode = getaddrinfo(hostname, NULL, &hints, &res)) != 0) {
 		fr_strerror_printf("ip_hton: %s", gai_strerror(rcode));
-- 
2.1.3