1 # $NetBSD: t_ndp.sh,v 1.13 2016/08/10 23:07:57 kre 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 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"
33 SOCKSRC=unix://commsock1
34 SOCKDST=unix://commsock2
41 atf_test_case ndp_cache_expiration cleanup
42 atf_test_case ndp_commands cleanup
43 atf_test_case ndp_cache_overwriting cleanup
44 atf_test_case ndp_neighborgcthresh cleanup
45 atf_test_case ndp_link_activation cleanup
47 ndp_cache_expiration_head()
49 atf_set "descr" "Tests for NDP cache expiration"
50 atf_set "require.progs" "rump_server"
55 atf_set "descr" "Tests for commands of ndp(8)"
56 atf_set "require.progs" "rump_server"
59 ndp_cache_overwriting_head()
61 atf_set "descr" "Tests for behavior of overwriting NDP caches"
62 atf_set "require.progs" "rump_server"
65 ndp_neighborgcthresh_head()
67 atf_set "descr" "Tests for GC of neighbor caches"
68 atf_set "require.progs" "rump_server"
71 ndp_link_activation_head()
73 atf_set "descr" "Tests for activating a new MAC address"
74 atf_set "require.progs" "rump_server"
81 export RUMP_SERVER=$SOCKDST
82 atf_check -s exit:0 rump.ifconfig shmif0 create
83 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
84 if [ "$assign_ip" != no ]; then
85 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6DST
87 atf_check -s exit:0 rump.ifconfig shmif0 up
88 atf_check -s exit:0 rump.ifconfig -w 10
90 $DEBUG && rump.ifconfig shmif0
91 $DEBUG && rump.ndp -n -a
96 $DEBUG && ulimit -c unlimited
97 export RUMP_SERVER=$SOCKSRC
100 atf_check -s exit:0 rump.ifconfig shmif0 create
101 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
102 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC
103 atf_check -s exit:0 rump.ifconfig shmif0 up
104 atf_check -s exit:0 rump.ifconfig -w 10
107 $DEBUG && rump.ifconfig shmif0
108 $DEBUG && rump.ndp -n -a
109 atf_check -s exit:0 -o ignore rump.ndp -n $IP6SRC
110 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
115 local timeout=$(env RUMP_SERVER=$SOCKSRC rump.ndp -n $IP6DST |grep $IP6DST|awk '{print $4;}')
120 ndp_cache_expiration_body()
122 atf_check -s exit:0 ${inetserver} $SOCKSRC
123 atf_check -s exit:0 ${inetserver} $SOCKDST
129 # Check if a cache is expired expectedly
131 export RUMP_SERVER=$SOCKSRC
132 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
134 $DEBUG && rump.ndp -n -a
135 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
137 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
139 timeout=$(get_timeout $IP6DST)
141 atf_check -s exit:0 sleep $(($timeout + 1))
143 $DEBUG && rump.ndp -n -a
144 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC
145 # Expired but remains until GC sweaps it (1 day)
146 atf_check -s exit:0 -o match:'(1d0h0m|23h59m)' rump.ndp -n $IP6DST
151 export RUMP_SERVER=$SOCKDST
152 atf_check -s exit:0 rump.ifconfig shmif0 down
153 export RUMP_SERVER=$SOCKSRC
158 atf_check -s exit:0 ${inetserver} $SOCKSRC
159 atf_check -s exit:0 ${inetserver} $SOCKDST
164 export RUMP_SERVER=$SOCKSRC
166 # We can delete the entry for the interface's IP address
167 atf_check -s exit:0 -o match:"$IP6SRC" rump.ndp -d $IP6SRC
169 # Add and delete a static entry
170 $DEBUG && rump.ndp -n -a
171 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10
172 $DEBUG && rump.ndp -n -a
173 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10
174 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10
175 $DEBUG && rump.ndp -n -a
176 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10
178 # Add multiple entries via a file (XXX not implemented)
179 #cat - > ./list <<-EOF
180 #fc00::11 b2:a0:20:00:00:11
181 #fc00::12 b2:a0:20:00:00:12
182 #fc00::13 b2:a0:20:00:00:13
183 #fc00::14 b2:a0:20:00:00:14
184 #fc00::15 b2:a0:20:00:00:15
186 #$DEBUG && rump.ndp -n -a
187 #atf_check -s exit:0 -o ignore rump.ndp -f ./list
188 #$DEBUG && rump.ndp -n -a
190 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
191 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11
192 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12
194 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST
195 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11
196 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12
199 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a
200 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a
202 # Ensure no packet upsets the src server
205 # Flush all entries (-c)
206 $DEBUG && rump.ndp -n -a
207 atf_check -s exit:0 -o ignore rump.ndp -c
208 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6SRC
209 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST
210 # Only the static caches are not deleted
211 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11
212 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12
214 $DEBUG && rump.ndp -n -a
215 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
216 rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
217 $DEBUG && rump.ndp -n -a
218 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
223 ndp_cache_overwriting_body()
225 atf_check -s exit:0 ${inetserver} $SOCKSRC
226 atf_check -s exit:0 ${inetserver} $SOCKDST
231 export RUMP_SERVER=$SOCKSRC
233 # Cannot overwrite a permanent cache
234 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff
235 $DEBUG && rump.ndp -n -a
237 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST
238 $DEBUG && rump.ndp -n -a
239 # Can overwrite a dynamic cache
240 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00
241 $DEBUG && rump.ndp -n -a
242 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST
244 # Test temp option (XXX it doesn't work; expire time isn't set)
245 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp
246 #$DEBUG && rump.ndp -n -a
247 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10
248 # Cannot overwrite a temp cache
249 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff
250 #$DEBUG && rump.ndp -n -a
258 echo $(rump.ndp -a -n |grep -v -e Neighbor -e permanent |wc -l)
261 ndp_neighborgcthresh_body()
264 atf_check -s exit:0 ${inetserver} $SOCKSRC
265 atf_check -s exit:0 ${inetserver} $SOCKDST
270 export RUMP_SERVER=$SOCKDST
271 for i in $(seq 0 9); do
272 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6DST}$i
275 export RUMP_SERVER=$SOCKSRC
277 # ping to 3 destinations
278 $DEBUG && rump.ndp -n -a
279 for i in $(seq 0 2); do
280 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
283 $DEBUG && rump.ndp -n -a
285 # 3 caches should be created
286 atf_check_equal $(get_n_caches) 3
288 # ping to additional 3 destinations
289 for i in $(seq 3 5); do
290 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
293 $DEBUG && rump.ndp -n -a
295 # 6 caches should be created in total
296 atf_check_equal $(get_n_caches) 6
298 # Limit the number of neighbor caches to 5
299 atf_check -s exit:0 -o ignore rump.sysctl -w \
300 net.inet6.ip6.neighborgcthresh=5
302 # ping to additional 4 destinations
303 for i in $(seq 6 9); do
304 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 \
308 # More than 5 caches should be created in total, but exceeded caches
310 if [ "$(get_n_caches)" -gt 5 ]; then
311 atf_fail "Neighbor caches are not GC-ed"
322 pkt="$mac > 33:33:00:00:00:01, ethertype IPv6 (0x86dd), length 86:"
323 pkt="$pkt $ip > ff02::1: ICMP6, neighbor advertisement"
327 extract_new_packets()
331 if [ ! -f $old ]; then
335 shmif_dumpbus -p - bus1 2>/dev/null| \
336 tcpdump -n -e -r - 2>/dev/null > ./new
337 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
342 ndp_link_activation_body()
346 atf_check -s exit:0 ${inetserver} $SOCKSRC
347 atf_check -s exit:0 ${inetserver} $SOCKDST
353 extract_new_packets > ./out
355 export RUMP_SERVER=$SOCKSRC
357 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
360 atf_check -s exit:0 sleep 1
361 extract_new_packets > ./out
364 linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
365 $DEBUG && echo $linklocal
367 pkt=$(make_pkt_str_na $linklocal b2:a1:00:00:00:01)
368 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
370 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 link \
371 b2:a1:00:00:00:02 active
373 atf_check -s exit:0 sleep 1
374 extract_new_packets > ./out
377 linklocal=$(rump.ifconfig shmif0 |awk '/fe80/ {print $2;}' |awk -F % '{print $1;}')
378 $DEBUG && echo $linklocal
380 pkt=$(make_pkt_str_na $linklocal b2:a1:00:00:00:02)
381 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
386 env RUMP_SERVER=$SOCKSRC rump.halt
387 env RUMP_SERVER=$SOCKDST rump.halt
392 export RUMP_SERVER=$SOCKSRC
401 export RUMP_SERVER=$SOCKDST
412 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
413 $DEBUG && gdb -ex bt /usr/bin/rump_server rump_server.core
414 $DEBUG && gdb -ex bt /usr/sbin/rump.ndp rump.ndp.core
417 ndp_cache_expiration_cleanup()
423 ndp_commands_cleanup()
429 ndp_cache_overwriting_cleanup()
435 ndp_neighborgcthresh_cleanup()
441 ndp_link_activation_cleanup()
447 atf_init_test_cases()
449 atf_add_test_case ndp_cache_expiration
450 atf_add_test_case ndp_commands
451 atf_add_test_case ndp_cache_overwriting
452 atf_add_test_case ndp_neighborgcthresh
453 atf_add_test_case ndp_link_activation