1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 4 # This test runs a simple ingress tc setup between two veth pairs, 5 # and chains a single egress rule to test ingress chaining to egress. 6 # 7 # Kselftest framework requirement - SKIP code is 4. 8 ksft_skip=4 9 10 if [ "$(id -u)" -ne 0 ];then 11 echo "SKIP: Need root privileges" 12 exit $ksft_skip 13 fi 14 15 needed_mods="act_mirred cls_flower sch_ingress" 16 for mod in $needed_mods; do 17 modinfo $mod &>/dev/null || { echo "SKIP: Need act_mirred module"; exit $ksft_skip; } 18 done 19 20 ns="ns$((RANDOM%899+100))" 21 veth1="veth1$((RANDOM%899+100))" 22 veth2="veth2$((RANDOM%899+100))" 23 peer1="peer1$((RANDOM%899+100))" 24 peer2="peer2$((RANDOM%899+100))" 25 ip_peer1=198.51.100.5 26 ip_peer2=198.51.100.6 27 28 function fail() { 29 echo "FAIL: $@" >> /dev/stderr 30 exit 1 31 } 32 33 function cleanup() { 34 killall -q -9 udpgso_bench_rx 35 ip link del $veth1 &> /dev/null 36 ip link del $veth2 &> /dev/null 37 ip netns del $ns &> /dev/null 38 } 39 trap cleanup EXIT 40 41 function config() { 42 echo "Setup veth pairs [$veth1, $peer1], and veth pair [$veth2, $peer2]" 43 ip link add $veth1 type veth peer name $peer1 44 ip link add $veth2 type veth peer name $peer2 45 ip addr add $ip_peer1/24 dev $peer1 46 ip link set $peer1 up 47 ip netns add $ns 48 ip link set dev $peer2 netns $ns 49 ip netns exec $ns ip addr add $ip_peer2/24 dev $peer2 50 ip netns exec $ns ip link set $peer2 up 51 ip link set $veth1 up 52 ip link set $veth2 up 53 54 echo "Add tc filter ingress->egress forwarding $veth1 <-> $veth2" 55 tc qdisc add dev $veth2 ingress 56 tc qdisc add dev $veth1 ingress 57 tc filter add dev $veth2 ingress prio 1 proto all flower \ 58 action mirred egress redirect dev $veth1 59 tc filter add dev $veth1 ingress prio 1 proto all flower \ 60 action mirred egress redirect dev $veth2 61 62 echo "Add tc filter egress->ingress forwarding $peer1 -> $veth1, bypassing the veth pipe" 63 tc qdisc add dev $peer1 clsact 64 tc filter add dev $peer1 egress prio 20 proto ip flower \ 65 action mirred ingress redirect dev $veth1 66 } 67 68 function test_run() { 69 echo "Run tcp traffic" 70 ./udpgso_bench_rx -t & 71 sleep 1 72 ip netns exec $ns timeout -k 2 10 ./udpgso_bench_tx -t -l 2 -4 -D $ip_peer1 || fail "traffic failed" 73 echo "Test passed" 74 } 75 76 config 77 test_run 78 trap - EXIT 79 cleanup
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.