xref: /freebsd/share/man/man4/bridge.4 (revision 0d48d1ffe0446cd2f87ce02555e3d17772ae7284)
1.\"
2.\" SPDX-License-Identifier: BSD-4-Clause
3.\"
4.\"	$NetBSD: bridge.4,v 1.5 2004/01/31 20:14:11 jdc Exp $
5.\"
6.\" Copyright 2001 Wasabi Systems, Inc.
7.\" All rights reserved.
8.\"
9.\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. All advertising materials mentioning features or use of this software
20.\"    must display the following acknowledgement:
21.\"	This product includes software developed for the NetBSD Project by
22.\"	Wasabi Systems, Inc.
23.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
24.\"    or promote products derived from this software without specific prior
25.\"    written permission.
26.\"
27.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
31.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37.\" POSSIBILITY OF SUCH DAMAGE.
38.\"
39.Dd May 13, 2025
40.Dt IF_BRIDGE 4
41.Os
42.Sh NAME
43.Nm if_bridge
44.Nd network bridge device
45.Sh SYNOPSIS
46To compile this driver into the kernel,
47place the following line in your
48kernel configuration file:
49.Bd -ragged -offset indent
50.Cd "device if_bridge"
51.Ed
52.Pp
53Alternatively, to load the driver as a
54module at boot time, place the following lines in
55.Xr loader.conf 5 :
56.Bd -literal -offset indent
57if_bridge_load="YES"
58bridgestp_load="YES"
59.Ed
60.Sh DESCRIPTION
61The
62.Nm
63driver creates a logical link between two or more IEEE 802 networks
64that use the same (or
65.Dq "similar enough" )
66framing format.
67For example, it is possible to bridge Ethernet and 802.11 networks together,
68but it is not possible to bridge Ethernet and Token Ring together.
69.Pp
70Each
71.Nm
72interface is created at runtime using interface cloning.
73This is
74most easily done with the
75.Xr ifconfig 8
76.Cm create
77command or using the
78.Va cloned_interfaces
79variable in
80.Xr rc.conf 5 .
81.Pp
82The
83.Nm
84interface randomly chooses a link (MAC) address in the range reserved for
85locally administered addresses when it is created.
86This address is guaranteed to be unique
87.Em only
88across all
89.Nm
90interfaces on the local machine.
91Thus you can theoretically have two bridges on different machines with
92the same link addresses.
93The address can be changed by assigning the desired link address using
94.Xr ifconfig 8 .
95.Pp
96If
97.Xr sysctl 8
98node
99.Va net.link.bridge.inherit_mac
100has a non-zero value, the newly created bridge will inherit the MAC
101address from its first member instead of choosing a random link-level
102address.
103This will provide more predictable bridge MAC addresses without any
104additional configuration, but currently this feature is known to break
105some L2 protocols, for example PPPoE that is provided by
106.Xr ng_pppoe 4
107and
108.Xr ppp 8 .
109Currently this feature is considered as experimental and is turned off
110by default.
111.Pp
112A bridge can be used to provide several services, such as a simple
113802.11-to-Ethernet bridge for wireless hosts, or traffic isolation.
114.Pp
115A bridge works like a switch, forwarding traffic from one interface
116to another.
117Multicast and broadcast packets are always forwarded to all
118interfaces that are part of the bridge.
119For unicast traffic, the bridge learns which MAC addresses are associated
120with which interfaces and will forward the traffic selectively.
121.Pp
122By default the bridge logs MAC address port flapping to
123.Xr syslog 3 .
124This behavior can be disabled by setting the
125.Xr sysctl 8
126variable
127.Va net.link.bridge.log_mac_flap
128to
129.Li 0 .
130.Pp
131All the bridged member interfaces need to be up
132in order to pass network traffic.
133These can be enabled using
134.Xr ifconfig 8
135or
136.Va ifconfig_ Ns Ao Ar interface Ac Ns Li ="up"
137in
138.Xr rc.conf 5 .
139.Pp
140The MTU of the first member interface to be added is used as the bridge MTU.
141All additional members will have their MTU changed to match.
142If the MTU of a bridge is changed after its creation, the MTU of all member
143interfaces is also changed to match.
144.Pp
145The TOE, TSO, TXCSUM and TXCSUM6 capabilities on all interfaces added to the
146bridge are disabled if any of the interfaces do not support/enable them.
147The LRO capability is always disabled.
148All the capabilities are restored when the interface is removed from the bridge.
149Changing capabilities at run-time may cause NIC reinit and a link flap.
150.Pp
151The bridge supports
152.Dq monitor mode ,
153where the packets are discarded after
154.Xr bpf 4
155processing, and are not processed or forwarded further.
156This can be used to multiplex the input of two or more interfaces into a single
157.Xr bpf 4
158stream.
159This is useful for reconstructing the traffic for network taps
160that transmit the RX/TX signals out through two separate interfaces.
161.Pp
162To allow the host to communicate with bridge members, IP addresses
163should be assigned to the
164.Nm
165interface itself, not to the bridge's member interfaces.
166Attempting to assign an IP address to a bridge member interface, or add
167a member interface with an assigned IP address to a bridge, will return
168an
169.Dv EINVAL
170.Dq ( "Invalid argument" )
171error.
172For compatibility with older releases where this was permitted, setting
173the
174.Xr sysctl 8
175variable
176.Va net.link.bridge.member_ifaddrs
177to 1 will permit this configuration.
178This sysctl variable will be removed in
179.Fx 16.0.
180.Sh IPV6 SUPPORT
181.Nm
182supports the
183.Li AF_INET6
184address family on bridge interfaces.
185The following
186.Xr rc.conf 5
187variable configures an IPv6 link-local address on
188.Li bridge0
189interface:
190.Bd -literal -offset indent
191ifconfig_bridge0_ipv6="inet6 auto_linklocal"
192.Ed
193.Pp
194However, the
195.Li AF_INET6
196address family has a concept of scope zone.
197Bridging multiple interfaces changes the zone configuration because
198multiple links are merged to each other and form a new single link
199while the member interfaces still work individually.
200This means each member interface still has a separate link-local scope
201zone and the
202.Nm
203interface has another single,
204aggregated link-local scope zone at the same time.
205This situation is clearly against the description
206.Qq zones of the same scope cannot overlap
207in Section 5,
208RFC 4007.
209Although it works in most cases,
210it can cause some counterintuitive or undesirable behavior in some
211edge cases when both, the
212.Nm
213interface and one of the member interfaces, have an IPv6 address
214and applications use both of them.
215.Pp
216To prevent this situation,
217.Nm
218checks whether a link-local scoped IPv6 address is configured on
219a member interface to be added and the
220.Nm
221interface.
222When the
223.Nm
224interface has IPv6 addresses,
225IPv6 addresses on the member interface will be automatically removed
226before the interface is added.
227.Pp
228This behavior can be disabled by setting
229.Xr sysctl 8
230variable
231.Va net.link.bridge.allow_llz_overlap
232to
233.Li 1 .
234.Pp
235Note that
236.Li ACCEPT_RTADV
237and
238.Li AUTO_LINKLOCAL
239interface flags are not enabled by default on
240.Nm
241interfaces even when
242.Va net.inet6.ip6.accept_rtadv
243and/or
244.Va net.inet6.ip6.auto_linklocal
245is set to
246.Li 1 .
247.Sh SPANNING TREE
248The
249.Nm
250driver implements the Rapid Spanning Tree Protocol (RSTP or 802.1w) with
251backwards compatibility with the legacy Spanning Tree Protocol (STP).
252Spanning Tree is used to detect and remove loops in a network topology.
253.Pp
254RSTP provides faster spanning tree convergence than legacy STP, the protocol
255will exchange information with neighbouring switches to quickly transition to
256forwarding without creating loops.
257.Pp
258The code will default to RSTP mode but will downgrade any port connected to a
259legacy STP network so is fully backward compatible.
260A bridge can be forced to operate in STP mode without rapid state transitions
261via the
262.Va proto
263command in
264.Xr ifconfig 8 .
265.Pp
266The bridge can log STP port changes to
267.Xr syslog 3
268by setting the
269.Va net.link.bridge.log_stp
270node using
271.Xr sysctl 8 .
272.Sh PACKET FILTERING
273Packet filtering can be used with any firewall package that hooks in via the
274.Xr pfil 9
275framework.
276When filtering is enabled, bridged packets will pass through the filter
277inbound on the originating interface, on the bridge interface and outbound on
278the appropriate interfaces.
279Either stage can be disabled.
280The filtering behavior can be controlled using
281.Xr sysctl 8 :
282.Bl -tag -width indent
283.It Va net.link.bridge.pfil_onlyip
284Controls the handling of non-IP packets which are not passed to
285.Xr pfil 9 .
286Set to
287.Li 1
288to only allow IP packets to pass (subject to firewall rules), set to
289.Li 0
290to unconditionally pass all non-IP Ethernet frames.
291.It Va net.link.bridge.pfil_member
292Set to
293.Li 1
294to enable filtering on the incoming and outgoing member interfaces, set
295to
296.Li 0
297to disable it.
298.It Va net.link.bridge.pfil_bridge
299Set to
300.Li 1
301to enable filtering on the bridge interface, set
302to
303.Li 0
304to disable it.
305.It Va net.link.bridge.pfil_local_phys
306Set to
307.Li 1
308to additionally filter on the physical interface for locally destined packets.
309Set to
310.Li 0
311to disable this feature.
312.It Va net.link.bridge.ipfw
313Set to
314.Li 1
315to enable layer2 filtering with
316.Xr ipfirewall 4 ,
317set to
318.Li 0
319to disable it.
320This needs to be enabled for
321.Xr dummynet 4
322support.
323When
324.Va ipfw
325is enabled,
326.Va pfil_bridge
327and
328.Va pfil_member
329will be disabled so that IPFW
330is not run twice; these can be re-enabled if desired.
331.It Va net.link.bridge.ipfw_arp
332Set to
333.Li 1
334to enable layer2 ARP filtering with
335.Xr ipfirewall 4 ,
336set to
337.Li 0
338to disable it.
339Requires
340.Va ipfw
341to be enabled.
342.El
343.Pp
344ARP and REVARP packets are forwarded without being filtered and others
345that are not IP nor IPv6 packets are not forwarded when
346.Va pfil_onlyip
347is enabled.
348IPFW can filter Ethernet types using
349.Cm mac-type
350so all packets are passed to
351the filter for processing.
352.Pp
353The packets originating from the bridging host will be seen by
354the filter on the interface that is looked up in the routing
355table.
356.Pp
357The packets destined to the bridging host will be seen by the filter
358on the interface with the MAC address equal to the packet's destination
359MAC.
360There are situations when some of the bridge members are sharing
361the same MAC address (for example the
362.Xr vlan 4
363interfaces: they are currently sharing the
364MAC address of the parent physical interface).
365It is not possible to distinguish between these interfaces using
366their MAC address, excluding the case when the packet's destination
367MAC address is equal to the MAC address of the interface on which
368the packet was entered to the system.
369In this case the filter will see the incoming packet on this
370interface.
371In all other cases the interface seen by the packet filter is chosen
372from the list of bridge members with the same MAC address and the
373result strongly depends on the member addition sequence and the
374actual implementation of
375.Nm .
376It is not recommended to rely on the order chosen by the current
377.Nm
378implementation since it may change in the future.
379.Pp
380The previous paragraph is best illustrated with the following
381pictures.
382Let
383.Bl -bullet
384.It
385the MAC address of the incoming packet's destination is
386.Nm nn:nn:nn:nn:nn:nn ,
387.It
388the interface on which packet entered the system is
389.Nm ifX ,
390.It
391.Nm ifX
392MAC address is
393.Nm xx:xx:xx:xx:xx:xx ,
394.It
395there are possibly other bridge members with the same MAC address
396.Nm xx:xx:xx:xx:xx:xx ,
397.It
398the bridge has more than one interface that are sharing the
399same MAC address
400.Nm yy:yy:yy:yy:yy:yy ;
401we will call them
402.Nm vlanY1 ,
403.Nm vlanY2 ,
404etc.
405.El
406.Pp
407If the MAC address
408.Nm nn:nn:nn:nn:nn:nn
409is equal to
410.Nm xx:xx:xx:xx:xx:xx
411the filter will see the packet on interface
412.Nm ifX
413no matter if there are any other bridge members carrying the same
414MAC address.
415But if the MAC address
416.Nm nn:nn:nn:nn:nn:nn
417is equal to
418.Nm yy:yy:yy:yy:yy:yy
419then the interface that will be seen by the filter is one of the
420.Nm vlanYn .
421It is not possible to predict the name of the actual interface
422without the knowledge of the system state and the
423.Nm
424implementation details.
425.Pp
426This problem arises for any bridge members that are sharing the same
427MAC address, not only to the
428.Xr vlan 4
429ones: they were taken just as an example of such a situation.
430So if one wants to filter the locally destined packets based on
431their interface name, one should be aware of this implication.
432The described situation will appear at least on the filtering bridges
433that are doing IP-forwarding; in some of such cases it is better
434to assign the IP address only to the
435.Nm
436interface and not to the bridge members.
437Enabling
438.Va net.link.bridge.pfil_local_phys
439will let you do the additional filtering on the physical interface.
440.Sh NETMAP
441.Xr netmap 4
442applications may open a bridge interface in emulated mode.
443The netmap application will receive all packets which arrive from member
444interfaces.
445In particular, packets which would otherwise be forwarded to another
446member interface will be received by the netmap application.
447.Pp
448When the
449.Xr netmap 4
450application transmits a packet to the host stack via the bridge interface,
451.Nm
452receive it and attempts to determine its
453.Ql source
454interface by looking up the source MAC address in the interface's learning
455tables.
456Packets for which no matching source interface is found are dropped and the
457input error counter is incremented.
458If a matching source interface is found,
459.Nm
460treats the packet as though it was received from the corresponding interface
461and handles it normally without passing the packet back to
462.Xr netmap 4 .
463.Sh EXAMPLES
464The following when placed in the file
465.Pa /etc/rc.conf
466will cause a bridge called
467.Dq Li bridge0
468to be created, and will add the interfaces
469.Dq Li wlan0
470and
471.Dq Li fxp0
472to the bridge, and then enable packet forwarding.
473Such a configuration could be used to implement a simple
474802.11-to-Ethernet bridge (assuming the 802.11 interface is
475in ad-hoc mode).
476.Bd -literal -offset indent
477cloned_interfaces="bridge0"
478ifconfig_bridge0="addm wlan0 addm fxp0 up"
479.Ed
480.Pp
481For the bridge to forward packets,
482all member interfaces and the bridge need to be up.
483The above example would also require:
484.Bd -literal -offset indent
485create_args_wlan0="wlanmode hostap"
486ifconfig_wlan0="up ssid my_ap mode 11g"
487ifconfig_fxp0="up"
488.Ed
489.Pp
490Consider a system with two 4-port Ethernet boards.
491The following will cause a bridge consisting of all 8 ports with
492Rapid Spanning Tree enabled to be created:
493.Bd -literal -offset indent
494ifconfig bridge0 create
495ifconfig bridge0 \e
496    addm fxp0 stp fxp0 \e
497    addm fxp1 stp fxp1 \e
498    addm fxp2 stp fxp2 \e
499    addm fxp3 stp fxp3 \e
500    addm fxp4 stp fxp4 \e
501    addm fxp5 stp fxp5 \e
502    addm fxp6 stp fxp6 \e
503    addm fxp7 stp fxp7 \e
504    up
505.Ed
506.Pp
507The bridge can be used as a regular host interface at the same time as bridging
508between its member ports.
509In this example, the bridge connects em0 and em1, and will receive its IP
510address through DHCP:
511.Bd -literal -offset indent
512cloned_interfaces="bridge0"
513ifconfig_bridge0="addm em0 addm em1 DHCP"
514ifconfig_em0="up"
515ifconfig_em1="up"
516.Ed
517.Pp
518The bridge can tunnel Ethernet across an IP internet using the EtherIP
519protocol.
520This can be combined with
521.Xr ipsec 4
522to provide an encrypted connection.
523Create a
524.Xr gif 4
525interface and set the local and remote IP addresses for the
526tunnel, these are reversed on the remote bridge.
527.Bd -literal -offset indent
528ifconfig gif0 create
529ifconfig gif0 tunnel 1.2.3.4 5.6.7.8 up
530ifconfig bridge0 create
531ifconfig bridge0 addm fxp0 addm gif0 up
532.Ed
533.Sh SEE ALSO
534.Xr gif 4 ,
535.Xr ipf 4 ,
536.Xr ipfw 4 ,
537.Xr netmap 4 ,
538.Xr pf 4 ,
539.Xr ifconfig 8
540.Sh HISTORY
541The
542.Nm
543driver first appeared in
544.Fx 6.0 .
545.Sh AUTHORS
546.An -nosplit
547The
548.Nm bridge
549driver was originally written by
550.An Jason L. Wright Aq Mt jason@thought.net
551as part of an undergraduate independent study at the University of
552North Carolina at Greensboro.
553.Pp
554This version of the
555.Nm
556driver has been heavily modified from the original version by
557.An Jason R. Thorpe Aq Mt thorpej@wasabisystems.com .
558.Pp
559Rapid Spanning Tree Protocol (RSTP) support was added by
560.An Andrew Thompson Aq Mt thompsa@FreeBSD.org .
561.Sh BUGS
562The
563.Nm
564driver currently supports only Ethernet and Ethernet-like (e.g., 802.11)
565network devices, which can be configured with the same MTU size as the bridge
566device.
567