]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/netbsd-tests/net/net/t_ping6_opts.sh
Merge llvm trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / netbsd-tests / net / net / t_ping6_opts.sh
1 #       $NetBSD: t_ping6_opts.sh,v 1.8 2016/11/25 08:51:17 ozaki-r Exp $
2 #
3 # Copyright (c) 2016 Internet Initiative Japan 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 SOCKSRC=unix://commsock1
29 SOCKFWD=unix://commsock2
30 SOCKDST=unix://commsock3
31 IP6SRC=fc00:0:0:1::2
32 IP6SRCGW=fc00:0:0:1::1
33 IP6DSTGW=fc00:0:0:2::1
34 IP6DST=fc00:0:0:2::2
35 BUS_SRCGW=bus1
36 BUS_DSTGW=bus2
37
38 IP6SRC2=fc00:0:0:1::3
39 IP6SRCGW2=fc00:0:0:1::254
40
41 DEBUG=${DEBUG:-false}
42 TIMEOUT=1
43
44 #
45 # Utility functions
46 #
47 setup_endpoint()
48 {
49         local sock=${1}
50         local addr=${2}
51         local bus=${3}
52         local gw=${4}
53
54         rump_server_add_iface $sock shmif0 $bus
55
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
61
62         if $DEBUG; then
63                 rump.ifconfig shmif0
64                 rump.netstat -nr
65         fi
66 }
67
68 setup_forwarder()
69 {
70
71         rump_server_add_iface $SOCKFWD shmif0 $BUS_SRCGW
72         rump_server_add_iface $SOCKFWD shmif1 $BUS_DSTGW
73
74         export RUMP_SERVER=$SOCKFWD
75
76         atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
77         atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
78
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
82
83         if $DEBUG; then
84                 rump.netstat -nr
85                 rump.sysctl net.inet6.ip6.forwarding
86         fi
87 }
88
89 setup_forwarding6()
90 {
91         export RUMP_SERVER=$SOCKFWD
92         atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
93 }
94
95 setup6()
96 {
97
98         rump_server_start $SOCKSRC netinet6
99         rump_server_start $SOCKFWD netinet6
100         rump_server_start $SOCKDST netinet6
101
102         setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW $IP6SRCGW
103         setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW $IP6DSTGW
104         setup_forwarder
105 }
106
107 check_echo_request_pkt()
108 {
109         local pkt="$1 > $2: .+ echo request"
110
111         extract_new_packets $BUS_SRCGW > ./out
112         $DEBUG && echo $pkt
113         $DEBUG && cat ./out
114         atf_check -s exit:0 -o match:"$pkt" cat ./out
115 }
116
117 check_echo_request_pkt_with_macaddr()
118 {
119         local pkt="$1 > $2, .+ $3 > $4: .+ echo request"
120
121         extract_new_packets $BUS_SRCGW > ./out
122         $DEBUG && echo $pkt
123         $DEBUG && cat ./out
124         atf_check -s exit:0 -o match:"$pkt" cat ./out
125 }
126
127 check_echo_request_pkt_with_macaddr_and_rthdr0()
128 {
129         local pkt=
130
131         pkt="$1 > $2, .+ $3 > $4:"
132         pkt="$pkt srcrt \\(len=2, type=0, segleft=1, \\[0\\]$5\\)"
133         pkt="$pkt .+ echo request"
134
135         extract_new_packets $BUS_SRCGW > ./out
136         $DEBUG && echo $pkt
137         $DEBUG && cat ./out
138         atf_check -s exit:0 -o match:"$pkt" cat ./out
139 }
140
141 #
142 # Tests
143 #
144 atf_test_case ping6_opts_sourceaddr cleanup
145 ping6_opts_sourceaddr_head()
146 {
147
148         atf_set "descr" "tests of ping6 -S option"
149         atf_set "require.progs" "rump_server"
150 }
151
152 ping6_opts_sourceaddr_body()
153 {
154
155         setup6
156         setup_forwarding6
157
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
161
162         atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC2
163         atf_check -s exit:0 rump.ifconfig -w 10
164
165         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
166         check_echo_request_pkt $IP6SRC $IP6DST
167
168         # ping6 -S <sourceaddr>
169         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
170             -S $IP6SRC $IP6DST
171         check_echo_request_pkt $IP6SRC $IP6DST
172
173         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
174             -S $IP6SRC2 $IP6DST
175         check_echo_request_pkt $IP6SRC2 $IP6DST
176
177         rump_server_destroy_ifaces
178 }
179
180 ping6_opts_sourceaddr_cleanup()
181 {
182
183         $DEBUG && dump
184         cleanup
185 }
186
187 atf_test_case ping6_opts_interface cleanup
188 ping6_opts_interface_head()
189 {
190
191         atf_set "descr" "tests of ping6 -I option"
192         atf_set "require.progs" "rump_server"
193 }
194
195 ping6_opts_interface_body()
196 {
197         local shmif0_lladdr=
198         local shmif1_lladdr=
199         local gw_lladdr=
200
201         setup6
202         setup_forwarding6
203
204         shmif0_lladdr=$(get_linklocal_addr ${SOCKSRC} shmif0)
205         gw_lladdr=$(get_linklocal_addr ${SOCKFWD} shmif0)
206
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
210
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)
215
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
218
219         # ping6 -I <interface>
220         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
221             -I shmif0 $gw_lladdr
222         check_echo_request_pkt $shmif0_lladdr $gw_lladdr
223
224         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
225             -I shmif1 $gw_lladdr
226         check_echo_request_pkt $shmif1_lladdr $gw_lladdr
227
228         rump_server_destroy_ifaces
229 }
230
231 ping6_opts_interface_cleanup()
232 {
233
234         $DEBUG && dump
235         cleanup
236 }
237
238 atf_test_case ping6_opts_gateway cleanup
239 ping6_opts_gateway_head()
240 {
241
242         atf_set "descr" "tests of ping6 -g option"
243         atf_set "require.progs" "rump_server"
244 }
245
246 ping6_opts_gateway_body()
247 {
248         local my_macaddr=
249         local gw_shmif0_macaddr=
250         local gw_shmif2_macaddr=
251
252         setup6
253         setup_forwarding6
254
255         my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
256         gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
257
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
262
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)
268
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
273
274         # ping6 -g <gateway>
275         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
276             -g $IP6SRCGW $IP6DST
277         check_echo_request_pkt_with_macaddr \
278             $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
279
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
284
285         rump_server_destroy_ifaces
286 }
287
288 ping6_opts_gateway_cleanup()
289 {
290
291         $DEBUG && dump
292         cleanup
293 }
294
295 atf_test_case ping6_opts_hops cleanup
296 ping6_opts_hops_head()
297 {
298
299         atf_set "descr" "tests of ping6 hops (Type 0 Routing Header)"
300         atf_set "require.progs" "rump_server"
301 }
302
303 ping6_opts_hops_body()
304 {
305         local my_macaddr=
306         local gw_shmif0_macaddr=
307         local gw_shmif2_macaddr=
308
309         setup6
310         setup_forwarding6
311
312         my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
313         gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
314
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
319
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)
325
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
330
331         # ping6 hops
332
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 \
337             $IP6SRCGW $IP6DST
338         check_echo_request_pkt_with_macaddr_and_rthdr0 \
339             $my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
340
341         atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
342             $IP6SRCGW2 $IP6DST
343         check_echo_request_pkt_with_macaddr_and_rthdr0 \
344             $my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
345
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
351
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
356
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
362
363         rump_server_destroy_ifaces
364 }
365
366 ping6_opts_hops_cleanup()
367 {
368
369         $DEBUG && dump
370         cleanup
371 }
372
373 atf_init_test_cases()
374 {
375
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
380 }