2 # SPDX-License-Identifier: GPL-2.0
4 # Test devlink-trap L3 exceptions functionality over mlxsw.
5 # Check all exception traps to make sure they are triggered under the right
8 # +---------------------------------+
12 # | | 2001:db8:1::1/64 |
14 # | | default via 192.0.2.2 |
15 # | | default via 2001:db8:1::2 |
16 # +----|----------------------------+
18 # +----|----------------------------------------------------------------------+
22 # | 2001:db8:1::2/64 |
24 # | 2001:db8:2::2/64 |
28 # +----|----------------------------------------------------------------------+
30 # +----|----------------------------+
31 # | | default via 198.51.100.2 |
32 # | | default via 2001:db8:2::2 |
34 # | | 2001:db8:2::1/64 |
35 # | | 198.51.100.1/24 |
38 # +---------------------------------+
40 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
43 mtu_value_is_too_small_test
44 ttl_value_is_too_small_test
45 mc_reverse_path_forwarding_test
53 source $lib_dir/lib.sh
54 source $lib_dir/tc_common.sh
55 source $lib_dir/devlink_lib.sh
58 require_command
$MC_CLI
63 simple_if_init
$h1 192.0.2.1/24 2001:db8
:1::1/64
65 ip
-4 route add default vrf v
$h1 nexthop via
192.0.2.2
66 ip
-6 route add default vrf v
$h1 nexthop via
2001:db8
:1::2
68 tc qdisc add dev
$h1 clsact
73 tc qdisc del dev
$h1 clsact
75 ip
-6 route del default vrf v
$h1 nexthop via
2001:db8
:1::2
76 ip
-4 route del default vrf v
$h1 nexthop via
192.0.2.2
78 simple_if_fini
$h1 192.0.2.1/24 2001:db8
:1::1/64
83 simple_if_init
$h2 198.51.100.1/24 2001:db8
:2::1/64
85 ip
-4 route add default vrf v
$h2 nexthop via
198.51.100.2
86 ip
-6 route add default vrf v
$h2 nexthop via
2001:db8
:2::2
91 ip
-6 route del default vrf v
$h2 nexthop via
2001:db8
:2::2
92 ip
-4 route del default vrf v
$h2 nexthop via
198.51.100.2
94 simple_if_fini
$h2 198.51.100.1/24 2001:db8
:2::1/64
99 ip link
set dev
$rp1 up
100 ip link
set dev
$rp2 up
102 tc qdisc add dev
$rp2 clsact
104 __addr_add_del
$rp1 add
192.0.2.2/24 2001:db8
:1::2/64
105 __addr_add_del
$rp2 add
198.51.100.2/24 2001:db8
:2::2/64
110 __addr_add_del
$rp2 del
198.51.100.2/24 2001:db8
:2::2/64
111 __addr_add_del
$rp1 del
192.0.2.2/24 2001:db8
:1::2/64
113 tc qdisc del dev
$rp2 clsact
124 rp1mac
=$
(mac_get
$rp1)
154 ping_do
$h1 198.51.100.1
155 check_err $?
"Packets that should not be trapped were trapped"
160 local trap_name
=$1; shift
161 local expected_action
=$1; shift
163 action
=$
(devlink_trap_action_get
$trap_name)
164 if [ "$action" != $expected_action ]; then
165 check_err
1 "Trap $trap_name has wrong action: $action"
169 mtu_value_is_too_small_test
()
171 local trap_name
="mtu_value_is_too_small"
172 local expected_action
="trap"
177 ping_check
$trap_name
178 trap_action_check
$trap_name $expected_action
180 # type - Destination Unreachable
181 # code - Fragmentation Needed and Don't Fragment was Set
182 tc filter add dev
$h1 ingress protocol ip pref
1 handle
101 \
183 flower skip_hw ip_proto icmp
type 3 code
4 action pass
187 # Generate IP packets bigger than router's MTU with don't fragment
189 $MZ $h1 -t udp
"sp=54321,dp=12345,df" -p 1400 -c 0 -d 1msec
-b $rp1mac \
193 devlink_trap_exception_test
$trap_name
195 tc_check_packets_hitting
"dev $h1 ingress" 101
196 check_err $?
"Packets were not received to h1"
198 log_test
"MTU value is too small"
202 kill $mz_pid && wait $mz_pid &> /dev
/null
203 tc filter del dev
$h1 ingress protocol ip pref
1 handle
101 flower
206 __ttl_value_is_too_small_test
()
208 local ttl_val
=$1; shift
209 local trap_name
="ttl_value_is_too_small"
210 local expected_action
="trap"
215 ping_check
$trap_name
216 trap_action_check
$trap_name $expected_action
218 # type - Time Exceeded
219 # code - Time to Live exceeded in Transit
220 tc filter add dev
$h1 ingress protocol ip pref
1 handle
101 \
221 flower skip_hw ip_proto icmp
type 11 code
0 action pass
223 # Generate IP packets with small TTL
224 $MZ $h1 -t udp
"ttl=$ttl_val,sp=54321,dp=12345" -c 0 -d 1msec \
225 -b $rp1mac -B 198.51.100.1 -q &
228 devlink_trap_exception_test
$trap_name
230 tc_check_packets_hitting
"dev $h1 ingress" 101
231 check_err $?
"Packets were not received to h1"
233 log_test
"TTL value is too small: TTL=$ttl_val"
235 kill $mz_pid && wait $mz_pid &> /dev
/null
236 tc filter del dev
$h1 ingress protocol ip pref
1 handle
101 flower
239 ttl_value_is_too_small_test
()
241 __ttl_value_is_too_small_test
0
242 __ttl_value_is_too_small_test
1
247 SMCROUTEDIR
="$(mktemp -d)"
248 for ((i
= 1; i
<= $NUM_NETIFS; ++i
)); do
249 echo "phyint ${NETIFS[p$i]} enable" >> \
250 $SMCROUTEDIR/$table_name.conf
253 $MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
254 -P $SMCROUTEDIR/$table_name.pid
263 __mc_reverse_path_forwarding_test
()
266 local src_ip
=$1; shift
267 local dst_ip
=$1; shift
268 local dst_mac
=$1; shift
269 local proto
=$1; shift
270 local flags
=${1:-""}; shift
271 local trap_name
="mc_reverse_path_forwarding"
272 local expected_action
="trap"
277 ping_check
$trap_name
278 trap_action_check
$trap_name $expected_action
280 tc filter add dev
$rp2 egress protocol
$proto pref
1 handle
101 \
281 flower dst_ip
$dst_ip ip_proto udp action drop
283 $MC_CLI -I $table_name add
$rp1 $src_ip $dst_ip $rp2
285 # Generate packets to multicast address.
286 $MZ $h2 $flags -t udp
"sp=54321,dp=12345" -c 0 -p 128 \
287 -a 00:11:22:33:44:55 -b $dst_mac \
288 -A $src_ip -B $dst_ip -q &
292 devlink_trap_exception_test
$trap_name
294 tc_check_packets
"dev $rp2 egress" 101 0
295 check_err $?
"Packets were not dropped"
297 log_test
"Multicast reverse path forwarding: $desc"
299 kill $mz_pid && wait $mz_pid &> /dev
/null
300 tc filter del dev
$rp2 egress protocol
$proto pref
1 handle
101 flower
303 mc_reverse_path_forwarding_test
()
305 __mc_reverse_path_forwarding_test
"IPv4" "192.0.2.1" "225.1.2.3" \
306 "01:00:5e:01:02:03" "ip"
307 __mc_reverse_path_forwarding_test
"IPv6" "2001:db8:1::1" "ff0e::3" \
308 "33:33:00:00:00:03" "ipv6" "-6"
311 __reject_route_test
()
314 local dst_ip
=$1; shift
315 local proto
=$1; shift
316 local ip_proto
=$1; shift
319 local unreachable
=$1; shift
320 local flags
=${1:-""}; shift
321 local trap_name
="reject_route"
322 local expected_action
="trap"
327 ping_check
$trap_name
328 trap_action_check
$trap_name $expected_action
330 tc filter add dev
$h1 ingress protocol
$proto pref
1 handle
101 flower \
331 skip_hw ip_proto
$ip_proto type $type code
$code action pass
333 ip route add unreachable
$unreachable
335 # Generate pacekts to h2. The destination IP is unreachable.
336 $MZ $flags $h1 -t udp
"sp=54321,dp=12345" -c 0 -d 1msec
-b $rp1mac \
340 devlink_trap_exception_test
$trap_name
342 tc_check_packets_hitting
"dev $h1 ingress" 101
343 check_err $?
"ICMP packet was not received to h1"
345 log_test
"Reject route: $desc"
347 kill $mz_pid && wait $mz_pid &> /dev
/null
348 ip route del unreachable
$unreachable
349 tc filter del dev
$h1 ingress protocol
$proto pref
1 handle
101 flower
354 # type - Destination Unreachable
355 # code - Host Unreachable
356 __reject_route_test
"IPv4" 198.51.100.1 "ip" "icmp" 3 1 \
358 # type - Destination Unreachable
360 __reject_route_test
"IPv6" 2001:db8
:2::1 "ipv6" "icmpv6" 1 0 \
361 "2001:db8:2::0/66" "-6"
368 local trap_name
="unresolved_neigh"
369 local expected_action
="trap"
374 ping_check
$trap_name
375 trap_action_check
$trap_name $expected_action
377 ip neigh flush dev
$rp2
379 t0_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
381 # Generate packets to h2 (will incur a unresolved neighbor).
382 # The ping should pass and devlink counters should be increased.
384 check_err $?
"ping failed: $desc"
386 t1_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
388 if [[ $t0_packets -eq $t1_packets ]]; then
389 check_err
1 "Trap counter did not increase"
392 log_test
"Unresolved neigh: host miss: $desc"
395 __invalid_nexthop_test
()
399 local extra_add
=$1; shift
400 local subnet
=$1; shift
401 local via_add
=$1; shift
402 local trap_name
="unresolved_neigh"
403 local expected_action
="trap"
408 ping_check
$trap_name
409 trap_action_check
$trap_name $expected_action
411 ip address add
$extra_add/$subnet dev
$h2
413 # Check that correct route does not trigger unresolved_neigh
414 ip
$flags route add
$dip via
$extra_add dev
$rp2
416 # Generate packets in order to discover all neighbours.
417 # Without it, counters of unresolved_neigh will be increased
418 # during neighbours discovery and the check below will fail
422 t0_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
424 t1_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
426 if [[ $t0_packets -ne $t1_packets ]]; then
427 check_err
1 "Trap counter increased when it should not"
430 ip
$flags route del
$dip via
$extra_add dev
$rp2
432 # Check that route to nexthop that does not exist trigger
434 ip
$flags route add
$dip via
$via_add dev
$h2
436 t0_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
438 t1_packets
=$
(devlink_trap_rx_packets_get
$trap_name)
440 if [[ $t0_packets -eq $t1_packets ]]; then
441 check_err
1 "Trap counter did not increase"
444 ip
$flags route del
$dip via
$via_add dev
$h2
445 ip address del
$extra_add/$subnet dev
$h2
446 log_test
"Unresolved neigh: nexthop does not exist: $desc"
449 unresolved_neigh_test
()
451 __host_miss_test
"IPv4" 198.51.100.1
452 __host_miss_test
"IPv6" 2001:db8
:2::1
453 __invalid_nexthop_test
"IPv4" 198.51.100.1 198.51.100.3 24 198.51.100.4
454 __invalid_nexthop_test
"IPv6" 2001:db8
:2::1 2001:db8
:2::3 64 \
458 vrf_without_routes_create
()
460 # VRF creating makes the links to be down and then up again.
461 # By default, IPv6 address is not saved after link becomes down.
462 # Save IPv6 address using sysctl configuration.
463 sysctl_set net.ipv6.conf.
$rp1.keep_addr_on_down
1
464 sysctl_set net.ipv6.conf.
$rp2.keep_addr_on_down
1
466 ip link add dev vrf1
type vrf table
101
467 ip link
set dev
$rp1 master vrf1
468 ip link
set dev
$rp2 master vrf1
469 ip link
set dev vrf1 up
471 # Wait for rp1 and rp2 to be up
475 vrf_without_routes_destroy
()
477 ip link
set dev
$rp1 nomaster
478 ip link
set dev
$rp2 nomaster
481 sysctl_restore net.ipv6.conf.
$rp2.keep_addr_on_down
482 sysctl_restore net.ipv6.conf.
$rp1.keep_addr_on_down
484 # Wait for interfaces to be up
490 local trap_name
="ipv4_lpm_miss"
491 local expected_action
="trap"
496 ping_check
$trap_name
497 trap_action_check
$trap_name $expected_action
499 # Create a VRF without a default route
500 vrf_without_routes_create
502 # Generate packets through a VRF without a matching route.
503 $MZ $h1 -t udp
"sp=54321,dp=12345" -c 0 -d 1msec
-b $rp1mac \
507 devlink_trap_exception_test
$trap_name
509 log_test
"LPM miss: IPv4"
511 kill $mz_pid && wait $mz_pid &> /dev
/null
512 vrf_without_routes_destroy
517 local trap_name
="ipv6_lpm_miss"
518 local expected_action
="trap"
523 ping_check
$trap_name
524 trap_action_check
$trap_name $expected_action
526 # Create a VRF without a default route
527 vrf_without_routes_create
529 # Generate packets through a VRF without a matching route.
530 $MZ -6 $h1 -t udp
"sp=54321,dp=12345" -c 0 -d 1msec
-b $rp1mac \
534 devlink_trap_exception_test
$trap_name
536 log_test
"LPM miss: IPv6"
538 kill $mz_pid && wait $mz_pid &> /dev
/null
539 vrf_without_routes_destroy