From owner-p4-projects@FreeBSD.ORG Fri Aug 3 23:20:06 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A7DEE16A41B; Fri, 3 Aug 2007 23:20:06 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C86B16A41A for ; Fri, 3 Aug 2007 23:20:06 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 748A713C442 for ; Fri, 3 Aug 2007 23:20:06 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l73NK6uT087445 for ; Fri, 3 Aug 2007 23:20:06 GMT (envelope-from zec@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l73NK6Zn087436 for perforce@freebsd.org; Fri, 3 Aug 2007 23:20:06 GMT (envelope-from zec@FreeBSD.org) Date: Fri, 3 Aug 2007 23:20:06 GMT Message-Id: <200708032320.l73NK6Zn087436@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@FreeBSD.org using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 124622 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2007 23:20:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=124622 Change 124622 by zec@zec_tpx32 on 2007/08/03 23:20:03 Maintain an independent instance of netgraph-ID to ng_node hashmap for each vnet. This completely prevents one vnet from (accidentaly) messing with other negraph address spaces (i.e. other vnets). Node IDs are now also assigned on per-vnet basis, so it's now possible for two ng_nodes with equal IDs to exist in two different vnets. Affected files ... .. //depot/projects/vimage/src/sys/netgraph/ng_base.c#18 edit .. //depot/projects/vimage/src/sys/netgraph/vnetgraph.h#5 edit Differences ... ==== //depot/projects/vimage/src/sys/netgraph/ng_base.c#18 (text+ko) ==== @@ -84,12 +84,10 @@ #ifdef NETGRAPH_DEBUG static struct mtx ngq_mtx; /* protects the queue item list */ -#ifndef VIMAGE static SLIST_HEAD(, ng_node) ng_allnodes; static LIST_HEAD(, ng_node) ng_freenodes; /* in debug, we never free() them */ static SLIST_HEAD(, ng_hook) ng_allhooks; static LIST_HEAD(, ng_hook) ng_freehooks; /* in debug, we never free() them */ -#endif static void ng_dumpitems(void); static void ng_dumpnodes(void); @@ -175,15 +173,16 @@ /* Hash related definitions */ /* XXX Don't need to initialise them because it's a LIST */ -#define NG_ID_HASH_SIZE 32 /* most systems wont need even this many */ +#ifndef VIMAGE static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE]; +#endif static struct mtx ng_idhash_mtx; /* Method to find a node.. used twice so do it here */ #define NG_IDHASH_FN(ID) ((ID) % (NG_ID_HASH_SIZE)) #define NG_IDHASH_FIND(ID, node) \ do { \ mtx_assert(&ng_idhash_mtx, MA_OWNED); \ - LIST_FOREACH(node, &ng_ID_hash[NG_IDHASH_FN(ID)], \ + LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \ nd_idnodes) { \ if (NG_NODE_IS_VALID(node) \ && (NG_NODE_ID(node) == ID)) { \ @@ -354,7 +353,9 @@ #define TRAP_ERROR() #endif -static ng_ID_t nextID = 1; +#ifndef VIMAGE +static ng_ID_t nextID; +#endif #ifdef INVARIANTS #define CHECK_DATA_MBUF(m) do { \ @@ -577,7 +578,8 @@ return (EINVAL); } - /* Locate the node type. If we fail we return. Do not try to load + /* + * Locate the node type. If we fail we return. Do not try to load * module. */ if ((type = ng_findtype(typename)) == NULL) @@ -653,7 +655,7 @@ mtx_lock(&ng_idhash_mtx); for (;;) { /* wrap protection, even if silly */ node_p node2 = NULL; - node->nd_ID = nextID++; /* 137/second for 1 year before wrap */ + node->nd_ID = V_nextID++; /* 137/sec for 1 year before wrap */ /* Is there a problem with the new number? */ NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */ @@ -661,7 +663,7 @@ break; } } - LIST_INSERT_HEAD(&ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], + LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], node, nd_idnodes); mtx_unlock(&ng_idhash_mtx); @@ -802,6 +804,7 @@ static node_p ng_ID2noderef(ng_ID_t ID) { + INIT_VNET_NETGRAPH(curvnet); node_p node; mtx_lock(&ng_idhash_mtx); NG_IDHASH_FIND(ID, node); @@ -3211,6 +3214,7 @@ INIT_VNET_NETGRAPH(curvnet); LIST_INIT(&V_ng_nodelist); + V_nextID = 1; return 0; } ==== //depot/projects/vimage/src/sys/netgraph/vnetgraph.h#5 (text+ko) ==== @@ -33,7 +33,7 @@ #ifndef _NETGRAPH_VNETGRPAH_H_ #define _NETGRAPH_VNETGRAPH_H_ -#include +#include #define INIT_VNET_NETGRAPH(vnet) \ INIT_FROM_VNET(vnet, VNET_MOD_NETGRAPH, \ @@ -41,19 +41,22 @@ #define VNET_NETGRAPH(sym) VSYM(vnet_netgraph, sym) +#define NG_ID_HASH_SIZE 32 /* most systems wont need even this many */ #ifdef VIMAGE struct vnet_netgraph { + LIST_HEAD(, ng_node) _ng_ID_hash[NG_ID_HASH_SIZE]; LIST_HEAD(, ng_node) _ng_nodelist; - + ng_ID_t _nextID; struct unrhdr *_ng_iface_unit; struct unrhdr *_ng_eiface_unit; }; #endif - /* Symbol translation macros */ +#define V_ng_ID_hash VNET_NETGRAPH(ng_ID_hash) #define V_ng_nodelist VNET_NETGRAPH(ng_nodelist) +#define V_nextID VNET_NETGRAPH(nextID) #define V_ng_iface_unit VNET_NETGRAPH(ng_iface_unit) #define V_ng_eiface_unit VNET_NETGRAPH(ng_eiface_unit)