1.\" Copyright 2001 Wasabi Systems, Inc. 2.\" All rights reserved. 3.\" 4.\" Written by Jason R. Thorpe for Wasabi Systems, Inc. 5.\" Spanning tree modifications by Matthew Dillon 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project by 18.\" Wasabi Systems, Inc. 19.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse 20.\" or promote products derived from this software without specific prior 21.\" written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 27.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33.\" POSSIBILITY OF SUCH DAMAGE. 34.\" 35.\" 36.Dd June 20, 2024 37.Dt BRIDGE 4 38.Os 39.Sh NAME 40.Nm bridge 41.Nd network bridge device 42.Sh SYNOPSIS 43.Cd "pseudo-device bridge" 44.Sh DESCRIPTION 45The 46.Nm 47driver creates a logical link between two or more IEEE 802 networks 48that use the same (or 49.Dq similar enough ) 50framing format. 51For example, it is possible to bridge Ethernet and 802.11 networks together, 52but it is not possible to bridge Ethernet and Token Ring together. 53.Pp 54To use 55.Nm , 56the administrator must first create the interface and configure 57the bridge parameters. 58The bridge is created using the 59.Xr ifconfig 8 60.Cm create 61subcommand. 62See the 63.Xr ifconfig 8 64manual page for further information on configuring bridges. 65.Pp 66A bridge can be used to provide several services, such as a simple 67802.11-to-Ethernet bridge for wireless hosts, and traffic isolation. 68.Pp 69A bridge works like a hub, forwarding traffic from one interface 70to another. 71Multicast and broadcast packets are always forwarded to all 72interfaces that are part of the bridge. 73For unicast traffic, the bridge learns which MAC addresses are associated 74with which interfaces and will forward the traffic selectively. 75By default the bridge can keep track of 4096 MAC addresses. 76.Pp 77The bridge operates in a safe mode by default, setting the MAC source in 78the link header on outgoing packets to the outgoing interface MAC. 79This reduces the chance that the layer-2 switching in your switches 80will become confused. 81.Pp 82The bridge supports various special features via 83.Cm link 84options. 85.Bl -tag -width indent 86.It Cm link0 87The link0 option enables transparent bridging mode. 88The bridge will make every effort to retain the ethernet header 89when forwarding packets between interfaces, making the bridging 90function work more like a hardware bridge device. 91.It Cm link1 92The link1 option enables keepalive transmission and automatically 93places a member into a special blocked mode if no keepalive reception 94occurs. 95If either sides of the link uses this option then both sides must use 96this option. 97This option is implemented by sending CFG updates on the hello interval 98to the remote. 99The link is considered lost after 10 intervals (typically 20 seconds). 100.It Cm link2 101The link2 option enables channel bonding (see also ifbondweight, ifpriority). 102All member interfaces with the same mac address are considered to 103be in a bonding group. Packets will be sent on the highest priority 104interface(s) in the bonding group, and will round-robin output interfaces 105when multiple (highest priority) interfaces have the same priority. 106When something like 107.Xr tap 4 108is used, you can manually control or copy the mac to create bonding groups. 109When interface bonding is enabled normally blocked interfaces belonging 110to the same bonding group as an active forwarding interface will be 111changed to the bonding state. 112Both sides of link the member represents must operate in bonding mode 113for this to work, otherwise the remote end may decide to throw away 114half your packets. 115.El 116.Pp 117If your network becomes glitchy, with long pauses in tcp sessions, then 118transparent bridging mode is likely the cause. This mode should only be 119used when you are bridging networks with devices that do MAC-based security 120or firewalling (for example, the supremely braindead at&t uverse router), 121or which impose severe limitations on MAC:IP assignments. 122.Pp 123If member interfaces constantly enter a 'blocked (link1)' state then the 124other end of those interfaces is not implementing the link1 keepalive. 125Both sides must implement the keepalive. 126.Pp 127If you get an enormous amount of packet loss and are using link2-based 128bonding, then the other side of those member interfaces are probably 129not implementing link2-based bonding. 130.Pp 131The 132.Nm 133driver implements the IEEE 802.1D Spanning Tree protocol (STP). 134Spanning Tree is used to detect and remove loops in a network topology. 135.Pp 136Packet filtering can be used with any firewall package that hooks in via the 137.Xr pfil 9 138framework. 139When filtering is enabled, bridged packets will pass through the filter 140inbound on the originating interface, on the bridge interface and outbound on 141the appropriate interfaces. 142Either stage can be disabled as well as the filtering of non IP and IPv6 143packets. 144Note that ARP and REVARP packets are always forwarded without being filtered. 145.Pp 146This behaviour can be controlled using 147.Xr sysctl 8 : 148Set 149.Va net.link.bridge.pfil_member 150to 151.Li 1 152to enable filtering on the incoming and outgoing member interfaces, 153set 154.Va net.link.bridge.pfil_bridge 155to 156.Li 1 157to enable filtering on the bridge interface 158and set 159.Va net.link.bridge.pfil_onlyip 160to 161.Li 1 162to only allow IP and IPv6 packets to be forawarded when filtering is 163enabled. 164For example, setting 165.Va net.link.bridge.pfil_onlyip 166to 167.Li 0 168would allow PPPoE traffic over the bridge. 169.Pp 170The default value of the 171.Va net.link.bridge.pfil_* 172nodes is 173.Li 1 . 174.Pp 175Note that packets to and from the bridging host will be seen by the 176filter on the interface with the appropriate address configured as well 177as on the interface on which the packet arrives or departs. 178.Pp 179The MTU of the first member interface to be added is used as the bridge MTU, 180all additional members are required to have exactly the same value. 181.Sh EXTRA FEATURES 182.Dx 183implements two additional features to make spanning tree operation more 184resilient. 185.Pp 186Specifying 187.Cm link0 188on the bridge interface places the bridge in transparent bridging mode. 189The bridge will make every attempt to retain the original source MAC in 190the ethernet link header. 191.Pp 192Specifying 193.Cm link1 194on the bridge interface forces the bridge to generate a 802.11d CFG 195message on every hello interval for all interfaces participating 196in the STP protocol. 197Normally CFG messages are only generated by the root bridge interface 198or during topology changes. 199In addition the bridge code expects to receive 802.11d frames from 200all interface participating in the STP protocol. 201.Pp 202An interface which fails to receive a 802.11d frame within 10 times 203the hello interval (usually 20 seconds) automatically goes into 204l1blocking mode, which can be observed in the ifconfig output for 205the bridge. This removes the interface from consideration and the 206bridge code automatically routes around it. 207.Pp 208Using 209.Cm link0 210and 211.Cm link1 212together between two 213.Dx 214boxes allows you to maintain multiple parallel vpns between those 215boxes via different networks (if you happen to be on more than one 216with internet access). 217Use separate openvpn instances and tap devices for each vpn link 218to accomplish this, placing them in the same bridge interface on 219the two endpoints. 220The tap devices do not need any IP configuration when bridged and 221can be assigned the same ether MAC (in fact they have to be 222if you want the failover to work nicely). 223.Sh SEE ALSO 224.Xr pf 4 , 225.Xr ifconfig 8 226.Sh HISTORY 227The 228.Nm 229driver first appeared in 230.Ox 2.5 231and found its way into 232.Dx 1.3 . 233Transparent bridging (link0) was added in 234.Dx 2.9 235in 2011. 236.Sh AUTHORS 237.An -nosplit 238The 239.Nm 240driver was originally written by 241.An Jason L. Wright Aq Mt jason@thought.net 242as part of an undergraduate independent study at the University of 243North Carolina at Greensboro. 244.Pp 245This version of the 246.Nm 247driver has been heavily modified from the original version by 248.An Jason R. Thorpe Aq Mt thorpej@wasabisystems.com . 249.Sh BUGS 250The 251.Nm 252driver currently supports only Ethernet and Ethernet-like (e.g. 802.11) 253network devices, with exactly the same interface MTU size as the bridge device. 254