2 # SPDX-License-Identifier: GPL-2.0
17 ip link
set dev
$h1 master vrf-h1
19 ip link
set dev vrf-h1 up
20 ip link
set dev
$h1 up
22 ip address add
192.0.2.2/24 dev
$h1
23 ip address add
2001:db8
:1::2/64 dev
$h1
25 ip route add
198.51.100.0/24 vrf vrf-h1 nexthop via
192.0.2.1
26 ip route add
2001:db8
:2::/64 vrf vrf-h1 nexthop via
2001:db8
:1::1
31 ip route del
2001:db8
:2::/64 vrf vrf-h1
32 ip route del
198.51.100.0/24 vrf vrf-h1
34 ip address del
2001:db8
:1::2/64 dev
$h1
35 ip address del
192.0.2.2/24 dev
$h1
37 ip link
set dev
$h1 down
44 ip link
set dev
$h2 master vrf-h2
46 ip link
set dev vrf-h2 up
47 ip link
set dev
$h2 up
49 ip address add
198.51.100.2/24 dev
$h2
50 ip address add
2001:db8
:2::2/64 dev
$h2
52 ip route add
192.0.2.0/24 vrf vrf-h2 nexthop via
198.51.100.1
53 ip route add
2001:db8
:1::/64 vrf vrf-h2 nexthop via
2001:db8
:2::1
58 ip route del
2001:db8
:1::/64 vrf vrf-h2
59 ip route del
192.0.2.0/24 vrf vrf-h2
61 ip address del
2001:db8
:2::2/64 dev
$h2
62 ip address del
198.51.100.2/24 dev
$h2
64 ip link
set dev
$h2 down
71 ip link
set dev
$rp11 master vrf-r1
72 ip link
set dev
$rp12 master vrf-r1
73 ip link
set dev
$rp13 master vrf-r1
75 ip link
set dev vrf-r1 up
76 ip link
set dev
$rp11 up
77 ip link
set dev
$rp12 up
78 ip link
set dev
$rp13 up
80 ip address add
192.0.2.1/24 dev
$rp11
81 ip address add
2001:db8
:1::1/64 dev
$rp11
83 ip address add
169.254.2.12/24 dev
$rp12
84 ip address add fe80
:2::12/64 dev
$rp12
86 ip address add
169.254.3.13/24 dev
$rp13
87 ip address add fe80
:3::13/64 dev
$rp13
92 ip route del
2001:db8
:2::/64 vrf vrf-r1
93 ip route del
198.51.100.0/24 vrf vrf-r1
95 ip address del fe80
:3::13/64 dev
$rp13
96 ip address del
169.254.3.13/24 dev
$rp13
98 ip address del fe80
:2::12/64 dev
$rp12
99 ip address del
169.254.2.12/24 dev
$rp12
101 ip address del
2001:db8
:1::1/64 dev
$rp11
102 ip address del
192.0.2.1/24 dev
$rp11
104 ip nexthop del id
103
105 ip nexthop del id
101
106 ip nexthop del id
102
107 ip nexthop del id
106
108 ip nexthop del id
104
109 ip nexthop del id
105
111 ip link
set dev
$rp13 down
112 ip link
set dev
$rp12 down
113 ip link
set dev
$rp11 down
121 ip link
set dev
$rp21 master vrf-r2
122 ip link
set dev
$rp22 master vrf-r2
123 ip link
set dev
$rp23 master vrf-r2
125 ip link
set dev vrf-r2 up
126 ip link
set dev
$rp21 up
127 ip link
set dev
$rp22 up
128 ip link
set dev
$rp23 up
130 ip address add
198.51.100.1/24 dev
$rp21
131 ip address add
2001:db8
:2::1/64 dev
$rp21
133 ip address add
169.254.2.22/24 dev
$rp22
134 ip address add fe80
:2::22/64 dev
$rp22
136 ip address add
169.254.3.23/24 dev
$rp23
137 ip address add fe80
:3::23/64 dev
$rp23
142 ip route del
2001:db8
:1::/64 vrf vrf-r2
143 ip route del
192.0.2.0/24 vrf vrf-r2
145 ip address del fe80
:3::23/64 dev
$rp23
146 ip address del
169.254.3.23/24 dev
$rp23
148 ip address del fe80
:2::22/64 dev
$rp22
149 ip address del
169.254.2.22/24 dev
$rp22
151 ip address del
2001:db8
:2::1/64 dev
$rp21
152 ip address del
198.51.100.1/24 dev
$rp21
154 ip nexthop del id
201
155 ip nexthop del id
202
156 ip nexthop del id
204
157 ip nexthop del id
205
159 ip link
set dev
$rp23 down
160 ip link
set dev
$rp22 down
161 ip link
set dev
$rp21 down
168 ip nexthop add id
101 via
169.254.2.22 dev
$rp12
169 ip nexthop add id
102 via
169.254.3.23 dev
$rp13
170 ip nexthop add id
103 group
101/102
171 ip route add
198.51.100.0/24 vrf vrf-r1 nhid
103
173 ip nexthop add id
104 via fe80
:2::22 dev
$rp12
174 ip nexthop add id
105 via fe80
:3::23 dev
$rp13
175 ip nexthop add id
106 group
104/105
176 ip route add
2001:db8
:2::/64 vrf vrf-r1 nhid
106
178 ip nexthop add id
201 via
169.254.2.12 dev
$rp22
179 ip nexthop add id
202 via
169.254.3.13 dev
$rp23
180 ip nexthop add id
203 group
201/202
181 ip route add
192.0.2.0/24 vrf vrf-r2 nhid
203
183 ip nexthop add id
204 via fe80
:2::12 dev
$rp22
184 ip nexthop add id
205 via fe80
:3::13 dev
$rp23
185 ip nexthop add id
206 group
204/205
186 ip route add
2001:db8
:1::/64 vrf vrf-r2 nhid
206
194 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
195 local packets_rp12 packets_rp13
197 # Transmit multiple flows from h1 to h2 and make sure they are
198 # distributed between both multipath links (rp12 and rp13)
199 # according to the configured weights.
200 sysctl_set net.ipv4.fib_multipath_hash_policy
1
201 ip nexthop replace id
103 group
101,$weight_rp12/102,$weight_rp13
203 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
204 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
206 ip vrf
exec vrf-h1
$MZ -q -p 64 -A 192.0.2.2 -B 198.51.100.2 \
207 -d 1msec
-t udp
"sp=1024,dp=0-32768"
209 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
210 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
212 let "packets_rp12 = $t1_rp12 - $t0_rp12"
213 let "packets_rp13 = $t1_rp13 - $t0_rp13"
214 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
217 ip nexthop replace id
103 group
101/102
218 sysctl_restore net.ipv4.fib_multipath_hash_policy
226 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
227 local packets_rp12 packets_rp13
229 # Transmit multiple flows from h1 to h2 and make sure they are
230 # distributed between both multipath links (rp12 and rp13)
231 # according to the configured weights.
232 sysctl_set net.ipv6.fib_multipath_hash_policy
1
234 ip nexthop replace id
106 group
104,$weight_rp12/105,$weight_rp13
236 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
237 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
239 $MZ $h1 -6 -q -p 64 -A 2001:db8
:1::2 -B 2001:db8
:2::2 \
240 -d 1msec
-t udp
"sp=1024,dp=0-32768"
242 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
243 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
245 let "packets_rp12 = $t1_rp12 - $t0_rp12"
246 let "packets_rp13 = $t1_rp13 - $t0_rp13"
247 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
249 ip nexthop replace id
106 group
104/105
251 sysctl_restore net.ipv6.fib_multipath_hash_policy
259 local t0_rp12 t0_rp13 t1_rp12 t1_rp13
260 local packets_rp12 packets_rp13
262 ip nexthop replace id
106 group
104,$weight_rp12/105,$weight_rp13
264 t0_rp12
=$
(link_stats_tx_packets_get
$rp12)
265 t0_rp13
=$
(link_stats_tx_packets_get
$rp13)
267 # Generate 16384 echo requests, each with a random flow label.
268 for _
in $
(seq 1 16384); do
269 ip vrf
exec vrf-h1
$PING6 2001:db8
:2::2 -F 0 -c 1 -q >/dev
/null
2>&1
272 t1_rp12
=$
(link_stats_tx_packets_get
$rp12)
273 t1_rp13
=$
(link_stats_tx_packets_get
$rp13)
275 let "packets_rp12 = $t1_rp12 - $t0_rp12"
276 let "packets_rp13 = $t1_rp13 - $t0_rp13"
277 multipath_eval
"$desc" $weight_rp12 $weight_rp13 $packets_rp12 $packets_rp13
279 ip nexthop replace id
106 group
104/105
284 log_info
"Running IPv4 multipath tests"
285 multipath4_test
"ECMP" 1 1
286 multipath4_test
"Weighted MP 2:1" 2 1
287 multipath4_test
"Weighted MP 11:45" 11 45
289 log_info
"Running IPv4 multipath tests with IPv6 link-local nexthops"
290 ip nexthop replace id
101 via fe80
:2::22 dev
$rp12
291 ip nexthop replace id
102 via fe80
:3::23 dev
$rp13
293 multipath4_test
"ECMP" 1 1
294 multipath4_test
"Weighted MP 2:1" 2 1
295 multipath4_test
"Weighted MP 11:45" 11 45
297 ip nexthop replace id
102 via
169.254.3.23 dev
$rp13
298 ip nexthop replace id
101 via
169.254.2.22 dev
$rp12
300 log_info
"Running IPv6 multipath tests"
301 multipath6_test
"ECMP" 1 1
302 multipath6_test
"Weighted MP 2:1" 2 1
303 multipath6_test
"Weighted MP 11:45" 11 45
305 log_info
"Running IPv6 L4 hash multipath tests"
306 multipath6_l4_test
"ECMP" 1 1
307 multipath6_l4_test
"Weighted MP 2:1" 2 1
308 multipath6_l4_test
"Weighted MP 11:45" 11 45
311 ping_ipv4_blackhole
()
315 ip nexthop add id
1001 blackhole
316 ip nexthop add id
1002 group
1001
318 ip route replace
198.51.100.0/24 vrf vrf-r1 nhid
1001
319 ping_do
$h1 198.51.100.2
320 check_fail $?
"ping did not fail when using a blackhole nexthop"
322 ip route replace
198.51.100.0/24 vrf vrf-r1 nhid
1002
323 ping_do
$h1 198.51.100.2
324 check_fail $?
"ping did not fail when using a blackhole nexthop group"
326 ip route replace
198.51.100.0/24 vrf vrf-r1 nhid
103
327 ping_do
$h1 198.51.100.2
328 check_err $?
"ping failed with a valid nexthop"
330 log_test
"IPv4 blackhole ping"
332 ip nexthop del id
1002
333 ip nexthop del id
1001
336 ping_ipv6_blackhole
()
340 ip
-6 nexthop add id
1001 blackhole
341 ip nexthop add id
1002 group
1001
343 ip route replace
2001:db8
:2::/64 vrf vrf-r1 nhid
1001
344 ping6_do
$h1 2001:db8
:2::2
345 check_fail $?
"ping did not fail when using a blackhole nexthop"
347 ip route replace
2001:db8
:2::/64 vrf vrf-r1 nhid
1002
348 ping6_do
$h1 2001:db8
:2::2
349 check_fail $?
"ping did not fail when using a blackhole nexthop group"
351 ip route replace
2001:db8
:2::/64 vrf vrf-r1 nhid
106
352 ping6_do
$h1 2001:db8
:2::2
353 check_err $?
"ping failed with a valid nexthop"
355 log_test
"IPv6 blackhole ping"
357 ip nexthop del id
1002
358 ip
-6 nexthop del id
1001
403 ping_test
$h1 198.51.100.2
408 ping6_test
$h1 2001:db8
:2::2
411 ip nexthop
ls >/dev
/null
2>&1
412 if [ $?
-ne 0 ]; then
413 echo "Nexthop objects not supported; skipping tests"