xref: /freebsd/share/man/man4/ng_bridge.4 (revision f6e0c471691e0005e450ec968a9fa3b5346a3c45)
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.\"
37*f6e0c471SLutz Donnerhacke.Dd May 13, 2021
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
79631cabbaSGleb SmirnoffThis node type supports an unlimited number of hooks.
80aebf2d1dSArchie CobbsEach connected hook represents a bridged link.
81aebf2d1dSArchie CobbsThe hooks are named
82689561d4SLutz Donnerhacke.Ar link0 ,
83689561d4SLutz Donnerhacke.Ar link1 ,
84aebf2d1dSArchie Cobbsetc.
85aebf2d1dSArchie CobbsTypically these hooks are connected to the
86689561d4SLutz Donnerhacke.Ar lower
87aebf2d1dSArchie Cobbshooks of one or more
88c2d6966aSPhilippe Charnier.Xr ng_ether 4
89aebf2d1dSArchie Cobbsnodes.
90aebf2d1dSArchie CobbsTo connect the host machine to a bridged network, simply connect the
91689561d4SLutz Donnerhacke.Ar upper
92aebf2d1dSArchie Cobbshook of an
93c2d6966aSPhilippe Charnier.Xr ng_ether 4
94aebf2d1dSArchie Cobbsnode to the bridge node.
95f961caf2SLutz Donnerhacke.Pp
96f961caf2SLutz DonnerhackeInstead of naming a hook
97689561d4SLutz Donnerhacke.Ar linkX
98f961caf2SLutz Donnerhackethe hook might be also named
99689561d4SLutz Donnerhacke.Ar uplinkX .
100f961caf2SLutz DonnerhackeThe node does not learn MAC addresses on uplink hooks, which keeps
101f961caf2SLutz Donnerhackethe internal address table small.
102f961caf2SLutz DonnerhackeThis way it is desirable to connect the
103689561d4SLutz Donnerhacke.Ar lower
104f961caf2SLutz Donnerhackehook of an
105f961caf2SLutz Donnerhacke.Xr ng_ether 4
106f961caf2SLutz Donnerhackenode to an
107689561d4SLutz Donnerhacke.Ar uplink
108f961caf2SLutz Donnerhackehook of the bridge, and ignore the complexity of the outside world.
109f961caf2SLutz DonnerhackeFrames with unknown MACs are always sent out to
110689561d4SLutz Donnerhacke.Ar uplink
111f961caf2SLutz Donnerhackehooks, so no functionality is lost.
112c869d905SLutz Donnerhacke.Pp
113c869d905SLutz DonnerhackeFrames with unknown destination MAC addresses are replicated to any
114c869d905SLutz Donnerhackeavailable hook, unless the first connected hook is an
115c869d905SLutz Donnerhacke.Ar uplink
116c869d905SLutz Donnerhackehook.
117c869d905SLutz DonnerhackeIn this case the node assumes, that all unknown MAC addresses are
118c869d905SLutz Donnerhackelocated soley on the
119c869d905SLutz Donnerhacke.Ar uplink
120c869d905SLutz Donnerhackehooks and only those hooks will be used to send out frames with
121c869d905SLutz Donnerhackeunknown destination MACs.
122c869d905SLutz DonnerhackeIf the first connected hook is an
123c869d905SLutz Donnerhacke.Ar link
124c869d905SLutz Donnerhackehook, the node will replicate such frames to all types of hooks,
125c869d905SLutz Donnerhackeeven if
126c869d905SLutz Donnerhacke.Ar uplink
127c869d905SLutz Donnerhackehooks are connected later.
128aebf2d1dSArchie Cobbs.Sh CONTROL MESSAGES
129aebf2d1dSArchie CobbsThis node type supports the generic control messages, plus the
130aebf2d1dSArchie Cobbsfollowing:
131aebf2d1dSArchie Cobbs.Bl -tag -width foo
132689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_SET_CONFIG Pq Ar setconfig
133aebf2d1dSArchie CobbsSet the node configuration.
134aebf2d1dSArchie CobbsThis command takes a
135689561d4SLutz Donnerhacke.Vt "struct ng_bridge_config"
136aebf2d1dSArchie Cobbsas an argument:
1373f610476SRuslan Ermilov.Bd -literal -offset 0n
138aebf2d1dSArchie Cobbs/* Node configuration structure */
139aebf2d1dSArchie Cobbsstruct ng_bridge_config {
140aebf2d1dSArchie Cobbs  u_char      debugLevel;           /* debug level */
1416b99842aSEd Schouten  uint32_t    loopTimeout;          /* link loopback mute time */
1426b99842aSEd Schouten  uint32_t    maxStaleness;         /* max host age before nuking */
1436b99842aSEd Schouten  uint32_t    minStableAge;         /* min time for a stable host */
144aebf2d1dSArchie Cobbs};
145aebf2d1dSArchie Cobbs.Ed
146aebf2d1dSArchie Cobbs.Pp
147aebf2d1dSArchie CobbsThe
148689561d4SLutz Donnerhacke.Va debugLevel
149aebf2d1dSArchie Cobbsfield sets the debug level on the node.
150aebf2d1dSArchie CobbsAt level of 2 or greater, detected loops are logged.
151aebf2d1dSArchie CobbsThe default level is 1.
152aebf2d1dSArchie Cobbs.Pp
153aebf2d1dSArchie CobbsThe
154689561d4SLutz Donnerhacke.Va loopTimeout
155aebf2d1dSArchie Cobbsdetermines how long (in seconds) a looped link is muted.
156aebf2d1dSArchie CobbsThe default is 60 seconds.
157aebf2d1dSArchie CobbsThe
158689561d4SLutz Donnerhacke.Va maxStaleness
159aebf2d1dSArchie Cobbsparameter determines how long a period of inactivity before
160aebf2d1dSArchie Cobbsa host's entry is forgotten.
161aebf2d1dSArchie CobbsThe default is 15 minutes.
162aebf2d1dSArchie CobbsThe
163689561d4SLutz Donnerhacke.Va minStableAge
164aebf2d1dSArchie Cobbsdetermines how quickly a host must jump from one link to another
165aebf2d1dSArchie Cobbsbefore we declare a loopback condition.
166aebf2d1dSArchie CobbsThe default is one second.
167689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_CONFIG Pq Ar getconfig
168aebf2d1dSArchie CobbsReturns the current configuration as a
169689561d4SLutz Donnerhacke.Vt "struct ng_bridge_config" .
170689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_RESET Pq Ar reset
171aebf2d1dSArchie CobbsCauses the node to forget all hosts and unmute all links.
172aebf2d1dSArchie CobbsThe node configuration is not changed.
173689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_STATS Pq Ar getstats
174aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and
175aebf2d1dSArchie Cobbsreturns a
176689561d4SLutz Donnerhacke.Vt "struct ng_bridge_link_stats"
177f961caf2SLutz Donnerhackecontaining statistics for the corresponding
178689561d4SLutz Donnerhacke.Ar link ,
179f961caf2SLutz Donnerhackewhich must be currently connected:
1803f610476SRuslan Ermilov.Bd -literal -offset 0n
181aebf2d1dSArchie Cobbs/* Statistics structure (one for each link) */
182aebf2d1dSArchie Cobbsstruct ng_bridge_link_stats {
1836b99842aSEd Schouten  uint64_t   recvOctets;     /* total octets rec'd on link */
1846b99842aSEd Schouten  uint64_t   recvPackets;    /* total pkts rec'd on link */
1856b99842aSEd Schouten  uint64_t   recvMulticasts; /* multicast pkts rec'd on link */
1866b99842aSEd Schouten  uint64_t   recvBroadcasts; /* broadcast pkts rec'd on link */
1876b99842aSEd Schouten  uint64_t   recvUnknown;    /* pkts rec'd with unknown dest addr */
1886b99842aSEd Schouten  uint64_t   recvRunts;      /* pkts rec'd less than 14 bytes */
1896b99842aSEd Schouten  uint64_t   recvInvalid;    /* pkts rec'd with bogus source addr */
1906b99842aSEd Schouten  uint64_t   xmitOctets;     /* total octets xmit'd on link */
1916b99842aSEd Schouten  uint64_t   xmitPackets;    /* total pkts xmit'd on link */
1926b99842aSEd Schouten  uint64_t   xmitMulticasts; /* multicast pkts xmit'd on link */
1936b99842aSEd Schouten  uint64_t   xmitBroadcasts; /* broadcast pkts xmit'd on link */
1946b99842aSEd Schouten  uint64_t   loopDrops;      /* pkts dropped due to loopback */
1956b99842aSEd Schouten  uint64_t   loopDetects;    /* number of loop detections */
1966b99842aSEd Schouten  uint64_t   memoryFailures; /* times couldn't get mem or mbuf */
197aebf2d1dSArchie Cobbs};
198aebf2d1dSArchie Cobbs.Ed
199f961caf2SLutz Donnerhacke.Pp
200f961caf2SLutz DonnerhackeNegative numbers refer to the
201689561d4SLutz Donnerhacke.Ar uplink
202f961caf2SLutz Donnerhackehooks.
203f961caf2SLutz DonnerhackeSo querying for -7 will get the statistics for hook
204689561d4SLutz Donnerhacke.Ar uplink7 .
205689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_CLR_STATS Pq Ar clrstats
206aebf2d1dSArchie CobbsThis command takes a four byte link number as an argument and
207aebf2d1dSArchie Cobbsclears the statistics for that link.
208689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GETCLR_STATS Pq Ar getclrstats
209aebf2d1dSArchie CobbsSame as
210aebf2d1dSArchie Cobbs.Dv NGM_BRIDGE_GET_STATS ,
211aebf2d1dSArchie Cobbsbut also atomically clears the statistics as well.
212689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_GET_TABLE Pq Ar gettable
213aebf2d1dSArchie CobbsReturns the current host mapping table used to direct packets, in a
214689561d4SLutz Donnerhacke.Vt "struct ng_bridge_host_ary" .
215689561d4SLutz Donnerhacke.It Dv NGM_BRIDGE_SET_PERSISTENT Pq Ar setpersistent
216f8aab721SMarko ZecThis command sets the persistent flag on the node, and takes no arguments.
217b1bd4473SLutz Donnerhacke.It Dv NGM_BRIDGE_MOVE_HOST Pq Ar movehost
218b1bd4473SLutz DonnerhackeThis command takes a
219b1bd4473SLutz Donnerhacke.Vt "struct ng_bridge_move_host"
220b1bd4473SLutz Donnerhackeas an argument.
221b1bd4473SLutz DonnerhackeIt assigns the MAC
222b1bd4473SLutz Donnerhacke.Va addr
223b1bd4473SLutz Donnerhacketo the
224*f6e0c471SLutz Donnerhacke.Va hook .
225b1bd4473SLutz DonnerhackeIf the
226b1bd4473SLutz Donnerhacke.Va hook
227b1bd4473SLutz Donnerhackeis the empty string, the incoming hook of the control message is
228b1bd4473SLutz Donnerhackeused as fallback.
229*f6e0c471SLutz Donnerhacke.Pp
230*f6e0c471SLutz DonnerhackeIf necessary, the MAC is removed from the currently assigned hook and
231*f6e0c471SLutz Donnerhackemoved to the new one.
232*f6e0c471SLutz DonnerhackeIf the MAC is moved faster than
233*f6e0c471SLutz Donnerhacke.Va minStableAge ,
234*f6e0c471SLutz Donnerhackethe hook is considered as a loop and will block traffic for
235*f6e0c471SLutz Donnerhacke.Va loopTimeout
236*f6e0c471SLutz Donnerhackeseconds.
237b1bd4473SLutz Donnerhacke.Bd -literal -offset 0n
238b1bd4473SLutz Donnerhackestruct ng_bridge_move_host {
239b1bd4473SLutz Donnerhacke  u_char  addr[ETHER_ADDR_LEN];	/* ethernet address */
240b1bd4473SLutz Donnerhacke  char    hook[NG_HOOKSIZ];	/* link where addr can be found */
241b1bd4473SLutz Donnerhacke};
242b1bd4473SLutz Donnerhacke.Ed
243aebf2d1dSArchie Cobbs.El
244aebf2d1dSArchie Cobbs.Sh SHUTDOWN
245aebf2d1dSArchie CobbsThis node shuts down upon receipt of a
246aebf2d1dSArchie Cobbs.Dv NGM_SHUTDOWN
24725972509SEdward Tomasz Napieralacontrol message, or when all hooks have been disconnected.
24825972509SEdward Tomasz NapieralaSetting the persistent flag via a
249f8aab721SMarko Zec.Dv NGM_BRIDGE_SET_PERSISTENT
250f8aab721SMarko Zeccontrol message disables automatic node shutdown when the last hook gets
251f8aab721SMarko Zecdisconnected.
2522573be5cSArchie Cobbs.Sh FILES
2532573be5cSArchie Cobbs.Bl -tag -width XXXXXXXX -compact
2542573be5cSArchie Cobbs.It Pa /usr/share/examples/netgraph/ether.bridge
2552573be5cSArchie CobbsExample script showing how to set up a bridging network
2562573be5cSArchie Cobbs.El
257aebf2d1dSArchie Cobbs.Sh SEE ALSO
258b6de9e91SMax Laier.Xr if_bridge 4 ,
259aebf2d1dSArchie Cobbs.Xr netgraph 4 ,
260aebf2d1dSArchie Cobbs.Xr ng_ether 4 ,
261b462702fSRuslan Ermilov.Xr ng_hub 4 ,
262b462702fSRuslan Ermilov.Xr ng_one2many 4 ,
263aebf2d1dSArchie Cobbs.Xr ngctl 8
264aebf2d1dSArchie Cobbs.Sh HISTORY
265aebf2d1dSArchie CobbsThe
266aebf2d1dSArchie Cobbs.Nm
267aebf2d1dSArchie Cobbsnode type was implemented in
268aebf2d1dSArchie Cobbs.Fx 4.2 .
269aebf2d1dSArchie Cobbs.Sh AUTHORS
2706c899950SBaptiste Daroussin.An Archie Cobbs Aq Mt archie@FreeBSD.org
271