|
|
75e927 |
From a23dbf402ad466bf41c95da82e58dedc7b615f99 Mon Sep 17 00:00:00 2001
|
|
|
75e927 |
From: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
|
|
|
75e927 |
Date: Mon, 1 Dec 2014 14:15:45 -0500
|
|
|
75e927 |
Subject: [PATCH 1/2] Resolve to all families on ip_hton fallback
|
|
|
75e927 |
|
|
|
75e927 |
If we're doing fallback resolution we need to set the address family to
|
|
|
75e927 |
AF_UNSPEC to get both IPv6 and IPv4 addresses
|
|
|
75e927 |
|
|
|
75e927 |
The af that was passed in, is then used to set the preference
|
|
|
75e927 |
---
|
|
|
75e927 |
src/lib/misc.c | 25 +++++++++++++------------
|
|
|
75e927 |
1 file changed, 13 insertions(+), 12 deletions(-)
|
|
|
75e927 |
|
|
|
75e927 |
diff --git a/src/lib/misc.c b/src/lib/misc.c
|
|
|
75e927 |
index d0ccd6c..ad27057 100644
|
|
|
75e927 |
--- a/src/lib/misc.c
|
|
|
75e927 |
+++ b/src/lib/misc.c
|
|
|
75e927 |
@@ -845,7 +845,15 @@ int ip_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
|
|
|
75e927 |
int rcode;
|
|
|
75e927 |
struct addrinfo hints, *ai = NULL, *alt = NULL, *res = NULL;
|
|
|
75e927 |
|
|
|
75e927 |
+ /*
|
|
|
75e927 |
+ * Avoid malloc for IP addresses. This helps us debug
|
|
|
75e927 |
+ * memory errors when using talloc.
|
|
|
75e927 |
+ */
|
|
|
75e927 |
+#ifdef TALLOC_DEBUG
|
|
|
75e927 |
+ if (true) {
|
|
|
75e927 |
+#else
|
|
|
75e927 |
if (!fr_hostname_lookups) {
|
|
|
75e927 |
+#endif
|
|
|
75e927 |
#ifdef HAVE_STRUCT_SOCKADDR_IN6
|
|
|
75e927 |
if (af == AF_UNSPEC) {
|
|
|
75e927 |
char const *p;
|
|
|
75e927 |
@@ -872,22 +880,15 @@ int ip_hton(fr_ipaddr_t *out, int af, char const *hostname, bool fallback)
|
|
|
75e927 |
}
|
|
|
75e927 |
|
|
|
75e927 |
memset(&hints, 0, sizeof(hints));
|
|
|
75e927 |
- hints.ai_family = af;
|
|
|
75e927 |
|
|
|
75e927 |
-#ifdef TALLOC_DEBUG
|
|
|
75e927 |
/*
|
|
|
75e927 |
- * Avoid malloc for IP addresses. This helps us debug
|
|
|
75e927 |
- * memory errors when using talloc.
|
|
|
75e927 |
+ * If we're falling back we need both IPv4 and IPv6 records
|
|
|
75e927 |
*/
|
|
|
75e927 |
- if (af == AF_INET) {
|
|
|
75e927 |
- /*
|
|
|
75e927 |
- * If it's all numeric, avoid getaddrinfo()
|
|
|
75e927 |
- */
|
|
|
75e927 |
- if (inet_pton(af, hostname, &out->ipaddr.ip4addr) == 1) {
|
|
|
75e927 |
- return 0;
|
|
|
75e927 |
- }
|
|
|
75e927 |
+ if (fallback) {
|
|
|
75e927 |
+ hints.ai_family = AF_UNSPEC;
|
|
|
75e927 |
+ } else {
|
|
|
75e927 |
+ hints.ai_family = af;
|
|
|
75e927 |
}
|
|
|
75e927 |
-#endif
|
|
|
75e927 |
|
|
|
75e927 |
if ((rcode = getaddrinfo(hostname, NULL, &hints, &res)) != 0) {
|
|
|
75e927 |
fr_strerror_printf("ip_hton: %s", gai_strerror(rcode));
|
|
|
75e927 |
--
|
|
|
75e927 |
2.1.3
|
|
|
75e927 |
|