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.\" 35aebf2d1dSArchie Cobbs.\" $FreeBSD$ 36aebf2d1dSArchie Cobbs.\" 37aebf2d1dSArchie Cobbs.Dd August 31, 2000 38aebf2d1dSArchie Cobbs.Dt NG_BRIDGE 4 393d45e180SRuslan Ermilov.Os 40aebf2d1dSArchie Cobbs.Sh NAME 41aebf2d1dSArchie Cobbs.Nm ng_bridge 42aebf2d1dSArchie Cobbs.Nd Ethernet bridging netgraph node type 43aebf2d1dSArchie Cobbs.Sh SYNOPSIS 4432eef9aeSRuslan Ermilov.In sys/types.h 4532eef9aeSRuslan Ermilov.In netgraph/ng_bridge.h 46aebf2d1dSArchie Cobbs.Sh DESCRIPTION 47aebf2d1dSArchie CobbsThe 48aebf2d1dSArchie Cobbs.Nm bridge 49aebf2d1dSArchie Cobbsnode type performs Ethernet bridging over one or more links. 50aebf2d1dSArchie CobbsEach link (represented by a connected hook) is used to transmit 51aebf2d1dSArchie Cobbsand receive raw Ethernet frames. 52aebf2d1dSArchie CobbsAs packets are received, the node learns which link each 53aebf2d1dSArchie Cobbshost resides on. 54aebf2d1dSArchie CobbsPackets unicast to a known host are directed out the appropriate 55aebf2d1dSArchie Cobbslink only, and other links are spared the traffic. 56aebf2d1dSArchie CobbsThis behavior is in contrast to a hub, which always forwards 57aebf2d1dSArchie Cobbsevery received packet to every other link. 58aebf2d1dSArchie Cobbs.Sh LOOP DETECTION 59aebf2d1dSArchie CobbsThe 60aebf2d1dSArchie Cobbs.Nm bridge 61aebf2d1dSArchie Cobbsnode incorporates a simple loop detection algorithm. 62aebf2d1dSArchie CobbsA loop is when two ports are connected to the same physical medium. 63aebf2d1dSArchie CobbsLoops are important to avoid because of packet storms, which severely 64aebf2d1dSArchie Cobbsdegrade performance. 65aebf2d1dSArchie CobbsA packet storm results when the same packet is sent and received 66aebf2d1dSArchie Cobbsover and over again. 67aebf2d1dSArchie CobbsIf a host is detected on link A, and is then detected on link B 68aebf2d1dSArchie Cobbswithin a certain time period after first being detected on link A, 69aebf2d1dSArchie Cobbsthen link B is considered to be a looped back link. 70aebf2d1dSArchie CobbsThe time period is called the minimum stable time. 71aebf2d1dSArchie Cobbs.Pp 72aebf2d1dSArchie CobbsA looped back link will be temporarily muted, i.e., all traffic 73aebf2d1dSArchie Cobbsreceived on that link is ignored. 74aebf2d1dSArchie Cobbs.Sh IPFW PROCESSING 75aebf2d1dSArchie CobbsProcessing of IP packets via the 76aebf2d1dSArchie Cobbs.Xr ipfirewall 4 77aebf2d1dSArchie Cobbsmechanism on a per-link basis is not yet implemented. 78aebf2d1dSArchie Cobbs.Sh HOOKS 79aebf2d1dSArchie CobbsThis node type supports up to 80aebf2d1dSArchie Cobbs.Dv NG_BRIDGE_MAX_LINKS 81aebf2d1dSArchie Cobbshooks. 82aebf2d1dSArchie CobbsEach connected hook represents a bridged link. 83aebf2d1dSArchie CobbsThe hooks are named 84aebf2d1dSArchie Cobbs.Dv link0 , 85aebf2d1dSArchie Cobbs.Dv link1 , 86aebf2d1dSArchie Cobbsetc. 87aebf2d1dSArchie CobbsTypically these hooks are connected to the 88aebf2d1dSArchie Cobbs.Dv lower 89aebf2d1dSArchie Cobbshooks of one or more 90c2d6966aSPhilippe Charnier.Xr ng_ether 4 91aebf2d1dSArchie Cobbsnodes. 92aebf2d1dSArchie CobbsTo connect the host machine to a bridged network, simply connect the 93aebf2d1dSArchie Cobbs.Dv upper 94aebf2d1dSArchie Cobbshook of an 95c2d6966aSPhilippe Charnier.Xr ng_ether 4 96aebf2d1dSArchie Cobbsnode to the bridge node. 97aebf2d1dSArchie Cobbs.Sh CONTROL MESSAGES 98aebf2d1dSArchie CobbsThis node type supports the generic control messages, plus the 99aebf2d1dSArchie Cobbsfollowing: 100aebf2d1dSArchie Cobbs.Bl -tag -width foo 101aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_SET_CONFIG 102aebf2d1dSArchie CobbsSet the node configuration. 103aebf2d1dSArchie CobbsThis command takes a 104aebf2d1dSArchie Cobbs.Dv "struct ng_bridge_config" 105aebf2d1dSArchie Cobbsas an argument: 1063f610476SRuslan Ermilov.Bd -literal -offset 0n 107aebf2d1dSArchie Cobbs/* Node configuration structure */ 108aebf2d1dSArchie Cobbsstruct ng_bridge_config { 109aebf2d1dSArchie Cobbs u_char ipfw[NG_BRIDGE_MAX_LINKS]; /* enable ipfw */ 110aebf2d1dSArchie Cobbs u_char debugLevel; /* debug level */ 111aebf2d1dSArchie Cobbs u_int32_t loopTimeout; /* link loopback mute time */ 112aebf2d1dSArchie Cobbs u_int32_t maxStaleness; /* max host age before nuking */ 113aebf2d1dSArchie Cobbs u_int32_t minStableAge; /* min time for a stable host */ 114aebf2d1dSArchie Cobbs}; 115aebf2d1dSArchie Cobbs.Ed 116aebf2d1dSArchie Cobbs.Pp 117aebf2d1dSArchie CobbsThe 118aebf2d1dSArchie Cobbs.Dv ipfw 119aebf2d1dSArchie Cobbsarray enables 120aebf2d1dSArchie Cobbs.Xr ipfirewall 4 121aebf2d1dSArchie Cobbsprocessing of IP packets received on the corresponding links. 122aebf2d1dSArchie CobbsThe 123aebf2d1dSArchie Cobbs.Dv debugLevel 124aebf2d1dSArchie Cobbsfield sets the debug level on the node. 125aebf2d1dSArchie CobbsAt level of 2 or greater, detected loops are logged. 126aebf2d1dSArchie CobbsThe default level is 1. 127aebf2d1dSArchie Cobbs.Pp 128aebf2d1dSArchie CobbsThe 129aebf2d1dSArchie Cobbs.Dv loopTimeout 130aebf2d1dSArchie Cobbsdetermines how long (in seconds) a looped link is muted. 131aebf2d1dSArchie CobbsThe default is 60 seconds. 132aebf2d1dSArchie CobbsThe 133aebf2d1dSArchie Cobbs.Dv maxStaleness 134aebf2d1dSArchie Cobbsparameter determines how long a period of inactivity before 135aebf2d1dSArchie Cobbsa host's entry is forgotten. 136aebf2d1dSArchie CobbsThe default is 15 minutes. 137aebf2d1dSArchie CobbsThe 138aebf2d1dSArchie Cobbs.Dv minStableAge 139aebf2d1dSArchie Cobbsdetermines how quickly a host must jump from one link to another 140aebf2d1dSArchie Cobbsbefore we declare a loopback condition. 141aebf2d1dSArchie CobbsThe default is one second. 142aebf2d1dSArchie Cobbs.Pp 143aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_GET_CONFIG 144aebf2d1dSArchie CobbsReturns the current configuration as a 145aebf2d1dSArchie Cobbs.Dv "struct ng_bridge_config" . 146aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_RESET 147aebf2d1dSArchie CobbsCauses the node to forget all hosts and unmute all links. 148aebf2d1dSArchie CobbsThe node configuration is not changed. 149aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_GET_STATS 150aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and 151aebf2d1dSArchie Cobbsreturns a 152aebf2d1dSArchie Cobbs.Dv "struct ng_bridge_link_stats" 153aebf2d1dSArchie Cobbscontaining statistics for the corresponding link, which must be 154aebf2d1dSArchie Cobbscurrently connected: 1553f610476SRuslan Ermilov.Bd -literal -offset 0n 156aebf2d1dSArchie Cobbs/* Statistics structure (one for each link) */ 157aebf2d1dSArchie Cobbsstruct ng_bridge_link_stats { 158aebf2d1dSArchie Cobbs u_int64_t recvOctets; /* total octets rec'd on link */ 159aebf2d1dSArchie Cobbs u_int64_t recvPackets; /* total pkts rec'd on link */ 160aebf2d1dSArchie Cobbs u_int64_t recvMulticasts; /* multicast pkts rec'd on link */ 161aebf2d1dSArchie Cobbs u_int64_t recvBroadcasts; /* broadcast pkts rec'd on link */ 162aebf2d1dSArchie Cobbs u_int64_t recvUnknown; /* pkts rec'd with unknown dest addr */ 163aebf2d1dSArchie Cobbs u_int64_t recvRunts; /* pkts rec'd less than 14 bytes */ 164aebf2d1dSArchie Cobbs u_int64_t recvInvalid; /* pkts rec'd with bogus source addr */ 165aebf2d1dSArchie Cobbs u_int64_t xmitOctets; /* total octets xmit'd on link */ 166aebf2d1dSArchie Cobbs u_int64_t xmitPackets; /* total pkts xmit'd on link */ 167aebf2d1dSArchie Cobbs u_int64_t xmitMulticasts; /* multicast pkts xmit'd on link */ 168aebf2d1dSArchie Cobbs u_int64_t xmitBroadcasts; /* broadcast pkts xmit'd on link */ 169aebf2d1dSArchie Cobbs u_int64_t loopDrops; /* pkts dropped due to loopback */ 170aebf2d1dSArchie Cobbs u_int64_t loopDetects; /* number of loop detections */ 171aebf2d1dSArchie Cobbs u_int64_t memoryFailures; /* times couldn't get mem or mbuf */ 172aebf2d1dSArchie Cobbs}; 173aebf2d1dSArchie Cobbs.Ed 174aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_CLR_STATS 175aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and 176aebf2d1dSArchie Cobbsclears the statistics for that link. 177aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_GETCLR_STATS 178aebf2d1dSArchie CobbsSame as 179aebf2d1dSArchie Cobbs.Dv NGM_BRIDGE_GET_STATS , 180aebf2d1dSArchie Cobbsbut also atomically clears the statistics as well. 181aebf2d1dSArchie Cobbs.It Dv NGM_BRIDGE_GET_TABLE 182aebf2d1dSArchie CobbsReturns the current host mapping table used to direct packets, in a 183aebf2d1dSArchie Cobbs.Dv "struct ng_bridge_host_ary" . 184aebf2d1dSArchie Cobbs.El 185aebf2d1dSArchie Cobbs.Sh SHUTDOWN 186aebf2d1dSArchie CobbsThis node shuts down upon receipt of a 187aebf2d1dSArchie Cobbs.Dv NGM_SHUTDOWN 188aebf2d1dSArchie Cobbscontrol message, or when all hooks have been disconnected. 1892573be5cSArchie Cobbs.Sh FILES 1902573be5cSArchie Cobbs.Bl -tag -width XXXXXXXX -compact 1912573be5cSArchie Cobbs.It Pa /usr/share/examples/netgraph/ether.bridge 1922573be5cSArchie CobbsExample script showing how to set up a bridging network 1932573be5cSArchie Cobbs.El 194aebf2d1dSArchie Cobbs.Sh SEE ALSO 195aebf2d1dSArchie Cobbs.Xr bridge 4 , 196aebf2d1dSArchie Cobbs.Xr netgraph 4 , 197aebf2d1dSArchie Cobbs.Xr ng_ether 4 , 198aebf2d1dSArchie Cobbs.Xr ngctl 8 199aebf2d1dSArchie Cobbs.Sh HISTORY 200aebf2d1dSArchie CobbsThe 201aebf2d1dSArchie Cobbs.Nm 202aebf2d1dSArchie Cobbsnode type was implemented in 203aebf2d1dSArchie Cobbs.Fx 4.2 . 204aebf2d1dSArchie Cobbs.Sh AUTHORS 205eddc45e7SJeroen Ruigrok van der Werven.An Archie Cobbs Aq archie@FreeBSD.org 206