Home | History | Annotate | Line # | Download | only in arp
t_dad.sh revision 1.10
      1 #	$NetBSD: t_dad.sh,v 1.10 2016/11/24 08:52:19 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"
     30 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
     31 
     32 SOCKLOCAL=unix://commsock1
     33 SOCKPEER=unix://commsock2
     34 
     35 DEBUG=${DEBUG:-false}
     36 
     37 atf_test_case dad_basic cleanup
     38 atf_test_case dad_duplicated cleanup
     39 
     40 dad_basic_head()
     41 {
     42 	atf_set "descr" "Tests for IPv4 DAD basic behavior"
     43 	atf_set "require.progs" "rump_server"
     44 }
     45 
     46 dad_duplicated_head()
     47 {
     48 	atf_set "descr" "Tests for IPv4 DAD duplicated state"
     49 	atf_set "require.progs" "rump_server"
     50 }
     51 
     52 setup_server()
     53 {
     54 	local sock=$1
     55 	local ip=$2
     56 
     57 	export RUMP_SERVER=$sock
     58 
     59 	atf_check -s exit:0 rump.ifconfig shmif0 create
     60 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
     61 	atf_check -s exit:0 rump.ifconfig shmif0 inet $ip/24
     62 	atf_check -s exit:0 rump.ifconfig shmif0 up
     63 	atf_check -s exit:0 rump.ifconfig -w 10
     64 
     65 	$DEBUG && rump.ifconfig shmif0
     66 }
     67 
     68 make_pkt_str()
     69 {
     70 	local target=$1
     71 	local sender=$2
     72 	pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
     73 	pkt="$pkt Request who-has $target tell $sender, length 28"
     74 	echo $pkt
     75 }
     76 
     77 dad_basic_body()
     78 {
     79 	local pkt=
     80 
     81 	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
     82 	export RUMP_SERVER=$SOCKLOCAL
     83 
     84 	atf_check -s exit:0 rump.ifconfig shmif0 create
     85 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
     86 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
     87 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
     88 	$DEBUG && rump.ifconfig shmif0
     89 
     90 	atf_check -s exit:0 rump.ifconfig shmif0 up
     91 	rump.ifconfig shmif0 > ./out
     92 	$DEBUG && cat ./out
     93 
     94 	# The primary address doesn't start with tentative state
     95 	atf_check -s not-exit:0 -x "cat ./out |grep 10.0.0.1 |grep -iq tentative"
     96 	# The alias address starts with tentative state
     97 	# XXX we have no stable way to check this, so skip for now
     98 	#atf_check -s exit:0 -x "cat ./out |grep 10.0.0.2 |grep -iq tentative"
     99 
    100 	atf_check -s exit:0 sleep 2
    101 	extract_new_packets > ./out
    102 	$DEBUG && cat ./out
    103 
    104 	# Check DAD probe packets
    105 	pkt=$(make_pkt_str 10.0.0.2 0.0.0.0)
    106 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    107 	# No DAD for the primary address
    108 	pkt=$(make_pkt_str 10.0.0.1 0.0.0.0)
    109 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    110 
    111 	# Waiting for DAD complete
    112 	atf_check -s exit:0 rump.ifconfig -w 10
    113 	# Give a chance to send a DAD announce packet
    114 	atf_check -s exit:0 sleep 1
    115 	extract_new_packets > ./out
    116 	$DEBUG && cat ./out
    117 
    118 	# Check the DAD announce packet
    119 	pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
    120 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    121 	# The alias address left tentative
    122 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -iq tentative"
    123 
    124 	#
    125 	# Add a new address on the fly
    126 	#
    127 	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias
    128 
    129 	# The new address starts with tentative state
    130 	# XXX we have no stable way to check this, so skip for now
    131 	#atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative"
    132 
    133 	# Check DAD probe packets
    134 	atf_check -s exit:0 sleep 2
    135 	extract_new_packets > ./out
    136 	$DEBUG && cat ./out
    137 	pkt=$(make_pkt_str 10.0.0.3 0.0.0.0)
    138 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    139 
    140 	# Waiting for DAD complete
    141 	atf_check -s exit:0 rump.ifconfig -w 10
    142 	# Give a chance to send a DAD announce packet
    143 	atf_check -s exit:0 sleep 1
    144 	extract_new_packets > ./out
    145 	$DEBUG && cat ./out
    146 
    147 	# Check the DAD announce packet
    148 	pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
    149 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    150 	# The new address left tentative
    151 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -iq tentative"
    152 }
    153 
    154 dad_duplicated_body()
    155 {
    156 	local localip1=10.0.1.1
    157 	local localip2=10.0.1.11
    158 	local peerip=10.0.1.2
    159 
    160 	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
    161 	atf_check -s exit:0 ${inetserver} $SOCKPEER
    162 
    163 	setup_server $SOCKLOCAL $localip1
    164 	setup_server $SOCKPEER $peerip
    165 
    166 	export RUMP_SERVER=$SOCKLOCAL
    167 
    168 	# The primary address isn't marked as duplicated
    169 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -iq duplicated"
    170 
    171 	#
    172 	# Add a new address duplicated with the peer server
    173 	#
    174 	atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias
    175 	atf_check -s exit:0 sleep 1
    176 
    177 	# The new address is marked as duplicated
    178 	atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -iq duplicated"
    179 
    180 	# A unique address isn't marked as duplicated
    181 	atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias
    182 	atf_check -s exit:0 sleep 1
    183 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -iq duplicated"
    184 }
    185 
    186 cleanup()
    187 {
    188 	env RUMP_SERVER=$SOCKLOCAL rump.halt
    189 	env RUMP_SERVER=$SOCKPEER rump.halt
    190 }
    191 
    192 dump_local()
    193 {
    194 	export RUMP_SERVER=$SOCKLOCAL
    195 	rump.netstat -nr
    196 	rump.arp -n -a
    197 	rump.ifconfig
    198 	$HIJACKING dmesg
    199 }
    200 
    201 dump_peer()
    202 {
    203 	export RUMP_SERVER=$SOCKPEER
    204 	rump.netstat -nr
    205 	rump.arp -n -a
    206 	rump.ifconfig
    207 	$HIJACKING dmesg
    208 }
    209 
    210 dump()
    211 {
    212 	dump_local
    213 	dump_peer
    214 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    215 }
    216 
    217 dad_basic_cleanup()
    218 {
    219 	$DEBUG && dump_local
    220 	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    221 	env RUMP_SERVER=$SOCKLOCAL rump.halt
    222 }
    223 
    224 dad_duplicated_cleanup()
    225 {
    226 	$DEBUG && dump
    227 	cleanup
    228 }
    229 
    230 atf_init_test_cases()
    231 {
    232 	atf_add_test_case dad_basic
    233 	atf_add_test_case dad_duplicated
    234 }
    235