aboutsummaryrefslogtreecommitdiff
path: root/testcases/network/stress/route/route4-redirect
blob: 53df9abf2da99fd0076b1dd06dc3748379e2e9ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/sh

################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2006                 ##
##                                                                            ##
## This program is free software;  you can redistribute it and#or modify      ##
## it under the terms of the GNU General Public License as published by       ##
## the Free Software Foundation; either version 2 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program is distributed in the hope that it will be useful, but        ##
## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
## for more details.                                                          ##
##                                                                            ##
## You should have received a copy of the GNU General Public License          ##
## along with this program;  if not, write to the Free Software               ##
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
##                                                                            ##
##                                                                            ##
################################################################################
#
# File:
#   route4-redirect
#
# Description:
#   Verify the kernel is not crashed when the IPv4 route is modified by
#   ICMP Redirects frequently
#
# Setup:
#   See testcases/network/stress/README
#
# Author:
#   Mitsuru Chinen <mitch@jp.ibm.com>
#
# History:
#	Apr 07 2006 - Created (Mitsuru Chinen)
#
#-----------------------------------------------------------------------
# Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

# The test case ID, the test case count and the total number of test case
TCID=route4-redirect01
TST_TOTAL=1
TST_COUNT=1
export TCID
export TST_COUNT
export TST_TOTAL

# Test description
tst_resm TINFO "Verify the kernel is not crashed when the IPv4 route is modified by  ICMP Redirects frequently"

# Make sure the value of LTPROOT
LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
export LTPROOT

# Check the environmanet variable
. check_envval || exit $TST_TOTAL

# The number of times where route is changed
NS_TIMES=${NS_TIMES:-10000}

# The number of the test link where tests run
LINK_NUM=${LINK_NUM:-0}

# Network portion of the IPv4 address
IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}

# Netmask of for the tested network
IPV4_NETMASK_NUM=24

# Broadcast address of the tested network
IPV4_BROADCAST=${IPV4_NETWORK}.255

# Host portion of the IPv4 address
LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"1"}	# src
RHOST_IPV4_HOST="2"	# gateway

# The destination network
DST_NETWORK="10.10.0"   # destination network would be 10.10.0.0/24
DST_HOST="5"
DST_PORT="7"


#-----------------------------------------------------------------------
#
# NAME:
#   do_cleanup
#
# DESCRIPTION:
#   Recover the tested interfaces
#
#-----------------------------------------------------------------------
do_cleanup()
{
    # Kill the redirector utility
    $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1

    # Initialize the interfaces
    initialize_if lhost ${LINK_NUM}
    initialize_if rhost ${LINK_NUM}
}


#-----------------------------------------------------------------------
#
# NAME:
#   do_setup
#
# DESCRIPTION:
#   Set the initial route and start icmp redirect on the remote host
#
# SET VALUES:
#   rhost_ipv4addr      - IPv4 Address of the remote host
#   lhost_ifname        - Interface name of the local host
#   rhost_ifname        - Interface name of the remote host
#
#-----------------------------------------------------------------------
do_setup()
{
    # Make sure to clean up
    do_cleanup

    # Get the Interface name of local host
    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to get the interface name at the local host"
	exit $TST_TOTAL
    fi

    # Get the Interface name of remote host
    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to get the interface name at the remote host"
	exit $TST_TOTAL
    fi

    # Remove the link-local address of the remote host
    sleep 3
    $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null

    # Assign IPv4 address to the interface of the local host
    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
    if [ $? -ne 0 ]; then
	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
	return 1
    fi

    # Add route to the initial gateway
    route add -net ${DST_NETWORK}.0 netmask 255.255.255.0 gw ${IPV4_NETWORK}.${RHOST_IPV4_HOST} dev $lhost_ifname

    # Make sure the sysctl value is set for accepting the redirect
    sysctl -w net.ipv4.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
    sysctl -w net.ipv4.conf.${lhost_ifname}.secure_redirects=0 >/dev/null

    # Run the redirector utility at the remote host
    ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
    if [ $ret -ne 0 ]; then
	tst_resm TBROK "Failed to run icmp redirector at the remote host"
	exit $TST_TOTAL
    fi
}



#-----------------------------------------------------------------------
#
# FUNCTION:
#   test_body
#
# DESCRIPTION:
#   main code of the test
#
# Arguments:
#   None
#
#-----------------------------------------------------------------------
test_body()
{
    # Loop for changing the route
    cnt=0
    while [ $cnt -lt $NS_TIMES ]; do
	ns-udpsender -f 4 -D ${DST_NETWORK}.${DST_HOST} -p $DST_PORT -o -s 8
	if [ $? -ne 0 ]; then
	    tst_resm TBROK "Failed to run udp packet sender"
	    return 1
	fi
	cnt=`expr $cnt + 1`
    done

    tst_resm TPASS "Test is finished correctly."
    return 0
}


#-----------------------------------------------------------------------
#
# Main
#
# Exit Value:
#   The number of the failure
#
#-----------------------------------------------------------------------
RC=0
do_setup
test_body || RC=`expr $RC + 1`
do_cleanup

exit $RC