~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/hsr/hsr_common.sh

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 # SPDX-License-Identifier: GPL-2.0
  2 # Common code for HSR testing scripts
  3 
  4 source ../lib.sh
  5 ret=0
  6 ksft_skip=4
  7 
  8 # $1: IP address
  9 is_v6()
 10 {
 11         [ -z "${1##*:*}" ]
 12 }
 13 
 14 do_ping()
 15 {
 16         local netns="$1"
 17         local connect_addr="$2"
 18         local ping_args="-q -c 2"
 19 
 20         if is_v6 "${connect_addr}"; then
 21                 $ipv6 || return 0
 22                 ping_args="${ping_args} -6"
 23         fi
 24 
 25         ip netns exec ${netns} ping ${ping_args} $connect_addr >/dev/null
 26         if [ $? -ne 0 ] ; then
 27                 echo "$netns -> $connect_addr connectivity [ FAIL ]" 1>&2
 28                 ret=1
 29                 return 1
 30         fi
 31 
 32         return 0
 33 }
 34 
 35 do_ping_long()
 36 {
 37         local netns="$1"
 38         local connect_addr="$2"
 39         local ping_args="-q -c 10"
 40 
 41         if is_v6 "${connect_addr}"; then
 42                 $ipv6 || return 0
 43                 ping_args="${ping_args} -6"
 44         fi
 45 
 46         OUT="$(LANG=C ip netns exec ${netns} ping ${ping_args} $connect_addr | grep received)"
 47         if [ $? -ne 0 ] ; then
 48                 echo "$netns -> $connect_addr ping [ FAIL ]" 1>&2
 49                 ret=1
 50                 return 1
 51         fi
 52 
 53         VAL="$(echo $OUT | cut -d' ' -f1-8)"
 54         SED_VAL="$(echo ${VAL} | sed -r -e 's/([0-9]{2}).*([0-9]{2}).*[[:space:]]([0-9]+%).*/\1 transmitted \2 received \3 loss/')"
 55         if [ "${SED_VAL}" != "10 transmitted 10 received 0% loss" ]
 56         then
 57                 echo "$netns -> $connect_addr ping TEST [ FAIL ]"
 58                 echo "Expect to send and receive 10 packets and no duplicates."
 59                 echo "Full message: ${OUT}."
 60                 ret=1
 61                 return 1
 62         fi
 63 
 64         return 0
 65 }
 66 
 67 stop_if_error()
 68 {
 69         local msg="$1"
 70 
 71         if [ ${ret} -ne 0 ]; then
 72                 echo "FAIL: ${msg}" 1>&2
 73                 exit ${ret}
 74         fi
 75 }
 76 
 77 check_prerequisites()
 78 {
 79         ip -Version > /dev/null 2>&1
 80         if [ $? -ne 0 ];then
 81                 echo "SKIP: Could not run test without ip tool"
 82                 exit $ksft_skip
 83         fi
 84 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php