route4-rmmod 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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-rmmod
  25. #
  26. # Description:
  27. # Verify the kernel is not crashed when IPv4 route is add then it is deleted
  28. # by the removing network driver
  29. #
  30. # Setup:
  31. # See testcases/network/stress/README
  32. #
  33. # Author:
  34. # Mitsuru Chinen <mitch@jp.ibm.com>
  35. #
  36. # History:
  37. # Apr 8 2006 - Created (Mitsuru Chinen)
  38. #
  39. #-----------------------------------------------------------------------
  40. # Uncomment line below for debug output.
  41. #trace_logic=${trace_logic:-"set -x"}
  42. $trace_logic
  43. # Make sure the value of LTPROOT
  44. LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
  45. export LTPROOT
  46. # Total number of the test case
  47. TST_TOTAL=2
  48. export TST_TOTAL
  49. # Default of the test case ID and the test case count
  50. TCID=route4-rmmod
  51. TST_COUNT=0
  52. export TCID
  53. export TST_COUNT
  54. # Check the environmanet variable
  55. . check_envval || exit $TST_TOTAL
  56. # The number of times where IPv4 route is add/delete
  57. NS_TIMES=${NS_TIMES:-10000}
  58. # The number of the test link where tests run
  59. LINK_NUM=${LINK_NUM:-0}
  60. # Network portion of the IPv4 address
  61. IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
  62. # Netmask of for the tested network
  63. IPV4_NETMASK="255.255.255.0"
  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:-"2"} # src
  69. RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"} # gateway
  70. # The destination network
  71. DST_NETWORK="10.10.10" # destination network would be 10.10.10.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. # Make sure to load the network driver
  86. if [ x${lhost_module} != x ]; then
  87. modprobe $lhost_module
  88. fi
  89. # Initialize the interfaces
  90. initialize_if lhost ${LINK_NUM}
  91. initialize_if rhost ${LINK_NUM}
  92. }
  93. #-----------------------------------------------------------------------
  94. #
  95. # NAME:
  96. # do_setup
  97. #
  98. # DESCRIPTION:
  99. # Make a IPv4 connectivity
  100. #
  101. #-----------------------------------------------------------------------
  102. do_setup()
  103. {
  104. # Check the local host has ethtool utility
  105. which ethtool >/dev/null
  106. if [ $? -ne 0 ]; then
  107. tst_resm TBROK "This test case requires ethtool utility"
  108. exit $TST_TOTAL
  109. fi
  110. # The module name of the interface at the local host
  111. lhost_module=
  112. # Make sure to clean up
  113. do_cleanup
  114. # Set IPv4 address to the interfaces of the remote host
  115. set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
  116. if [ $? -ne 0 ]; then
  117. tst_resm TBROK "Failed to add an IPv4 address the remote host"
  118. exit $TST_TOTAL
  119. fi
  120. rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
  121. # Assign IPv4 address to the interface of the local host
  122. set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
  123. if [ $? -ne 0 ]; then
  124. tst_resm TBROK "Failed to assign an IPv4 address at the local host"
  125. return 1
  126. fi
  127. lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
  128. # Get the Interface names
  129. lhost_ifname=`get_ifname lhost ${LINK_NUM}`
  130. if [ $? -ne 0 ]; then
  131. tst_resm TBROK "Failed to get the interface name at the local host"
  132. exit $TST_TOTAL
  133. fi
  134. rhost_ifname=`get_ifname rhost ${LINK_NUM}`
  135. if [ $? -ne 0 ]; then
  136. tst_resm TBROK "Failed to get the interface name at the remote host"
  137. exit $TST_TOTAL
  138. fi
  139. # Get the module name of the interface at the local host
  140. lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
  141. # Chack the other active interface uses the same driver
  142. for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do
  143. if [ $lhost_ifname = $ifname ]; then
  144. continue
  145. fi
  146. module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
  147. if [ $lhost_module = $module ]; then
  148. tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface."
  149. exit $TST_TOTAL
  150. fi
  151. done
  152. # Set the variables for destination network
  153. dst_addr=${DST_NETWORK}.${DST_HOST}
  154. dst_network=${DST_NETWORK}.0
  155. }
  156. #-----------------------------------------------------------------------
  157. #
  158. # FUNCTION:
  159. # test_body
  160. #
  161. # DESCRIPTION:
  162. # main code of the test
  163. #
  164. # Arguments:
  165. # $1: define the test type
  166. # 1 - route command case
  167. # 2 - ip command case
  168. #
  169. #-----------------------------------------------------------------------
  170. test_body()
  171. {
  172. test_type=$1
  173. TCID=route4-rmmod0${test_type}
  174. TST_COUNT=$test_type
  175. case $test_type in
  176. 1)
  177. tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
  178. ;;
  179. 2)
  180. tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
  181. ;;
  182. *)
  183. tst_resm TBROK "unspecified case"
  184. return 1
  185. ;;
  186. esac
  187. # Start the loop
  188. cnt=0
  189. while [ $cnt -lt $NS_TIMES ]; do
  190. # Check the connectivity to the gateway
  191. check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
  192. if [ $? -ne 0 ]; then
  193. tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
  194. return 1
  195. fi
  196. # Add the route
  197. case $test_type in
  198. 1)
  199. route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
  200. ;;
  201. 2)
  202. ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
  203. ;;
  204. esac
  205. if [ $? -ne 0 ]; then
  206. tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
  207. return 1
  208. fi
  209. # Load the route with UDP datagram
  210. ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
  211. if [ $? -ne 0 ]; then
  212. tst_resm TFAIL "Failed to run a UDP datagram sender"
  213. return 1
  214. fi
  215. # Remove and reload the network driver
  216. rmmod $lhost_module && modprobe $lhost_module
  217. if [ $? -ne 0 ]; then
  218. tst_resm TFAIL "Failed to unload/reload the network driver"
  219. return 1
  220. fi
  221. # Make sure to assing the IPv4 address
  222. set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1
  223. cnt=`expr $cnt + 1`
  224. done
  225. tst_resm TPASS "Test is finished correctly."
  226. return 0
  227. }
  228. #-----------------------------------------------------------------------
  229. #
  230. # Main
  231. #
  232. # Exit Value:
  233. # The number of the failure
  234. #
  235. #-----------------------------------------------------------------------
  236. RC=0
  237. do_setup
  238. test_body 1 || RC=`expr $RC + 1` # Case of route command
  239. test_body 2 || RC=`expr $RC + 1` # Case of ip command
  240. do_cleanup
  241. exit $RC