ng_bridge.c (184205) | ng_bridge.c (184214) |
---|---|
1/* 2 * ng_bridge.c 3 */ 4 5/*- 6 * Copyright (c) 2000 Whistle Communications, Inc. 7 * All rights reserved. 8 * --- 23 unchanged lines hidden (view full) --- 32 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 * 38 * Author: Archie Cobbs <archie@freebsd.org> 39 * | 1/* 2 * ng_bridge.c 3 */ 4 5/*- 6 * Copyright (c) 2000 Whistle Communications, Inc. 7 * All rights reserved. 8 * --- 23 unchanged lines hidden (view full) --- 32 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 * 38 * Author: Archie Cobbs <archie@freebsd.org> 39 * |
40 * $FreeBSD: head/sys/netgraph/ng_bridge.c 184205 2008-10-23 15:53:51Z des $ | 40 * $FreeBSD: head/sys/netgraph/ng_bridge.c 184214 2008-10-23 20:26:15Z des $ |
41 */ 42 43/* 44 * ng_bridge(4) netgraph node type 45 * 46 * The node performs standard intelligent Ethernet bridging over 47 * each of its connected hooks, or links. A simple loop detection 48 * algorithm is included which disables a link for priv->conf.loopTimeout --- 250 unchanged lines hidden (view full) --- 299 300 /* Allocate and initialize private info */ 301 priv = malloc(sizeof(*priv), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); 302 if (priv == NULL) 303 return (ENOMEM); 304 ng_callout_init(&priv->timer); 305 306 /* Allocate and initialize hash table, etc. */ | 41 */ 42 43/* 44 * ng_bridge(4) netgraph node type 45 * 46 * The node performs standard intelligent Ethernet bridging over 47 * each of its connected hooks, or links. A simple loop detection 48 * algorithm is included which disables a link for priv->conf.loopTimeout --- 250 unchanged lines hidden (view full) --- 299 300 /* Allocate and initialize private info */ 301 priv = malloc(sizeof(*priv), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); 302 if (priv == NULL) 303 return (ENOMEM); 304 ng_callout_init(&priv->timer); 305 306 /* Allocate and initialize hash table, etc. */ |
307 priv->tab = malloc( MIN_BUCKETS * sizeof(*priv->tab), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); | 307 priv->tab = malloc(MIN_BUCKETS * sizeof(*priv->tab), 308 M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); |
308 if (priv->tab == NULL) { 309 free(priv, M_NETGRAPH_BRIDGE); 310 return (ENOMEM); 311 } 312 priv->numBuckets = MIN_BUCKETS; 313 priv->hashMask = MIN_BUCKETS - 1; 314 priv->conf.debugLevel = 1; 315 priv->conf.loopTimeout = DEFAULT_LOOP_TIMEOUT; --- 37 unchanged lines hidden (view full) --- 353 cp = name + strlen(NG_BRIDGE_HOOK_LINK_PREFIX); 354 if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0')) 355 return (EINVAL); 356 linkNum = strtoul(cp, &eptr, 10); 357 if (*eptr != '\0' || linkNum >= NG_BRIDGE_MAX_LINKS) 358 return (EINVAL); 359 if (priv->links[linkNum] != NULL) 360 return (EISCONN); | 309 if (priv->tab == NULL) { 310 free(priv, M_NETGRAPH_BRIDGE); 311 return (ENOMEM); 312 } 313 priv->numBuckets = MIN_BUCKETS; 314 priv->hashMask = MIN_BUCKETS - 1; 315 priv->conf.debugLevel = 1; 316 priv->conf.loopTimeout = DEFAULT_LOOP_TIMEOUT; --- 37 unchanged lines hidden (view full) --- 354 cp = name + strlen(NG_BRIDGE_HOOK_LINK_PREFIX); 355 if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0')) 356 return (EINVAL); 357 linkNum = strtoul(cp, &eptr, 10); 358 if (*eptr != '\0' || linkNum >= NG_BRIDGE_MAX_LINKS) 359 return (EINVAL); 360 if (priv->links[linkNum] != NULL) 361 return (EISCONN); |
361 priv->links[linkNum] = malloc( sizeof(*priv->links[linkNum]), M_NETGRAPH_BRIDGE, M_NOWAIT|M_ZERO); | 362 priv->links[linkNum] = malloc(sizeof(*priv->links[linkNum]), 363 M_NETGRAPH_BRIDGE, M_NOWAIT|M_ZERO); |
362 if (priv->links[linkNum] == NULL) 363 return (ENOMEM); 364 priv->links[linkNum]->hook = hook; 365 NG_HOOK_SET_PRIVATE(hook, (void *)linkNum); 366 priv->numLinks++; 367 return (0); 368 } 369 --- 473 unchanged lines hidden (view full) --- 843 /* Assert that entry does not already exist in hashtable */ 844 SLIST_FOREACH(hent, &priv->tab[bucket], next) { 845 KASSERT(!ETHER_EQUAL(hent->host.addr, addr), 846 ("%s: entry %6D exists in table", __func__, addr, ":")); 847 } 848#endif 849 850 /* Allocate and initialize new hashtable entry */ | 364 if (priv->links[linkNum] == NULL) 365 return (ENOMEM); 366 priv->links[linkNum]->hook = hook; 367 NG_HOOK_SET_PRIVATE(hook, (void *)linkNum); 368 priv->numLinks++; 369 return (0); 370 } 371 --- 473 unchanged lines hidden (view full) --- 845 /* Assert that entry does not already exist in hashtable */ 846 SLIST_FOREACH(hent, &priv->tab[bucket], next) { 847 KASSERT(!ETHER_EQUAL(hent->host.addr, addr), 848 ("%s: entry %6D exists in table", __func__, addr, ":")); 849 } 850#endif 851 852 /* Allocate and initialize new hashtable entry */ |
851 hent = malloc( sizeof(*hent), M_NETGRAPH_BRIDGE, M_NOWAIT); | 853 hent = malloc(sizeof(*hent), M_NETGRAPH_BRIDGE, M_NOWAIT); |
852 if (hent == NULL) 853 return (0); 854 bcopy(addr, hent->host.addr, ETHER_ADDR_LEN); 855 hent->host.linkNum = linkNum; 856 hent->host.staleness = 0; 857 hent->host.age = 0; 858 859 /* Add new element to hash bucket */ --- 27 unchanged lines hidden (view full) --- 887 else if (priv->numHosts < (priv->numBuckets >> 2) 888 && (priv->numBuckets >> 2) >= MIN_BUCKETS) 889 newNumBuckets = priv->numBuckets >> 2; 890 else 891 return; 892 newMask = newNumBuckets - 1; 893 894 /* Allocate and initialize new table */ | 854 if (hent == NULL) 855 return (0); 856 bcopy(addr, hent->host.addr, ETHER_ADDR_LEN); 857 hent->host.linkNum = linkNum; 858 hent->host.staleness = 0; 859 hent->host.age = 0; 860 861 /* Add new element to hash bucket */ --- 27 unchanged lines hidden (view full) --- 889 else if (priv->numHosts < (priv->numBuckets >> 2) 890 && (priv->numBuckets >> 2) >= MIN_BUCKETS) 891 newNumBuckets = priv->numBuckets >> 2; 892 else 893 return; 894 newMask = newNumBuckets - 1; 895 896 /* Allocate and initialize new table */ |
895 newTab = malloc( newNumBuckets * sizeof(*newTab), M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); | 897 newTab = malloc(newNumBuckets * sizeof(*newTab), 898 M_NETGRAPH_BRIDGE, M_NOWAIT | M_ZERO); |
896 if (newTab == NULL) 897 return; 898 899 /* Move all entries from old table to new table */ 900 for (oldBucket = 0; oldBucket < priv->numBuckets; oldBucket++) { 901 struct ng_bridge_bucket *const oldList = &priv->tab[oldBucket]; 902 903 while (!SLIST_EMPTY(oldList)) { --- 136 unchanged lines hidden --- | 899 if (newTab == NULL) 900 return; 901 902 /* Move all entries from old table to new table */ 903 for (oldBucket = 0; oldBucket < priv->numBuckets; oldBucket++) { 904 struct ng_bridge_bucket *const oldList = &priv->tab[oldBucket]; 905 906 while (!SLIST_EMPTY(oldList)) { --- 136 unchanged lines hidden --- |