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 that gretap and ip6gretap mirroring works when the other tunnel endpoint
8# is reachable through a next-hop route (as opposed to directly-attached route).
9
10NUM_NETIFS=6
11source lib.sh
12source mirror_lib.sh
13source mirror_gre_lib.sh
14source mirror_gre_topo_lib.sh
15
16setup_prepare()
17{
18	h1=${NETIFS[p1]}
19	swp1=${NETIFS[p2]}
20
21	swp2=${NETIFS[p3]}
22	h2=${NETIFS[p4]}
23
24	swp3=${NETIFS[p5]}
25	h3=${NETIFS[p6]}
26
27	vrf_prepare
28	mirror_gre_topo_create
29
30	ip address add dev $swp3 192.0.2.161/28
31	ip address add dev $h3 192.0.2.162/28
32	ip address add dev gt4 192.0.2.129/32
33	ip address add dev h3-gt4 192.0.2.130/32
34
35	# IPv6 route can't be added after address. Such routes are rejected due
36	# to the gateway address having been configured on the local system. It
37	# works the other way around though.
38	ip address add dev $swp3 2001:db8:4::1/64
39	ip -6 route add 2001:db8:2::2/128 via 2001:db8:4::2
40	ip address add dev $h3 2001:db8:4::2/64
41	ip address add dev gt6 2001:db8:2::1
42	ip address add dev h3-gt6 2001:db8:2::2
43}
44
45cleanup()
46{
47	pre_cleanup
48
49	ip -6 route del 2001:db8:2::2/128 via 2001:db8:4::2
50	ip address del dev $h3 2001:db8:4::2/64
51	ip address del dev $swp3 2001:db8:4::1/64
52
53	ip address del dev $h3 192.0.2.162/28
54	ip address del dev $swp3 192.0.2.161/28
55
56	mirror_gre_topo_destroy
57	vrf_cleanup
58}
59
60test_gretap()
61{
62	RET=0
63	mirror_install $swp1 ingress gt4 "matchall $tcflags"
64
65	# For IPv4, test that there's no mirroring without the route directing
66	# the traffic to tunnel remote address. Then add it and test that
67	# mirroring starts. For IPv6 we can't test this due to the limitation
68	# that routes for locally-specified IPv6 addresses can't be added.
69	fail_test_span_gre_dir gt4 ingress
70
71	ip route add 192.0.2.130/32 via 192.0.2.162
72	quick_test_span_gre_dir gt4 ingress
73	ip route del 192.0.2.130/32 via 192.0.2.162
74
75	mirror_uninstall $swp1 ingress
76	log_test "mirror to gre with next-hop remote ($tcflags)"
77}
78
79test_ip6gretap()
80{
81	RET=0
82
83	mirror_install $swp1 ingress gt6 "matchall $tcflags"
84	quick_test_span_gre_dir gt6 ingress
85	mirror_uninstall $swp1 ingress
86
87	log_test "mirror to ip6gre with next-hop remote ($tcflags)"
88}
89
90test_all()
91{
92	slow_path_trap_install $swp1 ingress
93	slow_path_trap_install $swp1 egress
94
95	test_gretap
96	test_ip6gretap
97
98	slow_path_trap_uninstall $swp1 egress
99	slow_path_trap_uninstall $swp1 ingress
100}
101
102trap cleanup EXIT
103
104setup_prepare
105setup_wait
106
107tcflags="skip_hw"
108test_all
109
110if ! tc_offload_check; then
111	echo "WARN: Could not test offloaded functionality"
112else
113	tcflags="skip_sw"
114	test_all
115fi
116
117exit $EXIT_STATUS
118