selftests/net: packetdrill: Support single protocol test.

Currently, we cannot write IPv4 or IPv6 specific packetdrill tests
as ksft_runner.sh runs each .pkt file for both protocols.

Let's support single protocol test by checking --ip_version in the
.pkt file.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250819231527.1427361-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
pull/1354/merge
Kuniyuki Iwashima 2025-08-19 23:14:57 +00:00 committed by Jakub Kicinski
parent a6d4f25888
commit a5c10aa3d1
1 changed files with 28 additions and 19 deletions

View File

@ -3,21 +3,22 @@
source "$(dirname $(realpath $0))/../../kselftest/ktap_helpers.sh" source "$(dirname $(realpath $0))/../../kselftest/ktap_helpers.sh"
readonly ipv4_args=('--ip_version=ipv4 ' declare -A ip_args=(
'--local_ip=192.168.0.1 ' [ipv4]="--ip_version=ipv4
'--gateway_ip=192.168.0.1 ' --local_ip=192.168.0.1
'--netmask_ip=255.255.0.0 ' --gateway_ip=192.168.0.1
'--remote_ip=192.0.2.1 ' --netmask_ip=255.255.0.0
'-D CMSG_LEVEL_IP=SOL_IP ' --remote_ip=192.0.2.1
'-D CMSG_TYPE_RECVERR=IP_RECVERR ') -D CMSG_LEVEL_IP=SOL_IP
-D CMSG_TYPE_RECVERR=IP_RECVERR"
readonly ipv6_args=('--ip_version=ipv6 ' [ipv6]="--ip_version=ipv6
'--mtu=1520 ' --mtu=1520
'--local_ip=fd3d:0a0b:17d6::1 ' --local_ip=fd3d:0a0b:17d6::1
'--gateway_ip=fd3d:0a0b:17d6:8888::1 ' --gateway_ip=fd3d:0a0b:17d6:8888::1
'--remote_ip=fd3d:fa7b:d17d::1 ' --remote_ip=fd3d:fa7b:d17d::1
'-D CMSG_LEVEL_IP=SOL_IPV6 ' -D CMSG_LEVEL_IP=SOL_IPV6
'-D CMSG_TYPE_RECVERR=IPV6_RECVERR ') -D CMSG_TYPE_RECVERR=IPV6_RECVERR"
)
if [ $# -ne 1 ]; then if [ $# -ne 1 ]; then
ktap_exit_fail_msg "usage: $0 <script>" ktap_exit_fail_msg "usage: $0 <script>"
@ -38,12 +39,20 @@ if [[ -n "${KSFT_MACHINE_SLOW}" ]]; then
failfunc=ktap_test_xfail failfunc=ktap_test_xfail
fi fi
ip_versions=$(grep -E '^--ip_version=' $script | cut -d '=' -f 2)
if [[ -z $ip_versions ]]; then
ip_versions="ipv4 ipv6"
elif [[ ! "$ip_versions" =~ ^ipv[46]$ ]]; then
ktap_exit_fail_msg "Too many or unsupported --ip_version: $ip_versions"
exit "$KSFT_FAIL"
fi
ktap_print_header ktap_print_header
ktap_set_plan 2 ktap_set_plan 2
unshare -n packetdrill ${ipv4_args[@]} ${optargs[@]} $script > /dev/null \ for ip_version in $ip_versions; do
&& ktap_test_pass "ipv4" || $failfunc "ipv4" unshare -n packetdrill ${ip_args[$ip_version]} ${optargs[@]} $script > /dev/null \
unshare -n packetdrill ${ipv6_args[@]} ${optargs[@]} $script > /dev/null \ && ktap_test_pass $ip_version || $failfunc $ip_version
&& ktap_test_pass "ipv6" || $failfunc "ipv6" done
ktap_finished ktap_finished