Home | History | Annotate | Download | only in interface
      1 #!/bin/sh
      2 # Copyright (c) 2015-2016 Oracle and/or its affiliates. All Rights Reserved.
      3 # Copyright (c) International Business Machines  Corp., 2005
      4 #
      5 # This program is free software; you can redistribute it and/or
      6 # modify it under the terms of the GNU General Public License as
      7 # published by the Free Software Foundation; either version 2 of
      8 # the License, or (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it would be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     17 #
     18 # Author: Mitsuru Chinen <mitch (at] jp.ibm.com>
     19 
     20 TST_TOTAL=1
     21 TCID=if4-addr-change
     22 TST_CLEANUP="do_cleanup"
     23 
     24 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
     25 # Maximum host portion of the IPv4 address on the local host
     26 LHOST_IPV4_HOST_MAX="254"
     27 
     28 . test_net.sh
     29 
     30 do_cleanup()
     31 {
     32 	tst_restore_ipaddr
     33 	tst_wait_ipv6_dad
     34 }
     35 
     36 trap "tst_brkm TBROK 'test interrupted'" INT
     37 
     38 tst_check_cmds ifconfig
     39 
     40 tst_resm TINFO "ifconfig changes IPv4 address $NS_TIMES times"
     41 
     42 cnt=0
     43 num=1
     44 while [ $cnt -lt $NS_TIMES ]; do
     45 	# Define the network portion
     46 	num=$(($num + 1))
     47 	[ $num -gt $LHOST_IPV4_HOST_MAX ] && num=1
     48 
     49 	[ $num -eq $RHOST_IPV4_HOST ] && continue
     50 
     51 	# check prefix and fix values for prefix != 24
     52 	add_to_net=
     53 	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
     54 		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
     55 	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
     56 		add_to_net=".0.1"
     57 	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
     58 		add_to_net=".1"
     59 	fi
     60 
     61 	# Change IPv4 address
     62 	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
     63 		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
     64 
     65 	cnt=$(($cnt + 1))
     66 
     67 	[ $CHECK_INTERVAL -eq 0 ] && continue
     68 	[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
     69 
     70 	tst_resm TINFO "ping $(tst_ipaddr):$(tst_ipaddr rhost) ${cnt}/$NS_TIMES"
     71 	tst_ping
     72 done
     73 
     74 tst_ping
     75 
     76 tst_exit
     77