route6-rmmod 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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-rmmod
  25. #
  26. # Description:
  27. # Verify the kernel is not crashed when IPv6 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=route6-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 IPv6 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 IPv6 address
  61. IPV6_NETWORK="fec0:1:1:1"
  62. # Netmask of for the tested network
  63. IPV6_NETMASK_NUM=64
  64. # Host portion of the IPv6 address
  65. LHOST_IPV6_HOST=":2" # src
  66. RHOST_IPV6_HOST=":1" # gateway
  67. # The destination network
  68. DST_NETWORK="fec0:100:100:100" # destination network
  69. DST_HOST=":5"
  70. DST_PORT="7"
  71. #-----------------------------------------------------------------------
  72. #
  73. # NAME:
  74. # do_cleanup
  75. #
  76. # DESCRIPTION:
  77. # Recover the tested interfaces
  78. #
  79. #-----------------------------------------------------------------------
  80. do_cleanup()
  81. {
  82. # Make sure to load the network driver
  83. if [ x${lhost_module} != x ]; then
  84. modprobe $lhost_module
  85. fi
  86. # Initialize the interfaces
  87. initialize_if lhost ${LINK_NUM}
  88. initialize_if rhost ${LINK_NUM}
  89. }
  90. #-----------------------------------------------------------------------
  91. #
  92. # NAME:
  93. # do_setup
  94. #
  95. # DESCRIPTION:
  96. # Make a IPv6 connectivity
  97. #
  98. #-----------------------------------------------------------------------
  99. do_setup()
  100. {
  101. # Check the local host has ethtool utility
  102. which ethtool >/dev/null
  103. if [ $? -ne 0 ]; then
  104. tst_resm TBROK "This test case requires ethtool utility"
  105. exit $TST_TOTAL
  106. fi
  107. # The module name of the interface at the local host
  108. lhost_module=
  109. # Make sure to clean up
  110. do_cleanup
  111. # Assign IPv6 address to the interface of the local host
  112. add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
  113. if [ $? -ne 0 ]; then
  114. tst_resm TBROK "Failed to assign an IPv6 address at the local host"
  115. return 1
  116. fi
  117. lhost_ipv6addr="${IPV6_NETWORK}:${LHOST_IPV6_HOST}"
  118. # Set IPv6 address to the interfaces of the remote host
  119. add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${RHOST_IPV6_HOST}
  120. if [ $? -ne 0 ]; then
  121. tst_resm TBROK "Failed to add an IPv6 address the remote host"
  122. exit $TST_TOTAL
  123. fi
  124. rhost_ipv6addr="${IPV6_NETWORK}:${RHOST_IPV6_HOST}"
  125. # Get the Interface names
  126. lhost_ifname=`get_ifname lhost ${LINK_NUM}`
  127. if [ $? -ne 0 ]; then
  128. tst_resm TBROK "Failed to get the interface name at the local host"
  129. exit $TST_TOTAL
  130. fi
  131. rhost_ifname=`get_ifname rhost ${LINK_NUM}`
  132. if [ $? -ne 0 ]; then
  133. tst_resm TBROK "Failed to get the interface name at the remote host"
  134. exit $TST_TOTAL
  135. fi
  136. # Get the module name of the interface at the local host
  137. lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
  138. # Chack the other active interface uses the same driver
  139. for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do
  140. if [ $lhost_ifname = $ifname ]; then
  141. continue
  142. fi
  143. module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
  144. if [ $lhost_module = $module ]; then
  145. tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface."
  146. exit $TST_TOTAL
  147. fi
  148. done
  149. # Set the variables for destination network
  150. dst_addr=${DST_NETWORK}:${DST_HOST}
  151. dst_network=${DST_NETWORK}::
  152. }
  153. #-----------------------------------------------------------------------
  154. #
  155. # FUNCTION:
  156. # test_body
  157. #
  158. # DESCRIPTION:
  159. # main code of the test
  160. #
  161. # Arguments:
  162. # $1: define the test type
  163. # 1 - route command case
  164. # 2 - ip command case
  165. #
  166. #-----------------------------------------------------------------------
  167. test_body()
  168. {
  169. test_type=$1
  170. TCID=route6-rmmod0${test_type}
  171. TST_COUNT=$test_type
  172. case $test_type in
  173. 1)
  174. tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
  175. ;;
  176. 2)
  177. tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
  178. ;;
  179. *)
  180. tst_resm TBROK "unspecified case"
  181. return 1
  182. ;;
  183. esac
  184. # Start the loop
  185. cnt=0
  186. while [ $cnt -lt $NS_TIMES ]; do
  187. # Check the connectivity to the gateway
  188. check_icmpv6_connectivity $lhost_ifname $rhost_ipv6addr
  189. if [ $? -ne 0 ]; then
  190. tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
  191. return 1
  192. fi
  193. # Add the route
  194. case $test_type in
  195. 1)
  196. route -A inet6 add ${dst_network}/64 gw $rhost_ipv6addr dev $lhost_ifname
  197. ;;
  198. 2)
  199. ip -f inet6 route add ${dst_network}/64 via $rhost_ipv6addr dev $lhost_ifname
  200. ;;
  201. esac
  202. if [ $? -ne 0 ]; then
  203. tst_resm TFAIL "Failed to add the route to ${dst_network}/64"
  204. return 1
  205. fi
  206. # Load the route with UDP datagram
  207. ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -o -s 1452
  208. if [ $? -ne 0 ]; then
  209. tst_resm TFAIL "Failed to run a UDP datagram sender"
  210. return 1
  211. fi
  212. # Remove and reload the network driver
  213. rmmod $lhost_module && modprobe $lhost_module
  214. if [ $? -ne 0 ]; then
  215. tst_resm TFAIL "Failed to unload/reload the network driver"
  216. return 1
  217. fi
  218. # Make sure to assing the IPv6 address
  219. add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST} >/dev/null 2>&1
  220. cnt=`expr $cnt + 1`
  221. done
  222. tst_resm TPASS "Test is finished correctly."
  223. return 0
  224. }
  225. #-----------------------------------------------------------------------
  226. #
  227. # Main
  228. #
  229. # Exit Value:
  230. # The number of the failure
  231. #
  232. #-----------------------------------------------------------------------
  233. RC=0
  234. do_setup
  235. test_body 1 || RC=`expr $RC + 1` # Case of route command
  236. test_body 2 || RC=`expr $RC + 1` # Case of ip command
  237. do_cleanup
  238. exit $RC