xref: /linux/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1q_lag.sh (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Test for "tc action mirred egress mirror" when the underlay route points at a
5# bridge device with vlan filtering (802.1q), and the egress device is a team
6# device.
7#
8# +----------------------+                             +----------------------+
9# | H1                   |                             |                   H2 |
10# |     + $h1.333        |                             |        $h1.555 +     |
11# |     | 192.0.2.1/28   |                             |  192.0.2.18/28 |     |
12# +-----|----------------+                             +----------------|-----+
13#       |                               $h1                             |
14#       +--------------------------------+------------------------------+
15#                                        |
16# +--------------------------------------|------------------------------------+
17# | SW                                   o---> mirror                         |
18# |                                      |                                    |
19# |     +--------------------------------+------------------------------+     |
20# |     |                              $swp1                            |     |
21# |     + $swp1.333                                           $swp1.555 +     |
22# |       192.0.2.2/28                                    192.0.2.17/28       |
23# |                                                                           |
24# | +-----------------------------------------------------------------------+ |
25# | |                        BR1 (802.1q)                                   | |
26# | |     + lag (team)       192.0.2.129/28                                 | |
27# | |    / \                 2001:db8:2::1/64                               | |
28# | +---/---\---------------------------------------------------------------+ |
29# |    /     \                                                            ^   |
30# |   |       \                                        + gt4 (gretap)     |   |
31# |   |        \                                         loc=192.0.2.129  |   |
32# |   |         \                                        rem=192.0.2.130 -+   |
33# |   |          \                                       ttl=100              |
34# |   |           \                                      tos=inherit          |
35# |   |            \                                                          |
36# |   |             \_________________________________                        |
37# |   |                                               \                       |
38# |   + $swp3                                          + $swp4                |
39# +---|------------------------------------------------|----------------------+
40#     |                                                |
41# +---|----------------------+                     +---|----------------------+
42# |   + $h3               H3 |                     |   + $h4               H4 |
43# |     192.0.2.130/28       |                     |     192.0.2.130/28       |
44# |     2001:db8:2::2/64     |                     |     2001:db8:2::2/64     |
45# +--------------------------+                     +--------------------------+
46
47ALL_TESTS="
48	test_mirror_gretap_first
49	test_mirror_gretap_second
50"
51
52NUM_NETIFS=6
53source lib.sh
54source mirror_lib.sh
55source mirror_gre_lib.sh
56
57require_command $ARPING
58
59vlan_host_create()
60{
61	local if_name=$1; shift
62	local vid=$1; shift
63	local vrf_name=$1; shift
64	local ips=("${@}")
65
66	vrf_create $vrf_name
67	ip link set dev $vrf_name up
68	vlan_create $if_name $vid $vrf_name "${ips[@]}"
69}
70
71vlan_host_destroy()
72{
73	local if_name=$1; shift
74	local vid=$1; shift
75	local vrf_name=$1; shift
76
77	vlan_destroy $if_name $vid
78	ip link set dev $vrf_name down
79	vrf_destroy $vrf_name
80}
81
82h1_create()
83{
84	vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
85	ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
86}
87
88h1_destroy()
89{
90	ip -4 route del 192.0.2.16/28 vrf vrf-h1
91	vlan_host_destroy $h1 333 vrf-h1
92}
93
94h2_create()
95{
96	vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
97	ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
98}
99
100h2_destroy()
101{
102	ip -4 route del 192.0.2.0/28 vrf vrf-h2
103	vlan_host_destroy $h1 555 vrf-h2
104}
105
106h3_create()
107{
108	simple_if_init $h3 192.0.2.130/28
109	tc qdisc add dev $h3 clsact
110}
111
112h3_destroy()
113{
114	tc qdisc del dev $h3 clsact
115	simple_if_fini $h3 192.0.2.130/28
116}
117
118h4_create()
119{
120	simple_if_init $h4 192.0.2.130/28
121	tc qdisc add dev $h4 clsact
122}
123
124h4_destroy()
125{
126	tc qdisc del dev $h4 clsact
127	simple_if_fini $h4 192.0.2.130/28
128}
129
130switch_create()
131{
132	ip link set dev $swp1 up
133	tc qdisc add dev $swp1 clsact
134	vlan_create $swp1 333 "" 192.0.2.2/28
135	vlan_create $swp1 555 "" 192.0.2.17/28
136
137	tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
138		      ttl 100 tos inherit
139
140	ip link set dev $swp3 up
141	ip link set dev $swp4 up
142
143	ip link add name br1 address $(mac_get $swp3) \
144		type bridge vlan_filtering 1
145
146	team_create lag loadbalance $swp3 $swp4
147	ip link set dev lag master br1
148
149	ip link set dev br1 up
150	__addr_add_del br1 add 192.0.2.129/32
151	ip -4 route add 192.0.2.130/32 dev br1
152}
153
154switch_destroy()
155{
156	ip link set dev lag nomaster
157	team_destroy lag
158
159	ip -4 route del 192.0.2.130/32 dev br1
160	__addr_add_del br1 del 192.0.2.129/32
161	ip link set dev br1 down
162	ip link del dev br1
163
164	ip link set dev $swp4 down
165	ip link set dev $swp3 down
166
167	tunnel_destroy gt4
168
169	vlan_destroy $swp1 555
170	vlan_destroy $swp1 333
171	tc qdisc del dev $swp1 clsact
172	ip link set dev $swp1 down
173}
174
175setup_prepare()
176{
177	h1=${NETIFS[p1]}
178	swp1=${NETIFS[p2]}
179
180	swp3=${NETIFS[p3]}
181	h3=${NETIFS[p4]}
182
183	swp4=${NETIFS[p5]}
184	h4=${NETIFS[p6]}
185
186	vrf_prepare
187
188	ip link set dev $h1 up
189	h1_create
190	h2_create
191	h3_create
192	h4_create
193	switch_create
194
195	forwarding_enable
196
197	trap_install $h3 ingress
198	trap_install $h4 ingress
199}
200
201cleanup()
202{
203	pre_cleanup
204
205	trap_uninstall $h4 ingress
206	trap_uninstall $h3 ingress
207
208	forwarding_restore
209
210	switch_destroy
211	h4_destroy
212	h3_destroy
213	h2_destroy
214	h1_destroy
215	ip link set dev $h1 down
216
217	vrf_cleanup
218}
219
220test_lag_slave()
221{
222	local host_dev=$1; shift
223	local up_dev=$1; shift
224	local down_dev=$1; shift
225	local what=$1; shift
226
227	RET=0
228
229	tc filter add dev $swp1 ingress pref 999 \
230		proto 802.1q flower vlan_ethtype arp \
231		action pass
232	mirror_install $swp1 ingress gt4 \
233		"proto 802.1q flower vlan_id 333"
234
235	# Test connectivity through $up_dev when $down_dev is set down.
236	ip link set dev $down_dev down
237	ip neigh flush dev br1
238	setup_wait_dev $up_dev
239	setup_wait_dev $host_dev
240	$ARPING -I br1 192.0.2.130 -qfc 1
241	sleep 2
242	mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 ">= 10"
243
244	# Test lack of connectivity when both slaves are down.
245	ip link set dev $up_dev down
246	sleep 2
247	mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h3 1 0
248	mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h4 1 0
249
250	ip link set dev $up_dev up
251	ip link set dev $down_dev up
252	mirror_uninstall $swp1 ingress
253	tc filter del dev $swp1 ingress pref 999
254
255	log_test "$what"
256}
257
258test_mirror_gretap_first()
259{
260	test_lag_slave $h3 $swp3 $swp4 "mirror to gretap: LAG first slave"
261}
262
263test_mirror_gretap_second()
264{
265	test_lag_slave $h4 $swp4 $swp3 "mirror to gretap: LAG second slave"
266}
267
268trap cleanup EXIT
269
270setup_prepare
271setup_wait
272
273tests_run
274
275exit $EXIT_STATUS
276