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