route4-redirect 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. # route4-redirect
  25. #
  26. # Description:
  27. # Verify the kernel is not crashed when the IPv4 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=route4-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 IPv4 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 IPv4 address
  62. IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
  63. # Netmask of for the tested network
  64. IPV4_NETMASK_NUM=24
  65. # Broadcast address of the tested network
  66. IPV4_BROADCAST=${IPV4_NETWORK}.255
  67. # Host portion of the IPv4 address
  68. LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"} # src
  69. RHOST_IPV4_HOST="2" # gateway
  70. # The destination network
  71. DST_NETWORK="10.10.0" # destination network would be 10.10.0.0/24
  72. DST_HOST="5"
  73. DST_PORT="7"
  74. #-----------------------------------------------------------------------
  75. #
  76. # NAME:
  77. # do_cleanup
  78. #
  79. # DESCRIPTION:
  80. # Recover the tested interfaces
  81. #
  82. #-----------------------------------------------------------------------
  83. do_cleanup()
  84. {
  85. # Kill the redirector utility
  86. $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
  87. # Initialize the interfaces
  88. initialize_if lhost ${LINK_NUM}
  89. initialize_if rhost ${LINK_NUM}
  90. }
  91. #-----------------------------------------------------------------------
  92. #
  93. # NAME:
  94. # do_setup
  95. #
  96. # DESCRIPTION:
  97. # Set the initial route and start icmp redirect on the remote host
  98. #
  99. # SET VALUES:
  100. # rhost_ipv4addr - IPv4 Address of the remote host
  101. # lhost_ifname - Interface name of the local host
  102. # rhost_ifname - Interface name of the remote host
  103. #
  104. #-----------------------------------------------------------------------
  105. do_setup()
  106. {
  107. # Make sure to clean up
  108. do_cleanup
  109. # Get the Interface name of local host
  110. lhost_ifname=`get_ifname lhost ${LINK_NUM}`
  111. if [ $? -ne 0 ]; then
  112. tst_resm TBROK "Failed to get the interface name at the local host"
  113. exit $TST_TOTAL
  114. fi
  115. # Get the Interface name of remote host
  116. rhost_ifname=`get_ifname rhost ${LINK_NUM}`
  117. if [ $? -ne 0 ]; then
  118. tst_resm TBROK "Failed to get the interface name at the remote host"
  119. exit $TST_TOTAL
  120. fi
  121. # Remove the link-local address of the remote host
  122. sleep 3
  123. $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
  124. # Assign IPv4 address to the interface of the local host
  125. set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
  126. if [ $? -ne 0 ]; then
  127. tst_resm TBROK "Failed to assign an IPv4 address at the local host"
  128. return 1
  129. fi
  130. # Add route to the initial gateway
  131. route add -net ${DST_NETWORK}.0 netmask 255.255.255.0 gw ${IPV4_NETWORK}.${RHOST_IPV4_HOST} dev $lhost_ifname
  132. # Make sure the sysctl value is set for accepting the redirect
  133. sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
  134. sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null
  135. # Run the redirector utility at the remote host
  136. ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
  137. if [ $ret -ne 0 ]; then
  138. tst_resm TBROK "Failed to run icmp redirector at the remote host"
  139. exit $TST_TOTAL
  140. fi
  141. }
  142. #-----------------------------------------------------------------------
  143. #
  144. # FUNCTION:
  145. # test_body
  146. #
  147. # DESCRIPTION:
  148. # main code of the test
  149. #
  150. # Arguments:
  151. # None
  152. #
  153. #-----------------------------------------------------------------------
  154. test_body()
  155. {
  156. # Loop for changing the route
  157. cnt=0
  158. while [ $cnt -lt $NS_TIMES ]; do
  159. ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
  160. if [ $? -ne 0 ]; then
  161. tst_resm TBROK "Failed to run udp packet sender"
  162. return 1
  163. fi
  164. cnt=`expr $cnt + 1`
  165. done
  166. tst_resm TPASS "Test is finished correctly."
  167. return 0
  168. }
  169. #-----------------------------------------------------------------------
  170. #
  171. # Main
  172. #
  173. # Exit Value:
  174. # The number of the failure
  175. #
  176. #-----------------------------------------------------------------------
  177. RC=0
  178. do_setup
  179. test_body || RC=`expr $RC + 1`
  180. do_cleanup
  181. exit $RC