Bug 190824 - [patch] [libc] getaddrinfo: addrconfig doesn't ignore loopback addresses
Summary: [patch] [libc] getaddrinfo: addrconfig doesn't ignore loopback addresses
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Hajimu UMEMOTO
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-09 09:17 UTC by Justin McOmie
Modified: 2014-07-01 17:41 UTC (History)
1 user (show)

See Also:


Attachments
diff (3.88 KB, text/plain)
2014-06-09 09:18 UTC, Justin McOmie
no flags Details
patch using getifaddrs (2.38 KB, patch)
2014-06-18 07:01 UTC, Justin McOmie
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin McOmie 2014-06-09 09:17:38 UTC
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
Comment 1 Justin McOmie 2014-06-09 09:18:37 UTC
Created attachment 143557 [details]
diff
Comment 2 Hajimu UMEMOTO freebsd_committer freebsd_triage 2014-06-11 18:30:53 UTC
I'll take.
Comment 3 Justin McOmie 2014-06-18 07:01:27 UTC
Created attachment 143894 [details]
patch using getifaddrs
Comment 4 commit-hook freebsd_committer freebsd_triage 2014-06-18 18:08:09 UTC
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
Comment 5 Hajimu UMEMOTO freebsd_committer freebsd_triage 2014-06-18 18:11:56 UTC
Thank you for the patch.
I've committed the change with some modification.
Comment 6 commit-hook freebsd_committer freebsd_triage 2014-06-25 17:10:35 UTC
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
Comment 7 commit-hook freebsd_committer freebsd_triage 2014-06-25 17:34:37 UTC
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
Comment 8 commit-hook freebsd_committer freebsd_triage 2014-07-01 17:32:24 UTC
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