Home | History | Annotate | Line # | Download | only in ndp
t_dad.sh revision 1.10
      1 #	$NetBSD: t_dad.sh,v 1.10 2016/11/24 08:52:20 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"
     29 inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif"
     30 inetserver="$inetserver -lrumpdev"
     31 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
     32 
     33 SOCKLOCAL=unix://commsock1
     34 SOCKPEER=unix://commsock2
     35 
     36 DEBUG=${DEBUG:-false}
     37 
     38 duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]"
     39 
     40 atf_test_case dad_basic cleanup
     41 atf_test_case dad_duplicated cleanup
     42 atf_test_case dad_count cleanup
     43 
     44 dad_basic_head()
     45 {
     46 	atf_set "descr" "Tests for IPv6 DAD basic behavior"
     47 	atf_set "require.progs" "rump_server"
     48 }
     49 
     50 dad_duplicated_head()
     51 {
     52 	atf_set "descr" "Tests for IPv6 DAD duplicated state"
     53 	atf_set "require.progs" "rump_server"
     54 }
     55 
     56 dad_count_head()
     57 {
     58 	atf_set "descr" "Tests for IPv6 DAD count behavior"
     59 	atf_set "require.progs" "rump_server"
     60 }
     61 
     62 setup_server()
     63 {
     64 	local sock=$1
     65 	local ip=$2
     66 
     67 	export RUMP_SERVER=$sock
     68 
     69 	atf_check -s exit:0 rump.ifconfig shmif0 create
     70 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
     71 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
     72 	atf_check -s exit:0 rump.ifconfig shmif0 up
     73 	atf_check -s exit:0 rump.ifconfig -w 10
     74 
     75 	$DEBUG && rump.ifconfig shmif0
     76 }
     77 
     78 make_ns_pkt_str()
     79 {
     80 	local id=$1
     81 	local target=$2
     82 	pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::"
     83 	pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation,"
     84 	pkt="$pkt who has $target, length 24"
     85 	echo $pkt
     86 }
     87 
     88 dad_basic_body()
     89 {
     90 	local pkt=
     91 	local localip1=fc00::1
     92 	local localip2=fc00::2
     93 	local localip3=fc00::3
     94 
     95 	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
     96 	export RUMP_SERVER=$SOCKLOCAL
     97 
     98 	atf_check -s exit:0 rump.ifconfig shmif0 create
     99 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    100 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1
    101 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
    102 	$DEBUG && rump.ifconfig shmif0
    103 
    104 	atf_check -s exit:0 rump.ifconfig shmif0 up
    105 	rump.ifconfig shmif0 > ./out
    106 	$DEBUG && cat ./out
    107 
    108 	# The primary address doesn't start with tentative state
    109 	atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative"
    110 	# The alias address starts with tentative state
    111 	# XXX we have no stable way to check this, so skip for now
    112 	#atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
    113 
    114 	atf_check -s exit:0 sleep 2
    115 	extract_new_packets bus1 > ./out
    116 	$DEBUG && cat ./out
    117 
    118 	# Check DAD probe packets (Neighbor Solicitation Message)
    119 	pkt=$(make_ns_pkt_str 2 $localip2)
    120 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    121 	# No DAD for the primary address
    122 	pkt=$(make_ns_pkt_str 1 $localip1)
    123 	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
    124 
    125 	# Waiting for DAD complete
    126 	atf_check -s exit:0 rump.ifconfig -w 10
    127 	extract_new_packets bus1 > ./out
    128 	$DEBUG && cat ./out
    129 
    130 	# IPv6 DAD doesn't announce (Neighbor Advertisement Message)
    131 
    132 	# The alias address left tentative
    133 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
    134 
    135 	#
    136 	# Add a new address on the fly
    137 	#
    138 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
    139 
    140 	# The new address starts with tentative state
    141 	# XXX we have no stable way to check this, so skip for now
    142 	#atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
    143 
    144 	# Check DAD probe packets (Neighbor Solicitation Message)
    145 	atf_check -s exit:0 sleep 2
    146 	extract_new_packets bus1 > ./out
    147 	$DEBUG && cat ./out
    148 	pkt=$(make_ns_pkt_str 3 $localip3)
    149 	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
    150 
    151 	# Waiting for DAD complete
    152 	atf_check -s exit:0 rump.ifconfig -w 10
    153 	extract_new_packets bus1 > ./out
    154 	$DEBUG && cat ./out
    155 
    156 	# IPv6 DAD doesn't announce (Neighbor Advertisement Message)
    157 
    158 	# The new address left tentative
    159 	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
    160 }
    161 
    162 dad_duplicated_body()
    163 {
    164 	local localip1=fc00::1
    165 	local localip2=fc00::11
    166 	local peerip=fc00::2
    167 
    168 	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
    169 	atf_check -s exit:0 ${inetserver} $SOCKPEER
    170 
    171 	setup_server $SOCKLOCAL $localip1
    172 	setup_server $SOCKPEER $peerip
    173 
    174 	export RUMP_SERVER=$SOCKLOCAL
    175 
    176 	# The primary address isn't marked as duplicated
    177 	atf_check -s exit:0 -o not-match:"$localip1.+$duplicated" \
    178 	    rump.ifconfig shmif0
    179 
    180 	#
    181 	# Add a new address duplicated with the peer server
    182 	#
    183 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
    184 	atf_check -s exit:0 sleep 1
    185 
    186 	# The new address is marked as duplicated
    187 	atf_check -s exit:0 -o match:"$peerip.+$duplicated" \
    188 	    rump.ifconfig shmif0
    189 
    190 	# A unique address isn't marked as duplicated
    191 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
    192 	atf_check -s exit:0 sleep 1
    193 	atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \
    194 	    rump.ifconfig shmif0
    195 }
    196 
    197 dad_count_test()
    198 {
    199 	local pkt=
    200 	local count=$1
    201 	local id=$2
    202 	local target=$3
    203 
    204 	#
    205 	# Set DAD count to $count
    206 	#
    207 	atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count
    208 
    209 	# Add a new address
    210 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target
    211 
    212 	# Waiting for DAD complete
    213 	atf_check -s exit:0 rump.ifconfig -w 20
    214 
    215 	# Check the number of DAD probe packets (Neighbor Solicitation Message)
    216 	atf_check -s exit:0 sleep 2
    217 	extract_new_packets bus1 > ./out
    218 	$DEBUG && cat ./out
    219 	pkt=$(make_ns_pkt_str $id $target)
    220 	atf_check -s exit:0 -o match:"$count" \
    221 	    -x "cat ./out |grep '$pkt' | wc -l | tr -d ' '"
    222 }
    223 
    224 dad_count_body()
    225 {
    226 	local localip1=fc00::1
    227 	local localip2=fc00::2
    228 
    229 	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
    230 	export RUMP_SERVER=$SOCKLOCAL
    231 
    232 	# Check default value
    233 	atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count
    234 
    235 	# Setup interface
    236 	atf_check -s exit:0 rump.ifconfig shmif0 create
    237 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
    238 	atf_check -s exit:0 rump.ifconfig shmif0 up
    239 	atf_check -s exit:0 sleep 2
    240 	rump.ifconfig shmif0 > ./out
    241 	$DEBUG && cat ./out
    242 
    243 	#
    244 	# Set and test DAD count (count=1)
    245 	#
    246 	dad_count_test 1 1 $localip1
    247 
    248 	#
    249 	# Set and test DAD count (count=8)
    250 	#
    251 	dad_count_test 8 2 $localip2
    252 }
    253 
    254 cleanup()
    255 {
    256 	gdb -ex bt /usr/bin/rump_server rump_server.core
    257 	gdb -ex bt /usr/sbin/arp arp.core
    258 	env RUMP_SERVER=$SOCKLOCAL rump.halt
    259 	env RUMP_SERVER=$SOCKPEER rump.halt
    260 }
    261 
    262 dump_local()
    263 {
    264 	export RUMP_SERVER=$SOCKLOCAL
    265 	rump.netstat -nr
    266 	rump.arp -n -a
    267 	rump.ifconfig
    268 	$HIJACKING dmesg
    269 }
    270 
    271 dump_peer()
    272 {
    273 	export RUMP_SERVER=$SOCKPEER
    274 	rump.netstat -nr
    275 	rump.arp -n -a
    276 	rump.ifconfig
    277 	$HIJACKING dmesg
    278 }
    279 
    280 dump()
    281 {
    282 	dump_local
    283 	dump_peer
    284 	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    285 }
    286 
    287 dad_basic_cleanup()
    288 {
    289 	$DEBUG && dump_local
    290 	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    291 	env RUMP_SERVER=$SOCKLOCAL rump.halt
    292 }
    293 
    294 dad_duplicated_cleanup()
    295 {
    296 	$DEBUG && dump
    297 	cleanup
    298 }
    299 
    300 dad_count_cleanup()
    301 {
    302 	$DEBUG && dump_local
    303 	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
    304 	env RUMP_SERVER=$SOCKLOCAL rump.halt
    305 }
    306 
    307 atf_init_test_cases()
    308 {
    309 	atf_add_test_case dad_basic
    310 	atf_add_test_case dad_duplicated
    311 	atf_add_test_case dad_count
    312 }
    313