summaryrefslogtreecommitdiff
path: root/sys/netgraph
diff options
context:
space:
mode:
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/atm/ng_atm.c2
-rw-r--r--sys/netgraph/netgraph.h32
-rw-r--r--sys/netgraph/ng_base.c58
-rw-r--r--sys/netgraph/ng_eiface.c15
-rw-r--r--sys/netgraph/ng_ether.c7
-rw-r--r--sys/netgraph/ng_gif.c1
-rw-r--r--sys/netgraph/ng_iface.c15
7 files changed, 29 insertions, 101 deletions
diff --git a/sys/netgraph/atm/ng_atm.c b/sys/netgraph/atm/ng_atm.c
index e5e1e2eaadc1..7296aa153f14 100644
--- a/sys/netgraph/atm/ng_atm.c
+++ b/sys/netgraph/atm/ng_atm.c
@@ -1407,7 +1407,6 @@ ng_atm_mod_event(module_t mod, int event, void *data)
VNET_LIST_RLOCK();
VNET_FOREACH(vnet_iter) {
CURVNET_SET_QUIET(vnet_iter);
- INIT_VNET_NET(vnet_iter);
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
if (ifp->if_type == IFT_ATM)
ng_atm_attach(ifp);
@@ -1431,7 +1430,6 @@ ng_atm_mod_event(module_t mod, int event, void *data)
VNET_LIST_RLOCK();
VNET_FOREACH(vnet_iter) {
CURVNET_SET_QUIET(vnet_iter);
- INIT_VNET_NET(vnet_iter);
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
if (ifp->if_type == IFT_ATM)
ng_atm_detach(ifp);
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 5a0418e638aa..37ef833cae46 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -1218,36 +1218,4 @@ typedef void *meta_p;
("%s: negative td_ng_outbound", __func__)); \
} while (0)
-/* Virtualization macros */
-#define INIT_VNET_NETGRAPH(vnet) \
- INIT_FROM_VNET(vnet, VNET_MOD_NETGRAPH, \
- struct vnet_netgraph, vnet_netgraph)
-
-#define VNET_NETGRAPH(sym) VSYM(vnet_netgraph, sym)
-
-struct vnet_netgraph {
- LIST_HEAD(, ng_node) _ng_ID_hash[NG_ID_HASH_SIZE];
- LIST_HEAD(, ng_node) _ng_name_hash[NG_NAME_HASH_SIZE];
- LIST_HEAD(, ng_node) _ng_nodelist;
- ng_ID_t _nextID;
- struct unrhdr *_ng_iface_unit;
- struct unrhdr *_ng_eiface_unit;
- struct unrhdr *_ng_wormhole_unit;
-};
-
-#ifndef VIMAGE
-#ifndef VIMAGE_GLOBALS
-extern struct vnet_netgraph vnet_netgraph_0;
-#endif
-#endif
-
-/* Symbol translation macros */
-#define V_nextID VNET_NETGRAPH(nextID)
-#define V_ng_ID_hash VNET_NETGRAPH(ng_ID_hash)
-#define V_ng_eiface_unit VNET_NETGRAPH(ng_eiface_unit)
-#define V_ng_iface_unit VNET_NETGRAPH(ng_iface_unit)
-#define V_ng_name_hash VNET_NETGRAPH(ng_name_hash)
-#define V_ng_nodelist VNET_NETGRAPH(ng_nodelist)
-#define V_ng_wormhole_unit VNET_NETGRAPH(ng_wormhole_unit)
-
#endif /* _NETGRAPH_NETGRAPH_H_ */
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index a49570126325..9eb99d5539cd 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -68,6 +68,7 @@
#include <machine/cpu.h>
#include <net/netisr.h>
+#include <net/vnet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
@@ -75,16 +76,9 @@
MODULE_VERSION(netgraph, NG_ABI_VERSION);
-#ifndef VIMAGE
-#ifndef VIMAGE_GLOBALS
-struct vnet_netgraph vnet_netgraph_0;
-#endif
-#endif
-
/* Mutex to protect topology events. */
static struct mtx ng_topo_mtx;
-static vnet_attach_fn vnet_netgraph_iattach;
#ifdef VIMAGE
static vnet_detach_fn vnet_netgraph_idetach;
#endif
@@ -182,9 +176,9 @@ static struct mtx ng_typelist_mtx;
/* Hash related definitions */
/* XXX Don't need to initialise them because it's a LIST */
-#ifdef VIMAGE_GLOBALS
-static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE];
-#endif
+static VNET_DEFINE(LIST_HEAD(, ng_node), ng_ID_hash[NG_ID_HASH_SIZE]);
+#define V_ng_ID_hash VNET_GET(ng_ID_hash)
+
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))
@@ -200,9 +194,9 @@ static struct mtx ng_idhash_mtx;
} \
} while (0)
-#ifdef VIMAGE_GLOBALS
-static LIST_HEAD(, ng_node) ng_name_hash[NG_NAME_HASH_SIZE];
-#endif
+static VNET_DEFINE(LIST_HEAD(, ng_node), ng_name_hash[NG_NAME_HASH_SIZE]);
+#define V_ng_name_hash VNET_GET(ng_name_hash)
+
static struct mtx ng_namehash_mtx;
#define NG_NAMEHASH(NAME, HASH) \
do { \
@@ -370,9 +364,8 @@ ng_alloc_node(void)
#define TRAP_ERROR()
#endif
-#ifdef VIMAGE_GLOBALS
-static ng_ID_t nextID;
-#endif
+static VNET_DEFINE(ng_ID_t, nextID) = 1;
+#define V_nextID VNET_GET(nextID)
#ifdef INVARIANTS
#define CHECK_DATA_MBUF(m) do { \
@@ -634,7 +627,6 @@ ng_make_node(const char *typename, node_p *nodepp)
int
ng_make_node_common(struct ng_type *type, node_p *nodepp)
{
- INIT_VNET_NETGRAPH(curvnet);
node_p node;
/* Require the node type to have been already installed */
@@ -819,7 +811,6 @@ ng_unref_node(node_p node)
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);
@@ -845,7 +836,6 @@ ng_node2ID(node_p node)
int
ng_name_node(node_p node, const char *name)
{
- INIT_VNET_NETGRAPH(curvnet);
int i, hash;
node_p node2;
@@ -896,7 +886,6 @@ ng_name_node(node_p node, const char *name)
node_p
ng_name2noderef(node_p here, const char *name)
{
- INIT_VNET_NETGRAPH(curvnet);
node_p node;
ng_ID_t temp;
int hash;
@@ -2457,7 +2446,6 @@ ng_apply_item(node_p node, item_p item, int rw)
static int
ng_generic_msg(node_p here, item_p item, hook_p lasthook)
{
- INIT_VNET_NETGRAPH(curvnet);
int error = 0;
struct ng_mesg *msg;
struct ng_mesg *resp = NULL;
@@ -3080,37 +3068,24 @@ ng_mod_event(module_t mod, int event, void *data)
return (error);
}
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
static const vnet_modinfo_t vnet_netgraph_modinfo = {
.vmi_id = VNET_MOD_NETGRAPH,
.vmi_name = "netgraph",
- .vmi_size = sizeof(struct vnet_netgraph),
.vmi_dependson = VNET_MOD_LOIF,
- .vmi_iattach = vnet_netgraph_iattach,
-#ifdef VIMAGE
.vmi_idetach = vnet_netgraph_idetach
-#endif
};
#endif
-static int
-vnet_netgraph_iattach(const void *unused __unused)
-{
- INIT_VNET_NETGRAPH(curvnet);
-
- V_nextID = 1;
-
- return (0);
-}
-
#ifdef VIMAGE
static int
vnet_netgraph_idetach(const void *unused __unused)
{
- INIT_VNET_NETGRAPH(curvnet);
+#if 0
node_p node, last_killed = NULL;
- while ((node = LIST_FIRST(&V_ng_nodelist)) != NULL) {
+ /* XXXRW: utterly bogus. */
+ while ((node = LIST_FIRST(&V_ng_allnodes)) != NULL) {
if (node == last_killed) {
/* This should never happen */
node->nd_flags |= NGF_REALLY_DIE;
@@ -3118,13 +3093,14 @@ vnet_netgraph_idetach(const void *unused __unused)
node->nd_name);
ng_rmnode(node, NULL, NULL, 0);
/* This must never happen */
- if (node == LIST_FIRST(&V_ng_nodelist))
+ if (node == LIST_FIRST(&V_ng_allnodes))
panic("netgraph node %s won't die",
node->nd_name);
}
ng_rmnode(node, NULL, NULL, 0);
last_killed = node;
}
+#endif
return (0);
}
@@ -3144,10 +3120,8 @@ ngb_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
/* Initialize everything. */
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_register(&vnet_netgraph_modinfo);
-#else
- vnet_netgraph_iattach(NULL);
#endif
NG_WORKLIST_LOCK_INIT();
mtx_init(&ng_typelist_mtx, "netgraph types mutex", NULL,
diff --git a/sys/netgraph/ng_eiface.c b/sys/netgraph/ng_eiface.c
index 27b4b451bd8f..9969924f1bbd 100644
--- a/sys/netgraph/ng_eiface.c
+++ b/sys/netgraph/ng_eiface.c
@@ -116,11 +116,10 @@ NETGRAPH_INIT(eiface, &typestruct);
static vnet_attach_fn ng_eiface_iattach;
static vnet_detach_fn ng_eiface_idetach;
-#ifdef VIMAGE_GLOBALS
-static struct unrhdr *ng_eiface_unit;
-#endif
+static VNET_DEFINE(struct unrhdr *, ng_eiface_unit);
+#define V_ng_eiface_unit VNET_GET(ng_eiface_unit)
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
static vnet_modinfo_t vnet_ng_eiface_modinfo = {
.vmi_id = VNET_MOD_NG_EIFACE,
.vmi_name = "ng_eiface",
@@ -351,7 +350,6 @@ ng_eiface_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
static int
ng_eiface_constructor(node_p node)
{
- INIT_VNET_NETGRAPH(curvnet);
struct ifnet *ifp;
priv_p priv;
u_char eaddr[6] = {0,0,0,0,0,0};
@@ -563,7 +561,6 @@ ng_eiface_rcvdata(hook_p hook, item_p item)
static int
ng_eiface_rmnode(node_p node)
{
- INIT_VNET_NETGRAPH(curvnet);
const priv_p priv = NG_NODE_PRIVATE(node);
struct ifnet *const ifp = priv->ifp;
@@ -604,14 +601,14 @@ ng_eiface_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_register(&vnet_ng_eiface_modinfo);
#else
ng_eiface_iattach(NULL);
#endif
break;
case MOD_UNLOAD:
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_deregister(&vnet_ng_eiface_modinfo);
#else
ng_eiface_idetach(NULL);
@@ -626,7 +623,6 @@ ng_eiface_mod_event(module_t mod, int event, void *data)
static int ng_eiface_iattach(const void *unused)
{
- INIT_VNET_NETGRAPH(curvnet);
V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
@@ -635,7 +631,6 @@ static int ng_eiface_iattach(const void *unused)
static int ng_eiface_idetach(const void *unused)
{
- INIT_VNET_NETGRAPH(curvnet);
delete_unrhdr(V_ng_eiface_unit);
diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index 2be3b8832faa..09a8615ab87e 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -74,7 +74,7 @@
static vnet_attach_fn ng_ether_iattach;
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
static vnet_modinfo_t vnet_ng_ether_modinfo = {
.vmi_id = VNET_MOD_NG_ETHER,
.vmi_name = "ng_ether",
@@ -783,7 +783,7 @@ ng_ether_mod_event(module_t mod, int event, void *data)
ng_ether_input_orphan_p = ng_ether_input_orphan;
ng_ether_link_state_p = ng_ether_link_state;
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_register(&vnet_ng_ether_modinfo);
#else
error = ng_ether_iattach(NULL);
@@ -800,7 +800,7 @@ ng_ether_mod_event(module_t mod, int event, void *data)
* is MOD_UNLOAD, so there's no need to detach any nodes.
*/
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_deregister(&vnet_ng_ether_modinfo);
#endif
@@ -823,7 +823,6 @@ ng_ether_mod_event(module_t mod, int event, void *data)
static int ng_ether_iattach(const void *unused)
{
- INIT_VNET_NET(curvnet);
struct ifnet *ifp;
/* Create nodes for any already-existing Ethernet interfaces. */
diff --git a/sys/netgraph/ng_gif.c b/sys/netgraph/ng_gif.c
index 6f2657e74513..f099d614d6a3 100644
--- a/sys/netgraph/ng_gif.c
+++ b/sys/netgraph/ng_gif.c
@@ -565,7 +565,6 @@ ng_gif_mod_event(module_t mod, int event, void *data)
VNET_LIST_RLOCK();
VNET_FOREACH(vnet_iter) {
CURVNET_SET_QUIET(vnet_iter); /* XXX revisit quiet */
- INIT_VNET_NET(curvnet);
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
if (ifp->if_type == IFT_GIF)
ng_gif_attach(ifp);
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index cd65ad3b6d29..7743b2bc1488 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -212,11 +212,10 @@ NETGRAPH_INIT(iface, &typestruct);
static vnet_attach_fn ng_iface_iattach;
static vnet_detach_fn ng_iface_idetach;
-#ifdef VIMAGE_GLOBALS
-static struct unrhdr *ng_iface_unit;
-#endif
+static VNET_DEFINE(struct unrhdr *, ng_iface_unit);
+#define V_ng_iface_unit VNET_GET(ng_iface_unit)
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
static vnet_modinfo_t vnet_ng_iface_modinfo = {
.vmi_id = VNET_MOD_NG_IFACE,
.vmi_name = "ng_iface",
@@ -542,7 +541,6 @@ ng_iface_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
static int
ng_iface_constructor(node_p node)
{
- INIT_VNET_NETGRAPH(curvnet);
struct ifnet *ifp;
priv_p priv;
@@ -806,7 +804,6 @@ ng_iface_rcvdata(hook_p hook, item_p item)
static int
ng_iface_shutdown(node_p node)
{
- INIT_VNET_NETGRAPH(curvnet);
const priv_p priv = NG_NODE_PRIVATE(node);
/*
@@ -852,14 +849,14 @@ ng_iface_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_register(&vnet_ng_iface_modinfo);
#else
ng_iface_iattach(NULL);
#endif
break;
case MOD_UNLOAD:
-#ifndef VIMAGE_GLOBALS
+#ifdef VIMAGE
vnet_mod_deregister(&vnet_ng_iface_modinfo);
#else
ng_iface_idetach(NULL);
@@ -874,7 +871,6 @@ ng_iface_mod_event(module_t mod, int event, void *data)
static int ng_iface_iattach(const void *unused)
{
- INIT_VNET_NETGRAPH(curvnet);
V_ng_iface_unit = new_unrhdr(0, 0xffff, NULL);
@@ -883,7 +879,6 @@ static int ng_iface_iattach(const void *unused)
static int ng_iface_idetach(const void *unused)
{
- INIT_VNET_NETGRAPH(curvnet);
delete_unrhdr(V_ng_iface_unit);