Home | History | Annotate | Line # | Download | only in arp
t_arp.sh revision 1.31
      1 #	$NetBSD: t_arp.sh,v 1.31 2017/06/28 04:10:47 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 $IP4DST 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 $IP4DST b2:a0:20:00:00:fe
    329 	# cleanup
    330 	atf_check -s exit:0 rump.arp -d $IP4DST
    331 
    332 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    333 	$DEBUG && rump.arp -n -a
    334 	# Can overwrite a dynamic cache
    335 	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
    336 	$DEBUG && rump.arp -n -a
    337 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
    338 	atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
    339 
    340 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
    341 	$DEBUG && rump.arp -n -a
    342 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    343 	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
    344 	# Can overwrite a temp cache
    345 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
    346 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
    347 	$DEBUG && rump.arp -n -a
    348 
    349 	rump_server_destroy_ifaces
    350 }
    351 
    352 make_pkt_str_arprep()
    353 {
    354 	local ip=$1
    355 	local mac=$2
    356 	pkt="ethertype ARP (0x0806), length 42: "
    357 	pkt="Reply $ip is-at $mac, length 28"
    358 	echo $pkt
    359 }
    360 
    361 make_pkt_str_garp()
    362 {
    363 	local ip=$1
    364 	local mac=$2
    365 	local pkt=
    366 	pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
    367 	pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
    368 	echo $pkt
    369 }
    370 
    371 test_proxy_arp()
    372 {
    373 	local opts= title= flags=
    374 	local type=$1
    375 
    376 	rump_server_start $SOCKSRC
    377 	rump_server_start $SOCKDST tap
    378 
    379 	setup_dst_server
    380 	setup_src_server
    381 
    382 	export RUMP_SERVER=$SOCKDST
    383 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
    384 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    385 
    386 	if [ "$type" = "pub" ]; then
    387 		opts="pub"
    388 	else
    389 		opts="pub proxy"
    390 	fi
    391 	# Always proxy only since migrating to lltable/llentry
    392 	title='permanent published \(proxy only\)'
    393 
    394 	#
    395 	# Test#1: First setup an endpoint then create proxy arp entry
    396 	#
    397 	export RUMP_SERVER=$SOCKDST
    398 	atf_check -s exit:0 rump.ifconfig tap1 create
    399 	atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
    400 	atf_check -s exit:0 rump.ifconfig -w 10
    401 
    402 	# Try to ping (should fail w/o proxy arp)
    403 	export RUMP_SERVER=$SOCKSRC
    404 	atf_check -s not-exit:0 -o ignore -e ignore \
    405 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    406 
    407 	# Flushing
    408 	extract_new_packets bus1 > ./out
    409 
    410 	# Set up proxy ARP entry
    411 	export RUMP_SERVER=$SOCKDST
    412 	atf_check -s exit:0 -o ignore \
    413 	    rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
    414 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
    415 
    416 	# Try to ping
    417 	export RUMP_SERVER=$SOCKSRC
    418 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    419 
    420 	extract_new_packets bus1 > ./out
    421 	$DEBUG && cat ./out
    422 
    423 	pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
    424 	pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
    425 	atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    426 
    427 	#
    428 	# Test#2: Create proxy arp entry then set up an endpoint
    429 	#
    430 	export RUMP_SERVER=$SOCKDST
    431 	atf_check -s exit:0 -o ignore \
    432 	    rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
    433 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
    434 	$DEBUG && rump.netstat -nr -f inet
    435 
    436 	# Try to ping (should fail because no endpoint exists)
    437 	export RUMP_SERVER=$SOCKSRC
    438 	atf_check -s not-exit:0 -o ignore -e ignore \
    439 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    440 
    441 	extract_new_packets bus1 > ./out
    442 	$DEBUG && cat ./out
    443 
    444 	# ARP reply should be sent
    445 	pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
    446 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    447 
    448 	export RUMP_SERVER=$SOCKDST
    449 	atf_check -s exit:0 rump.ifconfig tap2 create
    450 	atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
    451 	atf_check -s exit:0 rump.ifconfig -w 10
    452 
    453 	# Try to ping
    454 	export RUMP_SERVER=$SOCKSRC
    455 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    456 }
    457 
    458 arp_proxy_arp_pub_body()
    459 {
    460 
    461 	test_proxy_arp pub
    462 	rump_server_destroy_ifaces
    463 }
    464 
    465 arp_proxy_arp_pubproxy_body()
    466 {
    467 
    468 	test_proxy_arp pubproxy
    469 	rump_server_destroy_ifaces
    470 }
    471 
    472 arp_link_activation_body()
    473 {
    474 	local bonus=2
    475 
    476 	rump_server_start $SOCKSRC
    477 	rump_server_start $SOCKDST
    478 
    479 	setup_dst_server
    480 	setup_src_server
    481 
    482 	# flush old packets
    483 	extract_new_packets bus1 > ./out
    484 
    485 	export RUMP_SERVER=$SOCKSRC
    486 
    487 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    488 	    b2:a1:00:00:00:01
    489 
    490 	atf_check -s exit:0 sleep 1
    491 	extract_new_packets bus1 > ./out
    492 	$DEBUG && cat ./out
    493 
    494 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    495 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    496 
    497 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    498 	    b2:a1:00:00:00:02 active
    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 exit:0 -x \
    506 	    "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
    507 
    508 	rump_server_destroy_ifaces
    509 }
    510 
    511 arp_static_body()
    512 {
    513 	local macaddr_src=
    514 
    515 	rump_server_start $SOCKSRC
    516 	rump_server_start $SOCKDST
    517 
    518 	setup_dst_server
    519 	setup_src_server
    520 
    521 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    522 
    523 	# Set a (valid) static ARP entry for the src server
    524 	export RUMP_SERVER=$SOCKDST
    525 	$DEBUG && rump.arp -n -a
    526 	atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
    527 	$DEBUG && rump.arp -n -a
    528 
    529 	# Test receiving an ARP request with the static ARP entry (as spa/sha)
    530 	export RUMP_SERVER=$SOCKSRC
    531 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    532 
    533 	rump_server_destroy_ifaces
    534 }
    535 
    536 arp_cache_expiration_5s_cleanup()
    537 {
    538 	$DEBUG && dump
    539 	cleanup
    540 }
    541 
    542 arp_cache_expiration_10s_cleanup()
    543 {
    544 	$DEBUG && dump
    545 	cleanup
    546 }
    547 
    548 arp_command_cleanup()
    549 {
    550 	$DEBUG && dump
    551 	cleanup
    552 }
    553 
    554 arp_garp_cleanup()
    555 {
    556 	$DEBUG && dump
    557 	cleanup
    558 }
    559 
    560 arp_cache_overwriting_cleanup()
    561 {
    562 	$DEBUG && dump
    563 	cleanup
    564 }
    565 
    566 arp_proxy_arp_pub_cleanup()
    567 {
    568 	$DEBUG && dump
    569 	cleanup
    570 }
    571 
    572 arp_proxy_arp_pubproxy_cleanup()
    573 {
    574 	$DEBUG && dump
    575 	cleanup
    576 }
    577 
    578 arp_link_activation_cleanup()
    579 {
    580 	$DEBUG && dump
    581 	cleanup
    582 }
    583 
    584 arp_static_cleanup()
    585 {
    586 	$DEBUG && dump
    587 	cleanup
    588 }
    589 
    590 atf_test_case arp_rtm cleanup
    591 arp_rtm_head()
    592 {
    593 
    594 	atf_set "descr" "Tests for routing messages on operations of ARP entries"
    595 	atf_set "require.progs" "rump_server"
    596 }
    597 
    598 arp_rtm_body()
    599 {
    600 	local macaddr_src= macaddr_dst=
    601 	local file=./tmp
    602 	local pid= str=
    603 
    604 	rump_server_start $SOCKSRC
    605 	rump_server_start $SOCKDST
    606 
    607 	setup_dst_server
    608 	setup_src_server
    609 
    610 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    611 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    612 
    613 	export RUMP_SERVER=$SOCKSRC
    614 
    615 	# Test ping and a resulting routing message (RTM_ADD)
    616 	rump.route -n monitor -c 1 > $file &
    617 	pid=$?
    618 	sleep 1
    619 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    620 	wait $pid
    621 	$DEBUG && cat $file
    622 
    623 	str="RTM_ADD.+<UP,HOST,DONE,LLINFO,CLONED>"
    624 	atf_check -s exit:0 -o match:"$str" cat $file
    625 	str="<DST,GATEWAY>"
    626 	atf_check -s exit:0 -o match:"$str" cat $file
    627 	str="$IP4DST link#2"
    628 	atf_check -s exit:0 -o match:"$str" cat $file
    629 
    630 	# Test arp -d and resulting routing messages (RTM_GET and RTM_DELETE)
    631 	rump.route -n monitor -c 2 > $file &
    632 	pid=$?
    633 	sleep 1
    634 	atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
    635 	wait $pid
    636 	$DEBUG && cat $file
    637 
    638 	str="RTM_GET.+<UP,DONE,LLINFO>"
    639 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    640 	str="<DST,GATEWAY>"
    641 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    642 	str="$IP4DST $macaddr_dst"
    643 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    644 	str="RTM_DELETE.+<DONE,LLINFO>"
    645 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    646 	str="<DST,GATEWAY>"
    647 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    648 	str="$IP4DST $macaddr_dst"
    649 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    650 
    651 	rump_server_destroy_ifaces
    652 }
    653 
    654 arp_rtm_cleanup()
    655 {
    656 
    657 	$DEBUG && dump
    658 	cleanup
    659 }
    660 
    661 atf_test_case arp_purge_on_route_change cleanup
    662 arp_purge_on_route_change_head()
    663 {
    664 
    665 	atf_set "descr" "Tests if ARP entries are removed on route change"
    666 	atf_set "require.progs" "rump_server"
    667 }
    668 
    669 arp_purge_on_route_change_body()
    670 {
    671 
    672 	rump_server_start $SOCKSRC
    673 	rump_server_start $SOCKDST
    674 
    675 	setup_dst_server
    676 	setup_src_server
    677 
    678 	rump_server_add_iface $SOCKSRC shmif1 bus1
    679 	export RUMP_SERVER=$SOCKSRC
    680 	atf_check -s exit:0 rump.ifconfig shmif1 inet $IP4SRC2/24
    681 	atf_check -s exit:0 rump.ifconfig -w 10
    682 
    683 	$DEBUG && rump.netstat -nr -f inet
    684 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    685 	$DEBUG && rump.arp -na
    686 	atf_check -s exit:0 -o ignore \
    687 	    rump.route change -net $IP4NET -ifp shmif1
    688 	$DEBUG && rump.netstat -nr -f inet
    689 	$DEBUG && rump.arp -na
    690 	# The entry was already removed on route change
    691 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    692 
    693 	rump_server_destroy_ifaces
    694 }
    695 
    696 arp_purge_on_route_change_cleanup()
    697 {
    698 
    699 	$DEBUG && dump
    700 	cleanup
    701 }
    702 
    703 atf_test_case arp_purge_on_route_delete cleanup
    704 arp_purge_on_route_delete_head()
    705 {
    706 
    707 	atf_set "descr" "Tests if ARP entries are removed on route delete"
    708 	atf_set "require.progs" "rump_server"
    709 }
    710 
    711 arp_purge_on_route_delete_body()
    712 {
    713 
    714 	rump_server_start $SOCKSRC
    715 	rump_server_start $SOCKDST
    716 
    717 	setup_dst_server
    718 	setup_src_server
    719 
    720 	$DEBUG && rump.netstat -nr -f inet
    721 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    722 	$DEBUG && rump.arp -na
    723 
    724 	atf_check -s exit:0 -o ignore rump.route delete -net $IP4NET
    725 	$DEBUG && rump.netstat -nr -f inet
    726 	$DEBUG && rump.arp -na
    727 
    728 	# The entry was already removed on route delete
    729 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    730 
    731 	rump_server_destroy_ifaces
    732 }
    733 
    734 arp_purge_on_route_delete_cleanup()
    735 {
    736 
    737 	$DEBUG && dump
    738 	cleanup
    739 }
    740 
    741 atf_test_case arp_purge_on_ifdown cleanup
    742 arp_purge_on_ifdown_head()
    743 {
    744 
    745 	atf_set "descr" "Tests if ARP entries are removed on interface down"
    746 	atf_set "require.progs" "rump_server"
    747 }
    748 
    749 arp_purge_on_ifdown_body()
    750 {
    751 
    752 	rump_server_start $SOCKSRC
    753 	rump_server_start $SOCKDST
    754 
    755 	setup_dst_server
    756 	setup_src_server
    757 
    758 	$DEBUG && rump.netstat -nr -f inet
    759 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    760 	atf_check -s exit:0 -o match:'shmif0' rump.arp -n $IP4DST
    761 
    762 	# Shutdown the interface
    763 	atf_check -s exit:0 rump.ifconfig shmif0 down
    764 	$DEBUG && rump.netstat -nr -f inet
    765 	$DEBUG && rump.arp -na
    766 
    767 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    768 
    769 	rump_server_destroy_ifaces
    770 }
    771 
    772 arp_purge_on_ifdown_cleanup()
    773 {
    774 
    775 	$DEBUG && dump
    776 	cleanup
    777 }
    778 
    779 atf_init_test_cases()
    780 {
    781 	atf_add_test_case arp_cache_expiration_5s
    782 	atf_add_test_case arp_cache_expiration_10s
    783 	atf_add_test_case arp_command
    784 	atf_add_test_case arp_garp
    785 	atf_add_test_case arp_cache_overwriting
    786 	atf_add_test_case arp_proxy_arp_pub
    787 	atf_add_test_case arp_proxy_arp_pubproxy
    788 	atf_add_test_case arp_link_activation
    789 	atf_add_test_case arp_static
    790 	atf_add_test_case arp_rtm
    791 	atf_add_test_case arp_purge_on_route_change
    792 	atf_add_test_case arp_purge_on_route_delete
    793 	atf_add_test_case arp_purge_on_ifdown
    794 }
    795