1 # $NetBSD: t_ping6_opts.sh,v 1.8 2016/11/25 08:51:17 ozaki-r Exp $
3 # Copyright (c) 2016 Internet Initiative Japan 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 SOCKFWD=unix://commsock2
30 SOCKDST=unix://commsock3
32 IP6SRCGW=fc00:0:0:1::1
33 IP6DSTGW=fc00:0:0:2::1
39 IP6SRCGW2=fc00:0:0:1::254
54 rump_server_add_iface $sock shmif0 $bus
56 export RUMP_SERVER=${sock}
57 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
58 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
59 atf_check -s exit:0 rump.ifconfig shmif0 up
60 atf_check -s exit:0 rump.ifconfig -w 10
71 rump_server_add_iface $SOCKFWD shmif0 $BUS_SRCGW
72 rump_server_add_iface $SOCKFWD shmif1 $BUS_DSTGW
74 export RUMP_SERVER=$SOCKFWD
76 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
77 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
79 atf_check -s exit:0 rump.ifconfig shmif0 up
80 atf_check -s exit:0 rump.ifconfig shmif1 up
81 atf_check -s exit:0 rump.ifconfig -w 10
85 rump.sysctl net.inet6.ip6.forwarding
91 export RUMP_SERVER=$SOCKFWD
92 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
98 rump_server_start $SOCKSRC netinet6
99 rump_server_start $SOCKFWD netinet6
100 rump_server_start $SOCKDST netinet6
102 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW $IP6SRCGW
103 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW $IP6DSTGW
107 check_echo_request_pkt()
109 local pkt="$1 > $2: .+ echo request"
111 extract_new_packets $BUS_SRCGW > ./out
114 atf_check -s exit:0 -o match:"$pkt" cat ./out
117 check_echo_request_pkt_with_macaddr()
119 local pkt="$1 > $2, .+ $3 > $4: .+ echo request"
121 extract_new_packets $BUS_SRCGW > ./out
124 atf_check -s exit:0 -o match:"$pkt" cat ./out
127 check_echo_request_pkt_with_macaddr_and_rthdr0()
131 pkt="$1 > $2, .+ $3 > $4:"
132 pkt="$pkt srcrt \\(len=2, type=0, segleft=1, \\[0\\]$5\\)"
133 pkt="$pkt .+ echo request"
135 extract_new_packets $BUS_SRCGW > ./out
138 atf_check -s exit:0 -o match:"$pkt" cat ./out
144 atf_test_case ping6_opts_sourceaddr cleanup
145 ping6_opts_sourceaddr_head()
148 atf_set "descr" "tests of ping6 -S option"
149 atf_set "require.progs" "rump_server"
152 ping6_opts_sourceaddr_body()
158 export RUMP_SERVER=$SOCKSRC
159 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
160 check_echo_request_pkt $IP6SRC $IP6DST
162 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC2
163 atf_check -s exit:0 rump.ifconfig -w 10
165 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
166 check_echo_request_pkt $IP6SRC $IP6DST
168 # ping6 -S <sourceaddr>
169 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
171 check_echo_request_pkt $IP6SRC $IP6DST
173 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
175 check_echo_request_pkt $IP6SRC2 $IP6DST
177 rump_server_destroy_ifaces
180 ping6_opts_sourceaddr_cleanup()
187 atf_test_case ping6_opts_interface cleanup
188 ping6_opts_interface_head()
191 atf_set "descr" "tests of ping6 -I option"
192 atf_set "require.progs" "rump_server"
195 ping6_opts_interface_body()
204 shmif0_lladdr=$(get_linklocal_addr ${SOCKSRC} shmif0)
205 gw_lladdr=$(get_linklocal_addr ${SOCKFWD} shmif0)
207 export RUMP_SERVER=$SOCKSRC
208 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $gw_lladdr
209 check_echo_request_pkt $shmif0_lladdr $gw_lladdr
211 rump_server_add_iface $SOCKSRC shmif1 $BUS_SRCGW
212 atf_check -s exit:0 rump.ifconfig shmif1 up
213 atf_check -s exit:0 rump.ifconfig -w 10
214 shmif1_lladdr=$(get_linklocal_addr ${SOCKSRC} shmif1)
216 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $gw_lladdr
217 check_echo_request_pkt $shmif0_lladdr $gw_lladdr
219 # ping6 -I <interface>
220 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
222 check_echo_request_pkt $shmif0_lladdr $gw_lladdr
224 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
226 check_echo_request_pkt $shmif1_lladdr $gw_lladdr
228 rump_server_destroy_ifaces
231 ping6_opts_interface_cleanup()
238 atf_test_case ping6_opts_gateway cleanup
239 ping6_opts_gateway_head()
242 atf_set "descr" "tests of ping6 -g option"
243 atf_set "require.progs" "rump_server"
246 ping6_opts_gateway_body()
249 local gw_shmif0_macaddr=
250 local gw_shmif2_macaddr=
255 my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
256 gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
258 export RUMP_SERVER=$SOCKSRC
259 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
260 check_echo_request_pkt_with_macaddr \
261 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
263 rump_server_add_iface $SOCKFWD shmif2 $BUS_SRCGW
264 export RUMP_SERVER=$SOCKFWD
265 atf_check -s exit:0 rump.ifconfig shmif2 inet6 $IP6SRCGW2
266 atf_check -s exit:0 rump.ifconfig -w 10
267 gw_shmif2_macaddr=$(get_macaddr ${SOCKFWD} shmif2)
269 export RUMP_SERVER=$SOCKSRC
270 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
271 check_echo_request_pkt_with_macaddr \
272 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
275 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
277 check_echo_request_pkt_with_macaddr \
278 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
280 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
281 -g $IP6SRCGW2 $IP6DST
282 check_echo_request_pkt_with_macaddr \
283 $my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6DST
285 rump_server_destroy_ifaces
288 ping6_opts_gateway_cleanup()
295 atf_test_case ping6_opts_hops cleanup
296 ping6_opts_hops_head()
299 atf_set "descr" "tests of ping6 hops (Type 0 Routing Header)"
300 atf_set "require.progs" "rump_server"
303 ping6_opts_hops_body()
306 local gw_shmif0_macaddr=
307 local gw_shmif2_macaddr=
312 my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
313 gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
315 export RUMP_SERVER=$SOCKSRC
316 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
317 check_echo_request_pkt_with_macaddr \
318 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
320 rump_server_add_iface $SOCKFWD shmif2 $BUS_SRCGW
321 export RUMP_SERVER=$SOCKFWD
322 atf_check -s exit:0 rump.ifconfig shmif2 inet6 $IP6SRCGW2
323 atf_check -s exit:0 rump.ifconfig -w 10
324 gw_shmif2_macaddr=$(get_macaddr ${SOCKFWD} shmif2)
326 export RUMP_SERVER=$SOCKSRC
327 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
328 check_echo_request_pkt_with_macaddr \
329 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
333 # ping6 fails expectedly because the kernel doesn't support
334 # to receive packets with type 0 routing headers, but we can
335 # check whether a sent packet is correct.
336 atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
338 check_echo_request_pkt_with_macaddr_and_rthdr0 \
339 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
341 atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
343 check_echo_request_pkt_with_macaddr_and_rthdr0 \
344 $my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
346 # ping6 -g <gateway> hops
347 atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
348 -g $IP6SRCGW $IP6SRCGW $IP6DST
349 check_echo_request_pkt_with_macaddr_and_rthdr0 \
350 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
352 atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
353 -g $IP6SRCGW2 $IP6SRCGW2 $IP6DST
354 check_echo_request_pkt_with_macaddr_and_rthdr0 \
355 $my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
357 # ping6 -g <gateway> hops, but different nexthops (is it valid?)
358 atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
359 -g $IP6SRCGW $IP6SRCGW2 $IP6DST
360 check_echo_request_pkt_with_macaddr_and_rthdr0 \
361 $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
363 rump_server_destroy_ifaces
366 ping6_opts_hops_cleanup()
373 atf_init_test_cases()
376 atf_add_test_case ping6_opts_sourceaddr
377 atf_add_test_case ping6_opts_interface
378 atf_add_test_case ping6_opts_gateway
379 atf_add_test_case ping6_opts_hops