Skip to content

Commit

Permalink
selftests: mlxsw: Test RIF MAC vetoing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Petr Machata authored and David S. Miller committed Dec 14, 2018
1 parent 74bc993 commit 555afaa
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 555afaa

Please sign in to comment.