t_dad.sh revision 1.9 1 # $NetBSD: t_dad.sh,v 1.9 2016/11/07 05:25: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
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet"
29 inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif"
30 inetserver="$inetserver -lrumpdev"
31 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
32
33 SOCKLOCAL=unix://commsock1
34 SOCKPEER=unix://commsock2
35
36 DEBUG=${DEBUG:-false}
37
38 duplicated="[Dd][Uu][Pp][Ll][Ii][Cc][Aa][Tt][Ee][Dd]"
39
40 atf_test_case dad_basic cleanup
41 atf_test_case dad_duplicated cleanup
42 atf_test_case dad_count cleanup
43
44 dad_basic_head()
45 {
46 atf_set "descr" "Tests for IPv6 DAD basic behavior"
47 atf_set "require.progs" "rump_server"
48 }
49
50 dad_duplicated_head()
51 {
52 atf_set "descr" "Tests for IPv6 DAD duplicated state"
53 atf_set "require.progs" "rump_server"
54 }
55
56 dad_count_head()
57 {
58 atf_set "descr" "Tests for IPv6 DAD count behavior"
59 atf_set "require.progs" "rump_server"
60 }
61
62 setup_server()
63 {
64 local sock=$1
65 local ip=$2
66
67 export RUMP_SERVER=$sock
68
69 atf_check -s exit:0 rump.ifconfig shmif0 create
70 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
71 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
72 atf_check -s exit:0 rump.ifconfig shmif0 up
73 atf_check -s exit:0 rump.ifconfig -w 10
74
75 $DEBUG && rump.ifconfig shmif0
76 }
77
78 make_ns_pkt_str()
79 {
80 local id=$1
81 local target=$2
82 pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::"
83 pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation,"
84 pkt="$pkt who has $target, length 24"
85 echo $pkt
86 }
87
88 extract_new_packets()
89 {
90 local old=./old
91
92 if [ ! -f $old ]; then
93 old=/dev/null
94 fi
95
96 shmif_dumpbus -p - bus1 2>/dev/null| \
97 tcpdump -n -e -r - 2>/dev/null > ./new
98 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
99 mv -f ./new ./old
100 cat ./diff
101 }
102
103 dad_basic_body()
104 {
105 local pkt=
106 local localip1=fc00::1
107 local localip2=fc00::2
108 local localip3=fc00::3
109
110 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
111 export RUMP_SERVER=$SOCKLOCAL
112
113 atf_check -s exit:0 rump.ifconfig shmif0 create
114 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
115 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1
116 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
117 $DEBUG && rump.ifconfig shmif0
118
119 atf_check -s exit:0 rump.ifconfig shmif0 up
120 rump.ifconfig shmif0 > ./out
121 $DEBUG && cat ./out
122
123 # The primary address doesn't start with tentative state
124 atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative"
125 # The alias address starts with tentative state
126 # XXX we have no stable way to check this, so skip for now
127 #atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
128
129 atf_check -s exit:0 sleep 2
130 extract_new_packets > ./out
131 $DEBUG && cat ./out
132
133 # Check DAD probe packets (Neighbor Solicitation Message)
134 pkt=$(make_ns_pkt_str 2 $localip2)
135 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
136 # No DAD for the primary address
137 pkt=$(make_ns_pkt_str 1 $localip1)
138 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
139
140 # Waiting for DAD complete
141 atf_check -s exit:0 rump.ifconfig -w 10
142 extract_new_packets > ./out
143 $DEBUG && cat ./out
144
145 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
146
147 # The alias address left tentative
148 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
149
150 #
151 # Add a new address on the fly
152 #
153 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
154
155 # The new address starts with tentative state
156 # XXX we have no stable way to check this, so skip for now
157 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
158
159 # Check DAD probe packets (Neighbor Solicitation Message)
160 atf_check -s exit:0 sleep 2
161 extract_new_packets > ./out
162 $DEBUG && cat ./out
163 pkt=$(make_ns_pkt_str 3 $localip3)
164 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
165
166 # Waiting for DAD complete
167 atf_check -s exit:0 rump.ifconfig -w 10
168 extract_new_packets > ./out
169 $DEBUG && cat ./out
170
171 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
172
173 # The new address left tentative
174 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
175 }
176
177 dad_duplicated_body()
178 {
179 local localip1=fc00::1
180 local localip2=fc00::11
181 local peerip=fc00::2
182
183 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
184 atf_check -s exit:0 ${inetserver} $SOCKPEER
185
186 setup_server $SOCKLOCAL $localip1
187 setup_server $SOCKPEER $peerip
188
189 export RUMP_SERVER=$SOCKLOCAL
190
191 # The primary address isn't marked as duplicated
192 atf_check -s exit:0 -o not-match:"$localip1.+$duplicated" \
193 rump.ifconfig shmif0
194
195 #
196 # Add a new address duplicated with the peer server
197 #
198 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
199 atf_check -s exit:0 sleep 1
200
201 # The new address is marked as duplicated
202 atf_check -s exit:0 -o match:"$peerip.+$duplicated" \
203 rump.ifconfig shmif0
204
205 # A unique address isn't marked as duplicated
206 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
207 atf_check -s exit:0 sleep 1
208 atf_check -s exit:0 -o not-match:"$localip2.+$duplicated" \
209 rump.ifconfig shmif0
210 }
211
212 dad_count_test()
213 {
214 local pkt=
215 local count=$1
216 local id=$2
217 local target=$3
218
219 #
220 # Set DAD count to $count
221 #
222 atf_check -s exit:0 rump.sysctl -w -q net.inet6.ip6.dad_count=$count
223
224 # Add a new address
225 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $target
226
227 # Waiting for DAD complete
228 atf_check -s exit:0 rump.ifconfig -w 20
229
230 # Check the number of DAD probe packets (Neighbor Solicitation Message)
231 atf_check -s exit:0 sleep 2
232 extract_new_packets > ./out
233 $DEBUG && cat ./out
234 pkt=$(make_ns_pkt_str $id $target)
235 atf_check -s exit:0 -o match:"$count" \
236 -x "cat ./out |grep '$pkt' | wc -l | tr -d ' '"
237 }
238
239 dad_count_body()
240 {
241 local localip1=fc00::1
242 local localip2=fc00::2
243
244 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
245 export RUMP_SERVER=$SOCKLOCAL
246
247 # Check default value
248 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.dad_count
249
250 # Setup interface
251 atf_check -s exit:0 rump.ifconfig shmif0 create
252 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
253 atf_check -s exit:0 rump.ifconfig shmif0 up
254 atf_check -s exit:0 sleep 2
255 rump.ifconfig shmif0 > ./out
256 $DEBUG && cat ./out
257
258 #
259 # Set and test DAD count (count=1)
260 #
261 dad_count_test 1 1 $localip1
262
263 #
264 # Set and test DAD count (count=8)
265 #
266 dad_count_test 8 2 $localip2
267 }
268
269 cleanup()
270 {
271 gdb -ex bt /usr/bin/rump_server rump_server.core
272 gdb -ex bt /usr/sbin/arp arp.core
273 env RUMP_SERVER=$SOCKLOCAL rump.halt
274 env RUMP_SERVER=$SOCKPEER rump.halt
275 }
276
277 dump_local()
278 {
279 export RUMP_SERVER=$SOCKLOCAL
280 rump.netstat -nr
281 rump.arp -n -a
282 rump.ifconfig
283 $HIJACKING dmesg
284 }
285
286 dump_peer()
287 {
288 export RUMP_SERVER=$SOCKPEER
289 rump.netstat -nr
290 rump.arp -n -a
291 rump.ifconfig
292 $HIJACKING dmesg
293 }
294
295 dump()
296 {
297 dump_local
298 dump_peer
299 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
300 }
301
302 dad_basic_cleanup()
303 {
304 $DEBUG && dump_local
305 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
306 env RUMP_SERVER=$SOCKLOCAL rump.halt
307 }
308
309 dad_duplicated_cleanup()
310 {
311 $DEBUG && dump
312 cleanup
313 }
314
315 dad_count_cleanup()
316 {
317 $DEBUG && dump_local
318 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
319 env RUMP_SERVER=$SOCKLOCAL rump.halt
320 }
321
322 atf_init_test_cases()
323 {
324 atf_add_test_case dad_basic
325 atf_add_test_case dad_duplicated
326 atf_add_test_case dad_count
327 }
328