1#!/bin/sh 2# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved. 3# Copyright (c) International Business Machines Corp., 2005 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License as 7# published by the Free Software Foundation; either version 2 of 8# the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it would be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17# 18# Author: Mitsuru Chinen <mitch@jp.ibm.com> 19 20TST_TOTAL=2 21TCID=if-addr-addlarge 22 23. if-lib.sh 24 25TST_CLEANUP="do_cleanup" 26 27# The interval of the check interface activity 28CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))} 29 30do_cleanup() 31{ 32 cleanup 33 restore_ipaddr 34} 35 36test_body() 37{ 38 local cmd_type=$1 39 40 case $cmd_type in 41 if_cmd) local cmd_name='ifconfig' ;; 42 ip_cmd) local cmd_name='ip' ;; 43 *) tst_brkm TBROK "Unknown test parameter '$cmd_type'" 44 esac 45 46 local iface=$(tst_iface) 47 [ "$TST_IPV6" ] && local netmask=64 || local netmask=16 48 49 tst_resm TINFO "'$cmd_name' add $IP_TOTAL IPv$ipver addresses" 50 tst_resm TINFO "check interval that $iface is working: $CHECK_INTERVAL" 51 52 if ! restore_ipaddr; then 53 tst_resm TBROK "Failed to set default IP addresses" 54 return 55 fi 56 57 make_background_tcp_traffic 58 59 local x=1 60 local y=1 61 local cnt=1 62 63 [ "$TST_IPV6" ] && local xymax=65535 || xymax=254 64 65 if [ $IP_TOTAL -gt $((xymax * xymax)) ]; then 66 tst_resm TWARN "set IP_TOTAL to $xymax * $xymax" 67 IP_TOTAL=$((xymax * xymax)) 68 fi 69 70 while [ $cnt -le $IP_TOTAL ]; do 71 72 if [ "$TST_IPV6" ]; then 73 local hex_x=$(printf '%x' $x) 74 local hex_y=$(printf '%x' $y) 75 local new_ip=${IPV6_NET32_UNUSED}:1:1:1:$hex_x:$hex_y:1 76 else 77 local new_ip=${IPV4_NET16_UNUSED}.$x.$y 78 fi 79 80 case $cmd_type in 81 if_cmd) 82 if [ "$TST_IPV6" ]; then 83 ifconfig $iface add $new_ip/$netmask 84 else 85 ifconfig $iface:$x:$y $new_ip netmask 255.255.0.0 86 fi 87 ;; 88 ip_cmd) ip addr add $new_ip/$netmask dev $iface ;; 89 esac 90 91 if [ $? -ne 0 ]; then 92 tst_resm TFAIL "command failed to add $new_ip to $iface" 93 return 94 fi 95 96 ip addr show $iface | grep -q $new_ip 97 if [ $? -ne 0 ]; then 98 ip addr show $iface 99 tst_resm TFAIL "$new_ip not configured" 100 return 101 fi 102 103 # Check the connectivity 104 check_connectivity $cnt || return 105 106 # Check the background TCP traffic 107 pgrep -x netstress > /dev/null || make_background_tcp_traffic 108 109 case $cmd_type in 110 if_cmd) 111 if [ "$TST_IPV6" ]; then 112 ifconfig $iface del $new_ip/$netmask 113 else 114 ifconfig $iface:$x:$y down 115 fi 116 ;; 117 ip_cmd) ip addr del $new_ip/$netmask dev $iface ;; 118 esac 119 120 if [ $? -ne 0 ]; then 121 tst_resm TFAIL " delete command failed". 122 return 123 fi 124 125 ip addr show $iface | grep -q $new_ip 126 if [ $? -eq 0 ]; then 127 ip addr show $iface 128 tst_resm TFAIL "Failed to remove '$new_ip' address" 129 return 130 fi 131 132 cnt=$(($cnt + 1)) 133 y=$(($y + 1)) 134 if [ $y -gt $xymax ]; then 135 y=1 136 x=$(($x + 1)) 137 if [ $x -gt $xymax ]; then 138 tst_brkm TBROK "Too large $IP_TOTAL" 139 fi 140 fi 141 done 142 143 tst_resm TPASS "Test is finished correctly" 144} 145 146setup 147 148tst_check_cmds ifconfig 149 150test_body 'if_cmd' 151test_body 'ip_cmd' 152 153tst_exit 154