Bug 496300 - getaddrinfo with AF_INET returns duplicate IPv4 results because of IPv6 results
Summary: getaddrinfo with AF_INET returns duplicate IPv4 results because of IPv6 results
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 29
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: glibc team
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: dualstack
TreeView+ depends on / blocked
 
Reported: 2009-04-17 17:05 UTC by Mads Kiilerich
Modified: 2019-09-10 13:25 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-09-10 13:25:30 UTC
Type: ---
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
Sourceware 14969 0 None None None 2018-12-18 11:06:28 UTC

Description Mads Kiilerich 2009-04-17 17:05:40 UTC
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 17:18:17 UTC
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 18:26:59 UTC
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 18:31:36 UTC
(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 18:41:34 UTC
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 07:04:11 UTC
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 11:43:31 UTC
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 18:33:05 UTC
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 14:01:06 UTC
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 06:22:27 UTC
*** Bug 507042 has been marked as a duplicate of this bug. ***

Comment 10 Bug Zapper 2010-04-27 13:44:14 UTC
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 19:41:01 UTC
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 14:01:07 UTC
(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 20:07:44 UTC
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 19:59:51 UTC
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 21:39:16 UTC
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 15:22:04 UTC
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

Comment 17 Fedora End Of Life 2016-11-24 10:23:38 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. 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 EOL if it remains open with a Fedora  'version'
of '23'.

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 23 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 18 Fedora End Of Life 2016-12-20 12:01:16 UTC
Fedora 23 changed to end-of-life (EOL) status on 2016-12-20. Fedora 23 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 19 Fedora End Of Life 2017-02-28 09:28:35 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 26 development cycle.
Changing version to '26'.

Comment 20 Fedora End Of Life 2018-05-03 08:51:31 UTC
This message is a reminder that Fedora 26 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 26. 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 EOL if it remains open with a Fedora  'version'
of '26'.

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 26 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 21 Florian Weimer 2018-05-03 10:58:57 UTC
Still present in rawhide.

Comment 22 Jan Kurik 2018-08-14 10:58:37 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 29 development cycle.
Changing version to '29'.

Comment 23 Florian Weimer 2019-09-10 13:25:30 UTC
This is being tracked upstream: https://sourceware.org/bugzilla/show_bug.cgi?id=14969


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