/
usr
/
src
/
linux-headers-5.15.0-190
/
tools
/
testing
/
selftests
/
net
/
/usr/src/linux-headers-5.15.0-190/tools/testing/selftests/net
mkdir
upload
Name
Size
Mode
Actions
af_unix/
-
0755
rm
forwarding/
-
0755
rm
mptcp/
-
0755
rm
altnames.sh
1817
0755
edit
dl
rm
bareudp.sh
21290
0755
edit
dl
rm
drop_monitor_tests.sh
4439
0755
edit
dl
rm
fcnal-test.sh
103221
0755
edit
dl
rm
fib-onlink-tests.sh
12409
0755
edit
dl
rm
fib_nexthops.sh
68003
0755
edit
dl
rm
fib_nexthop_multiprefix.sh
5870
0755
edit
dl
rm
fib_nexthop_nongw.sh
2327
0755
edit
dl
rm
fib_rule_tests.sh
5981
0755
edit
dl
rm
fib_tests.sh
57224
0755
edit
dl
rm
fin_ack_lat.sh
507
0755
edit
dl
rm
gre_gso.sh
4237
0755
edit
dl
rm
gro.sh
2132
0755
edit
dl
rm
icmp.sh
2618
0755
edit
dl
rm
icmp_redirect.sh
12820
0755
edit
dl
rm
in_netns.sh
323
0755
edit
dl
rm
ioam6.sh
25962
0755
edit
dl
rm
ip6_gre_headroom.sh
1400
0755
edit
dl
rm
ipv6_flowlabel.sh
502
0755
edit
dl
rm
ip_defrag.sh
2087
0755
edit
dl
rm
l2tp.sh
9909
0755
edit
dl
rm
lib.sh
597
0644
edit
dl
rm
Makefile
2499
0644
edit
dl
rm
msg_zerocopy.sh
3012
0755
edit
dl
rm
netdevice.sh
4521
0755
edit
dl
rm
net_helper.sh
514
0644
edit
dl
rm
pmtu.sh
74711
0755
edit
dl
rm
psock_snd.sh
2252
0755
edit
dl
rm
reuseaddr_ports_exhausted.sh
635
0755
edit
dl
rm
reuseport_addr_any.sh
81
0755
edit
dl
rm
route_localnet.sh
1871
0755
edit
dl
rm
rtnetlink.sh
29476
0755
edit
dl
rm
rxtimestamp.sh
79
0755
edit
dl
rm
setup_loopback.sh
2654
0644
edit
dl
rm
setup_veth.sh
929
0644
edit
dl
rm
so_txtime.sh
2434
0755
edit
dl
rm
srv6_end_dt4_l3vpn_test.sh
17454
0755
edit
dl
rm
srv6_end_dt6_l3vpn_test.sh
17615
0755
edit
dl
rm
srv6_end_dt46_l3vpn_test.sh
21121
0755
edit
dl
rm
tcp_fastopen_backup_key.sh
1086
0755
edit
dl
rm
test_blackhole_dev.sh
280
0755
edit
dl
rm
test_bpf.sh
225
0755
edit
dl
rm
test_vxlan_fdb_changelink.sh
678
0755
edit
dl
rm
test_vxlan_under_vrf.sh
5607
0755
edit
dl
rm
toeplitz.sh
4983
0755
edit
dl
rm
toeplitz_client.sh
667
0755
edit
dl
rm
traceroute.sh
7131
0755
edit
dl
rm
txtimestamp.sh
1702
0755
edit
dl
rm
udpgro.sh
5988
0755
edit
dl
rm
udpgro_bench.sh
2126
0755
edit
dl
rm
udpgro_fwd.sh
7145
0755
edit
dl
rm
udpgso.sh
545
0755
edit
dl
rm
udpgso_bench.sh
2852
0755
edit
dl
rm
unicast_extensions.sh
8263
0755
edit
dl
rm
veth.sh
10441
0755
edit
dl
rm
vrf-xfrm-tests.sh
10970
0755
edit
dl
rm
vrf_route_leaking.sh
14946
0755
edit
dl
rm
vrf_strict_mode_test.sh
7688
0755
edit
dl
rm
xfrm_policy.sh
14759
0755
edit
dl
rm
Edit:
/usr/src/linux-headers-5.15.0-190/tools/testing/selftests/net/vrf_strict_mode_test.sh
(7688B)
#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # This test is designed for testing the new VRF strict_mode functionality. # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 ret=0 # identifies the "init" network namespace which is often called root network # namespace. INIT_NETNS_NAME="init" PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} log_test() { local rc=$1 local expected=$2 local msg="$3" if [ ${rc} -eq ${expected} ]; then nsuccess=$((nsuccess+1)) printf "\n TEST: %-60s [ OK ]\n" "${msg}" else ret=1 nfail=$((nfail+1)) printf "\n TEST: %-60s [FAIL]\n" "${msg}" if [ "${PAUSE_ON_FAIL}" = "yes" ]; then echo echo "hit enter to continue, 'q' to quit" read a [ "$a" = "q" ] && exit 1 fi fi } print_log_test_results() { if [ "$TESTS" != "none" ]; then printf "\nTests passed: %3d\n" ${nsuccess} printf "Tests failed: %3d\n" ${nfail} fi } log_section() { echo echo "################################################################################" echo "TEST SECTION: $*" echo "################################################################################" } ip_expand_args() { local nsname=$1 local nsarg="" if [ "${nsname}" != "${INIT_NETNS_NAME}" ]; then nsarg="-netns ${nsname}" fi echo "${nsarg}" } vrf_count() { local nsname=$1 local nsarg="$(ip_expand_args ${nsname})" ip ${nsarg} -o link show type vrf | wc -l } count_vrf_by_table_id() { local nsname=$1 local tableid=$2 local nsarg="$(ip_expand_args ${nsname})" ip ${nsarg} -d -o link show type vrf | grep "table ${tableid}" | wc -l } add_vrf() { local nsname=$1 local vrfname=$2 local vrftable=$3 local nsarg="$(ip_expand_args ${nsname})" ip ${nsarg} link add ${vrfname} type vrf table ${vrftable} &>/dev/null } add_vrf_and_check() { local nsname=$1 local vrfname=$2 local vrftable=$3 local cnt local rc add_vrf ${nsname} ${vrfname} ${vrftable}; rc=$? cnt=$(count_vrf_by_table_id ${nsname} ${vrftable}) log_test ${rc} 0 "${nsname}: add vrf ${vrfname}, ${cnt} vrfs for table ${vrftable}" } add_vrf_and_check_fail() { local nsname=$1 local vrfname=$2 local vrftable=$3 local cnt local rc add_vrf ${nsname} ${vrfname} ${vrftable}; rc=$? cnt=$(count_vrf_by_table_id ${nsname} ${vrftable}) log_test ${rc} 2 "${nsname}: CANNOT add vrf ${vrfname}, ${cnt} vrfs for table ${vrftable}" } del_vrf_and_check() { local nsname=$1 local vrfname=$2 local nsarg="$(ip_expand_args ${nsname})" ip ${nsarg} link del ${vrfname} log_test $? 0 "${nsname}: remove vrf ${vrfname}" } config_vrf_and_check() { local nsname=$1 local addr=$2 local vrfname=$3 local nsarg="$(ip_expand_args ${nsname})" ip ${nsarg} link set dev ${vrfname} up && \ ip ${nsarg} addr add ${addr} dev ${vrfname} log_test $? 0 "${nsname}: vrf ${vrfname} up, addr ${addr}" } read_strict_mode() { local nsname=$1 local rval local rc=0 local nsexec="" if [ "${nsname}" != "${INIT_NETNS_NAME}" ]; then # a custom network namespace is provided nsexec="ip netns exec ${nsname}" fi rval="$(${nsexec} bash -c "cat /proc/sys/net/vrf/strict_mode" | \ grep -E "^[0-1]$")" &> /dev/null if [ $? -ne 0 ]; then # set errors rval=255 rc=1 fi # on success, rval can be only 0 or 1; on error, rval is equal to 255 echo ${rval} return ${rc} } read_strict_mode_compare_and_check() { local nsname=$1 local expected=$2 local res res="$(read_strict_mode ${nsname})" log_test ${res} ${expected} "${nsname}: check strict_mode=${res}" } set_strict_mode() { local nsname=$1 local val=$2 local nsexec="" if [ "${nsname}" != "${INIT_NETNS_NAME}" ]; then # a custom network namespace is provided nsexec="ip netns exec ${nsname}" fi ${nsexec} bash -c "echo ${val} >/proc/sys/net/vrf/strict_mode" &>/dev/null } enable_strict_mode() { local nsname=$1 set_strict_mode ${nsname} 1 } disable_strict_mode() { local nsname=$1 set_strict_mode ${nsname} 0 } disable_strict_mode_and_check() { local nsname=$1 disable_strict_mode ${nsname} log_test $? 0 "${nsname}: disable strict_mode (=0)" } enable_strict_mode_and_check() { local nsname=$1 enable_strict_mode ${nsname} log_test $? 0 "${nsname}: enable strict_mode (=1)" } enable_strict_mode_and_check_fail() { local nsname=$1 enable_strict_mode ${nsname} log_test $? 1 "${nsname}: CANNOT enable strict_mode" } strict_mode_check_default() { local nsname=$1 local strictmode local vrfcnt vrfcnt=$(vrf_count ${nsname}) strictmode=$(read_strict_mode ${nsname}) log_test ${strictmode} 0 "${nsname}: strict_mode=0 by default, ${vrfcnt} vrfs" } setup() { modprobe vrf ip netns add testns ip netns exec testns ip link set lo up } cleanup() { ip netns del testns 2>/dev/null ip link del vrf100 2>/dev/null ip link del vrf101 2>/dev/null ip link del vrf102 2>/dev/null echo 0 >/proc/sys/net/vrf/strict_mode 2>/dev/null } vrf_strict_mode_tests_init() { vrf_strict_mode_check_support init strict_mode_check_default init add_vrf_and_check init vrf100 100 config_vrf_and_check init 172.16.100.1/24 vrf100 enable_strict_mode_and_check init add_vrf_and_check_fail init vrf101 100 disable_strict_mode_and_check init add_vrf_and_check init vrf101 100 config_vrf_and_check init 172.16.101.1/24 vrf101 enable_strict_mode_and_check_fail init del_vrf_and_check init vrf101 enable_strict_mode_and_check init add_vrf_and_check init vrf102 102 config_vrf_and_check init 172.16.102.1/24 vrf102 # the strict_modle is enabled in the init } vrf_strict_mode_tests_testns() { vrf_strict_mode_check_support testns strict_mode_check_default testns enable_strict_mode_and_check testns add_vrf_and_check testns vrf100 100 config_vrf_and_check testns 10.0.100.1/24 vrf100 add_vrf_and_check_fail testns vrf101 100 add_vrf_and_check_fail testns vrf102 100 add_vrf_and_check testns vrf200 200 disable_strict_mode_and_check testns add_vrf_and_check testns vrf101 100 add_vrf_and_check testns vrf102 100 #the strict_mode is disabled in the testns } vrf_strict_mode_tests_mix() { read_strict_mode_compare_and_check init 1 read_strict_mode_compare_and_check testns 0 del_vrf_and_check testns vrf101 del_vrf_and_check testns vrf102 disable_strict_mode_and_check init enable_strict_mode_and_check testns enable_strict_mode_and_check init enable_strict_mode_and_check init disable_strict_mode_and_check testns disable_strict_mode_and_check testns read_strict_mode_compare_and_check init 1 read_strict_mode_compare_and_check testns 0 } vrf_strict_mode_tests() { log_section "VRF strict_mode test on init network namespace" vrf_strict_mode_tests_init log_section "VRF strict_mode test on testns network namespace" vrf_strict_mode_tests_testns log_section "VRF strict_mode test mixing init and testns network namespaces" vrf_strict_mode_tests_mix } vrf_strict_mode_check_support() { local nsname=$1 local output local rc output="$(lsmod | grep '^vrf' | awk '{print $1}')" if [ -z "${output}" ]; then modinfo vrf || return $? fi # we do not care about the value of the strict_mode; we only check if # the strict_mode parameter is available or not. read_strict_mode ${nsname} &>/dev/null; rc=$? log_test ${rc} 0 "${nsname}: net.vrf.strict_mode is available" return ${rc} } if [ "$(id -u)" -ne 0 ];then echo "SKIP: Need root privileges" exit $ksft_skip fi if [ ! -x "$(command -v ip)" ]; then echo "SKIP: Could not run test without ip tool" exit $ksft_skip fi modprobe vrf &>/dev/null if [ ! -e /proc/sys/net/vrf/strict_mode ]; then echo "SKIP: vrf sysctl does not exist" exit $ksft_skip fi cleanup &> /dev/null setup vrf_strict_mode_tests cleanup print_log_test_results exit $ret
Save
cmd:
run