aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLutz Donnerhacke <donner@FreeBSD.org>2021-02-25 09:59:45 +0000
committerLutz Donnerhacke <donner@FreeBSD.org>2021-02-25 09:59:45 +0000
commit9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff (patch)
tree30e290183da523f81f06c9a68a69c0581062f6d5
parent3de9c792eebe77ef2cdf1f6aad28cc4df9e8c37d (diff)
downloadsrc-9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff.tar.gz
src-9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff.zip
netgraph/ng_bridge: Merge internal structures
In a earlier version of ng_bridge(4) the exernal visible host entry structure was a strict subset of the internal one. So internal view was a direct annotation of the external structure. This strict inheritance was lost many versions ago. There is no need to encapsulate a part of the internal represntation as a separate structure. This patch is a preparation to make the internal structure read only in the data path in order to make ng_bridge(4) multithreaded. Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D28545 (cherry picked from commit ccf4cd2e7830394467d5f6cf546ab453f9657b69)
-rw-r--r--sys/netgraph/ng_bridge.c99
-rw-r--r--sys/netgraph/ng_bridge.h7
2 files changed, 50 insertions, 56 deletions
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c
index c2d0f79a6ca5..0b2b7f5ca6a3 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -134,13 +134,16 @@ typedef struct ng_bridge_private *priv_p;
typedef struct ng_bridge_private const *priv_cp; /* read only access */
/* Information about a host, stored in a hash table entry */
-struct ng_bridge_hent {
- struct ng_bridge_host host; /* actual host info */
- SLIST_ENTRY(ng_bridge_hent) next; /* next entry in bucket */
+struct ng_bridge_host {
+ u_char addr[6]; /* ethernet address */
+ link_p link; /* link where addr can be found */
+ u_int16_t age; /* seconds ago entry was created */
+ u_int16_t staleness; /* seconds ago host last heard from */
+ SLIST_ENTRY(ng_bridge_host) next; /* next entry in bucket */
};
/* Hash table bucket declaration */
-SLIST_HEAD(ng_bridge_bucket, ng_bridge_hent);
+SLIST_HEAD(ng_bridge_bucket, ng_bridge_host);
/* Netgraph node methods */
static ng_constructor_t ng_bridge_constructor;
@@ -496,7 +499,7 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
case NGM_BRIDGE_GET_TABLE:
{
struct ng_bridge_host_tbl_ary *ary;
- struct ng_bridge_hent *hent;
+ struct ng_bridge_host *host;
int i, bucket;
NG_MKRESPONSE(resp, msg, sizeof(*ary) +
@@ -509,18 +512,16 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
ary->numHosts = priv->numHosts;
i = 0;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
- SLIST_FOREACH(hent, &priv->tab[bucket], next) {
- const char *name = NG_HOOK_NAME(hent->host.link->hook);
+ SLIST_FOREACH(host, &priv->tab[bucket], next) {
+ const char *name = NG_HOOK_NAME(host->link->hook);
const char *prefix = name[0] == 'u' ?
NG_BRIDGE_HOOK_UPLINK_PREFIX :
NG_BRIDGE_HOOK_LINK_PREFIX;
- memcpy(ary->hosts[i].addr,
- hent->host.addr,
+ memcpy(ary->hosts[i].addr, host->addr,
sizeof(ary->hosts[i].addr));
- ary->hosts[i].age = hent->host.age;
- ary->hosts[i].staleness =
- hent->host.staleness;
+ ary->hosts[i].age = host->age;
+ ary->hosts[i].staleness = host->staleness;
ary->hosts[i].linkNum = strtol(
name + strlen(prefix), NULL, 10);
i++;
@@ -637,7 +638,7 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
case NGM_BRIDGE_GET_TABLE:
{
struct ng_bridge_host_ary *ary;
- struct ng_bridge_hent *hent;
+ struct ng_bridge_host *host;
int i = 0, bucket;
NG_MKRESPONSE(resp, msg, sizeof(*ary)
@@ -649,14 +650,14 @@ ng_bridge_rcvmsg(node_p node, item_p item, hook_p lasthook)
ary = (struct ng_bridge_host_ary *)resp->data;
ary->numHosts = priv->numHosts;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
- SLIST_FOREACH(hent, &priv->tab[bucket], next) {
+ SLIST_FOREACH(host, &priv->tab[bucket], next) {
memcpy(ary->hosts[i].addr,
- hent->host.addr,
+ host->addr,
sizeof(ary->hosts[i].addr));
- ary->hosts[i].age = hent->host.age;
- ary->hosts[i].staleness = hent->host.staleness;
+ ary->hosts[i].age = host->age;
+ ary->hosts[i].staleness = host->staleness;
strncpy(ary->hosts[i].hook,
- NG_HOOK_NAME(hent->host.link->hook),
+ NG_HOOK_NAME(host->link->hook),
sizeof(ary->hosts[i].hook));
i++;
}
@@ -1000,11 +1001,11 @@ static struct ng_bridge_host *
ng_bridge_get(priv_cp priv, const u_char *addr)
{
const int bucket = HASH(addr, priv->hashMask);
- struct ng_bridge_hent *hent;
+ struct ng_bridge_host *host;
- SLIST_FOREACH(hent, &priv->tab[bucket], next) {
- if (ETHER_EQUAL(hent->host.addr, addr))
- return (&hent->host);
+ SLIST_FOREACH(host, &priv->tab[bucket], next) {
+ if (ETHER_EQUAL(host->addr, addr))
+ return (host);
}
return (NULL);
}
@@ -1018,27 +1019,27 @@ static int
ng_bridge_put(priv_p priv, const u_char *addr, link_p link)
{
const int bucket = HASH(addr, priv->hashMask);
- struct ng_bridge_hent *hent;
+ struct ng_bridge_host *host;
#ifdef INVARIANTS
/* Assert that entry does not already exist in hashtable */
- SLIST_FOREACH(hent, &priv->tab[bucket], next) {
- KASSERT(!ETHER_EQUAL(hent->host.addr, addr),
+ SLIST_FOREACH(host, &priv->tab[bucket], next) {
+ KASSERT(!ETHER_EQUAL(host->addr, addr),
("%s: entry %6D exists in table", __func__, addr, ":"));
}
#endif
/* Allocate and initialize new hashtable entry */
- hent = malloc(sizeof(*hent), M_NETGRAPH_BRIDGE, M_NOWAIT);
- if (hent == NULL)
+ host = malloc(sizeof(*host), M_NETGRAPH_BRIDGE, M_NOWAIT);
+ if (host == NULL)
return (0);
- bcopy(addr, hent->host.addr, ETHER_ADDR_LEN);
- hent->host.link = link;
- hent->host.staleness = 0;
- hent->host.age = 0;
+ bcopy(addr, host->addr, ETHER_ADDR_LEN);
+ host->link = link;
+ host->staleness = 0;
+ host->age = 0;
/* Add new element to hash bucket */
- SLIST_INSERT_HEAD(&priv->tab[bucket], hent, next);
+ SLIST_INSERT_HEAD(&priv->tab[bucket], host, next);
priv->numHosts++;
/* Resize table if necessary */
@@ -1083,12 +1084,12 @@ ng_bridge_rehash(priv_p priv)
struct ng_bridge_bucket *const oldList = &priv->tab[oldBucket];
while (!SLIST_EMPTY(oldList)) {
- struct ng_bridge_hent *const hent
+ struct ng_bridge_host *const host
= SLIST_FIRST(oldList);
SLIST_REMOVE_HEAD(oldList, next);
- newBucket = HASH(hent->host.addr, newMask);
- SLIST_INSERT_HEAD(&newTab[newBucket], hent, next);
+ newBucket = HASH(host->addr, newMask);
+ SLIST_INSERT_HEAD(&newTab[newBucket], host, next);
}
}
@@ -1120,17 +1121,17 @@ ng_bridge_remove_hosts(priv_p priv, link_p link)
int bucket;
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
- struct ng_bridge_hent **hptr = &SLIST_FIRST(&priv->tab[bucket]);
+ struct ng_bridge_host **hptr = &SLIST_FIRST(&priv->tab[bucket]);
while (*hptr != NULL) {
- struct ng_bridge_hent *const hent = *hptr;
+ struct ng_bridge_host *const host = *hptr;
- if (link == NULL || hent->host.link == link) {
- *hptr = SLIST_NEXT(hent, next);
- free(hent, M_NETGRAPH_BRIDGE);
+ if (link == NULL || host->link == link) {
+ *hptr = SLIST_NEXT(host, next);
+ free(host, M_NETGRAPH_BRIDGE);
priv->numHosts--;
} else
- hptr = &SLIST_NEXT(hent, next);
+ hptr = &SLIST_NEXT(host, next);
}
}
}
@@ -1171,20 +1172,20 @@ ng_bridge_timeout(node_p node, hook_p hook, void *arg1, int arg2)
/* Update host time counters and remove stale entries */
for (bucket = 0; bucket < priv->numBuckets; bucket++) {
- struct ng_bridge_hent **hptr = &SLIST_FIRST(&priv->tab[bucket]);
+ struct ng_bridge_host **hptr = &SLIST_FIRST(&priv->tab[bucket]);
while (*hptr != NULL) {
- struct ng_bridge_hent *const hent = *hptr;
+ struct ng_bridge_host *const host = *hptr;
/* Remove hosts we haven't heard from in a while */
- if (++hent->host.staleness >= priv->conf.maxStaleness) {
- *hptr = SLIST_NEXT(hent, next);
- free(hent, M_NETGRAPH_BRIDGE);
+ if (++host->staleness >= priv->conf.maxStaleness) {
+ *hptr = SLIST_NEXT(host, next);
+ free(host, M_NETGRAPH_BRIDGE);
priv->numHosts--;
} else {
- if (hent->host.age < 0xffff)
- hent->host.age++;
- hptr = &SLIST_NEXT(hent, next);
+ if (host->age < 0xffff)
+ host->age++;
+ hptr = &SLIST_NEXT(host, next);
counter++;
}
}
diff --git a/sys/netgraph/ng_bridge.h b/sys/netgraph/ng_bridge.h
index b34bc0f5f55e..790e9c5da11e 100644
--- a/sys/netgraph/ng_bridge.h
+++ b/sys/netgraph/ng_bridge.h
@@ -130,13 +130,6 @@ struct ng_bridge_link_stats {
struct ng_bridge_link;
typedef struct ng_bridge_link *link_p;
-/* Structure describing a single host */
-struct ng_bridge_host {
- u_char addr[6]; /* ethernet address */
- link_p link; /* link where addr can be found */
- u_int16_t age; /* seconds ago entry was created */
- u_int16_t staleness; /* seconds ago host last heard from */
-};
#ifdef NGM_BRIDGE_TABLE_ABI
struct ng_bridge_host_tbl {