Home | History | Annotate | Line # | Download | only in arp
t_arp.sh revision 1.26
      1 #	$NetBSD: t_arp.sh,v 1.26 2017/06/21 09:05:31 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 IP4DST=10.0.1.2
     32 IP4DST_PROXYARP1=10.0.1.3
     33 IP4DST_PROXYARP2=10.0.1.4
     34 
     35 DEBUG=${DEBUG:-false}
     36 TIMEOUT=1
     37 
     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
     47 
     48 arp_cache_expiration_5s_head()
     49 {
     50 	atf_set "descr" "Tests for ARP cache expiration (5s)"
     51 	atf_set "require.progs" "rump_server"
     52 }
     53 
     54 arp_cache_expiration_10s_head()
     55 {
     56 	atf_set "descr" "Tests for ARP cache expiration (10s)"
     57 	atf_set "require.progs" "rump_server"
     58 }
     59 
     60 arp_command_head()
     61 {
     62 	atf_set "descr" "Tests for arp_commands of arp(8)"
     63 	atf_set "require.progs" "rump_server"
     64 }
     65 
     66 arp_garp_head()
     67 {
     68 	atf_set "descr" "Tests for GARP"
     69 	atf_set "require.progs" "rump_server"
     70 }
     71 
     72 arp_cache_overwriting_head()
     73 {
     74 	atf_set "descr" "Tests for behavior of overwriting ARP caches"
     75 	atf_set "require.progs" "rump_server"
     76 }
     77 
     78 arp_proxy_arp_pub_head()
     79 {
     80 	atf_set "descr" "Tests for Proxy ARP (pub)"
     81 	atf_set "require.progs" "rump_server"
     82 }
     83 
     84 arp_proxy_arp_pubproxy_head()
     85 {
     86 	atf_set "descr" "Tests for Proxy ARP (pub proxy)"
     87 	atf_set "require.progs" "rump_server"
     88 }
     89 
     90 arp_link_activation_head()
     91 {
     92 	atf_set "descr" "Tests for activating a new MAC address"
     93 	atf_set "require.progs" "rump_server"
     94 }
     95 
     96 arp_static_head()
     97 {
     98 
     99 	atf_set "descr" "Tests for static ARP entries"
    100 	atf_set "require.progs" "rump_server"
    101 }
    102 
    103 setup_dst_server()
    104 {
    105 
    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
    111 
    112 	$DEBUG && rump.ifconfig shmif0
    113 	$DEBUG && rump.arp -n -a
    114 }
    115 
    116 setup_src_server()
    117 {
    118 	local keep=${1:-0}
    119 
    120 	export RUMP_SERVER=$SOCKSRC
    121 
    122 	# Adjust ARP parameters
    123 	if [ $keep != 0 ]; then
    124 		atf_check -s exit:0 -o ignore \
    125 		    rump.sysctl -w net.inet.arp.keep=$keep
    126 	fi
    127 
    128 	# Setup an interface
    129 	rump_server_add_iface $SOCKSRC shmif0 bus1
    130 	atf_check -s exit:0 rump.ifconfig shmif0 inet $IP4SRC/24
    131 	atf_check -s exit:0 rump.ifconfig shmif0 up
    132 	atf_check -s exit:0 rump.ifconfig -w 10
    133 
    134 	# Sanity check
    135 	$DEBUG && rump.ifconfig shmif0
    136 	$DEBUG && rump.arp -n -a
    137 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    138 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    139 }
    140 
    141 test_cache_expiration()
    142 {
    143 	local arp_keep=$1
    144 	local bonus=2
    145 
    146 	rump_server_start $SOCKSRC
    147 	rump_server_start $SOCKDST
    148 
    149 	setup_dst_server
    150 	setup_src_server $arp_keep
    151 
    152 	#
    153 	# Check if a cache is expired expectedly
    154 	#
    155 	export RUMP_SERVER=$SOCKSRC
    156 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4DST
    157 
    158 	$DEBUG && rump.arp -n -a
    159 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    160 	# Should be cached
    161 	atf_check -s exit:0 -o ignore rump.arp -n $IP4DST
    162 
    163 	atf_check -s exit:0 sleep $(($arp_keep + $bonus))
    164 
    165 	$DEBUG && rump.arp -n -a
    166 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4SRC
    167 	# Should be expired
    168 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n $IP4DST
    169 }
    170 
    171 arp_cache_expiration_5s_body()
    172 {
    173 
    174 	test_cache_expiration 5
    175 	rump_server_destroy_ifaces
    176 }
    177 
    178 arp_cache_expiration_10s_body()
    179 {
    180 
    181 	test_cache_expiration 10
    182 	rump_server_destroy_ifaces
    183 }
    184 
    185 arp_command_body()
    186 {
    187 	local arp_keep=5
    188 	local bonus=2
    189 
    190 	rump_server_start $SOCKSRC
    191 	rump_server_start $SOCKDST
    192 
    193 	setup_dst_server
    194 	setup_src_server $arp_keep
    195 
    196 	export RUMP_SERVER=$SOCKSRC
    197 
    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
    207 
    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
    215 	EOF
    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
    229 
    230 	# Test arp -a
    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
    236 
    237 	# Flush all entries
    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
    246 
    247 	# Test temp option
    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
    253 
    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
    258 
    259 	rump_server_destroy_ifaces
    260 }
    261 
    262 make_pkt_str_arpreq()
    263 {
    264 	local target=$1
    265 	local sender=$2
    266 	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
    267 	pkt="$pkt Request who-has $target tell $sender, length 28"
    268 	echo $pkt
    269 }
    270 
    271 arp_garp_body()
    272 {
    273 	local pkt=
    274 
    275 	rump_server_start $SOCKSRC
    276 
    277 	export RUMP_SERVER=$SOCKSRC
    278 
    279 	# Setup an interface
    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
    285 
    286 	atf_check -s exit:0 sleep 1
    287 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
    288 
    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'"
    295 
    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
    299 
    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'"
    306 
    307 	rump_server_destroy_ifaces
    308 }
    309 
    310 arp_cache_overwriting_body()
    311 {
    312 	local bonus=2
    313 
    314 	rump_server_start $SOCKSRC
    315 	rump_server_start $SOCKDST
    316 
    317 	setup_dst_server
    318 	setup_src_server
    319 
    320 	export RUMP_SERVER=$SOCKSRC
    321 
    322 	# Cannot overwrite a permanent cache
    323 	atf_check -s exit:0 rump.arp -s $IP4SRC b2:a0:20:00:00:ff
    324 	$DEBUG && rump.arp -n -a
    325 	atf_check -s not-exit:0 -e match:'File exists' \
    326 	    rump.arp -s $IP4SRC b2:a0:20:00:00:fe
    327 
    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
    335 
    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
    344 
    345 	rump_server_destroy_ifaces
    346 }
    347 
    348 make_pkt_str_arprep()
    349 {
    350 	local ip=$1
    351 	local mac=$2
    352 	pkt="ethertype ARP (0x0806), length 42: "
    353 	pkt="Reply $ip is-at $mac, length 28"
    354 	echo $pkt
    355 }
    356 
    357 make_pkt_str_garp()
    358 {
    359 	local ip=$1
    360 	local mac=$2
    361 	local pkt=
    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"
    364 	echo $pkt
    365 }
    366 
    367 test_proxy_arp()
    368 {
    369 	local opts= title= flags=
    370 	local type=$1
    371 
    372 	rump_server_start $SOCKSRC
    373 	rump_server_start $SOCKDST tap
    374 
    375 	setup_dst_server
    376 	setup_src_server
    377 
    378 	export RUMP_SERVER=$SOCKDST
    379 	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
    380 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    381 
    382 	if [ "$type" = "pub" ]; then
    383 		opts="pub"
    384 		title="permanent published"
    385 	else
    386 		opts="pub proxy"
    387 		title='permanent published \(proxy only\)'
    388 	fi
    389 
    390 	#
    391 	# Test#1: First setup an endpoint then create proxy arp entry
    392 	#
    393 	export RUMP_SERVER=$SOCKDST
    394 	atf_check -s exit:0 rump.ifconfig tap1 create
    395 	atf_check -s exit:0 rump.ifconfig tap1 $IP4DST_PROXYARP1/24 up
    396 	atf_check -s exit:0 rump.ifconfig -w 10
    397 
    398 	# Try to ping (should fail w/o proxy arp)
    399 	export RUMP_SERVER=$SOCKSRC
    400 	atf_check -s not-exit:0 -o ignore -e ignore \
    401 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    402 
    403 	# Flushing
    404 	extract_new_packets bus1 > ./out
    405 
    406 	# Set up proxy ARP entry
    407 	export RUMP_SERVER=$SOCKDST
    408 	atf_check -s exit:0 -o ignore \
    409 	    rump.arp -s $IP4DST_PROXYARP1 $macaddr_dst $opts
    410 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP1
    411 
    412 	# Try to ping
    413 	export RUMP_SERVER=$SOCKSRC
    414 	if [ "$type" = "pub" ]; then
    415 		# XXX fails
    416 		atf_check -s not-exit:0 -o ignore -e ignore \
    417 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    418 	else
    419 		atf_check -s exit:0 -o ignore \
    420 		    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP1
    421 	fi
    422 
    423 	extract_new_packets bus1 > ./out
    424 	$DEBUG && cat ./out
    425 
    426 	pkt1=$(make_pkt_str_arprep $IP4DST_PROXYARP1 $macaddr_dst)
    427 	pkt2=$(make_pkt_str_garp $IP4DST_PROXYARP1 $macaddr_dst)
    428 	if [ "$type" = "pub" ]; then
    429 		atf_check -s not-exit:0 -x \
    430 		    "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    431 	else
    432 		atf_check -s exit:0 -x "cat ./out |grep -q -e '$pkt1' -e '$pkt2'"
    433 	fi
    434 
    435 	#
    436 	# Test#2: Create proxy arp entry then set up an endpoint
    437 	#
    438 	export RUMP_SERVER=$SOCKDST
    439 	atf_check -s exit:0 -o ignore \
    440 	    rump.arp -s $IP4DST_PROXYARP2 $macaddr_dst $opts
    441 	atf_check -s exit:0 -o match:"$title" rump.arp -n $IP4DST_PROXYARP2
    442 	$DEBUG && rump.netstat -nr -f inet
    443 
    444 	# Try to ping (should fail because no endpoint exists)
    445 	export RUMP_SERVER=$SOCKSRC
    446 	atf_check -s not-exit:0 -o ignore -e ignore \
    447 	    rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    448 
    449 	extract_new_packets bus1 > ./out
    450 	$DEBUG && cat ./out
    451 
    452 	# ARP reply should be sent
    453 	pkt=$(make_pkt_str_arprep $IP4DST_PROXYARP2 $macaddr_dst)
    454 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    455 
    456 	export RUMP_SERVER=$SOCKDST
    457 	atf_check -s exit:0 rump.ifconfig tap2 create
    458 	atf_check -s exit:0 rump.ifconfig tap2 $IP4DST_PROXYARP2/24 up
    459 	atf_check -s exit:0 rump.ifconfig -w 10
    460 
    461 	# Try to ping
    462 	export RUMP_SERVER=$SOCKSRC
    463 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST_PROXYARP2
    464 }
    465 
    466 arp_proxy_arp_pub_body()
    467 {
    468 
    469 	test_proxy_arp pub
    470 	rump_server_destroy_ifaces
    471 }
    472 
    473 arp_proxy_arp_pubproxy_body()
    474 {
    475 
    476 	test_proxy_arp pubproxy
    477 	rump_server_destroy_ifaces
    478 }
    479 
    480 arp_link_activation_body()
    481 {
    482 	local bonus=2
    483 
    484 	rump_server_start $SOCKSRC
    485 	rump_server_start $SOCKDST
    486 
    487 	setup_dst_server
    488 	setup_src_server
    489 
    490 	# flush old packets
    491 	extract_new_packets bus1 > ./out
    492 
    493 	export RUMP_SERVER=$SOCKSRC
    494 
    495 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    496 	    b2:a1:00:00:00:01
    497 
    498 	atf_check -s exit:0 sleep 1
    499 	extract_new_packets bus1 > ./out
    500 	$DEBUG && cat ./out
    501 
    502 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    503 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    504 
    505 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
    506 	    b2:a1:00:00:00:02 active
    507 
    508 	atf_check -s exit:0 sleep 1
    509 	extract_new_packets bus1 > ./out
    510 	$DEBUG && cat ./out
    511 
    512 	pkt=$(make_pkt_str_arpreq $IP4SRC $IP4SRC)
    513 	atf_check -s exit:0 -x \
    514 	    "cat ./out |grep '$pkt' |grep -q 'b2:a1:00:00:00:02'"
    515 
    516 	rump_server_destroy_ifaces
    517 }
    518 
    519 arp_static_body()
    520 {
    521 	local macaddr_src=
    522 
    523 	rump_server_start $SOCKSRC
    524 	rump_server_start $SOCKDST
    525 
    526 	setup_dst_server
    527 	setup_src_server
    528 
    529 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    530 
    531 	# Set a (valid) static ARP entry for the src server
    532 	export RUMP_SERVER=$SOCKDST
    533 	$DEBUG && rump.arp -n -a
    534 	atf_check -s exit:0 -o ignore rump.arp -s $IP4SRC $macaddr_src
    535 	$DEBUG && rump.arp -n -a
    536 
    537 	# Test receiving an ARP request with the static ARP entry (as spa/sha)
    538 	export RUMP_SERVER=$SOCKSRC
    539 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    540 
    541 	rump_server_destroy_ifaces
    542 }
    543 
    544 arp_cache_expiration_5s_cleanup()
    545 {
    546 	$DEBUG && dump
    547 	cleanup
    548 }
    549 
    550 arp_cache_expiration_10s_cleanup()
    551 {
    552 	$DEBUG && dump
    553 	cleanup
    554 }
    555 
    556 arp_command_cleanup()
    557 {
    558 	$DEBUG && dump
    559 	cleanup
    560 }
    561 
    562 arp_garp_cleanup()
    563 {
    564 	$DEBUG && dump
    565 	cleanup
    566 }
    567 
    568 arp_cache_overwriting_cleanup()
    569 {
    570 	$DEBUG && dump
    571 	cleanup
    572 }
    573 
    574 arp_proxy_arp_pub_cleanup()
    575 {
    576 	$DEBUG && dump
    577 	cleanup
    578 }
    579 
    580 arp_proxy_arp_pubproxy_cleanup()
    581 {
    582 	$DEBUG && dump
    583 	cleanup
    584 }
    585 
    586 arp_link_activation_cleanup()
    587 {
    588 	$DEBUG && dump
    589 	cleanup
    590 }
    591 
    592 arp_static_cleanup()
    593 {
    594 	$DEBUG && dump
    595 	cleanup
    596 }
    597 
    598 atf_test_case arp_rtm cleanup
    599 arp_rtm_head()
    600 {
    601 
    602 	atf_set "descr" "Tests for routing messages on operations of ARP entries"
    603 	atf_set "require.progs" "rump_server"
    604 }
    605 
    606 arp_rtm_body()
    607 {
    608 	local macaddr_src= macaddr_dst=
    609 	local file=./tmp
    610 	local pid= str=
    611 
    612 	rump_server_start $SOCKSRC
    613 	rump_server_start $SOCKDST
    614 
    615 	setup_dst_server
    616 	setup_src_server
    617 
    618 	macaddr_src=$(get_macaddr $SOCKSRC shmif0)
    619 	macaddr_dst=$(get_macaddr $SOCKDST shmif0)
    620 
    621 	export RUMP_SERVER=$SOCKSRC
    622 
    623 	# Test ping and a resulting routing message (RTM_ADD)
    624 	rump.route -n monitor -c 1 > $file &
    625 	pid=$?
    626 	sleep 1
    627 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP4DST
    628 	wait $pid
    629 	$DEBUG && cat $file
    630 
    631 	str="RTM_ADD.+<UP,HOST,DONE,LLINFO,CLONED>"
    632 	atf_check -s exit:0 -o match:"$str" cat $file
    633 	str="<DST,GATEWAY,IFP,IFA>"
    634 	atf_check -s exit:0 -o match:"$str" cat $file
    635 	str="$IP4DST link#2 $macaddr_src $IP4SRC"
    636 	atf_check -s exit:0 -o match:"$str" cat $file
    637 
    638 	# Test arp -d and resulting routing messages (RTM_GET and RTM_DELETE)
    639 	rump.route -n monitor -c 2 > $file &
    640 	pid=$?
    641 	sleep 1
    642 	atf_check -s exit:0 -o ignore rump.arp -d $IP4DST
    643 	wait $pid
    644 	$DEBUG && cat $file
    645 
    646 	str="RTM_GET.+<UP,DONE,LLINFO>"
    647 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    648 	str="<DST,GATEWAY,IFP,IFA>"
    649 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    650 	str="$IP4DST $macaddr_dst $macaddr_src $IP4SRC"
    651 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_GET $file
    652 	str="RTM_DELETE.+<UP,DONE,LLINFO>"
    653 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    654 	str="<DST,GATEWAY,IFP,IFA>"
    655 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    656 	str="$IP4DST $macaddr_dst $macaddr_src $IP4SRC"
    657 	atf_check -s exit:0 -o match:"$str" grep -A 3 RTM_DELETE $file
    658 
    659 	rump_server_destroy_ifaces
    660 }
    661 
    662 arp_rtm_cleanup()
    663 {
    664 
    665 	$DEBUG && dump
    666 	cleanup
    667 }
    668 
    669 atf_init_test_cases()
    670 {
    671 	atf_add_test_case arp_cache_expiration_5s
    672 	atf_add_test_case arp_cache_expiration_10s
    673 	atf_add_test_case arp_command
    674 	atf_add_test_case arp_garp
    675 	atf_add_test_case arp_cache_overwriting
    676 	atf_add_test_case arp_proxy_arp_pub
    677 	atf_add_test_case arp_proxy_arp_pubproxy
    678 	atf_add_test_case arp_link_activation
    679 	atf_add_test_case arp_static
    680 	atf_add_test_case arp_rtm
    681 }
    682