1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4source "$(dirname $(realpath $0))/../../kselftest/ktap_helpers.sh" 5 6declare -A ip_args=( 7 [ipv4]="--ip_version=ipv4 8 --local_ip=192.168.0.1 9 --gateway_ip=192.168.0.1 10 --netmask_ip=255.255.0.0 11 --remote_ip=192.0.2.1 12 -D CMSG_LEVEL_IP=SOL_IP 13 -D CMSG_TYPE_RECVERR=IP_RECVERR" 14 [ipv6]="--ip_version=ipv6 15 --mtu=1520 16 --local_ip=fd3d:0a0b:17d6::1 17 --gateway_ip=fd3d:0a0b:17d6:8888::1 18 --remote_ip=fd3d:fa7b:d17d::1 19 -D CMSG_LEVEL_IP=SOL_IPV6 20 -D CMSG_TYPE_RECVERR=IPV6_RECVERR" 21) 22 23if [ $# -ne 1 ]; then 24 ktap_exit_fail_msg "usage: $0 <script>" 25 exit "$KSFT_FAIL" 26fi 27script="$(basename $1)" 28 29if [ -z "$(which packetdrill)" ]; then 30 ktap_skip_all "packetdrill not found in PATH" 31 exit "$KSFT_SKIP" 32fi 33 34declare -a optargs 35failfunc=ktap_test_fail 36 37if [[ -n "${KSFT_MACHINE_SLOW}" ]]; then 38 optargs+=('--tolerance_usecs=14000') 39 failfunc=ktap_test_xfail 40fi 41 42ip_versions=$(grep -E '^--ip_version=' $script | cut -d '=' -f 2) 43if [[ -z $ip_versions ]]; then 44 ip_versions="ipv4 ipv6" 45elif [[ ! "$ip_versions" =~ ^ipv[46]$ ]]; then 46 ktap_exit_fail_msg "Too many or unsupported --ip_version: $ip_versions" 47 exit "$KSFT_FAIL" 48fi 49 50ktap_print_header 51ktap_set_plan 2 52 53for ip_version in $ip_versions; do 54 unshare -n packetdrill ${ip_args[$ip_version]} ${optargs[@]} $script > /dev/null \ 55 && ktap_test_pass $ip_version || $failfunc $ip_version 56done 57 58ktap_finished 59