xref: /freebsd/share/man/man4/ng_bridge.4 (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1.\" Copyright (c) 2000 Whistle Communications, Inc.
2.\" All rights reserved.
3.\"
4.\" Subject to the following obligations and disclaimer of warranty, use and
5.\" redistribution of this software, in source or object code forms, with or
6.\" without modifications are expressly permitted by Whistle Communications;
7.\" provided, however, that:
8.\" 1. Any and all reproductions of the source or object code must include the
9.\"    copyright notice above and the following disclaimer of warranties; and
10.\" 2. No rights are granted, in any manner or form, to use Whistle
11.\"    Communications, Inc. trademarks, including the mark "WHISTLE
12.\"    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
13.\"    such appears in the above copyright notice or in the software.
14.\"
15.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
16.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
17.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
18.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
19.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
20.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
21.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
22.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
23.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
24.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
25.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
27.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
31.\" OF SUCH DAMAGE.
32.\"
33.\" Author: Archie Cobbs <archie@FreeBSD.org>
34.\"
35.Dd May 13, 2021
36.Dt NG_BRIDGE 4
37.Os
38.Sh NAME
39.Nm ng_bridge
40.Nd Ethernet bridging netgraph node type
41.Sh SYNOPSIS
42.In sys/types.h
43.In netgraph/ng_bridge.h
44.Sh DESCRIPTION
45The
46.Nm bridge
47node type performs Ethernet bridging over one or more links.
48Each link (represented by a connected hook) is used to transmit
49and receive raw Ethernet frames.
50As packets are received, the node learns which link each
51host resides on.
52Packets unicast to a known host are directed out the appropriate
53link only, and other links are spared the traffic.
54This behavior is in contrast to a hub, which always forwards
55every received packet to every other link.
56.Sh LOOP DETECTION
57The
58.Nm bridge
59node incorporates a simple loop detection algorithm.
60A loop is when two ports are connected to the same physical medium.
61Loops are important to avoid because of packet storms, which severely
62degrade performance.
63A packet storm results when the same packet is sent and received
64over and over again.
65If a host is detected on link A, and is then detected on link B
66within a certain time period after first being detected on link A,
67then link B is considered to be a looped back link.
68The time period is called the minimum stable time.
69.Pp
70A looped back link will be temporarily muted, i.e., all traffic
71received on that link is ignored.
72.Sh IPFW PROCESSING
73Processing of IP packets via the
74.Xr ipfirewall 4
75mechanism on a per-link basis is not yet implemented.
76.Sh HOOKS
77This node type supports an unlimited number of hooks.
78Each connected hook represents a bridged link.
79The hooks are named
80.Ar link0 ,
81.Ar link1 ,
82etc.
83Typically these hooks are connected to the
84.Ar lower
85hooks of one or more
86.Xr ng_ether 4
87nodes.
88To connect the host machine to a bridged network, simply connect the
89.Ar upper
90hook of an
91.Xr ng_ether 4
92node to the bridge node.
93.Pp
94Instead of naming a hook
95.Ar linkX
96the hook might be also named
97.Ar uplinkX .
98The node does not learn MAC addresses on uplink hooks, which keeps
99the internal address table small.
100This way it is desirable to connect the
101.Ar lower
102hook of an
103.Xr ng_ether 4
104node to an
105.Ar uplink
106hook of the bridge, and ignore the complexity of the outside world.
107Frames with unknown MACs are always sent out to
108.Ar uplink
109hooks, so no functionality is lost.
110.Pp
111Frames with unknown destination MAC addresses are replicated to any
112available hook, unless the first connected hook is an
113.Ar uplink
114hook.
115In this case the node assumes, that all unknown MAC addresses are
116located solely on the
117.Ar uplink
118hooks and only those hooks will be used to send out frames with
119unknown destination MACs.
120If the first connected hook is an
121.Ar link
122hook, the node will replicate such frames to all types of hooks,
123even if
124.Ar uplink
125hooks are connected later.
126.Sh CONTROL MESSAGES
127This node type supports the generic control messages, plus the
128following:
129.Bl -tag -width foo
130.It Dv NGM_BRIDGE_SET_CONFIG Pq Ar setconfig
131Set the node configuration.
132This command takes a
133.Vt "struct ng_bridge_config"
134as an argument:
135.Bd -literal -offset 0n
136/* Node configuration structure */
137struct ng_bridge_config {
138  u_char      debugLevel;           /* debug level */
139  uint32_t    loopTimeout;          /* link loopback mute time */
140  uint32_t    maxStaleness;         /* max host age before nuking */
141  uint32_t    minStableAge;         /* min time for a stable host */
142};
143.Ed
144.Pp
145The
146.Va debugLevel
147field sets the debug level on the node.
148At level of 2 or greater, detected loops are logged.
149The default level is 1.
150.Pp
151The
152.Va loopTimeout
153determines how long (in seconds) a looped link is muted.
154The default is 60 seconds.
155The
156.Va maxStaleness
157parameter determines how long a period of inactivity before
158a host's entry is forgotten.
159The default is 15 minutes.
160The
161.Va minStableAge
162determines how quickly a host must jump from one link to another
163before we declare a loopback condition.
164The default is one second.
165.It Dv NGM_BRIDGE_GET_CONFIG Pq Ar getconfig
166Returns the current configuration as a
167.Vt "struct ng_bridge_config" .
168.It Dv NGM_BRIDGE_RESET Pq Ar reset
169Causes the node to forget all hosts and unmute all links.
170The node configuration is not changed.
171.It Dv NGM_BRIDGE_GET_STATS Pq Ar getstats
172This command takes a four byte link number as an argument and
173returns a
174.Vt "struct ng_bridge_link_stats"
175containing statistics for the corresponding
176.Ar link ,
177which must be currently connected:
178.Bd -literal -offset 0n
179/* Statistics structure (one for each link) */
180struct ng_bridge_link_stats {
181  uint64_t   recvOctets;     /* total octets rec'd on link */
182  uint64_t   recvPackets;    /* total pkts rec'd on link */
183  uint64_t   recvMulticasts; /* multicast pkts rec'd on link */
184  uint64_t   recvBroadcasts; /* broadcast pkts rec'd on link */
185  uint64_t   recvUnknown;    /* pkts rec'd with unknown dest addr */
186  uint64_t   recvRunts;      /* pkts rec'd less than 14 bytes */
187  uint64_t   recvInvalid;    /* pkts rec'd with bogus source addr */
188  uint64_t   xmitOctets;     /* total octets xmit'd on link */
189  uint64_t   xmitPackets;    /* total pkts xmit'd on link */
190  uint64_t   xmitMulticasts; /* multicast pkts xmit'd on link */
191  uint64_t   xmitBroadcasts; /* broadcast pkts xmit'd on link */
192  uint64_t   loopDrops;      /* pkts dropped due to loopback */
193  uint64_t   loopDetects;    /* number of loop detections */
194  uint64_t   memoryFailures; /* times couldn't get mem or mbuf */
195};
196.Ed
197.Pp
198Negative numbers refer to the
199.Ar uplink
200hooks.
201So querying for -7 will get the statistics for hook
202.Ar uplink7 .
203.It Dv NGM_BRIDGE_CLR_STATS Pq Ar clrstats
204This command takes a four byte link number as an argument and
205clears the statistics for that link.
206.It Dv NGM_BRIDGE_GETCLR_STATS Pq Ar getclrstats
207Same as
208.Dv NGM_BRIDGE_GET_STATS ,
209but also atomically clears the statistics as well.
210.It Dv NGM_BRIDGE_GET_TABLE Pq Ar gettable
211Returns the current host mapping table used to direct packets, in a
212.Vt "struct ng_bridge_host_ary" .
213.It Dv NGM_BRIDGE_SET_PERSISTENT Pq Ar setpersistent
214This command sets the persistent flag on the node, and takes no arguments.
215.It Dv NGM_BRIDGE_MOVE_HOST Pq Ar movehost
216This command takes a
217.Vt "struct ng_bridge_move_host"
218as an argument.
219It assigns the MAC
220.Va addr
221to the
222.Va hook .
223If the
224.Va hook
225is the empty string, the incoming hook of the control message is
226used as fallback.
227.Pp
228If necessary, the MAC is removed from the currently assigned hook and
229moved to the new one.
230If the MAC is moved faster than
231.Va minStableAge ,
232the hook is considered as a loop and will block traffic for
233.Va loopTimeout
234seconds.
235.Bd -literal -offset 0n
236struct ng_bridge_move_host {
237  u_char  addr[ETHER_ADDR_LEN];	/* ethernet address */
238  char    hook[NG_HOOKSIZ];	/* link where addr can be found */
239};
240.Ed
241.El
242.Sh SHUTDOWN
243This node shuts down upon receipt of a
244.Dv NGM_SHUTDOWN
245control message, or when all hooks have been disconnected.
246Setting the persistent flag via a
247.Dv NGM_BRIDGE_SET_PERSISTENT
248control message disables automatic node shutdown when the last hook gets
249disconnected.
250.Sh FILES
251.Bl -tag -width XXXXXXXX -compact
252.It Pa /usr/share/examples/netgraph/ether.bridge
253Example script showing how to set up a bridging network
254.El
255.Sh SEE ALSO
256.Xr if_bridge 4 ,
257.Xr netgraph 4 ,
258.Xr ng_ether 4 ,
259.Xr ng_hub 4 ,
260.Xr ng_one2many 4 ,
261.Xr ngctl 8
262.Sh HISTORY
263The
264.Nm
265node type was implemented in
266.Fx 4.2 .
267.Sh AUTHORS
268.An Archie Cobbs Aq Mt archie@FreeBSD.org
269