Netdev List
 help / color / mirror / Atom feed
From: willemb@google.com
To: Kalash Nainwal via B4 Relay
	<devnull+kalash.nexthop.ai@kernel.org>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	 David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	 Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>
Cc: Shuah Khan <shuah@kernel.org>,
	Joel Granados <joel.granados@kernel.org>,
	netdev@vger.kernel.org,  linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	Kalash Nainwal <kalash@nexthop.ai>
Subject: Re: [PATCH net-next v3 1/2] tcp: add net.ipv4.tcp_l3mdev_exempt_ports sysctl
Date: Thu, 03 Dec 2026 23:03:12 -0500	[thread overview]
Message-ID: <willemb.ddd823353b4f@google.com> (raw)
In-Reply-To: <20261127-tcp-l3mdev-exempt-ports-v3-1-f875b1184f26@nexthop.ai>

Kalash Nainwal via B4 Relay wrote:
> From: Kalash Nainwal <kalash@nexthop.ai>

> With tcp_l3mdev_accept=1, an unbound listener also matches connections
> that arrive in a VRF. If a VRF-bound listener exists on the same port
> and both use SO_REUSEPORT, the lookup returns whichever is first in the
> listen bucket, not the VRF-bound one. Since AF_INET and AF_INET6
> reuseport sockets are inserted at opposite ends of the bucket, the same
> setup can pick the VRF-bound listener for IPv4 and the unbound one for
> IPv6.

> This breaks, for example, a BGP daemon with a TCP-MD5 key only on its
> VRF-bound listener: IPv6 peers in the VRF reach the unbound listener
> and the session comes up without MD5.

> Add net.ipv4.tcp_l3mdev_exempt_ports, a per-netns port list in the
> same format as ip_local_reserved_ports. For a listed port, an unbound
> listener does not match connections that arrive in a VRF, so only a
> listener bound to the VRF or to the receiving device can take them.
> Only listener lookup changes. Other ports and default-VRF traffic are
> not affected. The default is empty.

> This is opt-in rather than a change to the lookup itself. With both
> listeners present, existing setups get a stable result that depends on
> creation order and address family; making the bound listener always
> win would change that for every tcp_l3mdev_accept user.

     This compatibility argument does not justify adding a permanent  
65536-bit
     port bitmap sysctl (and 8 KiB per network namespace) instead of fixing
     listener lookup:

     1. The current behavior is explicitly documented as unspecified, not a
        UAPI contract. Documentation/networking/vrf.rst (commit b1165777fe0b)
        already warns that with tcp_l3mdev_accept=1 "it is unspecified which
        listening socket will be selected to handle connections for VRF
        traffic" and calls out this exact TCP-MD5 failure mode.

     2. No deployment can meaningfully rely on the current behavior. Because
        inet_hash() prepends AF_INET sockets (LIFO) and appends AF_INET6
        SO_REUSEPORT sockets (FIFO), the same startup order selects opposite
        listeners for IPv4 vs IPv6, and any daemon/VRF restart flips the
        winner. Worse, whenever the unbound listener sits ahead in the  
bucket,
        the VRF-bound listener is completely unreachable (it cannot match
        non-VRF traffic and its own VRF traffic is stolen). For non-reuseport
        listeners, compute_score() already prefers sk_bound_dev_if != 0.

     3. Netdev precedent is to fix SO_REUSEPORT short-circuit shadowing in  
the
        lookup without a sysctl:
        - d894ba18d4e4 ("soreuseport: fix ordering for mixed v4/v6 sockets")
        - d9fbc7f6431f / 0ee58dad5b06 ("net: tcp[6]: prefer listeners bound  
to
          an address")
        - 8d6c414cd2fb ("net: prefer socket bound to interface when not in  
VRF")

     4. The bitmap sysctl leaves the real bug unfixed everywhere else: every
        unlisted port keeps the IPv4/IPv6 divergence and MD5/AO bypass,
        non-VRF SO_BINDTODEVICE + unbound SO_REUSEPORT (sdif == 0) remains
        broken regardless of the sysctl, and UDP (udp_l3mdev_accept=1,
        udp[46]_lib_lookup2() when !reuseport_has_conns()) has the same early
        return.

     Please drop the sysctl and rework the series to fix device-bound
     listener preference in inet_lhash2_lookup() / inet6_lhash2_lookup()

  reply	other threads:[~2026-12-04  4:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 22:15 [PATCH net-next v3 0/2] tcp: add net.ipv4.tcp_l3mdev_exempt_ports sysctl Kalash Nainwal via B4 Relay
2026-11-27 22:15 ` [PATCH net-next v3 1/2] " Kalash Nainwal via B4 Relay
2026-12-04  4:03   ` willemb [this message]
2026-11-27 22:15 ` [PATCH net-next v3 2/2] selftests: net: add tcp_l3mdev_exempt_ports test Kalash Nainwal via B4 Relay

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=willemb.ddd823353b4f@google.com \
    --to=willemb@google.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devnull+kalash.nexthop.ai@kernel.org \
    --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