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