diff options
Diffstat (limited to 'sys/netgraph')
| -rw-r--r-- | sys/netgraph/atm/ng_atm.c | 27 | ||||
| -rw-r--r-- | sys/netgraph/netgraph.h | 19 | ||||
| -rw-r--r-- | sys/netgraph/ng_base.c | 6 | ||||
| -rw-r--r-- | sys/netgraph/ng_eiface.c | 8 | ||||
| -rw-r--r-- | sys/netgraph/ng_gif.c | 14 | ||||
| -rw-r--r-- | sys/netgraph/ng_iface.c | 8 |
6 files changed, 72 insertions, 10 deletions
diff --git a/sys/netgraph/atm/ng_atm.c b/sys/netgraph/atm/ng_atm.c index 1378eec7d55c..2beed3292827 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 53fab56a9b9c..1fc0b19fdf4c 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 82caad1feeba..2a84d429f29e 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 ae47c752eab9..dc52f957294f 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 139a50b9af6d..96113d282c05 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 3753adbfdbb9..b216bfc0a505 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); |
