Home | History | Annotate | Download | only in route
      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-redirect
     26 #
     27 # Description:
     28 #   Verify the kernel is not crashed when the route is modified by
     29 #   ICMP Redirects frequently
     30 #
     31 # Setup:
     32 #   See ltp-yyyymmdd/testcases/network/stress/README
     33 #
     34 # Author:
     35 #   Mitsuru Chinen <mitch (at] jp.ibm.com>
     36 #
     37 # History:
     38 #	Apr 07 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 # The test case ID, the test case count and the total number of test case
     46 TCID=route6-redirect01
     47 TST_TOTAL=1
     48 TST_COUNT=1
     49 export TCID
     50 export TST_COUNT
     51 export TST_TOTAL
     52 
     53 # Test description
     54 tst_resm TINFO "Verify the kernel is not crashed when the IPv6 route is modified by  ICMP Redirects frequently"
     55 
     56 # Make sure the value of LTPROOT
     57 LTPROOT=${LTPROOT:-`(cd ../../../.. ; pwd)`}
     58 export LTPROOT
     59 
     60 # Check the environmanet variable
     61 . check_envval || exit $TST_TOTAL
     62 
     63 # The number of times where route is changed
     64 NS_TIMES=${NS_TIMES:-10000}
     65 
     66 # The number of the test link where tests run
     67 LINK_NUM=${LINK_NUM:-0}
     68 
     69 # Network portion of the IPv6 address
     70 IPV6_NETWORK="fec0:1:1:1"
     71 
     72 # Netmask of for the tested network
     73 IPV6_NETMASK_NUM=64
     74 
     75 # Host portion of the IPv6 address
     76 LHOST_IPV6_HOST=":1"	# src
     77 RHOST_IPV6_HOST=":2"	# gateway
     78 
     79 # The destination network
     80 DST_NETWORK="fec0:100:100:100"   # destination network
     81 DST_HOST=":5"
     82 DST_PORT="7"
     83 
     84 
     85 #-----------------------------------------------------------------------
     86 #
     87 # NAME:
     88 #   do_cleanup
     89 #
     90 # DESCRIPTION:
     91 #   Recover the tested interfaces
     92 #
     93 #-----------------------------------------------------------------------
     94 do_cleanup()
     95 {
     96     # Kill the redirector utility
     97     $LTP_RSH $RHOST killall -SIGHUP ns-icmp_redirector >/dev/null 2>&1
     98 
     99     # Initialize the interfaces
    100     initialize_if lhost ${LINK_NUM}
    101     initialize_if rhost ${LINK_NUM}
    102 }
    103 
    104 
    105 #-----------------------------------------------------------------------
    106 #
    107 # NAME:
    108 #   do_setup
    109 #
    110 # DESCRIPTION:
    111 #   Set the initial route and start icmp redirect on the remote host
    112 #
    113 # SET VALUES:
    114 #   rhost_ipv6addr      - IPv6 Address of the remote host
    115 #   lhost_ifname        - Interface name of the local host
    116 #   rhost_ifname        - Interface name of the remote host
    117 #
    118 #-----------------------------------------------------------------------
    119 do_setup()
    120 {
    121     # Make sure to cleanup the test environment
    122     do_cleanup
    123 
    124     # Get the Interface name of local host
    125     lhost_ifname=`get_ifname lhost ${LINK_NUM}`
    126     if [ $? -ne 0 ]; then
    127 	tst_resm TBROK "Failed to get the interface name at the local host"
    128 	exit $TST_TOTAL
    129     fi
    130 
    131     # Get the Interface name of remote host
    132     rhost_ifname=`get_ifname rhost ${LINK_NUM}`
    133     if [ $? -ne 0 ]; then
    134 	tst_resm TBROK "Failed to get the interface name at the remote host"
    135 	exit $TST_TOTAL
    136     fi
    137 
    138     # Remove the link-local address of the remote host
    139     sleep 5
    140     $LTP_RSH $RHOST "ip addr flush dev $rhost_ifname" > /dev/null
    141 
    142     # Assign IPv6 address to the interface of the local host
    143     add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
    144     if [ $? -ne 0 ]; then
    145 	tst_resm TBROK "Failed to assign an IPv6 address at the local host"
    146 	return 1
    147     fi
    148 
    149     # Add route to the initial gateway
    150     route -A inet6 add ${DST_NETWORK}::/64 gw fe80:${RHOST_IPV6_HOST} dev $lhost_ifname
    151 
    152     # Make sure the sysctl value is set for accepting the redirect
    153     sysctl -w net.ipv6.conf.${lhost_ifname}.accept_redirects=1 >/dev/null
    154 
    155     # Run the redirector utility at the remote host
    156     ret=`$LTP_RSH $RHOST "${LTPROOT}/testcases/bin/ns-icmp_redirector -I $rhost_ifname -b ; "'echo $?'`
    157     if [ $ret -ne 0 ]; then
    158 	tst_resm TBROK "Failed to run icmp redirector at the remote host"
    159 	exit $TST_TOTAL
    160     fi
    161 }
    162 
    163 
    164 #-----------------------------------------------------------------------
    165 #
    166 # FUNCTION:
    167 #   test_body
    168 #
    169 # DESCRIPTION:
    170 #   main code of the test
    171 #
    172 # Arguments:
    173 #   None
    174 #
    175 #-----------------------------------------------------------------------
    176 test_body()
    177 {
    178     # Loop for changing the route
    179     cnt=0
    180     while [ $cnt -lt $NS_TIMES ]; do
    181 	ns-udpsender -f 6 -D ${DST_NETWORK}:${DST_HOST} -p $DST_PORT -o -s 8
    182 	if [ $? -ne 0 ]; then
    183 	    tst_resm TBROK "Failed to run udp packet sender"
    184 	    return 1
    185 	fi
    186 	cnt=`expr $cnt + 1`
    187     done
    188 
    189     tst_resm TPASS "Test is finished correctly."
    190     return 0
    191 }
    192 
    193 
    194 #-----------------------------------------------------------------------
    195 #
    196 # Main
    197 #
    198 # Exit Value:
    199 #   The number of the failure
    200 #
    201 #-----------------------------------------------------------------------
    202 RC=0
    203 do_setup
    204 test_body || RC=`expr $RC + 1`
    205 do_cleanup
    206 
    207 exit $RC
    208