Skip to content

Commit

Permalink
Revert "ping: fix ping6 name resolution for hostnames with link-local…
Browse files Browse the repository at this point in the history
… addresses"

This reverts commit d217170.

This removes hints.ai_family = AF_UNSPEC and check for whether the
family matches (hopefully the check itself can be removed).

Reverting allows pinging IPv4-mapped IPv6 address because getaddrinfo()
implementation in glibc supports it already, only AF_UNSPEC enforcement
from d217170 disabled effect of -4 [1]:

$ ./builddir/ping/ping -4 -c1 ::ffff:127.0.0.1
PING ::ffff:127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.061 ms

--- ::ffff:127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.061/0.061/0.061/0.000 ms

With this change the behavior matches ping from inetutils [2] and BusyBox.

Unfortunately this will not help on musl, which probably does not
support IPv4-mapped IPv6 address (although musl wiki does not mention
anything about IPv4-mapped IPv6 address support or about any related
difference from glibc [3], but libuv issue [4] mentions missing support
by default, glibc is mentioned to use ai_flags in AI_ADDRCONFIG |
AI_V4MAPPED, but even this does not help).

Original effort from issue iputils#252 [5] PR#253 [6] intended to fix pinging
IPv6 local scope address without scope ID on raw socket. Fix d217170
enabled it on raw socket, but surprisingly it works even without it:

$ ./builddir/ping/ping -v -c1 fe80::fc54:ff:fe29:5693
./builddir/ping/ping: sock4.fd: 3 (socktype: SOCK_RAW), sock6.fd: 4 (socktype: SOCK_RAW), hints.ai_family: AF_UNSPEC

ai->ai_family: AF_INET6, ai->ai_canonname: 'fe80::fc54:ff:fe29:5693'
PING fe80::fc54:ff:fe29:5693 (fe80::fc54:ff:fe29:5693) 56 data bytes
64 bytes from fe80::fc54:ff:fe29:5693%vnet0: icmp_seq=1 ident=53558 ttl=64 time=0.066 ms

--- fe80::fc54:ff:fe29:5693 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.066/0.066/0.066/0.000 ms

This issue was later considered less important (see c4b8b44),
because it does not work on ICMP datagram socket anyway.

[1] https://lists.busybox.net/pipermail/busybox/2024-October/090985.html
[2] https://lists.busybox.net/pipermail/busybox/2024-October/090985.html
[3] https://wiki.musl-libc.org/functional-differences-from-glibc.html#Name_Resolver/DNS
[4] libuv/libuv#2225
[5] iputils#252
[6] iputils#253

Suggested-by: Vo Ya <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
pevik committed Nov 17, 2024
1 parent f5b12c4 commit 3fc0dff
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions ping/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,6 @@ main(int argc, char **argv)
if (rts.tclass)
set_socket_option(&sock6, IPPROTO_IPV6, IPV6_TCLASS, &rts.tclass, sizeof(rts.tclass));

/* getaddrinfo fails to indicate a scopeid when not used in dual-stack mode.
* Work around by always using dual-stack name resolution.
*
* https://github.com/iputils/iputils/issues/252
*/
int target_ai_family = hints.ai_family;
hints.ai_family = AF_UNSPEC;

if (!strchr(target, '%') && sock6.socktype == SOCK_DGRAM &&
inet_pton(AF_INET6, target, buf) > 0 &&
(IN6_IS_ADDR_LINKLOCAL(buf) || IN6_IS_ADDR_MC_LINKLOCAL(buf))) {
Expand All @@ -703,16 +695,6 @@ main(int argc, char **argv)
str_family(ai->ai_family),
ai->ai_canonname ? ai->ai_canonname : "");

if (target_ai_family != AF_UNSPEC &&
target_ai_family != ai->ai_family) {
if (!ai->ai_next) {
/* An address was found, but not of the family we really want.
* Throw the appropriate gai error.
*/
error(2, 0, "%s: %s", target, gai_strerror(EAI_ADDRFAMILY));
}
continue;
}
switch (ai->ai_family) {
case AF_INET:
ret_val = ping4_run(&rts, argc, argv, ai, &sock4);
Expand Down

0 comments on commit 3fc0dff

Please sign in to comment.