* [PATCH net] selftests: net: cmsg_sender: retain the resolved address family
@ 2026-11-10 3:39 Jingjing Xu
2026-11-10 6:33 ` Hangbin Liu
0 siblings, 1 reply; 2+ messages in thread
From: Jingjing Xu @ 2026-11-10 3:39 UTC (permalink / raw)
To: netdev
Cc: willemb, kuba, shuah, linux-kselftest, davem, edumazet, pabeni,
horms
When neither -4 nor -6 is supplied, getaddrinfo() selects the socket
family but opt.sock.family remains AF_UNSPEC. The cmsg and socket option
helpers then take the IPv6 branch even for an IPv4 socket.
For example, an IPv4 loopback packet sent with -l 11 arrived with the
default TTL of 64 on the test host. Using -L 11 instead failed with
ENOPROTOOPT because the tool tried IPV6_UNICAST_HOPS on an IPv4 socket.
Explicit -4 works in both cases.
Record the selected ai_family after successful address resolution so the
helpers use the same family as the socket.
Discovered by Codex-assisted code inspection and tested with real
loopback UDP traffic, without kernel instrumentation. Covered IPv4 and
IPv6, automatic and explicit family selection, and cmsg and setsockopt
hop limits. All eight cases receive the requested value after the fix.
Built through the net selftest Makefile and with GCC -Wall -Werror.
Fixes: 2e5584e0f913 ("selftests/net: expand cmsg_ipv6.sh with ipv4")
Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
---
tools/testing/selftests/net/cmsg_sender.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
index 67a72b1a2f3d..01617a021338 100644
--- a/tools/testing/selftests/net/cmsg_sender.c
+++ b/tools/testing/selftests/net/cmsg_sender.c
@@ -495,6 +495,7 @@ int main(int argc, char *argv[])
goto err_free_buff;
}
+ opt.sock.family = ai->ai_family;
if (ai->ai_family == AF_INET6 && opt.sock.proto == IPPROTO_ICMP)
opt.sock.proto = IPPROTO_ICMPV6;
base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] selftests: net: cmsg_sender: retain the resolved address family
2026-11-10 3:39 [PATCH net] selftests: net: cmsg_sender: retain the resolved address family Jingjing Xu
@ 2026-11-10 6:33 ` Hangbin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Hangbin Liu @ 2026-11-10 6:33 UTC (permalink / raw)
To: Jingjing Xu
Cc: netdev, willemb, kuba, shuah, linux-kselftest, davem, edumazet,
pabeni, horms
On Tue, Nov 10, 2026 at 03:39:18AM +0000, Jingjing Xu wrote:
> When neither -4 nor -6 is supplied, getaddrinfo() selects the socket
> family but opt.sock.family remains AF_UNSPEC. The cmsg and socket option
> helpers then take the IPv6 branch even for an IPv4 socket.
>
> For example, an IPv4 loopback packet sent with -l 11 arrived with the
> default TTL of 64 on the test host. Using -L 11 instead failed with
> ENOPROTOOPT because the tool tried IPV6_UNICAST_HOPS on an IPv4 socket.
> Explicit -4 works in both cases.
>
> Record the selected ai_family after successful address resolution so the
> helpers use the same family as the socket.
>
> Discovered by Codex-assisted code inspection and tested with real
> loopback UDP traffic, without kernel instrumentation. Covered IPv4 and
> IPv6, automatic and explicit family selection, and cmsg and setsockopt
> hop limits. All eight cases receive the requested value after the fix.
> Built through the net selftest Makefile and with GCC -Wall -Werror.
>
> Fixes: 2e5584e0f913 ("selftests/net: expand cmsg_ipv6.sh with ipv4")
> Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
> ---
> tools/testing/selftests/net/cmsg_sender.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/net/cmsg_sender.c b/tools/testing/selftests/net/cmsg_sender.c
> index 67a72b1a2f3d..01617a021338 100644
> --- a/tools/testing/selftests/net/cmsg_sender.c
> +++ b/tools/testing/selftests/net/cmsg_sender.c
> @@ -495,6 +495,7 @@ int main(int argc, char *argv[])
> goto err_free_buff;
> }
>
> + opt.sock.family = ai->ai_family;
> if (ai->ai_family == AF_INET6 && opt.sock.proto == IPPROTO_ICMP)
> opt.sock.proto = IPPROTO_ICMPV6;
>
> base-commit: 1d5e2c57e9ffc134e14b3f837c8d7c53b508bd22
> --
> 2.53.0
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-10 6:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 3:39 [PATCH net] selftests: net: cmsg_sender: retain the resolved address family Jingjing Xu
2026-11-10 6:33 ` Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox