blob: e113cfd659fc0569da7c4094e810d9bb5416cd13 [file] [log] [blame]
Ido Schimmel607bd2e2018-01-07 12:45:16 +02001#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test is for checking IPv4 and IPv6 FIB behavior in response to
5# different events.
6
7ret=0
8
David Ahern10566912018-02-13 08:37:34 -08009PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
Ido Schimmel607bd2e2018-01-07 12:45:16 +020010
David Ahern10566912018-02-13 08:37:34 -080011log_test()
Ido Schimmel607bd2e2018-01-07 12:45:16 +020012{
David Ahern10566912018-02-13 08:37:34 -080013 local rc=$1
14 local expected=$2
15 local msg="$3"
16
17 if [ ${rc} -eq ${expected} ]; then
18 printf " %-60s [ OK ]\n" "${msg}"
19 else
Ido Schimmel607bd2e2018-01-07 12:45:16 +020020 ret=1
David Ahern10566912018-02-13 08:37:34 -080021 printf " %-60s [FAIL]\n" "${msg}"
22 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
23 echo
24 echo "hit enter to continue, 'q' to quit"
25 read a
26 [ "$a" = "q" ] && exit 1
27 fi
Ido Schimmel607bd2e2018-01-07 12:45:16 +020028 fi
29}
30
David Ahernee395a52018-02-13 08:37:35 -080031setup()
Ido Schimmel607bd2e2018-01-07 12:45:16 +020032{
David Ahernee395a52018-02-13 08:37:35 -080033 set -e
34 ip netns add testns
35 ip -netns testns link set dev lo up
Ido Schimmel607bd2e2018-01-07 12:45:16 +020036
David Ahernee395a52018-02-13 08:37:35 -080037 ip -netns testns link add dummy0 type dummy
38 ip -netns testns link set dev dummy0 up
39 ip -netns testns address add 198.51.100.1/24 dev dummy0
40 ip -netns testns -6 address add 2001:db8:1::1/64 dev dummy0
41 set +e
42
43}
44
45cleanup()
46{
47 ip -netns testns link del dev dummy0 &> /dev/null
48 ip netns del testns
Ido Schimmel607bd2e2018-01-07 12:45:16 +020049}
50
51fib_unreg_unicast_test()
52{
David Ahern10566912018-02-13 08:37:34 -080053 echo
54 echo "Single path route test"
Ido Schimmel607bd2e2018-01-07 12:45:16 +020055
David Ahernee395a52018-02-13 08:37:35 -080056 setup
Ido Schimmel607bd2e2018-01-07 12:45:16 +020057
David Ahern10566912018-02-13 08:37:34 -080058 echo " Start point"
David Ahern07f4e622018-02-13 08:37:33 -080059 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -080060 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -080061 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -080062 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel607bd2e2018-01-07 12:45:16 +020063
David Ahern10566912018-02-13 08:37:34 -080064 set -e
David Ahern07f4e622018-02-13 08:37:33 -080065 ip -netns testns link del dev dummy0
David Ahern10566912018-02-13 08:37:34 -080066 set +e
Ido Schimmel607bd2e2018-01-07 12:45:16 +020067
David Ahern10566912018-02-13 08:37:34 -080068 echo " Nexthop device deleted"
David Ahern07f4e622018-02-13 08:37:33 -080069 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -080070 log_test $? 2 "IPv4 fibmatch - no route"
David Ahern07f4e622018-02-13 08:37:33 -080071 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -080072 log_test $? 2 "IPv6 fibmatch - no route"
Ido Schimmel607bd2e2018-01-07 12:45:16 +020073
David Ahernee395a52018-02-13 08:37:35 -080074 cleanup
Ido Schimmel607bd2e2018-01-07 12:45:16 +020075}
76
77fib_unreg_multipath_test()
78{
Ido Schimmel607bd2e2018-01-07 12:45:16 +020079
David Ahern10566912018-02-13 08:37:34 -080080 echo
81 echo "Multipath route test"
82
David Ahernee395a52018-02-13 08:37:35 -080083 setup
84
David Ahern10566912018-02-13 08:37:34 -080085 set -e
David Ahern07f4e622018-02-13 08:37:33 -080086 ip -netns testns link add dummy1 type dummy
87 ip -netns testns link set dev dummy1 up
David Ahern07f4e622018-02-13 08:37:33 -080088 ip -netns testns address add 192.0.2.1/24 dev dummy1
89 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1
Ido Schimmel607bd2e2018-01-07 12:45:16 +020090
David Ahern07f4e622018-02-13 08:37:33 -080091 ip -netns testns route add 203.0.113.0/24 \
Ido Schimmel607bd2e2018-01-07 12:45:16 +020092 nexthop via 198.51.100.2 dev dummy0 \
93 nexthop via 192.0.2.2 dev dummy1
David Ahern07f4e622018-02-13 08:37:33 -080094 ip -netns testns -6 route add 2001:db8:3::/64 \
Ido Schimmel607bd2e2018-01-07 12:45:16 +020095 nexthop via 2001:db8:1::2 dev dummy0 \
96 nexthop via 2001:db8:2::2 dev dummy1
David Ahern10566912018-02-13 08:37:34 -080097 set +e
Ido Schimmel607bd2e2018-01-07 12:45:16 +020098
David Ahern10566912018-02-13 08:37:34 -080099 echo " Start point"
David Ahern07f4e622018-02-13 08:37:33 -0800100 ip -netns testns route get fibmatch 203.0.113.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800101 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800102 ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800103 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200104
David Ahern10566912018-02-13 08:37:34 -0800105 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800106 ip -netns testns link del dev dummy0
David Ahern10566912018-02-13 08:37:34 -0800107 set +e
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200108
David Ahern10566912018-02-13 08:37:34 -0800109 echo " One nexthop device deleted"
David Ahern07f4e622018-02-13 08:37:33 -0800110 ip -netns testns route get fibmatch 203.0.113.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800111 log_test $? 2 "IPv4 - multipath route removed on delete"
112
David Ahern07f4e622018-02-13 08:37:33 -0800113 ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200114 # In IPv6 we do not flush the entire multipath route.
David Ahern10566912018-02-13 08:37:34 -0800115 log_test $? 0 "IPv6 - multipath down to single path"
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200116
David Ahern10566912018-02-13 08:37:34 -0800117 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800118 ip -netns testns link del dev dummy1
David Ahern10566912018-02-13 08:37:34 -0800119 set +e
120
121 echo " Second nexthop device deleted"
122 ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
123 log_test $? 2 "IPv6 - no route"
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200124
David Ahernee395a52018-02-13 08:37:35 -0800125 cleanup
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200126}
127
128fib_unreg_test()
129{
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200130 fib_unreg_unicast_test
131 fib_unreg_multipath_test
132}
133
Ido Schimmel5adb7682018-01-07 12:45:17 +0200134fib_down_unicast_test()
135{
David Ahern10566912018-02-13 08:37:34 -0800136 echo
137 echo "Single path, admin down"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200138
David Ahernee395a52018-02-13 08:37:35 -0800139 setup
Ido Schimmel5adb7682018-01-07 12:45:17 +0200140
David Ahern10566912018-02-13 08:37:34 -0800141 echo " Start point"
David Ahern07f4e622018-02-13 08:37:33 -0800142 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800143 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800144 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800145 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200146
David Ahern10566912018-02-13 08:37:34 -0800147 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800148 ip -netns testns link set dev dummy0 down
David Ahern10566912018-02-13 08:37:34 -0800149 set +e
Ido Schimmel5adb7682018-01-07 12:45:17 +0200150
David Ahern10566912018-02-13 08:37:34 -0800151 echo " Route deleted on down"
David Ahern07f4e622018-02-13 08:37:33 -0800152 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800153 log_test $? 2 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800154 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800155 log_test $? 2 "IPv6 fibmatch"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200156
David Ahernee395a52018-02-13 08:37:35 -0800157 cleanup
Ido Schimmel5adb7682018-01-07 12:45:17 +0200158}
159
160fib_down_multipath_test_do()
161{
162 local down_dev=$1
163 local up_dev=$2
164
David Ahern07f4e622018-02-13 08:37:33 -0800165 ip -netns testns route get fibmatch 203.0.113.1 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200166 oif $down_dev &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800167 log_test $? 2 "IPv4 fibmatch on down device"
David Ahern07f4e622018-02-13 08:37:33 -0800168 ip -netns testns -6 route get fibmatch 2001:db8:3::1 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200169 oif $down_dev &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800170 log_test $? 2 "IPv6 fibmatch on down device"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200171
David Ahern07f4e622018-02-13 08:37:33 -0800172 ip -netns testns route get fibmatch 203.0.113.1 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200173 oif $up_dev &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800174 log_test $? 0 "IPv4 fibmatch on up device"
David Ahern07f4e622018-02-13 08:37:33 -0800175 ip -netns testns -6 route get fibmatch 2001:db8:3::1 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200176 oif $up_dev &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800177 log_test $? 0 "IPv6 fibmatch on up device"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200178
David Ahern07f4e622018-02-13 08:37:33 -0800179 ip -netns testns route get fibmatch 203.0.113.1 | \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200180 grep $down_dev | grep -q "dead linkdown"
David Ahern10566912018-02-13 08:37:34 -0800181 log_test $? 0 "IPv4 flags on down device"
David Ahern07f4e622018-02-13 08:37:33 -0800182 ip -netns testns -6 route get fibmatch 2001:db8:3::1 | \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200183 grep $down_dev | grep -q "dead linkdown"
David Ahern10566912018-02-13 08:37:34 -0800184 log_test $? 0 "IPv6 flags on down device"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200185
David Ahern07f4e622018-02-13 08:37:33 -0800186 ip -netns testns route get fibmatch 203.0.113.1 | \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200187 grep $up_dev | grep -q "dead linkdown"
David Ahern10566912018-02-13 08:37:34 -0800188 log_test $? 1 "IPv4 flags on up device"
David Ahern07f4e622018-02-13 08:37:33 -0800189 ip -netns testns -6 route get fibmatch 2001:db8:3::1 | \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200190 grep $up_dev | grep -q "dead linkdown"
David Ahern10566912018-02-13 08:37:34 -0800191 log_test $? 1 "IPv6 flags on up device"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200192}
193
194fib_down_multipath_test()
195{
David Ahern10566912018-02-13 08:37:34 -0800196 echo
197 echo "Admin down multipath"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200198
David Ahernee395a52018-02-13 08:37:35 -0800199 setup
200
David Ahern10566912018-02-13 08:37:34 -0800201 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800202 ip -netns testns link add dummy1 type dummy
203 ip -netns testns link set dev dummy1 up
Ido Schimmel5adb7682018-01-07 12:45:17 +0200204
David Ahern07f4e622018-02-13 08:37:33 -0800205 ip -netns testns address add 192.0.2.1/24 dev dummy1
206 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy1
Ido Schimmel5adb7682018-01-07 12:45:17 +0200207
David Ahern07f4e622018-02-13 08:37:33 -0800208 ip -netns testns route add 203.0.113.0/24 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200209 nexthop via 198.51.100.2 dev dummy0 \
210 nexthop via 192.0.2.2 dev dummy1
David Ahern07f4e622018-02-13 08:37:33 -0800211 ip -netns testns -6 route add 2001:db8:3::/64 \
Ido Schimmel5adb7682018-01-07 12:45:17 +0200212 nexthop via 2001:db8:1::2 dev dummy0 \
213 nexthop via 2001:db8:2::2 dev dummy1
David Ahern10566912018-02-13 08:37:34 -0800214 set +e
Ido Schimmel5adb7682018-01-07 12:45:17 +0200215
David Ahern10566912018-02-13 08:37:34 -0800216 echo " Verify start point"
David Ahern07f4e622018-02-13 08:37:33 -0800217 ip -netns testns route get fibmatch 203.0.113.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800218 log_test $? 0 "IPv4 fibmatch"
219
David Ahern07f4e622018-02-13 08:37:33 -0800220 ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800221 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200222
David Ahern10566912018-02-13 08:37:34 -0800223 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800224 ip -netns testns link set dev dummy0 down
David Ahern10566912018-02-13 08:37:34 -0800225 set +e
Ido Schimmel5adb7682018-01-07 12:45:17 +0200226
David Ahern10566912018-02-13 08:37:34 -0800227 echo " One device down, one up"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200228 fib_down_multipath_test_do "dummy0" "dummy1"
229
David Ahern10566912018-02-13 08:37:34 -0800230 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800231 ip -netns testns link set dev dummy0 up
David Ahern07f4e622018-02-13 08:37:33 -0800232 ip -netns testns link set dev dummy1 down
David Ahern10566912018-02-13 08:37:34 -0800233 set +e
Ido Schimmel5adb7682018-01-07 12:45:17 +0200234
David Ahern10566912018-02-13 08:37:34 -0800235 echo " Other device down and up"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200236 fib_down_multipath_test_do "dummy1" "dummy0"
237
David Ahern10566912018-02-13 08:37:34 -0800238 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800239 ip -netns testns link set dev dummy0 down
David Ahern10566912018-02-13 08:37:34 -0800240 set +e
Ido Schimmel5adb7682018-01-07 12:45:17 +0200241
David Ahern10566912018-02-13 08:37:34 -0800242 echo " Both devices down"
David Ahern07f4e622018-02-13 08:37:33 -0800243 ip -netns testns route get fibmatch 203.0.113.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800244 log_test $? 2 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800245 ip -netns testns -6 route get fibmatch 2001:db8:3::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800246 log_test $? 2 "IPv6 fibmatch"
Ido Schimmel5adb7682018-01-07 12:45:17 +0200247
David Ahern07f4e622018-02-13 08:37:33 -0800248 ip -netns testns link del dev dummy1
David Ahernee395a52018-02-13 08:37:35 -0800249 cleanup
Ido Schimmel5adb7682018-01-07 12:45:17 +0200250}
251
252fib_down_test()
253{
Ido Schimmel5adb7682018-01-07 12:45:17 +0200254 fib_down_unicast_test
255 fib_down_multipath_test
256}
257
David Ahern10566912018-02-13 08:37:34 -0800258# Local routes should not be affected when carrier changes.
Ido Schimmel82e45b62018-01-07 12:45:18 +0200259fib_carrier_local_test()
260{
David Ahern10566912018-02-13 08:37:34 -0800261 echo
262 echo "Local carrier tests - single path"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200263
David Ahernee395a52018-02-13 08:37:35 -0800264 setup
265
David Ahern10566912018-02-13 08:37:34 -0800266 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800267 ip -netns testns link set dev dummy0 carrier on
David Ahern10566912018-02-13 08:37:34 -0800268 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200269
David Ahern10566912018-02-13 08:37:34 -0800270 echo " Start point"
David Ahern07f4e622018-02-13 08:37:33 -0800271 ip -netns testns route get fibmatch 198.51.100.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800272 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800273 ip -netns testns -6 route get fibmatch 2001:db8:1::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800274 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200275
David Ahern07f4e622018-02-13 08:37:33 -0800276 ip -netns testns route get fibmatch 198.51.100.1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200277 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800278 log_test $? 1 "IPv4 - no linkdown flag"
David Ahern07f4e622018-02-13 08:37:33 -0800279 ip -netns testns -6 route get fibmatch 2001:db8:1::1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200280 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800281 log_test $? 1 "IPv6 - no linkdown flag"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200282
David Ahern10566912018-02-13 08:37:34 -0800283 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800284 ip -netns testns link set dev dummy0 carrier off
David Ahern10566912018-02-13 08:37:34 -0800285 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200286
David Ahern10566912018-02-13 08:37:34 -0800287 echo " Carrier off on nexthop"
David Ahern07f4e622018-02-13 08:37:33 -0800288 ip -netns testns route get fibmatch 198.51.100.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800289 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800290 ip -netns testns -6 route get fibmatch 2001:db8:1::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800291 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200292
David Ahern07f4e622018-02-13 08:37:33 -0800293 ip -netns testns route get fibmatch 198.51.100.1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200294 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800295 log_test $? 1 "IPv4 - linkdown flag set"
David Ahern07f4e622018-02-13 08:37:33 -0800296 ip -netns testns -6 route get fibmatch 2001:db8:1::1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200297 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800298 log_test $? 1 "IPv6 - linkdown flag set"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200299
David Ahern10566912018-02-13 08:37:34 -0800300 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800301 ip -netns testns address add 192.0.2.1/24 dev dummy0
302 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy0
David Ahern10566912018-02-13 08:37:34 -0800303 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200304
David Ahern10566912018-02-13 08:37:34 -0800305 echo " Route to local address with carrier down"
David Ahern07f4e622018-02-13 08:37:33 -0800306 ip -netns testns route get fibmatch 192.0.2.1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800307 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800308 ip -netns testns -6 route get fibmatch 2001:db8:2::1 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800309 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200310
David Ahern07f4e622018-02-13 08:37:33 -0800311 ip -netns testns route get fibmatch 192.0.2.1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200312 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800313 log_test $? 1 "IPv4 linkdown flag set"
David Ahern07f4e622018-02-13 08:37:33 -0800314 ip -netns testns -6 route get fibmatch 2001:db8:2::1 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200315 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800316 log_test $? 1 "IPv6 linkdown flag set"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200317
David Ahernee395a52018-02-13 08:37:35 -0800318 cleanup
Ido Schimmel82e45b62018-01-07 12:45:18 +0200319}
320
321fib_carrier_unicast_test()
322{
323 ret=0
324
David Ahern10566912018-02-13 08:37:34 -0800325 echo
326 echo "Single path route carrier test"
327
David Ahernee395a52018-02-13 08:37:35 -0800328 setup
Ido Schimmel82e45b62018-01-07 12:45:18 +0200329
David Ahern10566912018-02-13 08:37:34 -0800330 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800331 ip -netns testns link set dev dummy0 carrier on
David Ahern10566912018-02-13 08:37:34 -0800332 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200333
David Ahern10566912018-02-13 08:37:34 -0800334 echo " Start point"
David Ahern07f4e622018-02-13 08:37:33 -0800335 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800336 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800337 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800338 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200339
David Ahern07f4e622018-02-13 08:37:33 -0800340 ip -netns testns route get fibmatch 198.51.100.2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200341 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800342 log_test $? 1 "IPv4 no linkdown flag"
David Ahern07f4e622018-02-13 08:37:33 -0800343 ip -netns testns -6 route get fibmatch 2001:db8:1::2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200344 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800345 log_test $? 1 "IPv6 no linkdown flag"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200346
David Ahern10566912018-02-13 08:37:34 -0800347 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800348 ip -netns testns link set dev dummy0 carrier off
David Ahern10566912018-02-13 08:37:34 -0800349 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200350
David Ahern10566912018-02-13 08:37:34 -0800351 echo " Carrier down"
David Ahern07f4e622018-02-13 08:37:33 -0800352 ip -netns testns route get fibmatch 198.51.100.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800353 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800354 ip -netns testns -6 route get fibmatch 2001:db8:1::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800355 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200356
David Ahern07f4e622018-02-13 08:37:33 -0800357 ip -netns testns route get fibmatch 198.51.100.2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200358 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800359 log_test $? 0 "IPv4 linkdown flag set"
David Ahern07f4e622018-02-13 08:37:33 -0800360 ip -netns testns -6 route get fibmatch 2001:db8:1::2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200361 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800362 log_test $? 0 "IPv6 linkdown flag set"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200363
David Ahern10566912018-02-13 08:37:34 -0800364 set -e
David Ahern07f4e622018-02-13 08:37:33 -0800365 ip -netns testns address add 192.0.2.1/24 dev dummy0
366 ip -netns testns -6 address add 2001:db8:2::1/64 dev dummy0
David Ahern10566912018-02-13 08:37:34 -0800367 set +e
Ido Schimmel82e45b62018-01-07 12:45:18 +0200368
David Ahern10566912018-02-13 08:37:34 -0800369 echo " Second address added with carrier down"
David Ahern07f4e622018-02-13 08:37:33 -0800370 ip -netns testns route get fibmatch 192.0.2.2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800371 log_test $? 0 "IPv4 fibmatch"
David Ahern07f4e622018-02-13 08:37:33 -0800372 ip -netns testns -6 route get fibmatch 2001:db8:2::2 &> /dev/null
David Ahern10566912018-02-13 08:37:34 -0800373 log_test $? 0 "IPv6 fibmatch"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200374
David Ahern07f4e622018-02-13 08:37:33 -0800375 ip -netns testns route get fibmatch 192.0.2.2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200376 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800377 log_test $? 0 "IPv4 linkdown flag set"
David Ahern07f4e622018-02-13 08:37:33 -0800378 ip -netns testns -6 route get fibmatch 2001:db8:2::2 | \
Ido Schimmel82e45b62018-01-07 12:45:18 +0200379 grep -q "linkdown"
David Ahern10566912018-02-13 08:37:34 -0800380 log_test $? 0 "IPv6 linkdown flag set"
Ido Schimmel82e45b62018-01-07 12:45:18 +0200381
David Ahernee395a52018-02-13 08:37:35 -0800382 cleanup
Ido Schimmel82e45b62018-01-07 12:45:18 +0200383}
384
385fib_carrier_test()
386{
Ido Schimmel82e45b62018-01-07 12:45:18 +0200387 fib_carrier_local_test
388 fib_carrier_unicast_test
389}
390
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200391fib_test()
392{
393 fib_unreg_test
Ido Schimmel5adb7682018-01-07 12:45:17 +0200394 fib_down_test
Ido Schimmel82e45b62018-01-07 12:45:18 +0200395 fib_carrier_test
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200396}
397
398if [ "$(id -u)" -ne 0 ];then
399 echo "SKIP: Need root privileges"
400 exit 0
401fi
402
403if [ ! -x "$(command -v ip)" ]; then
404 echo "SKIP: Could not run test without ip tool"
405 exit 0
406fi
407
408ip route help 2>&1 | grep -q fibmatch
409if [ $? -ne 0 ]; then
410 echo "SKIP: iproute2 too old, missing fibmatch"
411 exit 0
412fi
413
David Ahernee395a52018-02-13 08:37:35 -0800414# start clean
415cleanup &> /dev/null
416
Ido Schimmel607bd2e2018-01-07 12:45:16 +0200417fib_test
418
419exit $ret