brintos

brintos / linux-shallow public Read only

0
0
Text · 6.1 KiB · 7d7f862 Raw
264 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Test routing over bridge and verify that the order of configuration does not5# impact switch behavior. Verify that RIF is added correctly for existing6# mappings and that new mappings use the correct RIF.7 8# +-------------------+                   +--------------------+9# | H1                |                   | H2                 |10# |                   |                   |                    |11# |         $h1.10 +  |                   |  + $h2.10          |12# |   192.0.2.1/28 |  |                   |  | 192.0.2.3/28    |13# |                |  |                   |  |                 |14# |            $h1 +  |                   |  + $h2             |15# +----------------|--+                   +--|-----------------+16#                  |                         |17# +----------------|-------------------------|-----------------+18# | SW       $swp1 +                         + $swp2           |19# |                |                         |                 |20# | +--------------|-------------------------|---------------+ |21# | |     $swp1.10 +                         + $swp2.10      | |22# | |                                                        | |23# | |                           br0                          | |24# | |                       192.0.2.2/28                     | |25# | +--------------------------------------------------------+ |26# |                                                            |27# |      $swp3.10 +                                            |28# | 192.0.2.17/28 |                                            |29# |               |                                            |30# |         $swp3 +                                            |31# +---------------|--------------------------------------------+32#                 |33# +---------------|--+34# |           $h3 +  |35# |               |  |36# |        $h3.10 +  |37# | 192.0.2.18/28    |38# |                  |39# | H3               |40# +------------------+41 42lib_dir=$(dirname $0)/../../../net/forwarding43 44ALL_TESTS="45	port_vid_map_rif46	rif_port_vid_map47"48 49NUM_NETIFS=650source $lib_dir/lib.sh51source $lib_dir/tc_common.sh52source $lib_dir/devlink_lib.sh53 54h1_create()55{56	simple_if_init $h157	vlan_create $h1 10 v$h1 192.0.2.1/2858 59	ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.260}61 62h1_destroy()63{64	ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.265 66	vlan_destroy $h1 1067	simple_if_fini $h168}69 70h2_create()71{72	simple_if_init $h273	vlan_create $h2 10 v$h2 192.0.2.3/2874}75 76h2_destroy()77{78	vlan_destroy $h2 1079	simple_if_fini $h280}81 82h3_create()83{84	simple_if_init $h385	vlan_create $h3 10 v$h3 192.0.2.18/2886 87	ip route add 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1788}89 90h3_destroy()91{92	ip route del 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1793 94	vlan_destroy $h3 1095	simple_if_fini $h396}97 98switch_create()99{100	ip link set dev $swp1 up101 102	ip link add dev br0 type bridge mcast_snooping 0103 104	# By default, a link-local address is generated when netdevice becomes105	# up. Adding an address to the bridge will cause creating a RIF for it.106	# Prevent generating link-local address to be able to control when the107	# RIF is added.108	sysctl_set net.ipv6.conf.br0.addr_gen_mode 1109	ip link set dev br0 up110 111	ip link set dev $swp2 up112	vlan_create $swp2 10113	ip link set dev $swp2.10 master br0114 115	ip link set dev $swp3 up116	vlan_create $swp3 10 "" 192.0.2.17/28117	tc qdisc add dev $swp3 clsact118 119	# Replace neighbor to avoid 1 packet which is forwarded in software due120	# to "unresolved neigh".121	ip neigh replace dev $swp3.10 192.0.2.18 lladdr $(mac_get $h3.10)122}123 124switch_destroy()125{126	tc qdisc del dev $swp3 clsact127	vlan_destroy $swp3 10128	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	ip link set dev $swp1 down139}140 141setup_prepare()142{143	h1=${NETIFS[p1]}144	swp1=${NETIFS[p2]}145 146	swp2=${NETIFS[p3]}147	h2=${NETIFS[p4]}148 149	swp3=${NETIFS[p5]}150	h3=${NETIFS[p6]}151 152	vrf_prepare153	forwarding_enable154 155	h1_create156	h2_create157	h3_create158 159	switch_create160}161 162cleanup()163{164	pre_cleanup165 166	switch_destroy167 168	h3_destroy169	h2_destroy170	h1_destroy171 172	forwarding_restore173	vrf_cleanup174}175 176bridge_rif_add()177{178	rifs_occ_t0=$(devlink_resource_occ_get rifs)179	__addr_add_del br0 add 192.0.2.2/28180	rifs_occ_t1=$(devlink_resource_occ_get rifs)181 182	expected_rifs=$((rifs_occ_t0 + 1))183 184	[[ $expected_rifs -eq $rifs_occ_t1 ]]185	check_err $? "Expected $expected_rifs RIFs, $rifs_occ_t1 are used"186 187	sleep 1188}189 190bridge_rif_del()191{192	__addr_add_del br0 del 192.0.2.2/28193}194 195port_vid_map_rif()196{197	RET=0198 199	# First add {port, VID}->FID for $swp1.10, then add a RIF and verify200	# that packets can be routed via the existing mapping.201	vlan_create $swp1 10202	ip link set dev $swp1.10 master br0203	bridge_rif_add204 205	# The hardware matches on the first ethertype which is not VLAN,206	# so the protocol should be IP.207	tc filter add dev $swp3 egress protocol ip pref 1 handle 101 \208		flower skip_sw dst_ip 192.0.2.18 action pass209 210	ping_do $h1.10 192.0.2.18211	check_err $? "Ping failed"212 213	tc_check_at_least_x_packets "dev $swp3 egress" 101 10214	check_err $? "Packets were not routed in hardware"215 216	log_test "Add RIF for existing {port, VID}->FID mapping"217 218	tc filter del dev $swp3 egress219 220	bridge_rif_del221	ip link set dev $swp1.10 nomaster222	vlan_destroy $swp1 10223}224 225rif_port_vid_map()226{227	RET=0228 229	# First add an address to the bridge, which will create a RIF on top of230	# it, then add a new {port, VID}->FID mapping and verify that packets231	# can be routed via the new mapping.232	bridge_rif_add233	vlan_create $swp1 10234	ip link set dev $swp1.10 master br0235 236	# The hardware matches on the first ethertype which is not VLAN,237	# so the protocol should be IP.238	tc filter add dev $swp3 egress protocol ip pref 1 handle 101 \239		flower skip_sw dst_ip 192.0.2.18 action pass240 241	ping_do $h1.10 192.0.2.18242	check_err $? "Ping failed"243 244	tc_check_at_least_x_packets "dev $swp3 egress" 101 10245	check_err $? "Packets were not routed in hardware"246 247	log_test "Add {port, VID}->FID mapping for FID with a RIF"248 249	tc filter del dev $swp3 egress250 251	ip link set dev $swp1.10 nomaster252	vlan_destroy $swp1 10253	bridge_rif_del254}255 256trap cleanup EXIT257 258setup_prepare259setup_wait260 261tests_run262 263exit $EXIT_STATUS264