Home | History | Annotate | Line # | Download | only in arp
t_arp.sh revision 1.14
      1 #	$NetBSD: t_arp.sh,v 1.14 2016/04/04 07:37:08 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 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"
     31 
     32 SOCKSRC=unix://commsock1
     33 SOCKDST=unix://commsock2
     34 IP4SRC=10.0.1.1
     35 IP4DST=10.0.1.2
     36 IP4DST_PROXYARP1=10.0.1.3
     37 IP4DST_PROXYARP2=10.0.1.4
     38 
     39 DEBUG=false
     40 TIMEOUT=1
     41 
     42 atf_test_case cache_expiration_5s cleanup
     43 atf_test_case cache_expiration_10s cleanup
     44 atf_test_case command cleanup
     45 atf_test_case garp cleanup
     46 atf_test_case cache_overwriting cleanup
     47 atf_test_case proxy_arp_pub cleanup
     48 atf_test_case proxy_arp_pubproxy cleanup
     49 atf_test_case link_activation cleanup
     50 
     51 cache_expiration_5s_head()
     52 {
     53 	atf_set "descr" "Tests for ARP cache expiration (5s)"
     54 	atf_set "require.progs" "rump_server"
     55 }
     56 
     57 cache_expiration_10s_head()
     58 {
     59 	atf_set "descr" "Tests for ARP cache expiration (10s)"
     60 	atf_set "require.progs" "rump_server"
     61 }
     62 
     63 command_head()
     64 {
     65 	atf_set "descr" "Tests for commands of arp(8)"
     66 	atf_set "require.progs" "rump_server"
     67 }
     68 
     69 garp_head()
     70 {
     71 	atf_set "descr" "Tests for GARP"
     72 	atf_set "require.progs" "rump_server"
     73 }
     74 
     75 cache_overwriting_head()
     76 {
     77 	atf_set "descr" "Tests for behavior of overwriting ARP caches"
     78 	atf_set "require.progs" "rump_server"
     79 }
     80 
     81 proxy_arp_pub_head()
     82 {
     83 	atf_set "descr" "Tests for Proxy ARP (pub)"
     84 	atf_set "require.progs" "rump_server"
     85 }
     86 
     87 proxy_arp_pubproxy_head()
     88 {
     89 	atf_set "descr" "Tests for Proxy ARP (pub proxy)"
     90 	atf_set "require.progs" "rump_server"
     91 }
     92 
     93 link_activation_head()
     94 {
     95 	atf_set "descr" "Tests for activating a new MAC address"
     96 	atf_set "require.progs" "rump_server"
     97 }
     98 
     99 setup_dst_server()
    100 {
    101 	export RUMP_SERVER=$SOCKDST
    102 	atf_check -s exit:0 rump.ifconfig shmif0 create
    103 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    104 	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4DST/24
    105 	atf_check -s exit:0 rump.ifconfig shmif0 up
    106 	atf_check -s exit:0 rump.ifconfig -w 10
    107 
    108 	$DEBUG && rump.ifconfig shmif0
    109 	$DEBUG && rump.arp -n -a
    110 }
    111 
    112 setup_src_server()
    113 {
    114 	local keep=$1
    115 
    116 	export RUMP_SERVER=$SOCKSRC
    117 
    118 	# Adjust ARP parameters
    119 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.arp.keep=$keep
    120 
    121 	# Setup an interface
    122 	atf_check -s exit:0 rump.ifconfig shmif0 create
    123 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    124 	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
    125 	atf_check -s exit:0 rump.ifconfig shmif0 up
    126 	atf_check -s exit:0 rump.ifconfig -w 10
    127 
    128 	# Sanity check
    129 	$DEBUG && rump.ifconfig shmif0
    130 	$DEBUG && rump.arp -n -a
    131 	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
    132 	atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
    133 }
    134 
    135 test_cache_expiration()
    136 {
    137 	local arp_keep=$1
    138 	local bonus=2
    139 
    140 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    141 	atf_check -s exit:0 ${inetserver} $SOCKDST
    142 
    143 	setup_dst_server
    144 	setup_src_server $arp_keep
    145 
    146 	#
    147 	# Check if a cache is expired expectedly
    148 	#
    149 	export RUMP_SERVER=$SOCKSRC
    150 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    151 
    152 	$DEBUG && rump.arp -n -a
    153 	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
    154 	# Should be cached
    155 	atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
    156 
    157 	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
    158 
    159 	$DEBUG && rump.arp -n -a
    160 	atf_check -s exit:0 -o ignore rump.arp -n $IP4SRC
    161 	# Should be expired
    162 	atf_check -s not-exit:0 -e ignore rump.arp -n $IP4DST
    163 }
    164 
    165 cache_expiration_5s_body()
    166 {
    167 	test_cache_expiration 5
    168 }
    169 
    170 cache_expiration_10s_body()
    171 {
    172 	test_cache_expiration 10
    173 }
    174 
    175 command_body()
    176 {
    177 	local arp_keep=5
    178 	local bonus=2
    179 
    180 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    181 	atf_check -s exit:0 ${inetserver} $SOCKDST
    182 
    183 	setup_dst_server
    184 	setup_src_server $arp_keep
    185 
    186 	export RUMP_SERVER=$SOCKSRC
    187 
    188 	# We can delete the entry for the interface's IP address
    189 	atf_check -s exit:0 -o ignore rump.arp -d $IP4SRC
    190 
    191 	# Add and delete a static entry
    192 	$DEBUG && rump.arp -n -a
    193 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10
    194 	$DEBUG && rump.arp -n -a
    195 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    196 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.10
    197 	atf_check -s exit:0 -o ignore rump.arp -d 10.0.1.10
    198 	$DEBUG && rump.arp -n -a
    199 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
    200 
    201 	# Add multiple entries via a file
    202 	cat - > ./list <<-EOF
    203 	10.0.1.11 b2:a0:20:00:00:11
    204 	10.0.1.12 b2:a0:20:00:00:12
    205 	10.0.1.13 b2:a0:20:00:00:13
    206 	10.0.1.14 b2:a0:20:00:00:14
    207 	10.0.1.15 b2:a0:20:00:00:15
    208 	EOF
    209 	$DEBUG && rump.arp -n -a
    210 	atf_check -s exit:0 -o ignore rump.arp -f ./list
    211 	$DEBUG && rump.arp -n -a
    212 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:11' rump.arp -n 10.0.1.11
    213 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.11
    214 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:12' rump.arp -n 10.0.1.12
    215 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.12
    216 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:13' rump.arp -n 10.0.1.13
    217 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.13
    218 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:14' rump.arp -n 10.0.1.14
    219 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.14
    220 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:15' rump.arp -n 10.0.1.15
    221 	atf_check -s exit:0 -o match:'permanent' rump.arp -n 10.0.1.15
    222 
    223 	# Test arp -a
    224 	atf_check -s exit:0 -o match:'10.0.1.11' rump.arp -n -a
    225 	atf_check -s exit:0 -o match:'10.0.1.12' rump.arp -n -a
    226 	atf_check -s exit:0 -o match:'10.0.1.13' rump.arp -n -a
    227 	atf_check -s exit:0 -o match:'10.0.1.14' rump.arp -n -a
    228 	atf_check -s exit:0 -o match:'10.0.1.15' rump.arp -n -a
    229 
    230 	# Flush all entries
    231 	$DEBUG && rump.arp -n -a
    232 	atf_check -s exit:0 -o ignore rump.arp -d -a
    233 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.11
    234 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.12
    235 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.13
    236 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.14
    237 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.15
    238 	atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.1
    239 
    240 	# Test temp option
    241 	$DEBUG && rump.arp -n -a
    242 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
    243 	$DEBUG && rump.arp -n -a
    244 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    245 	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
    246 
    247 	# Hm? the cache doesn't expire...
    248 	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
    249 	$DEBUG && rump.arp -n -a
    250 	#atf_check -s not-exit:0 -e ignore rump.arp -n 10.0.1.10
    251 
    252 	return 0
    253 }
    254 
    255 make_pkt_str_arpreq()
    256 {
    257 	local target=$1
    258 	local sender=$2
    259 	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
    260 	pkt="$pkt Request who-has $target tell $sender, length 28"
    261 	echo $pkt
    262 }
    263 
    264 garp_body()
    265 {
    266 	local pkt=
    267 
    268 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    269 	export RUMP_SERVER=$SOCKSRC
    270 
    271 	# Setup an interface
    272 	atf_check -s exit:0 rump.ifconfig shmif0 create
    273 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    274 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
    275 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
    276 	atf_check -s exit:0 rump.ifconfig shmif0 up
    277 	$DEBUG && rump.ifconfig shmif0
    278 
    279 	atf_check -s exit:0 sleep 1
    280 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
    281 
    282 	# A GARP packet is sent for the primary address
    283 	pkt=$(make_pkt_str_arpreq 10.0.0.1 10.0.0.1)
    284 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    285 	# No GARP packet is sent for the alias address
    286 	pkt=$(make_pkt_str_arpreq 10.0.0.2 10.0.0.2)
    287 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    288 
    289 	atf_check -s exit:0 rump.ifconfig -w 10
    290 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24
    291 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.4/24 alias
    292 
    293 	# No GARP packets are sent during IFF_UP
    294 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
    295 	pkt=$(make_pkt_str_arpreq 10.0.0.3 10.0.0.3)
    296 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    297 	pkt=$(make_pkt_str_arpreq 10.0.0.4 10.0.0.4)
    298 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    299 }
    300 
    301 cache_overwriting_body()
    302 {
    303 	local arp_keep=5
    304 	local bonus=2
    305 
    306 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    307 	atf_check -s exit:0 ${inetserver} $SOCKDST
    308 
    309 	setup_dst_server
    310 	setup_src_server $arp_keep
    311 
    312 	export RUMP_SERVER=$SOCKSRC
    313 
    314 	# Cannot overwrite a permanent cache
    315 	atf_check -s not-exit:0 -e match:'File exists' \
    316 	    rump.arp -s $IP4SRC b2:a0:20:00:00:ff
    317 	$DEBUG && rump.arp -n -a
    318 
    319 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    320 	$DEBUG && rump.arp -n -a
    321 	# Can overwrite a dynamic cache
    322 	atf_check -s exit:0 -o ignore rump.arp -s $IP4DST b2:a0:20:00:00:00
    323 	$DEBUG && rump.arp -n -a
    324 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:00' rump.arp -n $IP4DST
    325 	atf_check -s exit:0 -o match:'permanent' rump.arp -n $IP4DST
    326 
    327 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:10 temp
    328 	$DEBUG && rump.arp -n -a
    329 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:10' rump.arp -n 10.0.1.10
    330 	atf_check -s exit:0 -o not-match:'permanent' rump.arp -n 10.0.1.10
    331 	# Can overwrite a temp cache
    332 	atf_check -s exit:0 -o ignore rump.arp -s 10.0.1.10 b2:a0:20:00:00:ff
    333 	atf_check -s exit:0 -o match:'b2:a0:20:00:00:ff' rump.arp -n 10.0.1.10
    334 	$DEBUG && rump.arp -n -a
    335 
    336 	return 0
    337 }
    338 
    339 make_pkt_str_arprep()
    340 {
    341 	local ip=$1
    342 	local mac=$2
    343 	pkt="ethertype ARP (0x0806), length 42: "
    344 	pkt="Reply $ip is-at $mac, length 28"
    345 	echo $pkt
    346 }
    347 
    348 make_pkt_str_garp()
    349 {
    350 	local ip=$1
    351 	local mac=$2
    352 	local pkt=
    353 	pkt="$mac > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),"
    354 	pkt="$pkt length 42: Request who-has $ip tell $ip, length 28"
    355 	echo $pkt
    356 }
    357 
    358 extract_new_packets()
    359 {
    360 	local old=./old
    361 
    362 	if [ ! -f $old ]; then
    363 		old=/dev/null
    364 	fi
    365 
    366 	shmif_dumpbus -p - bus1 2>/dev/null| \
    367 	    tcpdump -n -e -r - 2>/dev/null > ./new
    368 	diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
    369 	mv -f ./new ./old
    370 	cat ./diff
    371 }
    372 
    373 test_proxy_arp()
    374 {
    375 	local arp_keep=5
    376 	local opts= title= flags=
    377 	local type=$1
    378 
    379 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    380 	atf_check -s exit:0 ${inetserver} $SOCKDST
    381 
    382 	setup_dst_server
    383 	setup_src_server $arp_keep
    384 
    385 	export RUMP_SERVER=$SOCKDST
    386 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
    387 	macaddr_dst=$(rump.ifconfig shmif0 |awk '/address/ {print $2;}')
    388 
    389 	if [ "$type" = "pub" ]; then
    390 		opts="pub"
    391 		title="permanent published"
    392 	else
    393 		opts="pub proxy"
    394 		title='permanent published \(proxy only\)'
    395 	fi
    396 
    397 	#
    398 	# Test#1: First setup an endpoint then create proxy arp entry
    399 	#
    400 	export RUMP_SERVER=$SOCKDST
    401 	atf_check -s exit:0 rump.ifconfig tap1 create
    402 	atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
    403 	atf_check -s exit:0 rump.ifconfig -w 10
    404 
    405 	# Try to ping (should fail w/o proxy arp)
    406 	export RUMP_SERVER=$SOCKSRC
    407 	atf_check -s not-exit:0 -o ignore -e ignore \
    408 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    409 
    410 	# Flushing
    411 	extract_new_packets > ./out
    412 
    413 	# Set up proxy ARP entry
    414 	export RUMP_SERVER=$SOCKDST
    415 	atf_check -s exit:0 -o ignore \
    416 	    rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
    417 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
    418 
    419 	# Try to ping
    420 	export RUMP_SERVER=$SOCKSRC
    421 	if [ "$type" = "pub" ]; then
    422 		# XXX fails
    423 		atf_check -s not-exit:0 -o ignore -e ignore \
    424 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    425 	else
    426 		atf_check -s exit:0 -o ignore \
    427 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    428 	fi
    429 
    430 	extract_new_packets > ./out
    431 	$DEBUG && cat ./out
    432 
    433 	pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
    434 	pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
    435 	if [ "$type" = "pub" ]; then
    436 		atf_check -s not-exit:0 -x \
    437 		    "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    438 	else
    439 		atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    440 	fi
    441 
    442 	#
    443 	# Test#2: Create proxy arp entry then set up an endpoint
    444 	#
    445 	export RUMP_SERVER=$SOCKDST
    446 	atf_check -s exit:0 -o ignore \
    447 	    rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
    448 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
    449 	$DEBUG && rump.netstat -nr -f inet
    450 
    451 	# Try to ping (should fail because no endpoint exists)
    452 	export RUMP_SERVER=$SOCKSRC
    453 	atf_check -s not-exit:0 -o ignore -e ignore \
    454 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    455 
    456 	extract_new_packets > ./out
    457 	$DEBUG && cat ./out
    458 
    459 	# ARP reply should be sent
    460 	pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
    461 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    462 
    463 	export RUMP_SERVER=$SOCKDST
    464 	atf_check -s exit:0 rump.ifconfig tap2 create
    465 	atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
    466 	atf_check -s exit:0 rump.ifconfig -w 10
    467 
    468 	# Try to ping
    469 	export RUMP_SERVER=$SOCKSRC
    470 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    471 }
    472 
    473 proxy_arp_pub_body()
    474 {
    475 
    476 	test_proxy_arp pub
    477 }
    478 
    479 proxy_arp_pubproxy_body()
    480 {
    481 
    482 	test_proxy_arp pubproxy
    483 }
    484 
    485 link_activation_body()
    486 {
    487 	local arp_keep=5
    488 	local bonus=2
    489 
    490 	atf_check -s exit:0 ${inetserver} $SOCKSRC
    491 	atf_check -s exit:0 ${inetserver} $SOCKDST
    492 
    493 	setup_dst_server
    494 	setup_src_server $arp_keep
    495 
    496 	# flush old packets
    497 	extract_new_packets > ./out
    498 
    499 	export RUMP_SERVER=$SOCKSRC
    500 
    501 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    502 	    b2:a1:00:00:00:01
    503 
    504 	atf_check -s exit:0 sleep 1
    505 	extract_new_packets > ./out
    506 	$DEBUG && cat ./out
    507 
    508 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    509 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    510 
    511 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    512 	    b2:a1:00:00:00:02 active
    513 
    514 	atf_check -s exit:0 sleep 1
    515 	extract_new_packets > ./out
    516 	$DEBUG && cat ./out
    517 
    518 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    519 	atf_check -s exit:0 -x \
    520 	    "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
    521 }
    522 
    523 cleanup()
    524 {
    525 	env RUMP_SERVER=$SOCKSRC rump.halt
    526 	env RUMP_SERVER=$SOCKDST rump.halt
    527 }
    528 
    529 dump_src()
    530 {
    531 	export RUMP_SERVER=$SOCKSRC
    532 	rump.netstat -nr
    533 	rump.arp -n -a
    534 	rump.ifconfig
    535 	$HIJACKING dmesg
    536 }
    537 
    538 dump_dst()
    539 {
    540 	export RUMP_SERVER=$SOCKDST
    541 	rump.netstat -nr
    542 	rump.arp -n -a
    543 	rump.ifconfig
    544 	$HIJACKING dmesg
    545 }
    546 
    547 dump()
    548 {
    549 	dump_src
    550 	dump_dst
    551 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    552 }
    553 
    554 cache_expiration_5s_cleanup()
    555 {
    556 	$DEBUG && dump
    557 	cleanup
    558 }
    559 
    560 cache_expiration_10s_cleanup()
    561 {
    562 	$DEBUG && dump
    563 	cleanup
    564 }
    565 
    566 command_cleanup()
    567 {
    568 	$DEBUG && dump
    569 	cleanup
    570 }
    571 
    572 garp_cleanup()
    573 {
    574 	$DEBUG && dump_src
    575 	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    576 	env RUMP_SERVER=$SOCKSRC rump.halt
    577 }
    578 
    579 cache_overwriting_cleanup()
    580 {
    581 	$DEBUG && dump
    582 	cleanup
    583 }
    584 
    585 proxy_arp_pub_cleanup()
    586 {
    587 	$DEBUG && dump
    588 	cleanup
    589 }
    590 
    591 proxy_arp_pubproxy_cleanup()
    592 {
    593 	$DEBUG && dump
    594 	cleanup
    595 }
    596 
    597 link_activation_cleanup()
    598 {
    599 	$DEBUG && dump
    600 	cleanup
    601 }
    602 
    603 atf_init_test_cases()
    604 {
    605 	atf_add_test_case cache_expiration_5s
    606 	atf_add_test_case cache_expiration_10s
    607 	atf_add_test_case command
    608 	atf_add_test_case garp
    609 	atf_add_test_case cache_overwriting
    610 	atf_add_test_case proxy_arp_pub
    611 	atf_add_test_case proxy_arp_pubproxy
    612 	atf_add_test_case link_activation
    613 }
    614