brintos

brintos / linux-shallow public Read only

0
0
Text · 6.2 KiB · 577293b Raw
265 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# mapping and that packets can be routed via port which is added after the FID7# already has a RIF.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             |                         |                 |20# | +--------------|-------------------------|---------------+ |21# | |        $swp1 +                         + $swp2         | |22# | |                                                        | |23# | |                           br0                          | |24# | +--------------------------------------------------------+ |25# |                              |                             |26# |                           br0.10                           |27# |                        192.0.2.2/28                        |28# |                                                            |29# |                                                            |30# |          $swp3 +                                           |31# |  192.0.2.17/28 |                                           |32# +----------------|-------------------------------------------+33#                  |34# +----------------|--+35# |            $h3 +  |36# |  192.0.2.18/28    |37# |                   |38# | H3                |39# +-------------------+40 41lib_dir=$(dirname $0)/../../../net/forwarding42 43ALL_TESTS="44	vid_map_rif45	rif_vid_map46"47 48NUM_NETIFS=649source $lib_dir/lib.sh50source $lib_dir/tc_common.sh51source $lib_dir/devlink_lib.sh52 53h1_create()54{55	simple_if_init $h156	vlan_create $h1 10 v$h1 192.0.2.1/2857 58	ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.259}60 61h1_destroy()62{63	ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.264 65	vlan_destroy $h1 1066	simple_if_fini $h167}68 69h2_create()70{71	simple_if_init $h272	vlan_create $h2 10 v$h2 192.0.2.3/2873}74 75h2_destroy()76{77	vlan_destroy $h2 1078	simple_if_fini $h279}80 81h3_create()82{83	simple_if_init $h3 192.0.2.18/2884	ip route add 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1785}86 87h3_destroy()88{89	ip route del 192.0.2.0/28 vrf v$h3 nexthop via 192.0.2.1790	simple_if_fini $h3 192.0.2.18/2891}92 93switch_create()94{95	ip link set dev $swp1 up96 97	ip link add dev br0 type bridge vlan_filtering 1 mcast_snooping 098 99	# By default, a link-local address is generated when netdevice becomes100	# up. Adding an address to the bridge will cause creating a RIF for it.101	# Prevent generating link-local address to be able to control when the102	# RIF is added.103	sysctl_set net.ipv6.conf.br0.addr_gen_mode 1104	ip link set dev br0 up105 106	ip link set dev $swp2 up107	ip link set dev $swp2 master br0108	bridge vlan add vid 10 dev $swp2109 110	ip link set dev $swp3 up111	__addr_add_del $swp3 add 192.0.2.17/28112	tc qdisc add dev $swp3 clsact113 114	# Replace neighbor to avoid 1 packet which is forwarded in software due115	# to "unresolved neigh".116	ip neigh replace dev $swp3 192.0.2.18 lladdr $(mac_get $h3)117}118 119switch_destroy()120{121	tc qdisc del dev $swp3 clsact122	__addr_add_del $swp3 del 192.0.2.17/28123	ip link set dev $swp3 down124 125	bridge vlan del vid 10 dev $swp2126	ip link set dev $swp2 nomaster127	ip link set dev $swp2 down128 129	ip link set dev br0 down130	sysctl_restore net.ipv6.conf.br0.addr_gen_mode131	ip link del dev br0132 133	ip link set dev $swp1 down134}135 136setup_prepare()137{138	h1=${NETIFS[p1]}139	swp1=${NETIFS[p2]}140 141	swp2=${NETIFS[p3]}142	h2=${NETIFS[p4]}143 144	swp3=${NETIFS[p5]}145	h3=${NETIFS[p6]}146 147	vrf_prepare148	forwarding_enable149 150	h1_create151	h2_create152	h3_create153 154	switch_create155}156 157cleanup()158{159	pre_cleanup160 161	switch_destroy162 163	h3_destroy164	h2_destroy165	h1_destroy166 167	forwarding_restore168	vrf_cleanup169}170 171bridge_rif_add()172{173	rifs_occ_t0=$(devlink_resource_occ_get rifs)174	vlan_create br0 10 "" 192.0.2.2/28175	rifs_occ_t1=$(devlink_resource_occ_get rifs)176 177	expected_rifs=$((rifs_occ_t0 + 1))178 179	[[ $expected_rifs -eq $rifs_occ_t1 ]]180	check_err $? "Expected $expected_rifs RIFs, $rifs_occ_t1 are used"181 182	sleep 1183}184 185bridge_rif_del()186{187	vlan_destroy br0 10188}189 190vid_map_rif()191{192	RET=0193 194	# First add VID->FID for vlan 10, then add a RIF and verify that195	# packets can be routed via the existing mapping.196	bridge vlan add vid 10 dev br0 self197	ip link set dev $swp1 master br0198	bridge vlan add vid 10 dev $swp1199 200	bridge_rif_add201 202	tc filter add dev $swp3 egress protocol ip pref 1 handle 101 \203		flower skip_sw dst_ip 192.0.2.18 action pass204 205	ping_do $h1.10 192.0.2.18206	check_err $? "Ping failed"207 208	tc_check_at_least_x_packets "dev $swp3 egress" 101 10209	check_err $? "Packets were not routed in hardware"210 211	log_test "Add RIF for existing VID->FID mapping"212 213	tc filter del dev $swp3 egress214 215	bridge_rif_del216 217	bridge vlan del vid 10 dev $swp1218	ip link set dev $swp1 nomaster219	bridge vlan del vid 10 dev br0 self220}221 222rif_vid_map()223{224	RET=0225 226	# Using 802.1Q, there is only one VID->FID map for each VID. That means227	# that we cannot really check adding a new map for existing FID with a228	# RIF. Verify that packets can be routed via port which is added after229	# the FID already has a RIF, although in practice there is no new230	# mapping in the hardware.231	bridge vlan add vid 10 dev br0 self232	bridge_rif_add233 234	ip link set dev $swp1 master br0235	bridge vlan add vid 10 dev $swp1236 237	tc filter add dev $swp3 egress protocol ip pref 1 handle 101 \238		flower skip_sw dst_ip 192.0.2.18 action pass239 240	ping_do $h1.10 192.0.2.18241	check_err $? "Ping failed"242 243	tc_check_at_least_x_packets "dev $swp3 egress" 101 10244	check_err $? "Packets were not routed in hardware"245 246	log_test "Add port to VID->FID mapping for FID with a RIF"247 248	tc filter del dev $swp3 egress249 250	bridge vlan del vid 10 dev $swp1251	ip link set dev $swp1 nomaster252 253	bridge_rif_del254	bridge vlan del vid 10 dev br0 self255}256 257trap cleanup EXIT258 259setup_prepare260setup_wait261 262tests_run263 264exit $EXIT_STATUS265