t_ndp.sh revision 1.4 1 # $NetBSD: t_ndp.sh,v 1.4 2015/08/10 09:32: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
44 cache_expiration_head()
45 {
46 atf_set "descr" "Tests for NDP cache expiration"
47 atf_set "require.progs" "rump_server"
48 }
49
50 command_head()
51 {
52 atf_set "descr" "Tests for commands of ndp(8)"
53 atf_set "require.progs" "rump_server"
54 }
55
56 cache_overwriting_head()
57 {
58 atf_set "descr" "Tests for behavior of overwriting NDP caches"
59 atf_set "require.progs" "rump_server"
60 }
61
62 setup_dst_server()
63 {
64 export RUMP_SERVER=$SOCKDST
65 atf_check -s exit:0 rump.ifconfig shmif0 create
66 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
67 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6DST
68 atf_check -s exit:0 rump.ifconfig shmif0 up
69 atf_check -s exit:0 rump.ifconfig -w 10
70
71 $DEBUG && rump.ifconfig shmif0
72 $DEBUG && rump.ndp -n -a
73 }
74
75 setup_src_server()
76 {
77 $DEBUG && ulimit -c unlimited
78 export RUMP_SERVER=$SOCKSRC
79
80 # Setup an interface
81 atf_check -s exit:0 rump.ifconfig shmif0 create
82 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
83 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC
84 atf_check -s exit:0 rump.ifconfig shmif0 up
85 atf_check -s exit:0 rump.ifconfig -w 10
86
87 # Sanity check
88 $DEBUG && rump.ifconfig shmif0
89 $DEBUG && rump.ndp -n -a
90 atf_check -s exit:0 -o ignore rump.ndp -n $IP6SRC
91 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
92 }
93
94 get_timeout()
95 {
96 local timeout=$(env RUMP_SERVER=$SOCKSRC rump.ndp -n $IP6DST |grep $IP6DST|awk '{print $4;}')
97 timeout=${timeout%s}
98 echo $timeout
99 }
100
101 cache_expiration_body()
102 {
103 atf_check -s exit:0 ${inetserver} $SOCKSRC
104 atf_check -s exit:0 ${inetserver} $SOCKDST
105
106 setup_dst_server
107 setup_src_server
108
109 #
110 # Check if a cache is expired expectedly
111 #
112 export RUMP_SERVER=$SOCKSRC
113 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
114
115 $DEBUG && rump.ndp -n -a
116 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
117 # Should be cached
118 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
119
120 timeout=$(get_timeout $IP6DST)
121
122 atf_check -s exit:0 sleep $(($timeout + 1))
123
124 $DEBUG && rump.ndp -n -a
125 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
126 # Expired but remains until GC sweaps it (1 day)
127 atf_check -s exit:0 -o match:'23h59m' rump.ndp -n $IP6DST
128 }
129
130 command_body()
131 {
132 atf_check -s exit:0 ${inetserver} $SOCKSRC
133 atf_check -s exit:0 ${inetserver} $SOCKDST
134
135 setup_dst_server
136 setup_src_server
137
138 export RUMP_SERVER=$SOCKSRC
139
140 # Add and delete a static entry
141 $DEBUG && rump.ndp -n -a
142 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
143 $DEBUG && rump.ndp -n -a
144 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
145 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
146 $DEBUG && rump.ndp -n -a
147 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
148
149 # Add multiple entries via a file (XXX not implemented)
150 #cat - > ./list <<-EOF
151 #fc00::11 b2:a0:20:00:00:11
152 #fc00::12 b2:a0:20:00:00:12
153 #fc00::13 b2:a0:20:00:00:13
154 #fc00::14 b2:a0:20:00:00:14
155 #fc00::15 b2:a0:20:00:00:15
156 #EOF
157 #$DEBUG && rump.ndp -n -a
158 #atf_check -s exit:0 -o ignore rump.ndp -f ./list
159 #$DEBUG && rump.ndp -n -a
160
161 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
162 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11
163 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12
164
165 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
166 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
167 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
168
169 # Test ndp -a
170 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
171 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a
172
173 # Flush all entries (-c)
174 $DEBUG && rump.ndp -n -a
175 atf_check -s exit:0 -o ignore rump.ndp -c
176 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
177 # Only the static caches are not deleted
178 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
179 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
180
181 # Test temp option (XXX it doesn't work; expire time isn't set)
182 $DEBUG && rump.ndp -n -a
183 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
184 rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
185 $DEBUG && rump.ndp -n -a
186 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
187
188 return 0
189 }
190
191 cache_overwriting_body()
192 {
193 atf_check -s exit:0 ${inetserver} $SOCKSRC
194 atf_check -s exit:0 ${inetserver} $SOCKDST
195
196 setup_dst_server
197 setup_src_server
198
199 export RUMP_SERVER=$SOCKSRC
200
201 # Cannot overwrite a permanent cache
202 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff
203 $DEBUG && rump.ndp -n -a
204
205 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
206 $DEBUG && rump.ndp -n -a
207 # Can overwrite a dynamic cache
208 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00
209 $DEBUG && rump.ndp -n -a
210 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST
211
212 # Test temp option (XXX it doesn't work; expire time isn't set)
213 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
214 #$DEBUG && rump.ndp -n -a
215 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
216 # Cannot overwrite a temp cache
217 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff
218 #$DEBUG && rump.ndp -n -a
219
220 return 0
221 }
222
223 cleanup()
224 {
225 env RUMP_SERVER=$SOCKSRC rump.halt
226 env RUMP_SERVER=$SOCKDST rump.halt
227 }
228
229 dump_src()
230 {
231 export RUMP_SERVER=$SOCKSRC
232 rump.netstat -nr
233 rump.ndp -n -a
234 rump.ifconfig
235 $HIJACKING dmesg
236 }
237
238 dump_dst()
239 {
240 export RUMP_SERVER=$SOCKDST
241 rump.netstat -nr
242 rump.ndp -n -a
243 rump.ifconfig
244 $HIJACKING dmesg
245 }
246
247 dump()
248 {
249 dump_src
250 dump_dst
251 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
252 $DEBUG && gdb -ex bt /usr/bin/rump_server rump_server.core
253 $DEBUG && gdb -ex bt /usr/sbin/rump.ndp rump.ndp.core
254 }
255
256 cache_expiration_cleanup()
257 {
258 $DEBUG && dump
259 cleanup
260 }
261
262 command_cleanup()
263 {
264 $DEBUG && dump
265 cleanup
266 }
267
268 cache_overwriting_cleanup()
269 {
270 $DEBUG && dump
271 cleanup
272 }
273
274 atf_init_test_cases()
275 {
276 atf_add_test_case cache_expiration
277 atf_add_test_case command
278 atf_add_test_case cache_overwriting
279 }
280