selftests: netfilter: conntrack_ipip_mtu.sh" move to lib.sh infra
authorFlorian Westphal <fw@strlen.de>
Thu, 11 Apr 2024 23:36:13 +0000 (01:36 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 13 Apr 2024 00:51:25 +0000 (17:51 -0700)
Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20240411233624.8129-9-fw@strlen.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/netfilter/conntrack_ipip_mtu.sh

index eb9553e4986b01861709c0b4c533885213c30f6a..f87ca4c59d3b69ec20a135374a15cdf51eda6a02 100755 (executable)
@@ -1,8 +1,7 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
-# Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
+source lib.sh
 
 # Conntrack needs to reassemble fragments in order to have complete
 # packets for rule matching.  Reassembly can lead to packet loss.
@@ -23,15 +22,8 @@ ksft_skip=4
 # between Client A and Client B over WAN. Wanrouter has MTU 1400 set
 # on its interfaces.
 
-rnd=$(mktemp -u XXXXXXXX)
 rx=$(mktemp)
 
-r_a="ns-ra-$rnd"
-r_b="ns-rb-$rnd"
-r_w="ns-rw-$rnd"
-c_a="ns-ca-$rnd"
-c_b="ns-cb-$rnd"
-
 checktool (){
        if ! $1 > /dev/null 2>&1; then
                echo "SKIP: Could not $2"
@@ -40,29 +32,31 @@ checktool (){
 }
 
 checktool "iptables --version" "run test without iptables"
-checktool "ip -Version" "run test without ip tool"
-checktool "which socat" "run test without socat"
-checktool "ip netns add ${r_a}" "create net namespace"
+checktool "socat -h" "run test without socat"
 
-for n in ${r_b} ${r_w} ${c_a} ${c_b};do
-       ip netns add ${n}
-done
+setup_ns r_a r_b r_w c_a c_b
 
 cleanup() {
-       for n in ${r_a} ${r_b} ${r_w} ${c_a} ${c_b};do
-               ip netns del ${n}
-       done
+       cleanup_all_ns
        rm -f ${rx}
 }
 
 trap cleanup EXIT
 
+listener_ready()
+{
+       ns="$1"
+       port="$2"
+       ss -N "$ns" -lnu -o "sport = :$port" | grep -q "$port"
+}
+
 test_path() {
        msg="$1"
 
        ip netns exec ${c_b} socat -t 3 - udp4-listen:5000,reuseaddr > ${rx} < /dev/null &
 
-       sleep 1
+       busywait $BUSYWAIT_TIMEOUT listener_ready "$c_b" 5000
+
        for i in 1 2 3; do
                head -c1400 /dev/zero | tr "\000" "a" | \
                        ip netns exec ${c_a} socat -t 1 -u STDIN UDP:192.168.20.2:5000
@@ -129,7 +123,7 @@ r_addr="10.2.2.1"
 
 ip netns exec ${r_b} ip link add ipip0 type ipip local ${l_addr} remote ${r_addr} mode ipip || exit $ksft_skip
 
-for dev in lo veth0 veth1 ipip0; do
+for dev in veth0 veth1 ipip0; do
        ip -net ${r_b} link set $dev up
 done
 
@@ -142,21 +136,18 @@ ip netns exec ${r_b} sysctl -q net.ipv4.conf.all.forwarding=1 > /dev/null
 
 # Client A
 ip -net ${c_a} addr add 192.168.10.2/24 dev veth0
-ip -net ${c_a} link set dev lo up
 ip -net ${c_a} link set dev veth0 up
 ip -net ${c_a} route add default via 192.168.10.1
 
 # Client A
 ip -net ${c_b} addr add 192.168.20.2/24 dev veth0
 ip -net ${c_b} link set dev veth0 up
-ip -net ${c_b} link set dev lo up
 ip -net ${c_b} route add default via 192.168.20.1
 
 # Wan
 ip -net ${r_w} addr add 10.2.2.254/24 dev veth0
 ip -net ${r_w} addr add 10.4.4.254/24 dev veth1
 
-ip -net ${r_w} link set dev lo up
 ip -net ${r_w} link set dev veth0 up mtu 1400
 ip -net ${r_w} link set dev veth1 up mtu 1400