IF_BRIDGE(4)
okay so bestie, welcome to if_bridge(4) β straight out of the Kernel Interfaces Manual. It's the manual page for the network bridge device, and honestly? It's a lot. But you're gonna get it, because we're doing this together. π
π NAME π
if_bridge β network bridge device
β¨ SYNOPSIS β¨
So you wanna get this driver into your kernel? Slay. Drop this line into your kernel configuration file:
device if_bridge
Orrr, if you'd rather load it as a module at boot time, put these lines in loader.conf(5):
if_bridge_load="YES"
bridgestp_load="YES"
πΈ DESCRIPTION πΈ
The if_bridge driver creates a logical link between two or more IEEE 802 networks that use the same β or "similar enough" β framing format. Like, for example: you can bridge Ethernet and 802.11 networks together. You can not bridge Ethernet and Token Ring together. That's just not the vibe. π
Every if_bridge interface gets created at runtime using interface cloning. Easiest way to do that? The ifconfig(8) create command, or the cloned_interfaces variable in rc.conf(5). Pick your fighter. π«Ά
When it's created, the if_bridge interface randomly chooses a link (MAC) address in the range reserved for locally administered addresses. And here's the fine print, bestie: that address is guaranteed unique only across all if_bridge interfaces on the local machine. So theoretically you can have two bridges on different machines rockin' the exact same link address. No drama. If you want to change it, just assign whatever link address you want using ifconfig(8). π
If the sysctl(8) node net.link.bridge.inherit_mac has a non-zero value, then a newly created bridge will inherit its MAC address from its first member instead of picking a random link-level address. That gives you a more predictable bridge MAC with zero extra configurationβ¦ but currently this feature is known to break some L2 protocols, for example PPPoE, which is provided by ng_pppoe(4) and ppp(8). As of right now this feature is considered experimental and is turned off by default. π
A bridge can serve up several services, like a simple 802.11-to-Ethernet bridge for wireless hosts, and traffic isolation. Versatile icon. β¨
A bridge works like a switch β it forwards traffic from one interface to another. Multicast and broadcast packets are always forwarded to all interfaces that are part of the bridge. For unicast traffic, the bridge learns which MAC addresses are associated with which interfaces, and then it forwards the traffic selectively. Smart queen. π§
All the bridged member interfaces need to be up in order to pass network traffic. You can enable them with ifconfig(8), or with ifconfig_β¨interfaceβ©="up" in rc.conf(5).
The MTU of the first member interface to be added is what becomes the bridge MTU. Every additional member is required to have exactly the same value. Not "close enough." Exactly. β οΈ
The TOE, TSO, TXCSUM and TXCSUM6 capabilities on all interfaces added to the bridge get disabled if any of the interfaces doesn't support/enable them. The LRO capability is always disabled. All the capabilities get restored when the interface is removed from the bridge. And heads up β changing capabilities at run time may cause NIC reinit and the link flap. π
The bridge supports βmonitor modeβ, where packets are discarded after bpf(4) processing, and are not processed or forwarded any further. This lets you multiplex the input of two or more interfaces into a single bpf(4) stream. Super useful for reconstructing the traffic for network taps that transmit the RX/TX signals out through two separate interfaces. Obsessed. π
π IPV6 SUPPORT π
if_bridge supports the AF_INET6 address family on bridge interfaces. This rc.conf(5) variable configures an IPv6 link-local address on the bridge0 interface:
ifconfig_bridge0_ipv6="up"
or, in a more explicit manner:
ifconfig_bridge0_ipv6="inet6 auto_linklocal"
However β and this is the messy part β the AF_INET6 address family has a concept of scope zone. Bridging multiple interfaces changes the zone configuration, because multiple links get merged into each other and form a new single link, while the member interfaces still work individually. Which means each member interface still has a separate link-local scope zone, and the if_bridge interface has another single, aggregated link-local scope zone at the same time. π
That situation is clearly against the description "zones of the same scope cannot overlap" in Section 5, RFC 4007. It works in most cases, but it can cause some counterintuitive or undesirable behavior in some edge cases β specifically when both the if_bridge interface and one of the member interfaces have an IPv6 address, and applications use both of them.
To prevent this whole situation, if_bridge checks whether a link-local scoped IPv6 address is configured on a member interface that's about to be added and on the if_bridge interface. When the if_bridge interface has IPv6 addresses, the IPv6 addresses on the member interface will be automatically removed before that interface is added. π§Ή
Wanna turn that behavior off? Set the sysctl(8) variable net.link.bridge.allow_llz_overlap to 1.
Also, note that theACCEPT_RTADVandAUTO_LINKLOCALinterface flags are not enabled by default on anif_bridgeinterface β not even whennet.inet6.ip6.accept_rtadvand/ornet.inet6.ip6.auto_linklocalis set to1. π
π SPANNING TREE π
The if_bridge driver implements the Rapid Spanning Tree Protocol (RSTP, aka 802.1w) with backwards compatibility with the legacy Spanning Tree Protocol (STP). Spanning Tree is what detects and removes loops in a network topology. Loops? Not on our watch. π«π
RSTP provides faster spanning tree convergence than legacy STP β the protocol exchanges information with neighbouring switches so it can quickly transition to forwarding without creating loops. Main character energy, fr fr.
The code defaults to RSTP mode, but it will downgrade any port connected to a legacy STP network, so it's fully backward compatible. If you want, a bridge can be forced to operate in STP mode without rapid state transitions via the proto command in ifconfig(8).
And if you want receipts on what STP is doing, the bridge can log STP port changes to syslog(3) by enabling the net.link.bridge.log_stp variable using sysctl(8). πβ¨
okay bestie, packet filtering time π no more stalling, we're going in.
π PACKET FILTERING π
Packet filtering can be used with literally any firewall package that hooks in via the pfil(9) framework. When filtering is enabled, bridged packets will pass through the filter inbound on the originating interface, on the bridge interface, and outbound on the appropriate interfaces. Either stage can be disabled, your call. The filtering behaviour can be controlled using sysctl(8):
net.link.bridge.pfil_onlyipβ controls the handling of non-IP packets which are not passed topfil(9). Set to1to only allow IP packets to pass (subject to firewall rules), set to0to unconditionally pass all non-IP Ethernet frames. no filter, no problem πnet.link.bridge.pfil_memberβ set to1to enable filtering on the incoming and outgoing member interfaces, set to0to disable it.net.link.bridge.pfil_bridgeβ set to1to enable filtering on the bridge interface, set to0to disable it.net.link.bridge.pfil_local_physβ set to1to additionally filter on the physical interface for locally destined packets. Set to0to disable this feature.net.link.bridge.ipfwβ set to1to enable layer2 filtering withipfirewall(4), set to0to disable it. This needs to be enabled fordummynet(4)support. And here's the plot twist π«’: when ipfw is enabled,pfil_bridgeandpfil_memberwill be disabled so that IPFW is not run twice; these can be re-enabled if desired.net.link.bridge.ipfw_arpβ set to1to enable layer2 ARP filtering withipfirewall(4), set to0to disable it. Requires ipfw to be enabled.
ARP and REVARP packets are forwarded without being filtered and others that are not IP nor IPv6 packets are not forwarded when pfil_onlyip is enabled. IPFW can filter Ethernet types using mac-type so all packets are passed to the filter for processing.
The packets originating from the bridging host will be seen by the filter on the interface that is looked up in the routing table.
The packets destined to the bridging host will be seen by the filter on the interface with the MAC address equal to the packet's destination MAC. Now buckle up, because this next bit is a whole saga π There are situations when some of the bridge members are sharing the same MAC address (for example the vlan(4) interfaces: they are currently sharing the MAC address of the parent physical interface). It is not possible to distinguish between these interfaces using their MAC address, excluding the case when the packet's destination MAC address is equal to the MAC address of the interface on which the packet was entered to the system. In this case the filter will see the incoming packet on this interface. In all other cases the interface seen by the packet filter is chosen from the list of bridge members with the same MAC address and the result strongly depends on the member addition sequence and the actual implementation of if_bridge. It is not recommended to rely on the order chosen by the current if_bridge implementation: it can be changed in the future. periodt.
The previous paragraph is best illustrated with the following pictures. Let
- the MAC address of the incoming packet's destination is
nn:nn:nn:nn:nn:nn, - the interface on which packet entered the system is
ifX, ifXMAC address isxx:xx:xx:xx:xx:xx,- there are possibly other bridge members with the same MAC address
xx:xx:xx:xx:xx:xx, - the bridge has more than one interface that are sharing the same MAC address
yy:yy:yy:yy:yy:yy; we will call themvlanY1,vlanY2, etc.
Then if the MAC address nn:nn:nn:nn:nn:nn is equal to the xx:xx:xx:xx:xx:xx then the filter will see the packet on the interface ifX no matter if there are any other bridge members carrying the same MAC address. But if the MAC address nn:nn:nn:nn:nn:nn is equal to the yy:yy:yy:yy:yy:yy then the interface that will be seen by the filter is one of the vlanYn. It is not possible to predict the name of the actual interface without the knowledge of the system state and the if_bridge implementation details. iykyk.
This problem arises for any bridge members that are sharing the same MAC address, not only to the vlan(4) ones: they we taken just as the example of such situation. So if one wants the filter the locally destined packets based on their interface name, one should be aware of this implication. The described situation will appear at least on the filtering bridges that are doing IP-forwarding; in some of such cases it is better to assign the IP address only to the if_bridge interface and not to the bridge members. Enabling net.link.bridge.pfil_local_phys will let you do the additional filtering on the physical interface. π
π EXAMPLES π
The following when placed in the file /etc/rc.conf will cause a bridge called βbridge0β to be created, and will add the interfaces βwlan0β and βfxp0β to the bridge, and then enable packet forwarding. Such a configuration could be used to implement a simple 802.11-to-Ethernet bridge (assuming the 802.11 interface is in ad-hoc mode). so cozy, so simple β¨
cloned_interfaces="bridge0"
ifconfig_bridge0="addm wlan0 addm fxp0 up"
For the bridge to forward packets, all member interfaces and the bridge need to be up. The above example would also require:
create_args_wlan0="wlanmode hostap"
ifconfig_wlan0="up ssid my_ap mode 11g"
ifconfig_fxp0="up"
Consider a system with two 4-port Ethernet boards. The following will cause a bridge consisting of all 8 ports with Rapid Spanning Tree enabled to be created:
ifconfig bridge0 create
ifconfig bridge0 \
addm fxp0 stp fxp0 \
addm fxp1 stp fxp1 \
addm fxp2 stp fxp2 \
addm fxp3 stp fxp3 \
addm fxp4 stp fxp4 \
addm fxp5 stp fxp5 \
addm fxp6 stp fxp6 \
addm fxp7 stp fxp7 \
up
The bridge can be used as a regular host interface at the same time as bridging between its member ports. In this example, the bridge connects em0 and em1, and will receive its IP address through DHCP:
cloned_interfaces="bridge0"
ifconfig_bridge0="addm em0 addm em1 DHCP"
ifconfig_em0="up"
ifconfig_em1="up"
The bridge can tunnel Ethernet across an IP internet using the EtherIP protocol. This can be combined with ipsec(4) to provide an encrypted connection. Create a gif(4) interface and set the local and remote IP addresses for the tunnel, these are reversed on the remote bridge.
ifconfig gif0 create
ifconfig gif0 tunnel 1.2.3.4 5.6.7.8 up
ifconfig bridge0 create
ifconfig bridge0 addm fxp0 addm gif0 up
heads up bestie β οΈ Note that FreeBSD 6.1, 6.2, 6.3, 7.0, 7.1, and 7.2 have a bug in the EtherIP protocol. For more details and workaround, see gif(4) manual page.
π¦ SEE ALSO π¦
β HISTORY β
The if_bridge driver first appeared in FreeBSD 6.0. a legend since day one, fr fr π
π AUTHORS π
The bridge driver was originally written by Jason L. Wright <jason@thought.net> as part of an undergraduate independent study at the University of North Carolina at Greensboro. academic icon behaviour π
This version of the if_bridge driver has been heavily modified from the original version by Jason R. Thorpe <thorpej@wasabisystems.com>.
Rapid Spanning Tree Protocol (RSTP) support was added by Andrew Thompson <thompsa@FreeBSD.org>.
π BUGS π
The if_bridge driver currently supports only Ethernet and Ethernet-like (e.g., 802.11) network devices, with exactly the same interface MTU size as the bridge device. no cap, that's the whole limitation, and yes it means what it means π
and that's the whole page, bestie!! π«Ά this lil masterpiece is a Debian joint, dated October 16, 2017, and it lives in the manual as IF_BRIDGE(4). go forth and bridge responsibly, mwah πππ¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright 2001 Wasabi Systems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms