Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Sep 2022 15:53:12 -0500
From:      Mike Karels <mike@karels.net>
To:        freebsd-net@freebsd.org
Subject:   getaddrinfo error for existing host without requested address family
Message-ID:  <202209272053.28RKrDEa004321@mail.karels.net>

next in thread | raw e-mail | index | archive | help
I recently noticed the following behavior:

% ping6 redrock
ping6: Name does not resolve
% host redrock
redrock.karels.net has address 10.0.2.2
redrock.karels.net mail is handled by 10 mail.karels.net.
% ping6 nonexistenthost
ping6: Name does not resolve

The first error message is misleading, because the name *does* resolve,
but has no AAAA record, and it is the same error message as for a name
that truly does not exist.  The problem comes from the set of error
codes that getaddrinfo() returns in these two cases.  The problem did
not exist with gethostbyname(), which has separate error codes for the
two (although gethostbyname did not have provision for IPv6, it handled
cases like domain names and mail domains without IPv4 addresses).

getaddrinfo() uses a richer set of error codes than gethostbyname(), but
still misses this case.  However, looking at <netdb.h>, I see

#if 0
/* Obsoleted on RFC 2553bis-02 */
#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
#endif
...
#if 0
/* Obsoleted on RFC 2553bis-02 */
#define	EAI_NODATA	 7	/* no address associated with hostname */
#endif

I don't know why these two were omitted from the update to RFC 2553, but
the first seems to me to be the correct error for an existing name without
an address for the requested address family.  Also, that is the error
message produced by Linux (Ubuntu 22.04.1).

NetBSD and OpenBSD produce the second of these two errors for a host
without the requested address.  But they also produce the same error
when a name does not exist.

RFC 2553bis-02 has timed out, and is replaced by RFC 3493, which is also
missing EAI_ADDRFAMILY.  These are informational RFCs, not specifying an
Internet standard.

I propose re-enabling EAI_ADDRFAMILY and using it for the situation
where a name exists but does not have an address in the requested family.
This would make the error in the example less misleading, and would behave
the same as Linux in this regard.  The change to netdb.h is trivial, but
getaddrinfo() needs a little more work because it uses the NS_* errors
from <nsswitch.h> internally and then translates.  But it will benefit
from greater accuracy in other cases as well (e.g.  "out of memory"
rather than "Name does not resolve").

Comments?  I have a change in progress, but wanted to float the idea
before I finish it and put it into review.

		Mike



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209272053.28RKrDEa004321>