1aebf2d1dSArchie Cobbs.\" Copyright (c) 2000 Whistle Communications, Inc. 2aebf2d1dSArchie Cobbs.\" All rights reserved. 3aebf2d1dSArchie Cobbs.\" 4aebf2d1dSArchie Cobbs.\" Subject to the following obligations and disclaimer of warranty, use and 5aebf2d1dSArchie Cobbs.\" redistribution of this software, in source or object code forms, with or 6aebf2d1dSArchie Cobbs.\" without modifications are expressly permitted by Whistle Communications; 7aebf2d1dSArchie Cobbs.\" provided, however, that: 8aebf2d1dSArchie Cobbs.\" 1. Any and all reproductions of the source or object code must include the 9aebf2d1dSArchie Cobbs.\" copyright notice above and the following disclaimer of warranties; and 10aebf2d1dSArchie Cobbs.\" 2. No rights are granted, in any manner or form, to use Whistle 11aebf2d1dSArchie Cobbs.\" Communications, Inc. trademarks, including the mark "WHISTLE 12aebf2d1dSArchie Cobbs.\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as 13aebf2d1dSArchie Cobbs.\" such appears in the above copyright notice or in the software. 14aebf2d1dSArchie Cobbs.\" 15aebf2d1dSArchie Cobbs.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 16aebf2d1dSArchie Cobbs.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 17aebf2d1dSArchie Cobbs.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 18aebf2d1dSArchie Cobbs.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 19aebf2d1dSArchie Cobbs.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 20aebf2d1dSArchie Cobbs.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 21aebf2d1dSArchie Cobbs.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 22aebf2d1dSArchie Cobbs.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 23aebf2d1dSArchie Cobbs.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 24aebf2d1dSArchie Cobbs.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 25aebf2d1dSArchie Cobbs.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 26aebf2d1dSArchie Cobbs.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 27aebf2d1dSArchie Cobbs.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 28aebf2d1dSArchie Cobbs.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29aebf2d1dSArchie Cobbs.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30aebf2d1dSArchie Cobbs.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 31aebf2d1dSArchie Cobbs.\" OF SUCH DAMAGE. 32aebf2d1dSArchie Cobbs.\" 33eddc45e7SJeroen Ruigrok van der Werven.\" Author: Archie Cobbs <archie@FreeBSD.org> 34aebf2d1dSArchie Cobbs.\" 3586a6393aSDavid Marker.Dd April 8, 2024 36aebf2d1dSArchie Cobbs.Dt NG_BRIDGE 4 373d45e180SRuslan Ermilov.Os 38aebf2d1dSArchie Cobbs.Sh NAME 39aebf2d1dSArchie Cobbs.Nm ng_bridge 40aebf2d1dSArchie Cobbs.Nd Ethernet bridging netgraph node type 41aebf2d1dSArchie Cobbs.Sh SYNOPSIS 4232eef9aeSRuslan Ermilov.In sys/types.h 4332eef9aeSRuslan Ermilov.In netgraph/ng_bridge.h 44aebf2d1dSArchie Cobbs.Sh DESCRIPTION 45aebf2d1dSArchie CobbsThe 46aebf2d1dSArchie Cobbs.Nm bridge 47aebf2d1dSArchie Cobbsnode type performs Ethernet bridging over one or more links. 48aebf2d1dSArchie CobbsEach link (represented by a connected hook) is used to transmit 49aebf2d1dSArchie Cobbsand receive raw Ethernet frames. 50aebf2d1dSArchie CobbsAs packets are received, the node learns which link each 51aebf2d1dSArchie Cobbshost resides on. 52aebf2d1dSArchie CobbsPackets unicast to a known host are directed out the appropriate 53aebf2d1dSArchie Cobbslink only, and other links are spared the traffic. 54aebf2d1dSArchie CobbsThis behavior is in contrast to a hub, which always forwards 55aebf2d1dSArchie Cobbsevery received packet to every other link. 56aebf2d1dSArchie Cobbs.Sh LOOP DETECTION 57aebf2d1dSArchie CobbsThe 58aebf2d1dSArchie Cobbs.Nm bridge 59aebf2d1dSArchie Cobbsnode incorporates a simple loop detection algorithm. 60aebf2d1dSArchie CobbsA loop is when two ports are connected to the same physical medium. 61aebf2d1dSArchie CobbsLoops are important to avoid because of packet storms, which severely 62aebf2d1dSArchie Cobbsdegrade performance. 63aebf2d1dSArchie CobbsA packet storm results when the same packet is sent and received 64aebf2d1dSArchie Cobbsover and over again. 65aebf2d1dSArchie CobbsIf a host is detected on link A, and is then detected on link B 66aebf2d1dSArchie Cobbswithin a certain time period after first being detected on link A, 67aebf2d1dSArchie Cobbsthen link B is considered to be a looped back link. 68aebf2d1dSArchie CobbsThe time period is called the minimum stable time. 69aebf2d1dSArchie Cobbs.Pp 70aebf2d1dSArchie CobbsA looped back link will be temporarily muted, i.e., all traffic 71aebf2d1dSArchie Cobbsreceived on that link is ignored. 72aebf2d1dSArchie Cobbs.Sh IPFW PROCESSING 73aebf2d1dSArchie CobbsProcessing of IP packets via the 74aebf2d1dSArchie Cobbs.Xr ipfirewall 4 75aebf2d1dSArchie Cobbsmechanism on a per-link basis is not yet implemented. 76aebf2d1dSArchie Cobbs.Sh HOOKS 77631cabbaSGleb SmirnoffThis node type supports an unlimited number of hooks. 78aebf2d1dSArchie CobbsEach connected hook represents a bridged link. 79aebf2d1dSArchie CobbsThe hooks are named 80689561d4SLutz Donnerhacke.Ar link0 , 81689561d4SLutz Donnerhacke.Ar link1 , 82aebf2d1dSArchie Cobbsetc. 83aebf2d1dSArchie CobbsTypically these hooks are connected to the 84689561d4SLutz Donnerhacke.Ar lower 85aebf2d1dSArchie Cobbshooks of one or more 86c2d6966aSPhilippe Charnier.Xr ng_ether 4 87aebf2d1dSArchie Cobbsnodes. 88aebf2d1dSArchie CobbsTo connect the host machine to a bridged network, simply connect the 89689561d4SLutz Donnerhacke.Ar upper 90aebf2d1dSArchie Cobbshook of an 91c2d6966aSPhilippe Charnier.Xr ng_ether 4 92aebf2d1dSArchie Cobbsnode to the bridge node. 93f961caf2SLutz Donnerhacke.Pp 94f961caf2SLutz DonnerhackeInstead of naming a hook 95689561d4SLutz Donnerhacke.Ar linkX 96f961caf2SLutz Donnerhackethe hook might be also named 97689561d4SLutz Donnerhacke.Ar uplinkX . 98f961caf2SLutz DonnerhackeThe node does not learn MAC addresses on uplink hooks, which keeps 99f961caf2SLutz Donnerhackethe internal address table small. 100f961caf2SLutz DonnerhackeThis way it is desirable to connect the 101689561d4SLutz Donnerhacke.Ar lower 102f961caf2SLutz Donnerhackehook of an 103f961caf2SLutz Donnerhacke.Xr ng_ether 4 104f961caf2SLutz Donnerhackenode to an 105689561d4SLutz Donnerhacke.Ar uplink 106f961caf2SLutz Donnerhackehook of the bridge, and ignore the complexity of the outside world. 107f961caf2SLutz DonnerhackeFrames with unknown MACs are always sent out to 108689561d4SLutz Donnerhacke.Ar uplink 109f961caf2SLutz Donnerhackehooks, so no functionality is lost. 110*e943ecebSGleb SmirnoffThe 111*e943ecebSGleb Smirnoff.Ar uplink0 112*e943ecebSGleb Smirnoffhook is not allowed. 113c869d905SLutz Donnerhacke.Pp 11486a6393aSDavid MarkerThe 11586a6393aSDavid Marker.Ar linkX 11686a6393aSDavid Markerand 11786a6393aSDavid Marker.Ar uplinkX 11886a6393aSDavid Markerhook numbers can be autoassigned. 11986a6393aSDavid MarkerIf a new hook name was specified as 12086a6393aSDavid Marker.Ar link 12186a6393aSDavid Markeror 12286a6393aSDavid Marker.Ar uplink 12386a6393aSDavid Markerthe node will append lowest available valid number to the name of the new hook. 12486a6393aSDavid Marker.Pp 125c869d905SLutz DonnerhackeFrames with unknown destination MAC addresses are replicated to any 126c869d905SLutz Donnerhackeavailable hook, unless the first connected hook is an 127c869d905SLutz Donnerhacke.Ar uplink 128c869d905SLutz Donnerhackehook. 129c869d905SLutz DonnerhackeIn this case the node assumes, that all unknown MAC addresses are 130ffc4f93eSBenedict Reuschlinglocated solely on the 131c869d905SLutz Donnerhacke.Ar uplink 132c869d905SLutz Donnerhackehooks and only those hooks will be used to send out frames with 133c869d905SLutz Donnerhackeunknown destination MACs. 134c869d905SLutz DonnerhackeIf the first connected hook is an 135c869d905SLutz Donnerhacke.Ar link 136c869d905SLutz Donnerhackehook, the node will replicate such frames to all types of hooks, 137c869d905SLutz Donnerhackeeven if 138c869d905SLutz Donnerhacke.Ar uplink 139c869d905SLutz Donnerhackehooks are connected later. 140aebf2d1dSArchie Cobbs.Sh CONTROL MESSAGES 141aebf2d1dSArchie CobbsThis node type supports the generic control messages, plus the 142aebf2d1dSArchie Cobbsfollowing: 143aebf2d1dSArchie Cobbs.Bl -tag -width foo 144689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_SET_CONFIG Pq Ar setconfig 145aebf2d1dSArchie CobbsSet the node configuration. 146aebf2d1dSArchie CobbsThis command takes a 147689561d4SLutz Donnerhacke.Vt "struct ng_bridge_config" 148aebf2d1dSArchie Cobbsas an argument: 1493f610476SRuslan Ermilov.Bd -literal -offset 0n 150aebf2d1dSArchie Cobbs/* Node configuration structure */ 151aebf2d1dSArchie Cobbsstruct ng_bridge_config { 152aebf2d1dSArchie Cobbs u_char debugLevel; /* debug level */ 1536b99842aSEd Schouten uint32_t loopTimeout; /* link loopback mute time */ 1546b99842aSEd Schouten uint32_t maxStaleness; /* max host age before nuking */ 1556b99842aSEd Schouten uint32_t minStableAge; /* min time for a stable host */ 156aebf2d1dSArchie Cobbs}; 157aebf2d1dSArchie Cobbs.Ed 158aebf2d1dSArchie Cobbs.Pp 159aebf2d1dSArchie CobbsThe 160689561d4SLutz Donnerhacke.Va debugLevel 161aebf2d1dSArchie Cobbsfield sets the debug level on the node. 162aebf2d1dSArchie CobbsAt level of 2 or greater, detected loops are logged. 163aebf2d1dSArchie CobbsThe default level is 1. 164aebf2d1dSArchie Cobbs.Pp 165aebf2d1dSArchie CobbsThe 166689561d4SLutz Donnerhacke.Va loopTimeout 167aebf2d1dSArchie Cobbsdetermines how long (in seconds) a looped link is muted. 168aebf2d1dSArchie CobbsThe default is 60 seconds. 169aebf2d1dSArchie CobbsThe 170689561d4SLutz Donnerhacke.Va maxStaleness 171aebf2d1dSArchie Cobbsparameter determines how long a period of inactivity before 172aebf2d1dSArchie Cobbsa host's entry is forgotten. 173aebf2d1dSArchie CobbsThe default is 15 minutes. 174aebf2d1dSArchie CobbsThe 175689561d4SLutz Donnerhacke.Va minStableAge 176aebf2d1dSArchie Cobbsdetermines how quickly a host must jump from one link to another 177aebf2d1dSArchie Cobbsbefore we declare a loopback condition. 178aebf2d1dSArchie CobbsThe default is one second. 179689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_CONFIG Pq Ar getconfig 180aebf2d1dSArchie CobbsReturns the current configuration as a 181689561d4SLutz Donnerhacke.Vt "struct ng_bridge_config" . 182689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_RESET Pq Ar reset 183aebf2d1dSArchie CobbsCauses the node to forget all hosts and unmute all links. 184aebf2d1dSArchie CobbsThe node configuration is not changed. 185689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_STATS Pq Ar getstats 186aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and 187aebf2d1dSArchie Cobbsreturns a 188689561d4SLutz Donnerhacke.Vt "struct ng_bridge_link_stats" 189f961caf2SLutz Donnerhackecontaining statistics for the corresponding 190689561d4SLutz Donnerhacke.Ar link , 191f961caf2SLutz Donnerhackewhich must be currently connected: 1923f610476SRuslan Ermilov.Bd -literal -offset 0n 193aebf2d1dSArchie Cobbs/* Statistics structure (one for each link) */ 194aebf2d1dSArchie Cobbsstruct ng_bridge_link_stats { 1956b99842aSEd Schouten uint64_t recvOctets; /* total octets rec'd on link */ 1966b99842aSEd Schouten uint64_t recvPackets; /* total pkts rec'd on link */ 1976b99842aSEd Schouten uint64_t recvMulticasts; /* multicast pkts rec'd on link */ 1986b99842aSEd Schouten uint64_t recvBroadcasts; /* broadcast pkts rec'd on link */ 1996b99842aSEd Schouten uint64_t recvUnknown; /* pkts rec'd with unknown dest addr */ 2006b99842aSEd Schouten uint64_t recvRunts; /* pkts rec'd less than 14 bytes */ 2016b99842aSEd Schouten uint64_t recvInvalid; /* pkts rec'd with bogus source addr */ 2026b99842aSEd Schouten uint64_t xmitOctets; /* total octets xmit'd on link */ 2036b99842aSEd Schouten uint64_t xmitPackets; /* total pkts xmit'd on link */ 2046b99842aSEd Schouten uint64_t xmitMulticasts; /* multicast pkts xmit'd on link */ 2056b99842aSEd Schouten uint64_t xmitBroadcasts; /* broadcast pkts xmit'd on link */ 2066b99842aSEd Schouten uint64_t loopDrops; /* pkts dropped due to loopback */ 2076b99842aSEd Schouten uint64_t loopDetects; /* number of loop detections */ 2086b99842aSEd Schouten uint64_t memoryFailures; /* times couldn't get mem or mbuf */ 209aebf2d1dSArchie Cobbs}; 210aebf2d1dSArchie Cobbs.Ed 211f961caf2SLutz Donnerhacke.Pp 212f961caf2SLutz DonnerhackeNegative numbers refer to the 213689561d4SLutz Donnerhacke.Ar uplink 214f961caf2SLutz Donnerhackehooks. 215f961caf2SLutz DonnerhackeSo querying for -7 will get the statistics for hook 216689561d4SLutz Donnerhacke.Ar uplink7 . 217689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_CLR_STATS Pq Ar clrstats 218aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and 219aebf2d1dSArchie Cobbsclears the statistics for that link. 220689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GETCLR_STATS Pq Ar getclrstats 221aebf2d1dSArchie CobbsSame as 222aebf2d1dSArchie Cobbs.Dv NGM_BRIDGE_GET_STATS , 223aebf2d1dSArchie Cobbsbut also atomically clears the statistics as well. 224689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_TABLE Pq Ar gettable 225aebf2d1dSArchie CobbsReturns the current host mapping table used to direct packets, in a 226689561d4SLutz Donnerhacke.Vt "struct ng_bridge_host_ary" . 227689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_SET_PERSISTENT Pq Ar setpersistent 228f8aab721SMarko ZecThis command sets the persistent flag on the node, and takes no arguments. 229b1bd4473SLutz Donnerhacke.It Dv NGM_BRIDGE_MOVE_HOST Pq Ar movehost 230b1bd4473SLutz DonnerhackeThis command takes a 231b1bd4473SLutz Donnerhacke.Vt "struct ng_bridge_move_host" 232b1bd4473SLutz Donnerhackeas an argument. 233b1bd4473SLutz DonnerhackeIt assigns the MAC 234b1bd4473SLutz Donnerhacke.Va addr 235b1bd4473SLutz Donnerhacketo the 236f6e0c471SLutz Donnerhacke.Va hook . 237b1bd4473SLutz DonnerhackeIf the 238b1bd4473SLutz Donnerhacke.Va hook 239b1bd4473SLutz Donnerhackeis the empty string, the incoming hook of the control message is 240b1bd4473SLutz Donnerhackeused as fallback. 241f6e0c471SLutz Donnerhacke.Pp 242f6e0c471SLutz DonnerhackeIf necessary, the MAC is removed from the currently assigned hook and 243f6e0c471SLutz Donnerhackemoved to the new one. 244f6e0c471SLutz DonnerhackeIf the MAC is moved faster than 245f6e0c471SLutz Donnerhacke.Va minStableAge , 246f6e0c471SLutz Donnerhackethe hook is considered as a loop and will block traffic for 247f6e0c471SLutz Donnerhacke.Va loopTimeout 248f6e0c471SLutz Donnerhackeseconds. 249b1bd4473SLutz Donnerhacke.Bd -literal -offset 0n 250b1bd4473SLutz Donnerhackestruct ng_bridge_move_host { 251b1bd4473SLutz Donnerhacke u_char addr[ETHER_ADDR_LEN]; /* ethernet address */ 252b1bd4473SLutz Donnerhacke char hook[NG_HOOKSIZ]; /* link where addr can be found */ 253b1bd4473SLutz Donnerhacke}; 254b1bd4473SLutz Donnerhacke.Ed 255aebf2d1dSArchie Cobbs.El 256aebf2d1dSArchie Cobbs.Sh SHUTDOWN 257aebf2d1dSArchie CobbsThis node shuts down upon receipt of a 258aebf2d1dSArchie Cobbs.Dv NGM_SHUTDOWN 25925972509SEdward Tomasz Napieralacontrol message, or when all hooks have been disconnected. 26025972509SEdward Tomasz NapieralaSetting the persistent flag via a 261f8aab721SMarko Zec.Dv NGM_BRIDGE_SET_PERSISTENT 262f8aab721SMarko Zeccontrol message disables automatic node shutdown when the last hook gets 263f8aab721SMarko Zecdisconnected. 2642573be5cSArchie Cobbs.Sh FILES 2652573be5cSArchie Cobbs.Bl -tag -width XXXXXXXX -compact 2662573be5cSArchie Cobbs.It Pa /usr/share/examples/netgraph/ether.bridge 2672573be5cSArchie CobbsExample script showing how to set up a bridging network 2682573be5cSArchie Cobbs.El 269aebf2d1dSArchie Cobbs.Sh SEE ALSO 270b6de9e91SMax Laier.Xr if_bridge 4 , 271aebf2d1dSArchie Cobbs.Xr netgraph 4 , 272aebf2d1dSArchie Cobbs.Xr ng_ether 4 , 273b462702fSRuslan Ermilov.Xr ng_hub 4 , 274b462702fSRuslan Ermilov.Xr ng_one2many 4 , 275aebf2d1dSArchie Cobbs.Xr ngctl 8 276aebf2d1dSArchie Cobbs.Sh HISTORY 277aebf2d1dSArchie CobbsThe 278aebf2d1dSArchie Cobbs.Nm 279aebf2d1dSArchie Cobbsnode type was implemented in 280aebf2d1dSArchie Cobbs.Fx 4.2 . 281aebf2d1dSArchie Cobbs.Sh AUTHORS 2826c899950SBaptiste Daroussin.An Archie Cobbs Aq Mt archie@FreeBSD.org 283*e943ecebSGleb Smirnoff.Sh BUGS 284*e943ecebSGleb SmirnoffThe 285*e943ecebSGleb Smirnoff.Nm 286*e943ecebSGleb Smirnoffnode refuses to create the 287*e943ecebSGleb Smirnoff.Ar uplink0 288*e943ecebSGleb Smirnoffhook to avoid later ambiguity with the 289*e943ecebSGleb Smirnoff.Dv NGM_BRIDGE_GET_STATS 290*e943ecebSGleb Smirnoffmessage. 291