if4-addr-change.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
  4. # Copyright (c) 2015-2016 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. TST_CLEANUP="do_cleanup"
  8. TST_TESTFUNC="test_body"
  9. TST_NEEDS_CMDS="ifconfig"
  10. . tst_net.sh
  11. CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
  12. # Maximum host portion of the IPv4 address on the local host
  13. LHOST_IPV4_HOST_MAX="254"
  14. do_cleanup()
  15. {
  16. tst_restore_ipaddr
  17. tst_wait_ipv6_dad
  18. }
  19. test_body()
  20. {
  21. local cnt=0
  22. local num=1
  23. local add_to_net
  24. tst_res TINFO "ifconfig changes IPv4 address $NS_TIMES times"
  25. while [ $cnt -lt $NS_TIMES ]; do
  26. # Define the network portion
  27. num=$(($num + 1))
  28. [ $num -gt $LHOST_IPV4_HOST_MAX ] && num=1
  29. [ $num -eq $RHOST_IPV4_HOST ] && continue
  30. # check prefix and fix values for prefix != 24
  31. add_to_net=
  32. if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
  33. tst_brk TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
  34. elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
  35. add_to_net=".0.1"
  36. elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
  37. add_to_net=".1"
  38. fi
  39. # Change IPv4 address
  40. ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
  41. $IPV4_LNETMASK broadcast $IPV4_LBROADCAST
  42. cnt=$(($cnt + 1))
  43. [ $CHECK_INTERVAL -eq 0 ] && continue
  44. [ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
  45. tst_res TINFO "ping $(tst_ipaddr):$(tst_ipaddr rhost) ${cnt}/$NS_TIMES"
  46. tst_ping
  47. done
  48. tst_ping
  49. }
  50. tst_run