1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz> 4# Copyright (c) 2015 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 8IF_CMD='ifconfig' 9. if-lib.sh 10 11# The interval of the check interface activity 12CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))} 13 14test_body() 15{ 16 local cmd="$CMD" 17 local num=$(($(od -A n -t u1 -N 1 /dev/random) * 253 / 255 + 2 )) 18 local iface=$(tst_iface) 19 if [ "$TST_IPV6" ]; then 20 local new_ip=${IPV6_NET32_UNUSED}::$num 21 local netmask=64 22 else 23 local new_ip=${IPV4_NET16_UNUSED}.1.$num 24 local netmask=24 25 fi 26 27 tst_res TINFO "'$cmd' add/del IPv$TST_IPVER '$new_ip' $NS_TIMES times" 28 29 if ! restore_ipaddr; then 30 tst_res TBROK "Failed to set default IP addresses" 31 return 32 fi 33 34 local cnt=1 35 while [ $cnt -le $NS_TIMES ]; do 36 make_background_tcp_traffic 37 38 case $cmd in 39 ifconfig) 40 if [ "$TST_IPV6" ]; then 41 ifconfig $iface add $new_ip/$netmask 42 else 43 ifconfig $iface:1 $new_ip netmask 255.255.255.0 44 fi 45 ;; 46 ip) ip addr add $new_ip/$netmask dev $iface ;; 47 esac 48 49 if [ $? -ne 0 ]; then 50 tst_res TFAIL "command failed to add $new_ip to $iface" 51 return 52 fi 53 54 ip addr show $iface | grep -q $new_ip 55 if [ $? -ne 0 ]; then 56 ip addr show $iface 57 tst_res TFAIL "$new_ip not configured" 58 return 59 fi 60 61 check_connectivity_interval $cnt || return 62 63 cnt=$(($cnt + 1)) 64 65 case $cmd in 66 ifconfig) 67 if [ "$TST_IPV6" ]; then 68 ifconfig $iface del $new_ip/$netmask 69 else 70 ifconfig $iface:1 down 71 fi 72 ;; 73 ip) ip addr del $new_ip/$netmask dev $iface ;; 74 esac 75 76 if [ $? -ne 0 ]; then 77 tst_res TFAIL " delete command failed". 78 return 79 fi 80 81 ip addr show $iface | grep -q $new_ip 82 if [ $? -eq 0 ]; then 83 ip addr show $iface 84 tst_res TFAIL "Failed to remove '$new_ip' address" 85 return 86 fi 87 done 88 89 tst_res TPASS "Test is finished correctly" 90} 91 92tst_run 93