xref: /freebsd/tests/sys/net/if_gif.sh (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright (c) 2021 Rubicon Communications, LLC (Netgate)
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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26
27. $(atf_get_srcdir)/../common/vnet.subr
28
29atf_test_case "4in4" "cleanup"
304in4_head()
31{
32	atf_set descr 'IPv4 in IPv4 tunnel'
33	atf_set require.user root
34}
35
364in4_body()
37{
38	vnet_init
39	if ! kldstat -q -m if_gif; then
40		atf_skip "This test requires if_gif"
41	fi
42
43	epair=$(vnet_mkepair)
44
45	vnet_mkjail one ${epair}a
46	jexec one ifconfig ${epair}a 192.0.2.1/24 up
47	gone=$(jexec one ifconfig gif create)
48	jexec one ifconfig $gone tunnel 192.0.2.1 192.0.2.2
49	jexec one ifconfig $gone inet 198.51.100.1/24 198.51.100.2 up
50
51	vnet_mkjail two ${epair}b
52	jexec two ifconfig ${epair}b 192.0.2.2/24 up
53	gtwo=$(jexec two ifconfig gif create)
54	jexec two ifconfig $gtwo tunnel 192.0.2.2 192.0.2.1
55	jexec two ifconfig $gtwo inet 198.51.100.2/24 198.51.100.1 up
56
57	# Sanity check
58	atf_check -s exit:0 -o ignore \
59	    jexec one ping -c 1 192.0.2.2
60
61	# Tunnel test
62	atf_check -s exit:0 -o ignore \
63	    jexec one ping -c 1 198.51.100.2
64	atf_check -s exit:0 -o ignore \
65	    jexec two ping -c 1 198.51.100.1
66}
67
684in4_cleanup()
69{
70	vnet_cleanup
71}
72
73atf_test_case "6in4" "cleanup"
746in4_head()
75{
76	atf_set descr 'IPv6 in IPv4 tunnel'
77	atf_set require.user root
78}
79
806in4_body()
81{
82	vnet_init
83	if ! kldstat -q -m if_gif; then
84		atf_skip "This test requires if_gif"
85	fi
86
87	epair=$(vnet_mkepair)
88
89	vnet_mkjail one ${epair}a
90	jexec one ifconfig ${epair}a 192.0.2.1/24 up
91	gone=$(jexec one ifconfig gif create)
92	jexec one ifconfig $gone tunnel 192.0.2.1 192.0.2.2
93	jexec one ifconfig $gone inet6 no_dad 2001:db8:1::1/64 up
94
95	vnet_mkjail two ${epair}b
96	jexec two ifconfig ${epair}b 192.0.2.2/24 up
97	gtwo=$(jexec two ifconfig gif create)
98	jexec two ifconfig $gtwo tunnel 192.0.2.2 192.0.2.1
99	jexec two ifconfig $gtwo inet6 no_dad 2001:db8:1::2/64 up
100
101	# Sanity check
102	atf_check -s exit:0 -o ignore \
103	    jexec one ping -c 1 192.0.2.2
104
105	# Tunnel test
106	atf_check -s exit:0 -o ignore \
107	    jexec one ping -6 -c 1 2001:db8:1::2
108	atf_check -s exit:0 -o ignore \
109	    jexec two ping -6 -c 1 2001:db8:1::1
110}
111
1126in4_cleanup()
113{
114	vnet_cleanup
115}
116
117atf_test_case "4in6" "cleanup"
1184in6_head()
119{
120	atf_set descr 'IPv4 in IPv6 tunnel'
121	atf_set require.user root
122}
123
1244in6_body()
125{
126	vnet_init
127	if ! kldstat -q -m if_gif; then
128		atf_skip "This test requires if_gif"
129	fi
130
131	epair=$(vnet_mkepair)
132
133	vnet_mkjail one ${epair}a
134	jexec one ifconfig ${epair}a inet6 no_dad 2001:db8::1/64 up
135	gone=$(jexec one ifconfig gif create)
136	jexec one ifconfig $gone inet6 tunnel 2001:db8::1 2001:db8::2
137	jexec one ifconfig $gone inet 198.51.100.1/24 198.51.100.2 up
138
139	vnet_mkjail two ${epair}b
140	jexec two ifconfig ${epair}b inet6 no_dad 2001:db8::2/64 up
141	gtwo=$(jexec two ifconfig gif create)
142	jexec two ifconfig $gtwo inet6 tunnel 2001:db8::2 2001:db8::1
143	jexec two ifconfig $gtwo inet 198.51.100.2/24 198.51.100.1 up
144
145	# Sanity check
146	atf_check -s exit:0 -o ignore \
147	    jexec one ping -6 -c 1 2001:db8::2
148
149	# Tunnel test
150	atf_check -s exit:0 -o ignore \
151	    jexec one ping -c 1 198.51.100.2
152	atf_check -s exit:0 -o ignore \
153	    jexec two ping -c 1 198.51.100.1
154}
155
1564in6_cleanup()
157{
158	vnet_cleanup
159}
160
161atf_test_case "6in6" "cleanup"
1626in6_head()
163{
164	atf_set descr 'IPv6 in IPv6 tunnel'
165	atf_set require.user root
166}
167
1686in6_body()
169{
170	vnet_init
171	if ! kldstat -q -m if_gif; then
172		atf_skip "This test requires if_gif"
173	fi
174
175	epair=$(vnet_mkepair)
176
177	vnet_mkjail one ${epair}a
178	jexec one ifconfig ${epair}a inet6 no_dad 2001:db8::1/64 up
179	gone=$(jexec one ifconfig gif create)
180	jexec one ifconfig $gone inet6 tunnel 2001:db8::1 2001:db8::2
181	jexec one ifconfig $gone inet6 no_dad 2001:db8:1::1/64 up
182
183	vnet_mkjail two ${epair}b
184	jexec two ifconfig ${epair}b inet6 no_dad 2001:db8::2/64 up
185	gtwo=$(jexec two ifconfig gif create)
186	jexec two ifconfig $gtwo inet6 tunnel 2001:db8::2 2001:db8::1
187	jexec two ifconfig $gtwo inet6 no_dad 2001:db8:1::2/64 up
188
189	# Sanity check
190	atf_check -s exit:0 -o ignore \
191	    jexec one ping -6 -c 1 2001:db8::2
192
193	# Tunnel test
194	atf_check -s exit:0 -o ignore \
195	    jexec one ping -6 -c 1 2001:db8:1::2
196	atf_check -s exit:0 -o ignore \
197	    jexec two ping -6 -c 1 2001:db8:1::1
198}
199
2006in6_cleanup()
201{
202	vnet_cleanup
203}
204
205atf_test_case "etherip" "cleanup"
206etherip_head()
207{
208	atf_set descr 'EtherIP regression'
209	atf_set require.user root
210}
211
212etherip_body()
213{
214	vnet_init
215	vnet_init_bridge
216
217	if ! kldstat -q -m if_gif; then
218		atf_skip "This test requires if_gif"
219	fi
220
221	epair=$(vnet_mkepair)
222
223	vnet_mkjail one ${epair}a
224	gone=$(jexec one ifconfig gif create)
225	jexec one ifconfig ${epair}a 192.0.2.1/24 up
226	jexec one ifconfig $gone tunnel 192.0.2.1 192.0.2.2
227	jexec one ifconfig $gone 198.51.100.1/24 198.51.100.2 up
228	jexec one ifconfig $gone inet6 no_dad 2001:db8:1::1/64
229
230	bone=$(jexec one ifconfig bridge create)
231	jexec one ifconfig $bone addm $gone
232	jexec one ifconfig $bone 192.168.169.253/24 up
233	jexec one ifconfig $bone inet6 no_dad 2001:db8:2::1/64
234
235	vnet_mkjail two ${epair}b
236	gtwo=$(jexec two ifconfig gif create)
237	jexec two ifconfig ${epair}b 192.0.2.2/24 up
238	jexec two ifconfig $gtwo tunnel 192.0.2.2 192.0.2.1
239	jexec two ifconfig $gtwo 198.51.100.2/24 198.51.100.1 up
240	jexec two ifconfig $gtwo inet6 no_dad 2001:db8:1::2/64
241
242	btwo=$(jexec two ifconfig bridge create)
243	jexec two ifconfig $btwo addm $gtwo
244	jexec two ifconfig $btwo 192.168.169.254/24 up
245	jexec two ifconfig $btwo inet6 no_dad 2001:db8:2::2/64
246
247	# Sanity check
248	atf_check -s exit:0 -o ignore \
249	    jexec one ping -c 1 192.0.2.2
250
251	# EtherIP tunnel test
252	atf_check -s exit:0 -o ignore \
253	    jexec one ping -c 1 192.168.169.254
254	atf_check -s exit:0 -o ignore \
255	    jexec one ping -6 -c 1 2001:db8:2::2
256	atf_check -s exit:0 -o ignore \
257	    jexec two ping -c 1 192.168.169.253
258	atf_check -s exit:0 -o ignore \
259	    jexec two ping -6 -c 1 2001:db8:2::1
260
261	# EtherIP should not affect normal IPv[46] over IPv4 tunnel
262	# See bugzilla PR 227450
263	# IPv4 in IPv4 Tunnel test
264	atf_check -s exit:0 -o ignore \
265	    jexec one ping -c 1 198.51.100.2
266	atf_check -s exit:0 -o ignore \
267	    jexec two ping -c 1 198.51.100.1
268
269	# IPv6 in IPv4 tunnel test
270	atf_check -s exit:0 -o ignore \
271	    jexec one ping -6 -c 1 2001:db8:1::2
272	atf_check -s exit:0 -o ignore \
273	    jexec two ping -6 -c 1 2001:db8:1::1
274}
275
276etherip_cleanup()
277{
278	vnet_cleanup
279}
280
281atf_test_case "etherip6" "cleanup"
282etherip6_head()
283{
284	atf_set descr 'EtherIP over IPv6 regression'
285	atf_set require.user root
286}
287
288etherip6_body()
289{
290	vnet_init
291	vnet_init_bridge
292
293	if ! kldstat -q -m if_gif; then
294		atf_skip "This test requires if_gif"
295	fi
296
297	epair=$(vnet_mkepair)
298
299	vnet_mkjail one ${epair}a
300	gone=$(jexec one ifconfig gif create)
301	jexec one ifconfig ${epair}a inet6 no_dad 2001:db8::1/64 up
302	jexec one ifconfig $gone inet6 tunnel 2001:db8::1 2001:db8::2
303	jexec one ifconfig $gone 198.51.100.1/24 198.51.100.2 up
304	jexec one ifconfig $gone inet6 no_dad 2001:db8:1::1/64
305
306	bone=$(jexec one ifconfig bridge create)
307	jexec one ifconfig $bone addm $gone
308	jexec one ifconfig $bone 192.168.169.253/24 up
309	jexec one ifconfig $bone inet6 no_dad 2001:db8:2::1/64
310
311	vnet_mkjail two ${epair}b
312	gtwo=$(jexec two ifconfig gif create)
313	jexec two ifconfig ${epair}b inet6 no_dad 2001:db8::2/64 up
314	jexec two ifconfig $gtwo inet6 tunnel 2001:db8::2 2001:db8::1
315	jexec two ifconfig $gtwo 198.51.100.2/24 198.51.100.1 up
316	jexec two ifconfig $gtwo inet6 no_dad 2001:db8:1::2/64
317
318	btwo=$(jexec two ifconfig bridge create)
319	jexec two ifconfig $btwo addm $gtwo
320	jexec two ifconfig $btwo 192.168.169.254/24 up
321	jexec two ifconfig $btwo inet6 no_dad 2001:db8:2::2/64
322
323	# Sanity check
324	atf_check -s exit:0 -o ignore \
325	    jexec one ping -6 -c 1 2001:db8::2
326
327	# EtherIP tunnel test
328	atf_check -s exit:0 -o ignore \
329	    jexec one ping -c 1 192.168.169.254
330	atf_check -s exit:0 -o ignore \
331	    jexec one ping -6 -c 1 2001:db8:2::2
332	atf_check -s exit:0 -o ignore \
333	    jexec two ping -c 1 192.168.169.253
334	atf_check -s exit:0 -o ignore \
335	    jexec two ping -6 -c 1 2001:db8:2::1
336
337	# EtherIP should not affect normal IPv[46] over IPv6 tunnel
338	# See bugzilla PR 227450
339	# IPv4 in IPv6 Tunnel test
340	atf_check -s exit:0 -o ignore \
341	    jexec one ping -c 1 198.51.100.2
342	atf_check -s exit:0 -o ignore \
343	    jexec two ping -c 1 198.51.100.1
344
345	# IPv6 in IPv6 tunnel test
346	atf_check -s exit:0 -o ignore \
347	    jexec one ping -6 -c 1 2001:db8:1::2
348	atf_check -s exit:0 -o ignore \
349	    jexec two ping -6 -c 1 2001:db8:1::1
350}
351
352etherip6_cleanup()
353{
354	vnet_cleanup
355}
356
357atf_init_test_cases()
358{
359	atf_add_test_case "4in4"
360	atf_add_test_case "6in4"
361	atf_add_test_case "4in6"
362	atf_add_test_case "6in6"
363	atf_add_test_case "etherip"
364	atf_add_test_case "etherip6"
365}
366