xref: /minix3/tests/net/arp/t_arp.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#	$NetBSD: t_arp.sh,v 1.9 2015/08/31 08:08:20 ozaki-r Exp $
2*0a6a1f1dSLionel Sambuc#
3*0a6a1f1dSLionel Sambuc# Copyright (c) 2015 The NetBSD Foundation, Inc.
4*0a6a1f1dSLionel Sambuc# All rights reserved.
5*0a6a1f1dSLionel Sambuc#
6*0a6a1f1dSLionel Sambuc# Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc# modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc# are met:
9*0a6a1f1dSLionel Sambuc# 1. Redistributions of source code must retain the above copyright
10*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer.
11*0a6a1f1dSLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
12*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
13*0a6a1f1dSLionel Sambuc#    documentation and/or other materials provided with the distribution.
14*0a6a1f1dSLionel Sambuc#
15*0a6a1f1dSLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16*0a6a1f1dSLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17*0a6a1f1dSLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18*0a6a1f1dSLionel Sambuc# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19*0a6a1f1dSLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*0a6a1f1dSLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*0a6a1f1dSLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*0a6a1f1dSLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*0a6a1f1dSLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*0a6a1f1dSLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*0a6a1f1dSLionel Sambuc# POSSIBILITY OF SUCH DAMAGE.
26*0a6a1f1dSLionel Sambuc#
27*0a6a1f1dSLionel Sambuc
28*0a6a1f1dSLionel Sambucinetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29*0a6a1f1dSLionel SambucHIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
30*0a6a1f1dSLionel Sambuc
31*0a6a1f1dSLionel SambucSOCKSRC=unix://commsock1
32*0a6a1f1dSLionel SambucSOCKDST=unix://commsock2
33*0a6a1f1dSLionel SambucIP4SRC=10.0.1.1
34*0a6a1f1dSLionel SambucIP4DST=10.0.1.2
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel SambucDEBUG=false
37*0a6a1f1dSLionel SambucTIMEOUT=1
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel Sambucatf_test_case cache_expiration_5s cleanup
40*0a6a1f1dSLionel Sambucatf_test_case cache_expiration_10s cleanup
41*0a6a1f1dSLionel Sambucatf_test_case command cleanup
42*0a6a1f1dSLionel Sambucatf_test_case garp cleanup
43*0a6a1f1dSLionel Sambucatf_test_case cache_overwriting cleanup
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuccache_expiration_5s_head()
46*0a6a1f1dSLionel Sambuc{
47*0a6a1f1dSLionel Sambuc	atf_set "descr" "Tests for ARP cache expiration (5s)"
48*0a6a1f1dSLionel Sambuc	atf_set "require.progs" "rump_server"
49*0a6a1f1dSLionel Sambuc}
50*0a6a1f1dSLionel Sambuc
51*0a6a1f1dSLionel Sambuccache_expiration_10s_head()
52*0a6a1f1dSLionel Sambuc{
53*0a6a1f1dSLionel Sambuc	atf_set "descr" "Tests for ARP cache expiration (10s)"
54*0a6a1f1dSLionel Sambuc	atf_set "require.progs" "rump_server"
55*0a6a1f1dSLionel Sambuc}
56*0a6a1f1dSLionel Sambuc
57*0a6a1f1dSLionel Sambuccommand_head()
58*0a6a1f1dSLionel Sambuc{
59*0a6a1f1dSLionel Sambuc	atf_set "descr" "Tests for commands of arp(8)"
60*0a6a1f1dSLionel Sambuc	atf_set "require.progs" "rump_server"
61*0a6a1f1dSLionel Sambuc}
62*0a6a1f1dSLionel Sambuc
63*0a6a1f1dSLionel Sambucgarp_head()
64*0a6a1f1dSLionel Sambuc{
65*0a6a1f1dSLionel Sambuc	atf_set "descr" "Tests for GARP"
66*0a6a1f1dSLionel Sambuc	atf_set "require.progs" "rump_server"
67*0a6a1f1dSLionel Sambuc}
68*0a6a1f1dSLionel Sambuc
69*0a6a1f1dSLionel Sambuccache_overwriting_head()
70*0a6a1f1dSLionel Sambuc{
71*0a6a1f1dSLionel Sambuc	atf_set "descr" "Tests for behavior of overwriting ARP caches"
72*0a6a1f1dSLionel Sambuc	atf_set "require.progs" "rump_server"
73*0a6a1f1dSLionel Sambuc}
74*0a6a1f1dSLionel Sambuc
75*0a6a1f1dSLionel Sambucsetup_dst_server()
76*0a6a1f1dSLionel Sambuc{
77*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKDST
78*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 create
79*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
80*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
81*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 up
82*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig -w 10
83*0a6a1f1dSLionel Sambuc
84*0a6a1f1dSLionel Sambuc	$DEBUG && rump.ifconfig shmif0
85*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
86*0a6a1f1dSLionel Sambuc}
87*0a6a1f1dSLionel Sambuc
88*0a6a1f1dSLionel Sambucsetup_src_server()
89*0a6a1f1dSLionel Sambuc{
90*0a6a1f1dSLionel Sambuc	local keep=$1
91*0a6a1f1dSLionel Sambuc
92*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
93*0a6a1f1dSLionel Sambuc
94*0a6a1f1dSLionel Sambuc	# Adjust ARP parameters
95*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
96*0a6a1f1dSLionel Sambuc
97*0a6a1f1dSLionel Sambuc	# Setup an interface
98*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 create
99*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
100*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
101*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 up
102*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig -w 10
103*0a6a1f1dSLionel Sambuc
104*0a6a1f1dSLionel Sambuc	# Sanity check
105*0a6a1f1dSLionel Sambuc	$DEBUG && rump.ifconfig shmif0
106*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
107*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
108*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
109*0a6a1f1dSLionel Sambuc}
110*0a6a1f1dSLionel Sambuc
111*0a6a1f1dSLionel Sambuctest_cache_expiration()
112*0a6a1f1dSLionel Sambuc{
113*0a6a1f1dSLionel Sambuc	local arp_keep=$1
114*0a6a1f1dSLionel Sambuc	local bonus=2
115*0a6a1f1dSLionel Sambuc
116*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKSRC
117*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKDST
118*0a6a1f1dSLionel Sambuc
119*0a6a1f1dSLionel Sambuc	setup_dst_server
120*0a6a1f1dSLionel Sambuc	setup_src_server $arp_keep
121*0a6a1f1dSLionel Sambuc
122*0a6a1f1dSLionel Sambuc	#
123*0a6a1f1dSLionel Sambuc	# Check if a cache is expired expectedly
124*0a6a1f1dSLionel Sambuc	#
125*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
126*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
127*0a6a1f1dSLionel Sambuc
128*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
129*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
130*0a6a1f1dSLionel Sambuc	# Should be cached
131*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
132*0a6a1f1dSLionel Sambuc
133*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
134*0a6a1f1dSLionel Sambuc
135*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
136*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
137*0a6a1f1dSLionel Sambuc	# Should be expired
138*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
139*0a6a1f1dSLionel Sambuc}
140*0a6a1f1dSLionel Sambuc
141*0a6a1f1dSLionel Sambuccache_expiration_5s_body()
142*0a6a1f1dSLionel Sambuc{
143*0a6a1f1dSLionel Sambuc	test_cache_expiration 5
144*0a6a1f1dSLionel Sambuc}
145*0a6a1f1dSLionel Sambuc
146*0a6a1f1dSLionel Sambuccache_expiration_10s_body()
147*0a6a1f1dSLionel Sambuc{
148*0a6a1f1dSLionel Sambuc	test_cache_expiration 10
149*0a6a1f1dSLionel Sambuc}
150*0a6a1f1dSLionel Sambuc
151*0a6a1f1dSLionel Sambuccommand_body()
152*0a6a1f1dSLionel Sambuc{
153*0a6a1f1dSLionel Sambuc	local arp_keep=5
154*0a6a1f1dSLionel Sambuc	local bonus=2
155*0a6a1f1dSLionel Sambuc
156*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKSRC
157*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKDST
158*0a6a1f1dSLionel Sambuc
159*0a6a1f1dSLionel Sambuc	setup_dst_server
160*0a6a1f1dSLionel Sambuc	setup_src_server $arp_keep
161*0a6a1f1dSLionel Sambuc
162*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
163*0a6a1f1dSLionel Sambuc
164*0a6a1f1dSLionel Sambuc	# Add and delete a static entry
165*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
166*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
167*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
168*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
169*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
170*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
171*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
172*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
173*0a6a1f1dSLionel Sambuc
174*0a6a1f1dSLionel Sambuc	# Add multiple entries via a file
175*0a6a1f1dSLionel Sambuc	cat - > ./list <<-EOF
176*0a6a1f1dSLionel Sambuc	10.0.1.11 b2:a0:20:00:00:11
177*0a6a1f1dSLionel Sambuc	10.0.1.12 b2:a0:20:00:00:12
178*0a6a1f1dSLionel Sambuc	10.0.1.13 b2:a0:20:00:00:13
179*0a6a1f1dSLionel Sambuc	10.0.1.14 b2:a0:20:00:00:14
180*0a6a1f1dSLionel Sambuc	10.0.1.15 b2:a0:20:00:00:15
181*0a6a1f1dSLionel Sambuc	EOF
182*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
183*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -f ./list
184*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
185*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
186*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
187*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
188*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
189*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
190*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
191*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
192*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
193*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
194*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
195*0a6a1f1dSLionel Sambuc
196*0a6a1f1dSLionel Sambuc	# Test arp -a
197*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
198*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
199*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
200*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
201*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
202*0a6a1f1dSLionel Sambuc
203*0a6a1f1dSLionel Sambuc	# Flush all entries
204*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
205*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -d -a
206*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
207*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
208*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
209*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
210*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
211*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
212*0a6a1f1dSLionel Sambuc
213*0a6a1f1dSLionel Sambuc	# Test temp option
214*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
215*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
216*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
217*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
218*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
219*0a6a1f1dSLionel Sambuc
220*0a6a1f1dSLionel Sambuc	# Hm? the cache doesn't expire...
221*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
222*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
223*0a6a1f1dSLionel Sambuc	#atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
224*0a6a1f1dSLionel Sambuc
225*0a6a1f1dSLionel Sambuc	return 0
226*0a6a1f1dSLionel Sambuc}
227*0a6a1f1dSLionel Sambuc
228*0a6a1f1dSLionel Sambucmake_pkt_str()
229*0a6a1f1dSLionel Sambuc{
230*0a6a1f1dSLionel Sambuc	local target=$1
231*0a6a1f1dSLionel Sambuc	local sender=$2
232*0a6a1f1dSLionel Sambuc	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
233*0a6a1f1dSLionel Sambuc	pkt="$pkt Request who-has $target tell $sender, length 28"
234*0a6a1f1dSLionel Sambuc	echo $pkt
235*0a6a1f1dSLionel Sambuc}
236*0a6a1f1dSLionel Sambuc
237*0a6a1f1dSLionel Sambucgarp_body()
238*0a6a1f1dSLionel Sambuc{
239*0a6a1f1dSLionel Sambuc	local pkt=
240*0a6a1f1dSLionel Sambuc
241*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKSRC
242*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
243*0a6a1f1dSLionel Sambuc
244*0a6a1f1dSLionel Sambuc	# Setup an interface
245*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 create
246*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
247*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
248*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
249*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 up
250*0a6a1f1dSLionel Sambuc	$DEBUG && rump.ifconfig shmif0
251*0a6a1f1dSLionel Sambuc
252*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 sleep 1
253*0a6a1f1dSLionel Sambuc	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
254*0a6a1f1dSLionel Sambuc
255*0a6a1f1dSLionel Sambuc	# A GARP packet is sent for the primary address
256*0a6a1f1dSLionel Sambuc	pkt=$(make_pkt_str 10.0.0.1 10.0.0.1)
257*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
258*0a6a1f1dSLionel Sambuc	# No GARP packet is sent for the alias address
259*0a6a1f1dSLionel Sambuc	pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
260*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
261*0a6a1f1dSLionel Sambuc
262*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig -w 10
263*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
264*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
265*0a6a1f1dSLionel Sambuc
266*0a6a1f1dSLionel Sambuc	# No GARP packets are sent during IFF_UP
267*0a6a1f1dSLionel Sambuc	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
268*0a6a1f1dSLionel Sambuc	pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
269*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
270*0a6a1f1dSLionel Sambuc	pkt=$(make_pkt_str 10.0.0.4 10.0.0.4)
271*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
272*0a6a1f1dSLionel Sambuc}
273*0a6a1f1dSLionel Sambuc
274*0a6a1f1dSLionel Sambuccache_overwriting_body()
275*0a6a1f1dSLionel Sambuc{
276*0a6a1f1dSLionel Sambuc	local arp_keep=5
277*0a6a1f1dSLionel Sambuc	local bonus=2
278*0a6a1f1dSLionel Sambuc
279*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKSRC
280*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 ${inetserver} $SOCKDST
281*0a6a1f1dSLionel Sambuc
282*0a6a1f1dSLionel Sambuc	setup_dst_server
283*0a6a1f1dSLionel Sambuc	setup_src_server $arp_keep
284*0a6a1f1dSLionel Sambuc
285*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
286*0a6a1f1dSLionel Sambuc
287*0a6a1f1dSLionel Sambuc	# Cannot overwrite a permanent cache
288*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -s $IP4SRC b2:a0:20:00:00:ff
289*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
290*0a6a1f1dSLionel Sambuc
291*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
292*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
293*0a6a1f1dSLionel Sambuc	# Can overwrite a dynamic cache
294*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
295*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
296*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
297*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
298*0a6a1f1dSLionel Sambuc
299*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
300*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
301*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
302*0a6a1f1dSLionel Sambuc	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
303*0a6a1f1dSLionel Sambuc	# Cannot overwrite a temp cache
304*0a6a1f1dSLionel Sambuc	atf_check -s not-exit:0 -e ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
305*0a6a1f1dSLionel Sambuc	$DEBUG && rump.arp -n -a
306*0a6a1f1dSLionel Sambuc
307*0a6a1f1dSLionel Sambuc	return 0
308*0a6a1f1dSLionel Sambuc}
309*0a6a1f1dSLionel Sambuc
310*0a6a1f1dSLionel Sambuccleanup()
311*0a6a1f1dSLionel Sambuc{
312*0a6a1f1dSLionel Sambuc	env RUMP_SERVER=$SOCKSRC rump.halt
313*0a6a1f1dSLionel Sambuc	env RUMP_SERVER=$SOCKDST rump.halt
314*0a6a1f1dSLionel Sambuc}
315*0a6a1f1dSLionel Sambuc
316*0a6a1f1dSLionel Sambucdump_src()
317*0a6a1f1dSLionel Sambuc{
318*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKSRC
319*0a6a1f1dSLionel Sambuc	rump.netstat -nr
320*0a6a1f1dSLionel Sambuc	rump.arp -n -a
321*0a6a1f1dSLionel Sambuc	rump.ifconfig
322*0a6a1f1dSLionel Sambuc	$HIJACKING dmesg
323*0a6a1f1dSLionel Sambuc}
324*0a6a1f1dSLionel Sambuc
325*0a6a1f1dSLionel Sambucdump_dst()
326*0a6a1f1dSLionel Sambuc{
327*0a6a1f1dSLionel Sambuc	export RUMP_SERVER=$SOCKDST
328*0a6a1f1dSLionel Sambuc	rump.netstat -nr
329*0a6a1f1dSLionel Sambuc	rump.arp -n -a
330*0a6a1f1dSLionel Sambuc	rump.ifconfig
331*0a6a1f1dSLionel Sambuc	$HIJACKING dmesg
332*0a6a1f1dSLionel Sambuc}
333*0a6a1f1dSLionel Sambuc
334*0a6a1f1dSLionel Sambucdump()
335*0a6a1f1dSLionel Sambuc{
336*0a6a1f1dSLionel Sambuc	dump_src
337*0a6a1f1dSLionel Sambuc	dump_dst
338*0a6a1f1dSLionel Sambuc	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
339*0a6a1f1dSLionel Sambuc}
340*0a6a1f1dSLionel Sambuc
341*0a6a1f1dSLionel Sambuccache_expiration_5s_cleanup()
342*0a6a1f1dSLionel Sambuc{
343*0a6a1f1dSLionel Sambuc	$DEBUG && dump
344*0a6a1f1dSLionel Sambuc	cleanup
345*0a6a1f1dSLionel Sambuc}
346*0a6a1f1dSLionel Sambuc
347*0a6a1f1dSLionel Sambuccache_expiration_10s_cleanup()
348*0a6a1f1dSLionel Sambuc{
349*0a6a1f1dSLionel Sambuc	$DEBUG && dump
350*0a6a1f1dSLionel Sambuc	cleanup
351*0a6a1f1dSLionel Sambuc}
352*0a6a1f1dSLionel Sambuc
353*0a6a1f1dSLionel Sambuccommand_cleanup()
354*0a6a1f1dSLionel Sambuc{
355*0a6a1f1dSLionel Sambuc	$DEBUG && dump
356*0a6a1f1dSLionel Sambuc	cleanup
357*0a6a1f1dSLionel Sambuc}
358*0a6a1f1dSLionel Sambuc
359*0a6a1f1dSLionel Sambucgarp_cleanup()
360*0a6a1f1dSLionel Sambuc{
361*0a6a1f1dSLionel Sambuc	$DEBUG && dump_src
362*0a6a1f1dSLionel Sambuc	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
363*0a6a1f1dSLionel Sambuc	env RUMP_SERVER=$SOCKSRC rump.halt
364*0a6a1f1dSLionel Sambuc}
365*0a6a1f1dSLionel Sambuc
366*0a6a1f1dSLionel Sambuccache_overwriting_cleanup()
367*0a6a1f1dSLionel Sambuc{
368*0a6a1f1dSLionel Sambuc	$DEBUG && dump
369*0a6a1f1dSLionel Sambuc	cleanup
370*0a6a1f1dSLionel Sambuc}
371*0a6a1f1dSLionel Sambuc
372*0a6a1f1dSLionel Sambucatf_init_test_cases()
373*0a6a1f1dSLionel Sambuc{
374*0a6a1f1dSLionel Sambuc	atf_add_test_case cache_expiration_5s
375*0a6a1f1dSLionel Sambuc	atf_add_test_case cache_expiration_10s
376*0a6a1f1dSLionel Sambuc	atf_add_test_case command
377*0a6a1f1dSLionel Sambuc	atf_add_test_case garp
378*0a6a1f1dSLionel Sambuc	atf_add_test_case cache_overwriting
379*0a6a1f1dSLionel Sambuc}
380