1 # $NetBSD: t_arp.sh,v 1.16 2016/06/21 05:04:16 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 inetserver="$inetserver -lrumpdev -lrumpnet_tap"
30 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
32 SOCKSRC=unix://commsock1
33 SOCKDST=unix://commsock2
36 IP4DST_PROXYARP1=10.0.1.3
37 IP4DST_PROXYARP2=10.0.1.4
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_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
52 arp_cache_expiration_5s_head()
54 atf_set "descr" "Tests for ARP cache expiration (5s)"
55 atf_set "require.progs" "rump_server"
58 arp_cache_expiration_10s_head()
60 atf_set "descr" "Tests for ARP cache expiration (10s)"
61 atf_set "require.progs" "rump_server"
66 atf_set "descr" "Tests for arp_commands of arp(8)"
67 atf_set "require.progs" "rump_server"
72 atf_set "descr" "Tests for GARP"
73 atf_set "require.progs" "rump_server"
76 arp_cache_overwriting_head()
78 atf_set "descr" "Tests for behavior of overwriting ARP caches"
79 atf_set "require.progs" "rump_server"
82 arp_proxy_arp_pub_head()
84 atf_set "descr" "Tests for Proxy ARP (pub)"
85 atf_set "require.progs" "rump_server"
88 arp_proxy_arp_pubproxy_head()
90 atf_set "descr" "Tests for Proxy ARP (pub proxy)"
91 atf_set "require.progs" "rump_server"
94 arp_link_activation_head()
96 atf_set "descr" "Tests for activating a new MAC address"
97 atf_set "require.progs" "rump_server"
103 atf_set "descr" "Tests for static ARP entries"
104 atf_set "require.progs" "rump_server"
109 export RUMP_SERVER=$SOCKDST
110 atf_check -s exit:0 rump.ifconfig shmif0 create
111 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
112 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
113 atf_check -s exit:0 rump.ifconfig shmif0 up
114 atf_check -s exit:0 rump.ifconfig -w 10
116 $DEBUG && rump.ifconfig shmif0
117 $DEBUG && rump.arp -n -a
124 export RUMP_SERVER=$SOCKSRC
126 # Adjust ARP parameters
127 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
130 atf_check -s exit:0 rump.ifconfig shmif0 create
131 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
132 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
133 atf_check -s exit:0 rump.ifconfig shmif0 up
134 atf_check -s exit:0 rump.ifconfig -w 10
137 $DEBUG && rump.ifconfig shmif0
138 $DEBUG && rump.arp -n -a
139 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
140 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
143 test_cache_expiration()
148 atf_check -s exit:0 ${inetserver} $SOCKSRC
149 atf_check -s exit:0 ${inetserver} $SOCKDST
152 setup_src_server $arp_keep
155 # Check if a cache is expired expectedly
157 export RUMP_SERVER=$SOCKSRC
158 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
160 $DEBUG && rump.arp -n -a
161 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
163 atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
165 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
167 $DEBUG && rump.arp -n -a
168 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
170 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
173 arp_cache_expiration_5s_body()
175 test_cache_expiration 5
178 arp_cache_expiration_10s_body()
180 test_cache_expiration 10
188 atf_check -s exit:0 ${inetserver} $SOCKSRC
189 atf_check -s exit:0 ${inetserver} $SOCKDST
192 setup_src_server $arp_keep
194 export RUMP_SERVER=$SOCKSRC
196 # We can delete the entry for the interface's IP address
197 atf_check -s exit:0 -o ignore rump.arp -d $IP4SRC
199 # Add and delete a static entry
200 $DEBUG && rump.arp -n -a
201 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
202 $DEBUG && rump.arp -n -a
203 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
204 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
205 atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
206 $DEBUG && rump.arp -n -a
207 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
209 # Add multiple entries via a file
210 cat - > ./list <<-EOF
211 10.0.1.11 b2:a0:20:00:00:11
212 10.0.1.12 b2:a0:20:00:00:12
213 10.0.1.13 b2:a0:20:00:00:13
214 10.0.1.14 b2:a0:20:00:00:14
215 10.0.1.15 b2:a0:20:00:00:15
217 $DEBUG && rump.arp -n -a
218 atf_check -s exit:0 -o ignore rump.arp -f ./list
219 $DEBUG && rump.arp -n -a
220 atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
221 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
222 atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
223 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
224 atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
225 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
226 atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
227 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
228 atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
229 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
232 atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
233 atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
234 atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
235 atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
236 atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
239 $DEBUG && rump.arp -n -a
240 atf_check -s exit:0 -o ignore rump.arp -d -a
241 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
242 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
243 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
244 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
245 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
246 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
249 $DEBUG && rump.arp -n -a
250 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
251 $DEBUG && rump.arp -n -a
252 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
253 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
255 # Hm? the cache doesn't expire...
256 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
257 $DEBUG && rump.arp -n -a
258 #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
263 make_pkt_str_arpreq()
267 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
268 pkt="$pkt Request who-has $target tell $sender, length 28"
276 atf_check -s exit:0 ${inetserver} $SOCKSRC
277 export RUMP_SERVER=$SOCKSRC
280 atf_check -s exit:0 rump.ifconfig shmif0 create
281 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
282 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
283 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
284 atf_check -s exit:0 rump.ifconfig shmif0 up
285 $DEBUG && rump.ifconfig shmif0
287 atf_check -s exit:0 sleep 1
288 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
290 # A GARP packet is sent for the primary address
291 pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
292 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
293 # No GARP packet is sent for the alias address
294 pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
295 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
297 atf_check -s exit:0 rump.ifconfig -w 10
298 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
299 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
301 # No GARP packets are sent during IFF_UP
302 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
303 pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
304 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
305 pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
306 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
309 arp_cache_overwriting_body()
314 atf_check -s exit:0 ${inetserver} $SOCKSRC
315 atf_check -s exit:0 ${inetserver} $SOCKDST
318 setup_src_server $arp_keep
320 export RUMP_SERVER=$SOCKSRC
322 # Cannot overwrite a permanent cache
323 atf_check -s not-exit:0 -e match:'File exists' \
324 rump.arp -s $IP4SRC b2:a0:20:00:00:ff
325 $DEBUG && rump.arp -n -a
327 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
328 $DEBUG && rump.arp -n -a
329 # Can overwrite a dynamic cache
330 atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
331 $DEBUG && rump.arp -n -a
332 atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
333 atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
335 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
336 $DEBUG && rump.arp -n -a
337 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
338 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
339 # Can overwrite a temp cache
340 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
341 atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
342 $DEBUG && rump.arp -n -a
347 make_pkt_str_arprep()
351 pkt="ethertype ARP (0x0806), length 42: "
352 pkt="Reply $ip is-at $mac, length 28"
361 pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
362 pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
366 extract_new_packets()
370 if [ ! -f $old ]; then
374 shmif_dumpbus -p - bus1 2>/dev/null| \
375 tcpdump -n -e -r - 2>/dev/null > ./new
376 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
384 local opts= title= flags=
387 atf_check -s exit:0 ${inetserver} $SOCKSRC
388 atf_check -s exit:0 ${inetserver} $SOCKDST
391 setup_src_server $arp_keep
393 export RUMP_SERVER=$SOCKDST
394 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
395 macaddr_dst=$(rump.ifconfig shmif0 |awk '/address/ {print $2;}')
397 if [ "$type" = "pub" ]; then
399 title="permanent published"
402 title='permanent published \(proxy only\)'
406 # Test#1: First setup an endpoint then create proxy arp entry
408 export RUMP_SERVER=$SOCKDST
409 atf_check -s exit:0 rump.ifconfig tap1 create
410 atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
411 atf_check -s exit:0 rump.ifconfig -w 10
413 # Try to ping (should fail w/o proxy arp)
414 export RUMP_SERVER=$SOCKSRC
415 atf_check -s not-exit:0 -o ignore -e ignore \
416 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
419 extract_new_packets > ./out
421 # Set up proxy ARP entry
422 export RUMP_SERVER=$SOCKDST
423 atf_check -s exit:0 -o ignore \
424 rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
425 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
428 export RUMP_SERVER=$SOCKSRC
429 if [ "$type" = "pub" ]; then
431 atf_check -s not-exit:0 -o ignore -e ignore \
432 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
434 atf_check -s exit:0 -o ignore \
435 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
438 extract_new_packets > ./out
441 pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
442 pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
443 if [ "$type" = "pub" ]; then
444 atf_check -s not-exit:0 -x \
445 "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
447 atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
451 # Test#2: Create proxy arp entry then set up an endpoint
453 export RUMP_SERVER=$SOCKDST
454 atf_check -s exit:0 -o ignore \
455 rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
456 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
457 $DEBUG && rump.netstat -nr -f inet
459 # Try to ping (should fail because no endpoint exists)
460 export RUMP_SERVER=$SOCKSRC
461 atf_check -s not-exit:0 -o ignore -e ignore \
462 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
464 extract_new_packets > ./out
467 # ARP reply should be sent
468 pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
469 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
471 export RUMP_SERVER=$SOCKDST
472 atf_check -s exit:0 rump.ifconfig tap2 create
473 atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
474 atf_check -s exit:0 rump.ifconfig -w 10
477 export RUMP_SERVER=$SOCKSRC
478 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
481 arp_proxy_arp_pub_body()
487 arp_proxy_arp_pubproxy_body()
490 test_proxy_arp pubproxy
493 arp_link_activation_body()
498 atf_check -s exit:0 ${inetserver} $SOCKSRC
499 atf_check -s exit:0 ${inetserver} $SOCKDST
502 setup_src_server $arp_keep
505 extract_new_packets > ./out
507 export RUMP_SERVER=$SOCKSRC
509 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
512 atf_check -s exit:0 sleep 1
513 extract_new_packets > ./out
516 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
517 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
519 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
520 b2:a1:00:00:00:02 active
522 atf_check -s exit:0 sleep 1
523 extract_new_packets > ./out
526 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
527 atf_check -s exit:0 -x \
528 "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
536 atf_check -s exit:0 ${inetserver} $SOCKSRC
537 atf_check -s exit:0 ${inetserver} $SOCKDST
540 setup_src_server $arp_keep
542 export RUMP_SERVER=$SOCKSRC
543 macaddr_src=$(rump.ifconfig shmif0 |awk '/address/ {print $2;}')
545 # Set a (valid) static ARP entry for the src server
546 export RUMP_SERVER=$SOCKDST
547 $DEBUG && rump.arp -n -a
548 atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
549 $DEBUG && rump.arp -n -a
551 # Test receiving an ARP request with the static ARP entry (as spa/sha)
552 export RUMP_SERVER=$SOCKSRC
553 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
558 env RUMP_SERVER=$SOCKSRC rump.halt
559 env RUMP_SERVER=$SOCKDST rump.halt
564 export RUMP_SERVER=$SOCKSRC
573 export RUMP_SERVER=$SOCKDST
584 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
587 arp_cache_expiration_5s_cleanup()
593 arp_cache_expiration_10s_cleanup()
599 arp_command_cleanup()
608 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
609 env RUMP_SERVER=$SOCKSRC rump.halt
612 arp_cache_overwriting_cleanup()
618 arp_proxy_arp_pub_cleanup()
624 arp_proxy_arp_pubproxy_cleanup()
630 arp_link_activation_cleanup()
642 atf_init_test_cases()
644 atf_add_test_case arp_cache_expiration_5s
645 atf_add_test_case arp_cache_expiration_10s
646 atf_add_test_case arp_command
647 atf_add_test_case arp_garp
648 atf_add_test_case arp_cache_overwriting
649 atf_add_test_case arp_proxy_arp_pub
650 atf_add_test_case arp_proxy_arp_pubproxy
651 atf_add_test_case arp_link_activation
652 atf_add_test_case arp_static