xref: /freebsd/share/man/man4/bridge.4 (revision ae07a5805b1906f29e786f415d67bef334557bd3)
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 July 5, 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 VLAN SUPPORT
275The
276.Nm
277driver has full support for virtual LANs (VLANs).
278The bridge implements independent VLAN learning, i.e. MAC addresses are
279learned on a per-VLAN basis, and the same MAC address may be learned on
280multiple interfaces on different VLANs.
281Incoming frames with an 802.1Q tag will be assigned to the appropriate
282VLAN.
283.Pp
284Traffic sent to or from the host is not assigned to a VLAN by default.
285To allow the host to communicate on a VLAN, configure a
286.Xr vlan 4
287interface on the bridge and (if necessary) assign IP addresses there.
288.Pp
289By default no access control is enabled, so any interface may
290participate in any VLAN.
291.Pp
292VLAN filtering may be enabled on an interface using the
293.Xr ifconfig 8
294.Cm vlanfilter
295option.
296When VLAN filtering is enabled, an interface may only send and receive
297frames based on its configured VLAN access list.
298.Pp
299The interface's untagged VLAN ID may be configured using the
300.Xr ifconfig 8
301.Cm untagged
302option.
303If an untagged VLAN ID is configured, incoming frames will be assigned
304to that VLAN, and the interface may receive outgoing untagged frames
305in that VLAN.
306.Pp
307The tagged VLAN access list may be configured using the
308.Cm tagged ,
309.Cm +tagged
310and
311.Cm -tagged
312options to
313.Xr ifconfig 8 .
314An interface may send and receive tagged frames for any VLAN in its
315access list.
316.Pp
317The bridge will automatically insert or remove 802.1q tags as needed,
318based on the interface configuration, when forwarding frames between
319interfaces.
320This tag processing is only done for interfaces with VLAN filtering
321enabled.
322.Sh PACKET FILTERING
323Packet filtering can be used with any firewall package that hooks in via the
324.Xr pfil 9
325framework.
326When filtering is enabled, bridged packets will pass through the filter
327inbound on the originating interface, on the bridge interface and outbound on
328the appropriate interfaces.
329Either stage can be disabled.
330The filtering behavior can be controlled using
331.Xr sysctl 8 :
332.Bl -tag -width indent
333.It Va net.link.bridge.pfil_onlyip
334Controls the handling of non-IP packets which are not passed to
335.Xr pfil 9 .
336Set to
337.Li 1
338to only allow IP packets to pass (subject to firewall rules), set to
339.Li 0
340to unconditionally pass all non-IP Ethernet frames.
341.It Va net.link.bridge.pfil_member
342Set to
343.Li 1
344to enable filtering on the incoming and outgoing member interfaces, set
345to
346.Li 0
347to disable it.
348.It Va net.link.bridge.pfil_bridge
349Set to
350.Li 1
351to enable filtering on the bridge interface, set
352to
353.Li 0
354to disable it.
355.It Va net.link.bridge.pfil_local_phys
356Set to
357.Li 1
358to additionally filter on the physical interface for locally destined packets.
359Set to
360.Li 0
361to disable this feature.
362.It Va net.link.bridge.ipfw
363Set to
364.Li 1
365to enable layer2 filtering with
366.Xr ipfirewall 4 ,
367set to
368.Li 0
369to disable it.
370This needs to be enabled for
371.Xr dummynet 4
372support.
373When
374.Va ipfw
375is enabled,
376.Va pfil_bridge
377and
378.Va pfil_member
379will be disabled so that IPFW
380is not run twice; these can be re-enabled if desired.
381.It Va net.link.bridge.ipfw_arp
382Set to
383.Li 1
384to enable layer2 ARP filtering with
385.Xr ipfirewall 4 ,
386set to
387.Li 0
388to disable it.
389Requires
390.Va ipfw
391to be enabled.
392.El
393.Pp
394ARP and REVARP packets are forwarded without being filtered and others
395that are not IP nor IPv6 packets are not forwarded when
396.Va pfil_onlyip
397is enabled.
398IPFW can filter Ethernet types using
399.Cm mac-type
400so all packets are passed to
401the filter for processing.
402.Pp
403The packets originating from the bridging host will be seen by
404the filter on the interface that is looked up in the routing
405table.
406.Pp
407The packets destined to the bridging host will be seen by the filter
408on the interface with the MAC address equal to the packet's destination
409MAC.
410There are situations when some of the bridge members are sharing
411the same MAC address (for example the
412.Xr vlan 4
413interfaces: they are currently sharing the
414MAC address of the parent physical interface).
415It is not possible to distinguish between these interfaces using
416their MAC address, excluding the case when the packet's destination
417MAC address is equal to the MAC address of the interface on which
418the packet was entered to the system.
419In this case the filter will see the incoming packet on this
420interface.
421In all other cases the interface seen by the packet filter is chosen
422from the list of bridge members with the same MAC address and the
423result strongly depends on the member addition sequence and the
424actual implementation of
425.Nm .
426It is not recommended to rely on the order chosen by the current
427.Nm
428implementation since it may change in the future.
429.Pp
430The previous paragraph is best illustrated with the following
431pictures.
432Let
433.Bl -bullet
434.It
435the MAC address of the incoming packet's destination is
436.Nm nn:nn:nn:nn:nn:nn ,
437.It
438the interface on which packet entered the system is
439.Nm ifX ,
440.It
441.Nm ifX
442MAC address is
443.Nm xx:xx:xx:xx:xx:xx ,
444.It
445there are possibly other bridge members with the same MAC address
446.Nm xx:xx:xx:xx:xx:xx ,
447.It
448the bridge has more than one interface that are sharing the
449same MAC address
450.Nm yy:yy:yy:yy:yy:yy ;
451we will call them
452.Nm vlanY1 ,
453.Nm vlanY2 ,
454etc.
455.El
456.Pp
457If the MAC address
458.Nm nn:nn:nn:nn:nn:nn
459is equal to
460.Nm xx:xx:xx:xx:xx:xx
461the filter will see the packet on interface
462.Nm ifX
463no matter if there are any other bridge members carrying the same
464MAC address.
465But if the MAC address
466.Nm nn:nn:nn:nn:nn:nn
467is equal to
468.Nm yy:yy:yy:yy:yy:yy
469then the interface that will be seen by the filter is one of the
470.Nm vlanYn .
471It is not possible to predict the name of the actual interface
472without the knowledge of the system state and the
473.Nm
474implementation details.
475.Pp
476This problem arises for any bridge members that are sharing the same
477MAC address, not only to the
478.Xr vlan 4
479ones: they were taken just as an example of such a situation.
480So if one wants to filter the locally destined packets based on
481their interface name, one should be aware of this implication.
482The described situation will appear at least on the filtering bridges
483that are doing IP-forwarding; in some of such cases it is better
484to assign the IP address only to the
485.Nm
486interface and not to the bridge members.
487Enabling
488.Va net.link.bridge.pfil_local_phys
489will let you do the additional filtering on the physical interface.
490.Sh NETMAP
491.Xr netmap 4
492applications may open a bridge interface in emulated mode.
493The netmap application will receive all packets which arrive from member
494interfaces.
495In particular, packets which would otherwise be forwarded to another
496member interface will be received by the netmap application.
497.Pp
498When the
499.Xr netmap 4
500application transmits a packet to the host stack via the bridge interface,
501.Nm
502receive it and attempts to determine its
503.Ql source
504interface by looking up the source MAC address in the interface's learning
505tables.
506Packets for which no matching source interface is found are dropped and the
507input error counter is incremented.
508If a matching source interface is found,
509.Nm
510treats the packet as though it was received from the corresponding interface
511and handles it normally without passing the packet back to
512.Xr netmap 4 .
513.Sh EXAMPLES
514The following when placed in the file
515.Pa /etc/rc.conf
516will cause a bridge called
517.Dq Li bridge0
518to be created, and will add the interfaces
519.Dq Li wlan0
520and
521.Dq Li fxp0
522to the bridge, and then enable packet forwarding.
523Such a configuration could be used to implement a simple
524802.11-to-Ethernet bridge (assuming the 802.11 interface is
525in ad-hoc mode).
526.Bd -literal -offset indent
527cloned_interfaces="bridge0"
528ifconfig_bridge0="addm wlan0 addm fxp0 up"
529.Ed
530.Pp
531For the bridge to forward packets,
532all member interfaces and the bridge need to be up.
533The above example would also require:
534.Bd -literal -offset indent
535create_args_wlan0="wlanmode hostap"
536ifconfig_wlan0="up ssid my_ap mode 11g"
537ifconfig_fxp0="up"
538.Ed
539.Pp
540Consider a system with two 4-port Ethernet boards.
541The following will cause a bridge consisting of all 8 ports with
542Rapid Spanning Tree enabled to be created:
543.Bd -literal -offset indent
544ifconfig bridge0 create
545ifconfig bridge0 \e
546    addm fxp0 stp fxp0 \e
547    addm fxp1 stp fxp1 \e
548    addm fxp2 stp fxp2 \e
549    addm fxp3 stp fxp3 \e
550    addm fxp4 stp fxp4 \e
551    addm fxp5 stp fxp5 \e
552    addm fxp6 stp fxp6 \e
553    addm fxp7 stp fxp7 \e
554    up
555.Ed
556.Pp
557The bridge can be used as a regular host interface at the same time as bridging
558between its member ports.
559In this example, the bridge connects em0 and em1, and will receive its IP
560address through DHCP:
561.Bd -literal -offset indent
562cloned_interfaces="bridge0"
563ifconfig_bridge0="addm em0 addm em1 DHCP"
564ifconfig_em0="up"
565ifconfig_em1="up"
566.Ed
567.Pp
568The bridge can tunnel Ethernet across an IP internet using the EtherIP
569protocol.
570This can be combined with
571.Xr ipsec 4
572to provide an encrypted connection.
573Create a
574.Xr gif 4
575interface and set the local and remote IP addresses for the
576tunnel, these are reversed on the remote bridge.
577.Bd -literal -offset indent
578ifconfig gif0 create
579ifconfig gif0 tunnel 1.2.3.4 5.6.7.8 up
580ifconfig bridge0 create
581ifconfig bridge0 addm fxp0 addm gif0 up
582.Ed
583.Sh SEE ALSO
584.Xr gif 4 ,
585.Xr ipf 4 ,
586.Xr ipfw 4 ,
587.Xr netmap 4 ,
588.Xr pf 4 ,
589.Xr vlan 4 ,
590.Xr ifconfig 8
591.Sh HISTORY
592The
593.Nm
594driver first appeared in
595.Fx 6.0 .
596.Sh AUTHORS
597.An -nosplit
598The
599.Nm bridge
600driver was originally written by
601.An Jason L. Wright Aq Mt jason@thought.net
602as part of an undergraduate independent study at the University of
603North Carolina at Greensboro.
604.Pp
605This version of the
606.Nm
607driver has been heavily modified from the original version by
608.An Jason R. Thorpe Aq Mt thorpej@wasabisystems.com .
609.Pp
610Rapid Spanning Tree Protocol (RSTP) support was added by
611.An Andrew Thompson Aq Mt thompsa@FreeBSD.org .
612.Sh BUGS
613The
614.Nm
615driver currently supports only Ethernet and Ethernet-like (e.g., 802.11)
616network devices, which can be configured with the same MTU size as the bridge
617device.
618