xref: /linux/tools/testing/selftests/net/forwarding/mirror_gre_bridge_1d.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 without vlan filtering (802.1d).
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#  | +---------------------------------------------------------------------+ |
21#  |                                                                         |
22#  | +---------------------------------------------------------------------+ |
23#  | |                      + br2 (802.1d bridge)                          | |
24#  | |                        192.0.2.129/28                               | |
25#  | |   + $swp3              2001:db8:2::1/64                             | |
26#  | +---|-----------------------------------------------------------------+ |
27#  |     |                                          ^                    ^   |
28#  |     |                     + gt6 (ip6gretap)    | + gt4 (gretap)     |   |
29#  |     |                     : loc=2001:db8:2::1  | : loc=192.0.2.129  |   |
30#  |     |                     : rem=2001:db8:2::2 -+ : rem=192.0.2.130 -+   |
31#  |     |                     : ttl=100              : ttl=100              |
32#  |     |                     : tos=inherit          : tos=inherit          |
33#  +-----|---------------------:----------------------:----------------------+
34#        |                     :                      :
35#  +-----|---------------------:----------------------:----------------------+
36#  | H3  + $h3                 + h3-gt6(ip6gretap)    + h3-gt4 (gretap)      |
37#  |       192.0.2.130/28        loc=2001:db8:2::2      loc=192.0.2.130      |
38#  |       2001:db8:2::2/64      rem=2001:db8:2::1      rem=192.0.2.129      |
39#  |                             ttl=100                ttl=100              |
40#  |                             tos=inherit            tos=inherit          |
41#  +-------------------------------------------------------------------------+
42
43ALL_TESTS="
44	test_gretap
45	test_ip6gretap
46"
47
48NUM_NETIFS=6
49source lib.sh
50source mirror_lib.sh
51source mirror_gre_lib.sh
52source mirror_gre_topo_lib.sh
53
54setup_prepare()
55{
56	h1=${NETIFS[p1]}
57	swp1=${NETIFS[p2]}
58
59	swp2=${NETIFS[p3]}
60	h2=${NETIFS[p4]}
61
62	swp3=${NETIFS[p5]}
63	h3=${NETIFS[p6]}
64
65	vrf_prepare
66	mirror_gre_topo_create
67
68	ip link add name br2 address $(mac_get $swp3) \
69		type bridge vlan_filtering 0
70	ip link set dev br2 up
71
72	ip link set dev $swp3 master br2
73	ip route add 192.0.2.130/32 dev br2
74	ip -6 route add 2001:db8:2::2/128 dev br2
75
76	ip address add dev br2 192.0.2.129/28
77	ip address add dev br2 2001:db8:2::1/64
78
79	ip address add dev $h3 192.0.2.130/28
80	ip address add dev $h3 2001:db8:2::2/64
81}
82
83cleanup()
84{
85	pre_cleanup
86
87	ip address del dev $h3 2001:db8:2::2/64
88	ip address del dev $h3 192.0.2.130/28
89	ip link del dev br2
90
91	mirror_gre_topo_destroy
92	vrf_cleanup
93}
94
95test_gretap()
96{
97	ip neigh replace 192.0.2.130 lladdr $(mac_get $h3) \
98		 nud permanent dev br2
99	full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
100	full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
101}
102
103test_ip6gretap()
104{
105	ip neigh replace 2001:db8:2::2 lladdr $(mac_get $h3) \
106		nud permanent dev br2
107	full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
108	full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
109}
110
111trap cleanup EXIT
112
113setup_prepare
114setup_wait
115
116tests_run
117
118exit $EXIT_STATUS
119