Remove building with NOCRYPTO option
[minix.git] / tests / net / arp / t_arp.sh
blobc8b7c5c8967e8d80d92f669555a51d89a0c3e917
1 # $NetBSD: t_arp.sh,v 1.9 2015/08/31 08:08:20 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
31 SOCKSRC=unix://commsock1
32 SOCKDST=unix://commsock2
33 IP4SRC=10.0.1.1
34 IP4DST=10.0.1.2
36 DEBUG=false
37 TIMEOUT=1
39 atf_test_case cache_expiration_5s cleanup
40 atf_test_case cache_expiration_10s cleanup
41 atf_test_case command cleanup
42 atf_test_case garp cleanup
43 atf_test_case cache_overwriting cleanup
45 cache_expiration_5s_head()
47 atf_set "descr" "Tests for ARP cache expiration (5s)"
48 atf_set "require.progs" "rump_server"
51 cache_expiration_10s_head()
53 atf_set "descr" "Tests for ARP cache expiration (10s)"
54 atf_set "require.progs" "rump_server"
57 command_head()
59 atf_set "descr" "Tests for commands of arp(8)"
60 atf_set "require.progs" "rump_server"
63 garp_head()
65 atf_set "descr" "Tests for GARP"
66 atf_set "require.progs" "rump_server"
69 cache_overwriting_head()
71 atf_set "descr" "Tests for behavior of overwriting ARP caches"
72 atf_set "require.progs" "rump_server"
75 setup_dst_server()
77 export RUMP_SERVER=$SOCKDST
78 atf_check -s exit:0 rump.ifconfig shmif0 create
79 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
80 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
81 atf_check -s exit:0 rump.ifconfig shmif0 up
82 atf_check -s exit:0 rump.ifconfig -w 10
84 $DEBUG && rump.ifconfig shmif0
85 $DEBUG && rump.arp -n -a
88 setup_src_server()
90 local keep=$1
92 export RUMP_SERVER=$SOCKSRC
94 # Adjust ARP parameters
95 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
97 # Setup an interface
98 atf_check -s exit:0 rump.ifconfig shmif0 create
99 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
100 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
101 atf_check -s exit:0 rump.ifconfig shmif0 up
102 atf_check -s exit:0 rump.ifconfig -w 10
104 # Sanity check
105 $DEBUG && rump.ifconfig shmif0
106 $DEBUG && rump.arp -n -a
107 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
108 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
111 test_cache_expiration()
113 local arp_keep=$1
114 local bonus=2
116 atf_check -s exit:0 ${inetserver} $SOCKSRC
117 atf_check -s exit:0 ${inetserver} $SOCKDST
119 setup_dst_server
120 setup_src_server $arp_keep
123 # Check if a cache is expired expectedly
125 export RUMP_SERVER=$SOCKSRC
126 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
128 $DEBUG && rump.arp -n -a
129 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
130 # Should be cached
131 atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
133 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
135 $DEBUG && rump.arp -n -a
136 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
137 # Should be expired
138 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
141 cache_expiration_5s_body()
143 test_cache_expiration 5
146 cache_expiration_10s_body()
148 test_cache_expiration 10
151 command_body()
153 local arp_keep=5
154 local bonus=2
156 atf_check -s exit:0 ${inetserver} $SOCKSRC
157 atf_check -s exit:0 ${inetserver} $SOCKDST
159 setup_dst_server
160 setup_src_server $arp_keep
162 export RUMP_SERVER=$SOCKSRC
164 # Add and delete a static entry
165 $DEBUG && rump.arp -n -a
166 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
167 $DEBUG && rump.arp -n -a
168 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
169 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
170 atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
171 $DEBUG && rump.arp -n -a
172 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
174 # Add multiple entries via a file
175 cat - > ./list <<-EOF
176 10.0.1.11 b2:a0:20:00:00:11
177 10.0.1.12 b2:a0:20:00:00:12
178 10.0.1.13 b2:a0:20:00:00:13
179 10.0.1.14 b2:a0:20:00:00:14
180 10.0.1.15 b2:a0:20:00:00:15
182 $DEBUG && rump.arp -n -a
183 atf_check -s exit:0 -o ignore rump.arp -f ./list
184 $DEBUG && rump.arp -n -a
185 atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
186 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
187 atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
188 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
189 atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
190 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
191 atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
192 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
193 atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
194 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
196 # Test arp -a
197 atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
198 atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
199 atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
200 atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
201 atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
203 # Flush all entries
204 $DEBUG && rump.arp -n -a
205 atf_check -s exit:0 -o ignore rump.arp -d -a
206 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
207 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
208 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
209 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
210 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
211 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
213 # Test temp option
214 $DEBUG && rump.arp -n -a
215 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
216 $DEBUG && rump.arp -n -a
217 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
218 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
220 # Hm? the cache doesn't expire...
221 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
222 $DEBUG && rump.arp -n -a
223 #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
225 return 0
228 make_pkt_str()
230 local target=$1
231 local sender=$2
232 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
233 pkt="$pkt Request who-has $target tell $sender, length 28"
234 echo $pkt
237 garp_body()
239 local pkt=
241 atf_check -s exit:0 ${inetserver} $SOCKSRC
242 export RUMP_SERVER=$SOCKSRC
244 # Setup an interface
245 atf_check -s exit:0 rump.ifconfig shmif0 create
246 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
247 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
248 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
249 atf_check -s exit:0 rump.ifconfig shmif0 up
250 $DEBUG && rump.ifconfig shmif0
252 atf_check -s exit:0 sleep 1
253 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
255 # A GARP packet is sent for the primary address
256 pkt=$(make_pkt_str 10.0.0.1 10.0.0.1)
257 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
258 # No GARP packet is sent for the alias address
259 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
260 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
262 atf_check -s exit:0 rump.ifconfig -w 10
263 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
264 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
266 # No GARP packets are sent during IFF_UP
267 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
268 pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
269 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
270 pkt=$(make_pkt_str 10.0.0.4 10.0.0.4)
271 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
274 cache_overwriting_body()
276 local arp_keep=5
277 local bonus=2
279 atf_check -s exit:0 ${inetserver} $SOCKSRC
280 atf_check -s exit:0 ${inetserver} $SOCKDST
282 setup_dst_server
283 setup_src_server $arp_keep
285 export RUMP_SERVER=$SOCKSRC
287 # Cannot overwrite a permanent cache
288 atf_check -s not-exit:0 -e ignore rump.arp -s $IP4SRC b2:a0:20:00:00:ff
289 $DEBUG && rump.arp -n -a
291 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
292 $DEBUG && rump.arp -n -a
293 # Can overwrite a dynamic cache
294 atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
295 $DEBUG && rump.arp -n -a
296 atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
297 atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
299 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
300 $DEBUG && rump.arp -n -a
301 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
302 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
303 # Cannot overwrite a temp cache
304 atf_check -s not-exit:0 -e ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
305 $DEBUG && rump.arp -n -a
307 return 0
310 cleanup()
312 env RUMP_SERVER=$SOCKSRC rump.halt
313 env RUMP_SERVER=$SOCKDST rump.halt
316 dump_src()
318 export RUMP_SERVER=$SOCKSRC
319 rump.netstat -nr
320 rump.arp -n -a
321 rump.ifconfig
322 $HIJACKING dmesg
325 dump_dst()
327 export RUMP_SERVER=$SOCKDST
328 rump.netstat -nr
329 rump.arp -n -a
330 rump.ifconfig
331 $HIJACKING dmesg
334 dump()
336 dump_src
337 dump_dst
338 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
341 cache_expiration_5s_cleanup()
343 $DEBUG && dump
344 cleanup
347 cache_expiration_10s_cleanup()
349 $DEBUG && dump
350 cleanup
353 command_cleanup()
355 $DEBUG && dump
356 cleanup
359 garp_cleanup()
361 $DEBUG && dump_src
362 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
363 env RUMP_SERVER=$SOCKSRC rump.halt
366 cache_overwriting_cleanup()
368 $DEBUG && dump
369 cleanup
372 atf_init_test_cases()
374 atf_add_test_case cache_expiration_5s
375 atf_add_test_case cache_expiration_10s
376 atf_add_test_case command
377 atf_add_test_case garp
378 atf_add_test_case cache_overwriting