1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4NUM_NETIFS=4 5source tc_common.sh 6source lib.sh 7 8tcflags="skip_hw" 9 10h1_create() 11{ 12 simple_if_init $h1 192.0.2.1/24 13} 14 15h1_destroy() 16{ 17 simple_if_fini $h1 192.0.2.1/24 18} 19 20h2_create() 21{ 22 simple_if_init $h2 192.0.2.1/24 23} 24 25h2_destroy() 26{ 27 simple_if_fini $h2 192.0.2.1/24 28} 29 30switch_create() 31{ 32 simple_if_init $swp1 192.0.2.2/24 33 tc qdisc add dev $swp1 ingress_block 22 egress_block 23 clsact 34 35 simple_if_init $swp2 192.0.2.2/24 36 tc qdisc add dev $swp2 ingress_block 22 egress_block 23 clsact 37} 38 39switch_destroy() 40{ 41 tc qdisc del dev $swp2 clsact 42 simple_if_fini $swp2 192.0.2.2/24 43 44 tc qdisc del dev $swp1 clsact 45 simple_if_fini $swp1 192.0.2.2/24 46} 47 48shared_block_test() 49{ 50 RET=0 51 52 tc filter add block 22 protocol ip pref 1 handle 101 flower \ 53 $tcflags dst_ip 192.0.2.2 action drop 54 55 $MZ $h1 -c 1 -p 64 -a $h1mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \ 56 -t ip -q 57 58 tc_check_packets "block 22" 101 1 59 check_err $? "Did not match first incoming packet on a block" 60 61 $MZ $h2 -c 1 -p 64 -a $h2mac -b $swmac -A 192.0.2.1 -B 192.0.2.2 \ 62 -t ip -q 63 64 tc_check_packets "block 22" 101 2 65 check_err $? "Did not match second incoming packet on a block" 66 67 tc filter del block 22 protocol ip pref 1 handle 101 flower 68 69 log_test "shared block ($tcflags)" 70} 71 72setup_prepare() 73{ 74 h1=${NETIFS[p1]} 75 swp1=${NETIFS[p2]} 76 77 swp2=${NETIFS[p3]} 78 h2=${NETIFS[p4]} 79 80 h1mac=$(mac_get $h1) 81 h2mac=$(mac_get $h2) 82 83 swmac=$(mac_get $swp1) 84 swp2origmac=$(mac_get $swp2) 85 ip link set $swp2 address $swmac 86 87 vrf_prepare 88 89 h1_create 90 h2_create 91 switch_create 92} 93 94cleanup() 95{ 96 pre_cleanup 97 98 switch_destroy 99 h2_destroy 100 h1_destroy 101 102 vrf_cleanup 103 104 ip link set $swp2 address $swp2origmac 105} 106 107trap cleanup EXIT 108 109setup_prepare 110setup_wait 111 112shared_block_test 113 114tc_offload_check 115if [[ $? -ne 0 ]]; then 116 log_info "Could not test offloaded functionality" 117else 118 tcflags="skip_sw" 119 shared_block_test 120fi 121 122exit $EXIT_STATUS 123