This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 496300 - getaddrinfo with AF_INET returns duplicate IPv4 results because of IPv6 results
getaddrinfo with AF_INET returns duplicate IPv4 results because of IPv6 results
Status: ASSIGNED
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
23
All Linux
low Severity medium
: ---
: ---
Assigned To: Carlos O'Donell
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks: dualstack
  Show dependency treegraph
 
Reported: 2009-04-17 13:05 EDT by Mads Kiilerich
Modified: 2016-02-04 01:23 EST (History)
14 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-04-27 15:41:01 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
Test program for getaddrinfo (1.31 KB, text/plain)
2009-04-17 13:05 EDT, Mads Kiilerich
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
Sourceware 14969 None None None Never

  None (edit)
Description Mads Kiilerich 2009-04-17 13:05:40 EDT
Created attachment 340048 [details]
Test program for getaddrinfo

[root@localhost ~]# rpm -q glibc
glibc-2.9.90-16.i686
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.29.1-70.fc11.i686.PAE #1 SMP Mon Apr 13 14:20:28 EDT 2009 i686 i686 i386 GNU/Linux
[root@localhost ~]# cat /etc/hosts
127.0.0.1	localhost.localdomain	localhost
::1		localhost localhost.localdomain localhost6 localhost6.localdomain6

As expected getaddrinfo with AF_UNSPEC returns both IPv4 and IPv6 results:

[root@localhost ~]# python -c 'import socket; print socket.getaddrinfo("localhost", 7, socket.AF_UNSPEC, socket.SOCK_STREAM)'
[(10, 1, 6, '', ('::1', 7, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 7))]

But when I restrict to IPv4 then I get a duplicate:

[root@localhost ~]# python -c 'import socket; print socket.getaddrinfo("localhost", 7, socket.AF_INET, socket.SOCK_STREAM)'
[(2, 1, 6, '', ('127.0.0.1', 7)), (2, 1, 6, '', ('127.0.0.1', 7))]

Removing "localhost" from "::1" in /etc/hosts removes the duplicate in _both_ cases:

[mk@localhost tmp]$ python -c 'import socket; print socket.getaddrinfo("localhost", 7, socket.AF_UNSPEC, socket.SOCK_STREAM)'
[(2, 1, 6, '', ('127.0.0.1', 7))]
[mk@localhost tmp]$ python -c 'import socket; print socket.getaddrinfo("localhost", 7, socket.AF_INET, socket.SOCK_STREAM)'
[(2, 1, 6, '', ('127.0.0.1', 7))]

So it seems like IPv6 entries are partly used even when AF_INET is specified?

On Fedora 8 and Centos 5.2 it works as expected: Both IPv4 and IPv6 with AF_UNSPEC, and one IPv4 with AF_INET.

The behaviour has been verified with a C program too (attached).

Same results with and without nscd running. (Even though I _think_ I have seen it having some influence.)

Same results with and without network access to DNS server, so even though it looks a bit like bug 459756 it can't be the same.

CC'ing Ulrich because it might be feedback to his request for testing on bug 459756.
Comment 1 Ulrich Drepper 2009-04-17 13:18:17 EDT
This isn't different from duplicating any line in /etc/hosts.  You will get duplicated entries returned.  This is a bug in the system configuration and getaddrinfo just does what it is supposed to do.  Just fix your system configuration.
Comment 2 Mads Kiilerich 2009-04-17 14:26:59 EDT
setup-2.8.3-1.fc11.noarch contains /etc/hosts:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Ulrich, are you saying that is a bug?

