cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

devlink_in_netns.sh (1375B)


      1#!/bin/bash
      2# SPDX-License-Identifier: GPL-2.0
      3
      4lib_dir=$(dirname $0)/../../../net/forwarding
      5
      6ALL_TESTS="check_devlink_test check_ports_test"
      7NUM_NETIFS=0
      8source $lib_dir/lib.sh
      9
     10BUS_ADDR=10
     11PORT_COUNT=4
     12DEV_NAME=netdevsim$BUS_ADDR
     13SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
     14DL_HANDLE=netdevsim/$DEV_NAME
     15NETNS_NAME=testns1
     16
     17port_netdev_get()
     18{
     19	local port_index=$1
     20
     21	cmd_jq "devlink -N $NETNS_NAME port show -j" \
     22	       ".[][\"$DL_HANDLE/$port_index\"].netdev" "-e"
     23}
     24
     25check_ports_test()
     26{
     27	RET=0
     28
     29	for i in $(seq 0 $(expr $PORT_COUNT - 1)); do
     30		netdev_name=$(port_netdev_get $i)
     31		check_err $? "Failed to get netdev name for port $DL_HANDLE/$i"
     32		ip -n $NETNS_NAME link show $netdev_name &> /dev/null
     33		check_err $? "Failed to find netdev $netdev_name"
     34	done
     35
     36	log_test "check ports test"
     37}
     38
     39check_devlink_test()
     40{
     41	RET=0
     42
     43	devlink -N $NETNS_NAME dev show $DL_HANDLE &> /dev/null
     44	check_err $? "Failed to show devlink instance"
     45
     46	log_test "check devlink test"
     47}
     48
     49setup_prepare()
     50{
     51	modprobe netdevsim
     52	ip netns add $NETNS_NAME
     53	ip netns exec $NETNS_NAME \
     54		echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device
     55	while [ ! -d $SYSFS_NET_DIR ] ; do :; done
     56}
     57
     58cleanup()
     59{
     60	pre_cleanup
     61	echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device
     62	ip netns del $NETNS_NAME
     63	modprobe -r netdevsim
     64}
     65
     66trap cleanup EXIT
     67
     68setup_prepare
     69
     70tests_run
     71
     72exit $EXIT_STATUS