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