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