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:-$(($IP_TOTAL / 20))} 13 14test_body() 15{ 16 local cmd="$CMD" 17 18 local iface=$(tst_iface) 19 [ "$TST_IPV6" ] && local netmask=64 || local netmask=16 20 21 tst_res TINFO "'$cmd' add $IP_TOTAL IPv$TST_IPVER addresses" 22 tst_res TINFO "check interval that $iface is working: $CHECK_INTERVAL" 23 24 if ! restore_ipaddr; then 25 tst_res TBROK "Failed to set default IP addresses" 26 return 27 fi 28 29 local x=1 30 local y=1 31 local cnt=1 32 33 [ "$TST_IPV6" ] && local xymax=65535 || xymax=254 34 35 if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then 36 tst_res TWARN "set IP_TOTAL to $xymax * $xymax" 37 IP_TOTAL=$((xymax * xymax)) 38 fi 39 40 while [ $cnt -le $IP_TOTAL ]; do 41 make_background_tcp_traffic 42 43 if [ "$TST_IPV6" ]; then 44 local hex_x=$(printf '%x' $x) 45 local hex_y=$(printf '%x' $y) 46 local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1 47 else 48 local new_ip=${IPV4_NET16_UNUSED}.$x.$y 49 fi 50 51 case $cmd in 52 ifconfig) 53 if [ "$TST_IPV6" ]; then 54 ifconfig $iface add $new_ip/$netmask 55 else 56 ifconfig $iface:$x:$y $new_ip netmask 255.255.0.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 case $cmd in 77 ifconfig) 78 if [ "$TST_IPV6" ]; then 79 ifconfig $iface del $new_ip/$netmask 80 else 81 ifconfig $iface:$x:$y down 82 fi 83 ;; 84 ip) ip addr del $new_ip/$netmask dev $iface ;; 85 esac 86 87 if [ $? -ne 0 ]; then 88 tst_res TFAIL " delete command failed". 89 return 90 fi 91 92 ip addr show $iface | grep -q $new_ip 93 if [ $? -eq 0 ]; then 94 ip addr show $iface 95 tst_res TFAIL "Failed to remove '$new_ip' address" 96 return 97 fi 98 99 cnt=$(($cnt + 1)) 100 y=$(($y + 1)) 101 if [ $y -gt $xymax ]; then 102 y=1 103 x=$(($x + 1)) 104 if [ $x -gt $xymax ]; then 105 tst_brk TBROK "Too large $IP_TOTAL" 106 fi 107 fi 108 done 109 110 tst_res TPASS "Test is finished correctly" 111} 112 113tst_run 114