[PATCH 1/1] ping: Fix hop limit (TTL) handling for IPv6
Radoslav Kolev
radoslav.kolev at suse.com
Thu May 22 14:59:52 UTC 2025
Setting the hop limit was not implemented for IPv6. Also there was
a hack to override IPV6_HOPLIMIT to the value of IPV6_2292HOPLIMIT,
which was only introduced for backwards compatibility when RFC 3542
superseded RFC 2292. The proper way is to use IPV6_RECVHOPLIMIT in
the setsockopt call when requesting the value and IPV6_HOPLIMIT only
when retrieving it.
Signed-off-by: Radoslav Kolev <radoslav.kolev at suse.com>
---
networking/ping.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/networking/ping.c b/networking/ping.c
index b7e6955a9..4e1979d5a 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -92,8 +92,7 @@
//usage: "\n -s SIZE Send SIZE data bytes in packets (default 56)"
//usage: "\n -i SECS Interval"
//usage: "\n -A Ping as soon as reply is received"
-///////: "\n -t TTL Set TTL"
-///////^^^^^ -t not tested for IPv6, might be not working
+//usage: "\n -t TTL Set TTL"
//usage: "\n -I IFACE/IP Source interface or IP address"
//usage: "\n -W SEC Seconds to wait for the first response (default 10)"
//usage: "\n (after all -c CNT packets are sent)"
@@ -156,12 +155,6 @@
#if ENABLE_PING6
# include <netinet/icmp6.h>
-/* I see RENUMBERED constants in bits/in.h - !!?
- * What a fuck is going on with libc? Is it a glibc joke? */
-# ifdef IPV6_2292HOPLIMIT
-# undef IPV6_HOPLIMIT
-# define IPV6_HOPLIMIT IPV6_2292HOPLIMIT
-# endif
#endif
#if defined(__FreeBSD__)
@@ -844,6 +837,12 @@ static void ping6(len_and_sockaddr *lsa)
/* enable broadcast pings */
setsockopt_broadcast(pingsock);
+ if (opt_ttl != 0) {
+ setsockopt_int(pingsock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, opt_ttl);
+ /* above doesn't affect packets sent to bcast IP, so... */
+ setsockopt_int(pingsock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, opt_ttl);
+ }
+
/* set recv buf (needed if we can get lots of responses: flood ping,
* broadcast ping etc) */
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
@@ -854,7 +853,7 @@ static void ping6(len_and_sockaddr *lsa)
setsockopt_int(pingsock, SOL_RAW, IPV6_CHECKSUM, sockopt);
/* request ttl info to be returned in ancillary data */
- setsockopt_1(pingsock, SOL_IPV6, IPV6_HOPLIMIT);
+ setsockopt_1(pingsock, SOL_IPV6, IPV6_RECVHOPLIMIT);
if (if_index)
pingaddr.sin6.sin6_scope_id = if_index;
--
2.49.0
More information about the busybox
mailing list