Commit 0413156e authored by Florian Westphal's avatar Florian Westphal Committed by Jakub Kicinski

selftests: netfilter: conntrack_ipip_mtu.sh" move to lib.sh infra

Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20240411233624.8129-9-fw@strlen.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 954398b4
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
# Kselftest framework requirement - SKIP code is 4. source lib.sh
ksft_skip=4
# Conntrack needs to reassemble fragments in order to have complete # Conntrack needs to reassemble fragments in order to have complete
# packets for rule matching. Reassembly can lead to packet loss. # packets for rule matching. Reassembly can lead to packet loss.
...@@ -23,15 +22,8 @@ ksft_skip=4 ...@@ -23,15 +22,8 @@ ksft_skip=4
# between Client A and Client B over WAN. Wanrouter has MTU 1400 set # between Client A and Client B over WAN. Wanrouter has MTU 1400 set
# on its interfaces. # on its interfaces.
rnd=$(mktemp -u XXXXXXXX)
rx=$(mktemp) 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 (){ checktool (){
if ! $1 > /dev/null 2>&1; then if ! $1 > /dev/null 2>&1; then
echo "SKIP: Could not $2" echo "SKIP: Could not $2"
...@@ -40,29 +32,31 @@ checktool (){ ...@@ -40,29 +32,31 @@ checktool (){
} }
checktool "iptables --version" "run test without iptables" checktool "iptables --version" "run test without iptables"
checktool "ip -Version" "run test without ip tool" checktool "socat -h" "run test without socat"
checktool "which socat" "run test without socat"
checktool "ip netns add ${r_a}" "create net namespace"
for n in ${r_b} ${r_w} ${c_a} ${c_b};do setup_ns r_a r_b r_w c_a c_b
ip netns add ${n}
done
cleanup() { cleanup() {
for n in ${r_a} ${r_b} ${r_w} ${c_a} ${c_b};do cleanup_all_ns
ip netns del ${n}
done
rm -f ${rx} rm -f ${rx}
} }
trap cleanup EXIT trap cleanup EXIT
listener_ready()
{
ns="$1"
port="$2"
ss -N "$ns" -lnu -o "sport = :$port" | grep -q "$port"
}
test_path() { test_path() {
msg="$1" msg="$1"
ip netns exec ${c_b} socat -t 3 - udp4-listen:5000,reuseaddr > ${rx} < /dev/null & 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 for i in 1 2 3; do
head -c1400 /dev/zero | tr "\000" "a" | \ head -c1400 /dev/zero | tr "\000" "a" | \
ip netns exec ${c_a} socat -t 1 -u STDIN UDP:192.168.20.2:5000 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" ...@@ -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 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 ip -net ${r_b} link set $dev up
done done
...@@ -142,21 +136,18 @@ ip netns exec ${r_b} sysctl -q net.ipv4.conf.all.forwarding=1 > /dev/null ...@@ -142,21 +136,18 @@ ip netns exec ${r_b} sysctl -q net.ipv4.conf.all.forwarding=1 > /dev/null
# Client A # Client A
ip -net ${c_a} addr add 192.168.10.2/24 dev veth0 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} link set dev veth0 up
ip -net ${c_a} route add default via 192.168.10.1 ip -net ${c_a} route add default via 192.168.10.1
# Client A # Client A
ip -net ${c_b} addr add 192.168.20.2/24 dev veth0 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 veth0 up
ip -net ${c_b} link set dev lo up
ip -net ${c_b} route add default via 192.168.20.1 ip -net ${c_b} route add default via 192.168.20.1
# Wan # Wan
ip -net ${r_w} addr add 10.2.2.254/24 dev veth0 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} 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 veth0 up mtu 1400
ip -net ${r_w} link set dev veth1 up mtu 1400 ip -net ${r_w} link set dev veth1 up mtu 1400
......
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