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