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