summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2009-07-23 20:46:49 +0000
committerrwatson <rwatson@FreeBSD.org>2009-07-23 20:46:49 +0000
commitb3be1c6e3bd7d3b5cf946ddb04c1c5811644229b (patch)
tree0191b21173debdadfbf9f7565dfc5a8b9eefe94a /sys/netgraph
parentfc8defe5dd957eaee1f1c841d45804df5bbf20f5 (diff)
downloadFreeBSD-src-b3be1c6e3bd7d3b5cf946ddb04c1c5811644229b.zip
FreeBSD-src-b3be1c6e3bd7d3b5cf946ddb04c1c5811644229b.tar.gz
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT: - Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will occur each time a network stack is instantiated and destroyed. In the !VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT. For the VIMAGE case, we instead use SYSINIT's to track their order and properties on registration, using them for each vnet when created/ destroyed, or immediately on module load for already-started vnets. - Remove vnet_modinfo mechanism that existed to serve this purpose previously, as well as its dependency scheme: we now just use the SYSINIT ordering scheme. - Implement VNET_DOMAIN_SET() to allow protocol domains to declare that they want init functions to be called for each virtual network stack rather than just once at boot, compiling down to DOMAIN_SET() in the non-VIMAGE case. - Walk all virtualized kernel subsystems and make use of these instead of modinfo or DOMAIN_SET() for init/uninit events. In some cases, convert modular components from using modevent to using sysinit (where appropriate). In some cases, do minor rejuggling of SYSINIT ordering to make room for or better manage events. Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup) Discussed with: jhb, bz, julian, zec Reviewed by: bz Approved by: re (VIMAGE blanket)
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket.c7
-rw-r--r--sys/netgraph/netgraph.h2
-rw-r--r--sys/netgraph/ng_base.c24
-rw-r--r--sys/netgraph/ng_eiface.c39
-rw-r--r--sys/netgraph/ng_ether.c31
-rw-r--r--sys/netgraph/ng_iface.c39
-rw-r--r--sys/netgraph/ng_socket.c12
7 files changed, 41 insertions, 113 deletions
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket.c b/sys/netgraph/bluetooth/socket/ng_btsocket.c
index 6c6b1f3..f1620bc 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket.c
@@ -45,6 +45,7 @@
#include <sys/socketvar.h>
#include <sys/sysctl.h>
#include <sys/taskqueue.h>
+
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/bluetooth/include/ng_bluetooth.h>
@@ -57,7 +58,7 @@
#include <netgraph/bluetooth/include/ng_btsocket_sco.h>
static int ng_btsocket_modevent (module_t, int, void *);
-extern struct domain ng_btsocket_domain;
+static struct domain ng_btsocket_domain;
/*
* Bluetooth raw HCI sockets
@@ -219,7 +220,7 @@ static struct protosw ng_btsocket_protosw[] = {
* BLUETOOTH domain
*/
-struct domain ng_btsocket_domain = {
+static struct domain ng_btsocket_domain = {
.dom_family = AF_BLUETOOTH,
.dom_name = "bluetooth",
.dom_protosw = ng_btsocket_protosw,
@@ -269,7 +270,6 @@ ng_btsocket_modevent(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
- net_add_domain(&ng_btsocket_domain);
break;
case MOD_UNLOAD:
@@ -285,3 +285,4 @@ ng_btsocket_modevent(module_t mod, int event, void *data)
return (error);
} /* ng_btsocket_modevent */
+DOMAIN_SET(ng_btsocket_);
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 37ef833..8dbf0b5 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -1113,7 +1113,7 @@ MODULE_DEPEND(ng_##typename, netgraph, NG_ABI_VERSION, \
NG_ABI_VERSION)
#define NETGRAPH_INIT(tn, tp) \
- NETGRAPH_INIT_ORDERED(tn, tp, SI_SUB_PSEUDO, SI_ORDER_ANY)
+ NETGRAPH_INIT_ORDERED(tn, tp, SI_SUB_PSEUDO, SI_ORDER_MIDDLE)
/* Special malloc() type for netgraph structs and ctrl messages */
/* Only these two types should be visible to nodes */
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index 084c676..b618bb4 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -79,10 +79,6 @@ MODULE_VERSION(netgraph, NG_ABI_VERSION);
/* Mutex to protect topology events. */
static struct mtx ng_topo_mtx;
-#ifdef VIMAGE
-static vnet_detach_fn vnet_netgraph_idetach;
-#endif
-
#ifdef NETGRAPH_DEBUG
static struct mtx ng_nodelist_mtx; /* protects global node/hook lists */
static struct mtx ngq_mtx; /* protects the queue item list */
@@ -3068,18 +3064,9 @@ ng_mod_event(module_t mod, int event, void *data)
return (error);
}
-#ifdef VIMAGE
-static const vnet_modinfo_t vnet_netgraph_modinfo = {
- .vmi_id = VNET_MOD_NETGRAPH,
- .vmi_name = "netgraph",
- .vmi_dependson = VNET_MOD_LOIF,
- .vmi_idetach = vnet_netgraph_idetach
-};
-#endif
-
#ifdef VIMAGE
-static int
-vnet_netgraph_idetach(const void *unused __unused)
+static void
+vnet_netgraph_uninit(const void *unused __unused)
{
#if 0
node_p node, last_killed = NULL;
@@ -3101,9 +3088,9 @@ vnet_netgraph_idetach(const void *unused __unused)
last_killed = node;
}
#endif
-
- return (0);
}
+VNET_SYSUNINIT(vnet_netgraph_uninit, SI_SUB_NETGRAPH, SI_ORDER_ANY,
+ vnet_netgraph_uninit, NULL);
#endif /* VIMAGE */
/*
@@ -3120,9 +3107,6 @@ ngb_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
/* Initialize everything. */
-#ifdef VIMAGE
- vnet_mod_register(&vnet_netgraph_modinfo);
-#endif
NG_WORKLIST_LOCK_INIT();
mtx_init(&ng_typelist_mtx, "netgraph types mutex", NULL,
MTX_DEF);
diff --git a/sys/netgraph/ng_eiface.c b/sys/netgraph/ng_eiface.c
index fb43eef..ad9668e 100644
--- a/sys/netgraph/ng_eiface.c
+++ b/sys/netgraph/ng_eiface.c
@@ -44,6 +44,7 @@
#include <net/if_types.h>
#include <net/netisr.h>
#include <net/route.h>
+#include <net/vnet.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
@@ -113,22 +114,9 @@ static struct ng_type typestruct = {
};
NETGRAPH_INIT(eiface, &typestruct);
-static vnet_attach_fn ng_eiface_iattach;
-static vnet_detach_fn ng_eiface_idetach;
-
static VNET_DEFINE(struct unrhdr *, ng_eiface_unit);
#define V_ng_eiface_unit VNET(ng_eiface_unit)
-#ifdef VIMAGE
-static vnet_modinfo_t vnet_ng_eiface_modinfo = {
- .vmi_id = VNET_MOD_NG_EIFACE,
- .vmi_name = "ng_eiface",
- .vmi_dependson = VNET_MOD_NETGRAPH,
- .vmi_iattach = ng_eiface_iattach,
- .vmi_idetach = ng_eiface_idetach
-};
-#endif
-
/************************************************************************
INTERFACE STUFF
************************************************************************/
@@ -601,18 +589,7 @@ ng_eiface_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
-#ifdef VIMAGE
- vnet_mod_register(&vnet_ng_eiface_modinfo);
-#else
- ng_eiface_iattach(NULL);
-#endif
- break;
case MOD_UNLOAD:
-#ifdef VIMAGE
- vnet_mod_deregister(&vnet_ng_eiface_modinfo);
-#else
- ng_eiface_idetach(NULL);
-#endif
break;
default:
error = EOPNOTSUPP;
@@ -621,18 +598,20 @@ ng_eiface_mod_event(module_t mod, int event, void *data)
return (error);
}
-static int ng_eiface_iattach(const void *unused)
+static void
+vnet_ng_eiface_init(const void *unused)
{
V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
-
- return (0);
}
+VNET_SYSINIT(vnet_ng_eiface_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
+ vnet_ng_eiface_init, NULL);
-static int ng_eiface_idetach(const void *unused)
+static void
+vnet_ng_eiface_uninit(const void *unused)
{
delete_unrhdr(V_ng_eiface_unit);
-
- return (0);
}
+VNET_SYSUNINIT(vnet_ng_eiface_uninit, SI_SUB_PSEUDO, SI_ORDER_ANY,
+ vnet_ng_eiface_uninit, NULL);
diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index 09a8615..85fc7fc 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -72,17 +72,6 @@
#define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph)
-static vnet_attach_fn ng_ether_iattach;
-
-#ifdef VIMAGE
-static vnet_modinfo_t vnet_ng_ether_modinfo = {
- .vmi_id = VNET_MOD_NG_ETHER,
- .vmi_name = "ng_ether",
- .vmi_dependson = VNET_MOD_NETGRAPH,
- .vmi_iattach = ng_ether_iattach,
-};
-#endif
-
/* Per-node private data */
struct private {
struct ifnet *ifp; /* associated interface */
@@ -783,11 +772,6 @@ 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;
-#ifdef VIMAGE
- vnet_mod_register(&vnet_ng_ether_modinfo);
-#else
- error = ng_ether_iattach(NULL);
-#endif
break;
case MOD_UNLOAD:
@@ -800,10 +784,6 @@ ng_ether_mod_event(module_t mod, int event, void *data)
* is MOD_UNLOAD, so there's no need to detach any nodes.
*/
-#ifdef VIMAGE
- vnet_mod_deregister(&vnet_ng_ether_modinfo);
-#endif
-
/* Unregister function hooks */
ng_ether_attach_p = NULL;
ng_ether_detach_p = NULL;
@@ -821,10 +801,15 @@ ng_ether_mod_event(module_t mod, int event, void *data)
return (error);
}
-static int ng_ether_iattach(const void *unused)
+static void
+vnet_ng_ether_init(const void *unused)
{
struct ifnet *ifp;
+ /* If module load was rejected, don't attach to vnets. */
+ if (ng_ether_attach_p != ng_ether_attach)
+ return;
+
/* Create nodes for any already-existing Ethernet interfaces. */
IFNET_RLOCK();
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
@@ -833,6 +818,6 @@ static int ng_ether_iattach(const void *unused)
ng_ether_attach(ifp);
}
IFNET_RUNLOCK();
-
- return (0);
}
+VNET_SYSINIT(vnet_ng_ether_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
+ vnet_ng_ether_init, NULL);
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index 6ed1daf6..49cba25 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -76,6 +76,7 @@
#include <net/bpf.h>
#include <net/netisr.h>
#include <net/route.h>
+#include <net/vnet.h>
#include <netinet/in.h>
@@ -209,22 +210,9 @@ static struct ng_type typestruct = {
};
NETGRAPH_INIT(iface, &typestruct);
-static vnet_attach_fn ng_iface_iattach;
-static vnet_detach_fn ng_iface_idetach;
-
static VNET_DEFINE(struct unrhdr *, ng_iface_unit);
#define V_ng_iface_unit VNET(ng_iface_unit)
-#ifdef VIMAGE
-static vnet_modinfo_t vnet_ng_iface_modinfo = {
- .vmi_id = VNET_MOD_NG_IFACE,
- .vmi_name = "ng_iface",
- .vmi_dependson = VNET_MOD_NETGRAPH,
- .vmi_iattach = ng_iface_iattach,
- .vmi_idetach = ng_iface_idetach
-};
-#endif
-
/************************************************************************
HELPER STUFF
************************************************************************/
@@ -849,18 +837,7 @@ ng_iface_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
-#ifdef VIMAGE
- vnet_mod_register(&vnet_ng_iface_modinfo);
-#else
- ng_iface_iattach(NULL);
-#endif
- break;
case MOD_UNLOAD:
-#ifdef VIMAGE
- vnet_mod_deregister(&vnet_ng_iface_modinfo);
-#else
- ng_iface_idetach(NULL);
-#endif
break;
default:
error = EOPNOTSUPP;
@@ -869,18 +846,20 @@ ng_iface_mod_event(module_t mod, int event, void *data)
return (error);
}
-static int ng_iface_iattach(const void *unused)
+static void
+vnet_ng_iface_init(const void *unused)
{
V_ng_iface_unit = new_unrhdr(0, 0xffff, NULL);
-
- return (0);
}
+VNET_SYSINIT(vnet_ng_iface_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
+ vnet_ng_iface_init, NULL);
-static int ng_iface_idetach(const void *unused)
+static void
+vnet_ng_iface_uninit(const void *unused)
{
delete_unrhdr(V_ng_iface_unit);
-
- return (0);
}
+VNET_SYSUNINIT(vnet_ng_iface_uninit, SI_SUB_PSEUDO, SI_ORDER_ANY,
+ vnet_ng_iface_uninit, NULL);
diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c
index 0d59979..af68c63 100644
--- a/sys/netgraph/ng_socket.c
+++ b/sys/netgraph/ng_socket.c
@@ -67,6 +67,9 @@
#ifdef NOTYET
#include <sys/vnode.h>
#endif
+
+#include <net/vnet.h>
+
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_socketvar.h>
@@ -1112,17 +1115,12 @@ ngs_mod_event(module_t mod, int event, void *data)
switch (event) {
case MOD_LOAD:
- /* Register protocol domain. */
- net_add_domain(&ngdomain);
break;
case MOD_UNLOAD:
#ifdef NOTYET
/* Unregister protocol domain XXX can't do this yet.. */
- if ((error = net_rm_domain(&ngdomain)) != 0)
- break;
- else
#endif
- error = EBUSY;
+ error = EBUSY;
break;
default:
error = EOPNOTSUPP;
@@ -1131,6 +1129,8 @@ ngs_mod_event(module_t mod, int event, void *data)
return (error);
}
+VNET_DOMAIN_SET(ng);
+
SYSCTL_INT(_net_graph, OID_AUTO, family, CTLFLAG_RD, 0, AF_NETGRAPH, "");
SYSCTL_NODE(_net_graph, OID_AUTO, data, CTLFLAG_RW, 0, "DATA");
SYSCTL_INT(_net_graph_data, OID_AUTO, proto, CTLFLAG_RD, 0, NG_DATA, "");
OpenPOWER on IntegriCloud