3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2020 The FreeBSD Foundation
7 # This software was developed by Kristof Provost under sponsorship
8 # from the FreeBSD Foundation.
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 . $(atf_get_srcdir)/../common/vnet.subr
33 atf_test_case "bridge_transmit_ipv4_unicast" "cleanup"
34 bridge_transmit_ipv4_unicast_head()
36 atf_set descr 'bridge_transmit_ipv4_unicast bridging test'
37 atf_set require.user root
40 bridge_transmit_ipv4_unicast_body()
44 epair_alcatraz=$(vnet_mkepair)
45 epair_singsing=$(vnet_mkepair)
47 vnet_mkjail alcatraz ${epair_alcatraz}b
48 vnet_mkjail singsing ${epair_singsing}b
50 jexec alcatraz ifconfig ${epair_alcatraz}b 192.0.2.1/24 up
51 jexec singsing ifconfig ${epair_singsing}b 192.0.2.2/24 up
53 bridge=$(vnet_mkbridge)
56 ifconfig ${epair_alcatraz}a up
57 ifconfig ${epair_singsing}a up
58 ifconfig ${bridge} addm ${epair_alcatraz}a
59 ifconfig ${bridge} addm ${epair_singsing}a
61 atf_check -s exit:0 -o ignore jexec alcatraz ping -c 3 -t 1 192.0.2.2
62 atf_check -s exit:0 -o ignore jexec singsing ping -c 3 -t 1 192.0.2.1
65 bridge_transmit_ipv4_unicast_cleanup()
70 atf_test_case "stp" "cleanup"
73 atf_set descr 'Spanning tree test'
74 atf_set require.user root
75 atf_set require.progs jq
82 epair_one=$(vnet_mkepair)
83 epair_two=$(vnet_mkepair)
84 bridge_a=$(vnet_mkbridge)
85 bridge_b=$(vnet_mkbridge)
87 vnet_mkjail a ${bridge_a} ${epair_one}a ${epair_two}a
88 vnet_mkjail b ${bridge_b} ${epair_one}b ${epair_two}b
90 jexec a ifconfig ${bridge_a} up
91 jexec a ifconfig ${epair_one}a up
92 jexec a ifconfig ${epair_two}a up
93 jexec a ifconfig ${bridge_a} addm ${epair_one}a
94 jexec a ifconfig ${bridge_a} addm ${epair_two}a
96 jexec b ifconfig ${bridge_b} up
97 jexec b ifconfig ${epair_one}b up
98 jexec b ifconfig ${epair_two}b up
99 jexec b ifconfig ${bridge_b} addm ${epair_one}b
100 jexec b ifconfig ${bridge_b} addm ${epair_two}b
102 jexec a ifconfig ${bridge_a} 192.0.2.1/24
104 # Give the interfaces some time to come up and pass some traffic
107 # Confirm that there's looping traffic
108 nbr=$(jexec a netstat -I ${bridge_a} --libxo json \
109 | jq ".statistics.interface[0].\"received-packets\"")
110 if [ ${nbr} -lt 100 ]
112 atf_fail "Expected bridging loop, but found very few packets."
115 # Enable spanning tree
116 jexec a ifconfig ${bridge_a} stp ${epair_one}a
117 jexec a ifconfig ${bridge_a} stp ${epair_two}a
118 jexec b ifconfig ${bridge_b} stp ${epair_one}b
119 jexec b ifconfig ${bridge_b} stp ${epair_two}b
121 # Give STP time to do its thing
124 a_discard=$(jexec a ifconfig ${bridge_a} | grep discarding)
125 b_discard=$(jexec b ifconfig ${bridge_b} | grep discarding)
127 if [ -z "${a_discard}" ] && [ -z "${b_discard}" ]
129 atf_fail "STP failed to detect bridging loop"
138 atf_test_case "static" "cleanup"
141 atf_set descr 'Bridge static address test'
142 atf_set require.user root
149 epair=$(vnet_mkepair)
150 bridge=$(vnet_mkbridge)
152 vnet_mkjail one ${bridge} ${epair}a
154 ifconfig ${epair}b up
156 jexec one ifconfig ${bridge} up
157 jexec one ifconfig ${epair}a up
158 jexec one ifconfig ${bridge} addm ${epair}a
161 atf_check -s exit:1 -o ignore -e ignore \
162 jexec one ifconfig ${bridge} static ${epair}b 00:01:02:03:04:05
165 atf_check -s exit:1 -o ignore -e ignore \
166 jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04
169 atf_check -s exit:0 -o ignore \
170 jexec one ifconfig ${bridge} static ${epair}a 00:01:02:03:04:05
173 atf_check -s exit:0 -o ignore \
174 jexec one ifconfig ${bridge} addr
176 # Delete with bad address format
177 atf_check -s exit:1 -o ignore -e ignore \
178 jexec one ifconfig ${bridge} deladdr 00:01:02:03:04
180 # Delete with unlisted address
181 atf_check -s exit:1 -o ignore -e ignore \
182 jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:06
185 atf_check -s exit:0 -o ignore \
186 jexec one ifconfig ${bridge} deladdr 00:01:02:03:04:05
194 atf_test_case "span" "cleanup"
197 atf_set descr 'Bridge span test'
198 atf_set require.user root
206 epair=$(vnet_mkepair)
207 epair_span=$(vnet_mkepair)
208 bridge=$(vnet_mkbridge)
210 vnet_mkjail one ${bridge} ${epair}a ${epair_span}a
212 ifconfig ${epair}b up
213 ifconfig ${epair_span}b up
215 jexec one ifconfig ${bridge} up
216 jexec one ifconfig ${epair}a up
217 jexec one ifconfig ${epair_span}a up
218 jexec one ifconfig ${bridge} addm ${epair}a
220 jexec one ifconfig ${bridge} span ${epair_span}a
221 jexec one ifconfig ${bridge} 192.0.2.1/24
223 # Send some traffic through the span
224 jexec one ping -c 1 -t 1 192.0.2.2
226 # Check that we see the traffic on the span interface
227 atf_check -s exit:0 \
228 $(atf_get_srcdir)/../netpfil/common/pft_ping.py \
231 --recvif ${epair_span}b
233 jexec one ifconfig ${bridge} -span ${epair_span}a
235 # And no more traffic after we remove the span
236 atf_check -s exit:1 \
237 $(atf_get_srcdir)/../netpfil/common/pft_ping.py \
240 --recvif ${epair_span}b
248 atf_test_case "delete_with_members" "cleanup"
249 delete_with_members_head()
251 atf_set descr 'Delete a bridge which still has member interfaces'
252 atf_set require.user root
255 delete_with_members_body()
259 bridge=$(vnet_mkbridge)
260 epair=$(vnet_mkepair)
262 ifconfig ${bridge} 192.0.2.1/24 up
263 ifconfig ${epair}a up
264 ifconfig ${bridge} addm ${epair}a
266 ifconfig ${bridge} destroy
269 delete_with_members_cleanup()
274 atf_init_test_cases()
276 atf_add_test_case "bridge_transmit_ipv4_unicast"
277 atf_add_test_case "stp"
278 atf_add_test_case "static"
279 atf_add_test_case "span"
280 atf_add_test_case "delete_with_members"