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