WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / mirror_gre_changes.sh
blob472bd023e2a5fb591727dee854641adacb5d87fe
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test uses standard topology for testing gretap. See
5 # mirror_gre_topo_lib.sh for more details.
7 # Test how mirrors to gretap and ip6gretap react to changes to relevant
8 # configuration.
10 ALL_TESTS="
11 test_ttl
12 test_tun_up
13 test_egress_up
14 test_remote_ip
15 test_tun_del
16 test_route_del
19 NUM_NETIFS=6
20 source lib.sh
21 source mirror_lib.sh
22 source mirror_gre_lib.sh
23 source mirror_gre_topo_lib.sh
25 setup_prepare()
27 h1=${NETIFS[p1]}
28 swp1=${NETIFS[p2]}
30 swp2=${NETIFS[p3]}
31 h2=${NETIFS[p4]}
33 swp3=${NETIFS[p5]}
34 h3=${NETIFS[p6]}
36 vrf_prepare
37 mirror_gre_topo_create
39 # This test downs $swp3, which deletes the configured IPv6 address
40 # unless this sysctl is set.
41 sysctl_set net.ipv6.conf.$swp3.keep_addr_on_down 1
43 ip address add dev $swp3 192.0.2.129/28
44 ip address add dev $h3 192.0.2.130/28
46 ip address add dev $swp3 2001:db8:2::1/64
47 ip address add dev $h3 2001:db8:2::2/64
50 cleanup()
52 pre_cleanup
54 ip address del dev $h3 2001:db8:2::2/64
55 ip address del dev $swp3 2001:db8:2::1/64
57 ip address del dev $h3 192.0.2.130/28
58 ip address del dev $swp3 192.0.2.129/28
60 sysctl_restore net.ipv6.conf.$swp3.keep_addr_on_down
62 mirror_gre_topo_destroy
63 vrf_cleanup
66 test_span_gre_ttl()
68 local tundev=$1; shift
69 local type=$1; shift
70 local prot=$1; shift
71 local what=$1; shift
73 RET=0
75 mirror_install $swp1 ingress $tundev "matchall $tcflags"
76 tc filter add dev $h3 ingress pref 77 prot $prot \
77 flower ip_ttl 50 action pass
79 mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 0
81 ip link set dev $tundev type $type ttl 50
82 sleep 2
83 mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
85 ip link set dev $tundev type $type ttl 100
86 tc filter del dev $h3 ingress pref 77
87 mirror_uninstall $swp1 ingress
89 log_test "$what: TTL change ($tcflags)"
92 test_span_gre_tun_up()
94 local tundev=$1; shift
95 local what=$1; shift
97 RET=0
99 ip link set dev $tundev down
100 mirror_install $swp1 ingress $tundev "matchall $tcflags"
101 fail_test_span_gre_dir $tundev ingress
103 ip link set dev $tundev up
105 quick_test_span_gre_dir $tundev ingress
106 mirror_uninstall $swp1 ingress
108 log_test "$what: tunnel down/up ($tcflags)"
111 test_span_gre_egress_up()
113 local tundev=$1; shift
114 local remote_ip=$1; shift
115 local what=$1; shift
117 RET=0
119 ip link set dev $swp3 down
120 mirror_install $swp1 ingress $tundev "matchall $tcflags"
121 fail_test_span_gre_dir $tundev ingress
123 # After setting the device up, wait for neighbor to get resolved so that
124 # we can expect mirroring to work.
125 ip link set dev $swp3 up
126 setup_wait_dev $swp3
127 ping -c 1 -I $swp3 $remote_ip &>/dev/null
129 quick_test_span_gre_dir $tundev ingress
130 mirror_uninstall $swp1 ingress
132 log_test "$what: egress down/up ($tcflags)"
135 test_span_gre_remote_ip()
137 local tundev=$1; shift
138 local type=$1; shift
139 local correct_ip=$1; shift
140 local wrong_ip=$1; shift
141 local what=$1; shift
143 RET=0
145 ip link set dev $tundev type $type remote $wrong_ip
146 mirror_install $swp1 ingress $tundev "matchall $tcflags"
147 fail_test_span_gre_dir $tundev ingress
149 ip link set dev $tundev type $type remote $correct_ip
150 quick_test_span_gre_dir $tundev ingress
151 mirror_uninstall $swp1 ingress
153 log_test "$what: remote address change ($tcflags)"
156 test_span_gre_tun_del()
158 local tundev=$1; shift
159 local type=$1; shift
160 local flags=$1; shift
161 local local_ip=$1; shift
162 local remote_ip=$1; shift
163 local what=$1; shift
165 RET=0
167 mirror_install $swp1 ingress $tundev "matchall $tcflags"
168 quick_test_span_gre_dir $tundev ingress
169 ip link del dev $tundev
170 fail_test_span_gre_dir $tundev ingress
172 tunnel_create $tundev $type $local_ip $remote_ip \
173 ttl 100 tos inherit $flags
175 # Recreating the tunnel doesn't reestablish mirroring, so reinstall it
176 # and verify it works for the follow-up tests.
177 mirror_uninstall $swp1 ingress
178 mirror_install $swp1 ingress $tundev "matchall $tcflags"
179 quick_test_span_gre_dir $tundev ingress
180 mirror_uninstall $swp1 ingress
182 log_test "$what: tunnel deleted ($tcflags)"
185 test_span_gre_route_del()
187 local tundev=$1; shift
188 local edev=$1; shift
189 local route=$1; shift
190 local what=$1; shift
192 RET=0
194 mirror_install $swp1 ingress $tundev "matchall $tcflags"
195 quick_test_span_gre_dir $tundev ingress
197 ip route del $route dev $edev
198 fail_test_span_gre_dir $tundev ingress
200 ip route add $route dev $edev
201 quick_test_span_gre_dir $tundev ingress
203 mirror_uninstall $swp1 ingress
205 log_test "$what: underlay route removal ($tcflags)"
208 test_ttl()
210 test_span_gre_ttl gt4 gretap ip "mirror to gretap"
211 test_span_gre_ttl gt6 ip6gretap ipv6 "mirror to ip6gretap"
214 test_tun_up()
216 test_span_gre_tun_up gt4 "mirror to gretap"
217 test_span_gre_tun_up gt6 "mirror to ip6gretap"
220 test_egress_up()
222 test_span_gre_egress_up gt4 192.0.2.130 "mirror to gretap"
223 test_span_gre_egress_up gt6 2001:db8:2::2 "mirror to ip6gretap"
226 test_remote_ip()
228 test_span_gre_remote_ip gt4 gretap 192.0.2.130 192.0.2.132 "mirror to gretap"
229 test_span_gre_remote_ip gt6 ip6gretap 2001:db8:2::2 2001:db8:2::4 "mirror to ip6gretap"
232 test_tun_del()
234 test_span_gre_tun_del gt4 gretap "" \
235 192.0.2.129 192.0.2.130 "mirror to gretap"
236 test_span_gre_tun_del gt6 ip6gretap allow-localremote \
237 2001:db8:2::1 2001:db8:2::2 "mirror to ip6gretap"
240 test_route_del()
242 test_span_gre_route_del gt4 $swp3 192.0.2.128/28 "mirror to gretap"
243 test_span_gre_route_del gt6 $swp3 2001:db8:2::/64 "mirror to ip6gretap"
246 test_all()
248 slow_path_trap_install $swp1 ingress
249 slow_path_trap_install $swp1 egress
251 tests_run
253 slow_path_trap_uninstall $swp1 egress
254 slow_path_trap_uninstall $swp1 ingress
257 trap cleanup EXIT
259 setup_prepare
260 setup_wait
262 tcflags="skip_hw"
263 test_all
265 if ! tc_offload_check; then
266 echo "WARN: Could not test offloaded functionality"
267 else
268 tcflags="skip_sw"
269 test_all
272 exit $EXIT_STATUS