Home | History | Annotate | Line # | Download | only in arp
t_arp.sh revision 1.28
      1 #	$NetBSD: t_arp.sh,v 1.28 2017/06/26 03:13:40 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 
     37 DEBUG=${DEBUG:-false}
     38 TIMEOUT=1
     39 
     40 atf_test_case arp_cache_expiration_5s cleanup
     41 atf_test_case arp_cache_expiration_10s cleanup
     42 atf_test_case arp_command cleanup
     43 atf_test_case arp_garp cleanup
     44 atf_test_case arp_cache_overwriting cleanup
     45 atf_test_case arp_proxy_arp_pub cleanup
     46 atf_test_case arp_proxy_arp_pubproxy cleanup
     47 atf_test_case arp_link_activation cleanup
     48 atf_test_case arp_static cleanup
     49 
     50 arp_cache_expiration_5s_head()
     51 {
     52 	atf_set "descr" "Tests for ARP cache expiration (5s)"
     53 	atf_set "require.progs" "rump_server"
     54 }
     55 
     56 arp_cache_expiration_10s_head()
     57 {
     58 	atf_set "descr" "Tests for ARP cache expiration (10s)"
     59 	atf_set "require.progs" "rump_server"
     60 }
     61 
     62 arp_command_head()
     63 {
     64 	atf_set "descr" "Tests for arp_commands of arp(8)"
     65 	atf_set "require.progs" "rump_server"
     66 }
     67 
     68 arp_garp_head()
     69 {
     70 	atf_set "descr" "Tests for GARP"
     71 	atf_set "require.progs" "rump_server"
     72 }
     73 
     74 arp_cache_overwriting_head()
     75 {
     76 	atf_set "descr" "Tests for behavior of overwriting ARP caches"
     77 	atf_set "require.progs" "rump_server"
     78 }
     79 
     80 arp_proxy_arp_pub_head()
     81 {
     82 	atf_set "descr" "Tests for Proxy ARP (pub)"
     83 	atf_set "require.progs" "rump_server"
     84 }
     85 
     86 arp_proxy_arp_pubproxy_head()
     87 {
     88 	atf_set "descr" "Tests for Proxy ARP (pub proxy)"
     89 	atf_set "require.progs" "rump_server"
     90 }
     91 
     92 arp_link_activation_head()
     93 {
     94 	atf_set "descr" "Tests for activating a new MAC address"
     95 	atf_set "require.progs" "rump_server"
     96 }
     97 
     98 arp_static_head()
     99 {
    100 
    101 	atf_set "descr" "Tests for static ARP entries"
    102 	atf_set "require.progs" "rump_server"
    103 }
    104 
    105 setup_dst_server()
    106 {
    107 
    108 	rump_server_add_iface $SOCKDST shmif0 bus1
    109 	export RUMP_SERVER=$SOCKDST
    110 	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
    111 	atf_check -s exit:0 rump.ifconfig shmif0 up
    112 	atf_check -s exit:0 rump.ifconfig -w 10
    113 
    114 	$DEBUG && rump.ifconfig shmif0
    115 	$DEBUG && rump.arp -n -a
    116 }
    117 
    118 setup_src_server()
    119 {
    120 	local keep=${1:-0}
    121 
    122 	export RUMP_SERVER=$SOCKSRC
    123 
    124 	# Adjust ARP parameters
    125 	if [ $keep != 0 ]; then
    126 		atf_check -s exit:0 -o ignore \
    127 		    rump.sysctl -w net.inet.arp.keep=$keep
    128 	fi
    129 
    130 	# Setup an interface
    131 	rump_server_add_iface $SOCKSRC shmif0 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
    135 
    136 	# Sanity check
    137 	$DEBUG && rump.ifconfig shmif0
    138 	$DEBUG && rump.arp -n -a
    139 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    140 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    141 }
    142 
    143 test_cache_expiration()
    144 {
    145 	local arp_keep=$1
    146 	local bonus=2
    147 
    148 	rump_server_start $SOCKSRC
    149 	rump_server_start $SOCKDST
    150 
    151 	setup_dst_server
    152 	setup_src_server $arp_keep
    153 
    154 	#
    155 	# Check if a cache is expired expectedly
    156 	#
    157 	export RUMP_SERVER=$SOCKSRC
    158 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    159 
    160 	$DEBUG && rump.arp -n -a
    161 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    162 	# Should be cached
    163 	atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
    164 
    165 	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
    166 
    167 	$DEBUG && rump.arp -n -a
    168 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    169 	# Should be expired
    170 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    171 }
    172 
    173 arp_cache_expiration_5s_body()
    174 {
    175 
    176 	test_cache_expiration 5
    177 	rump_server_destroy_ifaces
    178 }
    179 
    180 arp_cache_expiration_10s_body()
    181 {
    182 
    183 	test_cache_expiration 10
    184 	rump_server_destroy_ifaces
    185 }
    186 
    187 arp_command_body()
    188 {
    189 	local arp_keep=5
    190 	local bonus=2
    191 
    192 	rump_server_start $SOCKSRC
    193 	rump_server_start $SOCKDST
    194 
    195 	setup_dst_server
    196 	setup_src_server $arp_keep
    197 
    198 	export RUMP_SERVER=$SOCKSRC
    199 
    200 	# Add and delete a static entry
    201 	$DEBUG && rump.arp -n -a
    202 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
    203 	$DEBUG && rump.arp -n -a
    204 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    205 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
    206 	atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
    207 	$DEBUG && rump.arp -n -a
    208 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
    209 
    210 	# Add multiple entries via a file
    211 	cat - > ./list <<-EOF
    212 	10.0.1.11 b2:a0:20:00:00:11
    213 	10.0.1.12 b2:a0:20:00:00:12
    214 	10.0.1.13 b2:a0:20:00:00:13
    215 	10.0.1.14 b2:a0:20:00:00:14
    216 	10.0.1.15 b2:a0:20:00:00:15
    217 	EOF
    218 	$DEBUG && rump.arp -n -a
    219 	atf_check -s exit:0 -o ignore rump.arp -f ./list
    220 	$DEBUG && rump.arp -n -a
    221 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
    222 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
    223 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
    224 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
    225 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
    226 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
    227 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
    228 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
    229 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
    230 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
    231 
    232 	# Test arp -a
    233 	atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
    234 	atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
    235 	atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
    236 	atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
    237 	atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
    238 
    239 	# Flush all entries
    240 	$DEBUG && rump.arp -n -a
    241 	atf_check -s exit:0 -o ignore rump.arp -d -a
    242 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
    243 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
    244 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
    245 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
    246 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
    247 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
    248 
    249 	# Test temp option
    250 	$DEBUG && rump.arp -n -a
    251 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
    252 	$DEBUG && rump.arp -n -a
    253 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    254 	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
    255 
    256 	# Hm? the cache doesn't expire...
    257 	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
    258 	$DEBUG && rump.arp -n -a
    259 	#atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
    260 
    261 	rump_server_destroy_ifaces
    262 }
    263 
    264 make_pkt_str_arpreq()
    265 {
    266 	local target=$1
    267 	local sender=$2
    268 	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
    269 	pkt="$pkt Request who-has $target tell $sender, length 28"
    270 	echo $pkt
    271 }
    272 
    273 arp_garp_body()
    274 {
    275 	local pkt=
    276 
    277 	rump_server_start $SOCKSRC
    278 
    279 	export RUMP_SERVER=$SOCKSRC
    280 
    281 	# Setup an interface
    282 	rump_server_add_iface $SOCKSRC shmif0 bus1
    283 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
    284 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
    285 	atf_check -s exit:0 rump.ifconfig shmif0 up
    286 	$DEBUG && rump.ifconfig shmif0
    287 
    288 	atf_check -s exit:0 sleep 1
    289 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
    290 
    291 	# A GARP packet is sent for the primary address
    292 	pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
    293 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    294 	# No GARP packet is sent for the alias address
    295 	pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
    296 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    297 
    298 	atf_check -s exit:0 rump.ifconfig -w 10
    299 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
    300 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
    301 
    302 	# No GARP packets are sent during IFF_UP
    303 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
    304 	pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
    305 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    306 	pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
    307 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    308 
    309 	rump_server_destroy_ifaces
    310 }
    311 
    312 arp_cache_overwriting_body()
    313 {
    314 	local bonus=2
    315 
    316 	rump_server_start $SOCKSRC
    317 	rump_server_start $SOCKDST
    318 
    319 	setup_dst_server
    320 	setup_src_server
    321 
    322 	export RUMP_SERVER=$SOCKSRC
    323 
    324 	# Cannot overwrite a permanent cache
    325 	atf_check -s exit:0 rump.arp -s $IP4SRC b2:a0:20:00:00:ff
    326 	$DEBUG && rump.arp -n -a
    327 	atf_check -s not-exit:0 -e match:'File exists' \
    328 	    rump.arp -s $IP4SRC b2:a0:20:00:00:fe
    329 
    330 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    331 	$DEBUG && rump.arp -n -a
    332 	# Can overwrite a dynamic cache
    333 	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
    334 	$DEBUG && rump.arp -n -a
    335 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
    336 	atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
    337 
    338 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
    339 	$DEBUG && rump.arp -n -a
    340 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    341 	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
    342 	# Can overwrite a temp cache
    343 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
    344 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
    345 	$DEBUG && rump.arp -n -a
    346 
    347 	rump_server_destroy_ifaces
    348 }
    349 
    350 make_pkt_str_arprep()
    351 {
    352 	local ip=$1
    353 	local mac=$2
    354 	pkt="ethertype ARP (0x0806), length 42: "
    355 	pkt="Reply $ip is-at $mac, length 28"
    356 	echo $pkt
    357 }
    358 
    359 make_pkt_str_garp()
    360 {
    361 	local ip=$1
    362 	local mac=$2
    363 	local pkt=
    364 	pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
    365 	pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
    366 	echo $pkt
    367 }
    368 
    369 test_proxy_arp()
    370 {
    371 	local opts= title= flags=
    372 	local type=$1
    373 
    374 	rump_server_start $SOCKSRC
    375 	rump_server_start $SOCKDST tap
    376 
    377 	setup_dst_server
    378 	setup_src_server
    379 
    380 	export RUMP_SERVER=$SOCKDST
    381 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
    382 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    383 
    384 	if [ "$type" = "pub" ]; then
    385 		opts="pub"
    386 		title="permanent published"
    387 	else
    388 		opts="pub proxy"
    389 		title='permanent published \(proxy only\)'
    390 	fi
    391 
    392 	#
    393 	# Test#1: First setup an endpoint then create proxy arp entry
    394 	#
    395 	export RUMP_SERVER=$SOCKDST
    396 	atf_check -s exit:0 rump.ifconfig tap1 create
    397 	atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
    398 	atf_check -s exit:0 rump.ifconfig -w 10
    399 
    400 	# Try to ping (should fail w/o proxy arp)
    401 	export RUMP_SERVER=$SOCKSRC
    402 	atf_check -s not-exit:0 -o ignore -e ignore \
    403 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    404 
    405 	# Flushing
    406 	extract_new_packets bus1 > ./out
    407 
    408 	# Set up proxy ARP entry
    409 	export RUMP_SERVER=$SOCKDST
    410 	atf_check -s exit:0 -o ignore \
    411 	    rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
    412 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
    413 
    414 	# Try to ping
    415 	export RUMP_SERVER=$SOCKSRC
    416 	if [ "$type" = "pub" ]; then
    417 		# XXX fails
    418 		atf_check -s not-exit:0 -o ignore -e ignore \
    419 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    420 	else
    421 		atf_check -s exit:0 -o ignore \
    422 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    423 	fi
    424 
    425 	extract_new_packets bus1 > ./out
    426 	$DEBUG && cat ./out
    427 
    428 	pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
    429 	pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
    430 	if [ "$type" = "pub" ]; then
    431 		atf_check -s not-exit:0 -x \
    432 		    "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    433 	else
    434 		atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    435 	fi
    436 
    437 	#
    438 	# Test#2: Create proxy arp entry then set up an endpoint
    439 	#
    440 	export RUMP_SERVER=$SOCKDST
    441 	atf_check -s exit:0 -o ignore \
    442 	    rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
    443 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
    444 	$DEBUG && rump.netstat -nr -f inet
    445 
    446 	# Try to ping (should fail because no endpoint exists)
    447 	export RUMP_SERVER=$SOCKSRC
    448 	atf_check -s not-exit:0 -o ignore -e ignore \
    449 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    450 
    451 	extract_new_packets bus1 > ./out
    452 	$DEBUG && cat ./out
    453 
    454 	# ARP reply should be sent
    455 	pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
    456 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    457 
    458 	export RUMP_SERVER=$SOCKDST
    459 	atf_check -s exit:0 rump.ifconfig tap2 create
    460 	atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
    461 	atf_check -s exit:0 rump.ifconfig -w 10
    462 
    463 	# Try to ping
    464 	export RUMP_SERVER=$SOCKSRC
    465 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    466 }
    467 
    468 arp_proxy_arp_pub_body()
    469 {
    470 
    471 	test_proxy_arp pub
    472 	rump_server_destroy_ifaces
    473 }
    474 
    475 arp_proxy_arp_pubproxy_body()
    476 {
    477 
    478 	test_proxy_arp pubproxy
    479 	rump_server_destroy_ifaces
    480 }
    481 
    482 arp_link_activation_body()
    483 {
    484 	local bonus=2
    485 
    486 	rump_server_start $SOCKSRC
    487 	rump_server_start $SOCKDST
    488 
    489 	setup_dst_server
    490 	setup_src_server
    491 
    492 	# flush old packets
    493 	extract_new_packets bus1 > ./out
    494 
    495 	export RUMP_SERVER=$SOCKSRC
    496 
    497 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    498 	    b2:a1:00:00:00:01
    499 
    500 	atf_check -s exit:0 sleep 1
    501 	extract_new_packets bus1 > ./out
    502 	$DEBUG && cat ./out
    503 
    504 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    505 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    506 
    507 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    508 	    b2:a1:00:00:00:02 active
    509 
    510 	atf_check -s exit:0 sleep 1
    511 	extract_new_packets bus1 > ./out
    512 	$DEBUG && cat ./out
    513 
    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'"
    517 
    518 	rump_server_destroy_ifaces
    519 }
    520 
    521 arp_static_body()
    522 {
    523 	local macaddr_src=
    524 
    525 	rump_server_start $SOCKSRC
    526 	rump_server_start $SOCKDST
    527 
    528 	setup_dst_server
    529 	setup_src_server
    530 
    531 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    532 
    533 	# Set a (valid) static ARP entry for the src server
    534 	export RUMP_SERVER=$SOCKDST
    535 	$DEBUG && rump.arp -n -a
    536 	atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
    537 	$DEBUG && rump.arp -n -a
    538 
    539 	# Test receiving an ARP request with the static ARP entry (as spa/sha)
    540 	export RUMP_SERVER=$SOCKSRC
    541 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    542 
    543 	rump_server_destroy_ifaces
    544 }
    545 
    546 arp_cache_expiration_5s_cleanup()
    547 {
    548 	$DEBUG && dump
    549 	cleanup
    550 }
    551 
    552 arp_cache_expiration_10s_cleanup()
    553 {
    554 	$DEBUG && dump
    555 	cleanup
    556 }
    557 
    558 arp_command_cleanup()
    559 {
    560 	$DEBUG && dump
    561 	cleanup
    562 }
    563 
    564 arp_garp_cleanup()
    565 {
    566 	$DEBUG && dump
    567 	cleanup
    568 }
    569 
    570 arp_cache_overwriting_cleanup()
    571 {
    572 	$DEBUG && dump
    573 	cleanup
    574 }
    575 
    576 arp_proxy_arp_pub_cleanup()
    577 {
    578 	$DEBUG && dump
    579 	cleanup
    580 }
    581 
    582 arp_proxy_arp_pubproxy_cleanup()
    583 {
    584 	$DEBUG && dump
    585 	cleanup
    586 }
    587 
    588 arp_link_activation_cleanup()
    589 {
    590 	$DEBUG && dump
    591 	cleanup
    592 }
    593 
    594 arp_static_cleanup()
    595 {
    596 	$DEBUG && dump
    597 	cleanup
    598 }
    599 
    600 atf_test_case arp_rtm cleanup
    601 arp_rtm_head()
    602 {
    603 
    604 	atf_set "descr" "Tests for routing messages on operations of ARP entries"
    605 	atf_set "require.progs" "rump_server"
    606 }
    607 
    608 arp_rtm_body()
    609 {
    610 	local macaddr_src= macaddr_dst=
    611 	local file=./tmp
    612 	local pid= str=
    613 
    614 	rump_server_start $SOCKSRC
    615 	rump_server_start $SOCKDST
    616 
    617 	setup_dst_server
    618 	setup_src_server
    619 
    620 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    621 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    622 
    623 	export RUMP_SERVER=$SOCKSRC
    624 
    625 	# Test ping and a resulting routing message (RTM_ADD)
    626 	rump.route -n monitor -c 1 > $file &
    627 	pid=$?
    628 	sleep 1
    629 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    630 	wait $pid
    631 	$DEBUG && cat $file
    632 
    633 	str="RTM_ADD.+<UP,HOST,DONE,LLINFO,CLONED>"
    634 	atf_check -s exit:0 -o match:"$str" cat $file
    635 	str="<DST,GATEWAY,IFP,IFA>"
    636 	atf_check -s exit:0 -o match:"$str" cat $file
    637 	str="$IP4DST link#2 $macaddr_src $IP4SRC"
    638 	atf_check -s exit:0 -o match:"$str" cat $file
    639 
    640 	# Test arp -d and resulting routing messages (RTM_GET and RTM_DELETE)
    641 	rump.route -n monitor -c 2 > $file &
    642 	pid=$?
    643 	sleep 1
    644 	atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
    645 	wait $pid
    646 	$DEBUG && cat $file
    647 
    648 	str="RTM_GET.+<UP,DONE,LLINFO>"
    649 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    650 	str="<DST,GATEWAY>"
    651 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    652 	str="$IP4DST $macaddr_dst"
    653 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    654 	str="RTM_DELETE.+<UP,DONE,LLINFO>"
    655 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    656 	str="<DST,GATEWAY>"
    657 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    658 	str="$IP4DST $macaddr_dst"
    659 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    660 
    661 	rump_server_destroy_ifaces
    662 }
    663 
    664 arp_rtm_cleanup()
    665 {
    666 
    667 	$DEBUG && dump
    668 	cleanup
    669 }
    670 
    671 atf_test_case arp_purge_on_route_change cleanup
    672 arp_purge_on_route_change_head()
    673 {
    674 
    675 	atf_set "descr" "Tests if ARP entries are removed on route change"
    676 	atf_set "require.progs" "rump_server"
    677 }
    678 
    679 arp_purge_on_route_change_body()
    680 {
    681 
    682 	rump_server_start $SOCKSRC
    683 	rump_server_start $SOCKDST
    684 
    685 	setup_dst_server
    686 	setup_src_server
    687 
    688 	rump_server_add_iface $SOCKSRC shmif1 bus1
    689 	export RUMP_SERVER=$SOCKSRC
    690 	atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
    691 	atf_check -s exit:0 rump.ifconfig -w 10
    692 
    693 	$DEBUG && rump.netstat -nr -f inet
    694 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    695 	$DEBUG && rump.arp -na
    696 	atf_check -s exit:0 -o ignore \
    697 	    rump.route change -net $IP4NET -ifp shmif1
    698 	$DEBUG && rump.netstat -nr -f inet
    699 	$DEBUG && rump.arp -na
    700 	# The entry was already removed on route change
    701 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    702 
    703 	rump_server_destroy_ifaces
    704 }
    705 
    706 arp_purge_on_route_change_cleanup()
    707 {
    708 
    709 	$DEBUG && dump
    710 	cleanup
    711 }
    712 
    713 atf_test_case arp_purge_on_route_delete cleanup
    714 arp_purge_on_route_delete_head()
    715 {
    716 
    717 	atf_set "descr" "Tests if ARP entries are removed on route delete"
    718 	atf_set "require.progs" "rump_server"
    719 }
    720 
    721 arp_purge_on_route_delete_body()
    722 {
    723 
    724 	rump_server_start $SOCKSRC
    725 	rump_server_start $SOCKDST
    726 
    727 	setup_dst_server
    728 	setup_src_server
    729 
    730 	$DEBUG && rump.netstat -nr -f inet
    731 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    732 	$DEBUG && rump.arp -na
    733 
    734 	atf_check -s exit:0 -o ignore rump.route delete -net $IP4NET
    735 	$DEBUG && rump.netstat -nr -f inet
    736 	$DEBUG && rump.arp -na
    737 
    738 	# The entry was already removed on route delete
    739 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    740 
    741 	rump_server_destroy_ifaces
    742 }
    743 
    744 arp_purge_on_route_delete_cleanup()
    745 {
    746 
    747 	$DEBUG && dump
    748 	cleanup
    749 }
    750 
    751 atf_test_case arp_purge_on_ifdown cleanup
    752 arp_purge_on_ifdown_head()
    753 {
    754 
    755 	atf_set "descr" "Tests if ARP entries are removed on interface down"
    756 	atf_set "require.progs" "rump_server"
    757 }
    758 
    759 arp_purge_on_ifdown_body()
    760 {
    761 
    762 	rump_server_start $SOCKSRC
    763 	rump_server_start $SOCKDST
    764 
    765 	setup_dst_server
    766 	setup_src_server
    767 
    768 	$DEBUG && rump.netstat -nr -f inet
    769 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    770 	atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
    771 
    772 	# Shutdown the interface
    773 	atf_check -s exit:0 rump.ifconfig shmif0 down
    774 	$DEBUG && rump.netstat -nr -f inet
    775 	$DEBUG && rump.arp -na
    776 
    777 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    778 
    779 	rump_server_destroy_ifaces
    780 }
    781 
    782 arp_purge_on_ifdown_cleanup()
    783 {
    784 
    785 	$DEBUG && dump
    786 	cleanup
    787 }
    788 
    789 atf_init_test_cases()
    790 {
    791 	atf_add_test_case arp_cache_expiration_5s
    792 	atf_add_test_case arp_cache_expiration_10s
    793 	atf_add_test_case arp_command
    794 	atf_add_test_case arp_garp
    795 	atf_add_test_case arp_cache_overwriting
    796 	atf_add_test_case arp_proxy_arp_pub
    797 	atf_add_test_case arp_proxy_arp_pubproxy
    798 	atf_add_test_case arp_link_activation
    799 	atf_add_test_case arp_static
    800 	atf_add_test_case arp_rtm
    801 	atf_add_test_case arp_purge_on_route_change
    802 	atf_add_test_case arp_purge_on_route_delete
    803 	atf_add_test_case arp_purge_on_ifdown
    804 }
    805