Commit 99bc5950 authored by Florian Westphal's avatar Florian Westphal Committed by Jakub Kicinski

selftests: netfilter: conntrack_vrf.sh: prefer socat, not iperf3

Use socat, like most of the other scripts already do.  This also makes
the script complete slightly faster (3s -> 1s).

iperf3 establishes two connections (1 control connection, and 1+x
depending on test), so adjust expected counter values as well.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20240423130604.7013-8-fw@strlen.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent bb0ee78f
...@@ -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
......
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