]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
selftests: mlxsw: Test RIF MAC vetoing
authorPetr Machata <petrm@mellanox.com>
Thu, 13 Dec 2018 11:54:54 +0000 (11:54 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 14 Dec 2018 02:41:39 +0000 (18:41 -0800)
Test that attempts to change address in a way that violates Spectrum
requirements are vetoed with extack.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh [new file with mode: 0755]

diff --git a/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh b/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh
new file mode 100755 (executable)
index 0000000..bc8b44c
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Test various interface configuration scenarios. Observe that configurations
+# deemed valid by mlxsw succeed, invalid configurations fail and that no traces
+# are produced. To prevent the test from passing in case traces are produced,
+# the user can set the 'kernel.panic_on_warn' and 'kernel.panic_on_oops'
+# sysctls in its environment.
+
+lib_dir=$(dirname $0)/../../../net/forwarding
+
+ALL_TESTS="
+       rif_set_addr_test
+"
+NUM_NETIFS=2
+source $lib_dir/lib.sh
+
+setup_prepare()
+{
+       swp1=${NETIFS[p1]}
+       swp2=${NETIFS[p2]}
+
+       ip link set dev $swp1 up
+       ip link set dev $swp2 up
+}
+
+cleanup()
+{
+       pre_cleanup
+
+       ip link set dev $swp2 down
+       ip link set dev $swp1 down
+}
+
+rif_set_addr_test()
+{
+       local swp1_mac=$(mac_get $swp1)
+       local swp2_mac=$(mac_get $swp2)
+
+       RET=0
+
+       # $swp1 and $swp2 likely got their IPv6 local addresses already, but
+       # here we need to test the transition to RIF.
+       ip addr flush dev $swp1
+       ip addr flush dev $swp2
+       sleep .1
+
+       ip addr add dev $swp1 192.0.2.1/28
+       check_err $?
+
+       ip link set dev $swp1 addr 00:11:22:33:44:55
+       check_err $?
+
+       # IP address enablement should be rejected if the MAC address prefix
+       # doesn't match other RIFs.
+       ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
+       check_fail $? "IP address addition passed for a device with a wrong MAC"
+       ip addr add dev $swp2 192.0.2.2/28 2>&1 >/dev/null \
+           | grep -q mlxsw_spectrum
+       check_err $? "no extack for IP address addition"
+
+       ip link set dev $swp2 addr 00:11:22:33:44:66
+       check_err $?
+       ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
+       check_err $?
+
+       # Change of MAC address of a RIF should be forbidden if the new MAC
+       # doesn't share the prefix with other MAC addresses.
+       ip link set dev $swp2 addr 00:11:22:33:00:66 &>/dev/null
+       check_fail $? "change of MAC address passed for a wrong MAC"
+       ip link set dev $swp2 addr 00:11:22:33:00:66 2>&1 >/dev/null \
+           | grep -q mlxsw_spectrum
+       check_err $? "no extack for MAC address change"
+
+       log_test "RIF - bad MAC change"
+
+       ip addr del dev $swp2 192.0.2.2/28
+       ip addr del dev $swp1 192.0.2.1/28
+
+       ip link set dev $swp2 addr $swp2_mac
+       ip link set dev $swp1 addr $swp1_mac
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS