xref: /linux/tools/testing/selftests/net/forwarding/mirror_gre_bound.sh (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4#   +---------------------+                             +---------------------+
5#   | H1                  |                             |                  H2 |
6#   |     + $h1           |                             |           $h2 +     |
7#   |     | 192.0.2.1/28  |                             |  192.0.2.2/28 |     |
8#   +-----|---------------+                             +---------------|-----+
9#         |                                                             |
10#   +-----|-------------------------------------------------------------|-----+
11#   | SW  o--> mirror                                                   |     |
12#   | +---|-------------------------------------------------------------|---+ |
13#   | |   + $swp1                    BR                           $swp2 +   | |
14#   | +---------------------------------------------------------------------+ |
15#   |                                                                         |
16#   | +---------------------------------------------------------------------+ |
17#   | | OL                      + gt6 (ip6gretap)      + gt4 (gretap)       | |
18#   | |                         : loc=2001:db8:2::1    : loc=192.0.2.129    | |
19#   | |                         : rem=2001:db8:2::2    : rem=192.0.2.130    | |
20#   | |                         : ttl=100              : ttl=100            | |
21#   | |                         : tos=inherit          : tos=inherit        | |
22#   | +-------------------------:--|-------------------:--|-----------------+ |
23#   |                           :  |                   :  |                   |
24#   | +-------------------------:--|-------------------:--|-----------------+ |
25#   | | UL                      :  |,---------------------'                 | |
26#   | |   + $swp3               :  ||                  :                    | |
27#   | |   | 192.0.2.129/28      :  vv                  :                    | |
28#   | |   | 2001:db8:2::1/64    :  + ul (dummy)        :                    | |
29#   | +---|---------------------:----------------------:--------------------+ |
30#   +-----|---------------------:----------------------:----------------------+
31#         |                     :                      :
32#   +-----|---------------------:----------------------:----------------------+
33#   | H3  + $h3                 + h3-gt6 (ip6gretap)   + h3-gt4 (gretap)      |
34#   |       192.0.2.130/28        loc=2001:db8:2::2      loc=192.0.2.130      |
35#   |       2001:db8:2::2/64      rem=2001:db8:2::1      rem=192.0.2.129      |
36#   |                             ttl=100                ttl=100              |
37#   |                             tos=inherit            tos=inherit          |
38#   |                                                                         |
39#   +-------------------------------------------------------------------------+
40#
41# This tests mirroring to gretap and ip6gretap configured in an overlay /
42# underlay manner, i.e. with a bound dummy device that marks underlay VRF where
43# the encapsulated packed should be routed.
44
45ALL_TESTS="
46	test_gretap
47	test_ip6gretap
48"
49
50NUM_NETIFS=6
51source lib.sh
52source mirror_lib.sh
53source mirror_gre_lib.sh
54
55h1_create()
56{
57	simple_if_init $h1 192.0.2.1/28
58}
59
60h1_destroy()
61{
62	simple_if_fini $h1 192.0.2.1/28
63}
64
65h2_create()
66{
67	simple_if_init $h2 192.0.2.2/28
68}
69
70h2_destroy()
71{
72	simple_if_fini $h2 192.0.2.2/28
73}
74
75h3_create()
76{
77	simple_if_init $h3 192.0.2.130/28 2001:db8:2::2/64
78
79	tunnel_create h3-gt4 gretap 192.0.2.130 192.0.2.129
80	ip link set h3-gt4 vrf v$h3
81	matchall_sink_create h3-gt4
82
83	tunnel_create h3-gt6 ip6gretap 2001:db8:2::2 2001:db8:2::1
84	ip link set h3-gt6 vrf v$h3
85	matchall_sink_create h3-gt6
86}
87
88h3_destroy()
89{
90	tunnel_destroy h3-gt6
91	tunnel_destroy h3-gt4
92
93	simple_if_fini $h3 192.0.2.130/28 2001:db8:2::2/64
94}
95
96switch_create()
97{
98	# Bridge between H1 and H2.
99
100	ip link add name br1 type bridge vlan_filtering 1
101	ip link set dev br1 addrgenmode none
102	ip link set dev br1 up
103
104	ip link set dev $swp1 master br1
105	ip link set dev $swp1 up
106
107	ip link set dev $swp2 master br1
108	ip link set dev $swp2 up
109
110	tc qdisc add dev $swp1 clsact
111
112	# Underlay.
113
114	simple_if_init $swp3 192.0.2.129/28 2001:db8:2::1/64
115
116	ip link add name ul type dummy
117	ip link set dev ul master v$swp3
118	ip link set dev ul up
119
120	# Overlay.
121
122	vrf_create vrf-ol
123	ip link set dev vrf-ol up
124
125	tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
126		      ttl 100 tos inherit dev ul
127	ip link set dev gt4 master vrf-ol
128	ip link set dev gt4 up
129
130	tunnel_create gt6 ip6gretap 2001:db8:2::1 2001:db8:2::2 \
131		      ttl 100 tos inherit dev ul allow-localremote
132	ip link set dev gt6 master vrf-ol
133	ip link set dev gt6 up
134}
135
136switch_destroy()
137{
138	vrf_destroy vrf-ol
139
140	tunnel_destroy gt6
141	tunnel_destroy gt4
142
143	simple_if_fini $swp3 192.0.2.129/28 2001:db8:2::1/64
144
145	ip link del dev ul
146
147	tc qdisc del dev $swp1 clsact
148
149	ip link set dev $swp1 down
150	ip link set dev $swp2 down
151	ip link del dev br1
152}
153
154setup_prepare()
155{
156	h1=${NETIFS[p1]}
157	swp1=${NETIFS[p2]}
158
159	swp2=${NETIFS[p3]}
160	h2=${NETIFS[p4]}
161
162	swp3=${NETIFS[p5]}
163	h3=${NETIFS[p6]}
164
165	vrf_prepare
166
167	h1_create
168	h2_create
169	h3_create
170
171	switch_create
172}
173
174cleanup()
175{
176	pre_cleanup
177
178	switch_destroy
179
180	h3_destroy
181	h2_destroy
182	h1_destroy
183
184	vrf_cleanup
185}
186
187test_gretap()
188{
189	full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap w/ UL"
190	full_test_span_gre_dir gt4 egress  0 8 "mirror to gretap w/ UL"
191}
192
193test_ip6gretap()
194{
195	full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap w/ UL"
196	full_test_span_gre_dir gt6 egress  0 8 "mirror to ip6gretap w/ UL"
197}
198
199trap cleanup EXIT
200
201setup_prepare
202setup_wait
203
204tests_run
205
206exit $EXIT_STATUS
207