route6-redirect 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/sh
  2. ################################################################################
  3. ## ##
  4. ## Copyright (c) International Business Machines Corp., 2006 ##
  5. ## ##
  6. ## This program is free software; you can redistribute it and#or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation; either version 2 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, but ##
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
  13. ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
  14. ## for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program; if not, write to the Free Software ##
  18. ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
  19. ## ##
  20. ## ##
  21. ################################################################################
  22. #
  23. # File:
  24. # route6-redirect
  25. #
  26. # Description:
  27. # Verify the kernel is not crashed when the route is modified by
  28. # ICMP Redirects frequently
  29. #
  30. # Setup:
  31. # See testcases/network/stress/README
  32. #
  33. # Author:
  34. # Mitsuru Chinen <mitch@jp.ibm.com>
  35. #
  36. # History:
  37. # Apr 07 2006 - Created (Mitsuru Chinen)
  38. #
  39. #-----------------------------------------------------------------------
  40. # Uncomment line below for debug output.
  41. #trace_logic=${trace_logic:-"set -x"}
  42. $trace_logic
  43. # The test case ID, the test case count and the total number of test case
  44. TCID=route6-redirect01
  45. TST_TOTAL=1
  46. TST_COUNT=1
  47. export TCID
  48. export TST_COUNT
  49. export TST_TOTAL
  50. # Test description
  51. tst_resm TINFO "Verify the kernel is not crashed when the IPv6 route is modified by ICMP Redirects frequently"
  52. # Make sure the value of LTPROOT
  53. LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
  54. export LTPROOT
  55. # Check the environmanet variable
  56. . check_envval || exit $TST_TOTAL
  57. # The number of times where route is changed
  58. NS_TIMES=${NS_TIMES:-10000}
  59. # The number of the test link where tests run
  60. LINK_NUM=${LINK_NUM:-0}
  61. # Network portion of the IPv6 address
  62. IPV6_NETWORK="fec0:1:1:1"
  63. # Netmask of for the tested network
  64. IPV6_NETMASK_NUM=64
  65. # Host portion of the IPv6 address
  66. LHOST_IPV6_HOST=":1" # src
  67. RHOST_IPV6_HOST=":2" # gateway
  68. # The destination network
  69. DST_NETWORK="fec0:100:100:100" # destination network
  70. DST_HOST=":5"
  71. DST_PORT="7"
  72. #-----------------------------------------------------------------------
  73. #
  74. # NAME:
  75. # do_cleanup
  76. #
  77. # DESCRIPTION:
  78. # Recover the tested interfaces
  79. #
  80. #-----------------------------------------------------------------------
  81. do_cleanup()
  82. {
  83. # Kill the redirector utility
  84. $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
  85. # Initialize the interfaces
  86. initialize_if lhost ${LINK_NUM}
  87. initialize_if rhost ${LINK_NUM}
  88. }
  89. #-----------------------------------------------------------------------
  90. #
  91. # NAME:
  92. # do_setup
  93. #
  94. # DESCRIPTION:
  95. # Set the initial route and start icmp redirect on the remote host
  96. #
  97. # SET VALUES:
  98. # rhost_ipv6addr - IPv6 Address of the remote host
  99. # lhost_ifname - Interface name of the local host
  100. # rhost_ifname - Interface name of the remote host
  101. #
  102. #-----------------------------------------------------------------------
  103. do_setup()
  104. {
  105. # Make sure to cleanup the test environment
  106. do_cleanup
  107. # Get the Interface name of local host
  108. lhost_ifname=`get_ifname lhost ${LINK_NUM}`
  109. if [ $? -ne 0 ]; then
  110. tst_resm TBROK "Failed to get the interface name at the local host"
  111. exit $TST_TOTAL
  112. fi
  113. # Get the Interface name of remote host
  114. rhost_ifname=`get_ifname rhost ${LINK_NUM}`
  115. if [ $? -ne 0 ]; then
  116. tst_resm TBROK "Failed to get the interface name at the remote host"
  117. exit $TST_TOTAL
  118. fi
  119. # Remove the link-local address of the remote host
  120. sleep 5
  121. $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
  122. # Assign IPv6 address to the interface of the local host
  123. add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
  124. if [ $? -ne 0 ]; then
  125. tst_resm TBROK "Failed to assign an IPv6 address at the local host"
  126. return 1
  127. fi
  128. # Add route to the initial gateway
  129. route -A inet6 add ${DST_NETWORK}::/64 gw fe80:${RHOST_IPV6_HOST} dev $lhost_ifname
  130. # Make sure the sysctl value is set for accepting the redirect
  131. sysctl -w net.ipv6.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
  132. # Run the redirector utility at the remote host
  133. ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
  134. if [ $ret -ne 0 ]; then
  135. tst_resm TBROK "Failed to run icmp redirector at the remote host"
  136. exit $TST_TOTAL
  137. fi
  138. }
  139. #-----------------------------------------------------------------------
  140. #
  141. # FUNCTION:
  142. # test_body
  143. #
  144. # DESCRIPTION:
  145. # main code of the test
  146. #
  147. # Arguments:
  148. # None
  149. #
  150. #-----------------------------------------------------------------------
  151. test_body()
  152. {
  153. # Loop for changing the route
  154. cnt=0
  155. while [ $cnt -lt $NS_TIMES ]; do
  156. ns-udpsender -f 6 -D ${DST_NETWORK}:${DST_HOST} -p $DST_PORT -o -s 8
  157. if [ $? -ne 0 ]; then
  158. tst_resm TBROK "Failed to run udp packet sender"
  159. return 1
  160. fi
  161. cnt=`expr $cnt + 1`
  162. done
  163. tst_resm TPASS "Test is finished correctly."
  164. return 0
  165. }
  166. #-----------------------------------------------------------------------
  167. #
  168. # Main
  169. #
  170. # Exit Value:
  171. # The number of the failure
  172. #
  173. #-----------------------------------------------------------------------
  174. RC=0
  175. do_setup
  176. test_body || RC=`expr $RC + 1`
  177. do_cleanup
  178. exit $RC