t_arp.sh revision 1.46 1 # $NetBSD: t_arp.sh,v 1.46 2024/08/20 08:23:15 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 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 #
387 # GARP on Link up
388 #
389 atf_check -s exit:0 rump.ifconfig shmif0 media none
390 extract_new_packets bus1 > ./out
391 atf_check -s exit:0 rump.ifconfig shmif0 media auto
392
393 atf_check -s exit:0 sleep 1
394 extract_new_packets bus1 > ./out
395
396 if $no_dad; then
397 # A GARP packet is sent for both primary and alias addresses.
398 pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
399 atf_check -s exit:0 -o match:"$pkt" cat ./out
400 pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
401 atf_check -s exit:0 -o match:"$pkt" cat ./out
402 else
403 # No GARP is sent.
404 pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
405 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
406 pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
407 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
408 # DAD packets are sent instead.
409 pkt=$(make_pkt_str_arpreq 10.0.0.3 0.0.0.0)
410 atf_check -s exit:0 -o match:"$pkt" cat ./out
411 pkt=$(make_pkt_str_arpreq 10.0.0.4 0.0.0.0)
412 atf_check -s exit:0 -o match:"$pkt" cat ./out
413 fi
414
415 rump_server_destroy_ifaces
416 }
417
418 arp_garp_body()
419 {
420
421 test_garp_common false
422 }
423
424 arp_garp_without_dad_body()
425 {
426
427 test_garp_common true
428 }
429
430 arp_cache_overwriting_body()
431 {
432
433 rump_server_start $SOCKSRC
434 rump_server_start $SOCKDST
435
436 setup_dst_server
437 setup_src_server
438
439 export RUMP_SERVER=$SOCKSRC
440
441 # Cannot overwrite a permanent cache
442 atf_check -s exit:0 rump.arp -s $IP4DST b2:a0:20:00:00:ff
443 $DEBUG && rump.arp -n -a
444 atf_check -s not-exit:0 -e match:'File exists' \
445 rump.arp -s $IP4DST b2:a0:20:00:00:fe
446 # cleanup
447 atf_check -s exit:0 rump.arp -d $IP4DST
448
449 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
450 $DEBUG && rump.arp -n -a
451 # Can overwrite a dynamic cache
452 atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
453 $DEBUG && rump.arp -n -a
454 atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
455 atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
456
457 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
458 $DEBUG && rump.arp -n -a
459 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
460 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
461 # Can overwrite a temp cache
462 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
463 atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
464 $DEBUG && rump.arp -n -a
465
466 rump_server_destroy_ifaces
467 }
468
469 make_pkt_str_arprep()
470 {
471 local ip=$1
472 local mac=$2
473 pkt="ethertype ARP (0x0806), length 42: "
474 pkt="Reply $ip is-at $mac, length 28"
475 echo $pkt
476 }
477
478 make_pkt_str_garp()
479 {
480 local ip=$1
481 local mac=$2
482 local pkt=
483 pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
484 pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
485 echo $pkt
486 }
487
488 test_proxy_arp()
489 {
490 local opts= title= flags=
491 local type=$1
492
493 rump_server_start $SOCKSRC
494 rump_server_fs_start $SOCKDST tap
495
496 setup_dst_server
497 setup_src_server
498
499 export RUMP_SERVER=$SOCKDST
500 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
501 macaddr_dst=$(get_macaddr $SOCKDST shmif0)
502
503 if [ "$type" = "pub" ]; then
504 opts="pub"
505 else
506 opts="pub proxy"
507 fi
508 # Always proxy only since migrating to lltable/llentry
509 title='published \(proxy only\)'
510
511 #
512 # Test#1: First setup an endpoint then create proxy arp entry
513 #
514 export RUMP_SERVER=$SOCKDST
515 rump_server_add_iface $SOCKDST tap1
516 atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
517 atf_check -s exit:0 rump.ifconfig -w 10
518
519 # Try to ping (should fail w/o proxy arp)
520 export RUMP_SERVER=$SOCKSRC
521 atf_check -s not-exit:0 -o ignore -e ignore \
522 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
523 # Remove ARP entry as it may hang around in WAITDELETE a few seconds
524 atf_check -s ignore rump.arp -d $IP4DST_PROXYARP1
525
526 # Flushing
527 extract_new_packets bus1 > ./out
528
529 # Set up proxy ARP entry
530 export RUMP_SERVER=$SOCKDST
531 atf_check -s exit:0 -o ignore \
532 rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
533 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
534
535 # Try to ping
536 export RUMP_SERVER=$SOCKSRC
537 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
538
539 extract_new_packets bus1 > ./out
540 $DEBUG && cat ./out
541
542 pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
543 pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
544 atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
545
546 #
547 # Test#2: Create proxy arp entry then set up an endpoint
548 #
549 export RUMP_SERVER=$SOCKDST
550 atf_check -s exit:0 -o ignore \
551 rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
552 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
553 $DEBUG && rump.netstat -nr -f inet
554
555 # Try to ping (should fail because no endpoint exists)
556 export RUMP_SERVER=$SOCKSRC
557 atf_check -s not-exit:0 -o ignore -e ignore \
558 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
559 # Remove ARP entry as it may hang around in WAITDELETE a few seconds
560 atf_check -s ignore rump.arp -d $IP4DST_PROXYARP2
561
562 extract_new_packets bus1 > ./out
563 $DEBUG && cat ./out
564
565 # ARP reply should be sent
566 pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
567 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
568
569 export RUMP_SERVER=$SOCKDST
570 rump_server_add_iface $SOCKDST tap2
571 atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
572 atf_check -s exit:0 rump.ifconfig -w 10
573
574 # Try to ping
575 export RUMP_SERVER=$SOCKSRC
576 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
577 }
578
579 arp_proxy_arp_pub_body()
580 {
581
582 test_proxy_arp pub
583 rump_server_destroy_ifaces
584 }
585
586 arp_proxy_arp_pubproxy_body()
587 {
588
589 test_proxy_arp pubproxy
590 rump_server_destroy_ifaces
591 }
592
593 arp_link_activation_body()
594 {
595
596 rump_server_start $SOCKSRC
597 rump_server_start $SOCKDST
598
599 setup_dst_server
600 setup_src_server
601
602 # flush old packets
603 extract_new_packets bus1 > ./out
604
605 export RUMP_SERVER=$SOCKSRC
606
607 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
608 b2:a1:00:00:00:01
609
610 atf_check -s exit:0 sleep 1
611 extract_new_packets bus1 > ./out
612 $DEBUG && cat ./out
613
614 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
615 atf_check -s exit:0 -o not-match:"$pkt" cat ./out
616
617 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
618 b2:a1:00:00:00:02 active
619
620 atf_check -s exit:0 sleep 1
621 extract_new_packets bus1 > ./out
622 $DEBUG && cat ./out
623
624 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
625 atf_check -s exit:0 -o match:"b2:a1:00:00:00:02 $pkt" cat ./out
626
627 rump_server_destroy_ifaces
628 }
629
630 arp_static_body()
631 {
632 local macaddr_src=
633
634 rump_server_start $SOCKSRC
635 rump_server_start $SOCKDST
636
637 setup_dst_server
638 setup_src_server
639
640 macaddr_src=$(get_macaddr $SOCKSRC shmif0)
641
642 # Set a (valid) static ARP entry for the src server
643 export RUMP_SERVER=$SOCKDST
644 $DEBUG && rump.arp -n -a
645 atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
646 $DEBUG && rump.arp -n -a
647
648 # Test receiving an ARP request with the static ARP entry (as spa/sha)
649 export RUMP_SERVER=$SOCKSRC
650 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
651
652 rump_server_destroy_ifaces
653 }
654
655 arp_cache_expiration_cleanup()
656 {
657 $DEBUG && dump
658 cleanup
659 }
660
661 arp_command_cleanup()
662 {
663 $DEBUG && dump
664 cleanup
665 }
666
667 arp_garp_cleanup()
668 {
669 $DEBUG && dump
670 cleanup
671 }
672
673 arp_garp_without_dad_cleanup()
674 {
675
676 $DEBUG && dump
677 cleanup
678 }
679
680 arp_cache_overwriting_cleanup()
681 {
682 $DEBUG && dump
683 cleanup
684 }
685
686 arp_proxy_arp_pub_cleanup()
687 {
688 $DEBUG && dump
689 cleanup
690 }
691
692 arp_proxy_arp_pubproxy_cleanup()
693 {
694 $DEBUG && dump
695 cleanup
696 }
697
698 arp_link_activation_cleanup()
699 {
700 $DEBUG && dump
701 cleanup
702 }
703
704 arp_static_cleanup()
705 {
706 $DEBUG && dump
707 cleanup
708 }
709
710 atf_test_case arp_rtm cleanup
711 arp_rtm_head()
712 {
713
714 atf_set "descr" "Tests for routing messages on operations of ARP entries"
715 atf_set "require.progs" "rump_server"
716 }
717
718 arp_rtm_body()
719 {
720 local macaddr_src= macaddr_dst=
721 local file=./tmp
722 local pid= hdr= what= addr=
723
724 rump_server_start $SOCKSRC
725 rump_server_start $SOCKDST
726
727 setup_dst_server
728 setup_src_server
729
730 macaddr_src=$(get_macaddr $SOCKSRC shmif0)
731 macaddr_dst=$(get_macaddr $SOCKDST shmif0)
732
733 export RUMP_SERVER=$SOCKSRC
734
735 # Test ping and a resulting routing message (RTM_ADD)
736 rump.route -n monitor -c 1 > $file &
737 pid=$!
738 sleep 1
739 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
740 wait $pid
741 $DEBUG && cat $file
742
743 hdr="RTM_ADD.+<UP,HOST,DONE,LLINFO,CLONED>"
744 what="<DST,GATEWAY>"
745 addr="$IP4DST $macaddr_dst"
746 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
747 cat $file
748
749 # Test ping and a resulting routing message (RTM_MISS) on subnet
750 rump.route -n monitor -c 1 > $file &
751 pid=$!
752 sleep 1
753 atf_check -s exit:2 -o ignore -e ignore \
754 rump.ping -n -w 1 -c 1 $IP4DST_FAIL1
755 wait $pid
756 $DEBUG && cat $file
757
758 hdr="RTM_MISS.+<DONE>"
759 what="<DST,GATEWAY,AUTHOR>"
760 addr="$IP4DST_FAIL1 link#2 $IP4SRC"
761 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
762 cat $file
763
764 # Test ping and a resulting routing message (RTM_MISS) off subnet
765 rump.route -n monitor -c 1 > $file &
766 pid=$!
767 sleep 1
768 atf_check -s exit:2 -o ignore -e ignore \
769 rump.ping -n -w 1 -c 1 $IP4DST_FAIL2
770 wait $pid
771 $DEBUG && cat $file
772
773 hdr="RTM_MISS.+<DONE>"
774 what="<DST>"
775 addr="$IP4DST_FAIL2"
776 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
777 cat $file
778
779 # Test arp -d and resulting routing messages (RTM_DELETE)
780 rump.route -n monitor -c 1 > $file &
781 pid=$!
782 sleep 1
783 atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
784 wait $pid
785 $DEBUG && cat $file
786
787 hdr="RTM_DELETE.+<HOST,DONE,LLINFO,CLONED>"
788 what="<DST,GATEWAY>"
789 addr="$IP4DST $macaddr_dst"
790 atf_check -s exit:0 -o match:"$hdr" -o match:"$what" -o match:"$addr" \
791 grep -A 3 RTM_DELETE $file
792
793 rump_server_destroy_ifaces
794 }
795
796 arp_rtm_cleanup()
797 {
798
799 $DEBUG && dump
800 cleanup
801 }
802
803 atf_test_case arp_purge_on_route_change cleanup
804 arp_purge_on_route_change_head()
805 {
806
807 atf_set "descr" "Tests if ARP entries are removed on route change"
808 atf_set "require.progs" "rump_server"
809 }
810
811 arp_purge_on_route_change_body()
812 {
813
814 rump_server_start $SOCKSRC
815 rump_server_start $SOCKDST
816
817 setup_dst_server
818 setup_src_server
819
820 rump_server_add_iface $SOCKSRC shmif1 bus1
821 export RUMP_SERVER=$SOCKSRC
822 atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
823 atf_check -s exit:0 rump.ifconfig -w 10
824
825 $DEBUG && rump.netstat -nr -f inet
826 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
827 $DEBUG && rump.arp -na
828 atf_check -s exit:0 -o ignore \
829 rump.route change -net $IP4NET -ifp shmif1
830 $DEBUG && rump.netstat -nr -f inet
831 $DEBUG && rump.arp -na
832 # The entry was already removed on route change
833 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
834
835 rump_server_destroy_ifaces
836 }
837
838 arp_purge_on_route_change_cleanup()
839 {
840
841 $DEBUG && dump
842 cleanup
843 }
844
845 atf_test_case arp_purge_on_route_delete cleanup
846 arp_purge_on_route_delete_head()
847 {
848
849 atf_set "descr" "Tests if ARP entries are removed on route delete"
850 atf_set "require.progs" "rump_server"
851 }
852
853 arp_purge_on_route_delete_body()
854 {
855
856 rump_server_start $SOCKSRC
857 rump_server_start $SOCKDST
858
859 setup_dst_server
860 setup_src_server
861
862 $DEBUG && rump.netstat -nr -f inet
863 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
864 $DEBUG && rump.arp -na
865
866 atf_check -s exit:0 -o ignore rump.route delete -net $IP4NET
867 $DEBUG && rump.netstat -nr -f inet
868 $DEBUG && rump.arp -na
869
870 # The entry was already removed on route delete
871 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
872
873 rump_server_destroy_ifaces
874 }
875
876 arp_purge_on_route_delete_cleanup()
877 {
878
879 $DEBUG && dump
880 cleanup
881 }
882
883 atf_test_case arp_purge_on_ifdown cleanup
884 arp_purge_on_ifdown_head()
885 {
886
887 atf_set "descr" "Tests if ARP entries are removed on interface down"
888 atf_set "require.progs" "rump_server"
889 }
890
891 arp_purge_on_ifdown_body()
892 {
893
894 rump_server_start $SOCKSRC
895 rump_server_start $SOCKDST
896
897 setup_dst_server
898 setup_src_server
899
900 $DEBUG && rump.netstat -nr -f inet
901 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
902 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
903
904 # Shutdown the interface
905 atf_check -s exit:0 rump.ifconfig shmif0 down
906 $DEBUG && rump.netstat -nr -f inet
907 $DEBUG && rump.arp -na
908
909 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
910
911 rump_server_destroy_ifaces
912 }
913
914 arp_purge_on_ifdown_cleanup()
915 {
916
917 $DEBUG && dump
918 cleanup
919 }
920
921 atf_test_case arp_stray_entries cleanup
922 arp_stray_entries_head()
923 {
924
925 atf_set "descr" "Tests if ARP entries are removed on route change"
926 atf_set "require.progs" "rump_server"
927 }
928
929 arp_stray_entries_body()
930 {
931
932 rump_server_start $SOCKSRC
933 rump_server_start $SOCKDST
934
935 setup_dst_server
936 setup_src_server
937
938 rump_server_add_iface $SOCKSRC shmif1 bus1
939
940 export RUMP_SERVER=$SOCKSRC
941 atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
942 atf_check -s exit:0 rump.ifconfig -w 10
943
944 $DEBUG && rump.netstat -nr -f inet
945 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
946 $DEBUG && rump.arp -na
947 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
948 atf_check -s exit:0 -o not-match:'shmif1' rump.arp -n $IP4DST
949
950 # Clean up
951 atf_check -s exit:0 -o ignore rump.arp -da
952 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
953
954 # ping from a different source address
955 atf_check -s exit:0 -o ignore \
956 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
957 $DEBUG && rump.arp -na
958 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
959 # ARP reply goes back via shmif1, so a cache is created on shmif1
960 atf_check -s exit:0 -o match:'shmif1' rump.arp -n $IP4DST
961
962 # Clean up by arp -da
963 atf_check -s exit:0 -o ignore rump.arp -da
964 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
965
966 # ping from a different source address again
967 atf_check -s exit:0 -o ignore \
968 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
969 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
970 # ARP reply doen't come
971 atf_check -s exit:0 -o not-match:'shmif1' rump.arp -n $IP4DST
972
973 # Cleanup caches on the destination
974 export RUMP_SERVER=$SOCKDST
975 atf_check -s exit:0 -o ignore rump.arp -da
976 export RUMP_SERVER=$SOCKSRC
977
978 # ping from a different source address again
979 atf_check -s exit:0 -o ignore \
980 rump.ping -n -w 1 -c 1 -I $IP4SRC2 $IP4DST
981 atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
982 # ARP reply goes back via shmif1
983 atf_check -s exit:0 -o match:'shmif1' rump.arp -n $IP4DST
984
985 # Clean up by arp -d <ip>
986 atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
987 # Both entries should be deleted
988 atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
989
990 rump_server_destroy_ifaces
991 }
992
993 arp_stray_entries_cleanup()
994 {
995
996 $DEBUG && dump
997 cleanup
998 }
999
1000 atf_init_test_cases()
1001 {
1002 atf_add_test_case arp_cache_expiration
1003 atf_add_test_case arp_command
1004 atf_add_test_case arp_garp
1005 atf_add_test_case arp_garp_without_dad
1006 atf_add_test_case arp_cache_overwriting
1007 atf_add_test_case arp_proxy_arp_pub
1008 atf_add_test_case arp_proxy_arp_pubproxy
1009 atf_add_test_case arp_link_activation
1010 atf_add_test_case arp_static
1011 atf_add_test_case arp_rtm
1012 atf_add_test_case arp_purge_on_route_change
1013 atf_add_test_case arp_purge_on_route_delete
1014 atf_add_test_case arp_purge_on_ifdown
1015 atf_add_test_case arp_stray_entries
1016 }
1017