11.3Srin# $NetBSD: t_capabilities.sh,v 1.3 2023/10/18 08:52:46 rin Exp $ 21.1Sjruoho# 31.1Sjruoho# Copyright (c) 2020 The NetBSD Foundation, Inc. 41.1Sjruoho# All rights reserved. 51.1Sjruoho# 61.1Sjruoho# This code is derived from software contributed to The NetBSD Foundation 71.1Sjruoho# by Jukka Ruohonen. 81.1Sjruoho# 91.1Sjruoho# Redistribution and use in source and binary forms, with or without 101.1Sjruoho# modification, are permitted provided that the following conditions 111.1Sjruoho# are met: 121.1Sjruoho# 1. Redistributions of source code must retain the above copyright 131.1Sjruoho# notice, this list of conditions and the following disclaimer. 141.1Sjruoho# 2. Redistributions in binary form must reproduce the above copyright 151.1Sjruoho# notice, this list of conditions and the following disclaimer in the 161.1Sjruoho# documentation and/or other materials provided with the distribution. 171.1Sjruoho# 181.1Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 191.1Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 201.1Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 211.1Sjruoho# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 221.1Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 231.1Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 241.1Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 251.1Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 261.1Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 271.1Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 281.1Sjruoho# POSSIBILITY OF SUCH DAMAGE. 291.1Sjruoho# 301.1Sjruohosetcap() { 311.1Sjruoho 321.1Sjruoho echo "Request: $1 $2 ($3)" 331.1Sjruoho ifconfig $1 $2 341.1Sjruoho 351.1Sjruoho if [ $4 -eq 1 ]; then 361.1Sjruoho 371.1Sjruoho if [ ! $? -eq 0 ]; then 381.1Sjruoho atf_fail "Failed to enable $3 for $1" 391.1Sjruoho fi 401.1Sjruoho 411.1Sjruoho if [ -z "$(ifconfig $1 | grep "enabled" | grep $3)" ]; then 421.1Sjruoho atf_fail "Failed to enable $3 for $1" 431.1Sjruoho fi 441.1Sjruoho 451.1Sjruoho echo "Request: $1 -$2 (-$3)" 461.1Sjruoho ifconfig $1 -$2 471.1Sjruoho 481.1Sjruoho if [ ! $? -eq 0 ]; then 491.1Sjruoho atf_fail "Failed to disable $3 for $1" 501.1Sjruoho fi 511.1Sjruoho 521.1Sjruoho if [ ! -z "$(ifconfig $1 | grep "enabled" | grep $3)" ]; then 531.1Sjruoho atf_fail "Failed to disable $3 for $1" 541.1Sjruoho fi 551.1Sjruoho fi 561.1Sjruoho} 571.1Sjruoho 581.1Sjruohoparsecap() { 591.1Sjruoho 601.1Sjruoho i=$1 611.1Sjruoho checkrv=$3 621.1Sjruoho x=$(echo $2 | sed "s/.*<//" | sed "s/>//") 631.1Sjruoho 641.1Sjruoho export IFS="," 651.1Sjruoho 661.1Sjruoho for y in $x; do 671.1Sjruoho 681.1Sjruoho z="" 691.1Sjruoho 701.1Sjruoho if [ $y = "TSO4" ]; then 711.1Sjruoho z="tso4" 721.1Sjruoho elif [ $y = "IP4CSUM_Rx" ]; then 731.1Sjruoho z="ip4csum-rx" 741.1Sjruoho elif [ $y = "IP4CSUM_Tx" ]; then 751.1Sjruoho z="ip4csum-tx" 761.1Sjruoho elif [ $y = "TCP4CSUM_Rx" ]; then 771.1Sjruoho z="tcp4csum-rx" 781.1Sjruoho elif [ $y = "TCP4CSUM_Tx" ]; then 791.1Sjruoho z="tcp4csum-tx" 801.1Sjruoho elif [ $y = "UDP4CSUM_Rx" ]; then 811.1Sjruoho z="udp4csum-rx" 821.1Sjruoho elif [ $y = "UDP4CSUM_Tx" ]; then 831.1Sjruoho z="udp4csum-tx" 841.1Sjruoho elif [ $y = "TCP6CSUM_Rx" ]; then 851.1Sjruoho z="tcp6csum-rx" 861.1Sjruoho elif [ $y = "TCP6CSUM_Tx" ]; then 871.1Sjruoho z="tcp6csum-tx" 881.1Sjruoho elif [ $y = "UDP6CSUM_Rx" ]; then 891.1Sjruoho z="udp6csum-rx" 901.1Sjruoho elif [ $y = "UDP6CSUM_Tx" ]; then 911.1Sjruoho z="udp6csum-tx" 921.1Sjruoho elif [ $y = "TSO6" ]; then 931.1Sjruoho z="tso6" 941.1Sjruoho fi 951.1Sjruoho 961.1Sjruoho if [ -z $z ]; then 971.1Sjruoho echo "Skipping unrecognized $y for $i" 981.1Sjruoho else 991.1Sjruoho setcap $i $z $y $checkrv 1001.1Sjruoho fi 1011.1Sjruoho done 1021.1Sjruoho 1031.1Sjruoho unset IFS 1041.1Sjruoho} 1051.1Sjruoho 1061.1Sjruohoatf_test_case basic 1071.1Sjruohobasic_head() { 1081.1Sjruoho atf_set "require.user" "root" 1091.1Sjruoho atf_set "descr" "Test setting interface capabilities" 1101.1Sjruoho} 1111.1Sjruoho 1121.1Sjruohobasic_body() { 1131.1Sjruoho 1141.2Srin if ! [ $(atf_config_get "run_unsafe" "no") = "yes" ]; then 1151.3Srin atf_skip "modify if_capenable for real interfaces" 1161.2Srin fi 1171.2Srin 1181.1Sjruoho for i in $(ifconfig -l); do 1191.1Sjruoho 1201.1Sjruoho c=$(ifconfig $i | grep "capabilities") 1211.1Sjruoho 1221.1Sjruoho if [ -z "$c" ]; then 1231.1Sjruoho echo "Skipping $i, no capabilities" 1241.1Sjruoho continue 1251.1Sjruoho fi 1261.1Sjruoho 1271.1Sjruoho if [ ! -z "$(echo $i | grep ixg)" ]; then 1281.1Sjruoho echo "Skipping $i (PR kern/50933)" 1291.1Sjruoho continue 1301.1Sjruoho fi 1311.1Sjruoho 1321.1Sjruoho enabled=$(ifconfig $i | grep "enabled") 1331.1Sjruoho 1341.1Sjruoho for l in $c; do 1351.1Sjruoho 1361.1Sjruoho if [ ! -z "$(echo $l | grep "ec_capabilities")" ]; then 1371.1Sjruoho continue 1381.1Sjruoho fi 1391.1Sjruoho 1401.1Sjruoho parsecap $i $l 1 1411.1Sjruoho done 1421.1Sjruoho 1431.1Sjruoho if [ ! -z "$enabled" ]; then 1441.1Sjruoho 1451.1Sjruoho echo "Restoring capabilities for $i" 1461.1Sjruoho 1471.1Sjruoho for l in $enabled; do 1481.1Sjruoho 1491.1Sjruoho ec=$(echo $l | grep "ec_enabled") 1501.1Sjruoho 1511.1Sjruoho if [ ! -z "$ec" ]; then 1521.1Sjruoho continue 1531.1Sjruoho fi 1541.1Sjruoho 1551.1Sjruoho parsecap $i $l 0 1561.1Sjruoho done 1571.1Sjruoho fi 1581.1Sjruoho done 1591.1Sjruoho} 1601.1Sjruoho 1611.1Sjruohoatf_init_test_cases() { 1621.1Sjruoho atf_add_test_case basic 1631.1Sjruoho} 164