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