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# This tests flower-triggered mirroring to gretap and ip6gretap netdevices. The
8# interfaces on H1 and H2 have two addresses each. Flower match on one of the
9# addresses is configured with mirror action. It is expected that when pinging
10# this address, mirroring takes place, whereas when pinging the other one,
11# there's no mirroring.
12
13NUM_NETIFS=6
14source lib.sh
15source mirror_lib.sh
16source mirror_gre_lib.sh
17source mirror_gre_topo_lib.sh
18
19setup_prepare()
20{
21	h1=${NETIFS[p1]}
22	swp1=${NETIFS[p2]}
23
24	swp2=${NETIFS[p3]}
25	h2=${NETIFS[p4]}
26
27	swp3=${NETIFS[p5]}
28	h3=${NETIFS[p6]}
29
30	vrf_prepare
31	mirror_gre_topo_create
32
33	ip address add dev $swp3 192.0.2.129/28
34	ip address add dev $h3 192.0.2.130/28
35
36	ip address add dev $swp3 2001:db8:2::1/64
37	ip address add dev $h3 2001:db8:2::2/64
38
39	ip address add dev $h1 192.0.2.3/28
40	ip address add dev $h2 192.0.2.4/28
41}
42
43cleanup()
44{
45	pre_cleanup
46
47	ip address del dev $h2 192.0.2.4/28
48	ip address del dev $h1 192.0.2.3/28
49
50	ip address del dev $h3 2001:db8:2::2/64
51	ip address del dev $swp3 2001:db8:2::1/64
52
53	ip address del dev $h3 192.0.2.130/28
54	ip address del dev $swp3 192.0.2.129/28
55
56	mirror_gre_topo_destroy
57	vrf_cleanup
58}
59
60test_span_gre_dir_acl()
61{
62	test_span_gre_dir_ips "$@" 192.0.2.3 192.0.2.4
63}
64
65full_test_span_gre_dir_acl()
66{
67	local tundev=$1; shift
68	local direction=$1; shift
69	local forward_type=$1; shift
70	local backward_type=$1; shift
71	local match_dip=$1; shift
72	local what=$1; shift
73
74	mirror_install $swp1 $direction $tundev \
75		       "protocol ip flower $tcflags dst_ip $match_dip"
76	fail_test_span_gre_dir $tundev $direction
77	test_span_gre_dir_acl "$tundev" "$direction" \
78			  "$forward_type" "$backward_type"
79	mirror_uninstall $swp1 $direction
80
81	log_test "$direction $what ($tcflags)"
82}
83
84test_all()
85{
86	RET=0
87
88	slow_path_trap_install $swp1 ingress
89	slow_path_trap_install $swp1 egress
90
91	full_test_span_gre_dir_acl gt4 ingress 8 0 192.0.2.4 "ACL mirror to gretap"
92	full_test_span_gre_dir_acl gt6 ingress 8 0 192.0.2.4 "ACL mirror to ip6gretap"
93
94	full_test_span_gre_dir_acl gt4 egress 0 8 192.0.2.3 "ACL mirror to gretap"
95	full_test_span_gre_dir_acl gt6 egress 0 8 192.0.2.3 "ACL mirror to ip6gretap"
96
97	slow_path_trap_uninstall $swp1 egress
98	slow_path_trap_uninstall $swp1 ingress
99}
100
101trap cleanup EXIT
102
103setup_prepare
104setup_wait
105
106tcflags="skip_hw"
107test_all
108
109if ! tc_offload_check; then
110	echo "WARN: Could not test offloaded functionality"
111else
112	tcflags="skip_sw"
113	test_all
114fi
115
116exit $EXIT_STATUS
117