The AI_ADDRCONFIG option of getaddrinfo is intended to reduce latency by excluding queries for address families not configured on the system. However loopback addresses are currently treated as "configured" addresses, effectively breaking this functionality. This patch addresses this by retooling addrconfig() to exclude addresses on loopback interfaces when looking for configured addresses. The code is based on getifaddrs.c. - This patch does not address link-local addresses with respect to AI_ADDRCONFIG. - This patch does not affect the ability to resolve numeric hosts such as '127.0.0.1', '::1', and 'ffff::%eth0', since getaddrinfo bypasses the call to addrconfig when such an address is requested. Testing: - Host info: $ ifconfig em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM> ether 00:0c:29:0d:a3:78 inet 172.16.69.133 netmask 0xffffff00 broadcast 172.16.69.255 nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> media: Ethernet autoselect (1000baseT <full-duplex>) status: active lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384 options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6> inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 inet 127.0.0.1 netmask 0xff000000 nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> - Using a test program like http://www.logix.cz/michal/devel/various/getaddrinfo.c.xp and filtering to just show the address families: - With AI_ADDRCONFIG NOT set: $ ./gai google.com | egrep -o IPv. | uniq IPv4 IPv6 $ ./gai 127.0.0.1 | egrep -o IPv. | uniq IPv4 $ ./gai fe80::1%lo0 | egrep -o IPv. | uniq IPv6 - With AI_ADDRCONFIG set: $ ./gai google.com | egrep -o IPv. | uniq IPv4 $ ./gai 127.0.0.1 | egrep -o IPv. | uniq IPv4 $ ./gai fe80::1%lo0 | egrep -o IPv. | uniq IPv6
Created attachment 143557 [details] diff
I'll take.
Created attachment 143894 [details] patch using getifaddrs
A commit references this bug: Author: ume Date: Wed Jun 18 18:07:19 UTC 2014 New revision: 267616 URL: http://svnweb.freebsd.org/changeset/base/267616 Log: Retooling addrconfig() to exclude addresses on loopback interfaces when looking for configured addresses. This change is based upon the code from the submitter, and made following changes: - Exclude addresses assigned on interfaces which are down, like NetBSD does. - Exclude addresses assigned on interfaces which are ifdisabled. PR: 190824 Submitted by: Justin McOmie MFC after: 1 week Changes: head/lib/libc/net/getaddrinfo.c
Thank you for the patch. I've committed the change with some modification.
A commit references this bug: Author: ume Date: Wed Jun 25 17:10:27 UTC 2014 New revision: 267874 URL: http://svnweb.freebsd.org/changeset/base/267874 Log: MFC r267616, 267640: Retooling addrconfig() to exclude addresses on loopback interfaces when looking for configured addresses. This change is based upon the code from the submitter, and made following changes: - Exclude addresses assigned on interfaces which are down, like NetBSD does. - Exclude addresses assigned on interfaces which are ifdisabled. Use SOCK_CLOEXEC. PR: 190824 Submitted by: Justin McOmie Changes: _U stable/10/ stable/10/lib/libc/net/getaddrinfo.c
A commit references this bug: Author: ume Date: Wed Jun 25 17:34:04 UTC 2014 New revision: 267876 URL: http://svnweb.freebsd.org/changeset/base/267876 Log: MFC r267616: Retooling addrconfig() to exclude addresses on loopback interfaces when looking for configured addresses. This change is based upon the code from the submitter, and made following changes: - Exclude addresses assigned on interfaces which are down, like NetBSD does. - Exclude addresses assigned on interfaces which are ifdisabled. PR: 190824 Submitted by: Justin McOmie Changes: _U stable/9/lib/libc/ stable/9/lib/libc/net/getaddrinfo.c
A commit references this bug: Author: ume Date: Tue Jul 1 17:31:48 UTC 2014 New revision: 268106 URL: http://svnweb.freebsd.org/changeset/base/268106 Log: MFS r267876 (MFC r267616): Retooling addrconfig() to exclude addresses on loopback interfaces when looking for configured addresses. This change is based upon the code from the submitter, and made following changes: - Exclude addresses assigned on interfaces which are down, like NetBSD does. - Exclude addresses assigned on interfaces which are ifdisabled. PR: 190824 Submitted by: Justin McOmie Approved by: re (marius) Changes: _U releng/9.3/lib/libc/ releng/9.3/lib/libc/net/getaddrinfo.c