Commit f03c528e authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'selftest-netfilter-additional-cleanups'

Florian Westphal says:

====================
selftest: netfilter: additional cleanups

This is the last planned series of the netfilter-selftest-move.
It contains cleanups (and speedups) and a few small updates to
scripts to improve error/skip reporting.

I intend to route future changes, if any, via nf(-next) trees
now that the 'massive code churn' phase is over.
====================

Link: https://lore.kernel.org/r/20240423130604.7013-1-fw@strlen.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 66270920 99bc5950
...@@ -124,6 +124,10 @@ table bridge filter { ...@@ -124,6 +124,10 @@ table bridge filter {
} }
} }
EOF EOF
if [ "$?" -ne 0 ];then
echo "SKIP: could not add nftables ruleset"
exit $ksft_skip
fi
# place 1, 2 & 3 in same subnet, connected via ns0:br0. # place 1, 2 & 3 in same subnet, connected via ns0:br0.
# ns4 is placed in same subnet as well, but its not # ns4 is placed in same subnet as well, but its not
......
...@@ -43,15 +43,9 @@ cleanup() ...@@ -43,15 +43,9 @@ cleanup()
cleanup_all_ns cleanup_all_ns
} }
if ! nft --version > /dev/null 2>&1;then checktool "nft --version" "run test without nft"
echo "SKIP: Could not run test without nft tool" checktool "conntrack --version" "run test without conntrack"
exit $ksft_skip checktool "socat -h" "run test without socat"
fi
if ! conntrack --version > /dev/null 2>&1;then
echo "SKIP: Could not run test without conntrack tool"
exit $ksft_skip
fi
trap cleanup EXIT trap cleanup EXIT
...@@ -79,7 +73,15 @@ ip -net "$ns1" li set veth0 up ...@@ -79,7 +73,15 @@ ip -net "$ns1" li set veth0 up
ip -net "$ns0" addr add $IP0/$PFXL dev veth0 ip -net "$ns0" addr add $IP0/$PFXL dev veth0
ip -net "$ns1" addr add $IP1/$PFXL dev veth0 ip -net "$ns1" addr add $IP1/$PFXL dev veth0
ip netns exec "$ns1" iperf3 -s > /dev/null 2>&1 & listener_ready()
{
local ns="$1"
ss -N "$ns" -l -n -t -o "sport = :55555" | grep -q "55555"
}
ip netns exec "$ns1" socat -u -4 TCP-LISTEN:55555,reuseaddr,fork STDOUT > /dev/null &
busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1"
# test vrf ingress handling. # test vrf ingress handling.
# The incoming connection should be placed in conntrack zone 1, # The incoming connection should be placed in conntrack zone 1,
...@@ -160,16 +162,16 @@ table ip nat { ...@@ -160,16 +162,16 @@ table ip nat {
} }
} }
EOF EOF
if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null; then if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then
echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device" echo "FAIL: connect failure with masquerade + sport rewrite on vrf device"
ret=1 ret=1
return return
fi fi
# must also check that nat table was evaluated on second (lower device) iteration. # must also check that nat table was evaluated on second (lower device) iteration.
ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2' && if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1' &&
if ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then
echo "PASS: iperf3 connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" echo "PASS: connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)"
else else
echo "FAIL: vrf rules have unexpected counter value" echo "FAIL: vrf rules have unexpected counter value"
ret=1 ret=1
...@@ -195,15 +197,15 @@ table ip nat { ...@@ -195,15 +197,15 @@ table ip nat {
} }
} }
EOF EOF
if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null; then if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then
echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device" echo "FAIL: connect failure with masquerade + sport rewrite on veth device"
ret=1 ret=1
return return
fi fi
# must also check that nat table was evaluated on second (lower device) iteration. # must also check that nat table was evaluated on second (lower device) iteration.
if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2'; then if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1'; then
echo "PASS: iperf3 connect with masquerade + sport rewrite on veth device" echo "PASS: connect with masquerade + sport rewrite on veth device"
else else
echo "FAIL: vrf masq rule has unexpected counter value" echo "FAIL: vrf masq rule has unexpected counter value"
ret=1 ret=1
......
...@@ -29,7 +29,8 @@ reset rules t c ...@@ -29,7 +29,8 @@ reset rules t c
EOF EOF
if [ "$?" -ne 0 ];then if [ "$?" -ne 0 ];then
echo "SKIP: nft reset feature test failed" echo -n "SKIP: nft reset feature test failed: "
nft --version
exit $SKIP_RC exit $SKIP_RC
fi fi
......
...@@ -64,12 +64,18 @@ ip -net "$ns2" a a fec0:42::1/64 dev d0 nodad ...@@ -64,12 +64,18 @@ ip -net "$ns2" a a fec0:42::1/64 dev d0 nodad
# firewall matches to test # firewall matches to test
[ -n "$iptables" ] && { [ -n "$iptables" ] && {
common='-t raw -A PREROUTING -s 192.168.0.0/16' common='-t raw -A PREROUTING -s 192.168.0.0/16'
ip netns exec "$ns2" "$iptables" $common -m rpfilter if ! ip netns exec "$ns2" "$iptables" $common -m rpfilter;then
echo "Cannot add rpfilter rule"
exit $ksft_skip
fi
ip netns exec "$ns2" "$iptables" $common -m rpfilter --invert ip netns exec "$ns2" "$iptables" $common -m rpfilter --invert
} }
[ -n "$ip6tables" ] && { [ -n "$ip6tables" ] && {
common='-t raw -A PREROUTING -s fec0::/16' common='-t raw -A PREROUTING -s fec0::/16'
ip netns exec "$ns2" "$ip6tables" $common -m rpfilter if ! ip netns exec "$ns2" "$ip6tables" $common -m rpfilter;then
echo "Cannot add rpfilter rule"
exit $ksft_skip
fi
ip netns exec "$ns2" "$ip6tables" $common -m rpfilter --invert ip netns exec "$ns2" "$ip6tables" $common -m rpfilter --invert
} }
[ -n "$nft" ] && ip netns exec "$ns2" $nft -f - <<EOF [ -n "$nft" ] && ip netns exec "$ns2" $nft -f - <<EOF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment