Skip to content

Commit b4f9763

Browse files
author
Sabrina Dubroca
committed
selftests: move macsec offload tests from net/rtnetlink to drivers/net/netdvesim
JIRA: https://issues.redhat.com/browse/RHEL-26055 commit 415b7ce Author: Sabrina Dubroca <sd@queasysnail.net> Date: Thu Nov 7 00:13:32 2024 +0100 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 <sd@queasysnail.net> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/a1f92c250cc129b4bb111a206c4b560bab4e24a5.1730929545.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
1 parent a0680e7 commit b4f9763

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
@@ -10,6 +10,7 @@ TEST_PROGS = devlink.sh \
1010
ethtool-ring.sh \
1111
fib.sh \
1212
hw_stats_l3.sh \
13+
macsec-offload.sh \
1314
nexthop.sh \
1415
peer.sh \
1516
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
@@ -561,73 +560,6 @@ kci_test_macsec()
561560
end_test "PASS: macsec"
562561
}
563562

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

0 commit comments

Comments
 (0)