1 # $NetBSD: t_ndp.sh,v 1.17 2016/11/25 08:51:17 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
28 SOCKSRC=unix://commsock1
29 SOCKDST=unix://commsock2
36 atf_test_case ndp_cache_expiration cleanup
37 atf_test_case ndp_commands cleanup
38 atf_test_case ndp_cache_overwriting cleanup
39 atf_test_case ndp_neighborgcthresh cleanup
40 atf_test_case ndp_link_activation cleanup
42 ndp_cache_expiration_head()
44 atf_set "descr" "Tests for NDP cache expiration"
45 atf_set "require.progs" "rump_server"
50 atf_set "descr" "Tests for commands of ndp(8)"
51 atf_set "require.progs" "rump_server"
54 ndp_cache_overwriting_head()
56 atf_set "descr" "Tests for behavior of overwriting NDP caches"
57 atf_set "require.progs" "rump_server"
60 ndp_neighborgcthresh_head()
62 atf_set "descr" "Tests for GC of neighbor caches"
63 atf_set "require.progs" "rump_server"
66 ndp_link_activation_head()
68 atf_set "descr" "Tests for activating a new MAC address"
69 atf_set "require.progs" "rump_server"
76 rump_server_add_iface $SOCKDST shmif0 bus1
77 export RUMP_SERVER=$SOCKDST
78 if [ "$assign_ip" != no ]; then
79 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6DST
81 atf_check -s exit:0 rump.ifconfig shmif0 up
82 atf_check -s exit:0 rump.ifconfig -w 10
84 $DEBUG && rump.ifconfig shmif0
85 $DEBUG && rump.ndp -n -a
90 $DEBUG && ulimit -c unlimited
91 export RUMP_SERVER=$SOCKSRC
94 rump_server_add_iface $SOCKSRC shmif0 bus1
95 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC
96 atf_check -s exit:0 rump.ifconfig shmif0 up
97 atf_check -s exit:0 rump.ifconfig -w 10
100 $DEBUG && rump.ifconfig shmif0
101 $DEBUG && rump.ndp -n -a
102 atf_check -s exit:0 -o ignore rump.ndp -n $IP6SRC
103 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
108 local timeout=$(env RUMP_SERVER=$SOCKSRC rump.ndp -n $IP6DST |grep $IP6DST|awk '{print $4;}')
113 ndp_cache_expiration_body()
116 rump_server_start $SOCKSRC netinet6
117 rump_server_start $SOCKDST netinet6
123 # Check if a cache is expired expectedly
125 export RUMP_SERVER=$SOCKSRC
126 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
128 $DEBUG && rump.ndp -n -a
129 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
131 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
133 timeout=$(get_timeout $IP6DST)
135 atf_check -s exit:0 sleep $(($timeout + 1))
137 $DEBUG && rump.ndp -n -a
138 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
139 # Expired but remains until GC sweaps it (1 day)
140 atf_check -s exit:0 -o match:'(1d0h0m|23h59m)' rump.ndp -n $IP6DST
142 rump_server_destroy_ifaces
147 export RUMP_SERVER=$SOCKDST
148 atf_check -s exit:0 rump.ifconfig shmif0 down
149 export RUMP_SERVER=$SOCKSRC
155 rump_server_start $SOCKSRC netinet6
156 rump_server_start $SOCKDST netinet6
161 export RUMP_SERVER=$SOCKSRC
163 # We can delete the entry for the interface's IP address
164 atf_check -s exit:0 -o match:"$IP6SRC" rump.ndp -d $IP6SRC
166 # Add and delete a static entry
167 $DEBUG && rump.ndp -n -a
168 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
169 $DEBUG && rump.ndp -n -a
170 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
171 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
172 $DEBUG && rump.ndp -n -a
173 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
175 # Add multiple entries via a file (XXX not implemented)
176 #cat - > ./list <<-EOF
177 #fc00::11 b2:a0:20:00:00:11
178 #fc00::12 b2:a0:20:00:00:12
179 #fc00::13 b2:a0:20:00:00:13
180 #fc00::14 b2:a0:20:00:00:14
181 #fc00::15 b2:a0:20:00:00:15
183 #$DEBUG && rump.ndp -n -a
184 #atf_check -s exit:0 -o ignore rump.ndp -f ./list
185 #$DEBUG && rump.ndp -n -a
187 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
188 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11
189 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12
191 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
192 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
193 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
196 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
197 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a
199 # Ensure no packet upsets the src server
202 # Flush all entries (-c)
203 $DEBUG && rump.ndp -n -a
204 atf_check -s exit:0 -o ignore rump.ndp -c
205 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6SRC
206 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
207 # Only the static caches are not deleted
208 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
209 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
211 $DEBUG && rump.ndp -n -a
212 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
213 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
217 rump_server_destroy_ifaces
220 ndp_cache_overwriting_body()
223 rump_server_start $SOCKSRC netinet6
224 rump_server_start $SOCKDST netinet6
229 export RUMP_SERVER=$SOCKSRC
231 # Cannot overwrite a permanent cache
232 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff
233 $DEBUG && rump.ndp -n -a
235 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
236 $DEBUG && rump.ndp -n -a
237 # Can overwrite a dynamic cache
238 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00
239 $DEBUG && rump.ndp -n -a
240 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST
242 # Test temp option (XXX it doesn't work; expire time isn't set)
243 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
244 #$DEBUG && rump.ndp -n -a
245 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
246 # Cannot overwrite a temp cache
247 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff
248 #$DEBUG && rump.ndp -n -a
250 rump_server_destroy_ifaces
256 echo $(rump.ndp -a -n |grep -v -e Neighbor -e permanent |wc -l)
259 ndp_neighborgcthresh_body()
262 rump_server_start $SOCKSRC netinet6
263 rump_server_start $SOCKDST netinet6
268 export RUMP_SERVER=$SOCKDST
269 for i in $(seq 0 9); do
270 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6DST}$i
273 export RUMP_SERVER=$SOCKSRC
275 # ping to 3 destinations
276 $DEBUG && rump.ndp -n -a
277 for i in $(seq 0 2); do
278 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
281 $DEBUG && rump.ndp -n -a
283 # 3 caches should be created
284 atf_check_equal $(get_n_caches) 3
286 # ping to additional 3 destinations
287 for i in $(seq 3 5); do
288 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
291 $DEBUG && rump.ndp -n -a
293 # 6 caches should be created in total
294 atf_check_equal $(get_n_caches) 6
296 # Limit the number of neighbor caches to 5
297 atf_check -s exit:0 -o ignore rump.sysctl -w \
298 net.inet6.ip6.neighborgcthresh=5
300 # ping to additional 4 destinations
301 for i in $(seq 6 9); do
302 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
306 # More than 5 caches should be created in total, but exceeded caches
308 if [ "$(get_n_caches)" -gt 5 ]; then
309 atf_fail "Neighbor caches are not GC-ed"
312 rump_server_destroy_ifaces
320 pkt="$mac > 33:33:00:00:00:01, ethertype IPv6 (0x86dd), length 86:"
321 pkt="$pkt $ip > ff02::1: ICMP6, neighbor advertisement"
325 ndp_link_activation_body()
329 rump_server_start $SOCKSRC netinet6
330 rump_server_start $SOCKDST netinet6
336 extract_new_packets bus1 > ./out
338 export RUMP_SERVER=$SOCKSRC
340 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
343 atf_check -s exit:0 sleep 1
344 extract_new_packets bus1 > ./out
347 linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
348 $DEBUG && echo $linklocal
350 pkt=$(make_pkt_str_na $linklocal b2:a1:00:00:00:01)
351 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
353 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
354 b2:a1:00:00:00:02 active
356 atf_check -s exit:0 sleep 1
357 extract_new_packets bus1 > ./out
360 linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
361 $DEBUG && echo $linklocal
363 pkt=$(make_pkt_str_na $linklocal b2:a1:00:00:00:02)
364 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
366 rump_server_destroy_ifaces
369 ndp_cache_expiration_cleanup()
375 ndp_commands_cleanup()
381 ndp_cache_overwriting_cleanup()
387 ndp_neighborgcthresh_cleanup()
393 ndp_link_activation_cleanup()
399 atf_init_test_cases()
401 atf_add_test_case ndp_cache_expiration
402 atf_add_test_case ndp_commands
403 atf_add_test_case ndp_cache_overwriting
404 atf_add_test_case ndp_neighborgcthresh
405 atf_add_test_case ndp_link_activation