Bug 14413 - nsswitch doesn't implement getaddrinfo(), plugins cannot provide full getaddrinfo features
Summary: nsswitch doesn't implement getaddrinfo(), plugins cannot provide full getaddr...
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 19565
Blocks: 2099 16826
  Show dependency treegraph
 
Reported: 2012-07-27 15:13 UTC by Pavel Šimerda
Modified: 2025-10-07 17:53 UTC (History)
17 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:
fweimer: security-


Attachments
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch (800 bytes, patch)
2025-10-07 00:25 UTC, Patrick Griffis
Details | Diff
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch (818 bytes, patch)
2025-10-07 17:22 UTC, Patrick Griffis
Details | Diff
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch (815 bytes, patch)
2025-10-07 17:35 UTC, Patrick Griffis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Šimerda 2012-07-27 15:13:10 UTC
GLIBC's name service switch doesn't provide a way to override getaddressinfo()
which is the only function that supports IPv6 link-local addresses.

IPv6 link-local addresses don't work without the interface name (when
written as text) that then translates to scope id.

http://tools.ietf.org/html/rfc2553

glibc-2.15-37.fc17.x86_64
Comment 1 Pavel Šimerda 2012-07-27 15:15:46 UTC
Fedora bug:

https://bugzilla.redhat.com/show_bug.cgi?id=843054

This is actually needed for link-local name resolution (whatever NSS plugin is used for it then).
Comment 2 Pavel Šimerda 2012-07-31 13:31:37 UTC
There's another usecase for getaddrinfo() in nsswitch and that is avoiding problems caused by solutions to bug 12377 including bug 12398. See discussions
in these two bug reports.
Comment 3 Alexandre Oliva 2014-06-02 03:32:38 UTC
Hi, Pavel,

I assume you're speaking of such addresses as ipv6%zone, as specified in RFC 4007.  That RFC only specifies (hex) numeric addresses in standard ipv6 format, folowed by a % and a zone id, that may be numeric, an interface name, or somesuch.

Since the address can only be numeric, without involving any lookups, and that and zone ids specified in that RFC are supported by existing getaddrinfo core implementation, what would the point be of introducing a getaddrinfo interface in the nss plugin interface?
Comment 4 Pavel Šimerda 2014-06-02 08:32:32 UTC
Hi Alexandre,

1) scope_id

There are name services that are capable of returning IPv6 link local addresses such as Multicast DNS. Those IPv6 link local addresses don't work as expected, though, as they miss the scope_id.

2) AI_ADDRCONFIG

There are name resolution protocols that should avoid querying for IPv4/IPv6 data according to the system configuration when AI_ADDRCONFIG is set. On the other hand, for literal address translations, Multicast DNS and /etc/hosts, this is counter-productive, see the linked bug reports.

3) __nss_gethostbyname*

The gethostbyname4 features are not superset of gethostbyname3 features which means the API is not satisfactory whichever of them is used.
Comment 5 Henrique 2017-03-12 03:50:15 UTC
Hello, I can confirm that this bug is still present. IPv6 link local addresses (fe80::/64) only work when coupled with sockaddr_in6.sin6_scope_id (some interface number). Since gethostent only returns the address (through hostent.h_addr_list), then all IPv6 link local addresses are returned in an incomplete way and so are broken.

This is why mdns does not work in linux with link local addresses.

Comparing with MacOS, getaddrinfo() seems to be implemented by the nss plugin, so executing ssh -6 host.local works. In linux, executing ssh -6 host.local does not work.
Comment 6 Florian Weimer 2017-03-13 09:56:02 UTC
We need to redesign the NSS interface anyway, but I'd prefer if we had the NSS modules allocate the required memory, after bug 19591 is fixed.
Comment 7 Florian Weimer 2019-12-03 09:33:12 UTC
Fixing bug 19591 is not necessary if we add a function to the NSS module which frees the allocated data structures.
Comment 8 Gavin 2020-04-07 19:53:29 UTC
Confirming that this issue still exists as of 2.31.

