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='route'
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_citest_body()
11f08c3bdfSopenharmony_ci{
12f08c3bdfSopenharmony_ci	local cmd="$CMD"
13f08c3bdfSopenharmony_ci	local iface=$(tst_iface)
14f08c3bdfSopenharmony_ci	local inet="inet$TST_IPV6"
15f08c3bdfSopenharmony_ci	local opt_rt=
16f08c3bdfSopenharmony_ci	if [ "$TST_IPV6" ]; then
17f08c3bdfSopenharmony_ci		opt_rt="/64"
18f08c3bdfSopenharmony_ci	elif [ "$cmd" = "ip" ]; then
19f08c3bdfSopenharmony_ci		opt_rt='/32'
20f08c3bdfSopenharmony_ci	fi
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_ci	tst_res TINFO "'$cmd' add IPv$TST_IPVER $ROUTE_TOTAL routes"
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_ci	if ! restore_ipaddr; then
25f08c3bdfSopenharmony_ci		tst_res TBROK "Failed to set default IP addresses"
26f08c3bdfSopenharmony_ci		return
27f08c3bdfSopenharmony_ci	fi
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_ci	local x=1
30f08c3bdfSopenharmony_ci	local y=1
31f08c3bdfSopenharmony_ci	local cnt=1
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ci	[ "$TST_IPV6" ] && local xymax=65535 || xymax=254
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci	if [ $ROUTE_TOTAL -gt $((xymax * xymax)) ]; then
36f08c3bdfSopenharmony_ci		tst_res TWARN "set ROUTE_TOTAL to $xymax * $xymax"
37f08c3bdfSopenharmony_ci		ROUTE_TOTAL=$((xymax * xymax))
38f08c3bdfSopenharmony_ci	fi
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_ci	while [ $cnt -le $ROUTE_TOTAL ]; do
41f08c3bdfSopenharmony_ci		make_background_tcp_traffic
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_ci		if [ "$TST_IPV6" ]; then
44f08c3bdfSopenharmony_ci			local hex_x=$(printf '%x' $x)
45f08c3bdfSopenharmony_ci			local hex_y=$(printf '%x' $y)
46f08c3bdfSopenharmony_ci			local new_rt=${IPV6_NET32_UNUSED}:$hex_x:$hex_y::
47f08c3bdfSopenharmony_ci		else
48f08c3bdfSopenharmony_ci			local new_rt=${IPV4_NET16_UNUSED}.$x.$y
49f08c3bdfSopenharmony_ci		fi
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci		case $cmd in
52f08c3bdfSopenharmony_ci		route) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
53f08c3bdfSopenharmony_ci		ip) ip route add ${new_rt}${opt_rt} dev $iface ;;
54f08c3bdfSopenharmony_ci		esac
55f08c3bdfSopenharmony_ci		if [ $? -ne 0 ]; then
56f08c3bdfSopenharmony_ci			tst_res TFAIL "Can't add route $new_rt to $iface"
57f08c3bdfSopenharmony_ci			return
58f08c3bdfSopenharmony_ci		fi
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci		check_connectivity_interval $cnt || return
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ci		cnt=$(($cnt + 1))
63f08c3bdfSopenharmony_ci		y=$(($y + 1))
64f08c3bdfSopenharmony_ci		if [ $y -gt $xymax ]; then
65f08c3bdfSopenharmony_ci			y=1
66f08c3bdfSopenharmony_ci			x=$(($x + 1))
67f08c3bdfSopenharmony_ci			if [ $x -gt $xymax ]; then
68f08c3bdfSopenharmony_ci				tst_brk TBROK "Too large $ROUTE_TOTAL"
69f08c3bdfSopenharmony_ci			fi
70f08c3bdfSopenharmony_ci		fi
71f08c3bdfSopenharmony_ci	done
72f08c3bdfSopenharmony_ci
73f08c3bdfSopenharmony_ci	tst_res TPASS "Test is finished correctly"
74f08c3bdfSopenharmony_ci}
75f08c3bdfSopenharmony_ci
76f08c3bdfSopenharmony_ci. if-lib.sh
77f08c3bdfSopenharmony_ci
78f08c3bdfSopenharmony_ciCHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
79f08c3bdfSopenharmony_ci
80f08c3bdfSopenharmony_citst_run
81