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. 8ksft_skip=4 9 10if [ "$(id -u)" -ne 0 ];then 11 echo "SKIP: Need root privileges" 12 exit $ksft_skip 13fi 14 15needed_mods="act_mirred cls_flower sch_ingress" 16for mod in $needed_mods; do 17 modinfo $mod &>/dev/null || { echo "SKIP: Need act_mirred module"; exit $ksft_skip; } 18done 19 20ns="ns$((RANDOM%899+100))" 21veth1="veth1$((RANDOM%899+100))" 22veth2="veth2$((RANDOM%899+100))" 23peer1="peer1$((RANDOM%899+100))" 24peer2="peer2$((RANDOM%899+100))" 25ip_peer1=198.51.100.5 26ip_peer2=198.51.100.6 27 28function fail() { 29 echo "FAIL: $@" >> /dev/stderr 30 exit 1 31} 32 33function 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} 39trap cleanup EXIT 40 41function 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 68function 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 76config 77test_run 78trap - EXIT 79cleanup 80