ssh -v host.local works:

OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/gavin/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to host.local [fe80::88aa:55ff:fec5:dd9%wlan0] port 22.
debug1: Connection established.

ssh -v -6 host.local does not work:

OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/gavin/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to host.local [fe80::88aa:55ff:fec5:dd9] port 22.
debug1: connect to address fe80::88aa:55ff:fec5:dd9 port 22: Invalid argument

The first case calls get getaddrinfo() with hints->ai_family=AF_UNSPEC, the second case calls it with hints->ai_family=AF_INET6.

As a workaround until gethostbyname5 comes along, would it make sense to modify gethostbyname3 such that it stuffs a whole sockaddr_in6 into h_addr, sets h_length to sizeof(sockaddr_in6), and glibc can take care of it accordingly depending on the value of h_length?
Comment 9 Patrick Griffis 2025-10-01 20:48:10 UTC
(In reply to Gavin from comment #8)
> Confirming that this issue still exists as of 2.31.
> 
> ssh -v host.local works:
> 
> ssh -v -6 host.local does not work:

I believe this issue was introduced by bug 14505
Comment 10 Matthijs van Duin 2025-10-06 22:23:27 UTC
(In reply to Patrick Griffis from comment #9)
> I believe this issue was introduced by bug 14505

Yes, the root cause of bug 14505 was gethostbyname4's inexplicable lack of support for filtering by address family, but instead it was "fixed" by conditionally reverting to gethostbyname3, blatantly ignoring the obvious fact that gethostbyname4 was introduced for good reason.

Given that bug 14505 only seems to be avoid superfluous DNS queries, while this bug causes severe breakage (in particular causes link-local IPv6 to be non-functional in Google Chrome since it does parallel IPv4-only and IPv6-only as part of the Happy Eyeballs algorithm), the obvious thing to do would be to fix this issue by reverting that patch and reopening 14505 for the longer-term fix of extending the API.
Comment 11 Matthijs van Duin 2025-10-06 22:30:01 UTC
(Actually I just remembered that link-local IPv6 is broken Chrome for multiple reasons, this bug just being one of them, so fixing this won't fix Chrome unfortunately. However at least it would still fix ssh -6 and every other program that uses getaddrinfo and has a similar IPv6-only option)
Comment 12 Patrick Griffis 2025-10-07 00:25:06 UTC
Created attachment 16412 [details]
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch

Yes that was the issue I ran into with glib's usage.

I can confirm the attached patch fixes it.
Comment 13 Petr Menšík 2025-10-07 09:58:48 UTC
I would add into the comment explicitly that scope_id and flowinfo are not present in hostent and link-local IPv6 needs them to work.
Comment 14 Patrick Griffis 2025-10-07 17:22:22 UTC
Created attachment 16413 [details]
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch

Updated comment.

Can patches from here be landed?
Comment 15 Matthijs van Duin 2025-10-07 17:30:06 UTC
(In reply to Petr Menšík from comment #13)
> I would add into the comment explicitly that scope_id and flowinfo are not
> present in hostent and link-local IPv6 needs them to work.

Just scope_id actually. flowinfo isn't related to link-local addressing (and is also ignored by the kernel by default)
Comment 16 Patrick Griffis 2025-10-07 17:35:40 UTC
Created attachment 16414 [details]
0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch
Comment 17 Adhemerval Zanella 2025-10-07 17:53:20 UTC
(In reply to Patrick Griffis from comment #14)
> Created attachment 16413 [details]
> 0001-Use-gethostbyname4_r-when-requesting-IPv6-addresses.patch
> 
> Updated comment.
> 
> Can patches from here be landed?

Patches are reviewed on libc-alpha maillist, could you check the wiki [1] and send the proposed fix?

[1] https://sourceware.org/glibc/wiki/Contribution%20checklist