Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / mirror_gre_changes.sh
blob135902aa8b11498bfbf99428a77084b4ee3de7fd
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 mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
84 ip link set dev $tundev type $type ttl 100
85 tc filter del dev $h3 ingress pref 77
86 mirror_uninstall $swp1 ingress
88 log_test "$what: TTL change ($tcflags)"
91 test_span_gre_tun_up()
93 local tundev=$1; shift
94 local what=$1; shift
96 RET=0
98 ip link set dev $tundev down
99 mirror_install $swp1 ingress $tundev "matchall $tcflags"
100 fail_test_span_gre_dir $tundev ingress
102 ip link set dev $tundev up
104 quick_test_span_gre_dir $tundev ingress
105 mirror_uninstall $swp1 ingress
107 log_test "$what: tunnel down/up ($tcflags)"
110 test_span_gre_egress_up()
112 local tundev=$1; shift
113 local remote_ip=$1; shift
114 local what=$1; shift
116 RET=0
118 ip link set dev $swp3 down
119 mirror_install $swp1 ingress $tundev "matchall $tcflags"
120 fail_test_span_gre_dir $tundev ingress
122 # After setting the device up, wait for neighbor to get resolved so that
123 # we can expect mirroring to work.
124 ip link set dev $swp3 up
125 setup_wait_dev $swp3
126 ping -c 1 -I $swp3 $remote_ip &>/dev/null
128 quick_test_span_gre_dir $tundev ingress
129 mirror_uninstall $swp1 ingress
131 log_test "$what: egress down/up ($tcflags)"
134 test_span_gre_remote_ip()
136 local tundev=$1; shift
137 local type=$1; shift
138 local correct_ip=$1; shift
139 local wrong_ip=$1; shift
140 local what=$1; shift
142 RET=0
144 ip link set dev $tundev type $type remote $wrong_ip
145 mirror_install $swp1 ingress $tundev "matchall $tcflags"
146 fail_test_span_gre_dir $tundev ingress
148 ip link set dev $tundev type $type remote $correct_ip
149 quick_test_span_gre_dir $tundev ingress
150 mirror_uninstall $swp1 ingress
152 log_test "$what: remote address change ($tcflags)"
155 test_span_gre_tun_del()
157 local tundev=$1; shift
158 local type=$1; shift
159 local flags=$1; shift
160 local local_ip=$1; shift
161 local remote_ip=$1; shift
162 local what=$1; shift
164 RET=0
166 mirror_install $swp1 ingress $tundev "matchall $tcflags"
167 quick_test_span_gre_dir $tundev ingress
168 ip link del dev $tundev
169 fail_test_span_gre_dir $tundev ingress
171 tunnel_create $tundev $type $local_ip $remote_ip \
172 ttl 100 tos inherit $flags
174 # Recreating the tunnel doesn't reestablish mirroring, so reinstall it
175 # and verify it works for the follow-up tests.
176 mirror_uninstall $swp1 ingress
177 mirror_install $swp1 ingress $tundev "matchall $tcflags"
178 quick_test_span_gre_dir $tundev ingress
179 mirror_uninstall $swp1 ingress
181 log_test "$what: tunnel deleted ($tcflags)"
184 test_span_gre_route_del()
186 local tundev=$1; shift
187 local edev=$1; shift
188 local route=$1; shift
189 local what=$1; shift
191 RET=0
193 mirror_install $swp1 ingress $tundev "matchall $tcflags"
194 quick_test_span_gre_dir $tundev ingress
196 ip route del $route dev $edev
197 fail_test_span_gre_dir $tundev ingress
199 ip route add $route dev $edev
200 quick_test_span_gre_dir $tundev ingress
202 mirror_uninstall $swp1 ingress
204 log_test "$what: underlay route removal ($tcflags)"
207 test_ttl()
209 test_span_gre_ttl gt4 gretap ip "mirror to gretap"
210 test_span_gre_ttl gt6 ip6gretap ipv6 "mirror to ip6gretap"
213 test_tun_up()
215 test_span_gre_tun_up gt4 "mirror to gretap"
216 test_span_gre_tun_up gt6 "mirror to ip6gretap"
219 test_egress_up()
221 test_span_gre_egress_up gt4 192.0.2.130 "mirror to gretap"
222 test_span_gre_egress_up gt6 2001:db8:2::2 "mirror to ip6gretap"
225 test_remote_ip()
227 test_span_gre_remote_ip gt4 gretap 192.0.2.130 192.0.2.132 "mirror to gretap"
228 test_span_gre_remote_ip gt6 ip6gretap 2001:db8:2::2 2001:db8:2::4 "mirror to ip6gretap"
231 test_tun_del()
233 test_span_gre_tun_del gt4 gretap "" \
234 192.0.2.129 192.0.2.130 "mirror to gretap"
235 test_span_gre_tun_del gt6 ip6gretap allow-localremote \
236 2001:db8:2::1 2001:db8:2::2 "mirror to ip6gretap"
239 test_route_del()
241 test_span_gre_route_del gt4 $swp3 192.0.2.128/28 "mirror to gretap"
242 test_span_gre_route_del gt6 $swp3 2001:db8:2::/64 "mirror to ip6gretap"
245 test_all()
247 slow_path_trap_install $swp1 ingress
248 slow_path_trap_install $swp1 egress
250 tests_run
252 slow_path_trap_uninstall $swp1 egress
253 slow_path_trap_uninstall $swp1 ingress
256 trap cleanup EXIT
258 setup_prepare
259 setup_wait
261 tcflags="skip_hw"
262 test_all
264 if ! tc_offload_check; then
265 echo "WARN: Could not test offloaded functionality"
266 else
267 tcflags="skip_sw"
268 test_all
271 exit $EXIT_STATUS