Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
	netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
	edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
Subject: Re: [PATCH net-next 13/13] selftests: netfilter: add UDP flowtable offload test
Date: Tue, 17 Nov 2026 00:22:53 +0000	[thread overview]
Message-ID: <179487497337.3136.6527591002750060287@kernel.org> (raw)
In-Reply-To: <20261116001612.2806263-14-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] listener_ready() in nft_flowtable_udp.sh (line 111) runs `ss
  -N "$ns2" -uln -H "sport = :$port" | grep -q "$port"`.
- [Low] The test cannot detect a broken UDP checksum rewrite in the
  flowtable NAT path, although the commit message and file header…
- [Low] The header comment of nft_flowtable_udp.sh lists
  nf_flow_dnat_ipv6 and flow_offload_fixup_ct among the paths this UDP…

--

selftests: netfilter: add UDP flowtable offload test

This adds nft_flowtable_udp.sh, which sends a burst of UDP echoes through
an ingress flowtable for IPv4 and IPv6, with and without masquerade. It
checks that the payload comes back, that the forward chain sees only the
first packets of the flow, and that conntrack marks the entry OFFLOAD and
accounts every datagram.

> diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable_udp.sh b/tools/testing/selftests/net/netfilter/nft_flowtable_udp.sh
> new file mode 100755
> index 0000000000000..e0f05c76bd8ec
> --- /dev/null
> +++ b/tools/testing/selftests/net/netfilter/nft_flowtable_udp.sh
> @@ -0,0 +1,238 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# nft_flowtable.sh offloads TCP only. These UDP paths therefore stay at
> +# zero coverage in that run:
> +#
> +#   nf_flow_tuple_ip / nf_flow_tuple_ipv6          IPPROTO_UDP
> +#   nf_flow_nat_ip_udp / nf_flow_nat_port_udp      IPv4 NAT checksum
> +#   nf_flow_snat_ipv6 / nf_flow_dnat_ipv6          IPv6 NAT, including UDP
> +#   flow_offload_get_timeout / flow_offload_fixup_ct for UDP

[Severity: Low]
Does this test actually exercise nf_flow_dnat_ipv6() and
flow_offload_fixup_ct()?

The only NAT rule the script adds is a source NAT:

    nft add rule inet nat postrouting oifname "veth1" masquerade

flow_offload_alloc() sets NF_FLOW_DNAT only from IPS_DST_NAT:

net/netfilter/nf_flow_table_core.c:flow_offload_alloc() {
    ...
	if (ct->status & IPS_DST_NAT)
		__set_bit(NF_FLOW_DNAT, &flow->flags);
    ...
}

