With 'hosts: mdns4' in nsswitch.conf, getaddrinfo() returns -5 (EAI_NODATA) when network interface is down

Bug #1295229 reported by Thomas Hood
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
nss-mdns (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

When the "hosts:" line in nsswitch.conf includes `mdns4` or `mdns4_minimal` last and the network interface is taken down, getaddrinfo() returns -5 (EAI_NODATA — "No address associated with hostname") instead of something more appropriate such as -4 (EAI_FAIL — "Non-recoverable failure in name resolution").

$ dpkg -l libc6
[...]
ii libc6:amd64 2.17-93ubuntu4 amd64

$ grep hosts /etc/nsswitch.conf
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

$ sudo su
# ifconfig eth0 down
# ./a.out
Making resolv.conf empty
Results of looking up www.google.com: status = -5, errno = 110
Results of looking up a bogus name: status = -5, errno = 110
Writing correct nameserver option to resolv.conf
Results of looking up www.google.com: status = -5, errno = 110
Results of looking up a bogus name: status = -5, errno = 110
Writing incorrect nameserver option to resolv.conf
Results of looking up www.google.com: status = -5, errno = 110
Results of looking up a bogus name: status = -5, errno = 110

# cat x.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
#include <stdio.h>

struct addrinfo *res;

void check_google()
{
    int status;
    status = getaddrinfo("www.google.com", NULL, NULL, &res);
    printf("Results of looking up www.google.com: status = %d, errno = %d\n", status, errno);
    status = getaddrinfo("sjfkdsjfswfloo0f02938sjf28398sd.com", NULL, NULL, &res);
    printf("Results of looking up a bogus name: status = %d, errno = %d\n", status, errno);
}

int main()
{
    FILE *fp;

    printf("Making resolv.conf empty\n");
    fp = fopen("/etc/resolv.conf", "w+"); fclose(fp);
    sleep(1);
    check_google();

    printf("Writing nameserver option to resolv.conf\n");
    fp = fopen("/etc/resolv.conf", "w+"); fprintf(fp, "nameserver 193.67.79.39\n"); fclose(fp);
    sleep(1);
    check_google();

    printf("Writing incorrect nameserver option to resolv.conf\n");
    fp = fopen("/etc/resolv.conf", "w+"); fprintf(fp, "nameserver 192.168.5.4\n"); fclose(fp);
    sleep(1);
    check_google();
}

Thomas Hood (jdthood)
affects: eglibc (Ubuntu) → nss-mdns (Ubuntu)
Thomas Hood (jdthood)
summary: - getaddrinfo() returns -5 (EAI_FAMILY) when network interface is down
+ getaddrinfo() returns -5 (EAI_NODATA) when network interface is down
summary: - getaddrinfo() returns -5 (EAI_NODATA) when network interface is down
+ With `hosts: mdns4` getaddrinfo() returns -5 (EAI_NODATA) when network
+ interface is down
summary: - With `hosts: mdns4` getaddrinfo() returns -5 (EAI_NODATA) when network
- interface is down
+ With 'hosts: mdns4' in nsswitch.conf, getaddrinfo() returns -5
+ (EAI_NODATA) when network interface is down
Revision history for this message
TJ (tj) wrote :

I've just spent several hours along with nacc debugging this same issue affecting a user with a fresh 17.10 install, causing several minute delays when using "sudo xxxx" commands.

Changed in nss-mdns (Ubuntu):
status: New → Confirmed
Revision history for this message
Trent Lloyd (lathiat) wrote :

Thanks for the update. Can you confirm that this is purely a function of having all external network interfaces down - bringing them up immediately fixes the issue?

Revision history for this message
Trent Lloyd (lathiat) wrote :

Did a quick test with the originally attached test file, this only happens if 'mdns4' is last on the nsswitch.conf line. I don't think this is the default we ship anymore, we currently ship:

hosts: files mdns4_minimal [NOTFOUND=return] dns

TJ: Do you have the exact nsswitch.conf line the user was using?

With regards to the multi second timeouts.. this should only happen if the user is looking up a .local hostname or reverse DNS specifically for 169.254.x.x.. I'd also wonder if they had a interface with a 169.254 link-local address assigned. Do you also happen to have the output of "ip addr" and "ip -6 addr"

Alternative I am lathiat on IRC, maybe you can put me in contact with the user?

Revision history for this message
TJ (tj) wrote :

The 17.10 install was default, with:

hosts: files mdns4_minimal [NOTFOUND=return] dns

The user gave up and re-installed with 16.04 so we don't have access any more to diagnostic output.

However, the issue here was that the lookup should have been satisfied by 'files' since the system hostname was in /etc/hosts, both for IPv4 and IPv6.

Regardless of that, what nacc and myself found perplexing is the [NOTFOUND=return] - if mdns fails to resolve the name surely NSS should 'continue' and try to resolve using DNS, not return?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.