summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorzec <zec@FreeBSD.org>2008-10-02 15:37:58 +0000
committerzec <zec@FreeBSD.org>2008-10-02 15:37:58 +0000
commit8797d4caecd5881e312923ee1d07be3de68755dc (patch)
tree53fef93d1ff076abec439159e0a765427992dee1 /sys/netgraph
parente682bfadb0a191a81290af2b846d8610ef3aff5c (diff)
downloadFreeBSD-src-8797d4caecd5881e312923ee1d07be3de68755dc.zip
FreeBSD-src-8797d4caecd5881e312923ee1d07be3de68755dc.tar.gz
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08: http://wiki.freebsd.org/Image/Notes200808DevSummit Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator macros, and CURVNET_SET() context setting macros, all currently resolving to NOPs. Prepare for virtualization of selected SYSCTL objects by introducing a family of SYSCTL_V_*() macros, currently resolving to their global counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT(). Move selected #defines from sys/sys/vimage.h to newly introduced header files specific to virtualized subsystems (sys/net/vnet.h, sys/netinet/vinet.h etc.). All the changes are verified to have zero functional impact at this point in time by doing MD5 comparision between pre- and post-change object files(*). (*) netipsec/keysock.c did not validate depending on compile time options. Implemented by: julian, bz, brooks, zec Reviewed by: julian, bz, brooks, kris, rwatson, ... Approved by: julian (mentor) Obtained from: //depot/projects/vimage-commit2/... X-MFC after: never Sponsored by: NLnet Foundation, The FreeBSD Foundation
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/atm/ng_atm.c27
-rw-r--r--sys/netgraph/netgraph.h19
-rw-r--r--sys/netgraph/ng_base.c6
-rw-r--r--sys/netgraph/ng_eiface.c8
-rw-r--r--sys/netgraph/ng_gif.c14
-rw-r--r--sys/netgraph/ng_iface.c8
6 files changed, 72 insertions, 10 deletions
diff --git a/sys/netgraph/atm/ng_atm.c b/sys/netgraph/atm/ng_atm.c
index 1378eec..2beed32 100644
--- a/sys/netgraph/atm/ng_atm.c
+++ b/sys/netgraph/atm/ng_atm.c
@@ -1379,6 +1379,7 @@ ng_atm_constructor(node_p nodep)
static int
ng_atm_mod_event(module_t mod, int event, void *data)
{
+ VNET_ITERATOR_DECL(vnet_iter);
struct ifnet *ifp;
int error = 0;
@@ -1402,10 +1403,17 @@ ng_atm_mod_event(module_t mod, int event, void *data)
ng_atm_event_p = ng_atm_event;
/* Create nodes for existing ATM interfaces */
- TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- if (ifp->if_type == IFT_ATM)
- ng_atm_attach(ifp);
+ 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);
+ }
+ CURVNET_RESTORE();
}
+ VNET_LIST_RUNLOCK();
IFNET_RUNLOCK();
break;
@@ -1419,10 +1427,17 @@ ng_atm_mod_event(module_t mod, int event, void *data)
ng_atm_input_orphan_p = NULL;
ng_atm_event_p = NULL;
- TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- if (ifp->if_type == IFT_ATM)
- ng_atm_detach(ifp);
+ 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);
+ }
+ CURVNET_RESTORE();
}
+ VNET_LIST_RUNLOCK();
IFNET_RUNLOCK();
break;
diff --git a/sys/netgraph/netgraph.h b/sys/netgraph/netgraph.h
index 53fab56..1fc0b19 100644
--- a/sys/netgraph/netgraph.h
+++ b/sys/netgraph/netgraph.h
@@ -1184,4 +1184,23 @@ typedef void *meta_p;
#define NGI_GET_META(i,m)
#define ng_copy_meta(meta) NULL
+/* Hash related definitions */
+#define NG_ID_HASH_SIZE 128 /* most systems wont need even this many */
+
+/* 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)
+
+/* 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 82caad1..2a84d429 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -167,7 +167,6 @@ static struct mtx ng_typelist_mtx;
/* Hash related definitions */
/* XXX Don't need to initialise them because it's a LIST */
-#define NG_ID_HASH_SIZE 128 /* most systems wont need even this many */
static LIST_HEAD(, ng_node) ng_ID_hash[NG_ID_HASH_SIZE];
static struct mtx ng_idhash_mtx;
/* Method to find a node.. used twice so do it here */
@@ -612,6 +611,7 @@ 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 */
@@ -793,6 +793,7 @@ 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);
@@ -818,6 +819,7 @@ 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;
@@ -868,6 +870,7 @@ 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;
@@ -2430,6 +2433,7 @@ 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;
diff --git a/sys/netgraph/ng_eiface.c b/sys/netgraph/ng_eiface.c
index ae47c75..dc52f95 100644
--- a/sys/netgraph/ng_eiface.c
+++ b/sys/netgraph/ng_eiface.c
@@ -333,6 +333,7 @@ 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};
@@ -545,11 +546,18 @@ 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;
+ /*
+ * the ifnet may be in a different vnet than the netgraph node,
+ * hence we have to change the current vnet context here.
+ */
+ CURVNET_SET_QUIET(ifp->if_vnet);
ether_ifdetach(ifp);
if_free(ifp);
+ CURVNET_RESTORE();
free_unr(V_ng_eiface_unit, priv->unit);
FREE(priv, M_NETGRAPH);
NG_NODE_SET_PRIVATE(node, NULL);
diff --git a/sys/netgraph/ng_gif.c b/sys/netgraph/ng_gif.c
index 139a50b..96113d2 100644
--- a/sys/netgraph/ng_gif.c
+++ b/sys/netgraph/ng_gif.c
@@ -541,6 +541,7 @@ ng_gif_disconnect(hook_p hook)
static int
ng_gif_mod_event(module_t mod, int event, void *data)
{
+ VNET_ITERATOR_DECL(vnet_iter);
struct ifnet *ifp;
int error = 0;
int s;
@@ -561,10 +562,17 @@ ng_gif_mod_event(module_t mod, int event, void *data)
/* Create nodes for any already-existing gif interfaces */
IFNET_RLOCK();
- TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- if (ifp->if_type == IFT_GIF)
- ng_gif_attach(ifp);
+ 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);
+ }
+ CURVNET_RESTORE();
}
+ VNET_LIST_RUNLOCK();
IFNET_RUNLOCK();
break;
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index 3753adb..b216bfc 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -506,6 +506,7 @@ 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;
@@ -766,11 +767,18 @@ 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);
+ /*
+ * The ifnet may be in a different vnet than the netgraph node,
+ * hence we have to change the current vnet context here.
+ */
+ CURVNET_SET_QUIET(priv->ifp->if_vnet);
bpfdetach(priv->ifp);
if_detach(priv->ifp);
if_free(priv->ifp);
+ CURVNET_RESTORE();
priv->ifp = NULL;
free_unr(V_ng_iface_unit, priv->unit);
FREE(priv, M_NETGRAPH_IFACE);
OpenPOWER on IntegriCloud