1# $NetBSD: t_dad.sh,v 1.15 2017/03/11 02:01:10 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 28SOCKLOCAL=unix://commsock1 29SOCKPEER=unix://commsock2 30 31DEBUG=${DEBUG:-false} 32 33atf_test_case dad_basic cleanup 34atf_test_case dad_duplicated cleanup 35 36dad_basic_head() 37{ 38 atf_set "descr" "Tests for IPv4 DAD basic behavior" 39 atf_set "require.progs" "rump_server" 40} 41 42dad_duplicated_head() 43{ 44 atf_set "descr" "Tests for IPv4 DAD duplicated state" 45 atf_set "require.progs" "rump_server" 46} 47 48setup_server() 49{ 50 local sock=$1 51 local ip=$2 52 53 rump_server_add_iface $sock shmif0 bus1 54 55 export RUMP_SERVER=$sock 56 atf_check -s exit:0 rump.ifconfig shmif0 inet $ip/24 57 atf_check -s exit:0 rump.ifconfig shmif0 up 58 atf_check -s exit:0 rump.ifconfig -w 10 59 60 $DEBUG && rump.ifconfig shmif0 61} 62 63make_pkt_str() 64{ 65 local target=$1 66 local sender=$2 67 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP \(0x0806\), length 42:" 68 pkt="$pkt Request who-has $target tell $sender, length 28" 69 echo $pkt 70} 71 72dad_basic_body() 73{ 74 local pkt= 75 76 rump_server_start $SOCKLOCAL 77 rump_server_add_iface $SOCKLOCAL shmif0 bus1 78 79 export RUMP_SERVER=$SOCKLOCAL 80 81 # Increase the number of trials, which makes the tests stable 82 atf_check -s exit:0 -o match:'3 -> 5' \ 83 rump.sysctl -w net.inet.ip.dad_count=5 84 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 exit:0 -o not-match:'10\.0\.0\.1.+TENTATIVE' cat ./out 95 # The alias address starts with tentative state 96 atf_check -s exit:0 -o match:'10\.0\.0\.2.+TENTATIVE' cat ./out 97 98 atf_check -s exit:0 sleep 2 99 extract_new_packets bus1 > ./out 100 $DEBUG && cat ./out 101 102 # Check DAD probe packets 103 pkt=$(make_pkt_str 10.0.0.2 0.0.0.0) 104 atf_check -s exit:0 -o match:"$pkt" cat ./out 105 # No DAD for the primary address 106 pkt=$(make_pkt_str 10.0.0.1 0.0.0.0) 107 atf_check -s exit:0 -o not-match:"$pkt" cat ./out 108 109 # Waiting for DAD complete 110 atf_check -s exit:0 rump.ifconfig -w 10 111 # Give a chance to send a DAD announce packet 112 atf_check -s exit:0 sleep 2 113 extract_new_packets bus1 > ./out 114 $DEBUG && cat ./out 115 116 # Check the DAD announce packet 117 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2) 118 atf_check -s exit:0 -o match:"$pkt" cat ./out 119 # The alias address left tentative 120 atf_check -s exit:0 -o not-match:'10\.0\.0\.2.+TENTATIVE' \ 121 rump.ifconfig shmif0 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 atf_check -s exit:0 -o match:'10\.0\.0\.3.+TENTATIVE' \ 130 rump.ifconfig shmif0 131 132 # Check DAD probe packets 133 atf_check -s exit:0 sleep 2 134 extract_new_packets bus1 > ./out 135 $DEBUG && cat ./out 136 pkt=$(make_pkt_str 10.0.0.3 0.0.0.0) 137 atf_check -s exit:0 -o match:"$pkt" cat ./out 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 2 143 extract_new_packets bus1 > ./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 -o match:"$pkt" cat ./out 149 # The new address left tentative 150 atf_check -s exit:0 -o not-match:'10\.0\.0\.3.+TENTATIVE' \ 151 rump.ifconfig shmif0 152 153 rump_server_destroy_ifaces 154} 155 156dad_duplicated_body() 157{ 158 local localip1=10.0.1.1 159 local localip2=10.0.1.11 160 local peerip=10.0.1.2 161 162 rump_server_start $SOCKLOCAL 163 rump_server_start $SOCKPEER 164 165 setup_server $SOCKLOCAL $localip1 166 setup_server $SOCKPEER $peerip 167 168 export RUMP_SERVER=$SOCKLOCAL 169 170 # The primary address isn't marked as duplicated 171 atf_check -s exit:0 -o not-match:"${localip1}.+DUPLICATED" \ 172 rump.ifconfig shmif0 173 174 # 175 # Add a new address duplicated with the peer server 176 # 177 atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias 178 atf_check -s exit:0 sleep 2 179 180 # The new address is marked as duplicated 181 atf_check -s exit:0 -o match:"${peerip}.+DUPLICATED" \ 182 rump.ifconfig shmif0 183 184 # A unique address isn't marked as duplicated 185 atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias 186 atf_check -s exit:0 sleep 2 187 atf_check -s exit:0 -o not-match:"${localip2}.+DUPLICATED" \ 188 rump.ifconfig shmif0 189 190 rump_server_destroy_ifaces 191} 192 193dad_basic_cleanup() 194{ 195 $DEBUG && dump 196 cleanup 197} 198 199dad_duplicated_cleanup() 200{ 201 $DEBUG && dump 202 cleanup 203} 204 205atf_init_test_cases() 206{ 207 atf_add_test_case dad_basic 208 atf_add_test_case dad_duplicated 209} 210