• 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
17do_setup()
18{
19	case $CMD in
20	ip)
21		SHOW_CMD="ip neigh show"
22		DEL_CMD="ROD ip neigh del $(tst_ipaddr rhost) dev $(tst_iface)"
23		;;
24	arp)
25		if [ -n "$TST_IPV6" ]; then
26			tst_brk TCONF "'arp' doesn't support IPv6"
27		fi
28		SHOW_CMD="arp -an"
29		DEL_CMD="ROD arp -d $(tst_ipaddr rhost) -i $(tst_iface)"
30		;;
31	*)
32		tst_brk TBROK "unknown or missing command, use -c [ arp | ip ]"
33		;;
34	esac
35
36	tst_require_cmds $CMD ping$TST_IPV6
37}
38
39usage()
40{
41	echo "-c [ arp | ip ] Test command"
42}
43
44parse_args()
45{
46	case $1 in
47	c) CMD="$2" ;;
48	esac
49}
50
51do_test()
52{
53	local entry_name="ARP"
54	[ "$TST_IPV6" ] && entry_name="NDISC"
55
56	tst_res TINFO "stress auto-creation $entry_name cache entry deleted with '$CMD' $NUMLOOPS times"
57
58	for i in $(seq 1 $NUMLOOPS); do
59
60		ping$TST_IPV6 -q -c1 $(tst_ipaddr rhost) -I $(tst_iface) > /dev/null || \
61			tst_brk TFAIL "cannot ping $(tst_ipaddr rhost)"
62
63		local k
64		local ret=1
65		for k in $(seq 1 30); do
66			$SHOW_CMD | grep -q $(tst_ipaddr rhost)
67			if [ $? -eq 0 ]; then
68				ret=0
69				break;
70			fi
71			tst_sleep 100ms
72		done
73
74		[ "$ret" -ne 0 ] && \
75			tst_brk TFAIL "$entry_name entry '$(tst_ipaddr rhost)' not listed"
76
77		$DEL_CMD
78
79		$SHOW_CMD | grep -q "$(tst_ipaddr rhost).*$(tst_hwaddr rhost)" && \
80			tst_brk TFAIL "'$DEL_CMD' failed, entry has " \
81				"$(tst_hwaddr rhost)' $i/$NUMLOOPS"
82	done
83
84	tst_res TPASS "verified adding/removing $entry_name cache entry"
85}
86
87. tst_net.sh
88tst_run
89