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).
6#
7# This test uses standard topology for testing mirror-to-gretap. See
8# mirror_gre_topo_lib.sh for more details. The full topology is as follows:
9#
10#  +---------------------+                               +---------------------+
11#  | H1                  |                               |                  H2 |
12#  |     + $h1           |                               |           $h2 +     |
13#  |     | 192.0.2.1/28  |                               |  192.0.2.2/28 |     |
14#  +-----|---------------+                               +---------------|-----+
15#        |                                                               |
16#  +-----|---------------------------------------------------------------|-----+
17#  | SW  o---> mirror                                                    |     |
18#  | +---|---------------------------------------------------------------|---+ |
19#  | |   + $swp1                  + br1 (802.1q bridge)            $swp2 +   | |
20#  | |                              192.0.2.129/28                           | |
21#  | |   + $swp3                    2001:db8:2::1/64                         | |
22#  | |   | vid555                   vid555[pvid,untagged]                    | |
23#  | +---|-------------------------------------------------------------------+ |
24#  |     |                                          ^                      ^   |
25#  |     |                     + gt6 (ip6gretap)    |   + gt4 (gretap)     |   |
26#  |     |                     : loc=2001:db8:2::1  |   : loc=192.0.2.129  |   |
27#  |     |                     : rem=2001:db8:2::2 -+   : rem=192.0.2.130 -+   |
28#  |     |                     : ttl=100                : ttl=100              |
29#  |     |                     : tos=inherit            : tos=inherit          |
30#  +-----|---------------------:------------------------:----------------------+
31#        |                     :                        :
32#  +-----|---------------------:------------------------:----------------------+
33#  | H3  + $h3                 + h3-gt6(ip6gretap)      + h3-gt4 (gretap)      |
34#  |     |                       loc=2001:db8:2::2        loc=192.0.2.130      |
35#  |     + $h3.555               rem=2001:db8:2::1        rem=192.0.2.129      |
36#  |       192.0.2.130/28        ttl=100                  ttl=100              |
37#  |       2001:db8:2::2/64      tos=inherit              tos=inherit          |
38#  +---------------------------------------------------------------------------+
39
40ALL_TESTS="
41	test_gretap
42	test_ip6gretap
43"
44
45NUM_NETIFS=6
46source lib.sh
47source mirror_lib.sh
48source mirror_gre_lib.sh
49source mirror_gre_topo_lib.sh
50
51setup_prepare()
52{
53	h1=${NETIFS[p1]}
54	swp1=${NETIFS[p2]}
55
56	swp2=${NETIFS[p3]}
57	h2=${NETIFS[p4]}
58
59	swp3=${NETIFS[p5]}
60	h3=${NETIFS[p6]}
61
62	vrf_prepare
63	mirror_gre_topo_create
64	# Avoid changing br1's PVID while it is operational as a L3 interface.
65	ip link set dev br1 down
66
67	ip link set dev $swp3 master br1
68	bridge vlan add dev br1 vid 555 pvid untagged self
69	ip link set dev br1 up
70	ip address add dev br1 192.0.2.129/28
71	ip address add dev br1 2001:db8:2::1/64
72
73	ip -4 route add 192.0.2.130/32 dev br1
74	ip -6 route add 2001:db8:2::2/128 dev br1
75
76	vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
77	bridge vlan add dev $swp3 vid 555
78}
79
80cleanup()
81{
82	pre_cleanup
83
84	ip link set dev $swp3 nomaster
85	vlan_destroy $h3 555
86
87	mirror_gre_topo_destroy
88	vrf_cleanup
89}
90
91test_gretap()
92{
93	full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
94	full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
95}
96
97test_ip6gretap()
98{
99	full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
100	full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
101}
102
103tests()
104{
105	slow_path_trap_install $swp1 ingress
106	slow_path_trap_install $swp1 egress
107
108	tests_run
109
110	slow_path_trap_uninstall $swp1 egress
111	slow_path_trap_uninstall $swp1 ingress
112}
113
114trap cleanup EXIT
115
116setup_prepare
117setup_wait
118
119tcflags="skip_hw"
120tests
121
122if ! tc_offload_check; then
123	echo "WARN: Could not test offloaded functionality"
124else
125	tcflags="skip_sw"
126	tests
127fi
128
129exit $EXIT_STATUS
130