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