Add a case with a vlan filtering bridge: veth0 is the untagged PVID member of VLAN 10 and the router address is on br0.10. ns1 sends its frames tagged with VID 10 and receives the replies untagged, like a switch that tags the frames it hands to the CPU. The flow has to match the tagged frames, so the forward counters stay below the file size. Then make veth0 an untagged member of VLAN 20, keeping PVID 10, and move the address to br0.20. An untagged frame from veth0 belongs to VLAN 10, so the VLAN 20 flow must not be offloaded and both forward counters see the whole file. Both cases run for IPv4 and IPv6. Signed-off-by: Julius Bairaktaris --- .../selftests/net/netfilter/nft_flowtable.sh | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable.sh b/tools/testing/selftests/net/netfilter/nft_flowtable.sh index 449c518bd947..22b5a7b888c6 100755 --- a/tools/testing/selftests/net/netfilter/nft_flowtable.sh +++ b/tools/testing/selftests/net/netfilter/nft_flowtable.sh @@ -847,10 +847,142 @@ ip -net "$nsr1" addr add dead:1::1/64 dev veth0 nodad ip -net "$nsr1" link set up dev veth0 } +check_counters_slowpath() +{ + local what=$1 + + local orig repl + orig=$(ip netns exec "$nsr1" \ + nft reset counter inet filter routed_orig | grep packets) + repl=$(ip netns exec "$nsr1" \ + nft reset counter inet filter routed_repl | grep packets) + + local orig_cnt=${orig#*bytes} + local repl_cnt=${repl#*bytes} + + local fs + fs=$(du -sb "$nsin") + local max=${fs%%/*} + + # no flow: the forward hook sees the whole file in both directions. + if [ "$orig_cnt" -le "$max" ] || [ "$repl_cnt" -le "$max" ]; then + echo "FAIL: $what: counters $orig_cnt/$repl_cnt," \ + "expected both above $max" 1>&2 + ret=1 + return + fi + + echo "PASS: $what" +} + +# Another test: +# veth0 is the untagged pvid member of VLAN 10 of a vlan filtering bridge, +# the address is on br0.10. ns1 sends frames tagged with VID 10 and gets +# them back untagged, like a switch that tags the frames it hands to the cpu. +test_bridge_vlan_pvid() { +local vid + +if ! ip -net "$nsr1" link add name br0 type bridge vlan_filtering 1 \ + vlan_default_pvid 0 2>/dev/null; then + echo "SKIP: could not add vlan filtering bridge" + [ "$ret" -eq 0 ] && ret=$ksft_skip + return +fi +ip -net "$ns1" link add name br0 type bridge \ + vlan_filtering 1 vlan_default_pvid 0 +ip -net "$nsr1" addr flush dev veth0 +ip -net "$nsr1" link set veth0 master br0 +ip -net "$nsr1" link set up dev br0 +bridge -n "$nsr1" vlan add vid 10 dev veth0 pvid untagged + +ip -net "$ns1" addr flush dev eth0 +ip -net "$ns1" link set eth0 master br0 +ip -net "$ns1" link set up dev br0 +ip -net "$ns1" addr add 10.0.1.99/24 dev br0 +ip -net "$ns1" addr add dead:1::99/64 dev br0 nodad +ip -net "$ns1" route replace default via 10.0.1.1 +ip -net "$ns1" route replace default via dead:1::1 +ip -net "$ns2" route add default via dead:2::1 + +for vid in 10 20; do + bridge -n "$nsr1" vlan add vid $vid dev br0 self + ip -net "$nsr1" link add link br0 name br0.$vid type vlan id $vid + ip -net "$nsr1" link set up dev br0.$vid + ip netns exec "$nsr1" \ + sysctl net.ipv4.conf.br0/$vid.forwarding=1 > /dev/null + + ip -net "$nsr1" addr add 10.0.1.1/24 dev br0.$vid + ip -net "$nsr1" addr add dead:1::1/64 dev br0.$vid nodad + bridge -n "$ns1" vlan add vid $vid dev eth0 pvid + bridge -n "$ns1" vlan add vid $vid dev br0 pvid untagged self + + ip netns exec "$nsr1" nft reset counters table inet filter >/dev/null + + if [ $vid -eq 20 ]; then + # veth0 sends VLAN 20 untagged, but its pvid is VLAN 10: an + # untagged frame from veth0 is not in VLAN 20, so no flow. + bridge -n "$nsr1" vlan add vid 20 dev veth0 untagged + + if test_tcp_forwarding "$ns1" "$ns2" 1 4 10.0.2.99 12345; then + check_counters_slowpath \ + "bridge vlan untagged, other pvid" + else + echo "FAIL: bridge vlan untagged, other pvid" 1>&2 + ret=1 + fi + if test_tcp_forwarding "$ns1" "$ns2" 1 6 \ + "[dead:2::99]" 12345; then + check_counters_slowpath \ + "IPv6 bridge vlan untagged, other pvid" + else + echo "FAIL: IPv6 bridge vlan untagged, other pvid" 1>&2 + ret=1 + fi + break + fi + + if test_tcp_forwarding "$ns1" "$ns2" 1 4 10.0.2.99 12345; then + check_counters "bridge vlan pvid, tagged from ns1" + else + echo "FAIL: flow offload for ns1/ns2 with bridge vlan pvid" 1>&2 + ip netns exec "$nsr1" nft list ruleset + ret=1 + fi + if test_tcp_forwarding "$ns1" "$ns2" 1 6 "[dead:2::99]" 12345; then + check_counters "IPv6 bridge vlan pvid, tagged from ns1" + else + echo "FAIL: IPv6 flow offload for ns1/ns2" \ + "with bridge vlan pvid" 1>&2 + ip netns exec "$nsr1" nft list ruleset + ret=1 + fi + + ip -net "$nsr1" link delete br0.$vid + bridge -n "$ns1" vlan del vid $vid dev eth0 + bridge -n "$ns1" vlan del vid $vid dev br0 self +done + +# restore test topology +ip -net "$nsr1" link delete br0.20 +ip -net "$nsr1" link delete br0 type bridge +ip -net "$ns1" link delete br0 type bridge +ip -net "$ns2" route del default via dead:2::1 + +ip -net "$ns1" addr add 10.0.1.99/24 dev eth0 +ip -net "$ns1" route add default via 10.0.1.1 +ip -net "$ns1" addr add dead:1::99/64 dev eth0 nodad +ip -net "$ns1" route add default via dead:1::1 +ip -net "$nsr1" addr add 10.0.1.1/24 dev veth0 +ip -net "$nsr1" addr add dead:1::1/64 dev veth0 nodad +ip -net "$nsr1" link set up dev veth0 +} + test_ipip test_bridge +test_bridge_vlan_pvid + KEY_SHA="0x"$(ps -af | sha1sum | cut -d " " -f 1) KEY_AES="0x"$(ps -af | md5sum | cut -d " " -f 1) SPI1=$RANDOM -- 2.53.0