t_dad.sh revision 1.4.2.2 1 # $NetBSD: t_dad.sh,v 1.4.2.2 2017/01/07 08:56:56 pgoyette 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 SOCKLOCAL=unix://commsock1
29 SOCKPEER=unix://commsock2
30
31 DEBUG=${DEBUG:-false}
32
33 duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]"
34
35 atf_test_case dad_basic cleanup
36 atf_test_case dad_duplicated cleanup
37 atf_test_case dad_count cleanup
38
39 dad_basic_head()
40 {
41 atf_set "descr" "Tests for IPv6 DAD basic behavior"
42 atf_set "require.progs" "rump_server"
43 }
44
45 dad_duplicated_head()
46 {
47 atf_set "descr" "Tests for IPv6 DAD duplicated state"
48 atf_set "require.progs" "rump_server"
49 }
50
51 dad_count_head()
52 {
53 atf_set "descr" "Tests for IPv6 DAD count behavior"
54 atf_set "require.progs" "rump_server"
55 }
56
57 setup_server()
58 {
59 local sock=$1
60 local ip=$2
61
62 rump_server_add_iface $sock shmif0 bus1
63
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
68
69 $DEBUG && rump.ifconfig shmif0
70 }
71
72 make_ns_pkt_str()
73 {
74 local id=$1
75 local target=$2
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"
79 echo $pkt
80 }
81
82 dad_basic_body()
83 {
84 local pkt=
85 local localip1=fc00::1
86 local localip2=fc00::2
87 local localip3=fc00::3
88
89 rump_server_start $SOCKLOCAL netinet6
90 rump_server_add_iface $SOCKLOCAL shmif0 bus1
91
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
96
97 atf_check -s exit:0 rump.ifconfig shmif0 up
98 rump.ifconfig shmif0 > ./out
99 $DEBUG && cat ./out
100
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"
106
107 atf_check -s exit:0 sleep 2
108 extract_new_packets bus1 > ./out
109 $DEBUG && cat ./out
110
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'"
117
118 # Waiting for DAD complete
119 atf_check -s exit:0 rump.ifconfig -w 10
120 extract_new_packets bus1 > ./out
121 $DEBUG && cat ./out
122
123 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
124
125 # The alias address left tentative
126 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
127
128 #
129 # Add a new address on the fly
130 #
131 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
132
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"
136
137 # Check DAD probe packets (Neighbor Solicitation Message)
138 atf_check -s exit:0 sleep 2
139 extract_new_packets bus1 > ./out
140 $DEBUG && cat ./out
141 pkt=$(make_ns_pkt_str 3 $localip3)
142 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
143
144 # Waiting for DAD complete
145 atf_check -s exit:0 rump.ifconfig -w 10
146 extract_new_packets bus1 > ./out
147 $DEBUG && cat ./out
148
149 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
150
151 # The new address left tentative
152 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
153
154 rump_server_destroy_ifaces
155 }
156
157 dad_duplicated_body()
158 {
159 local localip1=fc00::1
160 local localip2=fc00::11
161 local peerip=fc00::2
162
163 rump_server_start $SOCKLOCAL netinet6
164 rump_server_start $SOCKPEER netinet6
165
166 setup_server $SOCKLOCAL $localip1
167 setup_server $SOCKPEER $peerip
168
169 export RUMP_SERVER=$SOCKLOCAL
170
171 # The primary address isn't marked as duplicated
172 atf_check -s exit:0 -o not-match:"$localip1.+$duplicated" \
173 rump.ifconfig shmif0
174
175 #
176 # Add a new address duplicated with the peer server
177 #
178 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
179 atf_check -s exit:0 sleep 1
180
181 # The new address is marked as duplicated
182 atf_check -s exit:0 -o match:"$peerip.+$duplicated" \
183 rump.ifconfig shmif0
184
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" \
189 rump.ifconfig shmif0
190
191 rump_server_destroy_ifaces
192 }
193
194 dad_count_test()
195 {
196 local pkt=
197 local count=$1
198 local id=$2
199 local target=$3
200
201 #
202 # Set DAD count to $count
203 #
204 atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count
205
206 # Add a new address
207 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target
208
209 # Waiting for DAD complete
210 atf_check -s exit:0 rump.ifconfig -w 20
211
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
215 $DEBUG && cat ./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 ' '"
219 }
220
221 dad_count_body()
222 {
223 local localip1=fc00::1
224 local localip2=fc00::2
225
226 rump_server_start $SOCKLOCAL netinet6
227 rump_server_add_iface $SOCKLOCAL shmif0 bus1
228
229 export RUMP_SERVER=$SOCKLOCAL
230
231 # Check default value
232 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count
233
234 # Setup interface
235 atf_check -s exit:0 rump.ifconfig shmif0 up
236 atf_check -s exit:0 sleep 2
237 rump.ifconfig shmif0 > ./out
238 $DEBUG && cat ./out
239
240 #
241 # Set and test DAD count (count=1)
242 #
243 dad_count_test 1 1 $localip1
244
245 #
246 # Set and test DAD count (count=8)
247 #
248 dad_count_test 8 2 $localip2
249
250 rump_server_destroy_ifaces
251 }
252
253 dad_basic_cleanup()
254 {
255 $DEBUG && dump
256 cleanup
257 }
258
259 dad_duplicated_cleanup()
260 {
261 $DEBUG && dump
262 cleanup
263 }
264
265 dad_count_cleanup()
266 {
267 $DEBUG && dump
268 cleanup
269 }
270
271 atf_init_test_cases()
272 {
273 atf_add_test_case dad_basic
274 atf_add_test_case dad_duplicated
275 atf_add_test_case dad_count
276 }
277