if-addr-adddel.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
  4. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  5. # Copyright (c) International Business Machines Corp., 2005
  6. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  7. IF_CMD='ifconfig'
  8. . if-lib.sh
  9. # The interval of the check interface activity
  10. CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
  11. test_body()
  12. {
  13. local cmd="$CMD"
  14. local num=$(($(od -A n -t u1 -N 1 /dev/random) * 253 / 255 + 2 ))
  15. local iface=$(tst_iface)
  16. if [ "$TST_IPV6" ]; then
  17. local new_ip=${IPV6_NET32_UNUSED}::$num
  18. local netmask=64
  19. else
  20. local new_ip=${IPV4_NET16_UNUSED}.1.$num
  21. local netmask=24
  22. fi
  23. tst_res TINFO "'$cmd' add/del IPv$TST_IPVER '$new_ip' $NS_TIMES times"
  24. if ! restore_ipaddr; then
  25. tst_res TBROK "Failed to set default IP addresses"
  26. return
  27. fi
  28. local cnt=1
  29. while [ $cnt -le $NS_TIMES ]; do
  30. make_background_tcp_traffic
  31. case $cmd in
  32. ifconfig)
  33. if [ "$TST_IPV6" ]; then
  34. ifconfig $iface add $new_ip/$netmask
  35. else
  36. ifconfig $iface:1 $new_ip netmask 255.255.255.0
  37. fi
  38. ;;
  39. ip) ip addr add $new_ip/$netmask dev $iface ;;
  40. esac
  41. if [ $? -ne 0 ]; then
  42. tst_res TFAIL "command failed to add $new_ip to $iface"
  43. return
  44. fi
  45. ip addr show $iface | grep -q $new_ip
  46. if [ $? -ne 0 ]; then
  47. ip addr show $iface
  48. tst_res TFAIL "$new_ip not configured"
  49. return
  50. fi
  51. check_connectivity_interval $cnt || return
  52. cnt=$(($cnt + 1))
  53. case $cmd in
  54. ifconfig)
  55. if [ "$TST_IPV6" ]; then
  56. ifconfig $iface del $new_ip/$netmask
  57. else
  58. ifconfig $iface:1 down
  59. fi
  60. ;;
  61. ip) ip addr del $new_ip/$netmask dev $iface ;;
  62. esac
  63. if [ $? -ne 0 ]; then
  64. tst_res TFAIL " delete command failed".
  65. return
  66. fi
  67. ip addr show $iface | grep -q $new_ip
  68. if [ $? -eq 0 ]; then
  69. ip addr show $iface
  70. tst_res TFAIL "Failed to remove '$new_ip' address"
  71. return
  72. fi
  73. done
  74. tst_res TPASS "Test is finished correctly"
  75. }
  76. tst_run