t_ndp.sh revision 1.8 1 # $NetBSD: t_ndp.sh,v 1.8 2015/11/18 04:13:01 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 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
31
32 SOCKSRC=unix://commsock1
33 SOCKDST=unix://commsock2
34 IP6SRC=fc00::1
35 IP6DST=fc00::2
36
37 DEBUG=true
38 TIMEOUT=1
39
40 atf_test_case cache_expiration cleanup
41 atf_test_case command cleanup
42 atf_test_case cache_overwriting cleanup
43 atf_test_case neighborgcthresh cleanup
44
45 cache_expiration_head()
46 {
47 atf_set "descr" "Tests for NDP cache expiration"
48 atf_set "require.progs" "rump_server"
49 }
50
51 command_head()
52 {
53 atf_set "descr" "Tests for commands of ndp(8)"
54 atf_set "require.progs" "rump_server"
55 }
56
57 cache_overwriting_head()
58 {
59 atf_set "descr" "Tests for behavior of overwriting NDP caches"
60 atf_set "require.progs" "rump_server"
61 }
62
63 neighborgcthresh_head()
64 {
65 atf_set "descr" "Tests for GC of neighbor caches"
66 atf_set "require.progs" "rump_server"
67 }
68
69 setup_dst_server()
70 {
71 local assign_ip=$1
72
73 export RUMP_SERVER=$SOCKDST
74 atf_check -s exit:0 rump.ifconfig shmif0 create
75 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
76 if [ "$assign_ip" != no ]; then
77 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6DST
78 fi
79 atf_check -s exit:0 rump.ifconfig shmif0 up
80 atf_check -s exit:0 rump.ifconfig -w 10
81
82 $DEBUG && rump.ifconfig shmif0
83 $DEBUG && rump.ndp -n -a
84 }
85
86 setup_src_server()
87 {
88 $DEBUG && ulimit -c unlimited
89 export RUMP_SERVER=$SOCKSRC
90
91 # Setup an interface
92 atf_check -s exit:0 rump.ifconfig shmif0 create
93 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
94 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC
95 atf_check -s exit:0 rump.ifconfig shmif0 up
96 atf_check -s exit:0 rump.ifconfig -w 10
97
98 # Sanity check
99 $DEBUG && rump.ifconfig shmif0
100 $DEBUG && rump.ndp -n -a
101 atf_check -s exit:0 -o ignore rump.ndp -n $IP6SRC
102 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
103 }
104
105 get_timeout()
106 {
107 local timeout=$(env RUMP_SERVER=$SOCKSRC rump.ndp -n $IP6DST |grep $IP6DST|awk '{print $4;}')
108 timeout=${timeout%s}
109 echo $timeout
110 }
111
112 cache_expiration_body()
113 {
114 atf_check -s exit:0 ${inetserver} $SOCKSRC
115 atf_check -s exit:0 ${inetserver} $SOCKDST
116
117 setup_dst_server
118 setup_src_server
119
120 #
121 # Check if a cache is expired expectedly
122 #
123 export RUMP_SERVER=$SOCKSRC
124 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
125
126 $DEBUG && rump.ndp -n -a
127 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
128 # Should be cached
129 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
130
131 timeout=$(get_timeout $IP6DST)
132
133 atf_check -s exit:0 sleep $(($timeout + 1))
134
135 $DEBUG && rump.ndp -n -a
136 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
137 # Expired but remains until GC sweaps it (1 day)
138 atf_check -s exit:0 -o match:'(1d0h0m|23h59m)' rump.ndp -n $IP6DST
139 }
140
141 ifdown_dst_server()
142 {
143 export RUMP_SERVER=$SOCKDST
144 atf_check -s exit:0 rump.ifconfig shmif0 down
145 export RUMP_SERVER=$SOCKSRC
146 }
147
148 command_body()
149 {
150 atf_check -s exit:0 ${inetserver} $SOCKSRC
151 atf_check -s exit:0 ${inetserver} $SOCKDST
152
153 setup_dst_server
154 setup_src_server
155
156 export RUMP_SERVER=$SOCKSRC
157
158 # Add and delete a static entry
159 $DEBUG && rump.ndp -n -a
160 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
161 $DEBUG && rump.ndp -n -a
162 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
163 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
164 $DEBUG && rump.ndp -n -a
165 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
166
167 # Add multiple entries via a file (XXX not implemented)
168 #cat - > ./list <<-EOF
169 #fc00::11 b2:a0:20:00:00:11
170 #fc00::12 b2:a0:20:00:00:12
171 #fc00::13 b2:a0:20:00:00:13
172 #fc00::14 b2:a0:20:00:00:14
173 #fc00::15 b2:a0:20:00:00:15
174 #EOF
175 #$DEBUG && rump.ndp -n -a
176 #atf_check -s exit:0 -o ignore rump.ndp -f ./list
177 #$DEBUG && rump.ndp -n -a
178
179 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
180 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11
181 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12
182
183 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
184 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
185 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
186
187 # Test ndp -a
188 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
189 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a
190
191 # Ensure no packet upsets the src server
192 ifdown_dst_server
193
194 # Flush all entries (-c)
195 $DEBUG && rump.ndp -n -a
196 atf_check -s exit:0 -o ignore rump.ndp -c
197 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
198 # Only the static caches are not deleted
199 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
200 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
201
202 # Test temp option (XXX it doesn't work; expire time isn't set)
203 $DEBUG && rump.ndp -n -a
204 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
205 rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
206 $DEBUG && rump.ndp -n -a
207 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
208
209 return 0
210 }
211
212 cache_overwriting_body()
213 {
214 atf_check -s exit:0 ${inetserver} $SOCKSRC
215 atf_check -s exit:0 ${inetserver} $SOCKDST
216
217 setup_dst_server
218 setup_src_server
219
220 export RUMP_SERVER=$SOCKSRC
221
222 # Cannot overwrite a permanent cache
223 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff
224 $DEBUG && rump.ndp -n -a
225
226 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
227 $DEBUG && rump.ndp -n -a
228 # Can overwrite a dynamic cache
229 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00
230 $DEBUG && rump.ndp -n -a
231 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST
232
233 # Test temp option (XXX it doesn't work; expire time isn't set)
234 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
235 #$DEBUG && rump.ndp -n -a
236 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
237 # Cannot overwrite a temp cache
238 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff
239 #$DEBUG && rump.ndp -n -a
240
241 return 0
242 }
243
244 get_n_caches()
245 {
246
247 echo $(rump.ndp -a -n |grep -v -e Neighbor -e permanent |wc -l)
248 }
249
250 neighborgcthresh_body()
251 {
252
253 atf_check -s exit:0 ${inetserver} $SOCKSRC
254 atf_check -s exit:0 ${inetserver} $SOCKDST
255
256 setup_dst_server no
257 setup_src_server
258
259 export RUMP_SERVER=$SOCKDST
260 for i in $(seq 0 9); do
261 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6DST}$i
262 done
263
264 export RUMP_SERVER=$SOCKSRC
265
266 # ping to 3 destinations
267 $DEBUG && rump.ndp -n -a
268 for i in $(seq 0 2); do
269 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
270 ${IP6DST}$i
271 done
272 $DEBUG && rump.ndp -n -a
273
274 # 3 caches should be created
275 atf_check_equal $(get_n_caches) 3
276
277 # ping to additional 3 destinations
278 for i in $(seq 3 5); do
279 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
280 ${IP6DST}$i
281 done
282 $DEBUG && rump.ndp -n -a
283
284 # 6 caches should be created in total
285 atf_check_equal $(get_n_caches) 6
286
287 # Limit the number of neighbor caches to 5
288 atf_check -s exit:0 -o ignore rump.sysctl -w \
289 net.inet6.ip6.neighborgcthresh=5
290
291 # ping to additional 4 destinations
292 for i in $(seq 6 9); do
293 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
294 ${IP6DST}$i
295 done
296
297 # More than 5 caches should be created in total, but exceeded caches
298 # should be GC-ed
299 if [ "$(get_n_caches)" -gt 5 ]; then
300 atf_fail "Neighbor caches are not GC-ed"
301 fi
302
303 return 0
304 }
305
306 cleanup()
307 {
308 env RUMP_SERVER=$SOCKSRC rump.halt
309 env RUMP_SERVER=$SOCKDST rump.halt
310 }
311
312 dump_src()
313 {
314 export RUMP_SERVER=$SOCKSRC
315 rump.netstat -nr
316 rump.ndp -n -a
317 rump.ifconfig
318 $HIJACKING dmesg
319 }
320
321 dump_dst()
322 {
323 export RUMP_SERVER=$SOCKDST
324 rump.netstat -nr
325 rump.ndp -n -a
326 rump.ifconfig
327 $HIJACKING dmesg
328 }
329
330 dump()
331 {
332 dump_src
333 dump_dst
334 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
335 $DEBUG && gdb -ex bt /usr/bin/rump_server rump_server.core
336 $DEBUG && gdb -ex bt /usr/sbin/rump.ndp rump.ndp.core
337 }
338
339 cache_expiration_cleanup()
340 {
341 $DEBUG && dump
342 cleanup
343 }
344
345 command_cleanup()
346 {
347 $DEBUG && dump
348 cleanup
349 }
350
351 cache_overwriting_cleanup()
352 {
353 $DEBUG && dump
354 cleanup
355 }
356
357 neighborgcthresh_cleanup()
358 {
359 $DEBUG && dump
360 cleanup
361 }
362
363 atf_init_test_cases()
364 {
365 atf_add_test_case cache_expiration
366 atf_add_test_case command
367 atf_add_test_case cache_overwriting
368 atf_add_test_case neighborgcthresh
369 }
370