Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157105516
D23963.id81875.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D23963.id81875.diff
View Options
Index: share/man/man4/ng_bridge.4
===================================================================
--- share/man/man4/ng_bridge.4
+++ share/man/man4/ng_bridge.4
@@ -34,7 +34,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd October 2, 2019
+.Dd January 08, 2021
.Dt NG_BRIDGE 4
.Os
.Sh NAME
@@ -92,6 +92,39 @@
hook of an
.Xr ng_ether 4
node to the bridge node.
+.Pp
+Instead of naming a hook
+.Dv linkX
+the hook might be also named
+.Dv uplinkX .
+The node does not learn MAC addresses on uplink hooks, which keeps
+the internal address table small.
+This way it is desirable to connect the
+.Dv lower
+hook of an
+.Xr ng_ether 4
+node to an
+.Dv uplink
+hook of the bridge, and ignore the complexity of the outside world.
+Frames with unknown MACs are always sent out to
+.Dv uplink
+hooks, so no functionality is lost.
+.Pp
+Frames with unknown destination MAC addresses are replicated to any
+available hook, unless the first connected hook is an
+.Dv uplink
+hook.
+In this case the node assumes, that all unknown MAC addresses are
+located soley on the
+.Dv uplink
+hooks and only those hooks will be used to send out frames with
+unknown destination MACs.
+If the first connected hook is an
+.Dv link
+hook, the node will replicate such frames to all types of hooks,
+even if
+.Dv uplink
+hooks are connected later.
.Sh CONTROL MESSAGES
This node type supports the generic control messages, plus the
following:
@@ -141,8 +174,9 @@
This command takes a four byte link number as an argument and
returns a
.Dv "struct ng_bridge_link_stats"
-containing statistics for the corresponding link, which must be
-currently connected:
+containing statistics for the corresponding
+.Dv link ,
+which must be currently connected:
.Bd -literal -offset 0n
/* Statistics structure (one for each link) */
struct ng_bridge_link_stats {
@@ -162,6 +196,12 @@
uint64_t memoryFailures; /* times couldn't get mem or mbuf */
};
.Ed
+.Pp
+Negative numbers refer to the
+.Dv uplink
+hooks.
+So querying for -7 will get the statistics for hook
+.Dv uplink7 .
.It Dv NGM_BRIDGE_CLR_STATS Pq Ic clrstats
This command takes a four byte link number as an argument and
clears the statistics for that link.
Index: sys/netgraph/ng_bridge.h
===================================================================
--- sys/netgraph/ng_bridge.h
+++ sys/netgraph/ng_bridge.h
@@ -64,6 +64,8 @@
/* Hook names */
#define NG_BRIDGE_HOOK_LINK_PREFIX "link" /* append decimal integer */
#define NG_BRIDGE_HOOK_LINK_FMT "link%d" /* for use with printf(3) */
+#define NG_BRIDGE_HOOK_UPLINK_PREFIX "uplink" /* append decimal integer */
+#define NG_BRIDGE_HOOK_UPLINK_FMT "uplink%d" /* for use with printf(3) */
/* Node configuration structure */
struct ng_bridge_config {
Index: sys/netgraph/ng_bridge.c
===================================================================
--- sys/netgraph/ng_bridge.c
+++ sys/netgraph/ng_bridge.c
@@ -91,6 +91,8 @@
struct ng_bridge_link {
hook_p hook; /* netgraph hook */
u_int16_t loopCount; /* loop ignore timer */
+ unsigned int learnMac : 1, /* autolearn macs */
+ sendUnknown : 1;/* send unknown macs out */
struct ng_bridge_link_stats stats; /* link stats */
};
@@ -103,7 +105,8 @@
u_int numBuckets; /* num buckets in table */
u_int hashMask; /* numBuckets - 1 */
int numLinks; /* num connected links */
- int persistent; /* can exist w/o hooks */
+ unsigned int persistent : 1, /* can exist w/o hooks */
+ sendUnknown : 1;/* links receive unknowns by default */
struct callout timer; /* one second periodic timer */
};
typedef struct ng_bridge_private *priv_p;
@@ -307,6 +310,7 @@
priv->conf.loopTimeout = DEFAULT_LOOP_TIMEOUT;
priv->conf.maxStaleness = DEFAULT_MAX_STALENESS;
priv->conf.minStableAge = DEFAULT_MIN_STABLE_AGE;
+ priv->sendUnknown = 1; /* classic bridge */
/*
* This node has all kinds of stuff that could be screwed by SMP.
@@ -334,38 +338,52 @@
ng_bridge_newhook(node_p node, hook_p hook, const char *name)
{
const priv_p priv = NG_NODE_PRIVATE(node);
+ char linkName[NG_HOOKSIZ];
+ u_int32_t linkNum;
+ link_p link;
+ const char *prefix = NG_BRIDGE_HOOK_LINK_PREFIX;
+ bool isUplink;
/* Check for a link hook */
- if (strlen(name) > strlen(NG_BRIDGE_HOOK_LINK_PREFIX)) {
- char linkName[NG_HOOKSIZ];
- u_int32_t linkNum;
- link_p link;
-
- /* primitive parsing */
- linkNum = strtoul(name + strlen(NG_BRIDGE_HOOK_LINK_PREFIX),
- NULL, 10);
- /* validation by comparing against the reconstucted name */
- snprintf(linkName, sizeof(linkName),
- "%s%u", NG_BRIDGE_HOOK_LINK_PREFIX,
- linkNum);
- if (strcmp(linkName, name) != 0)
- return (EINVAL);
-
- if(NG_PEER_NODE(hook) == node)
- return (ELOOP);
-
- link = malloc(sizeof(*link), M_NETGRAPH_BRIDGE,
- M_WAITOK|M_ZERO);
- if (link == NULL)
- return (ENOMEM);
- link->hook = hook;
- NG_HOOK_SET_PRIVATE(hook, link);
- priv->numLinks++;
- return (0);
- }
+ if (strlen(name) <= strlen(prefix))
+ return (EINVAL); /* Unknown hook name */
+
+ isUplink = (name[0] == 'u');
+ if (isUplink)
+ prefix = NG_BRIDGE_HOOK_UPLINK_PREFIX;
+
+
+ /* primitive parsing */
+ linkNum = strtoul(name + strlen(prefix), NULL, 10);
+ /* validation by comparing against the reconstucted name */
+ snprintf(linkName, sizeof(linkName), "%s%u", prefix, linkNum);
+ if (strcmp(linkName, name) != 0)
+ return (EINVAL);
+
+ if (linkNum == 0 && isUplink)
+ return (EINVAL);
- /* Unknown hook name */
- return (EINVAL);
+ if(NG_PEER_NODE(hook) == node)
+ return (ELOOP);
+
+ link = malloc(sizeof(*link), M_NETGRAPH_BRIDGE, M_WAITOK|M_ZERO);
+ if (link == NULL)
+ return (ENOMEM);
+
+ link->hook = hook;
+ if (isUplink) {
+ link->learnMac = 0;
+ link->sendUnknown = 1;
+ if (priv->numLinks == 0) /* if the first link is an uplink */
+ priv->sendUnknown = 0; /* switch to restrictive mode */
+ } else {
+ link->learnMac = 1;
+ link->sendUnknown = priv->sendUnknown;
+ }
+
+ NG_HOOK_SET_PRIVATE(hook, link);
+ priv->numLinks++;
+ return (0);
}
/*
@@ -438,6 +456,11 @@
i = 0;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
SLIST_FOREACH(hent, &priv->tab[bucket], next) {
+ char * name = NG_HOOK_NAME(hent->host.link->hook);
+ char * prefix = name[0] == 'u' ?
+ NG_BRIDGE_HOOK_UPLINK_PREFIX :
+ NG_BRIDGE_HOOK_LINK_PREFIX;
+
memcpy(ary->hosts[i].addr,
hent->host.addr,
sizeof(ary->hosts[i].addr));
@@ -445,9 +468,7 @@
ary->hosts[i].staleness =
hent->host.staleness;
ary->hosts[i].linkNum = strtol(
- NG_HOOK_NAME(hent->host.link->hook) +
- strlen(NG_BRIDGE_HOOK_LINK_PREFIX),
- NULL, 10);
+ name + strlen(prefix), NULL, 10);
i++;
}
}
@@ -506,17 +527,23 @@
hook_p hook;
link_p link;
char linkName[NG_HOOKSIZ];
+ int linkNum;
/* Get link number */
if (msg->header.arglen != sizeof(u_int32_t)) {
error = EINVAL;
break;
}
- snprintf(linkName, sizeof(linkName),
- "%s%u", NG_BRIDGE_HOOK_LINK_PREFIX,
- *((u_int32_t *)msg->data));
+ linkNum = *((int32_t *)msg->data);
+ if (linkNum < 0)
+ snprintf(linkName, sizeof(linkName),
+ "%s%u", NG_BRIDGE_HOOK_UPLINK_PREFIX, -linkNum);
+ else
+ snprintf(linkName, sizeof(linkName),
+ "%s%u", NG_BRIDGE_HOOK_LINK_PREFIX, linkNum);
if ((hook = ng_findhook(node, linkName)) == NULL) {
+ printf("Not found %s for %d\n", linkName, linkNum);
error = ENOTCONN;
break;
}
@@ -609,6 +636,10 @@
return (1);
}
+ /* Skip sending unknowns to undesired links */
+ if (!ctx->manycast && !destLink->sendUnknown)
+ return (1);
+
if (ctx->foundFirst == NULL) {
/*
* This is the first usable link we have found.
@@ -750,7 +781,7 @@
host->link = ctx.incoming;
host->age = 0;
}
- } else {
+ } else if (ctx.incoming->learnMac) {
if (!ng_bridge_put(priv, eh->ether_shost, ctx.incoming)) {
ctx.incoming->stats.memoryFailures++;
NG_FREE_ITEM(item);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 19, 11:58 AM (13 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33310600
Default Alt Text
D23963.id81875.diff (7 KB)
Attached To
Mode
D23963: netgraph/ng_bridge: Introduce "uplink" ports without MAC learning
Attached
Detach File
Event Timeline
Log In to Comment