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 device to mirror to is a
8# gretap or ip6gretap netdevice. Expect that the packets come out encapsulated,
9# and another gretap / ip6gretap netdevice is then capable of decapsulating the
10# traffic. Test that the payload is what is expected (ICMP ping request or
11# reply, depending on test).
12
13ALL_TESTS="
14	test_gretap
15	test_ip6gretap
16	test_gretap_mac
17	test_ip6gretap_mac
18	test_two_spans
19"
20
21NUM_NETIFS=6
22source lib.sh
23source mirror_lib.sh
24source mirror_gre_lib.sh
25source mirror_gre_topo_lib.sh
26
27setup_prepare()
28{
29	h1=${NETIFS[p1]}
30	swp1=${NETIFS[p2]}
31
32	swp2=${NETIFS[p3]}
33	h2=${NETIFS[p4]}
34
35	swp3=${NETIFS[p5]}
36	h3=${NETIFS[p6]}
37
38	vrf_prepare
39	mirror_gre_topo_create
40
41	ip address add dev $swp3 192.0.2.129/28
42	ip address add dev $h3 192.0.2.130/28
43
44	ip address add dev $swp3 2001:db8:2::1/64
45	ip address add dev $h3 2001:db8:2::2/64
46}
47
48cleanup()
49{
50	pre_cleanup
51
52	ip address del dev $h3 2001:db8:2::2/64
53	ip address del dev $swp3 2001:db8:2::1/64
54
55	ip address del dev $h3 192.0.2.130/28
56	ip address del dev $swp3 192.0.2.129/28
57
58	mirror_gre_topo_destroy
59	vrf_cleanup
60}
61
62test_span_gre_mac()
63{
64	local tundev=$1; shift
65	local direction=$1; shift
66	local prot=$1; shift
67	local what=$1; shift
68
69	local swp3mac=$(mac_get $swp3)
70	local h3mac=$(mac_get $h3)
71
72	RET=0
73
74	mirror_install $swp1 $direction $tundev "matchall $tcflags"
75	tc filter add dev $h3 ingress pref 77 prot $prot \
76		flower ip_proto 0x2f src_mac $swp3mac dst_mac $h3mac \
77		action pass
78
79	mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
80
81	tc filter del dev $h3 ingress pref 77
82	mirror_uninstall $swp1 $direction
83
84	log_test "$direction $what: envelope MAC ($tcflags)"
85}
86
87test_two_spans()
88{
89	RET=0
90
91	mirror_install $swp1 ingress gt4 "matchall $tcflags"
92	mirror_install $swp1 egress gt6 "matchall $tcflags"
93	quick_test_span_gre_dir gt4 ingress
94	quick_test_span_gre_dir gt6 egress
95
96	mirror_uninstall $swp1 ingress
97	fail_test_span_gre_dir gt4 ingress
98	quick_test_span_gre_dir gt6 egress
99
100	mirror_install $swp1 ingress gt4 "matchall $tcflags"
101	mirror_uninstall $swp1 egress
102	quick_test_span_gre_dir gt4 ingress
103	fail_test_span_gre_dir gt6 egress
104
105	mirror_uninstall $swp1 ingress
106	log_test "two simultaneously configured mirrors ($tcflags)"
107}
108
109test_gretap()
110{
111	full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
112	full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
113}
114
115test_ip6gretap()
116{
117	full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
118	full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
119}
120
121test_gretap_mac()
122{
123	test_span_gre_mac gt4 ingress ip "mirror to gretap"
124	test_span_gre_mac gt4 egress ip "mirror to gretap"
125}
126
127test_ip6gretap_mac()
128{
129	test_span_gre_mac gt6 ingress ipv6 "mirror to ip6gretap"
130	test_span_gre_mac gt6 egress ipv6 "mirror to ip6gretap"
131}
132
133test_all()
134{
135	slow_path_trap_install $swp1 ingress
136	slow_path_trap_install $swp1 egress
137
138	tests_run
139
140	slow_path_trap_uninstall $swp1 egress
141	slow_path_trap_uninstall $swp1 ingress
142}
143
144trap cleanup EXIT
145
146setup_prepare
147setup_wait
148
149tcflags="skip_hw"
150test_all
151
152if ! tc_offload_check; then
153	echo "WARN: Could not test offloaded functionality"
154else
155	tcflags="skip_sw"
156	test_all
157fi
158
159exit $EXIT_STATUS
160