xref: /freebsd/tests/sys/net/if_stf.sh (revision e0c4386e)
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 "6to4" "cleanup"
306to4_head()
31{
32	atf_set descr 'Test 6to4'
33	atf_set require.user root
34}
35
366to4_body()
37{
38	vnet_init
39	if ! kldstat -q -m if_stf; then
40		atf_skip "This test requires if_stf"
41	fi
42	if ! kldstat -q -m if_gif; then
43		atf_skip "This test requires if_gif"
44	fi
45
46	epair=$(vnet_mkepair)
47
48	vnet_mkjail relay ${epair}a
49	jexec relay ifconfig lo0 inet6 2001:db8::1/64 up
50	jexec relay ifconfig ${epair}a 192.0.2.1/24 up
51	# Simple gif to terminate 6to4
52	gif=$(jexec relay ifconfig gif create)
53	jexec relay ifconfig $gif inet6 2002:c000:0201::1/64 up
54	jexec relay ifconfig $gif tunnel 192.0.2.1 192.0.2.2
55	jexec relay route -6 add default -interface $gif
56
57	vnet_mkjail client ${epair}b
58	jexec client ifconfig lo0 up
59	jexec client ifconfig ${epair}b 192.0.2.2/24 up
60	stf=$(jexec client ifconfig stf create)
61	jexec client ifconfig $stf inet6 2002:c000:0202::1/32 up
62	jexec client route -6 add default 2002:c000:0201::1
63
64	# Sanity check
65	atf_check -s exit:0 -o ignore \
66	    jexec client ping -c 1 192.0.2.1
67	# 6to4 direct
68	atf_check -s exit:0 -o ignore \
69	    jexec client ping6 -c 1 2002:c000:0201::1
70
71	# "Wider internet"
72	atf_check -s exit:0 -o ignore \
73	    jexec client ping6 -c 1 2001:db8::1
74}
75
766to4_cleanup()
77{
78	vnet_cleanup
79}
80
81atf_test_case "6rd" "cleanup"
826rd_head()
83{
84	atf_set descr '6RD test'
85	atf_set require.user root
86}
87
886rd_body()
89{
90	vnet_init
91
92	if ! kldstat -q -m if_stf; then
93		atf_skip "This test requires if_stf"
94	fi
95	if ! kldstat -q -m if_gif; then
96		atf_skip "This test requires if_gif"
97	fi
98
99	epair=$(vnet_mkepair)
100	vnet_mkjail br ${epair}a
101	jexec br ifconfig ${epair}a 192.0.2.1/24 up
102
103	# Simple gif to terminate the 6RD tunnel
104	gif=$(jexec br ifconfig gif create)
105	jexec br ifconfig lo0 inet6 2001:db9::1/64 up
106	jexec br ifconfig $gif inet6 2001:db8::/64 up
107	jexec br ifconfig $gif tunnel 192.0.2.1 192.0.2.2
108	jexec br route -6 add default -interface $gif
109
110	vnet_mkjail client ${epair}b
111	jexec client ifconfig lo0 up
112	jexec client ifconfig ${epair}b 192.0.2.2/24 up
113
114	# Sanity check
115	atf_check -s exit:0 -o ignore \
116	    jexec client ping -c 1 192.0.2.1
117
118	stf=$(jexec client ifconfig stf create)
119
120	jexec client ifconfig $stf stfv4br 192.0.2.1
121	jexec client ifconfig $stf stfv4net 192.0.2.2/32
122	jexec client ifconfig $stf inet6 2001:db8:c000:0202::1/32 up
123	jexec client route -6 add default -interface $stf
124
125	atf_check -s exit:0 -o ignore \
126	    jexec client ping6 -c 1 2001:db9::1
127}
128
1296rd_cleanup()
130{
131	vnet_cleanup
132}
133
134atf_test_case "6rd_peer" "cleanup"
1356rd_peer_head()
136{
137	atf_set descr '6RD peer test'
138	atf_set require.user root
139}
140
1416rd_peer_body()
142{
143	vnet_init
144
145	if ! kldstat -q -m if_stf; then
146		atf_skip "This test requires if_stf"
147	fi
148
149	epair=$(vnet_mkepair)
150
151	vnet_mkjail one ${epair}a
152	jexec one ifconfig lo0 up
153	jexec one ifconfig ${epair}a 192.0.2.1/24 up
154	stf_one=$(jexec one ifconfig stf create)
155	jexec one ifconfig $stf_one stfv4br 192.0.2.3
156	jexec one ifconfig $stf_one stfv4net 192.0.2.1/32
157	jexec one ifconfig $stf_one inet6 2001:db8:c000:0201::1/32 up
158	jexec one route -6 add default -interface $stf_one
159
160	vnet_mkjail two ${epair}b
161	jexec two ifconfig lo0 up
162	jexec two ifconfig ${epair}b 192.0.2.2/24 up
163	stf_two=$(jexec two ifconfig stf create)
164	jexec two ifconfig $stf_two stfv4br 192.0.2.3
165	jexec two ifconfig $stf_two stfv4net 192.0.2.2/32
166	jexec two ifconfig $stf_two inet6 2001:db8:c000:0202::1/32 up
167	jexec two route -6 add default -interface $stf_two
168
169	# Sanity check
170	atf_check -s exit:0 -o ignore \
171	    jexec one ping -c 1 192.0.2.2
172
173	# Test 6rd
174	atf_check -s exit:0 -o ignore \
175	    jexec one ping6 -c 1 2001:db8:c000:0202::1
176	atf_check -s exit:0 -o ignore \
177	    jexec two ping6 -c 1 2001:db8:c000:0201::1
178
179	# Shorter prefixes, for both v4 and v6
180	jexec one ifconfig $stf_one inet6 2001:db8:c000:0201::1 delete
181	jexec one ifconfig $stf_one inet6 2001:0201::1/16
182	jexec one ifconfig $stf_one stfv4net 192.0.2.1/16
183	jexec two ifconfig $stf_two inet6 2001:db8:c000:0202::1 delete
184	jexec two ifconfig $stf_two inet6 2001:0202::1/16
185	jexec two ifconfig $stf_two stfv4net 192.0.2.2/16
186
187	atf_check -s exit:0 -o ignore \
188	    jexec one ping6 -c 1 2001:0202::1
189	atf_check -s exit:0 -o ignore \
190	    jexec two ping6 -c 1 2001:0201::1
191}
192
1936rd_peer_cleanup()
194{
195	vnet_cleanup
196}
197
198atf_init_test_cases()
199{
200	atf_add_test_case "6to4"
201	atf_add_test_case "6rd"
202	atf_add_test_case "6rd_peer"
203}
204