nf_flow_nat_ipv6() calls nf_flow_dnat_ipv6() only when that bit is set:

	if (test_bit(NF_FLOW_DNAT, &flow->flags)) {
		nf_flow_dnat_port(flow, skb, thoff, ip6h->nexthdr, dir);
		nf_flow_dnat_ipv6(flow, skb, ip6h, thoff, dir);

So it looks like the DNAT path never runs.

flow_offload_fixup_ct() has one caller, flow_offload_teardown(). Teardown
happens through gc expiry, ct dying, dst/MTU failures, or flowtable/netdev
cleanup. None of these happen during the four run_case() checks.
Teardown only happens when the EXIT trap deletes the namespaces, which is
after every check has finished. A regression in the UDP fixup_ct path
would therefore not fail this test.

Also, tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c already
sends UDP through a flowtable. The "zero coverage" wording only holds
because of the "in that run" qualifier.

Could these entries be removed from the header? The other option is to
add a DNAT case (for example a prerouting dnat rule) and an explicit
teardown/fixup check.

[ ... ]

> +ip link add veth0 netns "$nsr" type veth peer name eth0 netns "$ns1"
> +ip link add veth1 netns "$nsr" type veth peer name eth0 netns "$ns2"
> +
> +ip -net "$nsr" link set veth0 up
> +ip -net "$nsr" link set veth1 up
> +ip -net "$ns1" link set eth0 up
> +ip -net "$ns2" link set eth0 up

[Severity: Low]
Can this test detect a broken UDP checksum rewrite in the masquerade
cases?

The veth pairs keep their default features. VETH_FEATURES includes
NETIF_F_HW_CSUM, so the datagrams socat sends from ns1 and ns2 are
CHECKSUM_PARTIAL.

For those skbs, nf_flow_nat_ip_udp() and the IPv6 equivalent,
nf_flow_nat_ipv6_l4proto(), only patch the pseudo-header partial sum:

	if (udph->check || skb->ip_summed == CHECKSUM_PARTIAL) {
		inet_proto_csum_replace4(&udph->check, skb, addr,
					 new_addr, true);

The skb is still CHECKSUM_PARTIAL when it reaches the peer namespace.
skb_csum_unnecessary() returns true for it, so the receiving UDP stack
never verifies the checksum.

The only correctness check is the payload echo in udp_exchange():

	if ! IFS= read -r -n 4 -t 2 got <&"${SO[0]}"; then

That check passes whether the rewrite is right or wrong. The
full-checksum (non-PARTIAL) branch of the rewrite never runs either.

Would it make sense to run "ethtool -K eth0 tx off" in ns1 and ns2, so
the datagrams carry full checksums that the receiver verifies? If not,
the header and commit message could say that checksum correctness is not
verified.

[ ... ]

> +listener_ready() {
> +	ss -N "$ns2" -uln -H "sport = :$port" | grep -q "$port"
> +}
> +
> +ip netns exec "$ns2" socat -T 60 \
> +	UDP4-LISTEN:"$port",reuseaddr,fork EXEC:cat >/dev/null 2>&1 &
> +ip netns exec "$ns2" socat -T 60 \
> +	UDP6-LISTEN:"$port",reuseaddr,ipv6only=1,fork EXEC:cat >/dev/null 2>&1 &
> +
> +if ! busywait 3000 listener_ready; then
> +	echo "FAIL: UDP listener did not start" >&2
> +	exit 1
> +fi

[Severity: Medium]
Can listener_ready() succeed when only one of the two listeners has
bound?

The ss query covers both address families. The grep matches as soon as
either the UDP4-LISTEN or the UDP6-LISTEN socat has bound port 12345.
busywait() returns on the first success via loopy_wait() in lib.sh:

	if out=$("$@"); then
		echo -n "$out"

The two socat processes start in the background at the same time.
Nothing orders their binds.

If the IPv6 listener binds first, the script goes straight to
run_case "IPv4 UDP". udp_exchange() can then send datagram 0 to
10.0.2.99:12345 before the UDP4 socat is listening. ns2 drops it with an
ICMP port unreachable, and the read times out. The run then reports
"FAIL: packet 0 timeout" and "IPv4 UDP: payload was not forwarded" for a
reason that has nothing to do with the flowtable.

Could the check wait for both sockets? For example, it could query
ss -4 and ss -6 separately, or require two matching lines.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116001612.2806263-2-pablo%40netfilter.org

      reply	other threads:[~2026-11-17  0:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  0:15 [PATCH net-next,v2 00/13] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-16  0:16 ` [PATCH net-next 01/13] netfilter: flowtable: do not hw offload flows in teardown state Pablo Neira Ayuso
2026-11-16  0:23   ` netdev-bot+sinfo
2026-11-16  0:27     ` Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 02/13] netfilter: flowtable: retrieve stats on flow deletion Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 03/13] net: ethernet: mtk_ppe: update " Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 04/13] net: airoha: " Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 05/13] netfilter: xt_time: fix monthday computation for dates past 2039 Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 06/13] netfilter: nft_flow_offload: do not offload multicast Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 07/13] netfilter: flowtable: purge entries immediately when destroying the flowtable Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 08/13] selftests: netfilter: nf_queue: drop the no-op loop initializer Pablo Neira Ayuso
2026-11-16  0:16 ` [PATCH net-next 09/13] netfilter: flowtable: do not scrub as crossing netns Pablo Neira Ayuso
2026-11-17  0:22   ` netdev-bot+sashiko
2026-11-16  0:16 ` [PATCH net-next 10/13] netfilter: flowtable: tunnel device poisons h_source of fast-path frames Pablo Neira Ayuso
2026-11-16  0:16 ` [PATCH net-next 11/13] netfilter: flowtable: do not clear the offload bit twice Pablo Neira Ayuso
2026-11-16  0:16 ` [PATCH net-next 12/13] netfilter: nfnetlink_queue: make skb writable before writing NFQA_L2HDR Pablo Neira Ayuso
2026-11-16  0:16 ` [PATCH net-next 13/13] selftests: netfilter: add UDP flowtable offload test Pablo Neira Ayuso
2026-11-17  0:22   ` 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=179487497337.3136.6527591002750060287@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=horms@kernel.org \
    --cc=ja@ssi.bg \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.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