[PATCH nf-next 4/4] selftests: netfilter: cover a TCP flow whose reply is never seen
From: Julius Bairaktaris <hidden>
Date: 2026-09-10 09:01:04
Also in:
netfilter-devel
Subsystem:
kernel selftest framework, netfilter, networking [general], the rest · Maintainers:
Shuah Khan, Shuah Khan, Pablo Neira Ayuso, Florian Westphal, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
Add an arm to nft_flowtable.sh in which ns2 answers over a direct link, so that nsr1 sees the original direction only. The forward hook counter then has to stay far below the size of the transferred file, which only happens if the flowtable takes the connection over. Signed-off-by: Julius Bairaktaris <redacted> Assisted-by: Claude:claude-opus-5 --- .../selftests/net/netfilter/nft_flowtable.sh | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+)
diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable.sh b/tools/testing/selftests/net/netfilter/nft_flowtable.sh
index 449c518bd947..516a544266f1 100755
--- a/tools/testing/selftests/net/netfilter/nft_flowtable.sh
+++ b/tools/testing/selftests/net/netfilter/nft_flowtable.sh@@ -516,6 +516,79 @@ else ret=1 fi +# Asymmetric path test: +# ns2 answers over a direct link, so nsr1 sees the original direction only. +# Such a connection never becomes assured, but the flowtable is expected to +# take over the direction that nsr1 does see. +check_orig_offloaded() +{ + local what=$1 + + local orig + orig=$(ip netns exec "$nsr1" nft reset counter inet filter routed_orig | grep packets) + local orig_cnt=${orig#*bytes} + + local fs + fs=$(du -sb "$nsin") + local max_orig=$(( ${fs%%/*} / 2 )) + + # the flowtable takes over after the first few packets, so the forward + # hook must see a small fraction of the transferred file. + if [ "$orig_cnt" -gt "$max_orig" ];then + echo "FAIL: $what: original counter $orig_cnt exceeds expected value $max_orig" 1>&2 + ret=1 + return 1 + fi + + echo "PASS: $what" +} + +test_asymmetric_path() +{ + ip link add name eth1 netns "$ns1" type veth peer name eth1 netns "$ns2" + ip -net "$ns1" addr add 10.0.9.99/24 dev eth1 + ip -net "$ns2" addr add 10.0.9.98/24 dev eth1 + ip -net "$ns1" addr add dead:9::99/64 dev eth1 nodad + ip -net "$ns2" addr add dead:9::98/64 dev eth1 nodad + ip -net "$ns1" link set eth1 up + ip -net "$ns2" link set eth1 up + + # ns1 keeps sending through nsr1, ns2 answers on the direct link. + ip -net "$ns2" route add 10.0.1.99 via 10.0.9.99 dev eth1 + ip -6 -net "$ns2" route add dead:1::99 via dead:9::99 dev eth1 + + ip netns exec "$ns1" sysctl -q net.ipv4.ip_no_pmtu_disc=0 + ip netns exec "$ns2" sysctl -q net.ipv4.ip_no_pmtu_disc=0 + + ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null + + if test_tcp_forwarding "$ns1" "$ns2" 1 4 10.0.2.99 12345; then + check_orig_offloaded "flow offloaded for ns1/ns2 without reply" + else + echo "FAIL: flow offload for ns1/ns2 without reply" 1>&2 + ip netns exec "$nsr1" nft list ruleset 1>&2 + ret=1 + fi + + ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null + + if test_tcp_forwarding "$ns1" "$ns2" 1 6 "[dead:2::99]" 12345; then + check_orig_offloaded "IPv6 flow offloaded for ns1/ns2 without reply" + else + echo "FAIL: IPv6 flow offload for ns1/ns2 without reply" 1>&2 + ip netns exec "$nsr1" nft list ruleset 1>&2 + ret=1 + fi + + ip netns exec "$ns1" sysctl -q net.ipv4.ip_no_pmtu_disc=1 + ip netns exec "$ns2" sysctl -q net.ipv4.ip_no_pmtu_disc=1 + + ip -net "$ns1" link del eth1 + ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null +} + +test_asymmetric_path + # delete default route, i.e. ns2 won't be able to reach ns1 and # will depend on ns1 being masqueraded in nsr1. # expect ns1 has nsr1 address.
--
2.53.0