xref: /linux/tools/testing/selftests/net/forwarding/mirror_gre.sh (revision c4c8f39a57bf5057fc51a848d42b7e348ecfa31d)
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 qdisc add dev $h3 clsact
76	tc filter add dev $h3 ingress pref 77 prot $prot \
77		flower ip_proto 0x2f src_mac $swp3mac dst_mac $h3mac \
78		action pass
79
80	mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
81
82	tc filter del dev $h3 ingress pref 77
83	tc qdisc del dev $h3 clsact
84	mirror_uninstall $swp1 $direction
85
86	log_test "$direction $what: envelope MAC ($tcflags)"
87}
88
89test_two_spans()
90{
91	RET=0
92
93	mirror_install $swp1 ingress gt4 "matchall $tcflags"
94	mirror_install $swp1 egress gt6 "matchall $tcflags"
95	quick_test_span_gre_dir gt4 ingress
96	quick_test_span_gre_dir gt6 egress
97
98	mirror_uninstall $swp1 ingress
99	fail_test_span_gre_dir gt4 ingress
100	quick_test_span_gre_dir gt6 egress
101
102	mirror_install $swp1 ingress gt4 "matchall $tcflags"
103	mirror_uninstall $swp1 egress
104	quick_test_span_gre_dir gt4 ingress
105	fail_test_span_gre_dir gt6 egress
106
107	mirror_uninstall $swp1 ingress
108	log_test "two simultaneously configured mirrors ($tcflags)"
109}
110
111test_gretap()
112{
113	full_test_span_gre_dir gt4 ingress 8 0 "mirror to gretap"
114	full_test_span_gre_dir gt4 egress 0 8 "mirror to gretap"
115}
116
117test_ip6gretap()
118{
119	full_test_span_gre_dir gt6 ingress 8 0 "mirror to ip6gretap"
120	full_test_span_gre_dir gt6 egress 0 8 "mirror to ip6gretap"
121}
122
123test_gretap_mac()
124{
125	test_span_gre_mac gt4 ingress ip "mirror to gretap"
126	test_span_gre_mac gt4 egress ip "mirror to gretap"
127}
128
129test_ip6gretap_mac()
130{
131	test_span_gre_mac gt6 ingress ipv6 "mirror to ip6gretap"
132	test_span_gre_mac gt6 egress ipv6 "mirror to ip6gretap"
133}
134
135test_all()
136{
137	slow_path_trap_install $swp1 ingress
138	slow_path_trap_install $swp1 egress
139
140	tests_run
141
142	slow_path_trap_uninstall $swp1 egress
143	slow_path_trap_uninstall $swp1 ingress
144}
145
146trap cleanup EXIT
147
148setup_prepare
149setup_wait
150
151tcflags="skip_hw"
152test_all
153
154if ! tc_offload_check; then
155	echo "WARN: Could not test offloaded functionality"
156else
157	tcflags="skip_sw"
158	test_all
159fi
160
161exit $EXIT_STATUS
162