1 # $NetBSD: t_arp.sh,v 1.22 2016/11/25 08:51: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 SOCKSRC=unix://commsock1
29 SOCKDST=unix://commsock2
32 IP4DST_PROXYARP1=10.0.1.3
33 IP4DST_PROXYARP2=10.0.1.4
38 atf_test_case arp_cache_expiration_5s cleanup
39 atf_test_case arp_cache_expiration_10s cleanup
40 atf_test_case arp_command cleanup
41 atf_test_case arp_garp cleanup
42 atf_test_case arp_cache_overwriting cleanup
43 atf_test_case arp_proxy_arp_pub cleanup
44 atf_test_case arp_proxy_arp_pubproxy cleanup
45 atf_test_case arp_link_activation cleanup
46 atf_test_case arp_static cleanup
48 arp_cache_expiration_5s_head()
50 atf_set "descr" "Tests for ARP cache expiration (5s)"
51 atf_set "require.progs" "rump_server"
54 arp_cache_expiration_10s_head()
56 atf_set "descr" "Tests for ARP cache expiration (10s)"
57 atf_set "require.progs" "rump_server"
62 atf_set "descr" "Tests for arp_commands of arp(8)"
63 atf_set "require.progs" "rump_server"
68 atf_set "descr" "Tests for GARP"
69 atf_set "require.progs" "rump_server"
72 arp_cache_overwriting_head()
74 atf_set "descr" "Tests for behavior of overwriting ARP caches"
75 atf_set "require.progs" "rump_server"
78 arp_proxy_arp_pub_head()
80 atf_set "descr" "Tests for Proxy ARP (pub)"
81 atf_set "require.progs" "rump_server"
84 arp_proxy_arp_pubproxy_head()
86 atf_set "descr" "Tests for Proxy ARP (pub proxy)"
87 atf_set "require.progs" "rump_server"
90 arp_link_activation_head()
92 atf_set "descr" "Tests for activating a new MAC address"
93 atf_set "require.progs" "rump_server"
99 atf_set "descr" "Tests for static ARP entries"
100 atf_set "require.progs" "rump_server"
106 rump_server_add_iface $SOCKDST shmif0 bus1
107 export RUMP_SERVER=$SOCKDST
108 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
109 atf_check -s exit:0 rump.ifconfig shmif0 up
110 atf_check -s exit:0 rump.ifconfig -w 10
112 $DEBUG && rump.ifconfig shmif0
113 $DEBUG && rump.arp -n -a
120 export RUMP_SERVER=$SOCKSRC
122 # Adjust ARP parameters
123 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
126 rump_server_add_iface $SOCKSRC shmif0 bus1
127 atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
128 atf_check -s exit:0 rump.ifconfig shmif0 up
129 atf_check -s exit:0 rump.ifconfig -w 10
132 $DEBUG && rump.ifconfig shmif0
133 $DEBUG && rump.arp -n -a
134 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
135 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
138 test_cache_expiration()
143 rump_server_start $SOCKSRC
144 rump_server_start $SOCKDST
147 setup_src_server $arp_keep
150 # Check if a cache is expired expectedly
152 export RUMP_SERVER=$SOCKSRC
153 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
155 $DEBUG && rump.arp -n -a
156 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
158 atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
160 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
162 $DEBUG && rump.arp -n -a
163 atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
165 atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
168 arp_cache_expiration_5s_body()
171 test_cache_expiration 5
172 rump_server_destroy_ifaces
175 arp_cache_expiration_10s_body()
178 test_cache_expiration 10
179 rump_server_destroy_ifaces
187 rump_server_start $SOCKSRC
188 rump_server_start $SOCKDST
191 setup_src_server $arp_keep
193 export RUMP_SERVER=$SOCKSRC
195 # We can delete the entry for the interface's IP address
196 atf_check -s exit:0 -o ignore rump.arp -d $IP4SRC
198 # Add and delete a static entry
199 $DEBUG && rump.arp -n -a
200 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
201 $DEBUG && rump.arp -n -a
202 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
203 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
204 atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
205 $DEBUG && rump.arp -n -a
206 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
208 # Add multiple entries via a file
209 cat - > ./list <<-EOF
210 10.0.1.11 b2:a0:20:00:00:11
211 10.0.1.12 b2:a0:20:00:00:12
212 10.0.1.13 b2:a0:20:00:00:13
213 10.0.1.14 b2:a0:20:00:00:14
214 10.0.1.15 b2:a0:20:00:00:15
216 $DEBUG && rump.arp -n -a
217 atf_check -s exit:0 -o ignore rump.arp -f ./list
218 $DEBUG && rump.arp -n -a
219 atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
220 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
221 atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
222 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
223 atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
224 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
225 atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
226 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
227 atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
228 atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
231 atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
232 atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
233 atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
234 atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
235 atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
238 $DEBUG && rump.arp -n -a
239 atf_check -s exit:0 -o ignore rump.arp -d -a
240 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
241 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
242 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
243 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
244 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
245 atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
248 $DEBUG && rump.arp -n -a
249 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
250 $DEBUG && rump.arp -n -a
251 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
252 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
254 # Hm? the cache doesn't expire...
255 atf_check -s exit:0 sleep $(($arp_keep + $bonus))
256 $DEBUG && rump.arp -n -a
257 #atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
259 rump_server_destroy_ifaces
262 make_pkt_str_arpreq()
266 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
267 pkt="$pkt Request who-has $target tell $sender, length 28"
275 rump_server_start $SOCKSRC
277 export RUMP_SERVER=$SOCKSRC
280 rump_server_add_iface $SOCKSRC shmif0 bus1
281 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
282 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
283 atf_check -s exit:0 rump.ifconfig shmif0 up
284 $DEBUG && rump.ifconfig shmif0
286 atf_check -s exit:0 sleep 1
287 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
289 # A GARP packet is sent for the primary address
290 pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
291 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
292 # No GARP packet is sent for the alias address
293 pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
294 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
296 atf_check -s exit:0 rump.ifconfig -w 10
297 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
298 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
300 # No GARP packets are sent during IFF_UP
301 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
302 pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
303 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
304 pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
305 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
307 rump_server_destroy_ifaces
310 arp_cache_overwriting_body()
315 rump_server_start $SOCKSRC
316 rump_server_start $SOCKDST
319 setup_src_server $arp_keep
321 export RUMP_SERVER=$SOCKSRC
323 # Cannot overwrite a permanent cache
324 atf_check -s not-exit:0 -e match:'File exists' \
325 rump.arp -s $IP4SRC b2:a0:20:00:00:ff
326 $DEBUG && rump.arp -n -a
328 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
329 $DEBUG && rump.arp -n -a
330 # Can overwrite a dynamic cache
331 atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
332 $DEBUG && rump.arp -n -a
333 atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
334 atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
336 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
337 $DEBUG && rump.arp -n -a
338 atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
339 atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
340 # Can overwrite a temp cache
341 atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
342 atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
343 $DEBUG && rump.arp -n -a
345 rump_server_destroy_ifaces
348 make_pkt_str_arprep()
352 pkt="ethertype ARP (0x0806), length 42: "
353 pkt="Reply $ip is-at $mac, length 28"
362 pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
363 pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
370 local opts= title= flags=
373 rump_server_start $SOCKSRC
374 rump_server_start $SOCKDST tap
377 setup_src_server $arp_keep
379 export RUMP_SERVER=$SOCKDST
380 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
381 macaddr_dst=$(get_macaddr $SOCKDST shmif0)
383 if [ "$type" = "pub" ]; then
385 title="permanent published"
388 title='permanent published \(proxy only\)'
392 # Test#1: First setup an endpoint then create proxy arp entry
394 export RUMP_SERVER=$SOCKDST
395 atf_check -s exit:0 rump.ifconfig tap1 create
396 atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
397 atf_check -s exit:0 rump.ifconfig -w 10
399 # Try to ping (should fail w/o proxy arp)
400 export RUMP_SERVER=$SOCKSRC
401 atf_check -s not-exit:0 -o ignore -e ignore \
402 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
405 extract_new_packets bus1 > ./out
407 # Set up proxy ARP entry
408 export RUMP_SERVER=$SOCKDST
409 atf_check -s exit:0 -o ignore \
410 rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
411 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
414 export RUMP_SERVER=$SOCKSRC
415 if [ "$type" = "pub" ]; then
417 atf_check -s not-exit:0 -o ignore -e ignore \
418 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
420 atf_check -s exit:0 -o ignore \
421 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
424 extract_new_packets bus1 > ./out
427 pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
428 pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
429 if [ "$type" = "pub" ]; then
430 atf_check -s not-exit:0 -x \
431 "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
433 atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
437 # Test#2: Create proxy arp entry then set up an endpoint
439 export RUMP_SERVER=$SOCKDST
440 atf_check -s exit:0 -o ignore \
441 rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
442 atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
443 $DEBUG && rump.netstat -nr -f inet
445 # Try to ping (should fail because no endpoint exists)
446 export RUMP_SERVER=$SOCKSRC
447 atf_check -s not-exit:0 -o ignore -e ignore \
448 rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
450 extract_new_packets bus1 > ./out
453 # ARP reply should be sent
454 pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
455 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
457 export RUMP_SERVER=$SOCKDST
458 atf_check -s exit:0 rump.ifconfig tap2 create
459 atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
460 atf_check -s exit:0 rump.ifconfig -w 10
463 export RUMP_SERVER=$SOCKSRC
464 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
467 arp_proxy_arp_pub_body()
471 rump_server_destroy_ifaces
474 arp_proxy_arp_pubproxy_body()
477 test_proxy_arp pubproxy
478 rump_server_destroy_ifaces
481 arp_link_activation_body()
486 rump_server_start $SOCKSRC
487 rump_server_start $SOCKDST
490 setup_src_server $arp_keep
493 extract_new_packets bus1 > ./out
495 export RUMP_SERVER=$SOCKSRC
497 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
500 atf_check -s exit:0 sleep 1
501 extract_new_packets bus1 > ./out
504 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
505 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
507 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
508 b2:a1:00:00:00:02 active
510 atf_check -s exit:0 sleep 1
511 extract_new_packets bus1 > ./out
514 pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
515 atf_check -s exit:0 -x \
516 "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
518 rump_server_destroy_ifaces
526 rump_server_start $SOCKSRC
527 rump_server_start $SOCKDST
530 setup_src_server $arp_keep
532 macaddr_src=$(get_macaddr $SOCKSRC shmif0)
534 # Set a (valid) static ARP entry for the src server
535 export RUMP_SERVER=$SOCKDST
536 $DEBUG && rump.arp -n -a
537 atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
538 $DEBUG && rump.arp -n -a
540 # Test receiving an ARP request with the static ARP entry (as spa/sha)
541 export RUMP_SERVER=$SOCKSRC
542 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
544 rump_server_destroy_ifaces
547 arp_cache_expiration_5s_cleanup()
553 arp_cache_expiration_10s_cleanup()
559 arp_command_cleanup()
571 arp_cache_overwriting_cleanup()
577 arp_proxy_arp_pub_cleanup()
583 arp_proxy_arp_pubproxy_cleanup()
589 arp_link_activation_cleanup()
601 atf_init_test_cases()
603 atf_add_test_case arp_cache_expiration_5s
604 atf_add_test_case arp_cache_expiration_10s
605 atf_add_test_case arp_command
606 atf_add_test_case arp_garp
607 atf_add_test_case arp_cache_overwriting
608 atf_add_test_case arp_proxy_arp_pub
609 atf_add_test_case arp_proxy_arp_pubproxy
610 atf_add_test_case arp_link_activation
611 atf_add_test_case arp_static