(I don't know if other tools overwrite it with better or worse definitions, but bug 491808 made anaconda no longer touch it.)


Testing this I see that for getaddrinfo with AF_INET then 127.0.0.1 is considered exactly the same as ::1, so it will see and return duplicate entries for localhost (and localhost.localdomain). Apparently this is magic for 127.0.0.1/::1 only? And apparently the magic only applies with AF_INET; with AF_UNSPEC or AF_INET6 the lines are not considered duplicates.

Is that correctly understood?

FWIW I find this behaviour surprising and can't see why it is needed. It makes getaddrinfo with AF_INET of localhost6 return 127.0.0.1. That might be useful in some cases, but it looks like a bug to me, and it seems to me that it would be better to fix the system configuration in these cases.
Comment 3 Ulrich Drepper 2009-04-17 14:31:36 EDT
(In reply to comment #2)
> setup-2.8.3-1.fc11.noarch contains /etc/hosts:
> 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
> ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

The ::1 entry should have no localhost names associated.
Comment 4 Mads Kiilerich 2009-04-17 14:41:34 EDT
Ok. So /etc/hosts should look like
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost6 localhost6.localdomain6

For the record: That will cause applications looking localhost up with AF_UNSPEC to get 127.0.0.1 only, and with AF_INET6 they will get EAI_NONAME.

I will reopen and assign to setup.
Comment 5 Ondrej Vasik 2009-04-18 03:04:11 EDT
Adding to cc Allen Kistler, as duplicate names to /etc/hosts were added due to his request in #483244 . It is required for IPv6 only system running correctly out of the box (and e.g. Gentoo provides IPv6 and IPv4 version of localhost in /etc/hosts as well). As the multi on is activated in /etc/host.conf in recent setups, I'm reluctant to change /etc/hosts one more time without consensus what's the right way.
Comment 6 Mads Kiilerich 2009-04-18 07:43:31 EDT
It seems like there is disagreement on what the end result should be, with the crux being whether the localhost/loopback convention applies to IPv4 only or also to IPv6.

Obviously getaddrinfo of localhost with AF_INET should return 127.0.0.1 (without duplicates).

But Ulrich wants getaddrinfo of localhost with AF_UNSPEC to return 127.0.0.1 only, while Allen wants ::1 too.

And Ullrich wants getaddrinfo of localhost with AF_INET6 to return EAI_NONAME, while Allen wants ::1.

Without agreement on this we can't get a hosts file that makes everybody happy.

Another point of disagreement could be if getaddrinfo of localhost6 (if defined for ::1 only) with AF_INET should return 127.0.0.1 or EAI_NONAME.
Comment 7 Allen Kistler 2009-04-18 14:33:05 EDT
Basically localhost (the name) should be the loopback, independent of address family.  For example, "ssh -X" sets DISPLAY=localhost:10.0, even if it's running over IPv6 (as it absolutely should set it).  It's true of dual-stacked machines, not just IPv6-only machines.  It's important to consider that dual-stacked machines are going to be common eventually.  RHEL, at least, should fully support that, preferably out-of-the-box, and Fedora leads the way.

The exact change decided by the maintainers
127.0.0.1 localhost localhost4 (etc.)
::1       localhost localhost6 (etc.)
is based, I believe, on what Gentoo does.  (I'm representing the maintainers' opinion there, although I'm not one of them.  I'm not a Gentoo user, either, but I am the one who pointed it out originally.)  Have we heard complaints of brokenness from the Gentoo direction?  I think the idea is to establish a convention.  Defining different names for the same thing is not a good convention, especially since apps which are already considered to be IPv6-capable might have to be rewritten again (maybe just to treat localhost differently, maybe not).

FWIW, I still toast the localhost4 and localhost6 entries on my setups.  If apps need loopback, they should ask for localhost.  If they get two addresses, they use whichever one that applies, the same as any other name that has both an IPv4 address and an IPv6 address.  For example, your browser should be smart enough (like Firefox and Apache mod_proxy already are), to use the right address to get to www.kame.net.

$ host www.kame.net
www.kame.net has address 203.178.141.194
www.kame.net has IPv6 address 2001:200:0:8002:203:47ff:fea5:3085

Anyway, apps looking for "localhost" on IPv6 machines generate errors, if "localhost" doesn't have IPv6 equivalence, like
Error: Can't open display: localhost:10.0
because ssh (to continue the first example) is listening on ::1:6010, not 127.0.0.1:6010.

The reason the adopted change to setup didn't toast the localhost6 name is because some apps apparently have taken up the use of it.  (That's me representing the maintainers again.)  By toasting the extra names on my machines, I'm looking for those apps using localhost6.  I must not use those apps, because I haven't had any difficulties.

Unfortunately there's no RFC that's definitive on the naming.

Asking specifically for the IPv4 value of localhost and getting back two copies of 127.0.0.1 is annoying.  Worse is the "magic" mentioned that made asking for localhost6 return 127.0.0.1.  Those are getaddr* problems, not setup rpm problems.  I'd agree that those are bugs.  Yanking out some well-established code, however goofy it may be, during the freeze would be a pretty gutsy move, but I'll cheer you on if you decide to go for it.  (Last chance before RHEL6?)
Comment 8 Bug Zapper 2009-06-09 10:01:06 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 11 development cycle.
Changing version to '11'.

More information and reason for this action is here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 9 Ondrej Vasik 2009-06-22 02:22:27 EDT
*** Bug 507042 has been marked as a duplicate of this bug. ***
Comment 10 Bug Zapper 2010-04-27 09:44:14 EDT
This message is a reminder that Fedora 11 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 11.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '11'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 11's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 11 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 11 Ondrej Vasik 2010-04-27 15:41:01 EDT
Ok, as I don't plan to do any change to the current settings at the moment, I'm closing that bugzilla NOTABUG. If any particular application has some troubles with it, bugzilla should be opened against that application.
Comment 12 Pavel Šimerda (pavlix) 2012-12-18 09:01:07 EST
(In reply to comment #0)
> But when I restrict to IPv4 then I get a duplicate:
> 
> [root@localhost ~]# python -c 'import socket; print
> socket.getaddrinfo("localhost", 7, socket.AF_INET, socket.SOCK_STREAM)'
> [(2, 1, 6, '', ('127.0.0.1', 7)), (2, 1, 6, '', ('127.0.0.1', 7))]

This is clearly wrong, still the case, and needs to be fixed. Moving to rawhide, adding upstream bug report.
Comment 13 Fedora Admin XMLRPC Client 2013-01-28 15:07:44 EST
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.
Comment 14 Fedora End Of Life 2013-04-03 15:59:51 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19
Comment 15 Fedora End Of Life 2015-01-09 16:39:16 EST
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.
Comment 16 Jan Kurik 2015-07-15 11:22:04 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 23 development cycle.
Changing version to '23'.

(As we did not run this process for some time, it could affect also pre-Fedora 23 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 23 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora23

Note You need to log in before you can comment on or make changes to this bug.