xref: /aosp_15_r20/external/ltp/testcases/network/stress/interface/if4-addr-change.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2017-2019 Petr Vorel <[email protected]>
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 <[email protected]>
7
8TST_CLEANUP="do_cleanup"
9TST_TESTFUNC="test_body"
10TST_NEEDS_CMDS="ifconfig"
11
12# Maximum host portion of the IPv4 address on the local host
13LHOST_IPV4_HOST_MAX="254"
14
15do_cleanup()
16{
17	tst_restore_ipaddr
18	tst_wait_ipv6_dad
19}
20
21test_body()
22{
23	local cnt=0
24	local num=1
25	local add_to_net
26
27	tst_res TINFO "ifconfig changes IPv4 address $NS_TIMES times"
28
29	while [ $cnt -lt $NS_TIMES ]; do
30		# Define the network portion
31		num=$(($num + 1))
32		[ $num -gt $LHOST_IPV4_HOST_MAX ] && num=1
33
34		[ $num -eq $RHOST_IPV4_HOST ] && continue
35
36		# check prefix and fix values for prefix != 24
37		add_to_net=
38		if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
39			tst_brk TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
40		elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
41			add_to_net=".0.1"
42		elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
43			add_to_net=".1"
44		fi
45
46		# Change IPv4 address
47		ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
48			$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
49
50		cnt=$(($cnt + 1))
51
52		[ $CHECK_INTERVAL -eq 0 ] && continue
53		[ $(($cnt % $CHECK_INTERVAL)) -ne 0 ] && continue
54
55		tst_res TINFO "ping $(tst_ipaddr):$(tst_ipaddr rhost) ${cnt}/$NS_TIMES"
56		tst_ping
57	done
58
59	tst_ping
60}
61
62. tst_net.sh
63
64CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
65
66tst_run
67