96 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3PORT_RANGE_NUM_NETIFS=24 5port_range_h1_create()6{7 simple_if_init $h18}9 10port_range_h1_destroy()11{12 simple_if_fini $h113}14 15port_range_switch_create()16{17 simple_if_init $swp118 tc qdisc add dev $swp1 clsact19}20 21port_range_switch_destroy()22{23 tc qdisc del dev $swp1 clsact24 simple_if_fini $swp125}26 27port_range_rules_create()28{29 local count=$1; shift30 local should_fail=$1; shift31 local batch_file="$(mktemp)"32 33 for ((i = 0; i < count; ++i)); do34 cat >> $batch_file <<-EOF35 filter add dev $swp1 ingress \36 prot ipv4 \37 pref 1000 \38 flower skip_sw \39 ip_proto udp dst_port 1-$((100 + i)) \40 action pass41 EOF42 done43 44 tc -b $batch_file45 check_err_fail $should_fail $? "Rule insertion"46 47 rm -f $batch_file48}49 50__port_range_test()51{52 local count=$1; shift53 local should_fail=$1; shift54 55 port_range_rules_create $count $should_fail56 57 offload_count=$(tc -j filter show dev $swp1 ingress |58 jq "[.[] | select(.options.in_hw == true)] | length")59 ((offload_count == count))60 check_err_fail $should_fail $? "port range offload count"61}62 63port_range_test()64{65 local count=$1; shift66 local should_fail=$1; shift67 68 if ! tc_offload_check $PORT_RANGE_NUM_NETIFS; then69 check_err 1 "Could not test offloaded functionality"70 return71 fi72 73 __port_range_test $count $should_fail74}75 76port_range_setup_prepare()77{78 h1=${NETIFS[p1]}79 swp1=${NETIFS[p2]}80 81 vrf_prepare82 83 port_range_h1_create84 port_range_switch_create85}86 87port_range_cleanup()88{89 pre_cleanup90 91 port_range_switch_destroy92 port_range_h1_destroy93 94 vrf_cleanup95}96