t_arp.sh revision 1.35 1 # $NetBSD: t_arp.sh,v 1.35 2018/04/06 09:21:57 ozaki-r Exp $
2 #
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
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.
14 #
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.
26 #
27
28 SOCKSRC=unix://commsock1
29 SOCKDST=unix://commsock2
30 IP4SRC=10.0.1.1
31 IP4SRC2=10.0.1.5
32 IP4NET=10.0.1.0
33 IP4DST=10.0.1.2
34 IP4DST_PROXYARP1=10.0.1.3
35 IP4DST_PROXYARP2=10.0.1.4
36
37 DEBUG=${DEBUG:-false}
38 TIMEOUT=1
39
40 atf_test_case arp_cache_expiration_5s cleanup
41 atf_test_case arp_cache_expiration_10s cleanup
42 atf_test_case arp_command cleanup
43 atf_test_case arp_garp cleanup
44 atf_test_case arp_cache_overwriting cleanup
45 atf_test_case arp_proxy_arp_pub cleanup
46 atf_test_case arp_proxy_arp_pubproxy cleanup
47 atf_test_case arp_link_activation cleanup
48 atf_test_case arp_static cleanup
49
50 arp_cache_expiration_5s_head()
51 {
52 atf_set "descr" "Tests for ARP cache expiration (5s)"
53 atf_set "require.progs" "rump_server"
54 }
55
56 arp_cache_expiration_10s_head()
57 {
58 atf_set "descr" "Tests for ARP cache expiration (10s)"
59 atf_set "require.progs" "rump_server"
60 }
61
62 arp_command_head()
63 {
64 atf_set "descr" "Tests for arp_commands of arp(8)"
65 atf_set "require.progs" "rump_server"
66 }
67
68 arp_garp_head()
69 {
70 atf_set "descr" "Tests for GARP"
71 atf_set "require.progs" "rump_server"
72 }
73
74 arp_cache_overwriting_head()
75 {
76 atf_set "descr" "Tests for behavior of overwriting ARP caches"
77 atf_set "require.progs" "rump_server"
78 }
79
80 arp_proxy_arp_pub_head()
81 {
82 atf_set "descr" "Tests for Proxy ARP (pub)"
83 atf_set "require.progs" "rump_server"
84 }
85
86 arp_proxy_arp_pubproxy_head()
87 {
88 atf_set "descr" "Tests for Proxy ARP (pub proxy)"
89 atf_set "require.progs" "rump_server"
90 }
91
92 arp_link_activation_head()
93 {
94 atf_set "descr" "Tests for activating a new MAC address"
95 atf_set "require.progs" "rump_server"
96 }
97
98 arp_static_head()
99 {
100
101 atf_set "descr" "Tests for static ARP entries"
102 atf_set "require.progs" "rump_server"
103 }
104
105 setup_dst_server()
106 {
107
108 rump_server_add_iface $SOCKDST shmif0 bus1
109 export RUMP_SERVER=$SOCKDST
110 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
111 atf_check -s exit:0 rump.ifconfig shmif0 up
112 atf_check -s exit:0 rump.ifconfig -w 10
113
114 $DEBUG && rump.ifconfig shmif0
115 $DEBUG && rump.arp -n -a
116 $DEBUG && rump.netstat -nr -f inet
117 }
118
119 setup_src_server()
120 {
121 local keep=${1:-0}
122
123 export RUMP_SERVER=$SOCKSRC
124
125 # Adjust ARP parameters
126 if [ $keep != 0 ]; then
127 atf_check -s exit:0 -o ignore \
128 rump.sysctl -w net.inet.arp.keep=$keep
129 fi
130
131 # Setup an interface
132 rump_server_add_iface $SOCKSRC shmif0 bus1
133 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
134 atf_check -s exit:0 rump.ifconfig shmif0 up
135 atf_check -s exit:0 rump.ifconfig -w 10
136
137 # Sanity check
138 $DEBUG && rump.ifconfig shmif0
139 $DEBUG && rump.arp -n -a
140 $DEBUG && rump.netstat -nr -f inet
141 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
142 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
143 }
144
145 test_cache_expiration()
146 {
147 local arp_keep=$1
148 local bonus=2
149
150 rump_server_start $SOCKSRC
151 rump_server_start $SOCKDST
152
153 setup_dst_server
154 setup_src_server $arp_keep
155
156 #
157 # Check if a cache is expired expectedly
158 #
159 export RUMP_SERVER=$SOCKSRC
160 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
161
162 $DEBUG && rump.arp -n -a
163 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
164 # Should be cached
165 atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
166 $DEBUG && rump.netstat -nr -f inet
167 atf_check -s exit:0 -o match:"$IP4DST" rump.netstat -nr -f inet
168
169 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
170
171 $DEBUG && rump.arp -n -a
172 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
173 # Should be expired
174 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
175 }
176
177 arp_cache_expiration_5s_body()
178 {
179
180 test_cache_expiration 5
181 rump_server_destroy_ifaces
182 }
183
184 arp_cache_expiration_10s_body()
185 {
186
187 test_cache_expiration 10
188 rump_server_destroy_ifaces
189 }
190
191 check_arp_static_entry()
192 {
193 local ip=$1
194 local mac=$2
195 local type=$3
196 local flags=
197
198 atf_check -s exit:0 -o match:"$mac" rump.arp -n $ip
199 if [ $type = 'permanent' ]; then
200 atf_check -s exit:0 -o match:'permanent' rump.arp -n $ip
201 check_route $ip "$mac" UHLS shmif0
202 else
203 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n $ip
204 check_route $ip "$mac" UHL shmif0
205 fi
206 }
207
208 arp_command_body()
209 {
210 local arp_keep=5
211 local bonus=2
212
213 rump_server_start $SOCKSRC
214 rump_server_start $SOCKDST
215
216 setup_dst_server
217 setup_src_server $arp_keep
218
219 export RUMP_SERVER=$SOCKSRC
220
221 # Add and delete a static entry
222 $DEBUG && rump.arp -n -a
223 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
224 $DEBUG && rump.arp -n -a
225 $DEBUG && rump.netstat -nr -f inet
226 check_arp_static_entry 10.0.1.10 'b2:a0:20:00:00:10' permanent
227 atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
228 $DEBUG && rump.arp -n -a
229 $DEBUG && rump.netstat -nr -f inet
230 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
231 check_route_no_entry 10.0.1.10
232
233 # Add multiple entries via a file
234 cat - > ./list <<-EOF
235 10.0.1.11 b2:a0:20:00:00:11
236 10.0.1.12 b2:a0:20:00:00:12
237 10.0.1.13 b2:a0:20:00:00:13
238 10.0.1.14 b2:a0:20:00:00:14
239 10.0.1.15 b2:a0:20:00:00:15
240 EOF
241 $DEBUG && rump.arp -n -a
242 $DEBUG && rump.netstat -nr -f inet
243 atf_check -s exit:0 -o ignore rump.arp -f ./list
244 $DEBUG && rump.arp -n -a
245 $DEBUG && rump.netstat -nr -f inet
246 check_arp_static_entry 10.0.1.11 'b2:a0:20:00:00:11' permanent
247 check_arp_static_entry 10.0.1.12 'b2:a0:20:00:00:12' permanent
248 check_arp_static_entry 10.0.1.13 'b2:a0:20:00:00:13' permanent
249 check_arp_static_entry 10.0.1.14 'b2:a0:20:00:00:14' permanent
250 check_arp_static_entry 10.0.1.15 'b2:a0:20:00:00:15' permanent
251
252 # Test arp -a
253 atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
254 atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
255 atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
256 atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
257 atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
258
259 # Flush all entries
260 $DEBUG && rump.arp -n -a
261 $DEBUG && rump.netstat -nr -f inet
262 atf_check -s exit:0 -o ignore rump.arp -d -a
263 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
264 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
265 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
266 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
267 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
268 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
269 check_route_no_entry 10.0.1.11
270 check_route_no_entry 10.0.1.12
271 check_route_no_entry 10.0.1.13
272 check_route_no_entry 10.0.1.14
273 check_route_no_entry 10.0.1.15
274
275 # Test temp option
276 $DEBUG && rump.arp -n -a
277 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
278 $DEBUG && rump.arp -n -a
279 $DEBUG && rump.netstat -nr -f inet
280 check_arp_static_entry 10.0.1.10 'b2:a0:20:00:00:10' temp
281
282 # Hm? the cache doesn't expire...
283 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
284 $DEBUG && rump.arp -n -a
285 $DEBUG && rump.netstat -nr -f inet
286 #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
287
288 rump_server_destroy_ifaces
289 }
290
291 make_pkt_str_arpreq()
292 {
293 local target=$1
294 local sender=$2
295 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP \(0x0806\), length 42:"
296 pkt="$pkt Request who-has $target tell $sender, length 28"
297 echo $pkt
298 }
299
300 arp_garp_body()
301 {
302 local pkt=
303
304 rump_server_start $SOCKSRC
305
306 export RUMP_SERVER=$SOCKSRC
307
308 # Setup an interface
309 rump_server_add_iface $SOCKSRC shmif0 bus1
310 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
311 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
312 atf_check -s exit:0 rump.ifconfig shmif0 up
313 $DEBUG && rump.ifconfig shmif0
314
315 atf_check -s exit:0 sleep 1
316 extract_new_packets bus1 > ./out
317
318 # A GARP packet is sent for the primary address
319 pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
320 atf_check -s exit:0 -o match:"$pkt" cat ./out
321 # No GARP packet is sent for the alias address
322 pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
323 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
324
325 atf_check -s exit:0 rump.ifconfig -w 10
326 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
327 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
328
329 # No GARP packets are sent during IFF_UP
330 extract_new_packets bus1 > ./out
331 pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
332 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
333 pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
334 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
335
336 rump_server_destroy_ifaces
337 }
338
339 arp_cache_overwriting_body()
340 {
341 local bonus=2
342
343 rump_server_start $SOCKSRC
344 rump_server_start $SOCKDST
345
346 setup_dst_server
347 setup_src_server
348
349 export RUMP_SERVER=$SOCKSRC
350
351 # Cannot overwrite a permanent cache
352 atf_check -s exit:0 rump.arp -s $IP4DST b2:a0:20:00:00:ff
353 $DEBUG && rump.arp -n -a
354 atf_check -s not-exit:0 -e match:'File exists' \
355 rump.arp -s $IP4DST b2:a0:20:00:00:fe
356 # cleanup
357 atf_check -s exit:0 rump.arp -d $IP4DST
358
359 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
360 $DEBUG && rump.arp -n -a
361 # Can overwrite a dynamic cache
362 atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
363 $DEBUG && rump.arp -n -a
364 atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
365 atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
366
367 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
368 $DEBUG && rump.arp -n -a
369 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
370 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
371 # Can overwrite a temp cache
372 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
373 atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
374 $DEBUG && rump.arp -n -a
375
376 rump_server_destroy_ifaces
377 }
378
379 make_pkt_str_arprep()
380 {
381 local ip=$1
382 local mac=$2
383 pkt="ethertype ARP (0x0806), length 42: "
384 pkt="Reply $ip is-at $mac, length 28"
385 echo $pkt
386 }
387
388 make_pkt_str_garp()
389 {
390 local ip=$1
391 local mac=$2
392 local pkt=
393 pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
394 pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
395 echo $pkt
396 }
397
398 test_proxy_arp()
399 {
400 local opts= title= flags=
401 local type=$1
402
403 rump_server_start $SOCKSRC
404 rump_server_start $SOCKDST tap
405
406 setup_dst_server
407 setup_src_server
408
409 export RUMP_SERVER=$SOCKDST
410 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
411 macaddr_dst=$(get_macaddr $SOCKDST shmif0)
412
413 if [ "$type" = "pub" ]; then
414 opts="pub"
415 else
416 opts="pub proxy"
417 fi
418 # Always proxy only since migrating to lltable/llentry
419 title='permanent published \(proxy only\)'
420
421 #
422 # Test#1: First setup an endpoint then create proxy arp entry
423 #
424 export RUMP_SERVER=$SOCKDST
425 atf_check -s exit:0 rump.ifconfig tap1 create
426 atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
427 atf_check -s exit:0 rump.ifconfig -w 10
428
429 # Try to ping (should fail w/o proxy arp)
430 export RUMP_SERVER=$SOCKSRC
431 atf_check -s not-exit:0 -o ignore -e ignore \
432 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
433
434 # Flushing
435 extract_new_packets bus1 > ./out
436
437 # Set up proxy ARP entry
438 export RUMP_SERVER=$SOCKDST
439 atf_check -s exit:0 -o ignore \
440 rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
441 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
442
443 # Try to ping
444 export RUMP_SERVER=$SOCKSRC
445 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
446
447 extract_new_packets bus1 > ./out
448 $DEBUG && cat ./out
449
450 pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
451 pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
452 atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
453
454 #
455 # Test#2: Create proxy arp entry then set up an endpoint
456 #
457 export RUMP_SERVER=$SOCKDST
458 atf_check -s exit:0 -o ignore \
459 rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
460 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
461 $DEBUG && rump.netstat -nr -f inet
462
463 # Try to ping (should fail because no endpoint exists)
464 export RUMP_SERVER=$SOCKSRC
465 atf_check -s not-exit:0 -o ignore -e ignore \
466 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
467
468 extract_new_packets bus1 > ./out
469 $DEBUG && cat ./out
470
471 # ARP reply should be sent
472 pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
473 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
474
475 export RUMP_SERVER=$SOCKDST
476 atf_check -s exit:0 rump.ifconfig tap2 create
477 atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
478 atf_check -s exit:0 rump.ifconfig -w 10
479
480 # Try to ping
481 export RUMP_SERVER=$SOCKSRC
482 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
483 }
484
485 arp_proxy_arp_pub_body()
486 {
487
488 test_proxy_arp pub
489 rump_server_destroy_ifaces
490 }
491
492 arp_proxy_arp_pubproxy_body()
493 {
494
495 test_proxy_arp pubproxy
496 rump_server_destroy_ifaces
497 }
498
499 arp_link_activation_body()
500 {
501 local bonus=2
502
503 rump_server_start $SOCKSRC
504 rump_server_start $SOCKDST
505
506 setup_dst_server
507 setup_src_server
508
509 # flush old packets
510 extract_new_packets bus1 > ./out
511
512 export RUMP_SERVER=$SOCKSRC
513
514 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
515 b2:a1:00:00:00:01
516
517 atf_check -s exit:0 sleep 1
518 extract_new_packets bus1 > ./out
519 $DEBUG && cat ./out
520
521 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
522 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
523
524 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
525 b2:a1:00:00:00:02 active
526
527 atf_check -s exit:0 sleep 1
528 extract_new_packets bus1 > ./out
529 $DEBUG && cat ./out
530
531 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
532 atf_check -s exit:0 -o match:"b2:a1:00:00:00:02 $pkt" cat ./out
533
534 rump_server_destroy_ifaces
535 }
536
537 arp_static_body()
538 {
539 local macaddr_src=
540
541 rump_server_start $SOCKSRC
542 rump_server_start $SOCKDST
543
544 setup_dst_server
545 setup_src_server
546
547 macaddr_src=$(get_macaddr $SOCKSRC shmif0)
548
549 # Set a (valid) static ARP entry for the src server
550 export RUMP_SERVER=$SOCKDST
551 $DEBUG && rump.arp -n -a
552 atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
553 $DEBUG && rump.arp -n -a
554
555 # Test receiving an ARP request with the static ARP entry (as spa/sha)
556 export RUMP_SERVER=$SOCKSRC
557 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
558
559 rump_server_destroy_ifaces
560 }
561
562 arp_cache_expiration_5s_cleanup()
563 {
564 $DEBUG && dump
565 cleanup
566 }
567
568 arp_cache_expiration_10s_cleanup()
569 {
570 $DEBUG && dump
571 cleanup
572 }
573
574 arp_command_cleanup()
575 {
576 $DEBUG && dump
577 cleanup
578 }
579
580 arp_garp_cleanup()
581 {
582 $DEBUG && dump
583 cleanup
584 }
585
586 arp_cache_overwriting_cleanup()
587 {
588 $DEBUG && dump
589 cleanup
590 }
591
592 arp_proxy_arp_pub_cleanup()
593 {
594 $DEBUG && dump
595 cleanup
596 }
597
598 arp_proxy_arp_pubproxy_cleanup()
599 {
600 $DEBUG && dump
601 cleanup
602 }
603
604 arp_link_activation_cleanup()
605 {
606 $DEBUG && dump
607 cleanup
608 }
609
610 arp_static_cleanup()
611 {
612 $DEBUG && dump
613 cleanup
614 }
615
616 atf_test_case arp_rtm cleanup
617 arp_rtm_head()
618 {
619
620 atf_set "descr" "Tests for routing messages on operations of ARP entries"
621 atf_set "require.progs" "rump_server"
622 }
623
624 arp_rtm_body()
625 {
626 local macaddr_src= macaddr_dst=
627 local file=./tmp
628 local pid= hdr= what= addr=
629
630 rump_server_start $SOCKSRC
631 rump_server_start $SOCKDST
632
633 setup_dst_server
634 setup_src_server
635
636 macaddr_src=$(get_macaddr $SOCKSRC shmif0)
637 macaddr_dst=$(get_macaddr $SOCKDST shmif0)
638
639 export RUMP_SERVER=$SOCKSRC
640
641 # Test ping and a resulting routing message (RTM_ADD)
642 rump.route -n monitor -c 1 > $file &
643 pid=$!
644 sleep 1
645 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
646 wait $pid
647 $DEBUG && cat $file
648
649 hdr="RTM_ADD.+<UP,HOST,DONE,LLINFO,CLONED>"
650 what="<DST,GATEWAY>"
651 addr="$IP4DST link#2"
652 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
653 cat $file
654
655 # Test arp -d and resulting routing messages (RTM_DELETE)
656 rump.route -n monitor -c 1 > $file &
657 pid=$!
658 sleep 1
659 atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
660 wait $pid
661 $DEBUG && cat $file
662
663 hdr="RTM_DELETE.+<HOST,DONE,LLINFO,CLONED>"
664 what="<DST,GATEWAY>"
665 addr="$IP4DST $macaddr_dst"
666 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
667 grep -A 3 RTM_DELETE $file
668
669 rump_server_destroy_ifaces
670 }
671
672 arp_rtm_cleanup()
673 {
674
675 $DEBUG && dump
676 cleanup
677 }
678
679 atf_test_case arp_purge_on_route_change cleanup
680 arp_purge_on_route_change_head()
681 {
682
683 atf_set "descr" "Tests if ARP entries are removed on route change"
684 atf_set "require.progs" "rump_server"
685 }
686
687 arp_purge_on_route_change_body()
688 {
689
690 rump_server_start $SOCKSRC
691 rump_server_start $SOCKDST
692
693 setup_dst_server
694 setup_src_server
695
696 rump_server_add_iface $SOCKSRC shmif1 bus1
697 export RUMP_SERVER=$SOCKSRC
698 atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
699 atf_check -s exit:0 rump.ifconfig -w 10
700
701 $DEBUG && rump.netstat -nr -f inet
702 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
703 $DEBUG && rump.arp -na
704 atf_check -s exit:0 -o ignore \
705 rump.route change -net $IP4NET -ifp shmif1
706 $DEBUG && rump.netstat -nr -f inet
707 $DEBUG && rump.arp -na
708 # The entry was already removed on route change
709 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
710
711 rump_server_destroy_ifaces
712 }
713
714 arp_purge_on_route_change_cleanup()
715 {
716
717 $DEBUG && dump
718 cleanup
719 }
720
721 atf_test_case arp_purge_on_route_delete cleanup
722 arp_purge_on_route_delete_head()
723 {
724
725 atf_set "descr" "Tests if ARP entries are removed on route delete"
726 atf_set "require.progs" "rump_server"
727 }
728
729 arp_purge_on_route_delete_body()
730 {
731
732 rump_server_start $SOCKSRC
733 rump_server_start $SOCKDST
734
735 setup_dst_server
736 setup_src_server
737
738 $DEBUG && rump.netstat -nr -f inet
739 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
740 $DEBUG && rump.arp -na
741
742 atf_check -s exit:0 -o ignore rump.route delete -net $IP4NET
743 $DEBUG && rump.netstat -nr -f inet
744 $DEBUG && rump.arp -na
745
746 # The entry was already removed on route delete
747 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
748
749 rump_server_destroy_ifaces
750 }
751
752 arp_purge_on_route_delete_cleanup()
753 {
754
755 $DEBUG && dump
756 cleanup
757 }
758
759 atf_test_case arp_purge_on_ifdown cleanup
760 arp_purge_on_ifdown_head()
761 {
762
763 atf_set "descr" "Tests if ARP entries are removed on interface down"
764 atf_set "require.progs" "rump_server"
765 }
766
767 arp_purge_on_ifdown_body()
768 {
769
770 rump_server_start $SOCKSRC
771 rump_server_start $SOCKDST
772
773 setup_dst_server
774 setup_src_server
775
776 $DEBUG && rump.netstat -nr -f inet
777 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
778 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
779
780 # Shutdown the interface
781 atf_check -s exit:0 rump.ifconfig shmif0 down
782 $DEBUG && rump.netstat -nr -f inet
783 $DEBUG && rump.arp -na
784
785 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
786
787 rump_server_destroy_ifaces
788 }
789
790 arp_purge_on_ifdown_cleanup()
791 {
792
793 $DEBUG && dump
794 cleanup
795 }
796
797 atf_test_case arp_stray_entries cleanup
798 arp_stray_entries_head()
799 {
800
801 atf_set "descr" "Tests if ARP entries are removed on route change"
802 atf_set "require.progs" "rump_server"
803 }
804
805 arp_stray_entries_body()
806 {
807
808 rump_server_start $SOCKSRC
809 rump_server_start $SOCKDST
810
811 setup_dst_server
812 setup_src_server
813
814 rump_server_add_iface $SOCKSRC shmif1 bus1
815
816 export RUMP_SERVER=$SOCKSRC
817 atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
818 atf_check -s exit:0 rump.ifconfig -w 10
819
820 $DEBUG && rump.netstat -nr -f inet
821 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
822 $DEBUG && rump.arp -na
823 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
824 atf_check -s exit:0 -o not-match:'shmif1' rump.arp -n $IP4DST
825
826 # Clean up
827 atf_check -s exit:0 -o ignore rump.arp -da
828 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
829
830 # ping from a different source address
831 atf_check -s exit:0 -o ignore \
832 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
833 $DEBUG && rump.arp -na
834 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
835 # ARP reply goes back via shmif1, so a cache is created on shmif1
836 atf_check -s exit:0 -o match:'shmif1' rump.arp -n $IP4DST
837
838 # Clean up by arp -da
839 atf_check -s exit:0 -o ignore rump.arp -da
840 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
841
842 # ping from a different source address again
843 atf_check -s exit:0 -o ignore \
844 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
845 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
846 # ARP reply doen't come
847 atf_check -s exit:0 -o not-match:'shmif1' rump.arp -n $IP4DST
848
849 # Cleanup caches on the destination
850 export RUMP_SERVER=$SOCKDST
851 atf_check -s exit:0 -o ignore rump.arp -da
852 export RUMP_SERVER=$SOCKSRC
853
854 # ping from a different source address again
855 atf_check -s exit:0 -o ignore \
856 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
857 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
858 # ARP reply goes back via shmif1
859 atf_check -s exit:0 -o match:'shmif1' rump.arp -n $IP4DST
860
861 # Clean up by arp -d <ip>
862 atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
863 # Both entries should be deleted
864 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
865
866 rump_server_destroy_ifaces
867 }
868
869 arp_stray_entries_cleanup()
870 {
871
872 $DEBUG && dump
873 cleanup
874 }
875
876 atf_init_test_cases()
877 {
878 atf_add_test_case arp_cache_expiration_5s
879 atf_add_test_case arp_cache_expiration_10s
880 atf_add_test_case arp_command
881 atf_add_test_case arp_garp
882 atf_add_test_case arp_cache_overwriting
883 atf_add_test_case arp_proxy_arp_pub
884 atf_add_test_case arp_proxy_arp_pubproxy
885 atf_add_test_case arp_link_activation
886 atf_add_test_case arp_static
887 atf_add_test_case arp_rtm
888 atf_add_test_case arp_purge_on_route_change
889 atf_add_test_case arp_purge_on_route_delete
890 atf_add_test_case arp_purge_on_ifdown
891 atf_add_test_case arp_stray_entries
892 }
893