Merge branch 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / tools / testing / selftests / net / fib_tests.sh
bloba9154eefb2e2193d7c80630e18406142be5714d6
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking IPv4 and IPv6 FIB behavior in response to
5 # different events.
7 ret=0
9 check_err()
11 if [ $ret -eq 0 ]; then
12 ret=$1
16 check_fail()
18 if [ $1 -eq 0 ]; then
19 ret=1
23 netns_create()
25 local testns=$1
27 ip netns add $testns
28 ip netns exec $testns ip link set dev lo up
31 fib_unreg_unicast_test()
33 ret=0
35 netns_create "testns"
37 ip netns exec testns ip link add dummy0 type dummy
38 ip netns exec testns ip link set dev dummy0 up
40 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
41 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
43 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
44 check_err $?
45 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
46 check_err $?
48 ip netns exec testns ip link del dev dummy0
49 check_err $?
51 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
52 check_fail $?
53 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
54 check_fail $?
56 ip netns del testns
58 if [ $ret -ne 0 ]; then
59 echo "FAIL: unicast route test"
60 return 1
62 echo "PASS: unicast route test"
65 fib_unreg_multipath_test()
67 ret=0
69 netns_create "testns"
71 ip netns exec testns ip link add dummy0 type dummy
72 ip netns exec testns ip link set dev dummy0 up
74 ip netns exec testns ip link add dummy1 type dummy
75 ip netns exec testns ip link set dev dummy1 up
77 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
78 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
80 ip netns exec testns ip address add 192.0.2.1/24 dev dummy1
81 ip netns exec testns ip -6 address add 2001:db8:2::1/64 dev dummy1
83 ip netns exec testns ip route add 203.0.113.0/24 \
84 nexthop via 198.51.100.2 dev dummy0 \
85 nexthop via 192.0.2.2 dev dummy1
86 ip netns exec testns ip -6 route add 2001:db8:3::/64 \
87 nexthop via 2001:db8:1::2 dev dummy0 \
88 nexthop via 2001:db8:2::2 dev dummy1
90 ip netns exec testns ip route get fibmatch 203.0.113.1 &> /dev/null
91 check_err $?
92 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 &> /dev/null
93 check_err $?
95 ip netns exec testns ip link del dev dummy0
96 check_err $?
98 ip netns exec testns ip route get fibmatch 203.0.113.1 &> /dev/null
99 check_fail $?
100 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 &> /dev/null
101 # In IPv6 we do not flush the entire multipath route.
102 check_err $?
104 ip netns exec testns ip link del dev dummy1
106 ip netns del testns
108 if [ $ret -ne 0 ]; then
109 echo "FAIL: multipath route test"
110 return 1
112 echo "PASS: multipath route test"
115 fib_unreg_test()
117 echo "Running netdev unregister tests"
119 fib_unreg_unicast_test
120 fib_unreg_multipath_test
123 fib_down_unicast_test()
125 ret=0
127 netns_create "testns"
129 ip netns exec testns ip link add dummy0 type dummy
130 ip netns exec testns ip link set dev dummy0 up
132 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
133 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
135 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
136 check_err $?
137 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
138 check_err $?
140 ip netns exec testns ip link set dev dummy0 down
141 check_err $?
143 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
144 check_fail $?
145 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
146 check_fail $?
148 ip netns exec testns ip link del dev dummy0
150 ip netns del testns
152 if [ $ret -ne 0 ]; then
153 echo "FAIL: unicast route test"
154 return 1
156 echo "PASS: unicast route test"
159 fib_down_multipath_test_do()
161 local down_dev=$1
162 local up_dev=$2
164 ip netns exec testns ip route get fibmatch 203.0.113.1 \
165 oif $down_dev &> /dev/null
166 check_fail $?
167 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 \
168 oif $down_dev &> /dev/null
169 check_fail $?
171 ip netns exec testns ip route get fibmatch 203.0.113.1 \
172 oif $up_dev &> /dev/null
173 check_err $?
174 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 \
175 oif $up_dev &> /dev/null
176 check_err $?
178 ip netns exec testns ip route get fibmatch 203.0.113.1 | \
179 grep $down_dev | grep -q "dead linkdown"
180 check_err $?
181 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 | \
182 grep $down_dev | grep -q "dead linkdown"
183 check_err $?
185 ip netns exec testns ip route get fibmatch 203.0.113.1 | \
186 grep $up_dev | grep -q "dead linkdown"
187 check_fail $?
188 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 | \
189 grep $up_dev | grep -q "dead linkdown"
190 check_fail $?
193 fib_down_multipath_test()
195 ret=0
197 netns_create "testns"
199 ip netns exec testns ip link add dummy0 type dummy
200 ip netns exec testns ip link set dev dummy0 up
202 ip netns exec testns ip link add dummy1 type dummy
203 ip netns exec testns ip link set dev dummy1 up
205 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
206 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
208 ip netns exec testns ip address add 192.0.2.1/24 dev dummy1
209 ip netns exec testns ip -6 address add 2001:db8:2::1/64 dev dummy1
211 ip netns exec testns ip route add 203.0.113.0/24 \
212 nexthop via 198.51.100.2 dev dummy0 \
213 nexthop via 192.0.2.2 dev dummy1
214 ip netns exec testns ip -6 route add 2001:db8:3::/64 \
215 nexthop via 2001:db8:1::2 dev dummy0 \
216 nexthop via 2001:db8:2::2 dev dummy1
218 ip netns exec testns ip route get fibmatch 203.0.113.1 &> /dev/null
219 check_err $?
220 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 &> /dev/null
221 check_err $?
223 ip netns exec testns ip link set dev dummy0 down
224 check_err $?
226 fib_down_multipath_test_do "dummy0" "dummy1"
228 ip netns exec testns ip link set dev dummy0 up
229 check_err $?
230 ip netns exec testns ip link set dev dummy1 down
231 check_err $?
233 fib_down_multipath_test_do "dummy1" "dummy0"
235 ip netns exec testns ip link set dev dummy0 down
236 check_err $?
238 ip netns exec testns ip route get fibmatch 203.0.113.1 &> /dev/null
239 check_fail $?
240 ip netns exec testns ip -6 route get fibmatch 2001:db8:3::1 &> /dev/null
241 check_fail $?
243 ip netns exec testns ip link del dev dummy1
244 ip netns exec testns ip link del dev dummy0
246 ip netns del testns
248 if [ $ret -ne 0 ]; then
249 echo "FAIL: multipath route test"
250 return 1
252 echo "PASS: multipath route test"
255 fib_down_test()
257 echo "Running netdev down tests"
259 fib_down_unicast_test
260 fib_down_multipath_test
263 fib_carrier_local_test()
265 ret=0
267 # Local routes should not be affected when carrier changes.
268 netns_create "testns"
270 ip netns exec testns ip link add dummy0 type dummy
271 ip netns exec testns ip link set dev dummy0 up
273 ip netns exec testns ip link set dev dummy0 carrier on
275 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
276 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
278 ip netns exec testns ip route get fibmatch 198.51.100.1 &> /dev/null
279 check_err $?
280 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::1 &> /dev/null
281 check_err $?
283 ip netns exec testns ip route get fibmatch 198.51.100.1 | \
284 grep -q "linkdown"
285 check_fail $?
286 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::1 | \
287 grep -q "linkdown"
288 check_fail $?
290 ip netns exec testns ip link set dev dummy0 carrier off
292 ip netns exec testns ip route get fibmatch 198.51.100.1 &> /dev/null
293 check_err $?
294 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::1 &> /dev/null
295 check_err $?
297 ip netns exec testns ip route get fibmatch 198.51.100.1 | \
298 grep -q "linkdown"
299 check_fail $?
300 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::1 | \
301 grep -q "linkdown"
302 check_fail $?
304 ip netns exec testns ip address add 192.0.2.1/24 dev dummy0
305 ip netns exec testns ip -6 address add 2001:db8:2::1/64 dev dummy0
307 ip netns exec testns ip route get fibmatch 192.0.2.1 &> /dev/null
308 check_err $?
309 ip netns exec testns ip -6 route get fibmatch 2001:db8:2::1 &> /dev/null
310 check_err $?
312 ip netns exec testns ip route get fibmatch 192.0.2.1 | \
313 grep -q "linkdown"
314 check_fail $?
315 ip netns exec testns ip -6 route get fibmatch 2001:db8:2::1 | \
316 grep -q "linkdown"
317 check_fail $?
319 ip netns exec testns ip link del dev dummy0
321 ip netns del testns
323 if [ $ret -ne 0 ]; then
324 echo "FAIL: local route carrier test"
325 return 1
327 echo "PASS: local route carrier test"
330 fib_carrier_unicast_test()
332 ret=0
334 netns_create "testns"
336 ip netns exec testns ip link add dummy0 type dummy
337 ip netns exec testns ip link set dev dummy0 up
339 ip netns exec testns ip link set dev dummy0 carrier on
341 ip netns exec testns ip address add 198.51.100.1/24 dev dummy0
342 ip netns exec testns ip -6 address add 2001:db8:1::1/64 dev dummy0
344 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
345 check_err $?
346 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
347 check_err $?
349 ip netns exec testns ip route get fibmatch 198.51.100.2 | \
350 grep -q "linkdown"
351 check_fail $?
352 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 | \
353 grep -q "linkdown"
354 check_fail $?
356 ip netns exec testns ip link set dev dummy0 carrier off
358 ip netns exec testns ip route get fibmatch 198.51.100.2 &> /dev/null
359 check_err $?
360 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 &> /dev/null
361 check_err $?
363 ip netns exec testns ip route get fibmatch 198.51.100.2 | \
364 grep -q "linkdown"
365 check_err $?
366 ip netns exec testns ip -6 route get fibmatch 2001:db8:1::2 | \
367 grep -q "linkdown"
368 check_err $?
370 ip netns exec testns ip address add 192.0.2.1/24 dev dummy0
371 ip netns exec testns ip -6 address add 2001:db8:2::1/64 dev dummy0
373 ip netns exec testns ip route get fibmatch 192.0.2.2 &> /dev/null
374 check_err $?
375 ip netns exec testns ip -6 route get fibmatch 2001:db8:2::2 &> /dev/null
376 check_err $?
378 ip netns exec testns ip route get fibmatch 192.0.2.2 | \
379 grep -q "linkdown"
380 check_err $?
381 ip netns exec testns ip -6 route get fibmatch 2001:db8:2::2 | \
382 grep -q "linkdown"
383 check_err $?
385 ip netns exec testns ip link del dev dummy0
387 ip netns del testns
389 if [ $ret -ne 0 ]; then
390 echo "FAIL: unicast route carrier test"
391 return 1
393 echo "PASS: unicast route carrier test"
396 fib_carrier_test()
398 echo "Running netdev carrier change tests"
400 fib_carrier_local_test
401 fib_carrier_unicast_test
404 fib_test()
406 fib_unreg_test
407 fib_down_test
408 fib_carrier_test
411 if [ "$(id -u)" -ne 0 ];then
412 echo "SKIP: Need root privileges"
413 exit 0
416 if [ ! -x "$(command -v ip)" ]; then
417 echo "SKIP: Could not run test without ip tool"
418 exit 0
421 ip route help 2>&1 | grep -q fibmatch
422 if [ $? -ne 0 ]; then
423 echo "SKIP: iproute2 too old, missing fibmatch"
424 exit 0
427 fib_test
429 exit $ret