xref: /freebsd/tests/sys/net/if_bridge_test.sh (revision c5f5d0cf49bfa042aa6f8416449010370853e2bc)
1095aabf7SKristof Provost#
24d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
3095aabf7SKristof Provost#
4095aabf7SKristof Provost# Copyright (c) 2020 The FreeBSD Foundation
5095aabf7SKristof Provost#
6095aabf7SKristof Provost# This software was developed by Kristof Provost under sponsorship
7095aabf7SKristof Provost# from the FreeBSD Foundation.
8095aabf7SKristof Provost#
9095aabf7SKristof Provost# Redistribution and use in source and binary forms, with or without
10095aabf7SKristof Provost# modification, are permitted provided that the following conditions
11095aabf7SKristof Provost# are met:
12095aabf7SKristof Provost# 1. Redistributions of source code must retain the above copyright
13095aabf7SKristof Provost#    notice, this list of conditions and the following disclaimer.
14095aabf7SKristof Provost# 2. Redistributions in binary form must reproduce the above copyright
15095aabf7SKristof Provost#    notice, this list of conditions and the following disclaimer in the
16095aabf7SKristof Provost#    documentation and/or other materials provided with the distribution.
17095aabf7SKristof Provost#
18095aabf7SKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19095aabf7SKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20095aabf7SKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21095aabf7SKristof Provost# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22095aabf7SKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23095aabf7SKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24095aabf7SKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25095aabf7SKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26095aabf7SKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27095aabf7SKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28095aabf7SKristof Provost# SUCH DAMAGE.
29095aabf7SKristof Provost
30095aabf7SKristof Provost. $(atf_get_srcdir)/../common/vnet.subr
31095aabf7SKristof Provost
32095aabf7SKristof Provostatf_test_case "bridge_transmit_ipv4_unicast" "cleanup"
33095aabf7SKristof Provostbridge_transmit_ipv4_unicast_head()
34095aabf7SKristof Provost{
35095aabf7SKristof Provost	atf_set descr 'bridge_transmit_ipv4_unicast bridging test'
36095aabf7SKristof Provost	atf_set require.user root
37095aabf7SKristof Provost}
38095aabf7SKristof Provost
39095aabf7SKristof Provostbridge_transmit_ipv4_unicast_body()
40095aabf7SKristof Provost{
41095aabf7SKristof Provost	vnet_init
42480ad405SKristof Provost	vnet_init_bridge
43095aabf7SKristof Provost
44095aabf7SKristof Provost	epair_alcatraz=$(vnet_mkepair)
45095aabf7SKristof Provost	epair_singsing=$(vnet_mkepair)
46095aabf7SKristof Provost
47095aabf7SKristof Provost	vnet_mkjail alcatraz ${epair_alcatraz}b
48095aabf7SKristof Provost	vnet_mkjail singsing ${epair_singsing}b
49095aabf7SKristof Provost
50095aabf7SKristof Provost	jexec alcatraz ifconfig ${epair_alcatraz}b 192.0.2.1/24 up
51095aabf7SKristof Provost	jexec singsing ifconfig ${epair_singsing}b 192.0.2.2/24 up
52095aabf7SKristof Provost
53095aabf7SKristof Provost	bridge=$(vnet_mkbridge)
54095aabf7SKristof Provost
55095aabf7SKristof Provost	ifconfig ${bridge} up
56095aabf7SKristof Provost	ifconfig ${epair_alcatraz}a up
57095aabf7SKristof Provost	ifconfig ${epair_singsing}a up
58095aabf7SKristof Provost	ifconfig ${bridge} addm ${epair_alcatraz}a
59095aabf7SKristof Provost	ifconfig ${bridge} addm ${epair_singsing}a
60095aabf7SKristof Provost
61095aabf7SKristof Provost	atf_check -s exit:0 -o ignore jexec alcatraz ping -c 3 -t 1 192.0.2.2
62095aabf7SKristof Provost	atf_check -s exit:0 -o ignore jexec singsing ping -c 3 -t 1 192.0.2.1
63095aabf7SKristof Provost}
64095aabf7SKristof Provost
65095aabf7SKristof Provostbridge_transmit_ipv4_unicast_cleanup()
66095aabf7SKristof Provost{
67095aabf7SKristof Provost	vnet_cleanup
68095aabf7SKristof Provost}
69095aabf7SKristof Provost
706f0a65b0SKristof Provostatf_test_case "stp" "cleanup"
716f0a65b0SKristof Provoststp_head()
726f0a65b0SKristof Provost{
736f0a65b0SKristof Provost	atf_set descr 'Spanning tree test'
746f0a65b0SKristof Provost	atf_set require.user root
756f0a65b0SKristof Provost}
766f0a65b0SKristof Provost
776f0a65b0SKristof Provoststp_body()
786f0a65b0SKristof Provost{
796f0a65b0SKristof Provost	vnet_init
80480ad405SKristof Provost	vnet_init_bridge
816f0a65b0SKristof Provost
826f0a65b0SKristof Provost	epair_one=$(vnet_mkepair)
836f0a65b0SKristof Provost	epair_two=$(vnet_mkepair)
846f0a65b0SKristof Provost	bridge_a=$(vnet_mkbridge)
856f0a65b0SKristof Provost	bridge_b=$(vnet_mkbridge)
866f0a65b0SKristof Provost
876f0a65b0SKristof Provost	vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
886f0a65b0SKristof Provost	vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
896f0a65b0SKristof Provost
906f0a65b0SKristof Provost	jexec a ifconfig ${epair_one}a up
916f0a65b0SKristof Provost	jexec a ifconfig ${epair_two}a up
926f0a65b0SKristof Provost	jexec a ifconfig ${bridge_a} addm ${epair_one}a
936f0a65b0SKristof Provost	jexec a ifconfig ${bridge_a} addm ${epair_two}a
946f0a65b0SKristof Provost
956f0a65b0SKristof Provost	jexec b ifconfig ${epair_one}b up
966f0a65b0SKristof Provost	jexec b ifconfig ${epair_two}b up
976f0a65b0SKristof Provost	jexec b ifconfig ${bridge_b} addm ${epair_one}b
986f0a65b0SKristof Provost	jexec b ifconfig ${bridge_b} addm ${epair_two}b
996f0a65b0SKristof Provost
1006f0a65b0SKristof Provost	jexec a ifconfig ${bridge_a} 192.0.2.1/24
1016f0a65b0SKristof Provost
1026f0a65b0SKristof Provost	# Enable spanning tree
1036f0a65b0SKristof Provost	jexec a ifconfig ${bridge_a} stp ${epair_one}a
1046f0a65b0SKristof Provost	jexec a ifconfig ${bridge_a} stp ${epair_two}a
1056f0a65b0SKristof Provost	jexec b ifconfig ${bridge_b} stp ${epair_one}b
1066f0a65b0SKristof Provost	jexec b ifconfig ${bridge_b} stp ${epair_two}b
1076f0a65b0SKristof Provost
108e07e002eSKristof Provost	jexec b ifconfig ${bridge_b} up
109e07e002eSKristof Provost	jexec a ifconfig ${bridge_a} up
110e07e002eSKristof Provost
1116f0a65b0SKristof Provost	# Give STP time to do its thing
1126f0a65b0SKristof Provost	sleep 5
1136f0a65b0SKristof Provost
1146f0a65b0SKristof Provost	a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
1156f0a65b0SKristof Provost	b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
1166f0a65b0SKristof Provost
1176f0a65b0SKristof Provost	if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
1186f0a65b0SKristof Provost	then
1196f0a65b0SKristof Provost		atf_fail "STP failed to detect bridging loop"
1206f0a65b0SKristof Provost	fi
1217a4dbffaSKristof Provost
1227a4dbffaSKristof Provost	# We must also have at least some forwarding interfaces
1237a4dbffaSKristof Provost	a_forwarding=$(jexec a ifconfig ${bridge_a} | grep forwarding)
1247a4dbffaSKristof Provost	b_forwarding=$(jexec b ifconfig ${bridge_b} | grep forwarding)
1257a4dbffaSKristof Provost
1267a4dbffaSKristof Provost	if [ -z "${a_forwarding}" ] && [ -z "${b_forwarding}" ]
1277a4dbffaSKristof Provost	then
1287a4dbffaSKristof Provost		atf_fail "STP failed to detect bridging loop"
1297a4dbffaSKristof Provost	fi
1306f0a65b0SKristof Provost}
1316f0a65b0SKristof Provost
1326f0a65b0SKristof Provoststp_cleanup()
1336f0a65b0SKristof Provost{
1346f0a65b0SKristof Provost	vnet_cleanup
1356f0a65b0SKristof Provost}
1366f0a65b0SKristof Provost
13726492ba2SKristof Provostatf_test_case "stp_vlan" "cleanup"
13826492ba2SKristof Provoststp_vlan_head()
13926492ba2SKristof Provost{
14026492ba2SKristof Provost	atf_set descr 'Spanning tree on VLAN test'
14126492ba2SKristof Provost	atf_set require.user root
14226492ba2SKristof Provost}
14326492ba2SKristof Provost
14426492ba2SKristof Provoststp_vlan_body()
14526492ba2SKristof Provost{
14626492ba2SKristof Provost	vnet_init
147480ad405SKristof Provost	vnet_init_bridge
14826492ba2SKristof Provost
14926492ba2SKristof Provost	epair_one=$(vnet_mkepair)
15026492ba2SKristof Provost	epair_two=$(vnet_mkepair)
15126492ba2SKristof Provost	bridge_a=$(vnet_mkbridge)
15226492ba2SKristof Provost	bridge_b=$(vnet_mkbridge)
15326492ba2SKristof Provost
15426492ba2SKristof Provost	vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
15526492ba2SKristof Provost	vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
15626492ba2SKristof Provost
15726492ba2SKristof Provost	jexec a ifconfig ${epair_one}a up
15826492ba2SKristof Provost	jexec a ifconfig ${epair_two}a up
15926492ba2SKristof Provost	vlan_a_one=$(jexec a ifconfig vlan create vlandev ${epair_one}a vlan 42)
16026492ba2SKristof Provost	vlan_a_two=$(jexec a ifconfig vlan create vlandev ${epair_two}a vlan 42)
16126492ba2SKristof Provost	jexec a ifconfig ${vlan_a_one} up
16226492ba2SKristof Provost	jexec a ifconfig ${vlan_a_two} up
16326492ba2SKristof Provost	jexec a ifconfig ${bridge_a} addm ${vlan_a_one}
16426492ba2SKristof Provost	jexec a ifconfig ${bridge_a} addm ${vlan_a_two}
16526492ba2SKristof Provost
16626492ba2SKristof Provost	jexec b ifconfig ${epair_one}b up
16726492ba2SKristof Provost	jexec b ifconfig ${epair_two}b up
16826492ba2SKristof Provost	vlan_b_one=$(jexec b ifconfig vlan create vlandev ${epair_one}b vlan 42)
16926492ba2SKristof Provost	vlan_b_two=$(jexec b ifconfig vlan create vlandev ${epair_two}b vlan 42)
17026492ba2SKristof Provost	jexec b ifconfig ${vlan_b_one} up
17126492ba2SKristof Provost	jexec b ifconfig ${vlan_b_two} up
17226492ba2SKristof Provost	jexec b ifconfig ${bridge_b} addm ${vlan_b_one}
17326492ba2SKristof Provost	jexec b ifconfig ${bridge_b} addm ${vlan_b_two}
17426492ba2SKristof Provost
17526492ba2SKristof Provost	jexec a ifconfig ${bridge_a} 192.0.2.1/24
17626492ba2SKristof Provost
17726492ba2SKristof Provost	# Enable spanning tree
17826492ba2SKristof Provost	jexec a ifconfig ${bridge_a} stp ${vlan_a_one}
17926492ba2SKristof Provost	jexec a ifconfig ${bridge_a} stp ${vlan_a_two}
18026492ba2SKristof Provost	jexec b ifconfig ${bridge_b} stp ${vlan_b_one}
18126492ba2SKristof Provost	jexec b ifconfig ${bridge_b} stp ${vlan_b_two}
18226492ba2SKristof Provost
18326492ba2SKristof Provost	jexec b ifconfig ${bridge_b} up
18426492ba2SKristof Provost	jexec a ifconfig ${bridge_a} up
18526492ba2SKristof Provost
18626492ba2SKristof Provost	# Give STP time to do its thing
18726492ba2SKristof Provost	sleep 5
18826492ba2SKristof Provost
18926492ba2SKristof Provost	a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
19026492ba2SKristof Provost	b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
19126492ba2SKristof Provost
19226492ba2SKristof Provost	if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
19326492ba2SKristof Provost	then
19426492ba2SKristof Provost		atf_fail "STP failed to detect bridging loop"
19526492ba2SKristof Provost	fi
1967a4dbffaSKristof Provost
1977a4dbffaSKristof Provost	# We must also have at least some forwarding interfaces
1987a4dbffaSKristof Provost	a_forwarding=$(jexec a ifconfig ${bridge_a} | grep forwarding)
1997a4dbffaSKristof Provost	b_forwarding=$(jexec b ifconfig ${bridge_b} | grep forwarding)
2007a4dbffaSKristof Provost
2017a4dbffaSKristof Provost	if [ -z "${a_forwarding}" ] && [ -z "${b_forwarding}" ]
2027a4dbffaSKristof Provost	then
2037a4dbffaSKristof Provost		atf_fail "STP failed to detect bridging loop"
2047a4dbffaSKristof Provost	fi
20526492ba2SKristof Provost}
20626492ba2SKristof Provost
20726492ba2SKristof Provoststp_vlan_cleanup()
20826492ba2SKristof Provost{
20926492ba2SKristof Provost	vnet_cleanup
21026492ba2SKristof Provost}
21126492ba2SKristof Provost
212d99bb677SKristof Provostatf_test_case "static" "cleanup"
213d99bb677SKristof Provoststatic_head()
214d99bb677SKristof Provost{
215d99bb677SKristof Provost	atf_set descr 'Bridge static address test'
216d99bb677SKristof Provost	atf_set require.user root
217d99bb677SKristof Provost}
218d99bb677SKristof Provost
219d99bb677SKristof Provoststatic_body()
220d99bb677SKristof Provost{
221d99bb677SKristof Provost	vnet_init
222480ad405SKristof Provost	vnet_init_bridge
223d99bb677SKristof Provost
224d99bb677SKristof Provost	epair=$(vnet_mkepair)
225d99bb677SKristof Provost	bridge=$(vnet_mkbridge)
226d99bb677SKristof Provost
227d99bb677SKristof Provost	vnet_mkjail one ${bridge} ${epair}a
228d99bb677SKristof Provost
229d99bb677SKristof Provost	ifconfig ${epair}b up
230d99bb677SKristof Provost
231d99bb677SKristof Provost	jexec one ifconfig ${bridge} up
232d99bb677SKristof Provost	jexec one ifconfig ${epair}a up
233d99bb677SKristof Provost	jexec one ifconfig ${bridge} addm ${epair}a
234d99bb677SKristof Provost
235d99bb677SKristof Provost	# Wrong interface
236d99bb677SKristof Provost	atf_check -s exit:1 -o ignore -e ignore \
237d99bb677SKristof Provost	    jexec one ifconfig ${bridge} static ${epair}b 00:01:02:03:04:05
238d99bb677SKristof Provost
239d99bb677SKristof Provost	# Bad address format
240d99bb677SKristof Provost	atf_check -s exit:1 -o ignore -e ignore \
241d99bb677SKristof Provost	    jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04
242d99bb677SKristof Provost
243d99bb677SKristof Provost	# Correct add
244d99bb677SKristof Provost	atf_check -s exit:0 -o ignore \
245d99bb677SKristof Provost	    jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04:05
246d99bb677SKristof Provost
247d99bb677SKristof Provost	# List addresses
248d99bb677SKristof Provost	atf_check -s exit:0 -o ignore \
249d99bb677SKristof Provost	    jexec one ifconfig ${bridge} addr
250d99bb677SKristof Provost
251d99bb677SKristof Provost	# Delete with bad address format
252d99bb677SKristof Provost	atf_check -s exit:1 -o ignore -e ignore \
253d99bb677SKristof Provost	    jexec one ifconfig ${bridge} deladdr 00:01:02:03:04
254d99bb677SKristof Provost
255d99bb677SKristof Provost	# Delete with unlisted address
256d99bb677SKristof Provost	atf_check -s exit:1 -o ignore -e ignore \
257d99bb677SKristof Provost	    jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:06
258d99bb677SKristof Provost
259d99bb677SKristof Provost	# Correct delete
260d99bb677SKristof Provost	atf_check -s exit:0 -o ignore \
261d99bb677SKristof Provost	    jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:05
262d99bb677SKristof Provost}
263d99bb677SKristof Provost
264d99bb677SKristof Provoststatic_cleanup()
265d99bb677SKristof Provost{
266d99bb677SKristof Provost	vnet_cleanup
267d99bb677SKristof Provost}
268d99bb677SKristof Provost
269bb490fcfSKristof Provostatf_test_case "span" "cleanup"
270bb490fcfSKristof Provostspan_head()
271bb490fcfSKristof Provost{
272bb490fcfSKristof Provost	atf_set descr 'Bridge span test'
273bb490fcfSKristof Provost	atf_set require.user root
274c46af893SJose Luis Duran	atf_set require.progs python3 scapy
275bb490fcfSKristof Provost}
276bb490fcfSKristof Provost
277bb490fcfSKristof Provostspan_body()
278bb490fcfSKristof Provost{
279bb490fcfSKristof Provost	vnet_init
280480ad405SKristof Provost	vnet_init_bridge
281bb490fcfSKristof Provost
282bb490fcfSKristof Provost	epair=$(vnet_mkepair)
283bb490fcfSKristof Provost	epair_span=$(vnet_mkepair)
284bb490fcfSKristof Provost	bridge=$(vnet_mkbridge)
285bb490fcfSKristof Provost
286bb490fcfSKristof Provost	vnet_mkjail one ${bridge} ${epair}a ${epair_span}a
287bb490fcfSKristof Provost
288bb490fcfSKristof Provost	ifconfig ${epair}b up
289bb490fcfSKristof Provost	ifconfig ${epair_span}b up
290bb490fcfSKristof Provost
291bb490fcfSKristof Provost	jexec one ifconfig ${bridge} up
292bb490fcfSKristof Provost	jexec one ifconfig ${epair}a up
293bb490fcfSKristof Provost	jexec one ifconfig ${epair_span}a up
294bb490fcfSKristof Provost	jexec one ifconfig ${bridge} addm ${epair}a
295bb490fcfSKristof Provost
296bb490fcfSKristof Provost	jexec one ifconfig ${bridge} span ${epair_span}a
297bb490fcfSKristof Provost	jexec one ifconfig ${bridge} 192.0.2.1/24
298bb490fcfSKristof Provost
299bb490fcfSKristof Provost	# Send some traffic through the span
300bb490fcfSKristof Provost	jexec one ping -c 1 -t 1 192.0.2.2
301bb490fcfSKristof Provost
302bb490fcfSKristof Provost	# Check that we see the traffic on the span interface
303bb490fcfSKristof Provost	atf_check -s exit:0 \
304bb490fcfSKristof Provost		$(atf_get_srcdir)/../netpfil/common/pft_ping.py \
305bb490fcfSKristof Provost		--sendif ${epair}b \
306bb490fcfSKristof Provost		--to 192.0.2.2 \
307bb490fcfSKristof Provost		--recvif ${epair_span}b
308bb490fcfSKristof Provost
309bb490fcfSKristof Provost	jexec one ifconfig ${bridge} -span ${epair_span}a
310bb490fcfSKristof Provost
311bb490fcfSKristof Provost	# And no more traffic after we remove the span
312bb490fcfSKristof Provost	atf_check -s exit:1 \
313bb490fcfSKristof Provost		$(atf_get_srcdir)/../netpfil/common/pft_ping.py \
314bb490fcfSKristof Provost		--sendif ${epair}b \
315bb490fcfSKristof Provost		--to 192.0.2.2 \
316bb490fcfSKristof Provost		--recvif ${epair_span}b
317bb490fcfSKristof Provost}
318bb490fcfSKristof Provost
319bb490fcfSKristof Provostspan_cleanup()
320bb490fcfSKristof Provost{
321bb490fcfSKristof Provost	vnet_cleanup
322bb490fcfSKristof Provost}
323bb490fcfSKristof Provost
3243f359bfdSKristof Provostatf_test_case "delete_with_members" "cleanup"
3253f359bfdSKristof Provostdelete_with_members_head()
3263f359bfdSKristof Provost{
3273f359bfdSKristof Provost	atf_set descr 'Delete a bridge which still has member interfaces'
3283f359bfdSKristof Provost	atf_set require.user root
3293f359bfdSKristof Provost}
3303f359bfdSKristof Provost
3313f359bfdSKristof Provostdelete_with_members_body()
3323f359bfdSKristof Provost{
3333f359bfdSKristof Provost	vnet_init
334480ad405SKristof Provost	vnet_init_bridge
3353f359bfdSKristof Provost
3363f359bfdSKristof Provost	bridge=$(vnet_mkbridge)
3373f359bfdSKristof Provost	epair=$(vnet_mkepair)
3383f359bfdSKristof Provost
3393f359bfdSKristof Provost	ifconfig ${bridge} 192.0.2.1/24 up
3403f359bfdSKristof Provost	ifconfig ${epair}a up
3413f359bfdSKristof Provost	ifconfig ${bridge} addm ${epair}a
3423f359bfdSKristof Provost
3433f359bfdSKristof Provost	ifconfig ${bridge} destroy
3443f359bfdSKristof Provost}
3453f359bfdSKristof Provost
3463f359bfdSKristof Provostdelete_with_members_cleanup()
3473f359bfdSKristof Provost{
3483f359bfdSKristof Provost	vnet_cleanup
3493f359bfdSKristof Provost}
3503f359bfdSKristof Provost
3512885ae0cSKristof Provostatf_test_case "mac_conflict" "cleanup"
3522885ae0cSKristof Provostmac_conflict_head()
3532885ae0cSKristof Provost{
3542885ae0cSKristof Provost	atf_set descr 'Ensure that bridges in different jails get different mac addresses'
3552885ae0cSKristof Provost	atf_set require.user root
3562885ae0cSKristof Provost}
3572885ae0cSKristof Provost
3582885ae0cSKristof Provostmac_conflict_body()
3592885ae0cSKristof Provost{
3602885ae0cSKristof Provost	vnet_init
361480ad405SKristof Provost	vnet_init_bridge
3622885ae0cSKristof Provost
3632885ae0cSKristof Provost	epair=$(vnet_mkepair)
3642885ae0cSKristof Provost
3652885ae0cSKristof Provost	# Ensure the bridge module is loaded so jails can use it.
3662885ae0cSKristof Provost	tmpbridge=$(vnet_mkbridge)
3672885ae0cSKristof Provost
3682885ae0cSKristof Provost	vnet_mkjail bridge_mac_conflict_one ${epair}a
3692885ae0cSKristof Provost	vnet_mkjail bridge_mac_conflict_two ${epair}b
3702885ae0cSKristof Provost
3712885ae0cSKristof Provost	jexec bridge_mac_conflict_one ifconfig bridge create
3722885ae0cSKristof Provost	jexec bridge_mac_conflict_one ifconfig bridge0 192.0.2.1/24 up \
3732885ae0cSKristof Provost	    addm ${epair}a
3742885ae0cSKristof Provost	jexec bridge_mac_conflict_one ifconfig ${epair}a up
3752885ae0cSKristof Provost
3762885ae0cSKristof Provost	jexec bridge_mac_conflict_two ifconfig bridge create
3772885ae0cSKristof Provost	jexec bridge_mac_conflict_two ifconfig bridge0 192.0.2.2/24 up \
3782885ae0cSKristof Provost	    addm ${epair}b
3792885ae0cSKristof Provost	jexec bridge_mac_conflict_two ifconfig ${epair}b up
3802885ae0cSKristof Provost
3812885ae0cSKristof Provost	atf_check -s exit:0 -o ignore \
3822885ae0cSKristof Provost	    jexec bridge_mac_conflict_one ping -c 3 192.0.2.2
3832885ae0cSKristof Provost}
3842885ae0cSKristof Provost
3852885ae0cSKristof Provostmac_conflict_cleanup()
3862885ae0cSKristof Provost{
3872885ae0cSKristof Provost	vnet_cleanup
3882885ae0cSKristof Provost}
3892885ae0cSKristof Provost
39053775607SKristof Provostatf_test_case "inherit_mac" "cleanup"
39153775607SKristof Provostinherit_mac_head()
39253775607SKristof Provost{
39353775607SKristof Provost	atf_set descr 'Bridge inherit_mac test, #216510'
39453775607SKristof Provost	atf_set require.user root
39553775607SKristof Provost}
39653775607SKristof Provost
39753775607SKristof Provostinherit_mac_body()
39853775607SKristof Provost{
39953775607SKristof Provost	vnet_init
400480ad405SKristof Provost	vnet_init_bridge
40153775607SKristof Provost
40253775607SKristof Provost	bridge=$(vnet_mkbridge)
40353775607SKristof Provost	epair=$(vnet_mkepair)
40453775607SKristof Provost	vnet_mkjail one ${bridge} ${epair}a
40553775607SKristof Provost
40653775607SKristof Provost	jexec one sysctl net.link.bridge.inherit_mac=1
40753775607SKristof Provost
40853775607SKristof Provost	# Attempt to provoke the panic described in #216510
40953775607SKristof Provost	jexec one ifconfig ${bridge} 192.0.0.1/24 up
41053775607SKristof Provost	jexec one ifconfig ${bridge} addm ${epair}a
41153775607SKristof Provost}
41253775607SKristof Provost
41353775607SKristof Provostinherit_mac_cleanup()
41453775607SKristof Provost{
41553775607SKristof Provost	vnet_cleanup
41653775607SKristof Provost}
41753775607SKristof Provost
4184ae3a97eSKristof Provostatf_test_case "stp_validation" "cleanup"
4194ae3a97eSKristof Provoststp_validation_head()
4204ae3a97eSKristof Provost{
4214ae3a97eSKristof Provost	atf_set descr 'Check STP validation'
4224ae3a97eSKristof Provost	atf_set require.user root
423c46af893SJose Luis Duran	atf_set require.progs python3 scapy
4244ae3a97eSKristof Provost}
4254ae3a97eSKristof Provost
4264ae3a97eSKristof Provoststp_validation_body()
4274ae3a97eSKristof Provost{
4284ae3a97eSKristof Provost	vnet_init
429480ad405SKristof Provost	vnet_init_bridge
4304ae3a97eSKristof Provost
4314ae3a97eSKristof Provost	epair_one=$(vnet_mkepair)
4324ae3a97eSKristof Provost	epair_two=$(vnet_mkepair)
4334ae3a97eSKristof Provost	bridge=$(vnet_mkbridge)
4344ae3a97eSKristof Provost
4354ae3a97eSKristof Provost	ifconfig ${bridge} up
4364ae3a97eSKristof Provost	ifconfig ${bridge} addm ${epair_one}a addm ${epair_two}a
4374ae3a97eSKristof Provost	ifconfig ${bridge} stp ${epair_one}a stp ${epair_two}a
4384ae3a97eSKristof Provost
4394ae3a97eSKristof Provost	ifconfig ${epair_one}a up
4404ae3a97eSKristof Provost	ifconfig ${epair_one}b up
4414ae3a97eSKristof Provost	ifconfig ${epair_two}a up
4424ae3a97eSKristof Provost	ifconfig ${epair_two}b up
4434ae3a97eSKristof Provost
4444ae3a97eSKristof Provost	# Wait until the interfaces are no longer discarding
4454ae3a97eSKristof Provost	while ifconfig ${bridge} | grep 'state discarding' >/dev/null
4464ae3a97eSKristof Provost	do
4474ae3a97eSKristof Provost		sleep 1
4484ae3a97eSKristof Provost	done
4494ae3a97eSKristof Provost
4504ae3a97eSKristof Provost	# Now inject invalid STP BPDUs on epair_one and see if they're repeated
4514ae3a97eSKristof Provost	# on epair_two
4524ae3a97eSKristof Provost	atf_check -s exit:0 \
4534ae3a97eSKristof Provost	    $(atf_get_srcdir)/stp.py \
4544ae3a97eSKristof Provost	    --sendif ${epair_one}b \
4554ae3a97eSKristof Provost	    --recvif ${epair_two}b
4564ae3a97eSKristof Provost}
4574ae3a97eSKristof Provost
4584ae3a97eSKristof Provoststp_validation_cleanup()
4594ae3a97eSKristof Provost{
4604ae3a97eSKristof Provost	vnet_cleanup
4614ae3a97eSKristof Provost}
4624ae3a97eSKristof Provost
4634b765ab4SKristof Provostatf_test_case "gif" "cleanup"
4644b765ab4SKristof Provostgif_head()
4654b765ab4SKristof Provost{
4664b765ab4SKristof Provost	atf_set descr 'gif as a bridge member'
4674b765ab4SKristof Provost	atf_set require.user root
4684b765ab4SKristof Provost}
4694b765ab4SKristof Provost
4704b765ab4SKristof Provostgif_body()
4714b765ab4SKristof Provost{
4724b765ab4SKristof Provost	vnet_init
473480ad405SKristof Provost	vnet_init_bridge
4744b765ab4SKristof Provost
4754b765ab4SKristof Provost	epair=$(vnet_mkepair)
4764b765ab4SKristof Provost
4774b765ab4SKristof Provost	vnet_mkjail one ${epair}a
4784b765ab4SKristof Provost	vnet_mkjail two ${epair}b
4794b765ab4SKristof Provost
4804b765ab4SKristof Provost	jexec one sysctl net.link.gif.max_nesting=2
4814b765ab4SKristof Provost	jexec two sysctl net.link.gif.max_nesting=2
4824b765ab4SKristof Provost
4834b765ab4SKristof Provost	jexec one ifconfig ${epair}a 192.0.2.1/24 up
4844b765ab4SKristof Provost	jexec two ifconfig ${epair}b 192.0.2.2/24 up
4854b765ab4SKristof Provost
4864b765ab4SKristof Provost	# Tunnel
4874b765ab4SKristof Provost	gif_one=$(jexec one ifconfig gif create)
4884b765ab4SKristof Provost	gif_two=$(jexec two ifconfig gif create)
4894b765ab4SKristof Provost
4904b765ab4SKristof Provost	jexec one ifconfig ${gif_one} tunnel 192.0.2.1 192.0.2.2
4914b765ab4SKristof Provost	jexec one ifconfig ${gif_one} up
4924b765ab4SKristof Provost	jexec two ifconfig ${gif_two} tunnel 192.0.2.2 192.0.2.1
4934b765ab4SKristof Provost	jexec two ifconfig ${gif_two} up
4944b765ab4SKristof Provost
4954b765ab4SKristof Provost	bridge_one=$(jexec one ifconfig bridge create)
4964b765ab4SKristof Provost	bridge_two=$(jexec two ifconfig bridge create)
4974b765ab4SKristof Provost	jexec one ifconfig ${bridge_one} 198.51.100.1/24 up
4984b765ab4SKristof Provost	jexec one ifconfig ${bridge_one} addm ${gif_one}
4994b765ab4SKristof Provost	jexec two ifconfig ${bridge_two} 198.51.100.2/24 up
5004b765ab4SKristof Provost	jexec two ifconfig ${bridge_two} addm ${gif_two}
5014b765ab4SKristof Provost
5024b765ab4SKristof Provost	# Sanity check
5034b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5044b765ab4SKristof Provost		jexec one ping -c 1 192.0.2.2
5054b765ab4SKristof Provost
5064b765ab4SKristof Provost	# Test tunnel
5074b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5084b765ab4SKristof Provost		jexec one ping -c 1 198.51.100.2
5094b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5104b765ab4SKristof Provost		jexec one ping -c 1 -s 1200 198.51.100.2
5114b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5124b765ab4SKristof Provost		jexec one ping -c 1 -s 2000 198.51.100.2
5134b765ab4SKristof Provost
5144b765ab4SKristof Provost	# Higher MTU on the tunnel than on the underlying interface
5154b765ab4SKristof Provost	jexec one ifconfig ${epair}a mtu 1000
5164b765ab4SKristof Provost	jexec two ifconfig ${epair}b mtu 1000
5174b765ab4SKristof Provost
5184b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5194b765ab4SKristof Provost		jexec one ping -c 1 -s 1200 198.51.100.2
5204b765ab4SKristof Provost	atf_check -s exit:0 -o ignore \
5214b765ab4SKristof Provost		jexec one ping -c 1 -s 2000 198.51.100.2
5224b765ab4SKristof Provost}
5234b765ab4SKristof Provost
5244b765ab4SKristof Provostgif_cleanup()
5254b765ab4SKristof Provost{
5264b765ab4SKristof Provost	vnet_cleanup
5274b765ab4SKristof Provost}
5284b765ab4SKristof Provost
5296e439506SKristof Provostatf_test_case "mtu" "cleanup"
5306e439506SKristof Provostmtu_head()
5316e439506SKristof Provost{
5326e439506SKristof Provost	atf_set descr 'Bridge MTU changes'
5336e439506SKristof Provost	atf_set require.user root
5346e439506SKristof Provost}
5356e439506SKristof Provost
5366e439506SKristof Provostget_mtu()
5376e439506SKristof Provost{
5386e439506SKristof Provost	intf=$1
5396e439506SKristof Provost
5406e439506SKristof Provost	ifconfig ${intf} ether | awk '$5 == "mtu" { print $6 }'
5416e439506SKristof Provost}
5426e439506SKristof Provost
5436e439506SKristof Provostcheck_mtu()
5446e439506SKristof Provost{
5456e439506SKristof Provost	intf=$1
5466e439506SKristof Provost	expected=$2
5476e439506SKristof Provost
5486e439506SKristof Provost	mtu=$(get_mtu $intf)
5496e439506SKristof Provost	if [ $mtu -ne $expected ];
5506e439506SKristof Provost	then
5516e439506SKristof Provost		atf_fail "Expected MTU of $expected on $intf but found $mtu"
5526e439506SKristof Provost	fi
5536e439506SKristof Provost}
5546e439506SKristof Provost
5556e439506SKristof Provostmtu_body()
5566e439506SKristof Provost{
5576e439506SKristof Provost	vnet_init
558480ad405SKristof Provost	vnet_init_bridge
5596e439506SKristof Provost
5606e439506SKristof Provost	epair=$(vnet_mkepair)
5616e439506SKristof Provost	gif=$(ifconfig gif create)
5626e439506SKristof Provost	echo ${gif} >> created_interfaces.lst
5636e439506SKristof Provost	bridge=$(vnet_mkbridge)
5646e439506SKristof Provost
5656e439506SKristof Provost	atf_check -s exit:0 \
5666e439506SKristof Provost		ifconfig ${bridge} addm ${epair}a
5676e439506SKristof Provost
5686e439506SKristof Provost	ifconfig ${gif} mtu 1500
5696e439506SKristof Provost	atf_check -s exit:0 \
5706e439506SKristof Provost		ifconfig ${bridge} addm ${gif}
5716e439506SKristof Provost
5726e439506SKristof Provost	# Changing MTU changes it for all member interfaces
5736e439506SKristof Provost	atf_check -s exit:0 \
5746e439506SKristof Provost		ifconfig ${bridge} mtu 2000
5756e439506SKristof Provost
5766e439506SKristof Provost	check_mtu ${bridge} 2000
5776e439506SKristof Provost	check_mtu ${gif} 2000
5786e439506SKristof Provost	check_mtu ${epair}a 2000
5796e439506SKristof Provost
5806e439506SKristof Provost	# Rejected MTUs mean none of the MTUs change
5816e439506SKristof Provost	atf_check -s exit:1 -e ignore \
5826e439506SKristof Provost		ifconfig ${bridge} mtu 9000
5836e439506SKristof Provost
5846e439506SKristof Provost	check_mtu ${bridge} 2000
5856e439506SKristof Provost	check_mtu ${gif} 2000
5866e439506SKristof Provost	check_mtu ${epair}a 2000
587441d15a4SKristof Provost
588441d15a4SKristof Provost	# We're not allowed to change the MTU of a member interface
589441d15a4SKristof Provost	atf_check -s exit:1 -e ignore \
590441d15a4SKristof Provost		ifconfig ${epair}a mtu 1900
591441d15a4SKristof Provost	check_mtu ${epair}a 2000
5921e824ee8SKristof Provost
5931e824ee8SKristof Provost	# Test adding an interface with a different MTU
5941e824ee8SKristof Provost	new_epair=$(vnet_mkepair)
5951e824ee8SKristof Provost	check_mtu ${new_epair}a 1500
5961e824ee8SKristof Provost	atf_check -s exit:0 -e ignore \
5971e824ee8SKristof Provost		ifconfig ${bridge} addm ${new_epair}a
5981e824ee8SKristof Provost
5991e824ee8SKristof Provost	check_mtu ${bridge} 2000
6001e824ee8SKristof Provost	check_mtu ${gif} 2000
6011e824ee8SKristof Provost	check_mtu ${epair}a 2000
6021e824ee8SKristof Provost	check_mtu ${new_epair}a 2000
6036e439506SKristof Provost}
6046e439506SKristof Provost
6056e439506SKristof Provostmtu_cleanup()
6066e439506SKristof Provost{
6076e439506SKristof Provost	vnet_cleanup
6086e439506SKristof Provost}
6096e439506SKristof Provost
610f97802a3SKristof Provostatf_test_case "vlan" "cleanup"
611f97802a3SKristof Provostvlan_head()
612f97802a3SKristof Provost{
613f97802a3SKristof Provost	atf_set descr 'Ensure the bridge takes vlan ID into account, PR#270559'
614f97802a3SKristof Provost	atf_set require.user root
615f97802a3SKristof Provost}
616f97802a3SKristof Provost
617f97802a3SKristof Provostvlan_body()
618f97802a3SKristof Provost{
619f97802a3SKristof Provost	vnet_init
620480ad405SKristof Provost	vnet_init_bridge
621f97802a3SKristof Provost
622f97802a3SKristof Provost	vid=1
623f97802a3SKristof Provost
624f97802a3SKristof Provost	epaira=$(vnet_mkepair)
625f97802a3SKristof Provost	epairb=$(vnet_mkepair)
626f97802a3SKristof Provost
627f97802a3SKristof Provost	br=$(vnet_mkbridge)
628f97802a3SKristof Provost
629f97802a3SKristof Provost	vnet_mkjail one ${epaira}b
630f97802a3SKristof Provost	vnet_mkjail two ${epairb}b
631f97802a3SKristof Provost
632f97802a3SKristof Provost	ifconfig ${br} up
633f97802a3SKristof Provost	ifconfig ${epaira}a up
634f97802a3SKristof Provost	ifconfig ${epairb}a up
635f97802a3SKristof Provost	ifconfig ${br} addm ${epaira}a addm ${epairb}a
636f97802a3SKristof Provost
637f97802a3SKristof Provost	jexec one ifconfig ${epaira}b up
638f97802a3SKristof Provost	jexec one ifconfig ${epaira}b.${vid} create
639f97802a3SKristof Provost
640f97802a3SKristof Provost	jexec two ifconfig ${epairb}b up
641f97802a3SKristof Provost	jexec two ifconfig ${epairb}b.${vid} create
642f97802a3SKristof Provost
643f97802a3SKristof Provost	# Create a MAC address conflict between an untagged and tagged interface
644f97802a3SKristof Provost	jexec two ifconfig ${epairb}b.${vid} ether 02:05:6e:06:28:1a
645f97802a3SKristof Provost	jexec one ifconfig ${epaira}b ether 02:05:6e:06:28:1a
646f97802a3SKristof Provost	jexec one ifconfig ${epaira}b.${vid} ether 02:05:6e:06:28:1b
647f97802a3SKristof Provost
648f97802a3SKristof Provost	# Add ip address, will also populate $br's fowarding table, by ARP announcement
649f97802a3SKristof Provost	jexec one ifconfig ${epaira}b.${vid} 192.0.2.1/24 up
650f97802a3SKristof Provost	jexec two ifconfig ${epairb}b.${vid} 192.0.2.2/24 up
651f97802a3SKristof Provost
652f97802a3SKristof Provost	sleep 0.5
653f97802a3SKristof Provost
654f97802a3SKristof Provost	ifconfig ${br}
655f97802a3SKristof Provost	jexec one ifconfig
656f97802a3SKristof Provost	jexec two ifconfig
657f97802a3SKristof Provost	ifconfig ${br} addr
658f97802a3SKristof Provost
659f97802a3SKristof Provost	atf_check -s exit:0 -o ignore \
660f97802a3SKristof Provost	    jexec one ping -c 1 -t 1 192.0.2.2
661f97802a3SKristof Provost
662f97802a3SKristof Provost	# This will trigger a mac flap (by ARP announcement)
663f97802a3SKristof Provost	jexec one ifconfig ${epaira}b 192.0.2.1/24 up
664f97802a3SKristof Provost
665f97802a3SKristof Provost	sleep 0.5
666f97802a3SKristof Provost
667f97802a3SKristof Provost	ifconfig ${br} addr
668f97802a3SKristof Provost
669f97802a3SKristof Provost	atf_check -s exit:0 -o ignore \
670f97802a3SKristof Provost	    jexec one ping -c 1 -t 1 192.0.2.2
671f97802a3SKristof Provost}
672f97802a3SKristof Provost
673f97802a3SKristof Provostvlan_cleanup()
674f97802a3SKristof Provost{
675f97802a3SKristof Provost	vnet_cleanup
676f97802a3SKristof Provost}
677f97802a3SKristof Provost
6783d36053cSMichael Gmelinatf_test_case "many_bridge_members" "cleanup"
6793d36053cSMichael Gmelinmany_bridge_members_head()
6803d36053cSMichael Gmelin{
6813d36053cSMichael Gmelin	atf_set descr 'many_bridge_members ifconfig test'
6823d36053cSMichael Gmelin	atf_set require.user root
6833d36053cSMichael Gmelin}
6843d36053cSMichael Gmelin
6853d36053cSMichael Gmelinmany_bridge_members_body()
6863d36053cSMichael Gmelin{
6873d36053cSMichael Gmelin	vnet_init
688480ad405SKristof Provost	vnet_init_bridge
6893d36053cSMichael Gmelin
6903d36053cSMichael Gmelin	bridge=$(vnet_mkbridge)
6913d36053cSMichael Gmelin	ifcount=256
6923d36053cSMichael Gmelin	for _ in $(seq 1 $ifcount); do
6933d36053cSMichael Gmelin		epair=$(vnet_mkepair)
6943d36053cSMichael Gmelin		ifconfig "${bridge}" addm "${epair}"a
6953d36053cSMichael Gmelin	done
6963d36053cSMichael Gmelin
6973d36053cSMichael Gmelin	atf_check -s exit:0 -o inline:"$ifcount\n" \
6983d36053cSMichael Gmelin	  sh -c "ifconfig ${bridge} | grep member: | wc -l | xargs"
6993d36053cSMichael Gmelin}
7003d36053cSMichael Gmelin
7013d36053cSMichael Gmelinmany_bridge_members_cleanup()
7023d36053cSMichael Gmelin{
7033d36053cSMichael Gmelin	vnet_cleanup
7043d36053cSMichael Gmelin}
7053d36053cSMichael Gmelin
7060a1294f6SLexi Winteratf_test_case "member_ifaddrs_enabled" "cleanup"
7070a1294f6SLexi Wintermember_ifaddrs_enabled_head()
7080a1294f6SLexi Winter{
7090a1294f6SLexi Winter	atf_set descr 'bridge with member_ifaddrs=1'
7100a1294f6SLexi Winter	atf_set require.user root
7110a1294f6SLexi Winter}
7120a1294f6SLexi Winter
7130a1294f6SLexi Wintermember_ifaddrs_enabled_body()
7140a1294f6SLexi Winter{
7150a1294f6SLexi Winter	vnet_init
7160a1294f6SLexi Winter	vnet_init_bridge
7170a1294f6SLexi Winter
7180a1294f6SLexi Winter	ep=$(vnet_mkepair)
7190a1294f6SLexi Winter	ifconfig ${ep}a inet 192.0.2.1/24 up
7200a1294f6SLexi Winter
7210a1294f6SLexi Winter	vnet_mkjail one ${ep}b
7220a1294f6SLexi Winter	jexec one sysctl net.link.bridge.member_ifaddrs=1
7230a1294f6SLexi Winter	jexec one ifconfig ${ep}b inet 192.0.2.2/24 up
7240a1294f6SLexi Winter	jexec one ifconfig bridge0 create addm ${ep}b
7250a1294f6SLexi Winter
7260a1294f6SLexi Winter	atf_check -s exit:0 -o ignore ping -c3 -t1 192.0.2.2
7270a1294f6SLexi Winter}
7280a1294f6SLexi Winter
7290a1294f6SLexi Wintermember_ifaddrs_enabled_cleanup()
7300a1294f6SLexi Winter{
7310a1294f6SLexi Winter	vnet_cleanup
7320a1294f6SLexi Winter}
7330a1294f6SLexi Winter
7340a1294f6SLexi Winteratf_test_case "member_ifaddrs_disabled" "cleanup"
7350a1294f6SLexi Wintermember_ifaddrs_disabled_head()
7360a1294f6SLexi Winter{
7370a1294f6SLexi Winter	atf_set descr 'bridge with member_ifaddrs=0'
7380a1294f6SLexi Winter	atf_set require.user root
7390a1294f6SLexi Winter}
7400a1294f6SLexi Winter
7410a1294f6SLexi Wintermember_ifaddrs_disabled_body()
7420a1294f6SLexi Winter{
7430a1294f6SLexi Winter	vnet_init
7440a1294f6SLexi Winter	vnet_init_bridge
7450a1294f6SLexi Winter
7460a1294f6SLexi Winter	vnet_mkjail one
7470a1294f6SLexi Winter	jexec one sysctl net.link.bridge.member_ifaddrs=0
7480a1294f6SLexi Winter
7490a1294f6SLexi Winter	bridge=$(jexec one ifconfig bridge create)
7500a1294f6SLexi Winter
7510a1294f6SLexi Winter	# adding an interface with an IPv4 address
7520a1294f6SLexi Winter	ep=$(jexec one ifconfig epair create)
7530a1294f6SLexi Winter	jexec one ifconfig ${ep} 192.0.2.1/32
7540a1294f6SLexi Winter	atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
7550a1294f6SLexi Winter
7560a1294f6SLexi Winter	# adding an interface with an IPv6 address
7570a1294f6SLexi Winter	ep=$(jexec one ifconfig epair create)
7580a1294f6SLexi Winter	jexec one ifconfig ${ep} inet6 2001:db8::1/128
7590a1294f6SLexi Winter	atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
7600a1294f6SLexi Winter
7610a1294f6SLexi Winter	# adding an interface with an IPv6 link-local address
7620a1294f6SLexi Winter	ep=$(jexec one ifconfig epair create)
7630a1294f6SLexi Winter	jexec one ifconfig ${ep} inet6 -ifdisabled auto_linklocal up
7640a1294f6SLexi Winter	atf_check -s exit:1 -e ignore jexec one ifconfig ${bridge} addm ${ep}
7650a1294f6SLexi Winter
7660a1294f6SLexi Winter	# adding an IPv4 address to a member
7670a1294f6SLexi Winter	ep=$(jexec one ifconfig epair create)
7680a1294f6SLexi Winter	jexec one ifconfig ${bridge} addm ${ep}
7690a1294f6SLexi Winter	atf_check -s exit:1 -e ignore jexec one ifconfig ${ep} inet 192.0.2.2/32
7700a1294f6SLexi Winter
7710a1294f6SLexi Winter	# adding an IPv6 address to a member
7720a1294f6SLexi Winter	ep=$(jexec one ifconfig epair create)
7730a1294f6SLexi Winter	jexec one ifconfig ${bridge} addm ${ep}
7740a1294f6SLexi Winter	atf_check -s exit:1 -e ignore jexec one ifconfig ${ep} inet6 2001:db8::1/128
7750a1294f6SLexi Winter}
7760a1294f6SLexi Winter
7770a1294f6SLexi Wintermember_ifaddrs_disabled_cleanup()
7780a1294f6SLexi Winter{
7790a1294f6SLexi Winter	vnet_cleanup
7800a1294f6SLexi Winter}
7810a1294f6SLexi Winter
782a5fe142eSLexi Winter#
783a5fe142eSLexi Winter# Test kern/287150: when member_ifaddrs=0, and a physical interface which is in
784a5fe142eSLexi Winter# a bridge also has a vlan(4) on it, tagged packets are not correctly passed to
785a5fe142eSLexi Winter# vlan(4).
786a5fe142eSLexi Winteratf_test_case "member_ifaddrs_vlan" "cleanup"
787a5fe142eSLexi Wintermember_ifaddrs_vlan_head()
788a5fe142eSLexi Winter{
789a5fe142eSLexi Winter	atf_set descr 'kern/287150: vlan and bridge on the same interface'
790a5fe142eSLexi Winter	atf_set require.user root
791a5fe142eSLexi Winter}
792a5fe142eSLexi Winter
793a5fe142eSLexi Wintermember_ifaddrs_vlan_body()
794a5fe142eSLexi Winter{
795a5fe142eSLexi Winter	vnet_init
796a5fe142eSLexi Winter	vnet_init_bridge
797a5fe142eSLexi Winter
798a5fe142eSLexi Winter	epone=$(vnet_mkepair)
799a5fe142eSLexi Winter	eptwo=$(vnet_mkepair)
800a5fe142eSLexi Winter
801a5fe142eSLexi Winter	# The first jail has an epair with an IP address on vlan 20.
802a5fe142eSLexi Winter	vnet_mkjail one ${epone}a
803a5fe142eSLexi Winter	atf_check -s exit:0 jexec one ifconfig ${epone}a up
804a5fe142eSLexi Winter	atf_check -s exit:0 jexec one \
805a5fe142eSLexi Winter	    ifconfig ${epone}a.20 create inet 192.0.2.1/24 up
806a5fe142eSLexi Winter
807a5fe142eSLexi Winter	# The second jail has an epair with an IP address on vlan 20,
808a5fe142eSLexi Winter	# which is also in a bridge.
809a5fe142eSLexi Winter	vnet_mkjail two ${epone}b
810a5fe142eSLexi Winter
811a5fe142eSLexi Winter	jexec two ifconfig
812a5fe142eSLexi Winter	atf_check -s exit:0 -o save:bridge jexec two ifconfig bridge create
813a5fe142eSLexi Winter	bridge=$(cat bridge)
814a5fe142eSLexi Winter	atf_check -s exit:0 jexec two ifconfig ${bridge} addm ${epone}b up
815a5fe142eSLexi Winter
816a5fe142eSLexi Winter	atf_check -s exit:0 -o ignore jexec two \
817a5fe142eSLexi Winter	    sysctl net.link.bridge.member_ifaddrs=0
818a5fe142eSLexi Winter	atf_check -s exit:0 jexec two ifconfig ${epone}b up
819a5fe142eSLexi Winter	atf_check -s exit:0 jexec two \
820a5fe142eSLexi Winter	    ifconfig ${epone}b.20 create inet 192.0.2.2/24 up
821a5fe142eSLexi Winter
822a5fe142eSLexi Winter	# Make sure the two jails can communicate over the vlan.
823a5fe142eSLexi Winter	atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
824a5fe142eSLexi Winter	atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
825a5fe142eSLexi Winter}
826a5fe142eSLexi Winter
827a5fe142eSLexi Wintermember_ifaddrs_vlan_cleanup()
828a5fe142eSLexi Winter{
829a5fe142eSLexi Winter	vnet_cleanup
830a5fe142eSLexi Winter}
831a5fe142eSLexi Winter
83265ed1a03SLexi Winteratf_test_case "vlan_pvid" "cleanup"
83365ed1a03SLexi Wintervlan_pvid_head()
83465ed1a03SLexi Winter{
83565ed1a03SLexi Winter	atf_set descr 'bridge with two ports with pvid set'
83665ed1a03SLexi Winter	atf_set require.user root
83765ed1a03SLexi Winter}
83865ed1a03SLexi Winter
83965ed1a03SLexi Wintervlan_pvid_body()
84065ed1a03SLexi Winter{
84165ed1a03SLexi Winter	vnet_init
84265ed1a03SLexi Winter	vnet_init_bridge
84365ed1a03SLexi Winter
84465ed1a03SLexi Winter	epone=$(vnet_mkepair)
84565ed1a03SLexi Winter	eptwo=$(vnet_mkepair)
84665ed1a03SLexi Winter
84765ed1a03SLexi Winter	vnet_mkjail one ${epone}b
84865ed1a03SLexi Winter	vnet_mkjail two ${eptwo}b
84965ed1a03SLexi Winter
85065ed1a03SLexi Winter	jexec one ifconfig ${epone}b 192.0.2.1/24 up
85165ed1a03SLexi Winter	jexec two ifconfig ${eptwo}b 192.0.2.2/24 up
85265ed1a03SLexi Winter
85365ed1a03SLexi Winter	bridge=$(vnet_mkbridge)
85465ed1a03SLexi Winter
85565ed1a03SLexi Winter	ifconfig ${bridge} up
85665ed1a03SLexi Winter	ifconfig ${epone}a up
85765ed1a03SLexi Winter	ifconfig ${eptwo}a up
85865ed1a03SLexi Winter	ifconfig ${bridge} addm ${epone}a untagged ${epone}a 20
85965ed1a03SLexi Winter	ifconfig ${bridge} addm ${eptwo}a untagged ${eptwo}a 20
86065ed1a03SLexi Winter
86165ed1a03SLexi Winter	# With VLAN filtering enabled, traffic should be passed.
86265ed1a03SLexi Winter	atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
86365ed1a03SLexi Winter	atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
86465ed1a03SLexi Winter
86565ed1a03SLexi Winter	# Removed the untagged VLAN on one port; traffic should not be passed.
86665ed1a03SLexi Winter	ifconfig ${bridge} -untagged ${epone}a
86765ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
86865ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
86965ed1a03SLexi Winter}
87065ed1a03SLexi Winter
87165ed1a03SLexi Wintervlan_pvid_cleanup()
87265ed1a03SLexi Winter{
87365ed1a03SLexi Winter	vnet_cleanup
87465ed1a03SLexi Winter}
87565ed1a03SLexi Winter
87665ed1a03SLexi Winteratf_test_case "vlan_pvid_filtered" "cleanup"
87765ed1a03SLexi Wintervlan_pvid_filtered_head()
87865ed1a03SLexi Winter{
87965ed1a03SLexi Winter	atf_set descr 'bridge with two ports with different pvids'
88065ed1a03SLexi Winter	atf_set require.user root
88165ed1a03SLexi Winter}
88265ed1a03SLexi Winter
88365ed1a03SLexi Wintervlan_pvid_filtered_body()
88465ed1a03SLexi Winter{
88565ed1a03SLexi Winter	vnet_init
88665ed1a03SLexi Winter	vnet_init_bridge
88765ed1a03SLexi Winter
88865ed1a03SLexi Winter	epone=$(vnet_mkepair)
88965ed1a03SLexi Winter	eptwo=$(vnet_mkepair)
89065ed1a03SLexi Winter
89165ed1a03SLexi Winter	vnet_mkjail one ${epone}b
89265ed1a03SLexi Winter	vnet_mkjail two ${eptwo}b
89365ed1a03SLexi Winter
89465ed1a03SLexi Winter	jexec one ifconfig ${epone}b 192.0.2.1/24 up
89565ed1a03SLexi Winter	jexec two ifconfig ${eptwo}b 192.0.2.2/24 up
89665ed1a03SLexi Winter
89765ed1a03SLexi Winter	bridge=$(vnet_mkbridge)
89865ed1a03SLexi Winter
89965ed1a03SLexi Winter	ifconfig ${bridge} up
90065ed1a03SLexi Winter	ifconfig ${epone}a up
90165ed1a03SLexi Winter	ifconfig ${eptwo}a up
90265ed1a03SLexi Winter	ifconfig ${bridge} addm ${epone}a untagged ${epone}a 20
90365ed1a03SLexi Winter	ifconfig ${bridge} addm ${eptwo}a untagged ${eptwo}a 30
90465ed1a03SLexi Winter
90565ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
90665ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
90765ed1a03SLexi Winter}
90865ed1a03SLexi Winter
90965ed1a03SLexi Wintervlan_pvid_filtered_cleanup()
91065ed1a03SLexi Winter{
91165ed1a03SLexi Winter	vnet_cleanup
91265ed1a03SLexi Winter}
91365ed1a03SLexi Winter
91465ed1a03SLexi Winteratf_test_case "vlan_pvid_tagged" "cleanup"
91565ed1a03SLexi Wintervlan_pvid_tagged_head()
91665ed1a03SLexi Winter{
91765ed1a03SLexi Winter	atf_set descr 'bridge pvid with tagged frames for pvid'
91865ed1a03SLexi Winter	atf_set require.user root
91965ed1a03SLexi Winter}
92065ed1a03SLexi Winter
92165ed1a03SLexi Wintervlan_pvid_tagged_body()
92265ed1a03SLexi Winter{
92365ed1a03SLexi Winter	vnet_init
92465ed1a03SLexi Winter	vnet_init_bridge
92565ed1a03SLexi Winter
92665ed1a03SLexi Winter	epone=$(vnet_mkepair)
92765ed1a03SLexi Winter	eptwo=$(vnet_mkepair)
92865ed1a03SLexi Winter
92965ed1a03SLexi Winter	vnet_mkjail one ${epone}b
93065ed1a03SLexi Winter	vnet_mkjail two ${eptwo}b
93165ed1a03SLexi Winter
93265ed1a03SLexi Winter	# Create two tagged interfaces on the appropriate VLANs
93365ed1a03SLexi Winter	jexec one ifconfig ${epone}b up
93465ed1a03SLexi Winter	jexec one ifconfig ${epone}b.20 create 192.0.2.1/24 up
93565ed1a03SLexi Winter	jexec two ifconfig ${eptwo}b up
93665ed1a03SLexi Winter	jexec two ifconfig ${eptwo}b.20 create 192.0.2.2/24 up
93765ed1a03SLexi Winter
93865ed1a03SLexi Winter	bridge=$(vnet_mkbridge)
93965ed1a03SLexi Winter
94065ed1a03SLexi Winter	ifconfig ${bridge} up
94165ed1a03SLexi Winter	ifconfig ${epone}a up
94265ed1a03SLexi Winter	ifconfig ${eptwo}a up
94365ed1a03SLexi Winter	ifconfig ${bridge} addm ${epone}a untagged ${epone}a 20
94465ed1a03SLexi Winter	ifconfig ${bridge} addm ${eptwo}a untagged ${eptwo}a 20
94565ed1a03SLexi Winter
94665ed1a03SLexi Winter	# Tagged frames should not be passed.
94765ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
94865ed1a03SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
94965ed1a03SLexi Winter}
95065ed1a03SLexi Winter
95165ed1a03SLexi Wintervlan_pvid_tagged_cleanup()
95265ed1a03SLexi Winter{
95365ed1a03SLexi Winter	vnet_cleanup
95465ed1a03SLexi Winter}
955877a7a32SLexi Winter
956877a7a32SLexi Winteratf_test_case "vlan_pvid_1q" "cleanup"
957877a7a32SLexi Wintervlan_pvid_1q_head()
958877a7a32SLexi Winter{
959877a7a32SLexi Winter	atf_set descr '802.1q tag addition and removal'
960877a7a32SLexi Winter	atf_set require.user root
961877a7a32SLexi Winter}
962877a7a32SLexi Winter
963877a7a32SLexi Wintervlan_pvid_1q_body()
964877a7a32SLexi Winter{
965877a7a32SLexi Winter	vnet_init
966877a7a32SLexi Winter	vnet_init_bridge
967877a7a32SLexi Winter
968877a7a32SLexi Winter	epone=$(vnet_mkepair)
969877a7a32SLexi Winter	eptwo=$(vnet_mkepair)
970877a7a32SLexi Winter
971877a7a32SLexi Winter	vnet_mkjail one ${epone}b
972877a7a32SLexi Winter	vnet_mkjail two ${eptwo}b
973877a7a32SLexi Winter
974877a7a32SLexi Winter	# Set up one jail with an access port, and the other with a trunk port.
975877a7a32SLexi Winter	# This forces the bridge to add and remove .1q tags to bridge the
976877a7a32SLexi Winter	# traffic.
977877a7a32SLexi Winter
978877a7a32SLexi Winter	jexec one ifconfig ${epone}b 192.0.2.1/24 up
979877a7a32SLexi Winter	jexec two ifconfig ${eptwo}b up
980877a7a32SLexi Winter	jexec two ifconfig ${eptwo}b.20 create 192.0.2.2/24 up
981877a7a32SLexi Winter
982877a7a32SLexi Winter	bridge=$(vnet_mkbridge)
983877a7a32SLexi Winter
984877a7a32SLexi Winter	ifconfig ${bridge} addm ${epone}a untagged ${epone}a 20
985877a7a32SLexi Winter	ifconfig ${bridge} addm ${eptwo}a
986877a7a32SLexi Winter
987877a7a32SLexi Winter	ifconfig ${bridge} up
988877a7a32SLexi Winter	ifconfig ${epone}a up
989877a7a32SLexi Winter	ifconfig ${eptwo}a up
990877a7a32SLexi Winter
991877a7a32SLexi Winter	atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
992877a7a32SLexi Winter	atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
993877a7a32SLexi Winter}
994877a7a32SLexi Winter
995877a7a32SLexi Wintervlan_pvid_1q_cleanup()
996877a7a32SLexi Winter{
997877a7a32SLexi Winter       vnet_cleanup
998877a7a32SLexi Winter}
999877a7a32SLexi Winter
1000032d32c2SLexi Winter#
1001032d32c2SLexi Winter# Test vlan filtering.
1002032d32c2SLexi Winter#
1003032d32c2SLexi Winteratf_test_case "vlan_filtering" "cleanup"
1004032d32c2SLexi Wintervlan_filtering_head()
1005032d32c2SLexi Winter{
1006032d32c2SLexi Winter	atf_set descr 'tagged traffic with filtering'
1007032d32c2SLexi Winter	atf_set require.user root
1008032d32c2SLexi Winter}
1009032d32c2SLexi Winter
1010032d32c2SLexi Wintervlan_filtering_body()
1011032d32c2SLexi Winter{
1012032d32c2SLexi Winter	vnet_init
1013032d32c2SLexi Winter	vnet_init_bridge
1014032d32c2SLexi Winter
1015032d32c2SLexi Winter	epone=$(vnet_mkepair)
1016032d32c2SLexi Winter	eptwo=$(vnet_mkepair)
1017032d32c2SLexi Winter
1018032d32c2SLexi Winter	vnet_mkjail one ${epone}b
1019032d32c2SLexi Winter	vnet_mkjail two ${eptwo}b
1020032d32c2SLexi Winter
1021032d32c2SLexi Winter	jexec one ifconfig ${epone}b up
1022032d32c2SLexi Winter	jexec one ifconfig ${epone}b.20 create 192.0.2.1/24 up
1023032d32c2SLexi Winter	jexec two ifconfig ${eptwo}b up
1024032d32c2SLexi Winter	jexec two ifconfig ${eptwo}b.20 create 192.0.2.2/24 up
1025032d32c2SLexi Winter
1026032d32c2SLexi Winter	bridge=$(vnet_mkbridge)
1027032d32c2SLexi Winter
1028032d32c2SLexi Winter	ifconfig ${bridge} up
1029032d32c2SLexi Winter	ifconfig ${epone}a up
1030032d32c2SLexi Winter	ifconfig ${eptwo}a up
1031032d32c2SLexi Winter	ifconfig ${bridge} addm ${epone}a vlanfilter ${epone}a
1032032d32c2SLexi Winter	ifconfig ${bridge} addm ${eptwo}a vlanfilter ${eptwo}a
1033032d32c2SLexi Winter
1034032d32c2SLexi Winter	# Right now there are no VLANs on the access list, so everything
1035032d32c2SLexi Winter	# should be blocked.
1036032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1037032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1038032d32c2SLexi Winter
1039032d32c2SLexi Winter	# Set the untagged vlan on both ports to 20 and make sure traffic is
1040032d32c2SLexi Winter	# still blocked.  We intentionally do not pass tagged traffic for the
1041032d32c2SLexi Winter	# untagged vlan.
1042032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} untagged ${epone}a 20
1043032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} untagged ${eptwo}a 20
1044032d32c2SLexi Winter
1045032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1046032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1047032d32c2SLexi Winter
1048032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} -untagged ${epone}a
1049032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} -untagged ${eptwo}a
1050032d32c2SLexi Winter
1051032d32c2SLexi Winter	# Add VLANs 10-30 to the access list; now access should be allowed.
1052032d32c2SLexi Winter	ifconfig ${bridge} +tagged ${epone}a 10-30
1053032d32c2SLexi Winter	ifconfig ${bridge} +tagged ${eptwo}a 10-30
1054032d32c2SLexi Winter	atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1055032d32c2SLexi Winter	atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1056032d32c2SLexi Winter
1057032d32c2SLexi Winter	# Remove vlan 20 from the access list, now access should be blocked
1058032d32c2SLexi Winter	# again.
1059032d32c2SLexi Winter	ifconfig ${bridge} -tagged ${epone}a 20
1060032d32c2SLexi Winter	ifconfig ${bridge} -tagged ${eptwo}a 20
1061032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1062032d32c2SLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1063032d32c2SLexi Winter}
1064032d32c2SLexi Winter
1065032d32c2SLexi Wintervlan_filtering_cleanup()
1066032d32c2SLexi Winter{
1067032d32c2SLexi Winter	vnet_cleanup
1068032d32c2SLexi Winter}
1069032d32c2SLexi Winter
1070032d32c2SLexi Winter#
1071032d32c2SLexi Winter# Test the ifconfig 'tagged' option.
1072032d32c2SLexi Winter#
1073032d32c2SLexi Winteratf_test_case "vlan_ifconfig_tagged" "cleanup"
1074032d32c2SLexi Wintervlan_ifconfig_tagged_head()
1075032d32c2SLexi Winter{
1076032d32c2SLexi Winter	atf_set descr 'test the ifconfig tagged option'
1077032d32c2SLexi Winter	atf_set require.user root
1078032d32c2SLexi Winter}
1079032d32c2SLexi Winter
1080032d32c2SLexi Wintervlan_ifconfig_tagged_body()
1081032d32c2SLexi Winter{
1082032d32c2SLexi Winter	vnet_init
1083032d32c2SLexi Winter	vnet_init_bridge
1084032d32c2SLexi Winter
1085032d32c2SLexi Winter	ep=$(vnet_mkepair)
1086032d32c2SLexi Winter	bridge=$(vnet_mkbridge)
1087032d32c2SLexi Winter
1088032d32c2SLexi Winter	ifconfig ${bridge} addm ${ep}a vlanfilter ${ep}a up
1089032d32c2SLexi Winter	ifconfig ${ep}a up
1090032d32c2SLexi Winter
1091032d32c2SLexi Winter	# To start with, no vlans should be configured.
1092032d32c2SLexi Winter	atf_check -s exit:0 -o not-match:"tagged" ifconfig ${bridge}
1093032d32c2SLexi Winter
1094032d32c2SLexi Winter	# Add vlans 100-149.
1095032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} tagged ${ep}a 100-149
1096032d32c2SLexi Winter	atf_check -s exit:0 -o match:"tagged 100-149" ifconfig ${bridge}
1097032d32c2SLexi Winter
1098032d32c2SLexi Winter	# Replace the vlan list with 139-199.
1099032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} tagged ${ep}a 139-199
1100032d32c2SLexi Winter	atf_check -s exit:0 -o match:"tagged 139-199" ifconfig ${bridge}
1101032d32c2SLexi Winter
1102032d32c2SLexi Winter	# Add vlans 100-170.
1103032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} +tagged ${ep}a 100-170
1104032d32c2SLexi Winter	atf_check -s exit:0 -o match:"tagged 100-199" ifconfig ${bridge}
1105032d32c2SLexi Winter
1106032d32c2SLexi Winter	# Remove vlans 104, 105, and 150-159
1107032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} -tagged ${ep}a 104,105,150-159
1108032d32c2SLexi Winter	atf_check -s exit:0 -o match:"tagged 100-103,106-149,160-199" \
1109032d32c2SLexi Winter	    ifconfig ${bridge}
1110032d32c2SLexi Winter
1111032d32c2SLexi Winter	# Remove the entire vlan list.
1112032d32c2SLexi Winter	atf_check -s exit:0 ifconfig ${bridge} tagged ${ep}a none
1113032d32c2SLexi Winter	atf_check -s exit:0 -o not-match:"tagged" ifconfig ${bridge}
1114032d32c2SLexi Winter
1115032d32c2SLexi Winter	# Test some invalid vlans sets.
1116032d32c2SLexi Winter	for bad_vlan in -1 0 4096 4097 foo 0-10 4000-5000 foo-40 40-foo; do
1117032d32c2SLexi Winter		atf_check -s exit:1 -e ignore \
1118032d32c2SLexi Winter		    ifconfig ${bridge} tagged "$bad_vlan"
1119032d32c2SLexi Winter	done
1120032d32c2SLexi Winter}
1121032d32c2SLexi Winter
1122032d32c2SLexi Wintervlan_ifconfig_tagged_cleanup()
1123032d32c2SLexi Winter{
1124032d32c2SLexi Winter	vnet_cleanup
1125032d32c2SLexi Winter}
1126032d32c2SLexi Winter
112795e7d47aSLexi Winter#
112895e7d47aSLexi Winter# Test a vlan(4) "SVI" interface on top of a bridge.
112995e7d47aSLexi Winter#
113095e7d47aSLexi Winteratf_test_case "vlan_svi" "cleanup"
113195e7d47aSLexi Wintervlan_svi_head()
113295e7d47aSLexi Winter{
113395e7d47aSLexi Winter	atf_set descr 'vlan bridge with an SVI'
113495e7d47aSLexi Winter	atf_set require.user root
113595e7d47aSLexi Winter}
113695e7d47aSLexi Winter
113795e7d47aSLexi Wintervlan_svi_body()
113895e7d47aSLexi Winter{
113995e7d47aSLexi Winter	vnet_init
114095e7d47aSLexi Winter	vnet_init_bridge
114195e7d47aSLexi Winter
114295e7d47aSLexi Winter	epone=$(vnet_mkepair)
114395e7d47aSLexi Winter
114495e7d47aSLexi Winter	vnet_mkjail one ${epone}b
114595e7d47aSLexi Winter
114695e7d47aSLexi Winter	jexec one ifconfig ${epone}b up
114795e7d47aSLexi Winter	jexec one ifconfig ${epone}b.20 create 192.0.2.1/24 up
114895e7d47aSLexi Winter
114995e7d47aSLexi Winter	bridge=$(vnet_mkbridge)
115095e7d47aSLexi Winter
115195e7d47aSLexi Winter	ifconfig ${bridge} up
115295e7d47aSLexi Winter	ifconfig ${epone}a up
115395e7d47aSLexi Winter	ifconfig ${bridge} addm ${epone}a tagged ${epone}a 20
115495e7d47aSLexi Winter
115595e7d47aSLexi Winter	svi=$(vnet_mkvlan)
115695e7d47aSLexi Winter	ifconfig ${svi} vlan 20 vlandev ${bridge}
115795e7d47aSLexi Winter	ifconfig ${svi} inet 192.0.2.2/24 up
115895e7d47aSLexi Winter
115995e7d47aSLexi Winter	atf_check -s exit:0 -o ignore ping -c 3 -t 1 192.0.2.1
116095e7d47aSLexi Winter}
116195e7d47aSLexi Winter
116295e7d47aSLexi Wintervlan_svi_cleanup()
116395e7d47aSLexi Winter{
116495e7d47aSLexi Winter	vnet_cleanup
116595e7d47aSLexi Winter}
116695e7d47aSLexi Winter
1167*c5f5d0cfSLexi Winter#
1168*c5f5d0cfSLexi Winter# Test QinQ (802.1ad).
1169*c5f5d0cfSLexi Winter#
1170*c5f5d0cfSLexi Winteratf_test_case "vlan_qinq" "cleanup"
1171*c5f5d0cfSLexi Wintervlan_qinq_head()
1172*c5f5d0cfSLexi Winter{
1173*c5f5d0cfSLexi Winter	atf_set descr 'vlan filtering with QinQ traffic'
1174*c5f5d0cfSLexi Winter	atf_set require.user root
1175*c5f5d0cfSLexi Winter}
1176*c5f5d0cfSLexi Winter
1177*c5f5d0cfSLexi Wintervlan_qinq_body()
1178*c5f5d0cfSLexi Winter{
1179*c5f5d0cfSLexi Winter	vnet_init
1180*c5f5d0cfSLexi Winter	vnet_init_bridge
1181*c5f5d0cfSLexi Winter
1182*c5f5d0cfSLexi Winter	epone=$(vnet_mkepair)
1183*c5f5d0cfSLexi Winter	eptwo=$(vnet_mkepair)
1184*c5f5d0cfSLexi Winter
1185*c5f5d0cfSLexi Winter	vnet_mkjail one ${epone}b
1186*c5f5d0cfSLexi Winter	vnet_mkjail two ${eptwo}b
1187*c5f5d0cfSLexi Winter
1188*c5f5d0cfSLexi Winter	# Create a QinQ trunk between the two jails.  The outer (provider) tag
1189*c5f5d0cfSLexi Winter	# is 5, and the inner tag is 10.
1190*c5f5d0cfSLexi Winter
1191*c5f5d0cfSLexi Winter	jexec one ifconfig ${epone}b up
1192*c5f5d0cfSLexi Winter	jexec one ifconfig ${epone}b.5 create vlanproto 802.1ad up
1193*c5f5d0cfSLexi Winter	jexec one ifconfig ${epone}b.5.10 create inet 192.0.2.1/24 up
1194*c5f5d0cfSLexi Winter
1195*c5f5d0cfSLexi Winter	jexec two ifconfig ${eptwo}b up
1196*c5f5d0cfSLexi Winter	jexec two ifconfig ${eptwo}b.5 create vlanproto 802.1ad up
1197*c5f5d0cfSLexi Winter	jexec two ifconfig ${eptwo}b.5.10 create inet 192.0.2.2/24 up
1198*c5f5d0cfSLexi Winter
1199*c5f5d0cfSLexi Winter	bridge=$(vnet_mkbridge)
1200*c5f5d0cfSLexi Winter
1201*c5f5d0cfSLexi Winter	ifconfig ${bridge} up
1202*c5f5d0cfSLexi Winter	ifconfig ${epone}a up
1203*c5f5d0cfSLexi Winter	ifconfig ${eptwo}a up
1204*c5f5d0cfSLexi Winter	ifconfig ${bridge} addm ${epone}a vlanfilter ${epone}a
1205*c5f5d0cfSLexi Winter	ifconfig ${bridge} addm ${eptwo}a vlanfilter ${eptwo}a
1206*c5f5d0cfSLexi Winter
1207*c5f5d0cfSLexi Winter	# Right now there are no VLANs on the access list, so everything
1208*c5f5d0cfSLexi Winter	# should be blocked.
1209*c5f5d0cfSLexi Winter	atf_check -s exit:2 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1210*c5f5d0cfSLexi Winter	atf_check -s exit:2 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1211*c5f5d0cfSLexi Winter
1212*c5f5d0cfSLexi Winter	# Add the provider tag to the access list; now traffic should be passed.
1213*c5f5d0cfSLexi Winter	ifconfig ${bridge} +tagged ${epone}a 5
1214*c5f5d0cfSLexi Winter	ifconfig ${bridge} +tagged ${eptwo}a 5
1215*c5f5d0cfSLexi Winter	atf_check -s exit:0 -o ignore jexec one ping -c 3 -t 1 192.0.2.2
1216*c5f5d0cfSLexi Winter	atf_check -s exit:0 -o ignore jexec two ping -c 3 -t 1 192.0.2.1
1217*c5f5d0cfSLexi Winter}
1218*c5f5d0cfSLexi Winter
1219*c5f5d0cfSLexi Wintervlan_qinq_cleanup()
1220*c5f5d0cfSLexi Winter{
1221*c5f5d0cfSLexi Winter	vnet_cleanup
1222*c5f5d0cfSLexi Winter}
1223*c5f5d0cfSLexi Winter
1224095aabf7SKristof Provostatf_init_test_cases()
1225095aabf7SKristof Provost{
1226095aabf7SKristof Provost	atf_add_test_case "bridge_transmit_ipv4_unicast"
12276f0a65b0SKristof Provost	atf_add_test_case "stp"
122826492ba2SKristof Provost	atf_add_test_case "stp_vlan"
1229d99bb677SKristof Provost	atf_add_test_case "static"
1230bb490fcfSKristof Provost	atf_add_test_case "span"
123153775607SKristof Provost	atf_add_test_case "inherit_mac"
12323f359bfdSKristof Provost	atf_add_test_case "delete_with_members"
12332885ae0cSKristof Provost	atf_add_test_case "mac_conflict"
12344ae3a97eSKristof Provost	atf_add_test_case "stp_validation"
12354b765ab4SKristof Provost	atf_add_test_case "gif"
12366e439506SKristof Provost	atf_add_test_case "mtu"
1237f97802a3SKristof Provost	atf_add_test_case "vlan"
12383d36053cSMichael Gmelin	atf_add_test_case "many_bridge_members"
12390a1294f6SLexi Winter	atf_add_test_case "member_ifaddrs_enabled"
12400a1294f6SLexi Winter	atf_add_test_case "member_ifaddrs_disabled"
1241a5fe142eSLexi Winter	atf_add_test_case "member_ifaddrs_vlan"
124265ed1a03SLexi Winter	atf_add_test_case "vlan_pvid"
1243877a7a32SLexi Winter	atf_add_test_case "vlan_pvid_1q"
124465ed1a03SLexi Winter	atf_add_test_case "vlan_pvid_filtered"
124565ed1a03SLexi Winter	atf_add_test_case "vlan_pvid_tagged"
1246032d32c2SLexi Winter	atf_add_test_case "vlan_filtering"
1247032d32c2SLexi Winter	atf_add_test_case "vlan_ifconfig_tagged"
124895e7d47aSLexi Winter	atf_add_test_case "vlan_svi"
1249*c5f5d0cfSLexi Winter	atf_add_test_case "vlan_qinq"
1250095aabf7SKristof Provost}
1251