1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Test various interface configuration scenarios. Observe that configurations 5# deemed valid by mlxsw succeed, invalid configurations fail and that no traces 6# are produced. To prevent the test from passing in case traces are produced, 7# the user can set the 'kernel.panic_on_warn' and 'kernel.panic_on_oops' 8# sysctls in its environment. 9 10lib_dir=$(dirname $0)/../../../net/forwarding 11 12ALL_TESTS=" 13 rif_set_addr_test 14 rif_vrf_set_addr_test 15 rif_inherit_bridge_addr_test 16 rif_non_inherit_bridge_addr_test 17 vlan_interface_deletion_test 18 bridge_deletion_test 19 bridge_vlan_flags_test 20 vlan_1_test 21 lag_bridge_upper_test 22 duplicate_vlans_test 23 vlan_rif_refcount_test 24 subport_rif_refcount_test 25 subport_rif_lag_join_test 26 vlan_dev_deletion_test 27 lag_unlink_slaves_test 28 lag_dev_deletion_test 29 vlan_interface_uppers_test 30 bridge_extern_learn_test 31 neigh_offload_test 32 nexthop_offload_test 33 nexthop_obj_invalid_test 34 nexthop_obj_offload_test 35 nexthop_obj_group_offload_test 36 nexthop_obj_bucket_offload_test 37 nexthop_obj_blackhole_offload_test 38 nexthop_obj_route_offload_test 39 devlink_reload_test 40" 41NUM_NETIFS=2 42: ${TIMEOUT:=20000} # ms 43source $lib_dir/lib.sh 44source $lib_dir/devlink_lib.sh 45 46setup_prepare() 47{ 48 swp1=${NETIFS[p1]} 49 swp2=${NETIFS[p2]} 50 51 ip link set dev $swp1 up 52 ip link set dev $swp2 up 53} 54 55cleanup() 56{ 57 pre_cleanup 58 59 ip link set dev $swp2 down 60 ip link set dev $swp1 down 61} 62 63rif_set_addr_test() 64{ 65 local swp1_mac=$(mac_get $swp1) 66 local swp2_mac=$(mac_get $swp2) 67 68 RET=0 69 70 # $swp1 and $swp2 likely got their IPv6 local addresses already, but 71 # here we need to test the transition to RIF. 72 ip addr flush dev $swp1 73 ip addr flush dev $swp2 74 sleep .1 75 76 ip addr add dev $swp1 192.0.2.1/28 77 check_err $? 78 79 ip link set dev $swp1 addr 00:11:22:33:44:55 80 check_err $? 81 82 # IP address enablement should be rejected if the MAC address prefix 83 # doesn't match other RIFs. 84 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null 85 check_fail $? "IP address addition passed for a device with a wrong MAC" 86 ip addr add dev $swp2 192.0.2.2/28 2>&1 >/dev/null \ 87 | grep -q mlxsw_spectrum 88 check_err $? "no extack for IP address addition" 89 90 ip link set dev $swp2 addr 00:11:22:33:44:66 91 check_err $? 92 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null 93 check_err $? 94 95 # Change of MAC address of a RIF should be forbidden if the new MAC 96 # doesn't share the prefix with other MAC addresses. 97 ip link set dev $swp2 addr 00:11:22:33:00:66 &>/dev/null 98 check_fail $? "change of MAC address passed for a wrong MAC" 99 ip link set dev $swp2 addr 00:11:22:33:00:66 2>&1 >/dev/null \ 100 | grep -q mlxsw_spectrum 101 check_err $? "no extack for MAC address change" 102 103 log_test "RIF - bad MAC change" 104 105 ip addr del dev $swp2 192.0.2.2/28 106 ip addr del dev $swp1 192.0.2.1/28 107 108 ip link set dev $swp2 addr $swp2_mac 109 ip link set dev $swp1 addr $swp1_mac 110} 111 112rif_vrf_set_addr_test() 113{ 114 # Test that it is possible to set an IP address on a VRF upper despite 115 # its random MAC address. 116 RET=0 117 118 ip link add name vrf-test type vrf table 10 119 ip link set dev $swp1 master vrf-test 120 121 ip -4 address add 192.0.2.1/24 dev vrf-test 122 check_err $? "failed to set IPv4 address on VRF" 123 ip -6 address add 2001:db8:1::1/64 dev vrf-test 124 check_err $? "failed to set IPv6 address on VRF" 125 126 log_test "RIF - setting IP address on VRF" 127 128 ip link del dev vrf-test 129} 130 131rif_inherit_bridge_addr_test() 132{ 133 RET=0 134 135 # Create first RIF 136 ip addr add dev $swp1 192.0.2.1/28 137 check_err $? 138 139 # Create a FID RIF 140 ip link add name br1 up type bridge vlan_filtering 0 141 ip link set dev $swp2 master br1 142 ip addr add dev br1 192.0.2.17/28 143 check_err $? 144 145 # Prepare a device with a low MAC address 146 ip link add name d up type dummy 147 ip link set dev d addr 00:11:22:33:44:55 148 149 # Attach the device to br1. That prompts bridge address change, which 150 # should be vetoed, thus preventing the attachment. 151 ip link set dev d master br1 &>/dev/null 152 check_fail $? "Device with low MAC was permitted to attach a bridge with RIF" 153 ip link set dev d master br1 2>&1 >/dev/null \ 154 | grep -q mlxsw_spectrum 155 check_err $? "no extack for bridge attach rejection" 156 157 ip link set dev $swp2 addr 00:11:22:33:44:55 &>/dev/null 158 check_fail $? "Changing swp2's MAC address permitted" 159 ip link set dev $swp2 addr 00:11:22:33:44:55 2>&1 >/dev/null \ 160 | grep -q mlxsw_spectrum 161 check_err $? "no extack for bridge port MAC address change rejection" 162 163 log_test "RIF - attach port with bad MAC to bridge" 164 165 ip link del dev d 166 ip link del dev br1 167 ip addr del dev $swp1 192.0.2.1/28 168} 169 170rif_non_inherit_bridge_addr_test() 171{ 172 local swp2_mac=$(mac_get $swp2) 173 174 RET=0 175 176 # Create first RIF 177 ip addr add dev $swp1 192.0.2.1/28 178 check_err $? 179 180 # Create a FID RIF 181 ip link add name br1 up type bridge vlan_filtering 0 182 ip link set dev br1 addr $swp2_mac 183 ip link set dev $swp2 master br1 184 ip addr add dev br1 192.0.2.17/28 185 check_err $? 186 187 # Prepare a device with a low MAC address 188 ip link add name d up type dummy 189 ip link set dev d addr 00:11:22:33:44:55 190 191 # Attach the device to br1. Since the bridge address was set, it should 192 # work. 193 ip link set dev d master br1 &>/dev/null 194 check_err $? "Could not attach a device with low MAC to a bridge with RIF" 195 196 # Port MAC address change should be allowed for a bridge with set MAC. 197 ip link set dev $swp2 addr 00:11:22:33:44:55 198 check_err $? "Changing swp2's MAC address not permitted" 199 200 log_test "RIF - attach port with bad MAC to bridge with set MAC" 201 202 ip link set dev $swp2 addr $swp2_mac 203 ip link del dev d 204 ip link del dev br1 205 ip addr del dev $swp1 192.0.2.1/28 206} 207 208vlan_interface_deletion_test() 209{ 210 # Test that when a VLAN interface is deleted, its associated router 211 # interface (RIF) is correctly deleted and not leaked. See commit 212 # c360867ec46a ("mlxsw: spectrum: Delete RIF when VLAN device is 213 # removed") for more details 214 RET=0 215 216 ip link add name br0 type bridge vlan_filtering 1 217 ip link set dev $swp1 master br0 218 219 ip link add link br0 name br0.10 type vlan id 10 220 ip -6 address add 2001:db8:1::1/64 dev br0.10 221 ip link del dev br0.10 222 223 # If we leaked the previous RIF, then this should produce a trace 224 ip link add link br0 name br0.20 type vlan id 20 225 ip -6 address add 2001:db8:1::1/64 dev br0.20 226 ip link del dev br0.20 227 228 log_test "vlan interface deletion" 229 230 ip link del dev br0 231} 232 233bridge_deletion_test() 234{ 235 # Test that when a bridge with VLAN interfaces is deleted, we correctly 236 # delete the associated RIFs. See commit 602b74eda813 ("mlxsw: 237 # spectrum_switchdev: Do not leak RIFs when removing bridge") for more 238 # details 239 RET=0 240 241 ip link add name br0 type bridge vlan_filtering 1 242 ip link set dev $swp1 master br0 243 ip -6 address add 2001:db8::1/64 dev br0 244 245 ip link add link br0 name br0.10 type vlan id 10 246 ip -6 address add 2001:db8:1::1/64 dev br0.10 247 248 ip link add link br0 name br0.20 type vlan id 20 249 ip -6 address add 2001:db8:2::1/64 dev br0.20 250 251 ip link del dev br0 252 253 # If we leaked previous RIFs, then this should produce a trace 254 ip -6 address add 2001:db8:1::1/64 dev $swp1 255 ip -6 address del 2001:db8:1::1/64 dev $swp1 256 257 log_test "bridge deletion" 258} 259 260bridge_vlan_flags_test() 261{ 262 # Test that when bridge VLAN flags are toggled, we do not take 263 # unnecessary references on related structs. See commit 9e25826ffc94 264 # ("mlxsw: spectrum_switchdev: Fix port_vlan refcounting") for more 265 # details 266 RET=0 267 268 ip link add name br0 type bridge vlan_filtering 1 269 ip link set dev $swp1 master br0 270 271 bridge vlan add vid 10 dev $swp1 pvid untagged 272 bridge vlan add vid 10 dev $swp1 untagged 273 bridge vlan add vid 10 dev $swp1 pvid 274 bridge vlan add vid 10 dev $swp1 275 ip link del dev br0 276 277 # If we did not handle references correctly, then this should produce a 278 # trace 279 devlink dev reload "$DEVLINK_DEV" 280 281 # Allow netdevices to be re-created following the reload 282 sleep 20 283 284 log_test "bridge vlan flags" 285} 286 287vlan_1_test() 288{ 289 # Test that VLAN 1 can be configured over mlxsw ports. In the past it 290 # was used internally for untagged traffic. See commit 47bf9df2e820 291 # ("mlxsw: spectrum: Forbid creation of VLAN 1 over port/LAG") for more 292 # details 293 RET=0 294 295 ip link add link $swp1 name $swp1.1 type vlan id 1 296 check_err $? "did not manage to create vlan 1 when should" 297 298 log_test "vlan 1" 299 300 ip link del dev $swp1.1 301} 302 303lag_bridge_upper_test() 304{ 305 # Test that ports cannot be enslaved to LAG devices that have uppers 306 # and that failure is handled gracefully. See commit b3529af6bb0d 307 # ("spectrum: Reference count VLAN entries") for more details 308 RET=0 309 310 ip link add name bond1 type bond mode 802.3ad 311 312 ip link add name br0 type bridge vlan_filtering 1 313 ip link set dev bond1 master br0 314 315 ip link set dev $swp1 down 316 ip link set dev $swp1 master bond1 &> /dev/null 317 check_fail $? "managed to enslave port to lag when should not" 318 319 # This might generate a trace, if we did not handle the failure 320 # correctly 321 ip -6 address add 2001:db8:1::1/64 dev $swp1 322 ip -6 address del 2001:db8:1::1/64 dev $swp1 323 324 log_test "lag with bridge upper" 325 326 ip link del dev br0 327 ip link del dev bond1 328} 329 330duplicate_vlans_test() 331{ 332 # Test that on a given port a VLAN is only used once. Either as VLAN 333 # in a VLAN-aware bridge or as a VLAN device 334 RET=0 335 336 ip link add name br0 type bridge vlan_filtering 1 337 ip link set dev $swp1 master br0 338 bridge vlan add vid 10 dev $swp1 339 340 ip link add link $swp1 name $swp1.10 type vlan id 10 &> /dev/null 341 check_fail $? "managed to create vlan device when should not" 342 343 bridge vlan del vid 10 dev $swp1 344 ip link add link $swp1 name $swp1.10 type vlan id 10 345 check_err $? "did not manage to create vlan device when should" 346 bridge vlan add vid 10 dev $swp1 &> /dev/null 347 check_fail $? "managed to add bridge vlan when should not" 348 349 log_test "duplicate vlans" 350 351 ip link del dev $swp1.10 352 ip link del dev br0 353} 354 355vlan_rif_refcount_test() 356{ 357 # Test that RIFs representing VLAN interfaces are not affected from 358 # ports member in the VLAN. We use the offload indication on routes 359 # configured on the RIF to understand if it was created / destroyed 360 RET=0 361 362 ip link add name br0 type bridge vlan_filtering 1 363 ip link set dev $swp1 master br0 364 365 ip link set dev $swp1 up 366 ip link set dev br0 up 367 368 ip link add link br0 name br0.10 up type vlan id 10 369 ip -6 address add 2001:db8:1::1/64 dev br0.10 370 371 busywait "$TIMEOUT" wait_for_offload \ 372 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 373 check_err $? "vlan rif was not created before adding port to vlan" 374 375 bridge vlan add vid 10 dev $swp1 376 busywait "$TIMEOUT" wait_for_offload \ 377 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 378 check_err $? "vlan rif was destroyed after adding port to vlan" 379 380 bridge vlan del vid 10 dev $swp1 381 busywait "$TIMEOUT" wait_for_offload \ 382 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 383 check_err $? "vlan rif was destroyed after removing port from vlan" 384 385 ip link set dev $swp1 nomaster 386 busywait "$TIMEOUT" not wait_for_offload \ 387 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 388 check_err $? "vlan rif was not destroyed after unlinking port from bridge" 389 390 log_test "vlan rif refcount" 391 392 ip link del dev br0.10 393 ip link set dev $swp1 down 394 ip link del dev br0 395} 396 397subport_rif_refcount_test() 398{ 399 # Test that RIFs representing upper devices of physical ports are 400 # reference counted correctly and destroyed when should. We use the 401 # offload indication on routes configured on the RIF to understand if 402 # it was created / destroyed 403 RET=0 404 405 ip link add name bond1 type bond mode 802.3ad 406 ip link set dev $swp1 down 407 ip link set dev $swp2 down 408 ip link set dev $swp1 master bond1 409 ip link set dev $swp2 master bond1 410 411 ip link set dev bond1 up 412 ip link add link bond1 name bond1.10 up type vlan id 10 413 ip -6 address add 2001:db8:1::1/64 dev bond1 414 ip -6 address add 2001:db8:2::1/64 dev bond1.10 415 416 busywait "$TIMEOUT" wait_for_offload \ 417 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 418 check_err $? "subport rif was not created on lag device" 419 busywait "$TIMEOUT" wait_for_offload \ 420 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 421 check_err $? "subport rif was not created on vlan device" 422 423 ip link set dev $swp1 nomaster 424 busywait "$TIMEOUT" wait_for_offload \ 425 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 426 check_err $? "subport rif of lag device was destroyed when should not" 427 busywait "$TIMEOUT" wait_for_offload \ 428 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 429 check_err $? "subport rif of vlan device was destroyed when should not" 430 431 ip link set dev $swp2 nomaster 432 busywait "$TIMEOUT" not wait_for_offload \ 433 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 434 check_err $? "subport rif of lag device was not destroyed when should" 435 busywait "$TIMEOUT" not wait_for_offload \ 436 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 437 check_err $? "subport rif of vlan device was not destroyed when should" 438 439 log_test "subport rif refcount" 440 441 ip link del dev bond1.10 442 ip link del dev bond1 443} 444 445subport_rif_lag_join_test() 446{ 447 # Test that the reference count of a RIF configured for a LAG is 448 # incremented / decremented when ports join / leave the LAG. We use the 449 # offload indication on routes configured on the RIF to understand if 450 # it was created / destroyed 451 RET=0 452 453 ip link add name bond1 type bond mode 802.3ad 454 ip link set dev $swp1 down 455 ip link set dev $swp2 down 456 ip link set dev $swp1 master bond1 457 ip link set dev $swp2 master bond1 458 459 ip link set dev bond1 up 460 ip -6 address add 2001:db8:1::1/64 dev bond1 461 462 busywait "$TIMEOUT" wait_for_offload \ 463 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 464 check_err $? "subport rif was not created on lag device" 465 466 ip link set dev $swp1 nomaster 467 busywait "$TIMEOUT" wait_for_offload \ 468 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 469 check_err $? "subport rif of lag device was destroyed after removing one port" 470 471 ip link set dev $swp1 master bond1 472 ip link set dev $swp2 nomaster 473 busywait "$TIMEOUT" wait_for_offload \ 474 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 475 check_err $? "subport rif of lag device was destroyed after re-adding a port and removing another" 476 477 ip link set dev $swp1 nomaster 478 busywait "$TIMEOUT" not wait_for_offload \ 479 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 480 check_err $? "subport rif of lag device was not destroyed when should" 481 482 log_test "subport rif lag join" 483 484 ip link del dev bond1 485} 486 487vlan_dev_deletion_test() 488{ 489 # Test that VLAN devices are correctly deleted / unlinked when enslaved 490 # to bridge 491 RET=0 492 493 ip link add name br10 type bridge 494 ip link add name br20 type bridge 495 ip link add name br30 type bridge 496 ip link add link $swp1 name $swp1.10 type vlan id 10 497 ip link add link $swp1 name $swp1.20 type vlan id 20 498 ip link add link $swp1 name $swp1.30 type vlan id 30 499 ip link set dev $swp1.10 master br10 500 ip link set dev $swp1.20 master br20 501 ip link set dev $swp1.30 master br30 502 503 # If we did not handle the situation correctly, then these operations 504 # might produce a trace 505 ip link set dev $swp1.30 nomaster 506 ip link del dev $swp1.20 507 # Deletion via ioctl uses different code paths from netlink 508 vconfig rem $swp1.10 &> /dev/null 509 510 log_test "vlan device deletion" 511 512 ip link del dev $swp1.30 513 ip link del dev br30 514 ip link del dev br20 515 ip link del dev br10 516} 517 518lag_create() 519{ 520 ip link add name bond1 type bond mode 802.3ad 521 ip link set dev $swp1 down 522 ip link set dev $swp2 down 523 ip link set dev $swp1 master bond1 524 ip link set dev $swp2 master bond1 525 526 ip link add link bond1 name bond1.10 type vlan id 10 527 ip link add link bond1 name bond1.20 type vlan id 20 528 529 ip link add name br0 type bridge vlan_filtering 1 530 ip link set dev bond1 master br0 531 532 ip link add name br10 type bridge 533 ip link set dev bond1.10 master br10 534 535 ip link add name br20 type bridge 536 ip link set dev bond1.20 master br20 537} 538 539lag_unlink_slaves_test() 540{ 541 # Test that ports are correctly unlinked from their LAG master, when 542 # the LAG and its VLAN uppers are enslaved to bridges 543 RET=0 544 545 lag_create 546 547 ip link set dev $swp1 nomaster 548 check_err $? "lag slave $swp1 was not unlinked from master" 549 ip link set dev $swp2 nomaster 550 check_err $? "lag slave $swp2 was not unlinked from master" 551 552 # Try to configure corresponding VLANs as router interfaces 553 ip -6 address add 2001:db8:1::1/64 dev $swp1 554 check_err $? "failed to configure ip address on $swp1" 555 556 ip link add link $swp1 name $swp1.10 type vlan id 10 557 ip -6 address add 2001:db8:10::1/64 dev $swp1.10 558 check_err $? "failed to configure ip address on $swp1.10" 559 560 ip link add link $swp1 name $swp1.20 type vlan id 20 561 ip -6 address add 2001:db8:20::1/64 dev $swp1.20 562 check_err $? "failed to configure ip address on $swp1.20" 563 564 log_test "lag slaves unlinking" 565 566 ip link del dev $swp1.20 567 ip link del dev $swp1.10 568 ip address flush dev $swp1 569 570 ip link del dev br20 571 ip link del dev br10 572 ip link del dev br0 573 ip link del dev bond1 574} 575 576lag_dev_deletion_test() 577{ 578 # Test that LAG device is correctly deleted, when the LAG and its VLAN 579 # uppers are enslaved to bridges 580 RET=0 581 582 lag_create 583 584 ip link del dev bond1 585 586 log_test "lag device deletion" 587 588 ip link del dev br20 589 ip link del dev br10 590 ip link del dev br0 591} 592 593vlan_interface_uppers_test() 594{ 595 # Test that uppers of a VLAN interface are correctly sanitized 596 RET=0 597 598 ip link add name br0 type bridge vlan_filtering 1 599 ip link set dev $swp1 master br0 600 601 ip link add link br0 name br0.10 type vlan id 10 602 ip link add link br0.10 name macvlan0 \ 603 type macvlan mode private &> /dev/null 604 check_fail $? "managed to create a macvlan when should not" 605 606 ip -6 address add 2001:db8:1::1/64 dev br0.10 607 ip link add link br0.10 name macvlan0 type macvlan mode private 608 check_err $? "did not manage to create a macvlan when should" 609 610 ip link del dev macvlan0 611 612 ip link add name vrf-test type vrf table 10 613 ip link set dev br0.10 master vrf-test 614 check_err $? "did not manage to enslave vlan interface to vrf" 615 ip link del dev vrf-test 616 617 ip link add name br-test type bridge 618 ip link set dev br0.10 master br-test &> /dev/null 619 check_fail $? "managed to enslave vlan interface to bridge when should not" 620 ip link del dev br-test 621 622 log_test "vlan interface uppers" 623 624 ip link del dev br0 625} 626 627bridge_extern_learn_test() 628{ 629 # Test that externally learned entries added from user space are 630 # marked as offloaded 631 RET=0 632 633 ip link add name br0 type bridge 634 ip link set dev $swp1 master br0 635 636 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn 637 638 busywait "$TIMEOUT" wait_for_offload \ 639 bridge fdb show brport $swp1 de:ad:be:ef:13:37 640 check_err $? "fdb entry not marked as offloaded when should" 641 642 log_test "externally learned fdb entry" 643 644 ip link del dev br0 645} 646 647neigh_offload_test() 648{ 649 # Test that IPv4 and IPv6 neighbour entries are marked as offloaded 650 RET=0 651 652 ip -4 address add 192.0.2.1/24 dev $swp1 653 ip -6 address add 2001:db8:1::1/64 dev $swp1 654 655 ip -4 neigh add 192.0.2.2 lladdr de:ad:be:ef:13:37 nud perm dev $swp1 656 ip -6 neigh add 2001:db8:1::2 lladdr de:ad:be:ef:13:37 nud perm \ 657 dev $swp1 658 659 busywait "$TIMEOUT" wait_for_offload \ 660 ip -4 neigh show dev $swp1 192.0.2.2 661 check_err $? "ipv4 neigh entry not marked as offloaded when should" 662 busywait "$TIMEOUT" wait_for_offload \ 663 ip -6 neigh show dev $swp1 2001:db8:1::2 664 check_err $? "ipv6 neigh entry not marked as offloaded when should" 665 666 log_test "neighbour offload indication" 667 668 ip -6 neigh del 2001:db8:1::2 dev $swp1 669 ip -4 neigh del 192.0.2.2 dev $swp1 670 ip -6 address del 2001:db8:1::1/64 dev $swp1 671 ip -4 address del 192.0.2.1/24 dev $swp1 672} 673 674nexthop_offload_test() 675{ 676 # Test that IPv4 and IPv6 nexthops are marked as offloaded 677 RET=0 678 679 sysctl_set net.ipv6.conf.$swp2.keep_addr_on_down 1 680 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 681 simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64 682 setup_wait 683 684 ip -4 route add 198.51.100.0/24 vrf v$swp1 \ 685 nexthop via 192.0.2.2 dev $swp1 686 ip -6 route add 2001:db8:2::/64 vrf v$swp1 \ 687 nexthop via 2001:db8:1::2 dev $swp1 688 689 busywait "$TIMEOUT" wait_for_offload \ 690 ip -4 route show 198.51.100.0/24 vrf v$swp1 691 check_err $? "ipv4 nexthop not marked as offloaded when should" 692 busywait "$TIMEOUT" wait_for_offload \ 693 ip -6 route show 2001:db8:2::/64 vrf v$swp1 694 check_err $? "ipv6 nexthop not marked as offloaded when should" 695 696 ip link set dev $swp2 down 697 sleep 1 698 699 busywait "$TIMEOUT" not wait_for_offload \ 700 ip -4 route show 198.51.100.0/24 vrf v$swp1 701 check_err $? "ipv4 nexthop marked as offloaded when should not" 702 busywait "$TIMEOUT" not wait_for_offload \ 703 ip -6 route show 2001:db8:2::/64 vrf v$swp1 704 check_err $? "ipv6 nexthop marked as offloaded when should not" 705 706 ip link set dev $swp2 up 707 setup_wait 708 709 busywait "$TIMEOUT" wait_for_offload \ 710 ip -4 route show 198.51.100.0/24 vrf v$swp1 711 check_err $? "ipv4 nexthop not marked as offloaded after neigh add" 712 busywait "$TIMEOUT" wait_for_offload \ 713 ip -6 route show 2001:db8:2::/64 vrf v$swp1 714 check_err $? "ipv6 nexthop not marked as offloaded after neigh add" 715 716 log_test "nexthop offload indication" 717 718 ip -6 route del 2001:db8:2::/64 vrf v$swp1 719 ip -4 route del 198.51.100.0/24 vrf v$swp1 720 721 simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64 722 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 723 sysctl_restore net.ipv6.conf.$swp2.keep_addr_on_down 724} 725 726nexthop_obj_invalid_test() 727{ 728 # Test that invalid nexthop object configurations are rejected 729 RET=0 730 731 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 732 simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64 733 setup_wait 734 735 ip nexthop add id 1 via 192.0.2.3 fdb 736 check_fail $? "managed to configure an FDB nexthop when should not" 737 738 ip nexthop add id 1 encap mpls 200/300 via 192.0.2.3 dev $swp1 739 check_fail $? "managed to configure a nexthop with MPLS encap when should not" 740 741 ip nexthop add id 1 dev $swp1 742 ip nexthop add id 2 dev $swp1 743 ip nexthop add id 3 via 192.0.2.3 dev $swp1 744 ip nexthop add id 10 group 1/2 745 check_fail $? "managed to configure a nexthop group with device-only nexthops when should not" 746 747 ip nexthop add id 10 group 3 type resilient buckets 7 748 check_fail $? "managed to configure a too small resilient nexthop group when should not" 749 750 ip nexthop add id 10 group 3 type resilient buckets 129 751 check_fail $? "managed to configure a resilient nexthop group with invalid number of buckets when should not" 752 753 ip nexthop add id 10 group 1/2 type resilient buckets 32 754 check_fail $? "managed to configure a resilient nexthop group with device-only nexthops when should not" 755 756 ip nexthop add id 10 group 3 type resilient buckets 32 757 check_err $? "failed to configure a valid resilient nexthop group" 758 ip nexthop replace id 3 dev $swp1 759 check_fail $? "managed to populate a nexthop bucket with a device-only nexthop when should not" 760 761 log_test "nexthop objects - invalid configurations" 762 763 ip nexthop del id 10 764 ip nexthop del id 3 765 ip nexthop del id 2 766 ip nexthop del id 1 767 768 simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64 769 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 770} 771 772nexthop_obj_offload_test() 773{ 774 # Test offload indication of nexthop objects 775 RET=0 776 777 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 778 simple_if_init $swp2 779 setup_wait 780 781 ip nexthop add id 1 via 192.0.2.2 dev $swp1 782 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \ 783 dev $swp1 784 785 busywait "$TIMEOUT" wait_for_offload \ 786 ip nexthop show id 1 787 check_err $? "nexthop not marked as offloaded when should" 788 789 ip neigh replace 192.0.2.2 nud failed dev $swp1 790 busywait "$TIMEOUT" not wait_for_offload \ 791 ip nexthop show id 1 792 check_err $? "nexthop marked as offloaded after setting neigh to failed state" 793 794 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \ 795 dev $swp1 796 busywait "$TIMEOUT" wait_for_offload \ 797 ip nexthop show id 1 798 check_err $? "nexthop not marked as offloaded after neigh replace" 799 800 ip nexthop replace id 1 via 192.0.2.3 dev $swp1 801 busywait "$TIMEOUT" not wait_for_offload \ 802 ip nexthop show id 1 803 check_err $? "nexthop marked as offloaded after replacing to use an invalid address" 804 805 ip nexthop replace id 1 via 192.0.2.2 dev $swp1 806 busywait "$TIMEOUT" wait_for_offload \ 807 ip nexthop show id 1 808 check_err $? "nexthop not marked as offloaded after replacing to use a valid address" 809 810 log_test "nexthop objects offload indication" 811 812 ip neigh del 192.0.2.2 dev $swp1 813 ip nexthop del id 1 814 815 simple_if_fini $swp2 816 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 817} 818 819nexthop_obj_group_offload_test() 820{ 821 # Test offload indication of nexthop group objects 822 RET=0 823 824 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 825 simple_if_init $swp2 826 setup_wait 827 828 ip nexthop add id 1 via 192.0.2.2 dev $swp1 829 ip nexthop add id 2 via 2001:db8:1::2 dev $swp1 830 ip nexthop add id 10 group 1/2 831 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \ 832 dev $swp1 833 ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud reachable \ 834 dev $swp1 835 ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud reachable \ 836 dev $swp1 837 838 busywait "$TIMEOUT" wait_for_offload \ 839 ip nexthop show id 1 840 check_err $? "IPv4 nexthop not marked as offloaded when should" 841 busywait "$TIMEOUT" wait_for_offload \ 842 ip nexthop show id 2 843 check_err $? "IPv6 nexthop not marked as offloaded when should" 844 busywait "$TIMEOUT" wait_for_offload \ 845 ip nexthop show id 10 846 check_err $? "nexthop group not marked as offloaded when should" 847 848 # Invalidate nexthop id 1 849 ip neigh replace 192.0.2.2 nud failed dev $swp1 850 busywait "$TIMEOUT" not wait_for_offload \ 851 ip nexthop show id 10 852 check_fail $? "nexthop group not marked as offloaded with one valid nexthop" 853 854 # Invalidate nexthop id 2 855 ip neigh replace 2001:db8:1::2 nud failed dev $swp1 856 busywait "$TIMEOUT" not wait_for_offload \ 857 ip nexthop show id 10 858 check_err $? "nexthop group marked as offloaded when should not" 859 860 # Revalidate nexthop id 1 861 ip nexthop replace id 1 via 192.0.2.3 dev $swp1 862 busywait "$TIMEOUT" wait_for_offload \ 863 ip nexthop show id 10 864 check_err $? "nexthop group not marked as offloaded after revalidating nexthop" 865 866 log_test "nexthop group objects offload indication" 867 868 ip neigh del 2001:db8:1::2 dev $swp1 869 ip neigh del 192.0.2.3 dev $swp1 870 ip neigh del 192.0.2.2 dev $swp1 871 ip nexthop del id 10 872 ip nexthop del id 2 873 ip nexthop del id 1 874 875 simple_if_fini $swp2 876 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 877} 878 879nexthop_obj_bucket_offload_test() 880{ 881 # Test offload indication of nexthop buckets 882 RET=0 883 884 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 885 simple_if_init $swp2 886 setup_wait 887 888 ip nexthop add id 1 via 192.0.2.2 dev $swp1 889 ip nexthop add id 2 via 2001:db8:1::2 dev $swp1 890 ip nexthop add id 10 group 1/2 type resilient buckets 32 idle_timer 0 891 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \ 892 dev $swp1 893 ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud reachable \ 894 dev $swp1 895 ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud reachable \ 896 dev $swp1 897 898 busywait "$TIMEOUT" wait_for_offload \ 899 ip nexthop bucket show nhid 1 900 check_err $? "IPv4 nexthop buckets not marked as offloaded when should" 901 busywait "$TIMEOUT" wait_for_offload \ 902 ip nexthop bucket show nhid 2 903 check_err $? "IPv6 nexthop buckets not marked as offloaded when should" 904 905 # Invalidate nexthop id 1 906 ip neigh replace 192.0.2.2 nud failed dev $swp1 907 busywait "$TIMEOUT" wait_for_trap \ 908 ip nexthop bucket show nhid 1 909 check_err $? "IPv4 nexthop buckets not marked with trap when should" 910 911 # Invalidate nexthop id 2 912 ip neigh replace 2001:db8:1::2 nud failed dev $swp1 913 busywait "$TIMEOUT" wait_for_trap \ 914 ip nexthop bucket show nhid 2 915 check_err $? "IPv6 nexthop buckets not marked with trap when should" 916 917 # Revalidate nexthop id 1 by changing its configuration 918 ip nexthop replace id 1 via 192.0.2.3 dev $swp1 919 busywait "$TIMEOUT" wait_for_offload \ 920 ip nexthop bucket show nhid 1 921 check_err $? "nexthop bucket not marked as offloaded after revalidating nexthop" 922 923 # Revalidate nexthop id 2 by changing its neighbour 924 ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud reachable \ 925 dev $swp1 926 busywait "$TIMEOUT" wait_for_offload \ 927 ip nexthop bucket show nhid 2 928 check_err $? "nexthop bucket not marked as offloaded after revalidating neighbour" 929 930 log_test "nexthop bucket offload indication" 931 932 ip neigh del 2001:db8:1::2 dev $swp1 933 ip neigh del 192.0.2.3 dev $swp1 934 ip neigh del 192.0.2.2 dev $swp1 935 ip nexthop del id 10 936 ip nexthop del id 2 937 ip nexthop del id 1 938 939 simple_if_fini $swp2 940 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 941} 942 943nexthop_obj_blackhole_offload_test() 944{ 945 # Test offload indication of blackhole nexthop objects 946 RET=0 947 948 ip nexthop add id 1 blackhole 949 busywait "$TIMEOUT" wait_for_offload \ 950 ip nexthop show id 1 951 check_err $? "Blackhole nexthop not marked as offloaded when should" 952 953 ip nexthop add id 10 group 1 954 busywait "$TIMEOUT" wait_for_offload \ 955 ip nexthop show id 10 956 check_err $? "Nexthop group not marked as offloaded when should" 957 958 log_test "blackhole nexthop objects offload indication" 959 960 ip nexthop del id 10 961 ip nexthop del id 1 962} 963 964nexthop_obj_route_offload_test() 965{ 966 # Test offload indication of routes using nexthop objects 967 RET=0 968 969 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64 970 simple_if_init $swp2 971 setup_wait 972 973 ip nexthop add id 1 via 192.0.2.2 dev $swp1 974 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \ 975 dev $swp1 976 ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud reachable \ 977 dev $swp1 978 979 ip route replace 198.51.100.0/24 nhid 1 980 busywait "$TIMEOUT" wait_for_offload \ 981 ip route show 198.51.100.0/24 982 check_err $? "route not marked as offloaded when using valid nexthop" 983 984 ip nexthop replace id 1 via 192.0.2.3 dev $swp1 985 busywait "$TIMEOUT" wait_for_offload \ 986 ip route show 198.51.100.0/24 987 check_err $? "route not marked as offloaded after replacing valid nexthop with a valid one" 988 989 ip nexthop replace id 1 via 192.0.2.4 dev $swp1 990 busywait "$TIMEOUT" not wait_for_offload \ 991 ip route show 198.51.100.0/24 992 check_err $? "route marked as offloaded after replacing valid nexthop with an invalid one" 993 994 ip nexthop replace id 1 via 192.0.2.2 dev $swp1 995 busywait "$TIMEOUT" wait_for_offload \ 996 ip route show 198.51.100.0/24 997 check_err $? "route not marked as offloaded after replacing invalid nexthop with a valid one" 998 999 log_test "routes using nexthop objects offload indication" 1000 1001 ip route del 198.51.100.0/24 1002 ip neigh del 192.0.2.3 dev $swp1 1003 ip neigh del 192.0.2.2 dev $swp1 1004 ip nexthop del id 1 1005 1006 simple_if_fini $swp2 1007 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64 1008} 1009 1010devlink_reload_test() 1011{ 1012 # Test that after executing all the above configuration tests, a 1013 # devlink reload can be performed without errors 1014 RET=0 1015 1016 devlink dev reload "$DEVLINK_DEV" 1017 check_err $? "devlink reload failed" 1018 1019 log_test "devlink reload - last test" 1020 1021 sleep 20 1022} 1023 1024trap cleanup EXIT 1025 1026setup_prepare 1027setup_wait 1028 1029tests_run 1030 1031exit $EXIT_STATUS 1032