• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2018 SUSE Linux GmbH
3# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
4# Copyright (c) International Business Machines  Corp., 2000
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# Test basic functionality of 'arp' and 'ip neigh'.
19
20NUMLOOPS=${NUMLOOPS:-50}
21TST_TESTFUNC=do_test
22TST_SETUP=do_setup
23TST_OPTS="c:"
24TST_PARSE_ARGS="parse_args"
25TST_USAGE="usage"
26TST_NEEDS_ROOT=1
27. tst_net.sh
28
29do_setup()
30{
31	case $CMD in
32	ip)
33		SHOW_CMD="ip neigh show"
34		DEL_CMD="ip neigh del $(tst_ipaddr rhost) dev $(tst_iface)"
35		;;
36	arp)
37		if [ -n "$TST_IPV6" ]; then
38			tst_brk TCONF "'arp' doesn't support IPv6"
39		fi
40		SHOW_CMD="arp -a"
41		DEL_CMD="arp -d $(tst_ipaddr rhost)"
42		;;
43	*)
44		tst_brk TBROK "unknown or missing command, use -c [ arp | ip ]"
45		;;
46	esac
47
48	tst_test_cmds $CMD ping$TST_IPV6
49}
50
51usage()
52{
53	echo "-c [ arp | ip ] Test command"
54}
55
56parse_args()
57{
58	case $1 in
59	c) CMD="$2" ;;
60	esac
61}
62
63do_test()
64{
65	local entry_name="ARP"
66	[ "$TST_IPV6" ] && entry_name="NDISC"
67
68	tst_res TINFO "stress auto-creation $entry_name cache entry deleted with '$CMD' $NUMLOOPS times"
69
70	for i in $(seq 1 $NUMLOOPS); do
71
72		ping$TST_IPV6 -q -c1 $(tst_ipaddr rhost) > /dev/null || \
73			tst_brk TFAIL "cannot ping $(tst_ipaddr rhost)"
74
75		local k
76		local ret=1
77		for k in $(seq 1 30); do
78			$SHOW_CMD | grep -q $(tst_ipaddr rhost)
79			if [ $? -eq 0 ]; then
80				ret=0
81				break;
82			fi
83			tst_sleep 100ms
84		done
85
86		[ "$ret" -ne 0 ] && \
87			tst_brk TFAIL "$entry_name entry '$(tst_ipaddr rhost)' not listed"
88
89		$DEL_CMD || tst_brk TFAIL "fail to delete entry"
90
91		$SHOW_CMD | grep -q "$(tst_ipaddr rhost).*$(tst_hwaddr rhost)" && \
92			tst_brk TFAIL "'$DEL_CMD' failed, entry has " \
93				"$(tst_hwaddr rhost)' $i/$NUMLOOPS"
94	done
95
96	tst_res TPASS "verified adding/removing $entry_name cache entry"
97}
98
99tst_run
100