t_dad.sh revision 1.6 1 # $NetBSD: t_dad.sh,v 1.6 2016/09/16 00:14:33 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=false
37
38 atf_test_case dad_basic cleanup
39 atf_test_case dad_duplicated cleanup
40
41 dad_basic_head()
42 {
43 atf_set "descr" "Tests for IPv6 DAD basic behavior"
44 atf_set "require.progs" "rump_server"
45 }
46
47 dad_duplicated_head()
48 {
49 atf_set "descr" "Tests for IPv6 DAD duplicated state"
50 atf_set "require.progs" "rump_server"
51 }
52
53 setup_server()
54 {
55 local sock=$1
56 local ip=$2
57
58 export RUMP_SERVER=$sock
59
60 atf_check -s exit:0 rump.ifconfig shmif0 create
61 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
62 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
63 atf_check -s exit:0 rump.ifconfig shmif0 up
64 atf_check -s exit:0 rump.ifconfig -w 10
65
66 $DEBUG && rump.ifconfig shmif0
67 }
68
69 make_ns_pkt_str()
70 {
71 local id=$1
72 local target=$2
73 pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::"
74 pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation,"
75 pkt="$pkt who has $target, length 24"
76 echo $pkt
77 }
78
79 extract_new_packets()
80 {
81 local old=./old
82
83 if [ ! -f $old ]; then
84 old=/dev/null
85 fi
86
87 shmif_dumpbus -p - bus1 2>/dev/null| \
88 tcpdump -n -e -r - 2>/dev/null > ./new
89 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
90 mv -f ./new ./old
91 cat ./diff
92 }
93
94 dad_basic_body()
95 {
96 local pkt=
97 local localip1=fc00::1
98 local localip2=fc00::2
99 local localip3=fc00::3
100
101 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
102 export RUMP_SERVER=$SOCKLOCAL
103
104 atf_check -s exit:0 rump.ifconfig shmif0 create
105 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
106 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1
107 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
108 $DEBUG && rump.ifconfig shmif0
109
110 atf_check -s exit:0 rump.ifconfig shmif0 up
111 rump.ifconfig shmif0 > ./out
112 $DEBUG && cat ./out
113
114 # The primary address doesn't start with tentative state
115 atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative"
116 # The alias address starts with tentative state
117 # XXX we have no stable way to check this, so skip for now
118 #atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
119
120 atf_check -s exit:0 sleep 2
121 extract_new_packets > ./out
122 $DEBUG && cat ./out
123
124 # Check DAD probe packets (Neighbor Solicitation Message)
125 pkt=$(make_ns_pkt_str 2 $localip2)
126 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
127 # No DAD for the primary address
128 pkt=$(make_ns_pkt_str 1 $localip1)
129 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
130
131 # Waiting for DAD complete
132 atf_check -s exit:0 rump.ifconfig -w 10
133 extract_new_packets > ./out
134 $DEBUG && cat ./out
135
136 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
137
138 # The alias address left tentative
139 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
140
141 #
142 # Add a new address on the fly
143 #
144 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
145
146 # The new address starts with tentative state
147 # XXX we have no stable way to check this, so skip for now
148 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
149
150 # Check DAD probe packets (Neighbor Solicitation Message)
151 atf_check -s exit:0 sleep 2
152 extract_new_packets > ./out
153 $DEBUG && cat ./out
154 pkt=$(make_ns_pkt_str 3 $localip3)
155 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
156
157 # Waiting for DAD complete
158 atf_check -s exit:0 rump.ifconfig -w 10
159 extract_new_packets > ./out
160 $DEBUG && cat ./out
161
162 # IPv6 DAD doesn't announce (Neighbor Advertisement Message)
163
164 # The new address left tentative
165 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
166 }
167
168 dad_duplicated_body()
169 {
170 local localip1=fc00::1
171 local localip2=fc00::11
172 local peerip=fc00::2
173
174 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
175 atf_check -s exit:0 ${inetserver} $SOCKPEER
176
177 setup_server $SOCKLOCAL $localip1
178 setup_server $SOCKPEER $peerip
179
180 export RUMP_SERVER=$SOCKLOCAL
181
182 # The primary address isn't marked as duplicated
183 atf_check -s exit:0 -o not-match:'DUPLICATED' \
184 -x "rump.ifconfig shmif0 |grep $localip1"
185
186 #
187 # Add a new address duplicated with the peer server
188 #
189 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
190 atf_check -s exit:0 sleep 1
191
192 # The new address is marked as duplicated
193 atf_check -s exit:0 -o match:'DUPLICATED' \
194 -x "rump.ifconfig shmif0 |grep $peerip"
195
196 # A unique address isn't marked as duplicated
197 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
198 atf_check -s exit:0 sleep 1
199 atf_check -s exit:0 -o not-match:'DUPLICATED' \
200 -x "rump.ifconfig shmif0 |grep $localip2"
201 }
202
203 cleanup()
204 {
205 gdb -ex bt /usr/bin/rump_server rump_server.core
206 gdb -ex bt /usr/sbin/arp arp.core
207 env RUMP_SERVER=$SOCKLOCAL rump.halt
208 env RUMP_SERVER=$SOCKPEER rump.halt
209 }
210
211 dump_local()
212 {
213 export RUMP_SERVER=$SOCKLOCAL
214 rump.netstat -nr
215 rump.arp -n -a
216 rump.ifconfig
217 $HIJACKING dmesg
218 }
219
220 dump_peer()
221 {
222 export RUMP_SERVER=$SOCKPEER
223 rump.netstat -nr
224 rump.arp -n -a
225 rump.ifconfig
226 $HIJACKING dmesg
227 }
228
229 dump()
230 {
231 dump_local
232 dump_peer
233 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
234 }
235
236 dad_basic_cleanup()
237 {
238 $DEBUG && dump_local
239 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
240 env RUMP_SERVER=$SOCKLOCAL rump.halt
241 }
242
243 dad_duplicated_cleanup()
244 {
245 $DEBUG && dump
246 cleanup
247 }
248
249 atf_init_test_cases()
250 {
251 atf_add_test_case dad_basic
252 atf_add_test_case dad_duplicated
253 }
254