xref: /linux/tools/testing/selftests/net/forwarding/mirror_vlan.sh (revision 13a370b9d275959ac75e92dc14e43eeae75804f8)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test uses standard topology for testing mirroring. See mirror_topo_lib.sh
5# for more details.
6#
7# Test for "tc action mirred egress mirror" that mirrors to a vlan device.
8
9ALL_TESTS="
10	test_vlan
11	test_tagged_vlan
12"
13
14NUM_NETIFS=6
15source lib.sh
16source mirror_lib.sh
17source mirror_topo_lib.sh
18
19setup_prepare()
20{
21	h1=${NETIFS[p1]}
22	swp1=${NETIFS[p2]}
23
24	swp2=${NETIFS[p3]}
25	h2=${NETIFS[p4]}
26
27	swp3=${NETIFS[p5]}
28	h3=${NETIFS[p6]}
29
30	vrf_prepare
31	mirror_topo_create
32
33	vlan_create $swp3 555
34
35	vlan_create $h3 555 v$h3
36	matchall_sink_create $h3.555
37
38	vlan_create $h1 111 v$h1 192.0.2.17/28
39	bridge vlan add dev $swp1 vid 111
40
41	vlan_create $h2 111 v$h2 192.0.2.18/28
42	bridge vlan add dev $swp2 vid 111
43}
44
45cleanup()
46{
47	pre_cleanup
48
49	vlan_destroy $h2 111
50	vlan_destroy $h1 111
51	vlan_destroy $h3 555
52	vlan_destroy $swp3 555
53
54	mirror_topo_destroy
55	vrf_cleanup
56}
57
58test_vlan_dir()
59{
60	local direction=$1; shift
61	local forward_type=$1; shift
62	local backward_type=$1; shift
63
64	RET=0
65
66	mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
67	test_span_dir "$h3.555" "$direction" "$forward_type" "$backward_type"
68	mirror_uninstall $swp1 $direction
69
70	log_test "$direction mirror to vlan ($tcflags)"
71}
72
73test_vlan()
74{
75	test_vlan_dir ingress 8 0
76	test_vlan_dir egress 0 8
77}
78
79vlan_capture_add_del()
80{
81	local add_del=$1; shift
82	local pref=$1; shift
83	local dev=$1; shift
84	local filter=$1; shift
85
86	tc filter $add_del dev "$dev" ingress \
87	   proto 802.1q pref $pref \
88	   flower $filter \
89	   action pass
90}
91
92vlan_capture_install()
93{
94	vlan_capture_add_del add 100 "$@"
95}
96
97vlan_capture_uninstall()
98{
99	vlan_capture_add_del del 100 "$@"
100}
101
102do_test_span_vlan_dir_ips()
103{
104	local expect=$1; shift
105	local dev=$1; shift
106	local vid=$1; shift
107	local direction=$1; shift
108	local ip1=$1; shift
109	local ip2=$1; shift
110
111	vlan_capture_install $dev "vlan_id $vid"
112	mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
113	mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
114	vlan_capture_uninstall $dev
115}
116
117test_tagged_vlan_dir()
118{
119	local direction=$1; shift
120	local forward_type=$1; shift
121	local backward_type=$1; shift
122
123	RET=0
124
125	mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
126	do_test_span_vlan_dir_ips 10 "$h3.555" 111 "$direction" \
127				  192.0.2.17 192.0.2.18
128	do_test_span_vlan_dir_ips  0 "$h3.555" 555 "$direction" \
129				  192.0.2.17 192.0.2.18
130	mirror_uninstall $swp1 $direction
131
132	log_test "$direction mirror to vlan ($tcflags)"
133}
134
135test_tagged_vlan()
136{
137	test_tagged_vlan_dir ingress 8 0
138	test_tagged_vlan_dir egress 0 8
139}
140
141test_all()
142{
143	slow_path_trap_install $swp1 ingress
144	slow_path_trap_install $swp1 egress
145	trap_install $h3 ingress
146
147	tests_run
148
149	trap_install $h3 ingress
150	slow_path_trap_uninstall $swp1 egress
151	slow_path_trap_uninstall $swp1 ingress
152}
153
154trap cleanup EXIT
155
156setup_prepare
157setup_wait
158
159tcflags="skip_hw"
160test_all
161
162if ! tc_offload_check; then
163	echo "WARN: Could not test offloaded functionality"
164else
165	tcflags="skip_sw"
166	test_all
167fi
168
169exit $EXIT_STATUS
170