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