xref: /netbsd-src/tests/net/if_gif/t_gif_unnumbered.sh (revision d432a9d987fee0578a0100a58eb1837afa537338)
1#	$NetBSD: t_gif_unnumbered.sh,v 1.1 2022/11/25 08:43:16 knakahara Exp $
2#
3# Copyright (c) 2022 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
28SOCK_LOCAL=unix://gif_local
29SOCK_REMOTE=unix://gif_remote
30BUS_LOCAL_I=./bus_gif_local_inner
31BUS_REMOTE_I=./bus_gif_remote_inner
32BUS_GLOBAL=./bus_gif_global
33
34DEBUG=${DEBUG:-false}
35TIMEOUT=5
36
37setup_servers_ipv4()
38{
39
40	rump_server_start $SOCK_LOCAL gif
41	rump_server_start $SOCK_REMOTE gif
42	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_GLOBAL
43	rump_server_add_iface $SOCK_LOCAL shmif1 $BUS_LOCAL_I
44	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_GLOBAL
45	rump_server_add_iface $SOCK_REMOTE shmif1 $BUS_REMOTE_I
46}
47
48setup_servers_ipv6()
49{
50
51	rump_server_start $SOCK_LOCAL netinet6 gif
52	rump_server_start $SOCK_REMOTE netinet6 gif
53	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_GLOBAL
54	rump_server_add_iface $SOCK_LOCAL shmif1 $BUS_LOCAL_I
55	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_GLOBAL
56	rump_server_add_iface $SOCK_REMOTE shmif1 $BUS_REMOTE_I
57}
58
59setup_servers()
60{
61	local proto=$1
62
63	setup_servers_$proto
64}
65
66test_gif_unnumbered_ipv4()
67{
68	local ip_local_i=192.168.22.1
69	local ip_local_i_subnet=192.168.22.0/24
70	local ip_local_o=10.0.0.2
71	local ip_remote_i=192.168.33.1
72	local ip_remote_i_subnet=192.168.33.0/24
73	local ip_remote_o=10.0.0.3
74	local outfile=./out
75
76	setup_servers ipv4
77
78	export RUMP_SERVER=$SOCK_LOCAL
79	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0
80	atf_check -s exit:0 rump.ifconfig shmif0 $ip_local_o/24
81	atf_check -s exit:0 rump.ifconfig shmif1 $ip_local_i/24
82
83	export RUMP_SERVER=$SOCK_REMOTE
84	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0
85	atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote_o/24
86	atf_check -s exit:0 rump.ifconfig shmif1 $ip_remote_i/24
87
88	export RUMP_SERVER=$SOCK_LOCAL
89	atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w $TIMEOUT $ip_remote_o
90
91	# setup gif(4) as unnumbered for local
92	export RUMP_SERVER=$SOCK_LOCAL
93	atf_check -s exit:0 -o ignore rump.ifconfig gif0 create
94	atf_check -s exit:0 -o ignore \
95		  rump.ifconfig gif0 tunnel $ip_local_o $ip_remote_o
96	atf_check -s exit:0 -o ignore rump.ifconfig gif0 unnumbered
97	atf_check -s exit:0 -o ignore rump.ifconfig gif0 $ip_local_i/32
98	atf_check -s exit:0 -o ignore \
99		  rump.route add -inet $ip_remote_i_subnet -ifp gif0 $ip_local_i
100	$DEBUG && rump.ifconfig -v gif0
101	$DEBUG && rump.route -nL show
102
103	# setup gif(4) as unnumbered for remote
104	export RUMP_SERVER=$SOCK_REMOTE
105	atf_check -s exit:0 -o ignore rump.ifconfig gif0 create
106	atf_check -s exit:0 -o ignore \
107		  rump.ifconfig gif0 tunnel $ip_remote_o $ip_local_o
108	atf_check -s exit:0 -o ignore rump.ifconfig gif0 unnumbered
109	atf_check -s exit:0 -o ignore rump.ifconfig gif0 $ip_remote_i/32
110	atf_check -s exit:0 -o ignore \
111		  rump.route add -inet $ip_local_i_subnet -ifp gif0 $ip_remote_i
112	$DEBUG && rump.ifconfig -v gif0
113	$DEBUG && rump.route -nL show
114
115	# test unnumbered gif(4)
116	extract_new_packets $BUS_GLOBAL > $outfile
117	export RUMP_SERVER=$SOCK_LOCAL
118	atf_check -s exit:0 -o ignore \
119		  rump.ping -c 1 -n -w $TIMEOUT -I $ip_local_i $ip_remote_i
120	extract_new_packets $BUS_GLOBAL > $outfile
121	$DEBUG && cat $outfile
122	atf_check -s exit:0 \
123	    -o match:"$ip_local_o > $ip_remote_o: $ip_local_i > $ip_remote_i: ICMP echo request" \
124	    cat $outfile
125	atf_check -s exit:0 \
126	    -o match:"$ip_remote_o > $ip_local_o: $ip_remote_i > $ip_local_i: ICMP echo reply" \
127	    cat $outfile
128}
129
130test_gif_unnumbered_ipv6()
131{
132	local ip_local_i=192.168.22.1
133	local ip_local_i_subnet=192.168.22.0/24
134	local ip_local_o=fc00::2
135	local ip_remote_i=192.168.33.1
136	local ip_remote_i_subnet=192.168.33.0/24
137	local ip_remote_o=fc00::3
138	local outfile=./out
139
140	setup_servers ipv6
141
142	export RUMP_SERVER=$SOCK_LOCAL
143	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0
144	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.dad_count=0
145	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_local_o/64
146	atf_check -s exit:0 rump.ifconfig shmif1 $ip_local_i/24
147
148	export RUMP_SERVER=$SOCK_REMOTE
149	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0
150	atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.dad_count=0
151	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote_o/64
152	atf_check -s exit:0 rump.ifconfig shmif1 $ip_remote_i/24
153
154	export RUMP_SERVER=$SOCK_LOCAL
155	atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X $TIMEOUT $ip_remote_o
156
157	# setup gif(4) as unnumbered for local
158	export RUMP_SERVER=$SOCK_LOCAL
159	atf_check -s exit:0 -o ignore rump.ifconfig gif0 create
160	atf_check -s exit:0 -o ignore \
161		  rump.ifconfig gif0 tunnel $ip_local_o $ip_remote_o
162	atf_check -s exit:0 -o ignore rump.ifconfig gif0 unnumbered
163	atf_check -s exit:0 -o ignore rump.ifconfig gif0 $ip_local_i/32
164	atf_check -s exit:0 -o ignore \
165		  rump.route add -inet $ip_remote_i_subnet -ifp gif0 $ip_local_i
166	$DEBUG && rump.ifconfig -v gif0
167	$DEBUG && rump.route -nL show
168
169	# setup gif(4) as unnumbered for remote
170	export RUMP_SERVER=$SOCK_REMOTE
171	atf_check -s exit:0 -o ignore rump.ifconfig gif0 create
172	atf_check -s exit:0 -o ignore \
173		  rump.ifconfig gif0 tunnel $ip_remote_o $ip_local_o
174	atf_check -s exit:0 -o ignore rump.ifconfig gif0 unnumbered
175	atf_check -s exit:0 -o ignore rump.ifconfig gif0 $ip_remote_i/32
176	atf_check -s exit:0 -o ignore \
177		  rump.route add -inet $ip_local_i_subnet -ifp gif0 $ip_remote_i
178	$DEBUG && rump.ifconfig -v gif0
179	$DEBUG && rump.route -nL show
180
181	# test unnumbered gif(4)
182	extract_new_packets $BUS_GLOBAL > $outfile
183	export RUMP_SERVER=$SOCK_LOCAL
184	atf_check -s exit:0 -o ignore \
185		  rump.ping -c 1 -n -w $TIMEOUT -I $ip_local_i $ip_remote_i
186	extract_new_packets $BUS_GLOBAL > $outfile
187	$DEBUG && cat $outfile
188	atf_check -s exit:0 \
189	    -o match:"$ip_local_o > $ip_remote_o: $ip_local_i > $ip_remote_i: ICMP echo request" \
190	    cat $outfile
191	atf_check -s exit:0 \
192	    -o match:"$ip_remote_o > $ip_local_o: $ip_remote_i > $ip_local_i: ICMP echo reply" \
193	    cat $outfile
194}
195
196add_test_gif_unnumbered()
197{
198	outer=$1
199
200	name="gif_unnumbered_over${outer}"
201	desc="Does unnumbered gif over ${outer}"
202
203	atf_test_case ${name} cleanup
204	eval "
205	     ${name}_head() {
206		atf_set descr \"${desc}\"
207		atf_set require.progs rump_server
208	    }
209	    ${name}_body() {
210		test_gif_unnumbered_${outer}
211		rump_server_destroy_ifaces
212	    }
213	    ${name}_cleanup() {
214			\$DEBUG && dump
215			cleanup
216	    }"
217	atf_add_test_case ${name}
218}
219
220atf_init_test_cases()
221{
222
223	add_test_gif_unnumbered ipv4
224    	add_test_gif_unnumbered ipv6
225}
226