1313680Sngie# $NetBSD: t_dad.sh,v 1.12 2016/11/25 08:51:17 ozaki-r Exp $ 2303980Sngie# 3303980Sngie# Copyright (c) 2015 The NetBSD Foundation, Inc. 4303980Sngie# All rights reserved. 5303980Sngie# 6303980Sngie# Redistribution and use in source and binary forms, with or without 7303980Sngie# modification, are permitted provided that the following conditions 8303980Sngie# are met: 9303980Sngie# 1. Redistributions of source code must retain the above copyright 10303980Sngie# notice, this list of conditions and the following disclaimer. 11303980Sngie# 2. Redistributions in binary form must reproduce the above copyright 12303980Sngie# notice, this list of conditions and the following disclaimer in the 13303980Sngie# documentation and/or other materials provided with the distribution. 14303980Sngie# 15303980Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16303980Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17303980Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18303980Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19303980Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20303980Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21303980Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22303980Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23303980Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24303980Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25303980Sngie# POSSIBILITY OF SUCH DAMAGE. 26303980Sngie# 27303980Sngie 28303980SngieSOCKLOCAL=unix://commsock1 29303980SngieSOCKPEER=unix://commsock2 30303980Sngie 31313680SngieDEBUG=${DEBUG:-false} 32303980Sngie 33313680Sngieduplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]" 34313680Sngie 35303980Sngieatf_test_case dad_basic cleanup 36303980Sngieatf_test_case dad_duplicated cleanup 37313680Sngieatf_test_case dad_count cleanup 38303980Sngie 39303980Sngiedad_basic_head() 40303980Sngie{ 41303980Sngie atf_set "descr" "Tests for IPv6 DAD basic behavior" 42303980Sngie atf_set "require.progs" "rump_server" 43303980Sngie} 44303980Sngie 45303980Sngiedad_duplicated_head() 46303980Sngie{ 47303980Sngie atf_set "descr" "Tests for IPv6 DAD duplicated state" 48303980Sngie atf_set "require.progs" "rump_server" 49303980Sngie} 50303980Sngie 51313680Sngiedad_count_head() 52313680Sngie{ 53313680Sngie atf_set "descr" "Tests for IPv6 DAD count behavior" 54313680Sngie atf_set "require.progs" "rump_server" 55313680Sngie} 56313680Sngie 57303980Sngiesetup_server() 58303980Sngie{ 59303980Sngie local sock=$1 60303980Sngie local ip=$2 61303980Sngie 62313680Sngie rump_server_add_iface $sock shmif0 bus1 63313680Sngie 64303980Sngie export RUMP_SERVER=$sock 65303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip 66303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 67303980Sngie atf_check -s exit:0 rump.ifconfig -w 10 68303980Sngie 69303980Sngie $DEBUG && rump.ifconfig shmif0 70303980Sngie} 71303980Sngie 72303980Sngiemake_ns_pkt_str() 73303980Sngie{ 74303980Sngie local id=$1 75303980Sngie local target=$2 76303980Sngie pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::" 77303980Sngie pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation," 78303980Sngie pkt="$pkt who has $target, length 24" 79303980Sngie echo $pkt 80303980Sngie} 81303980Sngie 82303980Sngiedad_basic_body() 83303980Sngie{ 84303980Sngie local pkt= 85303980Sngie local localip1=fc00::1 86303980Sngie local localip2=fc00::2 87303980Sngie local localip3=fc00::3 88303980Sngie 89313680Sngie rump_server_start $SOCKLOCAL netinet6 90313680Sngie rump_server_add_iface $SOCKLOCAL shmif0 bus1 91313680Sngie 92303980Sngie export RUMP_SERVER=$SOCKLOCAL 93303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1 94303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2 95303980Sngie $DEBUG && rump.ifconfig shmif0 96303980Sngie 97303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 98303980Sngie rump.ifconfig shmif0 > ./out 99303980Sngie $DEBUG && cat ./out 100303980Sngie 101303980Sngie # The primary address doesn't start with tentative state 102303980Sngie atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative" 103303980Sngie # The alias address starts with tentative state 104303980Sngie # XXX we have no stable way to check this, so skip for now 105303980Sngie #atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative" 106303980Sngie 107303980Sngie atf_check -s exit:0 sleep 2 108313680Sngie extract_new_packets bus1 > ./out 109303980Sngie $DEBUG && cat ./out 110303980Sngie 111303980Sngie # Check DAD probe packets (Neighbor Solicitation Message) 112303980Sngie pkt=$(make_ns_pkt_str 2 $localip2) 113303980Sngie atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 114303980Sngie # No DAD for the primary address 115303980Sngie pkt=$(make_ns_pkt_str 1 $localip1) 116303980Sngie atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'" 117303980Sngie 118303980Sngie # Waiting for DAD complete 119303980Sngie atf_check -s exit:0 rump.ifconfig -w 10 120313680Sngie extract_new_packets bus1 > ./out 121303980Sngie $DEBUG && cat ./out 122303980Sngie 123303980Sngie # IPv6 DAD doesn't announce (Neighbor Advertisement Message) 124303980Sngie 125303980Sngie # The alias address left tentative 126303980Sngie atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative" 127303980Sngie 128303980Sngie # 129303980Sngie # Add a new address on the fly 130303980Sngie # 131303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3 132303980Sngie 133303980Sngie # The new address starts with tentative state 134303980Sngie # XXX we have no stable way to check this, so skip for now 135303980Sngie #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative" 136303980Sngie 137303980Sngie # Check DAD probe packets (Neighbor Solicitation Message) 138303980Sngie atf_check -s exit:0 sleep 2 139313680Sngie extract_new_packets bus1 > ./out 140303980Sngie $DEBUG && cat ./out 141303980Sngie pkt=$(make_ns_pkt_str 3 $localip3) 142303980Sngie atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'" 143303980Sngie 144303980Sngie # Waiting for DAD complete 145303980Sngie atf_check -s exit:0 rump.ifconfig -w 10 146313680Sngie extract_new_packets bus1 > ./out 147303980Sngie $DEBUG && cat ./out 148303980Sngie 149303980Sngie # IPv6 DAD doesn't announce (Neighbor Advertisement Message) 150303980Sngie 151303980Sngie # The new address left tentative 152303980Sngie atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative" 153313680Sngie 154313680Sngie rump_server_destroy_ifaces 155303980Sngie} 156303980Sngie 157303980Sngiedad_duplicated_body() 158303980Sngie{ 159303980Sngie local localip1=fc00::1 160303980Sngie local localip2=fc00::11 161303980Sngie local peerip=fc00::2 162303980Sngie 163313680Sngie rump_server_start $SOCKLOCAL netinet6 164313680Sngie rump_server_start $SOCKPEER netinet6 165303980Sngie 166303980Sngie setup_server $SOCKLOCAL $localip1 167303980Sngie setup_server $SOCKPEER $peerip 168303980Sngie 169303980Sngie export RUMP_SERVER=$SOCKLOCAL 170303980Sngie 171303980Sngie # The primary address isn't marked as duplicated 172313680Sngie atf_check -s exit:0 -o not-match:"$localip1.+$duplicated" \ 173313680Sngie rump.ifconfig shmif0 174303980Sngie 175303980Sngie # 176303980Sngie # Add a new address duplicated with the peer server 177303980Sngie # 178303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip 179303980Sngie atf_check -s exit:0 sleep 1 180303980Sngie 181303980Sngie # The new address is marked as duplicated 182313680Sngie atf_check -s exit:0 -o match:"$peerip.+$duplicated" \ 183313680Sngie rump.ifconfig shmif0 184303980Sngie 185303980Sngie # A unique address isn't marked as duplicated 186303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2 187303980Sngie atf_check -s exit:0 sleep 1 188313680Sngie atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \ 189313680Sngie rump.ifconfig shmif0 190313680Sngie 191313680Sngie rump_server_destroy_ifaces 192303980Sngie} 193303980Sngie 194313680Sngiedad_count_test() 195303980Sngie{ 196313680Sngie local pkt= 197313680Sngie local count=$1 198313680Sngie local id=$2 199313680Sngie local target=$3 200313680Sngie 201313680Sngie # 202313680Sngie # Set DAD count to $count 203313680Sngie # 204313680Sngie atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count 205313680Sngie 206313680Sngie # Add a new address 207313680Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target 208313680Sngie 209313680Sngie # Waiting for DAD complete 210313680Sngie atf_check -s exit:0 rump.ifconfig -w 20 211313680Sngie 212313680Sngie # Check the number of DAD probe packets (Neighbor Solicitation Message) 213313680Sngie atf_check -s exit:0 sleep 2 214313680Sngie extract_new_packets bus1 > ./out 215313680Sngie $DEBUG && cat ./out 216313680Sngie pkt=$(make_ns_pkt_str $id $target) 217313680Sngie atf_check -s exit:0 -o match:"$count" \ 218313680Sngie -x "cat ./out |grep '$pkt' | wc -l | tr -d ' '" 219303980Sngie} 220303980Sngie 221313680Sngiedad_count_body() 222303980Sngie{ 223313680Sngie local localip1=fc00::1 224313680Sngie local localip2=fc00::2 225313680Sngie 226313680Sngie rump_server_start $SOCKLOCAL netinet6 227313680Sngie rump_server_add_iface $SOCKLOCAL shmif0 bus1 228313680Sngie 229303980Sngie export RUMP_SERVER=$SOCKLOCAL 230303980Sngie 231313680Sngie # Check default value 232313680Sngie atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count 233303980Sngie 234313680Sngie # Setup interface 235313680Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 236313680Sngie atf_check -s exit:0 sleep 2 237313680Sngie rump.ifconfig shmif0 > ./out 238313680Sngie $DEBUG && cat ./out 239313680Sngie 240313680Sngie # 241313680Sngie # Set and test DAD count (count=1) 242313680Sngie # 243313680Sngie dad_count_test 1 1 $localip1 244313680Sngie 245313680Sngie # 246313680Sngie # Set and test DAD count (count=8) 247313680Sngie # 248313680Sngie dad_count_test 8 2 $localip2 249313680Sngie 250313680Sngie rump_server_destroy_ifaces 251303980Sngie} 252303980Sngie 253303980Sngiedad_basic_cleanup() 254303980Sngie{ 255313680Sngie $DEBUG && dump 256313680Sngie cleanup 257303980Sngie} 258303980Sngie 259303980Sngiedad_duplicated_cleanup() 260303980Sngie{ 261303980Sngie $DEBUG && dump 262303980Sngie cleanup 263303980Sngie} 264303980Sngie 265313680Sngiedad_count_cleanup() 266313680Sngie{ 267313680Sngie $DEBUG && dump 268313680Sngie cleanup 269313680Sngie} 270313680Sngie 271303980Sngieatf_init_test_cases() 272303980Sngie{ 273303980Sngie atf_add_test_case dad_basic 274303980Sngie atf_add_test_case dad_duplicated 275313680Sngie atf_add_test_case dad_count 276303980Sngie} 277