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