Date: Fri, 3 Aug 2007 23:20:06 GMT From: Marko Zec <zec@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 124622 for review Message-ID: <200708032320.l73NK6Zn087436@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <net/vnet.h> +#include <netgraph/ng_message.h> #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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708032320.l73NK6Zn087436>