From: Hangbin Liu <hangbin.liu@linux.dev>
To: Jingjing Xu <xujingjing@cmss.chinamobile.com>
Cc: netdev@vger.kernel.org, willemb@google.com, kuba@kernel.org,
shuah@kernel.org, linux-kselftest@vger.kernel.org,
davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
horms@kernel.org
Subject: Re: [PATCH net] selftests: net: cmsg_sender: retain the resolved address family
Date: Tue, 10 Nov 2026 14:33:02 +0800 [thread overview]
Message-ID: <avK6ngiakOhpKYbg@fedora> (raw)
In-Reply-To: <20261110033918.49238-1-xujingjing@cmss.chinamobile.com>
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>
prev parent reply other threads:[~2026-11-10 6:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=avK6ngiakOhpKYbg@fedora \
--to=hangbin.liu@linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
--cc=xujingjing@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox