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 # Make sure to clean up 129 do_cleanup 130 131 # Set IPv4 address to the interfaces of the remote host 132 set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST} 133 if [ $? -ne 0 ]; then 134 tst_resm TBROK "Failed to add an IPv4 address the remote host" 135 exit $TST_TOTAL 136 fi 137 rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}" 138 139 # Assign IPv4 address to the interface of the local host 140 set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} 141 if [ $? -ne 0 ]; then 142 tst_resm TBROK "Failed to assign an IPv4 address at the local host" 143 return 1 144 fi 145 lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}" 146 147 # Get the Interface names 148 lhost_ifname=`get_ifname lhost ${LINK_NUM}` 149 if [ $? -ne 0 ]; then 150 tst_resm TBROK "Failed to get the interface name at the local host" 151 exit $TST_TOTAL 152 fi 153 154 rhost_ifname=`get_ifname rhost ${LINK_NUM}` 155 if [ $? -ne 0 ]; then 156 tst_resm TBROK "Failed to get the interface name at the remote host" 157 exit $TST_TOTAL 158 fi 159 160 # Get the module name of the interface at the local host 161 lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"` 162 163 # Chack the other active interface uses the same driver 164 for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do 165 if [ $lhost_ifname = $ifname ]; then 166 continue 167 fi 168 169 module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"` 170 if [ $lhost_module = $module ]; then 171 tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface." 172 exit $TST_TOTAL 173 fi 174 done 175 176 # Set the variables for destination network 177 dst_addr=${DST_NETWORK}.${DST_HOST} 178 dst_network=${DST_NETWORK}.0 179} 180 181 182#----------------------------------------------------------------------- 183# 184# FUNCTION: 185# test_body 186# 187# DESCRIPTION: 188# main code of the test 189# 190# Arguments: 191# $1: define the test type 192# 1 - route command case 193# 2 - ip command case 194# 195#----------------------------------------------------------------------- 196test_body() 197{ 198 test_type=$1 199 200 TCID=route4-rmmod0${test_type} 201 TST_COUNT=$test_type 202 203 case $test_type in 204 1) 205 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" 206 ;; 207 2) 208 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" 209 ;; 210 *) 211 tst_resm TBROK "unspecified case" 212 return 1 213 ;; 214 esac 215 216 # Start the loop 217 cnt=0 218 while [ $cnt -lt $NS_TIMES ]; do 219 # Check the connectivity to the gateway 220 check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr 221 if [ $? -ne 0 ]; then 222 tst_resm TBROK "Test Link $LINK_NUM is somthing wrong." 223 return 1 224 fi 225 226 # Add the route 227 case $test_type in 228 1) 229 route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname 230 ;; 231 2) 232 ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname 233 ;; 234 esac 235 if [ $? -ne 0 ]; then 236 tst_resm TFAIL "Failed to add the route to ${dst_network}/24" 237 return 1 238 fi 239 240 # Load the route with UDP datagram 241 ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472 242 if [ $? -ne 0 ]; then 243 tst_resm TFAIL "Failed to run a UDP datagram sender" 244 return 1 245 fi 246 247 # Remove and reload the network driver 248 rmmod $lhost_module && modprobe $lhost_module 249 if [ $? -ne 0 ]; then 250 tst_resm TFAIL "Failed to unload/reload the network driver" 251 return 1 252 fi 253 254 # Make sure to assing the IPv4 address 255 set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1 256 257 cnt=`expr $cnt + 1` 258 done 259 260 tst_resm TPASS "Test is finished correctly." 261 return 0 262} 263 264 265#----------------------------------------------------------------------- 266# 267# Main 268# 269# Exit Value: 270# The number of the failure 271# 272#----------------------------------------------------------------------- 273 274RC=0 275do_setup 276test_body 1 || RC=`expr $RC + 1` # Case of route command 277test_body 2 || RC=`expr $RC + 1` # Case of ip command 278do_cleanup 279 280exit $RC 281