2022-02-05 14:23:32 +00:00
|
|
|
commit 45918e237cd32bb3d9a5fde83f81f83b52584771
|
|
|
|
Author: Stefan Saraev <stefan@saraev.ca>
|
|
|
|
Date: Tue Oct 1 12:09:07 2013 +0300
|
|
|
|
|
|
|
|
fix dns with broken routers
|
|
|
|
|
|
|
|
ref: https://fedoraproject.org/wiki/Networking/NameResolution/ADDRCONFIG
|
|
|
|
|
|
|
|
--- a/sysdeps/posix/getaddrinfo.c
|
|
|
|
+++ b/sysdeps/posix/getaddrinfo.c
|
2022-07-02 11:20:10 +00:00
|
|
|
@@ -730,6 +730,38 @@ gaih_inet (const char *name, const struc
|
2022-11-01 10:04:06 +00:00
|
|
|
if (res_ctx == NULL)
|
|
|
|
no_more = 1;
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2022-11-01 10:04:06 +00:00
|
|
|
+ /* AI_ADDRCONFIG determines whether or not we should suppress any
|
|
|
|
+ * hostname lookups. If the local host has only IPv4 interfaces,
|
|
|
|
+ * then suppress lookups for IPv6 addresses, and vice versa; if
|
|
|
|
+ * the local host has only IPv6 interfaces, suppress any lookups
|
|
|
|
+ * for IPv4 addresses..
|
|
|
|
+ *
|
|
|
|
+ * Link-local IPv6 addresses and loopback addresses of either
|
|
|
|
+ * family are ignored when determining whether or not the host has
|
|
|
|
+ * an interface of the given address family, cf. __check_pf().
|
|
|
|
+ *
|
|
|
|
+ * This logic is only applied for AF_UNSPEC. If the caller
|
|
|
|
+ * explicitly requested an address family, give him what he asked
|
|
|
|
+ * for.
|
|
|
|
+ *
|
|
|
|
+ * If we didn't find any interfaces of either address family,
|
|
|
|
+ * we ignore AI_ADDRCONFIG and return all available resutlts. */
|
|
|
|
+ int suppress_af = 0;
|
|
|
|
+ if (req->ai_family == AF_UNSPEC)
|
|
|
|
+ {
|
|
|
|
+ struct in6addrinfo *in6ai = NULL;
|
|
|
|
+ size_t in6ailen = 0;
|
|
|
|
+ bool seen_ipv4 = false;
|
|
|
|
+ bool seen_ipv6 = false;
|
|
|
|
+ __check_pf (&seen_ipv4, &seen_ipv6, &in6ai, &in6ailen);
|
|
|
|
+ __free_in6ai (in6ai);
|
2022-02-05 14:23:32 +00:00
|
|
|
+
|
2022-11-01 10:04:06 +00:00
|
|
|
+ if(seen_ipv4 && !seen_ipv6)
|
|
|
|
+ suppress_af = AF_INET6;
|
|
|
|
+ else if(seen_ipv6 && !seen_ipv4)
|
|
|
|
+ suppress_af = AF_INET;
|
|
|
|
+ }
|
2022-02-05 14:23:32 +00:00
|
|
|
+
|
2022-11-01 10:04:06 +00:00
|
|
|
while (!no_more)
|
|
|
|
{
|
|
|
|
no_data = 0;
|
2022-07-02 11:20:10 +00:00
|
|
|
@@ -737,7 +769,7 @@ gaih_inet (const char *name, const struc
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2022-11-01 10:04:06 +00:00
|
|
|
/* gethostbyname4_r sends out parallel A and AAAA queries and
|
|
|
|
is thus only suitable for PF_UNSPEC. */
|
|
|
|
- if (req->ai_family == PF_UNSPEC)
|
|
|
|
+ if (req->ai_family == PF_UNSPEC && !suppress_af)
|
|
|
|
fct4 = __nss_lookup_function (nip, "gethostbyname4_r");
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2022-11-01 10:04:06 +00:00
|
|
|
if (fct4 != NULL)
|
|
|
|
@@ -826,25 +858,27 @@ gaih_inet (const char *name, const struc
|
2022-02-05 14:23:32 +00:00
|
|
|
|
2022-11-01 10:04:06 +00:00
|
|
|
if (fct != NULL)
|
|
|
|
{
|
|
|
|
- if (req->ai_family == AF_INET6
|
|
|
|
- || req->ai_family == AF_UNSPEC)
|
|
|
|
+ if ((req->ai_family == AF_INET6
|
|
|
|
+ || req->ai_family == AF_UNSPEC)
|
|
|
|
+ && suppress_af != AF_INET6)
|
|
|
|
{
|
|
|
|
if ((result = gethosts (fct, AF_INET6, name, req, tmpbuf,
|
|
|
|
res, &status, &no_data)) != 0)
|
2022-02-05 14:23:32 +00:00
|
|
|
{
|
2022-11-01 10:04:06 +00:00
|
|
|
__resolv_context_put (res_ctx);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
inet6_status = status;
|
|
|
|
}
|
|
|
|
- if (req->ai_family == AF_INET
|
|
|
|
- || req->ai_family == AF_UNSPEC
|
|
|
|
- || (req->ai_family == AF_INET6
|
|
|
|
- && (req->ai_flags & AI_V4MAPPED)
|
|
|
|
- /* Avoid generating the mapped addresses if we
|
|
|
|
- know we are not going to need them. */
|
|
|
|
- && ((req->ai_flags & AI_ALL) || !res->got_ipv6)))
|
|
|
|
+ if ((req->ai_family == AF_INET
|
|
|
|
+ || req->ai_family == AF_UNSPEC
|
|
|
|
+ || (req->ai_family == AF_INET6
|
|
|
|
+ && (req->ai_flags & AI_V4MAPPED)
|
|
|
|
+ /* Avoid generating the mapped addresses if we
|
|
|
|
+ know we are not going to need them. */
|
|
|
|
+ && ((req->ai_flags & AI_ALL) || !res->got_ipv6)))
|
|
|
|
+ && suppress_af != AF_INET)
|
|
|
|
{
|
|
|
|
if ((result = gethosts (fct, AF_INET, name, req, tmpbuf,
|
|
|
|
res, &status, &no_data)) != 0)
|
2022-02-05 14:23:32 +00:00
|
|
|
--- a/sysdeps/unix/sysv/linux/check_pf.c
|
|
|
|
+++ b/sysdeps/unix/sysv/linux/check_pf.c
|
2022-07-02 11:20:10 +00:00
|
|
|
@@ -224,7 +224,8 @@ make_request (int fd, pid_t pid)
|
2022-02-05 14:23:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
- if (!IN6_IS_ADDR_LOOPBACK (address))
|
|
|
|
+ if (!IN6_IS_ADDR_LOOPBACK (address) &&
|
|
|
|
+ !IN6_IS_ADDR_LINKLOCAL (address))
|
|
|
|
seen_ipv6 = true;
|
|
|
|
}
|
|
|
|
}
|