udp_io, traceroute: Standardise IPv6 PKTINFO handling to be portable

The current standard (RFC 3542) is for IPV6_RECVPKTINFO to be given to
setsockopt, and IPV6_PKTINFO to be used as the packet type. Previously,
RFC 2292 required IPV6_PKTINFO to be used for both, but RFC 3542
re-purposed IPV6_PKTINFO when given to setsockopt. The special
Linux-specific IPV6_2292PKTINFO has the same semantics as IPV6_PKTINFO
in RFC 2292, but was introduced at the same time as IPV6_RECVPKTINFO.

Therefore, if we have IPV6_RECVPKTINFO available, we can use the RFC
3542 style, and if not, we assume that only the RFC 2292 API is
available, using IPV6_PKTINFO for both.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
James Clarke 2017-10-07 18:53:23 +01:00 committed by Denys Vlasenko
parent d1535216ca
commit 518fb3ba19
2 changed files with 9 additions and 7 deletions

View File

@ -8,6 +8,10 @@
*/ */
#include "libbb.h" #include "libbb.h"
#if defined(IPV6_PKTINFO) && !defined(IPV6_RECVPKTINFO)
# define IPV6_RECVPKTINFO IPV6_PKTINFO
#endif
/* /*
* This asks kernel to let us know dst addr/port of incoming packets * This asks kernel to let us know dst addr/port of incoming packets
* We don't check for errors here. Not supported == won't be used * We don't check for errors here. Not supported == won't be used
@ -18,8 +22,8 @@ socket_want_pktinfo(int fd UNUSED_PARAM)
#ifdef IP_PKTINFO #ifdef IP_PKTINFO
setsockopt_1(fd, IPPROTO_IP, IP_PKTINFO); setsockopt_1(fd, IPPROTO_IP, IP_PKTINFO);
#endif #endif
#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO) #if ENABLE_FEATURE_IPV6 && defined(IPV6_RECVPKTINFO)
setsockopt_1(fd, IPPROTO_IPV6, IPV6_PKTINFO); setsockopt_1(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO);
#endif #endif
} }

View File

@ -311,6 +311,9 @@
# ifndef SOL_IPV6 # ifndef SOL_IPV6
# define SOL_IPV6 IPPROTO_IPV6 # define SOL_IPV6 IPPROTO_IPV6
# endif # endif
# if defined(IPV6_PKTINFO) && !defined(IPV6_RECVPKTINFO)
# define IPV6_RECVPKTINFO IPV6_PKTINFO
# endif
#endif #endif
#include "libbb.h" #include "libbb.h"
@ -911,12 +914,7 @@ common_traceroute_main(int op, char **argv)
#if ENABLE_TRACEROUTE6 #if ENABLE_TRACEROUTE6
if (af == AF_INET6) { if (af == AF_INET6) {
xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock); xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock);
# ifdef IPV6_RECVPKTINFO
setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO); setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO);
setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO);
# else
setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO);
# endif
} else } else
#endif #endif
{ {