Skip to content

Commit 0b7d028

Browse files
qsnNipaLocal
authored and
NipaLocal
committed
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: Sabrina Dubroca <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent fac1608 commit 0b7d028

File tree

4 files changed

+65
-68
lines changed

4 files changed

+65
-68
lines changed

tools/testing/selftests/drivers/net/netdevsim/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ TEST_PROGS = devlink.sh \
1111
fib.sh \
1212
fib_notifications.sh \
1313
hw_stats_l3.sh \
14+
macsec-offload.sh \
1415
nexthop.sh \
1516
peer.sh \
1617
psample.sh \

tools/testing/selftests/drivers/net/netdevsim/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_DUMMY=y
22
CONFIG_GENEVE=m
33
CONFIG_IPV6=y
4+
CONFIG_MACSEC=m
45
CONFIG_NETDEVSIM=m
56
CONFIG_NET_SCH_MQPRIO=y
67
CONFIG_NET_SCH_MULTIQ=y
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
4+
source ethtool-common.sh
5+
6+
NSIM_NETDEV=$(make_netdev)
7+
MACSEC_NETDEV=macsec_nsim
8+
9+
set -o pipefail
10+
11+
if ! ethtool -k $NSIM_NETDEV | grep -q 'macsec-hw-offload: on'; then
12+
echo "SKIP: netdevsim doesn't support MACsec offload"
13+
exit 4
14+
fi
15+
16+
if ! ip link add link $NSIM_NETDEV $MACSEC_NETDEV type macsec offload mac 2>/dev/null; then
17+
echo "SKIP: couldn't create macsec device"
18+
exit 4
19+
fi
20+
ip link del $MACSEC_NETDEV
21+
22+
#
23+
# test macsec offload API
24+
#
25+
26+
ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}" type macsec port 4 offload mac
27+
check $?
28+
29+
ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}2" type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
30+
check $?
31+
32+
ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}3" type macsec sci abbacdde01020304 offload mac
33+
check $?
34+
35+
ip link add link $NSIM_NETDEV "${MACSEC_NETDEV}4" type macsec port 8 offload mac 2> /dev/null
36+
check $? '' '' 1
37+
38+
ip macsec add "${MACSEC_NETDEV}" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
39+
check $?
40+
41+
ip macsec add "${MACSEC_NETDEV}" rx port 1234 address "1c:ed:de:ad:be:ef"
42+
check $?
43+
44+
ip macsec add "${MACSEC_NETDEV}" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
45+
key 00 0123456789abcdef0123456789abcdef
46+
check $?
47+
48+
ip macsec add "${MACSEC_NETDEV}" rx port 1235 address "1c:ed:de:ad:be:ef" 2> /dev/null
49+
check $? '' '' 1
50+
51+
for dev in ${MACSEC_NETDEV}{,2,3} ; do
52+
ip link del $dev
53+
check $?
54+
done
55+
56+
57+
if [ $num_errors -eq 0 ]; then
58+
echo "PASSED all $((num_passes)) checks"
59+
exit 0
60+
else
61+
echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
62+
exit 1
63+
fi

tools/testing/selftests/net/rtnetlink.sh

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ ALL_TESTS="
2121
kci_test_vrf
2222
kci_test_encap
2323
kci_test_macsec
24-
kci_test_macsec_offload
2524
kci_test_ipsec
2625
kci_test_ipsec_offload
2726
kci_test_fdb_get
@@ -560,73 +559,6 @@ kci_test_macsec()
560559
end_test "PASS: macsec"
561560
}
562561

563-
kci_test_macsec_offload()
564-
{
565-
sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
566-
sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
567-
probed=false
568-
local ret=0
569-
run_cmd_grep "^Usage: ip macsec" ip macsec help
570-
if [ $? -ne 0 ]; then
571-
end_test "SKIP: macsec: iproute2 too old"
572-
return $ksft_skip
573-
fi
574-
575-
if ! mount | grep -q debugfs; then
576-
mount -t debugfs none /sys/kernel/debug/ &> /dev/null
577-
fi
578-
579-
# setup netdevsim since dummydev doesn't have offload support
580-
if [ ! -w /sys/bus/netdevsim/new_device ] ; then
581-
run_cmd modprobe -q netdevsim
582-
583-
if [ $ret -ne 0 ]; then
584-
end_test "SKIP: macsec_offload can't load netdevsim"
585-
return $ksft_skip
586-
fi
587-
probed=true
588-
fi
589-
590-
echo "0" > /sys/bus/netdevsim/new_device
591-
while [ ! -d $sysfsnet ] ; do :; done
592-
udevadm settle
593-
dev=`ls $sysfsnet`
594-
595-
ip link set $dev up
596-
if [ ! -d $sysfsd ] ; then
597-
end_test "FAIL: macsec_offload can't create device $dev"
598-
return 1
599-
fi
600-
run_cmd_grep 'macsec-hw-offload: on' ethtool -k $dev
601-
if [ $? -eq 1 ] ; then
602-
end_test "FAIL: macsec_offload netdevsim doesn't support MACsec offload"
603-
return 1
604-
fi
605-
run_cmd ip link add link $dev kci_macsec1 type macsec port 4 offload mac
606-
run_cmd ip link add link $dev kci_macsec2 type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
607-
run_cmd ip link add link $dev kci_macsec3 type macsec sci abbacdde01020304 offload mac
608-
run_cmd_fail ip link add link $dev kci_macsec4 type macsec port 8 offload mac
609-
610-
msname=kci_macsec1
611-
run_cmd ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
612-
run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
613-
run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
614-
key 00 0123456789abcdef0123456789abcdef
615-
run_cmd_fail ip macsec add "$msname" rx port 1235 address "1c:ed:de:ad:be:ef"
616-
# clean up any leftovers
617-
for msdev in kci_macsec{1,2,3,4} ; do
618-
ip link del $msdev 2> /dev/null
619-
done
620-
echo 0 > /sys/bus/netdevsim/del_device
621-
$probed && rmmod netdevsim
622-
623-
if [ $ret -ne 0 ]; then
624-
end_test "FAIL: macsec_offload"
625-
return 1
626-
fi
627-
end_test "PASS: macsec_offload"
628-
}
629-
630562
#-------------------------------------------------------------------
631563
# Example commands
632564
# ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \

0 commit comments

Comments
 (0)