Commit 415b7cef authored by Sabrina Dubroca's avatar Sabrina Dubroca Committed by Jakub Kicinski
Browse files

selftests: move macsec offload tests from net/rtnetlink to drivers/net/netdvesim



We're going to expand this test, and macsec offload is only lightly
related to rtnetlink.

Signed-off-by: default avatarSabrina Dubroca <sd@queasysnail.net>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://patch.msgid.link/a1f92c250cc129b4bb111a206c4b560bab4e24a5.1730929545.git.sd@queasysnail.net


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent de187a39
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ TEST_PROGS = devlink.sh \
	fib.sh \
	fib_notifications.sh \
	hw_stats_l3.sh \
	macsec-offload.sh \
	nexthop.sh \
	peer.sh \
	psample.sh \
+1 −0
Original line number Diff line number Diff line
CONFIG_DUMMY=y
CONFIG_GENEVE=m
CONFIG_IPV6=y
CONFIG_MACSEC=m
CONFIG_NETDEVSIM=m
CONFIG_NET_SCH_MQPRIO=y
CONFIG_NET_SCH_MULTIQ=y
+63 −0
Original line number Diff line number Diff line
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only

source ethtool-common.sh

NSIM_NETDEV=$(make_netdev)
MACSEC_NETDEV=macsec_nsim

set -o pipefail

if ! ethtool -k $NSIM_NETDEV | grep -q 'macsec-hw-offload: on'; then
    echo "SKIP: netdevsim doesn't support MACsec offload"
    exit 4
fi

if ! ip link add link $NSIM_NETDEV $MACSEC_NETDEV type macsec offload mac 2>/dev/null; then
    echo "SKIP: couldn't create macsec device"
    exit 4
fi
ip link del $MACSEC_NETDEV

#
# test macsec offload API
#

ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}" type macsec port 4 offload mac
check $?

ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}2" type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
check $?

ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}3" type macsec sci abbacdde01020304 offload mac
check $?

ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}4" type macsec port 8 offload mac 2> /dev/null
check $? '' '' 1

ip macsec add "${MACSEC_NETDEV}" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
check $?

ip macsec add "${MACSEC_NETDEV}" rx port 1234 address "1c:ed:de:ad:be:ef"
check $?

ip macsec add "${MACSEC_NETDEV}" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
    key 00 0123456789abcdef0123456789abcdef
check $?

ip macsec add "${MACSEC_NETDEV}" rx port 1235 address "1c:ed:de:ad:be:ef" 2> /dev/null
check $? '' '' 1

for dev in ${MACSEC_NETDEV}{,2,3} ; do
    ip link del $dev
    check $?
done


if [ $num_errors -eq 0 ]; then
    echo "PASSED all $((num_passes)) checks"
    exit 0
else
    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
    exit 1
fi
+0 −68
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ ALL_TESTS="
	kci_test_vrf
	kci_test_encap
	kci_test_macsec
	kci_test_macsec_offload
	kci_test_ipsec
	kci_test_ipsec_offload
	kci_test_fdb_get
@@ -560,73 +559,6 @@ kci_test_macsec()
	end_test "PASS: macsec"
}

kci_test_macsec_offload()
{
	sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
	sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
	probed=false
	local ret=0
	run_cmd_grep "^Usage: ip macsec" ip macsec help
	if [ $? -ne 0 ]; then
		end_test "SKIP: macsec: iproute2 too old"
		return $ksft_skip
	fi

	if ! mount | grep -q debugfs; then
		mount -t debugfs none /sys/kernel/debug/ &> /dev/null
	fi

	# setup netdevsim since dummydev doesn't have offload support
	if [ ! -w /sys/bus/netdevsim/new_device ] ; then
		run_cmd modprobe -q netdevsim

		if [ $ret -ne 0 ]; then
			end_test "SKIP: macsec_offload can't load netdevsim"
			return $ksft_skip
		fi
		probed=true
	fi

	echo "0" > /sys/bus/netdevsim/new_device
	while [ ! -d $sysfsnet ] ; do :; done
	udevadm settle
	dev=`ls $sysfsnet`

	ip link set $dev up
	if [ ! -d $sysfsd ] ; then
		end_test "FAIL: macsec_offload can't create device $dev"
		return 1
	fi
	run_cmd_grep 'macsec-hw-offload: on' ethtool -k $dev
	if [ $? -eq 1 ] ; then
		end_test "FAIL: macsec_offload netdevsim doesn't support MACsec offload"
		return 1
	fi
	run_cmd ip link add link $dev kci_macsec1 type macsec port 4 offload mac
	run_cmd ip link add link $dev kci_macsec2 type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
	run_cmd ip link add link $dev kci_macsec3 type macsec sci abbacdde01020304 offload mac
	run_cmd_fail ip link add link $dev kci_macsec4 type macsec port 8 offload mac

	msname=kci_macsec1
	run_cmd ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
	run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
	run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
		key 00 0123456789abcdef0123456789abcdef
	run_cmd_fail ip macsec add "$msname" rx port 1235 address "1c:ed:de:ad:be:ef"
	# clean up any leftovers
	for msdev in kci_macsec{1,2,3,4} ; do
	    ip link del $msdev 2> /dev/null
	done
	echo 0 > /sys/bus/netdevsim/del_device
	$probed && rmmod netdevsim

	if [ $ret -ne 0 ]; then
		end_test "FAIL: macsec_offload"
		return 1
	fi
	end_test "PASS: macsec_offload"
}

#-------------------------------------------------------------------
# Example commands
#   ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \