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