• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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='route'
9. if-lib.sh
10
11CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
12
13test_body()
14{
15	local cmd="$CMD"
16	local iface=$(tst_iface)
17	local inet="inet$TST_IPV6"
18	local new_rt=
19	local opt_rt=
20	if [ "$TST_IPV6" ]; then
21		new_rt="$(TST_IPV6=6 tst_ipaddr_un 0)"
22		opt_rt="/64"
23	else
24		new_rt="$(tst_ipaddr_un 23)"
25		if [ "$cmd" = "ip" ]; then
26			opt_rt='/24'
27		fi
28	fi
29
30	tst_res TINFO "'$cmd' add/del ${new_rt}${opt_rt} $NS_TIMES times"
31
32	if ! restore_ipaddr; then
33		tst_res TBROK "Failed to set default IP addresses"
34		return
35	fi
36
37	local cnt=1
38	while [ $cnt -le $NS_TIMES ]; do
39		make_background_tcp_traffic
40
41		case $cmd in
42		route) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
43		ip) ip route add ${new_rt}${opt_rt} dev $iface ;;
44		esac
45		if [ $? -ne 0 ]; then
46			tst_res TFAIL "Can't add route $new_rt to $iface"
47			return
48		fi
49
50		case $cmd in
51		route) route -A $inet del ${new_rt}${opt_rt} dev $iface ;;
52		ip) ip route del ${new_rt}${opt_rt} dev $iface ;;
53		esac
54		if [ $? -ne 0 ]; then
55			tst_res TFAIL "Can't del route $new_rt from $iface"
56			return
57		fi
58
59		check_connectivity_interval $cnt || return
60
61		cnt=$(($cnt + 1))
62	done
63
64	tst_res TPASS "Test is finished correctly"
65}
66
67tst_run
68