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