1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2017-2022 Petr Vorel <[email protected]> 4# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 5# Copyright (c) International Business Machines Corp., 2005 6# Author: Mitsuru Chinen <[email protected]> 7 8IF_CMD='ifconfig' 9 10test_body() 11{ 12 local cmd="$CMD" 13 14 local iface=$(tst_iface) 15 [ "$TST_IPV6" ] && local netmask=64 || local netmask=16 16 17 tst_res TINFO "'$cmd' add $IP_TOTAL IPv$TST_IPVER addresses" 18 tst_res TINFO "check interval that $iface is working: $CHECK_INTERVAL" 19 20 if ! restore_ipaddr; then 21 tst_res TBROK "Failed to set default IP addresses" 22 return 23 fi 24 25 local x=1 26 local y=1 27 local cnt=1 28 29 [ "$TST_IPV6" ] && local xymax=65535 || xymax=254 30 31 if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then 32 tst_res TWARN "set IP_TOTAL to $xymax * $xymax" 33 IP_TOTAL=$((xymax * xymax)) 34 fi 35 36 while [ $cnt -le $IP_TOTAL ]; do 37 make_background_tcp_traffic 38 39 if [ "$TST_IPV6" ]; then 40 local hex_x=$(printf '%x' $x) 41 local hex_y=$(printf '%x' $y) 42 local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1 43 else 44 local new_ip=${IPV4_NET16_UNUSED}.$x.$y 45 fi 46 47 case $cmd in 48 ifconfig) 49 if [ "$TST_IPV6" ]; then 50 ifconfig $iface add $new_ip/$netmask 51 else 52 ifconfig $iface:$x:$y $new_ip netmask 255.255.0.0 53 fi 54 ;; 55 ip) ip addr add $new_ip/$netmask dev $iface ;; 56 esac 57 58 if [ $? -ne 0 ]; then 59 tst_res TFAIL "command failed to add $new_ip to $iface" 60 return 61 fi 62 63 ip addr show $iface | grep -q $new_ip 64 if [ $? -ne 0 ]; then 65 ip addr show $iface 66 tst_res TFAIL "$new_ip not configured" 67 return 68 fi 69 70 check_connectivity_interval $cnt || return 71 72 case $cmd in 73 ifconfig) 74 if [ "$TST_IPV6" ]; then 75 ifconfig $iface del $new_ip/$netmask 76 else 77 ifconfig $iface:$x:$y down 78 fi 79 ;; 80 ip) ip addr del $new_ip/$netmask dev $iface ;; 81 esac 82 83 if [ $? -ne 0 ]; then 84 tst_res TFAIL " delete command failed". 85 return 86 fi 87 88 ip addr show $iface | grep -q $new_ip 89 if [ $? -eq 0 ]; then 90 ip addr show $iface 91 tst_res TFAIL "Failed to remove '$new_ip' address" 92 return 93 fi 94 95 cnt=$(($cnt + 1)) 96 y=$(($y + 1)) 97 if [ $y -gt $xymax ]; then 98 y=1 99 x=$(($x + 1)) 100 if [ $x -gt $xymax ]; then 101 tst_brk TBROK "Too large $IP_TOTAL" 102 fi 103 fi 104 done 105 106 tst_res TPASS "Test is finished correctly" 107} 108 109. if-lib.sh 110 111# The interval of the check interface activity 112CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))} 113 114tst_run 115