xref: /freebsd/share/man/man4/bridge.4 (revision 66e576525d35c68fcb86f142ebaa5a448555c0c7)
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.\" $FreeBSD$
37.\"
38.Dd January 9, 2010
39.Dt IF_BRIDGE 4
40.Os
41.Sh NAME
42.Nm if_bridge
43.Nd network bridge device
44.Sh SYNOPSIS
45To compile this driver into the kernel,
46place the following line in your
47kernel configuration file:
48.Bd -ragged -offset indent
49.Cd "device if_bridge"
50.Ed
51.Pp
52Alternatively, to load the driver as a
53module at boot time, place the following lines in
54.Xr loader.conf 5 :
55.Bd -literal -offset indent
56if_bridge_load="YES"
57bridgestp_load="YES"
58.Ed
59.Sh DESCRIPTION
60The
61.Nm
62driver creates a logical link between two or more IEEE 802 networks
63that use the same (or
64.Dq "similar enough" )
65framing format.
66For example, it is possible to bridge Ethernet and 802.11 networks together,
67but it is not possible to bridge Ethernet and Token Ring together.
68.Pp
69Each
70.Nm
71interface is created at runtime using interface cloning.
72This is
73most easily done with the
74.Xr ifconfig 8
75.Cm create
76command or using the
77.Va cloned_interfaces
78variable in
79.Xr rc.conf 5 .
80.Pp
81The
82.Nm
83interface randomly chooses a link (MAC) address in the range reserved for
84locally administered addresses when it is created.
85This address is guaranteed to be unique
86.Em only
87across all
88.Nm
89interfaces on the local machine.
90Thus you can theoretically have two bridges on the different machines with
91the same link addresses.
92The address can be changed by assigning the desired link address using
93.Xr ifconfig 8 .
94.Pp
95If
96.Xr sysctl 8
97node
98.Va net.link.bridge.inherit_mac
99has non-zero value, newly created bridge will inherit MAC address
100from its first member instead of choosing random link-level address.
101This will provide more predictable bridge MAC without any
102additional configuration, but currently this feature is known
103to break some L2 protocols, for example PPPoE that is provided
104by
105.Xr ng_pppoe 4
106and
107.Xr ppp 8 .
108Now this feature is considered as experimental and is turned off
109by-default.
110.Pp
111A bridge can be used to provide several services, such as a simple
112802.11-to-Ethernet bridge for wireless hosts, and traffic isolation.
113.Pp
114A bridge works like a switch, forwarding traffic from one interface
115to another.
116Multicast and broadcast packets are always forwarded to all
117interfaces that are part of the bridge.
118For unicast traffic, the bridge learns which MAC addresses are associated
119with which interfaces and will forward the traffic selectively.
120.Pp
121All the bridged member interfaces need to be up in order to pass network traffic.
122These can be enabled using
123.Xr ifconfig 8
124or
125.Va ifconfig_ Ns Ao Ar interface Ac Ns Li ="up"
126in
127.Xr rc.conf 5 .
128.Pp
129The MTU of the first member interface to be added is used as the bridge MTU.
130All additional members are required to have exactly the same value.
131.Pp
132The TXCSUM capability is disabled for any interface added to the bridge, and it
133is restored when the interface is removed again.
134.Pp
135The bridge supports
136.Dq monitor mode ,
137where the packets are discarded after
138.Xr bpf 4
139processing, and are not processed or forwarded further.
140This can be used to multiplex the input of two or more interfaces into a single
141.Xr bpf 4
142stream.
143This is useful for reconstructing the traffic for network taps
144that transmit the RX/TX signals out through two separate interfaces.
145.Sh SPANNING TREE
146The
147.Nm
148driver implements the Rapid Spanning Tree Protocol (RSTP or 802.1w) with
149backwards compatibility with the legacy Spanning Tree Protocol (STP).
150Spanning Tree is used to detect and remove loops in a network topology.
151.Pp
152RSTP provides faster spanning tree convergence than legacy STP, the protocol
153will exchange information with neighbouring switches to quickly transition to
154forwarding without creating loops.
155.Pp
156The code will default to RSTP mode but will downgrade any port connected to a
157legacy STP network so is fully backward compatible.
158A bridge can be forced to operate in STP mode without rapid state transitions
159via the
160.Va proto
161command in
162.Xr ifconfig 8 .
163.Pp
164The bridge can log STP port changes to
165.Xr syslog 3
166by enabling the
167.Va net.link.bridge.log_stp
168variable using
169.Xr sysctl 8 .
170.Pp
171.Sh PACKET FILTERING
172Packet filtering can be used with any firewall package that hooks in via the
173.Xr pfil 9
174framework.
175When filtering is enabled, bridged packets will pass through the filter
176inbound on the originating interface, on the bridge interface and outbound on
177the appropriate interfaces.
178Either stage can be disabled.
179The filtering behaviour can be controlled using
180.Xr sysctl 8 :
181.Bl -tag -width ".Va net.link.bridge.pfil_onlyip"
182.It Va net.link.bridge.pfil_onlyip
183Controls the handling of non-IP packets which are not passed to
184.Xr pfil 9 .
185Set to
186.Li 1
187to only allow IP packets to pass (subject to firewall rules), set to
188.Li 0
189to unconditionally pass all non-IP Ethernet frames.
190.It Va net.link.bridge.pfil_member
191Set to
192.Li 1
193to enable filtering on the incoming and outgoing member interfaces, set
194to
195.Li 0
196to disable it.
197.It Va net.link.bridge.pfil_bridge
198Set to
199.Li 1
200to enable filtering on the bridge interface, set
201to
202.Li 0
203to disable it.
204.It Va net.link.bridge.pfil_local_phys
205Set to
206.Li 1
207to additionally filter on the physical interface for locally destined packets.
208Set to
209.Li 0
210to disable this feature.
211.It Va net.link.bridge.ipfw
212Set to
213.Li 1
214to enable layer2 filtering with
215.Xr ipfirewall 4 ,
216set to
217.Li 0
218to disable it.
219This needs to be enabled for
220.Xr dummynet 4
221support.
222When
223.Va ipfw
224is enabled,
225.Va pfil_bridge
226and
227.Va pfil_member
228will be disabled so that IPFW
229is not run twice; these can be re-enabled if desired.
230.It Va net.link.bridge.ipfw_arp
231Set to
232.Li 1
233to enable layer2 ARP filtering with
234.Xr ipfirewall 4 ,
235set to
236.Li 0
237to disable it.
238Requires
239.Va ipfw
240to be enabled.
241.El
242.Pp
243ARP and REVARP packets are forwarded without being filtered and others
244that are not IP nor IPv6 packets are not forwarded when
245.Va pfil_onlyip
246is enabled.
247IPFW can filter Ethernet types using
248.Cm mac-type
249so all packets are passed to
250the filter for processing.
251.Pp
252The packets originating from the bridging host will be seen by
253the filter on the interface that is looked up in the routing
254table.
255.Pp
256The packets destined to the bridging host will be seen by the filter
257on the interface with the MAC address equal to the packet's destination
258MAC.
259There are situations when some of the bridge members are sharing
260the same MAC address (for example the
261.Xr vlan 4
262interfaces: they are currently sharing the
263MAC address of the parent physical interface).
264It is not possible to distinguish between these interfaces using
265their MAC address, excluding the case when the packet's destination
266MAC address is equal to the MAC address of the interface on which
267the packet was entered to the system.
268In this case the filter will see the incoming packet on this
269interface.
270In all other cases the interface seen by the packet filter is chosen
271from the list of bridge members with the same MAC address and the
272result strongly depends on the member addition sequence and the
273actual implementation of
274.Nm .
275It is not recommended to rely on the order chosen by the current
276.Nm
277implementation: it can be changed in the future.
278.Pp
279The previous paragraph is best illustrated with the following
280pictures.
281Let
282.Bl -bullet
283.It
284the MAC address of the incoming packet's destination is
285.Nm nn:nn:nn:nn:nn:nn ,
286.It
287the interface on which packet entered the system is
288.Nm ifX ,
289.It
290.Nm ifX
291MAC address is
292.Nm xx:xx:xx:xx:xx:xx ,
293.It
294there are possibly other bridge members with the same MAC address
295.Nm xx:xx:xx:xx:xx:xx ,
296.It
297the bridge has more than one interface that are sharing the
298same MAC address
299.Nm yy:yy:yy:yy:yy:yy ;
300we will call them
301.Nm vlanY1 ,
302.Nm vlanY2 ,
303etc.
304.El
305.Pp
306Then if the MAC address
307.Nm nn:nn:nn:nn:nn:nn
308is equal to the
309.Nm xx:xx:xx:xx:xx:xx
310then the filter will see the packet on the interface
311.Nm ifX
312no matter if there are any other bridge members carrying the same
313MAC address.
314But if the MAC address
315.Nm nn:nn:nn:nn:nn:nn
316is equal to the
317.Nm yy:yy:yy:yy:yy:yy
318then the interface that will be seen by the filter is one of the
319.Nm vlanYn .
320It is not possible to predict the name of the actual interface
321without the knowledge of the system state and the
322.Nm
323implementation details.
324.Pp
325This problem arises for any bridge members that are sharing the same
326MAC address, not only to the
327.Xr vlan 4
328ones: they we taken just as the example of such situation.
329So if one wants the filter the locally destined packets based on
330their interface name, one should be aware of this implication.
331The described situation will appear at least on the filtering bridges
332that are doing IP-forwarding; in some of such cases it is better
333to assign the IP address only to the
334.Nm
335interface and not to the bridge members.
336Enabling
337.Va net.link.bridge.pfil_local_phys
338will let you do the additional filtering on the physical interface.
339.Sh EXAMPLES
340The following when placed in the file
341.Pa /etc/rc.conf
342will cause a bridge called
343.Dq Li bridge0
344to be created, and will add the interfaces
345.Dq Li wlan0
346and
347.Dq Li fxp0
348to the bridge, and then enable packet forwarding.
349Such a configuration could be used to implement a simple
350802.11-to-Ethernet bridge (assuming the 802.11 interface is
351in ad-hoc mode).
352.Bd -literal -offset indent
353cloned_interfaces="bridge0"
354ifconfig_bridge0="addm wlan0 addm fxp0 up"
355.Ed
356.Pp
357For the bridge to forward packets all member interfaces and the bridge need
358to be up.
359The above example would also require:
360.Bd -literal -offset indent
361create_args_wlan0="wlanmode hostap"
362ifconfig_wlan0="up ssid my_ap mode 11g"
363ifconfig_fxp0="up"
364.Ed
365.Pp
366Consider a system with two 4-port Ethernet boards.
367The following will cause a bridge consisting of all 8 ports with Rapid Spanning
368Tree enabled to be created:
369.Bd -literal -offset indent
370ifconfig bridge0 create
371ifconfig bridge0 \e
372    addm fxp0 stp fxp0 \e
373    addm fxp1 stp fxp1 \e
374    addm fxp2 stp fxp2 \e
375    addm fxp3 stp fxp3 \e
376    addm fxp4 stp fxp4 \e
377    addm fxp5 stp fxp5 \e
378    addm fxp6 stp fxp6 \e
379    addm fxp7 stp fxp7 \e
380    up
381.Ed
382.Pp
383The bridge can be used as a regular host interface at the same time as bridging
384between its member ports.
385In this example, the bridge connects em0 and em1, and will receive its IP
386address through DHCP:
387.Bd -literal -offset indent
388cloned_interfaces="bridge0"
389ifconfig_bridge0="addm em0 addm em1 DHCP"
390ifconfig_em0="up"
391ifconfig_em1="up"
392.Ed
393.Pp
394The bridge can tunnel Ethernet across an IP internet using the EtherIP
395protocol.
396This can be combined with
397.Xr ipsec 4
398to provide an encrypted connection.
399Create a
400.Xr gif 4
401interface and set the local and remote IP addresses for the
402tunnel, these are reversed on the remote bridge.
403.Bd -literal -offset indent
404ifconfig gif0 create
405ifconfig gif0 tunnel 1.2.3.4 5.6.7.8 up
406ifconfig bridge0 create
407ifconfig bridge0 addm fxp0 addm gif0 up
408.Ed
409.Pp
410Note that
411.Fx
4126.1, 6.2, 6.3, 7.0, 7.1, and 7.2 have a bug in the EtherIP protocol.
413For more details and workaround, see
414.Xr gif 4 manual page.
415.Sh SEE ALSO
416.Xr gif 4 ,
417.Xr ipf 4 ,
418.Xr ipfw 4 ,
419.Xr pf 4 ,
420.Xr ifconfig 8
421.Sh HISTORY
422The
423.Nm
424driver first appeared in
425.Fx 6.0 .
426.Sh AUTHORS
427.An -nosplit
428The
429.Nm bridge
430driver was originally written by
431.An Jason L. Wright
432.Aq jason@thought.net
433as part of an undergraduate independent study at the University of
434North Carolina at Greensboro.
435.Pp
436This version of the
437.Nm
438driver has been heavily modified from the original version by
439.An Jason R. Thorpe
440.Aq thorpej@wasabisystems.com .
441.Pp
442Rapid Spanning Tree Protocol (RSTP) support was added by
443.An Andrew Thompson
444.Aq thompsa@FreeBSD.org .
445.Sh BUGS
446The
447.Nm
448driver currently supports only Ethernet and Ethernet-like (e.g., 802.11)
449network devices, with exactly the same interface MTU size as the bridge device.
450