PERFORCE change 124616 for review
Marko Zec
zec at FreeBSD.org
Fri Aug 3 15:15:41 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=124616
Change 124616 by zec at zec_tpx32 on 2007/08/03 22:15:17
Promote ng_iface and ng_eiface to vnet modules, in order to
ensure they become registered only after netgraph vnet module.
In both ng_iface and ng_eiface, during vnet cleanup destroy
all per-vnet instances of iface / eiface netgraph nodes.
Add a missing VNET_MOD_NG_ETHER definition to sys/vimage.h
which should have been already submited along the changes to
ng_ether.
Affected files ...
.. //depot/projects/vimage/src/sys/netgraph/ng_eiface.c#6 edit
.. //depot/projects/vimage/src/sys/netgraph/ng_iface.c#3 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#31 edit
Differences ...
==== //depot/projects/vimage/src/sys/netgraph/ng_eiface.c#6 (text+ko) ====
@@ -45,7 +45,9 @@
#include <net/if.h>
#include <net/if_types.h>
#include <net/netisr.h>
+#include <net/route.h>
+#include <netgraph/vnetgraph.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
@@ -114,8 +116,16 @@
};
NETGRAPH_INIT(eiface, &typestruct);
+static vnet_attach_fn ng_eiface_iattach;
+static vnet_detach_fn ng_eiface_idetach;
+
+#ifndef VIMAGE
static struct unrhdr *ng_eiface_unit;
+#endif
+VNET_MOD_DECLARE_STATELESS(NG_EIFACE, ng_eiface, ng_eiface_iattach,
+ ng_eiface_idetach, NETGRAPH)
+
/************************************************************************
INTERFACE STUFF
************************************************************************/
@@ -335,6 +345,7 @@
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};
@@ -354,7 +365,7 @@
ifp->if_softc = priv;
/* Get an interface unit number */
- priv->unit = alloc_unr(ng_eiface_unit);
+ priv->unit = alloc_unr(V_ng_eiface_unit);
/* Link together node and private info */
NG_NODE_SET_PRIVATE(node, priv);
@@ -446,8 +457,6 @@
caddr_t ptr;
int buflen;
-#define SA_SIZE(s) ((s)->sa_len<sizeof(*(s))? sizeof(*(s)):(s)->sa_len)
-
/* Determine size of response and allocate it */
buflen = 0;
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
@@ -545,6 +554,7 @@
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;
@@ -552,7 +562,7 @@
ether_ifdetach(ifp);
if_free(ifp);
CURVNET_RESTORE();
- free_unr(ng_eiface_unit, priv->unit);
+ free_unr(V_ng_eiface_unit, priv->unit);
FREE(priv, M_NETGRAPH);
NG_NODE_SET_PRIVATE(node, NULL);
NG_NODE_UNREF(node);
@@ -581,10 +591,18 @@
switch (event) {
case MOD_LOAD:
- ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
+#ifdef VIMAGE
+ vnet_mod_register(&vnet_ng_eiface_modinfo);
+#else
+ ng_eiface_iattach(NULL);
+#endif
break;
case MOD_UNLOAD:
- delete_unrhdr(ng_eiface_unit);
+#ifdef VIMAGE
+ vnet_mod_deregister(&vnet_ng_eiface_modinfo);
+#else
+ ng_eiface_idetach(NULL);
+#endif
break;
default:
error = EOPNOTSUPP;
@@ -592,3 +610,32 @@
}
return (error);
}
+
+static int ng_eiface_iattach(const void *unused)
+{
+ INIT_VNET_NETGRAPH(curvnet);
+
+ V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
+
+ return 0;
+}
+
+static int ng_eiface_idetach(const void *unused)
+{
+ INIT_VNET_NETGRAPH(curvnet);
+#ifdef VIMAGE
+ node_p node;
+
+ do {
+ LIST_FOREACH(node, &V_ng_nodelist, nd_nodes)
+ if (node->nd_type == &typestruct)
+ break;
+ if (node != NULL)
+ ng_rmnode_self(node);
+ } while (node != NULL);
+#endif
+
+ delete_unrhdr(V_ng_eiface_unit);
+
+ return 0;
+}
==== //depot/projects/vimage/src/sys/netgraph/ng_iface.c#3 (text+ko) ====
@@ -79,6 +79,7 @@
#include <netinet/in.h>
+#include <netgraph/vnetgraph.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
@@ -209,7 +210,15 @@
};
NETGRAPH_INIT(iface, &typestruct);
+static vnet_attach_fn ng_iface_iattach;
+static vnet_detach_fn ng_iface_idetach;
+
+#ifndef VIMAGE
static struct unrhdr *ng_iface_unit;
+#endif
+
+VNET_MOD_DECLARE_STATELESS(NG_IFACE, ng_iface, ng_iface_iattach,
+ ng_iface_idetach, NETGRAPH)
/************************************************************************
HELPER STUFF
@@ -507,6 +516,7 @@
static int
ng_iface_constructor(node_p node)
{
+ INIT_VNET_NETGRAPH(curvnet);
struct ifnet *ifp;
priv_p priv;
@@ -525,7 +535,7 @@
priv->ifp = ifp;
/* Get an interface unit number */
- priv->unit = alloc_unr(ng_iface_unit);
+ priv->unit = alloc_unr(V_ng_iface_unit);
/* Link together node and private info */
NG_NODE_SET_PRIVATE(node, priv);
@@ -766,6 +776,7 @@
static int
ng_iface_shutdown(node_p node)
{
+ INIT_VNET_NETGRAPH(curvnet);
const priv_p priv = NG_NODE_PRIVATE(node);
CURVNET_SET_QUIET(priv->ifp->if_vnet);
@@ -774,7 +785,7 @@
if_free(priv->ifp);
CURVNET_RESTORE();
priv->ifp = NULL;
- free_unr(ng_iface_unit, priv->unit);
+ free_unr(V_ng_iface_unit, priv->unit);
FREE(priv, M_NETGRAPH_IFACE);
NG_NODE_SET_PRIVATE(node, NULL);
NG_NODE_UNREF(node);
@@ -807,10 +818,18 @@
switch (event) {
case MOD_LOAD:
- ng_iface_unit = new_unrhdr(0, 0xffff, NULL);
+#ifdef VIMAGE
+ vnet_mod_register(&vnet_ng_iface_modinfo);
+#else
+ ng_iface_iattach(NULL);
+#endif
break;
case MOD_UNLOAD:
- delete_unrhdr(ng_iface_unit);
+#ifdef VIMAGE
+ vnet_mod_deregister(&vnet_ng_iface_modinfo);
+#else
+ ng_iface_idetach(NULL);
+#endif
break;
default:
error = EOPNOTSUPP;
@@ -818,3 +837,32 @@
}
return (error);
}
+
+static int ng_iface_iattach(const void *unused)
+{
+ INIT_VNET_NETGRAPH(curvnet);
+
+ V_ng_iface_unit = new_unrhdr(0, 0xffff, NULL);
+
+ return 0;
+}
+
+static int ng_iface_idetach(const void *unused)
+{
+ INIT_VNET_NETGRAPH(curvnet);
+#ifdef VIMAGE
+ node_p node;
+
+ do {
+ LIST_FOREACH(node, &V_ng_nodelist, nd_nodes)
+ if (node->nd_type == &typestruct)
+ break;
+ if (node != NULL)
+ ng_rmnode_self(node);
+ } while (node != NULL);
+#endif
+
+ delete_unrhdr(V_ng_iface_unit);
+
+ return 0;
+}
==== //depot/projects/vimage/src/sys/sys/vimage.h#31 (text+ko) ====
@@ -79,6 +79,8 @@
#define VNET_MOD_ALTQ 8
#define VNET_MOD_IPX 9
#define VNET_MOD_ATALK 10
+
+#define VNET_MOD_NG_ETHER 20
#define VNET_MOD_NG_IFACE 21
#define VNET_MOD_NG_EIFACE 22
#define VNET_MOD_ESP 23
More information about the p4-projects
mailing list