• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2017-2019 Petr Vorel <pvorel@suse.cz>
4# Copyright (c) 2015-2016 Oracle and/or its affiliates. All Rights Reserved.
5# Copyright (c) International Business Machines Corp., 2005
6# Author: Mitsuru Chinen <mitch@jp.ibm.com>
7
8TST_CLEANUP="do_cleanup"
9TST_TESTFUNC="test_body"
10TST_NEEDS_CMDS="ifconfig"
11. tst_net.sh
12
13CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
14# Maximum host portion of the IPv4 address on the local host
15LHOST_IPV4_HOST_MAX="254"
16
17do_cleanup()
18{
19	tst_restore_ipaddr
20	tst_wait_ipv6_dad
21}
22
23test_body()
24{
25	local cnt=0
26	local num=1
27	local add_to_net
28
29	tst_res TINFO "ifconfig changes IPv4 address $NS_TIMES times"
30
31	while [ $cnt -lt $NS_TIMES ]; do
32		# Define the network portion
33		num=$(($num + 1))
34		[ $num -gt $LHOST_IPV4_HOST_MAX ] && num=1
35
36		[ $num -eq $RHOST_IPV4_HOST ] && continue
37
38		# check prefix and fix values for prefix != 24
39		add_to_net=
40		if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
41			tst_brk TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
42		elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
43			add_to_net=".0.1"
44		elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
45			add_to_net=".1"
46		fi
47
48		# Change IPv4 address
49		ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
50			$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
51
52		cnt=$(($cnt + 1))
53
54		[ $CHECK_INTERVAL -eq 0 ] && continue
55		[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
56
57		tst_res TINFO "ping $(tst_ipaddr):$(tst_ipaddr rhost) ${cnt}/$NS_TIMES"
58		tst_ping
59	done
60
61	tst_ping
62}
63
64tst_run
65