if-addr-addlarge.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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:-$(($IP_TOTAL / 20))}
  11. test_body()
  12. {
  13. local cmd="$CMD"
  14. local iface=$(tst_iface)
  15. [ "$TST_IPV6" ] && local netmask=64 || local netmask=16
  16. tst_res TINFO "'$cmd' add $IP_TOTAL IPv$TST_IPVER addresses"
  17. tst_res TINFO "check interval that $iface is working: $CHECK_INTERVAL"
  18. if ! restore_ipaddr; then
  19. tst_res TBROK "Failed to set default IP addresses"
  20. return
  21. fi
  22. local x=1
  23. local y=1
  24. local cnt=1
  25. [ "$TST_IPV6" ] && local xymax=65535 || xymax=254
  26. if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then
  27. tst_res TWARN "set IP_TOTAL to $xymax * $xymax"
  28. IP_TOTAL=$((xymax * xymax))
  29. fi
  30. while [ $cnt -le $IP_TOTAL ]; do
  31. make_background_tcp_traffic
  32. if [ "$TST_IPV6" ]; then
  33. local hex_x=$(printf '%x' $x)
  34. local hex_y=$(printf '%x' $y)
  35. local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1
  36. else
  37. local new_ip=${IPV4_NET16_UNUSED}.$x.$y
  38. fi
  39. case $cmd in
  40. ifconfig)
  41. if [ "$TST_IPV6" ]; then
  42. ifconfig $iface add $new_ip/$netmask
  43. else
  44. ifconfig $iface:$x:$y $new_ip netmask 255.255.0.0
  45. fi
  46. ;;
  47. ip) ip addr add $new_ip/$netmask dev $iface ;;
  48. esac
  49. if [ $? -ne 0 ]; then
  50. tst_res TFAIL "command failed to add $new_ip to $iface"
  51. return
  52. fi
  53. ip addr show $iface | grep -q $new_ip
  54. if [ $? -ne 0 ]; then
  55. ip addr show $iface
  56. tst_res TFAIL "$new_ip not configured"
  57. return
  58. fi
  59. check_connectivity_interval $cnt || return
  60. case $cmd in
  61. ifconfig)
  62. if [ "$TST_IPV6" ]; then
  63. ifconfig $iface del $new_ip/$netmask
  64. else
  65. ifconfig $iface:$x:$y down
  66. fi
  67. ;;
  68. ip) ip addr del $new_ip/$netmask dev $iface ;;
  69. esac
  70. if [ $? -ne 0 ]; then
  71. tst_res TFAIL " delete command failed".
  72. return
  73. fi
  74. ip addr show $iface | grep -q $new_ip
  75. if [ $? -eq 0 ]; then
  76. ip addr show $iface
  77. tst_res TFAIL "Failed to remove '$new_ip' address"
  78. return
  79. fi
  80. cnt=$(($cnt + 1))
  81. y=$(($y + 1))
  82. if [ $y -gt $xymax ]; then
  83. y=1
  84. x=$(($x + 1))
  85. if [ $x -gt $xymax ]; then
  86. tst_brk TBROK "Too large $IP_TOTAL"
  87. fi
  88. fi
  89. done
  90. tst_res TPASS "Test is finished correctly"
  91. }
  92. tst_run