xref: /aosp_15_r20/external/ltp/testcases/network/virt/macsec_lib.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2018-2022 Petr Vorel <[email protected]>
4# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
5# Author: Alexey Kodanev <[email protected]>
6
7virt_type="macsec"
8VIRT_PERF_THRESHOLD_MIN=100
9IPSEC_MODE="transport"
10
11TST_NEEDS_TMPDIR=1
12TST_TESTFUNC=virt_netperf_msg_sizes
13TST_SETUP="${TST_SETUP:-macsec_lib_setup}"
14TST_CLEANUP="${TST_CLEANUP:-macsec_lib_cleanup}"
15TST_NEEDS_DRIVERS="macsec"
16
17# MACSEC_LIB_SETUP:
18# [ cipher { default | gcm-aes-128 } ] [ encrypt { on | off } ]
19# [ protect { on | off } ] [ replay { on | off } ] [ window WINDOW ]
20# [ validate { strict | check | disabled } ]
21macsec_lib_setup()
22{
23	local keyid0="01"
24	local keyid1="02"
25	local sa=0
26	local h0=$(tst_hwaddr)
27	local h1=$(tst_hwaddr rhost)
28	local cmd="ip macsec add ltp_v0"
29	local key0="01234567890123456789012345678901"
30	local key1="98765432109876543210987612343434"
31
32	ipsec_lib_setup
33
34	tst_res TINFO "setup IPsec $IPSEC_MODE/$IPSEC_PROTO $EALGO"
35	tst_ipsec lhost $(tst_ipaddr) $(tst_ipaddr rhost)
36	tst_ipsec rhost $(tst_ipaddr rhost) $(tst_ipaddr)
37
38	virt_setup "icvlen 16 encodingsa $sa $MACSEC_LIB_SETUP"
39
40	ROD $cmd tx sa $sa pn 100 on key $keyid0 $key0
41	ROD $cmd rx address $h1 port 1
42	ROD $cmd rx address $h1 port 1 sa $sa pn 100 on key $keyid1 $key1
43
44	tst_rhost_run -s -c "$cmd tx sa $sa pn 100 on key $keyid1 $key1"
45	tst_rhost_run -s -c "$cmd rx address $h0 port 1"
46	tst_rhost_run -s -c \
47		"$cmd rx address $h0 port 1 sa $sa pn 100 on key $keyid0 $key0"
48}
49
50macsec_lib_cleanup()
51{
52	virt_cleanup
53	tst_ipsec_cleanup
54}
55
56. ipsec_lib.sh
57. virt_lib.sh
58