• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
3# Copyright (c) International Business Machines  Corp., 2000
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 2 of
7# the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it would be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17# Test basic functionality of 'arp' and 'ip neigh'.
18
19TCID=ipneigh01
20NUMLOOPS=${NUMLOOPS:-50}
21TST_TOTAL=2
22. test_net.sh
23
24do_setup()
25{
26	tst_require_root
27	tst_check_cmds ip arp grep ping$TST_IPV6
28}
29
30do_test()
31{
32	local arp_show_cmd="$1"
33	local arp_del_cmd="$2"
34
35	local entry_name
36	[ "$TST_IPV6" ] && entry_name="NDISC" || entry_name="ARP"
37
38	tst_resm TINFO "Stress auto-creation of $entry_name cache entry"
39	tst_resm TINFO "by pinging '$rhost' and deleting entry again"
40	tst_resm TINFO "with '$arp_del_cmd'"
41
42	for i in $(seq 1 $NUMLOOPS); do
43
44		ping$TST_IPV6 -q -c1 $rhost > /dev/null
45
46		local k
47		local ret=1
48		# wait for arp entry at least 3 seconds
49		for k in $(seq 1 30); do
50			$arp_show_cmd | grep -q $rhost
51			if [ $? -eq 0 ]; then
52				ret=0
53				break;
54			fi
55			tst_sleep 100ms
56		done
57
58		[ "$ret" -ne 0 ] && \
59			tst_brkm TFAIL "$entry_name entry '$rhost' not listed"
60
61		$arp_del_cmd
62
63		$arp_show_cmd | grep -q "${rhost}.*$(tst_hwaddr rhost)" && \
64			tst_brkm TFAIL "'$arp_del_cmd' failed, entry has " \
65				       "$(tst_hwaddr rhost)' $i/$NUMLOOPS"
66	done
67
68	tst_resm TPASS "verified adding/removing of $entry_name cache entry"
69}
70
71do_setup
72
73rhost=$(tst_ipaddr rhost)
74
75if [ -z "$TST_IPV6" ]; then
76	do_test "arp -a" "arp -d $rhost"
77else
78	tst_resm TCONF "'arp cmd doesn't support IPv6, skipping test-case"
79fi
80
81do_test "ip neigh show" "ip neigh del $rhost dev $(tst_iface)"
82
83tst_exit
84