214 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4lib_dir=$(dirname $0)/../../../net/forwarding5 6ALL_TESTS="7 mac_profile_test8"9NUM_NETIFS=410source $lib_dir/lib.sh11source $lib_dir/tc_common.sh12source $lib_dir/devlink_lib.sh13 14h1_create()15{16 simple_if_init $h1 192.0.2.1/2417 ip route add 198.51.100.0/24 vrf v$h1 nexthop via 192.0.2.218 19 tc qdisc add dev $h1 ingress20}21 22h1_destroy()23{24 tc qdisc del dev $h1 ingress25 26 ip route del 198.51.100.0/24 vrf v$h127 simple_if_fini $h1 192.0.2.1/2428}29 30h2_create()31{32 simple_if_init $h2 198.51.100.1/2433 ip route add 192.0.2.0/24 vrf v$h2 nexthop via 198.51.100.234 35 tc qdisc add dev $h2 ingress36}37 38h2_destroy()39{40 tc qdisc del dev $h2 ingress41 42 ip route del 192.0.2.0/24 vrf v$h243 simple_if_fini $h2 198.51.100.1/2444}45 46router_create()47{48 ip link set dev $rp1 up49 ip link set dev $rp2 up50 51 tc qdisc add dev $rp1 clsact52 tc qdisc add dev $rp2 clsact53 ip address add 192.0.2.2/24 dev $rp154 ip address add 198.51.100.2/24 dev $rp255}56 57router_destroy()58{59 ip address del 198.51.100.2/24 dev $rp260 ip address del 192.0.2.2/24 dev $rp161 tc qdisc del dev $rp2 clsact62 tc qdisc del dev $rp1 clsact63 64 ip link set dev $rp2 down65 ip link set dev $rp1 down66}67 68setup_prepare()69{70 h1=${NETIFS[p1]}71 rp1=${NETIFS[p2]}72 73 rp2=${NETIFS[p3]}74 h2=${NETIFS[p4]}75 76 vrf_prepare77 78 h1_create79 h2_create80 81 router_create82 83 forwarding_enable84}85 86cleanup()87{88 pre_cleanup89 90 forwarding_restore91 92 router_destroy93 94 h2_destroy95 h1_destroy96 97 vrf_cleanup98}99 100h1_to_h2()101{102 local test_name=$@; shift103 local smac=$(mac_get $rp2)104 105 RET=0106 107 # Replace neighbour to avoid first packet being forwarded in software108 ip neigh replace dev $rp2 198.51.100.1 lladdr $(mac_get $h2)109 110 # Add a filter to ensure that packets are forwarded in hardware. Cannot111 # match on source MAC because it is not set in eACL after routing112 tc filter add dev $rp2 egress proto ip pref 1 handle 101 \113 flower skip_sw ip_proto udp src_port 12345 dst_port 54321 \114 action pass115 116 # Add a filter to ensure that packets are received with the correct117 # source MAC118 tc filter add dev $h2 ingress proto ip pref 1 handle 101 \119 flower skip_sw src_mac $smac ip_proto udp src_port 12345 \120 dst_port 54321 action pass121 122 $MZ $h1 -a own -b $(mac_get $rp1) -t udp "sp=12345,dp=54321" \123 -A 192.0.2.1 -B 198.51.100.1 -c 10 -p 100 -d 1msec -q124 125 tc_check_packets "dev $rp2 egress" 101 10126 check_err $? "packets not forwarded in hardware"127 128 tc_check_packets "dev $h2 ingress" 101 10129 check_err $? "packets not forwarded with correct source mac"130 131 log_test "h1->h2: $test_name"132 133 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower134 tc filter del dev $rp2 egress protocol ip pref 1 handle 101 flower135 ip neigh del dev $rp2 198.51.100.1 lladdr $(mac_get $h2)136}137 138h2_to_h1()139{140 local test_name=$@; shift141 local rp1_mac=$(mac_get $rp1)142 143 RET=0144 145 ip neigh replace dev $rp1 192.0.2.1 lladdr $(mac_get $h1)146 147 tc filter add dev $rp1 egress proto ip pref 1 handle 101 \148 flower skip_sw ip_proto udp src_port 54321 dst_port 12345 \149 action pass150 151 tc filter add dev $h1 ingress proto ip pref 1 handle 101 \152 flower skip_sw src_mac $rp1_mac ip_proto udp src_port 54321 \153 dst_port 12345 action pass154 155 $MZ $h2 -a own -b $(mac_get $rp2) -t udp "sp=54321,dp=12345" \156 -A 198.51.100.1 -B 192.0.2.1 -c 10 -p 100 -d 1msec -q157 158 tc_check_packets "dev $rp1 egress" 101 10159 check_err $? "packets not forwarded in hardware"160 161 tc_check_packets "dev $h1 ingress" 101 10162 check_err $? "packets not forwarded with correct source mac"163 164 log_test "h2->h1: $test_name"165 166 tc filter del dev $h1 ingress protocol ip pref 1 handle 101 flower167 tc filter del dev $rp1 egress protocol ip pref 1 handle 101 flower168 ip neigh del dev $rp1 192.0.2.1 lladdr $(mac_get $h1)169}170 171smac_test()172{173 local test_name=$@; shift174 175 # Test that packets forwarded to $h2 via $rp2 are forwarded with the176 # current source MAC of $rp2177 h1_to_h2 $test_name178 179 # Test that packets forwarded to $h1 via $rp1 are forwarded with the180 # current source MAC of $rp1. This MAC is never changed during the test,181 # but given the shared nature of MAC profile, the point is to see that182 # changes to the MAC of $rp2 do not affect that of $rp1183 h2_to_h1 $test_name184}185 186mac_profile_test()187{188 local rp2_mac=$(mac_get $rp2)189 190 # Test behavior when the RIF backing $rp2 is transitioned to use191 # a new MAC profile192 ip link set dev $rp2 addr 00:11:22:33:44:55193 smac_test "new mac profile"194 195 # Test behavior when the MAC profile used by the RIF is edited196 ip link set dev $rp2 address 00:22:22:22:22:22197 smac_test "edit mac profile"198 199 # Restore original MAC200 ip link set dev $rp2 addr $rp2_mac201}202 203trap cleanup EXIT204 205setup_prepare206setup_wait207 208mac_profiles=$(devlink_resource_size_get rif_mac_profiles)209if [[ $mac_profiles -ne 1 ]]; then210 tests_run211fi212 213exit $EXIT_STATUS214