diff --git a/CHANGES b/CHANGES index aba9093b7b..2c8a9b59f4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +5089. [bug] Restore localhost fallback in dig and host which is + used when no nameserver addresses present in + /etc/resolv.conf are usable due to the requested + address family restrictions. [GL #433] + 5088. [bug] dig/host/nslookup could crash when interrupted close to a query timeout. [GL #599] diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 410b63435b..5d35e79439 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -1227,6 +1227,19 @@ create_search_list(irs_resconf_t *resconf) { } } +/*% + * Append 'addr' to the list of servers to be queried. This function is only + * called when no server addresses are explicitly specified and either libirs + * returns an empty list of servers to use or none of the addresses returned by + * libirs are usable due to the specified address family restrictions. + */ +static void +add_fallback_nameserver(const char *addr) { + dig_server_t *server = make_server(addr, addr); + ISC_LINK_INIT(server, link); + ISC_LIST_APPEND(server_list, server, link); +} + /*% * Setup the system as a whole, reading key information and resolv.conf * settings. @@ -1272,6 +1285,16 @@ setup_system(bool ipv4only, bool ipv6only) { get_server_list(resconf); } + /* If we don't find a nameserver fall back to localhost */ + if (ISC_LIST_EMPTY(server_list)) { + if (have_ipv6) { + add_fallback_nameserver("::1"); + } + if (have_ipv4) { + add_fallback_nameserver("127.0.0.1"); + } + } + irs_resconf_destroy(&resconf); #ifdef HAVE_SETLOCALE