t_ndp.sh revision 1.1 1 # $NetBSD: t_ndp.sh,v 1.1 2015/08/03 09:54:20 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()
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 $HIJACKING ping6 -n -X $TIMEOUT -c 1 $IP6DST
114 export LD_PRELOAD=/usr/lib/librumphijack.so
115 atf_check -s exit:0 -o ignore ping6 -n -X $TIMEOUT -c 1 $IP6DST
116 unset LD_PRELOAD
117
118 $DEBUG && rump.ndp -n -a
119 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
120 # Should be cached
121 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
122
123 timeout=$(get_timeout $IP6DST)
124
125 atf_check -s exit:0 sleep $(($timeout + 1))
126
127 $DEBUG && rump.ndp -n -a
128 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
129 # Expired but remains until GC sweaps it (1 day)
130 atf_check -s exit:0 -o match:'23h59m' rump.ndp -n $IP6DST
131 }
132
133 command_body()
134 {
135 atf_check -s exit:0 ${inetserver} $SOCKSRC
136 atf_check -s exit:0 ${inetserver} $SOCKDST
137
138 setup_dst_server
139 setup_src_server
140
141 export RUMP_SERVER=$SOCKSRC
142
143 # Add and delete a static entry
144 $DEBUG && rump.ndp -n -a
145 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
146 $DEBUG && rump.ndp -n -a
147 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
148 atf_check -s exit:0 -o ignore rump.ndp -d fc00::10
149 $DEBUG && rump.ndp -n -a
150 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
151
152 # Add multiple entries via a file (XXX not implemented)
153 #cat - > ./list <<-EOF
154 #fc00::11 b2:a0:20:00:00:11
155 #fc00::12 b2:a0:20:00:00:12
156 #fc00::13 b2:a0:20:00:00:13
157 #fc00::14 b2:a0:20:00:00:14
158 #fc00::15 b2:a0:20:00:00:15
159 #EOF
160 #$DEBUG && rump.ndp -n -a
161 #atf_check -s exit:0 -o ignore rump.ndp -f ./list
162 #$DEBUG && rump.ndp -n -a
163
164 export LD_PRELOAD=/usr/lib/librumphijack.so
165 atf_check -s exit:0 -o ignore ping6 -n -X $TIMEOUT -c 1 $IP6DST
166 unset LD_PRELOAD
167 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11
168 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12
169
170 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
171 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
172 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
173
174 # Test ndp -a
175 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
176 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a
177
178 # Flush all entries (-c)
179 $DEBUG && rump.ndp -n -a
180 atf_check -s exit:0 -o ignore rump.ndp -c
181 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
182 # Only the static caches are not deleted
183 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
184 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
185
186 # Test temp option (XXX it doesn't work; expire time isn't set)
187 $DEBUG && rump.ndp -n -a
188 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
189 rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
190 $DEBUG && rump.ndp -n -a
191 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
192
193 return 0
194 }
195
196 cache_overwriting_body()
197 {
198 atf_check -s exit:0 ${inetserver} $SOCKSRC
199 atf_check -s exit:0 ${inetserver} $SOCKDST
200
201 setup_dst_server
202 setup_src_server
203
204 export RUMP_SERVER=$SOCKSRC
205
206 # Cannot overwrite a permanent cache
207 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff
208 $DEBUG && rump.ndp -n -a
209
210 export LD_PRELOAD=/usr/lib/librumphijack.so
211 atf_check -s exit:0 -o ignore ping6 -n -X $TIMEOUT -c 1 $IP6DST
212 unset LD_PRELOAD
213 $DEBUG && rump.ndp -n -a
214 # Can overwrite a dynamic cache
215 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00
216 $DEBUG && rump.ndp -n -a
217 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST
218
219 # Test temp option (XXX it doesn't work; expire time isn't set)
220 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
221 #$DEBUG && rump.ndp -n -a
222 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
223 # Cannot overwrite a temp cache
224 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff
225 #$DEBUG && rump.ndp -n -a
226
227 return 0
228 }
229
230 cleanup()
231 {
232 env RUMP_SERVER=$SOCKSRC rump.halt
233 env RUMP_SERVER=$SOCKDST rump.halt
234 }
235
236 dump_src()
237 {
238 export RUMP_SERVER=$SOCKSRC
239 rump.netstat -nr
240 rump.ndp -n -a
241 rump.ifconfig
242 $HIJACKING dmesg
243 }
244
245 dump_dst()
246 {
247 export RUMP_SERVER=$SOCKDST
248 rump.netstat -nr
249 rump.ndp -n -a
250 rump.ifconfig
251 $HIJACKING dmesg
252 }
253
254 dump()
255 {
256 dump_src
257 dump_dst
258 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
259 $DEBUG && gdb -ex bt /usr/bin/rump_server rump_server.core
260 $DEBUG && gdb -ex bt /usr/sbin/rump.ndp rump.ndp.core
261 }
262
263 cache_expiration()
264 {
265 $DEBUG && dump
266 cleanup
267 }
268
269 command_cleanup()
270 {
271 $DEBUG && dump
272 cleanup
273 }
274
275 cache_overwriting_cleanup()
276 {
277 $DEBUG && dump
278 cleanup
279 }
280
281 atf_init_test_cases()
282 {
283 atf_add_test_case cache_expiration
284 atf_add_test_case command
285 atf_add_test_case cache_overwriting
286 }
287