1 # $NetBSD: t_dad.sh,v 1.12 2016/11/25 08:51:17 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
28 SOCKLOCAL=unix://commsock1
29 SOCKPEER=unix://commsock2
33 duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]"
35 atf_test_case dad_basic cleanup
36 atf_test_case dad_duplicated cleanup
37 atf_test_case dad_count cleanup
41 atf_set "descr" "Tests for IPv6 DAD basic behavior"
42 atf_set "require.progs" "rump_server"
47 atf_set "descr" "Tests for IPv6 DAD duplicated state"
48 atf_set "require.progs" "rump_server"
53 atf_set "descr" "Tests for IPv6 DAD count behavior"
54 atf_set "require.progs" "rump_server"
62 rump_server_add_iface $sock shmif0 bus1
64 export RUMP_SERVER=$sock
65 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
66 atf_check -s exit:0 rump.ifconfig shmif0 up
67 atf_check -s exit:0 rump.ifconfig -w 10
69 $DEBUG && rump.ifconfig shmif0
76 pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::"
77 pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation,"
78 pkt="$pkt who has $target, length 24"
85 local localip1=fc00::1
86 local localip2=fc00::2
87 local localip3=fc00::3
89 rump_server_start $SOCKLOCAL netinet6
90 rump_server_add_iface $SOCKLOCAL shmif0 bus1
92 export RUMP_SERVER=$SOCKLOCAL
93 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1
94 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
95 $DEBUG && rump.ifconfig shmif0
97 atf_check -s exit:0 rump.ifconfig shmif0 up
98 rump.ifconfig shmif0 > ./out
101 # The primary address doesn't start with tentative state
102 atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative"
103 # The alias address starts with tentative state
104 # XXX we have no stable way to check this, so skip for now
105 #atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
107 atf_check -s exit:0 sleep 2
108 extract_new_packets bus1 > ./out
111 # Check DAD probe packets (Neighbor Solicitation Message)
112 pkt=$(make_ns_pkt_str 2 $localip2)
113 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
114 # No DAD for the primary address
115 pkt=$(make_ns_pkt_str 1 $localip1)
116 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
118 # Waiting for DAD complete
119 atf_check -s exit:0 rump.ifconfig -w 10
120 extract_new_packets bus1 > ./out
123 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
125 # The alias address left tentative
126 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
129 # Add a new address on the fly
131 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
133 # The new address starts with tentative state
134 # XXX we have no stable way to check this, so skip for now
135 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
137 # Check DAD probe packets (Neighbor Solicitation Message)
138 atf_check -s exit:0 sleep 2
139 extract_new_packets bus1 > ./out
141 pkt=$(make_ns_pkt_str 3 $localip3)
142 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
144 # Waiting for DAD complete
145 atf_check -s exit:0 rump.ifconfig -w 10
146 extract_new_packets bus1 > ./out
149 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
151 # The new address left tentative
152 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
154 rump_server_destroy_ifaces
157 dad_duplicated_body()
159 local localip1=fc00::1
160 local localip2=fc00::11
163 rump_server_start $SOCKLOCAL netinet6
164 rump_server_start $SOCKPEER netinet6
166 setup_server $SOCKLOCAL $localip1
167 setup_server $SOCKPEER $peerip
169 export RUMP_SERVER=$SOCKLOCAL
171 # The primary address isn't marked as duplicated
172 atf_check -s exit:0 -o not-match:"$localip1.+$duplicated" \
176 # Add a new address duplicated with the peer server
178 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
179 atf_check -s exit:0 sleep 1
181 # The new address is marked as duplicated
182 atf_check -s exit:0 -o match:"$peerip.+$duplicated" \
185 # A unique address isn't marked as duplicated
186 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
187 atf_check -s exit:0 sleep 1
188 atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \
191 rump_server_destroy_ifaces
202 # Set DAD count to $count
204 atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count
207 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target
209 # Waiting for DAD complete
210 atf_check -s exit:0 rump.ifconfig -w 20
212 # Check the number of DAD probe packets (Neighbor Solicitation Message)
213 atf_check -s exit:0 sleep 2
214 extract_new_packets bus1 > ./out
216 pkt=$(make_ns_pkt_str $id $target)
217 atf_check -s exit:0 -o match:"$count" \
218 -x "cat ./out |grep '$pkt' | wc -l | tr -d ' '"
223 local localip1=fc00::1
224 local localip2=fc00::2
226 rump_server_start $SOCKLOCAL netinet6
227 rump_server_add_iface $SOCKLOCAL shmif0 bus1
229 export RUMP_SERVER=$SOCKLOCAL
231 # Check default value
232 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count
235 atf_check -s exit:0 rump.ifconfig shmif0 up
236 atf_check -s exit:0 sleep 2
237 rump.ifconfig shmif0 > ./out
241 # Set and test DAD count (count=1)
243 dad_count_test 1 1 $localip1
246 # Set and test DAD count (count=8)
248 dad_count_test 8 2 $localip2
250 rump_server_destroy_ifaces
259 dad_duplicated_cleanup()
271 atf_init_test_cases()
273 atf_add_test_case dad_basic
274 atf_add_test_case dad_duplicated
275 atf_add_test_case dad_count