273 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test VLAN classification after routing and verify that the order of5# configuration does not impact switch behavior. Verify that {RIF, Port}->VID6# mapping is added correctly for existing {Port, VID}->FID mapping and that7# {RIF, Port}->VID mapping is added correctly for new {Port, VID}->FID mapping.8 9# +-------------------+ +--------------------+10# | H1 | | H2 |11# | | | |12# | $h1.10 + | | + $h2.10 |13# | 192.0.2.1/28 | | | | 192.0.2.3/28 |14# | | | | | |15# | $h1 + | | + $h2 |16# +----------------|--+ +--|-----------------+17# | |18# +----------------|-------------------------|-----------------+19# | SW $swp1 + + $swp2 |20# | | | |21# | +--------------|-------------------------|---------------+ |22# | | $swp1.10 + + $swp2.10 | |23# | | | |24# | | br0 | |25# | | 192.0.2.2/28 | |26# | +--------------------------------------------------------+ |27# | |28# | $swp3.20 + |29# | 192.0.2.17/28 | |30# | | |31# | $swp3 + |32# +---------------|--------------------------------------------+33# |34# +---------------|--+35# | $h3 + |36# | | |37# | $h3.20 + |38# | 192.0.2.18/28 |39# | |40# | H3 |41# +------------------+42 43lib_dir=$(dirname $0)/../../../net/forwarding44 45ALL_TESTS="46 port_vid_map_rif47 rif_port_vid_map48"49 50NUM_NETIFS=651source $lib_dir/lib.sh52source $lib_dir/tc_common.sh53source $lib_dir/devlink_lib.sh54 55h1_create()56{57 simple_if_init $h158 vlan_create $h1 10 v$h1 192.0.2.1/2859 60 ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.261}62 63h1_destroy()64{65 ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.266 67 vlan_destroy $h1 1068 simple_if_fini $h169}70 71h2_create()72{73 simple_if_init $h274 vlan_create $h2 10 v$h2 192.0.2.3/2875}76 77h2_destroy()78{79 vlan_destroy $h2 1080 simple_if_fini $h281}82 83h3_create()84{85 simple_if_init $h386 vlan_create $h3 20 v$h3 192.0.2.18/2887 88 ip route add 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1789}90 91h3_destroy()92{93 ip route del 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1794 95 vlan_destroy $h3 2096 simple_if_fini $h397}98 99switch_create()100{101 ip link set dev $swp1 up102 tc qdisc add dev $swp1 clsact103 104 ip link add dev br0 type bridge mcast_snooping 0105 106 # By default, a link-local address is generated when netdevice becomes107 # up. Adding an address to the bridge will cause creating a RIF for it.108 # Prevent generating link-local address to be able to control when the109 # RIF is added.110 sysctl_set net.ipv6.conf.br0.addr_gen_mode 1111 ip link set dev br0 up112 113 ip link set dev $swp2 up114 vlan_create $swp2 10115 ip link set dev $swp2.10 master br0116 117 ip link set dev $swp3 up118 vlan_create $swp3 20 "" 192.0.2.17/28119 120 # Replace neighbor to avoid 1 packet which is forwarded in software due121 # to "unresolved neigh".122 ip neigh replace dev $swp3.20 192.0.2.18 lladdr $(mac_get $h3.20)123}124 125switch_destroy()126{127 vlan_destroy $swp3 20128 ip link set dev $swp3 down129 130 ip link set dev $swp2.10 nomaster131 vlan_destroy $swp2 10132 ip link set dev $swp2 down133 134 ip link set dev br0 down135 sysctl_restore net.ipv6.conf.br0.addr_gen_mode136 ip link del dev br0137 138 tc qdisc del dev $swp1 clsact139 ip link set dev $swp1 down140}141 142setup_prepare()143{144 h1=${NETIFS[p1]}145 swp1=${NETIFS[p2]}146 147 swp2=${NETIFS[p3]}148 h2=${NETIFS[p4]}149 150 swp3=${NETIFS[p5]}151 h3=${NETIFS[p6]}152 153 vrf_prepare154 forwarding_enable155 156 h1_create157 h2_create158 h3_create159 160 switch_create161}162 163cleanup()164{165 pre_cleanup166 167 switch_destroy168 169 h3_destroy170 h2_destroy171 h1_destroy172 173 forwarding_restore174 vrf_cleanup175}176 177bridge_rif_add()178{179 rifs_occ_t0=$(devlink_resource_occ_get rifs)180 __addr_add_del br0 add 192.0.2.2/28181 rifs_occ_t1=$(devlink_resource_occ_get rifs)182 183 expected_rifs=$((rifs_occ_t0 + 1))184 185 [[ $expected_rifs -eq $rifs_occ_t1 ]]186 check_err $? "Expected $expected_rifs RIFs, $rifs_occ_t1 are used"187 188 sleep 1189}190 191bridge_rif_del()192{193 __addr_add_del br0 del 192.0.2.2/28194}195 196port_vid_map_rif()197{198 RET=0199 200 # First add {port, VID}->FID for swp1.10, then add a RIF and verify that201 # packets get the correct VID after routing.202 vlan_create $swp1 10203 ip link set dev $swp1.10 master br0204 bridge_rif_add205 206 # Replace neighbor to avoid 1 packet which is forwarded in software due207 # to "unresolved neigh".208 ip neigh replace dev br0 192.0.2.1 lladdr $(mac_get $h1.10)209 210 # The hardware matches on the first ethertype which is not VLAN,211 # so the protocol should be IP.212 tc filter add dev $swp1 egress protocol ip pref 1 handle 101 \213 flower skip_sw dst_ip 192.0.2.1 action pass214 215 ping_do $h1.10 192.0.2.18216 check_err $? "Ping failed"217 218 tc_check_at_least_x_packets "dev $swp1 egress" 101 10219 check_err $? "Packets were not routed in hardware"220 221 log_test "Add RIF for existing {port, VID}->FID mapping"222 223 tc filter del dev $swp1 egress224 225 bridge_rif_del226 ip link set dev $swp1.10 nomaster227 vlan_destroy $swp1 10228}229 230rif_port_vid_map()231{232 RET=0233 234 # First add an address to the bridge, which will create a RIF on top of235 # it, then add a new {port, VID}->FID mapping and verify that packets236 # get the correct VID after routing.237 bridge_rif_add238 vlan_create $swp1 10239 ip link set dev $swp1.10 master br0240 241 # Replace neighbor to avoid 1 packet which is forwarded in software due242 # to "unresolved neigh".243 ip neigh replace dev br0 192.0.2.1 lladdr $(mac_get $h1.10)244 245 # The hardware matches on the first ethertype which is not VLAN,246 # so the protocol should be IP.247 tc filter add dev $swp1 egress protocol ip pref 1 handle 101 \248 flower skip_sw dst_ip 192.0.2.1 action pass249 250 ping_do $h1.10 192.0.2.18251 check_err $? "Ping failed"252 253 tc_check_at_least_x_packets "dev $swp1 egress" 101 10254 check_err $? "Packets were not routed in hardware"255 256 log_test "Add {port, VID}->FID mapping for FID with a RIF"257 258 tc filter del dev $swp1 egress259 260 ip link set dev $swp1.10 nomaster261 vlan_destroy $swp1 10262 bridge_rif_del263}264 265trap cleanup EXIT266 267setup_prepare268setup_wait269 270tests_run271 272exit $EXIT_STATUS273