NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/44915: getaddrinfo() error code usage

>Number:         44915
>Category:       lib
>Synopsis:       getaddrinfo() error code usage
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 28 12:05:01 +0000 2011
>Originator:     Havard Eidnes
>Release:        NetBSD 5.1
        I Try, Inc.
System: NetBSD 5.1 NetBSD 5.1 (MAANEN) #12: Wed Dec 22 
11:42:27 CET 2010 i386
Architecture: i386
Machine: i386
        There are a few issues with getaddrinfo() this particular PR

         - getaddrinfo() when looking for AAAA info for a name which
           has a CNAME but where the target doesn't have AAAA returns
           EAI_FAIL ("Non-recoverable failure in name resolution").

           I think RFC 3493 prescribes that EAI_NONAME should be
           returned instead.

         - getaddrinfo() makes use of the EAI_NODATA error code.
           Between RFC 2553 and RFC 3493, that error code has
           apparently been deprecated.  I have searched but not found
           the reason for this particular change; it may have come
           from the POSIX side.

         - The error text for EAI_NONAME is perhaps a bit confusing
           and also slightly misleading ("hostname nor servname
           provided, or not known"); I have tried to think of a better
           short message which is more fitting, but the best I've come
           up with so far is "Hostname/servname/address-type not found
           or not provided", which is longer and which I'm not
           entirely happy with, but it also covers the case where
           "name exists, but not the data you were looking for".

           No diff is provided for this particular issue.

        % ping6
        ping6: Non-recoverable failure in name resolution
        % dig aaaa
        ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 1, ADDITIONAL: 0
        ;; ANSWER SECTION:              1262 IN CNAME 60 IN CNAME  6583 IN CNAME

        The deprecation of EAI_NODATA can be seen by inspection in RFC

        The first hunk below removes an instance where EAI_NODATA is
        being returned, bringing us one small step closer to complying
        with RFC 3493.  EAI_NONAME is returned instead.

        The rest is so that we distinguish between "no data of
        requested type" and "(severe) lookup failure" which otherwise
        appears as the default error code.

Index: net/getaddrinfo.c
RCS file: /cvsroot/src/lib/libc/net/getaddrinfo.c,v
retrieving revision
diff -u -u -p -r1.91.6.1 getaddrinfo.c
--- net/getaddrinfo.c   26 Jan 2009 00:27:34 -0000
+++ net/getaddrinfo.c   28 Apr 2011 11:19:28 -0000
@@ -581,7 +581,7 @@ explore_fqdn(const struct addrinfo *pai,
                error = EAI_FAIL;
                goto free;
        case NS_NOTFOUND:
-               error = EAI_NODATA;
+               error = EAI_NONAME;
                goto free;
        case NS_SUCCESS:
                error = 0;
@@ -1235,7 +1235,12 @@ getanswer(const querybuf *answer, int an
                return sentinel.ai_next;
-       h_errno = NO_RECOVERY;
+       /* We could have walked a CNAME chain, */
+       /* but the ultimate target may not have what we looked for */
+       if (ntohs(hp->ancount) > 0)
+               h_errno = NO_DATA;
+       else
+               h_errno = NO_RECOVERY;
        return NULL;
@@ -1367,6 +1372,7 @@ _dns_getaddrinfo(void *rv, void   *cb_data
                switch (h_errno) {
                case HOST_NOT_FOUND:
+               case NO_DATA:
                        return NS_NOTFOUND;
                case TRY_AGAIN:
                        return NS_TRYAGAIN;

Home | Main Index | Thread Index | Old Index