Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: kalash@nexthop.ai
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
	skhan@linuxfoundation.org, rdunlap@infradead.org,
	dsahern@kernel.org, idosch@nvidia.com, ncardwell@google.com,
	kuniyu@google.com, shuah@kernel.org, joel.granados@kernel.org,
	netdev@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v2 2/2] selftests: net: add tcp_l3mdev_exempt_ports test
Date: Thu, 26 Nov 2026 21:20:27 +0000	[thread overview]
Message-ID: <179572802703.3135.17411865692194388871@kernel.org> (raw)
In-Reply-To: <20261125-tcp-l3mdev-exempt-ports-v2-2-b920f3ff8f5e@nexthop.ai>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The header comment of the new test script
  tools/testing/selftests/net/tcp_l3mdev_exempt_ports.sh (lines 8-9)…
- [Low] In vrf_and_unbound_listeners() in
  tools/testing/selftests/net/tcp_l3mdev_exempt_ports.sh, the first…

--

selftests: net: add tcp_l3mdev_exempt_ports test

This adds a selftest for net.ipv4.tcp_l3mdev_exempt_ports. With
tcp_l3mdev_accept=1 and the port exempted, it checks that a VRF
connection reaches the VRF-bound listener in either creation order and
is refused by an unbound-only listener. It also checks that default-VRF
connections still reach the unbound listener, for both IPv4 and IPv6.

> diff --git a/tools/testing/selftests/net/tcp_l3mdev_exempt_ports.sh b/tools/testing/selftests/net/tcp_l3mdev_exempt_ports.sh
> new file mode 100755
> index 0000000000000..da7f20bf2e9e6
> --- /dev/null
> +++ b/tools/testing/selftests/net/tcp_l3mdev_exempt_ports.sh
> @@ -0,0 +1,260 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Test net.ipv4.tcp_l3mdev_exempt_ports.
> +#
> +# With tcp_l3mdev_accept=1, a listener that is not bound to a device also
> +# matches connections that arrive in a VRF. For a port listed in
> +# tcp_l3mdev_exempt_ports it must not: only a listener bound to the VRF
> +# may take such a connection. Connections in the default VRF are not
> +# affected.

[Severity: Low]
This isn't a bug, but is this comment narrower than what the kernel
does?

Documentation/networking/ip-sysctl.rst describes tcp_l3mdev_exempt_ports
as:

    only a listen socket bound to the L3
    master device or to the receiving device can accept them.

The check in compute_score() (net/ipv4/inet_hashtables.c, and its twin
in net/ipv6/inet6_hashtables.c) only rejects sockets with no bound
device:

    if (!sk->sk_bound_dev_if && sdif &&
        tcp_port_l3mdev_exempt(net, hnum))
            return -1;

A listener bound to the slave device (veth_vrf here) still matches
through the sdif comparison in inet_sk_bound_dev_eq().

Could the comment say "bound to the VRF or to the receiving device"?

Also, none of the cases uses a listener bound to the slave device, so
that documented behaviour has no test coverage. Would it be worth adding
one?

[ ... ]

> +# Start a server in the background. nettest sets SO_REUSEPORT on its
> +# listeners, so an unbound and a VRF-bound listener can share the port.
> +# $1: IP version, $2: "vrf" or "unbound"
> +start_server()
> +{
> +	local args=()
> +
> +	[ "$1" = 6 ] && args+=(-6)
> +	[ "$2" = vrf ] && args+=(-I "$VRF")
> +	ip netns exec "$ns_s" nettest "${args[@]}" -s -p "$PORT" -t 3 -q &
> +}

[ ... ]

> +		for order in "unbound vrf" "vrf unbound"; do
> +			read -r first second <<< "$order"
> +			RET=0
> +
> +			start_server "$ver" "$first"
> +			pid_first=$!
> +			wait_listeners 1
> +			check_err $? "first listener did not start"
> +			start_server "$ver" "$second"
> +			pid_second=$!
> +			wait_listeners 2
> +			check_err $? "second listener did not start"
> +
> +			connect "$ns_c" "$ver" "$addr"
> +			check_err $? "VRF connection failed"

[Severity: Low]
Can the first server time out before the client's SYN arrives here?

start_server() gives each nettest a fixed -t 3. In nettest.c, do_server()
does a single select() with that budget right after listen(), and closes
the listener when it expires:

tools/testing/selftests/net/nettest.c:do_server() {
    ...
		rc = select(lsd+1, &rfds, NULL, NULL, ptval);
		if (rc == 0) {
			rc = 2;
			break;
		}
    ...
}

The first server's 3 second timer is already running while the script
does all of this:

  - finishes the slowwait poll
  - starts the second server through ip netns exec
  - polls until wait_listeners 2 sees two listeners (up to 2s)
  - starts the client through ip netns exec

On a slow or debug kernel (KASAN, lockdep) these steps can add up to
about 3s.

With order "vrf unbound", the VRF listener would then be gone. The
exempt port makes the unbound listener refuse the connection, so the
connect fails and rc_vrf is 2, even though the kernel behaved correctly.

With order "unbound vrf", the unbound listener exits early. The
check_timeout() on rc_unbound then passes trivially, and the subtest no
longer shows that the unbound listener was skipped.

If wait_listeners itself times out, check_err records it, but the
subtest still goes on to connect.

Would a server -t larger than the total wait budget avoid this?

> +
> +			wait "$pid_first"
> +			rc_first=$?
> +			wait "$pid_second"
> +			rc_second=$?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-tcp-l3mdev-exempt-ports-v2-0-b920f3ff8f5e%40nexthop.ai

      reply	other threads:[~2026-11-26 21:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 21:17 [PATCH net-next v2 0/2] tcp: add net.ipv4.tcp_l3mdev_exempt_ports sysctl Kalash Nainwal via B4 Relay
2026-11-25 21:17 ` [PATCH net-next v2 1/2] " Kalash Nainwal via B4 Relay
2026-11-26 21:20   ` netdev-bot+sashiko
2026-11-25 21:17 ` [PATCH net-next v2 2/2] selftests: net: add tcp_l3mdev_exempt_ports test Kalash Nainwal via B4 Relay
2026-11-26 21:20   ` netdev-bot+sashiko [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=179572802703.3135.17411865692194388871@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=joel.granados@kernel.org \
    --cc=kalash@nexthop.ai \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /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