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
11ALL_TESTS="
12	test_gretap
13	test_ip6gretap
14	test_gretap_stp
15	test_ip6gretap_stp
16"
17
18NUM_NETIFS=6
19source lib.sh
20source mirror_lib.sh
21source mirror_gre_lib.sh
22source mirror_gre_topo_lib.sh
23
24setup_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 address $(mac_get $swp3) \
39		type bridge vlan_filtering 0
40	ip link set dev br2 up
41
42	vlan_create $swp3 555
43
44	ip link set dev $swp3.555 master br2
45	ip route add 192.0.2.130/32 dev br2
46	ip -6 route add 2001:db8:2::2/128 dev br2
47
48	ip address add dev br2 192.0.2.129/32
49	ip address add dev br2 2001:db8:2::1/128
50
51	vlan_create $h3 555 v$h3 192.0.2.130/28 2001:db8:2::2/64
52}
53
54cleanup()
55{
56	pre_cleanup
57
58	vlan_destroy $h3 555
59	ip link del dev br2
60	vlan_destroy $swp3 555
61
62	mirror_gre_topo_destroy
63	vrf_cleanup
64}
65
66test_vlan_match()
67{
68	local tundev=$1; shift
69	local vlan_match=$1; shift
70	local what=$1; shift
71
72	full_test_span_gre_dir_vlan $tundev ingress "$vlan_match" 8 0 "$what"
73	full_test_span_gre_dir_vlan $tundev egress "$vlan_match" 0 8 "$what"
74}
75
76test_gretap()
77{
78	test_vlan_match gt4 'skip_hw vlan_id 555 vlan_ethtype ip' \
79			"mirror to gretap"
80}
81
82test_ip6gretap()
83{
84	test_vlan_match gt6 'skip_hw vlan_id 555 vlan_ethtype ipv6' \
85			"mirror to ip6gretap"
86}
87
88test_gretap_stp()
89{
90	# Sometimes after mirror installation, the neighbor's state is not valid.
91	# The reason is that there is no SW datapath activity related to the
92	# neighbor for the remote GRE address. Therefore whether the corresponding
93	# neighbor will be valid is a matter of luck, and the test is thus racy.
94	# Set the neighbor's state to permanent, so it would be always valid.
95	ip neigh replace 192.0.2.130 lladdr $(mac_get $h3) \
96		nud permanent dev br2
97	full_test_span_gre_stp gt4 $swp3.555 "mirror to gretap"
98}
99
100test_ip6gretap_stp()
101{
102	ip neigh replace 2001:db8:2::2 lladdr $(mac_get $h3) \
103		nud permanent dev br2
104	full_test_span_gre_stp gt6 $swp3.555 "mirror to ip6gretap"
105}
106
107test_all()
108{
109	slow_path_trap_install $swp1 ingress
110	slow_path_trap_install $swp1 egress
111
112	tests_run
113
114	slow_path_trap_uninstall $swp1 egress
115	slow_path_trap_uninstall $swp1 ingress
116}
117
118trap cleanup EXIT
119
120setup_prepare
121setup_wait
122
123tcflags="skip_hw"
124test_all
125
126if ! tc_offload_check; then
127	echo "WARN: Could not test offloaded functionality"
128else
129	tcflags="skip_sw"
130	test_all
131fi
132
133exit $EXIT_STATUS
134