2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking IPv4 and IPv6 FIB behavior in response to
11 if [ $ret -eq 0 ]; then
28 ip netns
exec $testns ip link
set dev lo up
31 fib_unreg_unicast_test
()
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
45 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
48 ip netns
exec testns ip link del dev dummy0
51 ip netns
exec testns ip route get fibmatch
198.51.100.2 &> /dev
/null
53 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
58 if [ $ret -ne 0 ]; then
59 echo "FAIL: unicast route test"
62 echo "PASS: unicast route test"
65 fib_unreg_multipath_test
()
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
92 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 &> /dev
/null
95 ip netns
exec testns ip link del dev dummy0
98 ip netns
exec testns ip route get fibmatch
203.0.113.1 &> /dev
/null
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.
104 ip netns
exec testns ip link del dev dummy1
108 if [ $ret -ne 0 ]; then
109 echo "FAIL: multipath route test"
112 echo "PASS: multipath route test"
117 echo "Running netdev unregister tests"
119 fib_unreg_unicast_test
120 fib_unreg_multipath_test
123 fib_down_unicast_test
()
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
137 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
140 ip netns
exec testns ip link
set dev dummy0 down
143 ip netns
exec testns ip route get fibmatch
198.51.100.2 &> /dev
/null
145 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
148 ip netns
exec testns ip link del dev dummy0
152 if [ $ret -ne 0 ]; then
153 echo "FAIL: unicast route test"
156 echo "PASS: unicast route test"
159 fib_down_multipath_test_do
()
164 ip netns
exec testns ip route get fibmatch
203.0.113.1 \
165 oif
$down_dev &> /dev
/null
167 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 \
168 oif
$down_dev &> /dev
/null
171 ip netns
exec testns ip route get fibmatch
203.0.113.1 \
172 oif
$up_dev &> /dev
/null
174 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 \
175 oif
$up_dev &> /dev
/null
178 ip netns
exec testns ip route get fibmatch
203.0.113.1 | \
179 grep $down_dev |
grep -q "dead linkdown"
181 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 | \
182 grep $down_dev |
grep -q "dead linkdown"
185 ip netns
exec testns ip route get fibmatch
203.0.113.1 | \
186 grep $up_dev |
grep -q "dead linkdown"
188 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 | \
189 grep $up_dev |
grep -q "dead linkdown"
193 fib_down_multipath_test
()
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
220 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 &> /dev
/null
223 ip netns
exec testns ip link
set dev dummy0 down
226 fib_down_multipath_test_do
"dummy0" "dummy1"
228 ip netns
exec testns ip link
set dev dummy0 up
230 ip netns
exec testns ip link
set dev dummy1 down
233 fib_down_multipath_test_do
"dummy1" "dummy0"
235 ip netns
exec testns ip link
set dev dummy0 down
238 ip netns
exec testns ip route get fibmatch
203.0.113.1 &> /dev
/null
240 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:3::1 &> /dev
/null
243 ip netns
exec testns ip link del dev dummy1
244 ip netns
exec testns ip link del dev dummy0
248 if [ $ret -ne 0 ]; then
249 echo "FAIL: multipath route test"
252 echo "PASS: multipath route test"
257 echo "Running netdev down tests"
259 fib_down_unicast_test
260 fib_down_multipath_test
263 fib_carrier_local_test
()
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
280 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::1 &> /dev
/null
283 ip netns
exec testns ip route get fibmatch
198.51.100.1 | \
286 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::1 | \
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
294 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::1 &> /dev
/null
297 ip netns
exec testns ip route get fibmatch
198.51.100.1 | \
300 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::1 | \
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
309 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:2::1 &> /dev
/null
312 ip netns
exec testns ip route get fibmatch
192.0.2.1 | \
315 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:2::1 | \
319 ip netns
exec testns ip link del dev dummy0
323 if [ $ret -ne 0 ]; then
324 echo "FAIL: local route carrier test"
327 echo "PASS: local route carrier test"
330 fib_carrier_unicast_test
()
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
346 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
349 ip netns
exec testns ip route get fibmatch
198.51.100.2 | \
352 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 | \
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
360 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 &> /dev
/null
363 ip netns
exec testns ip route get fibmatch
198.51.100.2 | \
366 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:1::2 | \
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
375 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:2::2 &> /dev
/null
378 ip netns
exec testns ip route get fibmatch
192.0.2.2 | \
381 ip netns
exec testns ip
-6 route get fibmatch
2001:db8
:2::2 | \
385 ip netns
exec testns ip link del dev dummy0
389 if [ $ret -ne 0 ]; then
390 echo "FAIL: unicast route carrier test"
393 echo "PASS: unicast route carrier test"
398 echo "Running netdev carrier change tests"
400 fib_carrier_local_test
401 fib_carrier_unicast_test
411 if [ "$(id -u)" -ne 0 ];then
412 echo "SKIP: Need root privileges"
416 if [ ! -x "$(command -v ip)" ]; then
417 echo "SKIP: Could not run test without ip tool"
421 ip route
help 2>&1 |
grep -q fibmatch
422 if [ $?
-ne 0 ]; then
423 echo "SKIP: iproute2 too old, missing fibmatch"