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