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-route-adddel
22
23. if-lib.sh
24
25CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 100))}
26
27test_body()
28{
29	local cmd_type=$1
30
31	case $cmd_type in
32	rt_cmd) local cmd_name='route' ;;
33	ip_cmd) local cmd_name='ip' ;;
34	*) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
35	esac
36
37	local iface=$(tst_iface)
38	local inet="inet$TST_IPV6"
39	local new_rt=
40	local opt_rt=
41	if [ "$TST_IPV6" ]; then
42		new_rt=${IPV6_NET32_UNUSED}::
43		opt_rt="/64"
44	else
45		new_rt="${IPV4_NET16_UNUSED}.23.0"
46		case $cmd_type in
47		rt_cmd) ;;
48		ip_cmd) opt_rt='/24' ;;
49		esac
50	fi
51
52	tst_resm TINFO "'$cmd_name' add/del ${new_rt}${opt_rt} $NS_TIMES times"
53
54	tst_restore_ipaddr || \
55		tst_resm TBROK "Failed to set default IP addresses"
56
57	make_background_tcp_traffic
58
59	local cnt=1
60	while [ $cnt -le $NS_TIMES ]; do
61		case $cmd_type in
62		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
63		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
64		esac
65		if [ $? -ne 0 ]; then
66			tst_resm TFAIL "Can't add route $new_rt to $iface"
67			return
68		fi
69
70		case $cmd_type in
71		rt_cmd) route -A $inet del ${new_rt}${opt_rt} dev $iface ;;
72		ip_cmd) ip route del ${new_rt}${opt_rt} dev $iface ;;
73		esac
74		if [ $? -ne 0 ]; then
75			tst_resm TFAIL "Can't del route $new_rt from $iface"
76			return
77		fi
78
79		check_connectivity $cnt || return
80
81		# Check the background TCP traffic
82		pgrep -x tcp_fastopen > /dev/null || make_background_tcp_traffic
83
84		cnt=$(($cnt + 1))
85	done
86
87	tst_resm TPASS "Test is finished correctly"
88}
89
90setup
91
92tst_check_cmds route
93
94test_body 'rt_cmd'
95test_body 'ip_cmd'
96
97tst_exit
98