GNU Linux-libre 4.19.286-gnu1
[releases.git] / tools / testing / selftests / net / forwarding / mirror_gre_bridge_1d_vlan.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 # This test uses standard topology for testing gretap. See
5 # mirror_gre_topo_lib.sh for more details.
6 #
7 # Test for "tc action mirred egress mirror" when the underlay route points at a
8 # bridge device without vlan filtering (802.1d). The device attached to that
9 # bridge is a VLAN.
10
11 ALL_TESTS="
12         test_gretap
13         test_ip6gretap
14         test_gretap_stp
15         test_ip6gretap_stp
16 "
17
18 NUM_NETIFS=6
19 source lib.sh
20 source mirror_lib.sh
21 source mirror_gre_lib.sh
22 source mirror_gre_topo_lib.sh
23
24 setup_prepare()
25 {
26         h1=${NETIFS[p1]}
27         swp1=${NETIFS[p2]}
28
29         swp2=${NETIFS[p3]}
30         h2=${NETIFS[p4]}
31
32         swp3=${NETIFS[p5]}
33         h3=${NETIFS[p6]}
34
35         vrf_prepare
36         mirror_gre_topo_create
37
38         ip link add name br2 type bridge vlan_filtering 0
39         ip link set dev br2 up
40
41         vlan_create $swp3 555
42
43         ip link set dev $swp3.555 master br2
44         ip route add 192.0.2.130/32 dev br2
45         ip -6 route add 2001:db8:2::2/128 dev br2
46
47         ip address add dev br2 192.0.2.129/32
48         ip address add dev br2 2001:db8:2::1/128
49
50         vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
51 }
52
53 cleanup()
54 {
55         pre_cleanup
56
57         vlan_destroy $h3 555
58         ip link del dev br2
59         vlan_destroy $swp3 555
60
61         mirror_gre_topo_destroy
62         vrf_cleanup
63 }
64
65 test_vlan_match()
66 {
67         local tundev=$1; shift
68         local vlan_match=$1; shift
69         local what=$1; shift
70
71         full_test_span_gre_dir_vlan $tundev ingress "$vlan_match" 8 0 "$what"
72         full_test_span_gre_dir_vlan $tundev egress "$vlan_match" 0 8 "$what"
73 }
74
75 test_gretap()
76 {
77         test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
78                         "mirror to gretap"
79 }
80
81 test_ip6gretap()
82 {
83         test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ip' \
84                         "mirror to ip6gretap"
85 }
86
87 test_gretap_stp()
88 {
89         # Sometimes after mirror installation, the neighbor's state is not valid.
90         # The reason is that there is no SW datapath activity related to the
91         # neighbor for the remote GRE address. Therefore whether the corresponding
92         # neighbor will be valid is a matter of luck, and the test is thus racy.
93         # Set the neighbor's state to permanent, so it would be always valid.
94         ip neigh replace 192.0.2.130 lladdr $(mac_get $h3) \
95                 nud permanent dev br2
96         full_test_span_gre_stp gt4 $swp3.555 "mirror to gretap"
97 }
98
99 test_ip6gretap_stp()
100 {
101         ip neigh replace 2001:db8:2::2 lladdr $(mac_get $h3) \
102                 nud permanent dev br2
103         full_test_span_gre_stp gt6 $swp3.555 "mirror to ip6gretap"
104 }
105
106 test_all()
107 {
108         slow_path_trap_install $swp1 ingress
109         slow_path_trap_install $swp1 egress
110
111         tests_run
112
113         slow_path_trap_uninstall $swp1 egress
114         slow_path_trap_uninstall $swp1 ingress
115 }
116
117 trap cleanup EXIT
118
119 setup_prepare
120 setup_wait
121
122 tcflags="skip_hw"
123 test_all
124
125 if ! tc_offload_check; then
126         echo "WARN: Could not test offloaded functionality"
127 else
128         tcflags="skip_sw"
129         test_all
130 fi
131
132 exit $EXIT_STATUS