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