|
| 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 | + |
| 10 | +lib_dir=$(dirname $0)/../../../net/forwarding |
| 11 | + |
| 12 | +ALL_TESTS=" |
| 13 | + rif_set_addr_test |
| 14 | +" |
| 15 | +NUM_NETIFS=2 |
| 16 | +source $lib_dir/lib.sh |
| 17 | + |
| 18 | +setup_prepare() |
| 19 | +{ |
| 20 | + swp1=${NETIFS[p1]} |
| 21 | + swp2=${NETIFS[p2]} |
| 22 | + |
| 23 | + ip link set dev $swp1 up |
| 24 | + ip link set dev $swp2 up |
| 25 | +} |
| 26 | + |
| 27 | +cleanup() |
| 28 | +{ |
| 29 | + pre_cleanup |
| 30 | + |
| 31 | + ip link set dev $swp2 down |
| 32 | + ip link set dev $swp1 down |
| 33 | +} |
| 34 | + |
| 35 | +rif_set_addr_test() |
| 36 | +{ |
| 37 | + local swp1_mac=$(mac_get $swp1) |
| 38 | + local swp2_mac=$(mac_get $swp2) |
| 39 | + |
| 40 | + RET=0 |
| 41 | + |
| 42 | + # $swp1 and $swp2 likely got their IPv6 local addresses already, but |
| 43 | + # here we need to test the transition to RIF. |
| 44 | + ip addr flush dev $swp1 |
| 45 | + ip addr flush dev $swp2 |
| 46 | + sleep .1 |
| 47 | + |
| 48 | + ip addr add dev $swp1 192.0.2.1/28 |
| 49 | + check_err $? |
| 50 | + |
| 51 | + ip link set dev $swp1 addr 00:11:22:33:44:55 |
| 52 | + check_err $? |
| 53 | + |
| 54 | + # IP address enablement should be rejected if the MAC address prefix |
| 55 | + # doesn't match other RIFs. |
| 56 | + ip addr add dev $swp2 192.0.2.2/28 &>/dev/null |
| 57 | + check_fail $? "IP address addition passed for a device with a wrong MAC" |
| 58 | + ip addr add dev $swp2 192.0.2.2/28 2>&1 >/dev/null \ |
| 59 | + | grep -q mlxsw_spectrum |
| 60 | + check_err $? "no extack for IP address addition" |
| 61 | + |
| 62 | + ip link set dev $swp2 addr 00:11:22:33:44:66 |
| 63 | + check_err $? |
| 64 | + ip addr add dev $swp2 192.0.2.2/28 &>/dev/null |
| 65 | + check_err $? |
| 66 | + |
| 67 | + # Change of MAC address of a RIF should be forbidden if the new MAC |
| 68 | + # doesn't share the prefix with other MAC addresses. |
| 69 | + ip link set dev $swp2 addr 00:11:22:33:00:66 &>/dev/null |
| 70 | + check_fail $? "change of MAC address passed for a wrong MAC" |
| 71 | + ip link set dev $swp2 addr 00:11:22:33:00:66 2>&1 >/dev/null \ |
| 72 | + | grep -q mlxsw_spectrum |
| 73 | + check_err $? "no extack for MAC address change" |
| 74 | + |
| 75 | + log_test "RIF - bad MAC change" |
| 76 | + |
| 77 | + ip addr del dev $swp2 192.0.2.2/28 |
| 78 | + ip addr del dev $swp1 192.0.2.1/28 |
| 79 | + |
| 80 | + ip link set dev $swp2 addr $swp2_mac |
| 81 | + ip link set dev $swp1 addr $swp1_mac |
| 82 | +} |
| 83 | + |
| 84 | +trap cleanup EXIT |
| 85 | + |
| 86 | +setup_prepare |
| 87 | +setup_wait |
| 88 | + |
| 89 | +tests_run |
| 90 | + |
| 91 | +exit $EXIT_STATUS |
0 commit comments