From owner-dev-commits-src-branches@freebsd.org Thu Feb 25 10:00:12 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5E09555D351; Thu, 25 Feb 2021 10:00:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DmSvc2C1Tz4STG; Thu, 25 Feb 2021 10:00:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3E965155E2; Thu, 25 Feb 2021 10:00:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11PA0CVP010805; Thu, 25 Feb 2021 10:00:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11PA0CQf010798; Thu, 25 Feb 2021 10:00:12 GMT (envelope-from git) Date: Thu, 25 Feb 2021 10:00:12 GMT Message-Id: <202102251000.11PA0CQf010798@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Lutz Donnerhacke Subject: git: 9a972281e7f1 - stable/12 - netgraph/ng_bridge: Merge internal structures MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: donner X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2021 10:00:12 -0000 The branch stable/12 has been updated by donner: URL: https://cgit.FreeBSD.org/src/commit/?id=9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff commit 9a972281e7f1fbd3b1ecf9c5d5bad8880227f0ff Author: Lutz Donnerhacke AuthorDate: 2021-02-25 09:59:45 +0000 Commit: Lutz Donnerhacke CommitDate: 2021-02-25 09:59:45 +0000 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) --- sys/netgraph/ng_bridge.c | 99 ++++++++++++++++++++++++------------------------ sys/netgraph/ng_bridge.h | 7 ---- 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 {