PERFORCE change 124354 for review
Marko Zec
zec at FreeBSD.org
Mon Jul 30 13:37:53 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124354
Change 124354 by zec at zec_tpx32 on 2007/07/30 13:37:17
Overhaul of memory allocation handling for vnet modules.
Previously, attach / detach functions in vnet modules were
individually responsible for allocating and freeing memory
for storing private state. This change hides the details
of memory management from vnet modules by providing them
with already allocated and zeroed storage before vnet's attach
method (if provided) is called, and by ensuring that this
storage will be freed immediately after vnet's detach method
(if provided) is executed.
From now on all vnet modules have to be declared through one
of the following two macros: VNET_MOD_DECLARE() or
VNET_MOD_DECLARE_STATELESS(). The former macro is to be
used when a vnet module requires an instance of private
storage to be allocated per each vnet, while the later form
should be used when no private storage is required, but only
the initialization ordering has to be enforced.
While here, deprecate backpointers from vnet modules to
the corresponding parent vnets, given that so far they have
never been used.
Affected files ...
.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#27 edit
.. //depot/projects/vimage/src/sys/kern/uipc_domain.c#8 edit
.. //depot/projects/vimage/src/sys/net/if.c#17 edit
.. //depot/projects/vimage/src/sys/net/if_gif.c#7 edit
.. //depot/projects/vimage/src/sys/net/if_gif.h#4 edit
.. //depot/projects/vimage/src/sys/net/if_loop.c#15 edit
.. //depot/projects/vimage/src/sys/net/route.c#9 edit
.. //depot/projects/vimage/src/sys/net/vnet.h#7 edit
.. //depot/projects/vimage/src/sys/netgraph/ng_base.c#11 edit
.. //depot/projects/vimage/src/sys/netinet/if_ether.c#12 edit
.. //depot/projects/vimage/src/sys/netinet/in_proto.c#7 edit
.. //depot/projects/vimage/src/sys/netinet/ip_fw.h#7 edit
.. //depot/projects/vimage/src/sys/netinet/ip_fw2.c#19 edit
.. //depot/projects/vimage/src/sys/netinet/ip_input.c#19 edit
.. //depot/projects/vimage/src/sys/netinet/ip_var.h#7 edit
.. //depot/projects/vimage/src/sys/netinet/tcp_subr.c#24 edit
.. //depot/projects/vimage/src/sys/netinet/tcp_syncache.h#6 edit
.. //depot/projects/vimage/src/sys/netinet/vinet.h#18 edit
.. //depot/projects/vimage/src/sys/netinet6/ip6_input.c#16 edit
.. //depot/projects/vimage/src/sys/netinet6/udp6_usrreq.c#16 edit
.. //depot/projects/vimage/src/sys/netinet6/vinet6.h#8 edit
.. //depot/projects/vimage/src/sys/netipsec/ipsec.c#12 edit
.. //depot/projects/vimage/src/sys/netipsec/vipsec.h#9 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ah.c#8 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_esp.c#7 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ipcomp.c#6 edit
.. //depot/projects/vimage/src/sys/netipsec/xform_ipip.c#9 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#28 edit
Differences ...
==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#27 (text+ko) ====
@@ -69,6 +69,8 @@
MALLOC_DEFINE(M_VCPU, "vcpu", "cpu resource control block");
static void vi_destroy(struct vimage *);
+static int vnet_mod_constructor(struct vnet_modlink *);
+static int vnet_mod_destructor(struct vnet_modlink *);
struct vimage vimage_0;
struct vprocg vprocg_0;
@@ -84,25 +86,25 @@
static TAILQ_HEAD(vnet_modlink_head, vnet_modlink) vnet_modlink_head;
-void vnet_mod_register(modinfo)
- struct vnet_modinfo *modinfo;
+void vnet_mod_register(vmi)
+ const struct vnet_modinfo *vmi;
{
- vnet_mod_register_multi(modinfo, NULL, NULL);
+ vnet_mod_register_multi(vmi, NULL, NULL);
}
-void vnet_mod_register_multi(modinfo, iarg, iname)
- struct vnet_modinfo *modinfo;
- void *iarg;
- char *iname;
+void vnet_mod_register_multi(vmi, iarg, iname)
+ const struct vnet_modinfo *vmi;
+ const void *iarg;
+ const char *iname;
{
struct vnet_modlink *vml;
/* Do not register the same module instance more than once */
- TAILQ_FOREACH(vml, &vnet_modlink_head, mod_le)
- if (vml->modinfo == modinfo && vml->iarg == iarg)
+ TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le)
+ if (vml->vml_modinfo == vmi && vml->vml_iarg == iarg)
break;
if (vml != NULL)
- panic("attempt to register already registered vnet module");
+ panic("attempt to register an already registered vnet module");
vml = malloc(sizeof(struct vnet_modlink), M_VIMAGE, M_NOWAIT);
/*
@@ -110,47 +112,43 @@
* In principle modules should be able to get a dynamically
* assigned ID at registration time.
*/
- VNET_ASSERT(modinfo->id > 0 || modinfo->id < VNET_MOD_MAX);
+ VNET_ASSERT(vmi->vmi_id > 0 || vmi->vmi_id < VNET_MOD_MAX);
VNET_ASSERT(!((iarg == NULL) ^ (iname == NULL)));
- vml->modinfo = modinfo;
- vml->iarg = iarg;
- vml->iname = iname;
- TAILQ_INSERT_TAIL(&vnet_modlink_head, vml, mod_le);
+ vml->vml_modinfo = vmi;
+ vml->vml_iarg = iarg;
+ vml->vml_iname = iname;
+ TAILQ_INSERT_TAIL(&vnet_modlink_head, vml, vml_mod_le);
- if (modinfo->i_attach) {
- VNET_ITERLOOP_BEGIN_QUIET();
- modinfo->i_attach(iarg);
- VNET_ITERLOOP_END();
- }
+ VNET_ITERLOOP_BEGIN_QUIET();
+ vnet_mod_constructor(vml);
+ VNET_ITERLOOP_END();
}
-void vnet_mod_deregister(modinfo)
- struct vnet_modinfo *modinfo;
+void vnet_mod_deregister(vmi)
+ const struct vnet_modinfo *vmi;
{
- vnet_mod_deregister_multi(modinfo, NULL, NULL);
+ vnet_mod_deregister_multi(vmi, NULL, NULL);
}
-void vnet_mod_deregister_multi(modinfo, iarg, iname)
- struct vnet_modinfo *modinfo;
- void *iarg;
- char *iname;
+void vnet_mod_deregister_multi(vmi, iarg, iname)
+ const struct vnet_modinfo *vmi;
+ const void *iarg;
+ const char *iname;
{
struct vnet_modlink *vml;
- TAILQ_FOREACH(vml, &vnet_modlink_head, mod_le)
- if (vml->modinfo == modinfo && vml->iarg == iarg)
+ TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le)
+ if (vml->vml_modinfo == vmi && vml->vml_iarg == iarg)
break;
if (vml == NULL)
panic("cannot deregister unregistered vnet module");
- if (modinfo->i_detach) {
- VNET_ITERLOOP_BEGIN_QUIET();
- modinfo->i_detach(iarg);
- VNET_ITERLOOP_END();
- }
+ VNET_ITERLOOP_BEGIN_QUIET();
+ vnet_mod_destructor(vml);
+ VNET_ITERLOOP_END();
- TAILQ_REMOVE(&vnet_modlink_head, vml, mod_le);
+ TAILQ_REMOVE(&vnet_modlink_head, vml, vml_mod_le);
free(vml, M_VIMAGE);
}
@@ -415,17 +413,17 @@
{
struct vnet_modlink *vml;
- TAILQ_FOREACH(vml, &vnet_modlink_head, mod_le) {
+ TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le) {
struct vnet_symmap *mapentry;
- if (vml->modinfo->symmap == NULL)
+ if (vml->vml_modinfo->vmi_symmap == NULL)
continue;
- for (mapentry = vml->modinfo->symmap;
+ for (mapentry = vml->vml_modinfo->vmi_symmap;
mapentry->name != NULL; mapentry++) {
if (strcmp(symstr, mapentry->name) == 0) {
lookup->symvalue =
- (int) curvnet->mod_data[vml->modinfo->id];
+ (int) curvnet->mod_data[vml->vml_modinfo->vmi_id]; /* XXX */
lookup->symvalue += mapentry->offset;
lookup->symsize = mapentry->size;
return 0;
@@ -457,29 +455,25 @@
if (vip == NULL)
goto vi_alloc_done;
- vip = realloc(vip, sizeof(struct vimage), M_VIMAGE, M_NOWAIT);
+ vip = realloc(vip, sizeof(struct vimage), M_VIMAGE, M_NOWAIT | M_ZERO);
if (vip == NULL)
panic("vi_alloc: malloc failed for vimage \"%s\"\n", name);
- bzero(vip, sizeof(struct vimage));
vip->vi_id = last_vi_id++;
- vnet = malloc(sizeof(struct vnet), M_VNET, M_NOWAIT);
+ vnet = malloc(sizeof(struct vnet), M_VNET, M_NOWAIT | M_ZERO);
if (vnet == NULL)
panic("vi_alloc: malloc failed for vnet \"%s\"\n", name);
- bzero(vnet, sizeof(struct vnet));
vip->v_vnet = vnet;
vnet->vnet_magic_n = VNET_MAGIC_N;
- vprocg = malloc(sizeof(struct vprocg), M_VPROCG, M_NOWAIT);
+ vprocg = malloc(sizeof(struct vprocg), M_VPROCG, M_NOWAIT | M_ZERO);
if (vprocg == NULL)
panic("vi_alloc: malloc failed for vprocg \"%s\"\n", name);
- bzero(vprocg, sizeof(struct vprocg));
vip->v_procg = vprocg;
- vcpu = malloc(sizeof(struct vcpu), M_VCPU, M_NOWAIT);
+ vcpu = malloc(sizeof(struct vcpu), M_VCPU, M_NOWAIT | M_ZERO);
if (vcpu == NULL)
panic ("vi_alloc: malloc failed for vcpu \"%s\"\n", name);
- bzero (vcpu, sizeof(struct vcpu));
vip->v_cpu = vcpu;
/* Some initialization stuff... */
@@ -487,12 +481,9 @@
CURVNET_SET_QUIET(vnet);
- /*
- * Initialize / attach module instances.
- */
- TAILQ_FOREACH(vml, &vnet_modlink_head, mod_le)
- if (vml->modinfo->i_attach != NULL)
- vml->modinfo->i_attach(vml->iarg);
+ /* Initialize / attach module instances. */
+ TAILQ_FOREACH(vml, &vnet_modlink_head, vml_mod_le)
+ vnet_mod_constructor(vml);
CURVNET_RESTORE();
@@ -553,9 +544,8 @@
* Detach / free per-module state instances.
*/
TAILQ_FOREACH_REVERSE(vml, &vnet_modlink_head,
- vnet_modlink_head, mod_le)
- if (vml->modinfo->i_detach)
- vml->modinfo->i_detach(vml->iarg);
+ vnet_modlink_head, vml_mod_le)
+ vnet_mod_destructor(vml);
#if 0
free((caddr_t)vnet->ifnet_addrs, M_IFADDR);
@@ -578,7 +568,42 @@
free(vip, M_VIMAGE);
}
+static int vnet_mod_constructor(vml)
+struct vnet_modlink *vml;
+{
+ const struct vnet_modinfo *vmi = vml->vml_modinfo;
+ if (vml->vml_modinfo->vmi_struct_size) {
+ void *mem = malloc(vmi->vmi_struct_size, M_VNET, M_NOWAIT);
+ if (mem == NULL) /* XXX should return error, not panic */
+ panic("vi_alloc: malloc for %s\n", vmi->vmi_name);
+ bzero(mem, vmi->vmi_struct_size);
+ curvnet->mod_data[vmi->vmi_id] = mem;
+ }
+
+ if (vml->vml_modinfo->vmi_iattach != NULL)
+ vml->vml_modinfo->vmi_iattach(vml->vml_iarg);
+
+ return 0;
+}
+
+static int vnet_mod_destructor(vml)
+struct vnet_modlink *vml;
+{
+ if (vml->vml_modinfo->vmi_idetach)
+ vml->vml_modinfo->vmi_idetach(vml->vml_iarg);
+ if (vml->vml_modinfo->vmi_struct_size) {
+ if (curvnet->mod_data[vml->vml_modinfo->vmi_id] == NULL)
+ panic("vi_destroy: %s\n",
+ vml->vml_modinfo->vmi_name);
+ free(curvnet->mod_data[vml->vml_modinfo->vmi_id],
+ M_VNET);
+ curvnet->mod_data[vml->vml_modinfo->vmi_id] = NULL;
+ }
+
+ return 0;
+}
+
static void
vi_init(void *unused)
{
@@ -621,19 +646,20 @@
if (arg)
db_printf(" %p", arg);
else
- db_printf(" 0x0");
+ db_printf(" 0");
}
DB_SHOW_COMMAND(vnets, db_show_vnets)
{
- db_printf(" vnet ifcs socks");
- db_printf(" net inet inet6 netgraph\n");
+ db_printf(" vnet ifs socks");
+ db_printf(" net inet inet6 ipsec netgraph\n");
VNET_ITERLOOP_BEGIN_QUIET();
- db_printf("%p %4d %5d",
+ db_printf("%p %3d %5d",
vnet_iter, vnet_iter->ifccnt, vnet_iter->sockcnt);
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NET]);
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_INET]);
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_INET6]);
+ db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_IPSEC]);
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NETGRAPH]);
db_printf("\n");
VNET_ITERLOOP_END();
==== //depot/projects/vimage/src/sys/kern/uipc_domain.c#8 (text+ko) ====
@@ -67,9 +67,9 @@
SYSINIT(domainfin, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, domainfinalize,
NULL)
-static int net_init_domain(void *);
+static vnet_attach_fn net_init_domain;
#ifdef VIMAGE
-static int net_detach_domain(void *);
+static vnet_detach_fn net_detach_domain;
#endif
static struct callout pffast_callout;
@@ -108,14 +108,7 @@
.pru_sopoll = pru_sopoll_notsupp,
};
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_domain_modinfo = {
- .id = VNET_MOD_DOMAIN,
- .name = "domain",
- .i_attach = net_init_domain,
- .i_detach = net_detach_domain
-};
-#endif
+VNET_MOD_DECLARE_STATELESS(DOMAIN, domain, net_init_domain, net_detach_domain)
static void
protosw_init(struct protosw *pr)
@@ -148,9 +141,9 @@
* Initialize a domain instance.
*/
static int
-net_init_domain(void *arg)
+net_init_domain(const void *arg)
{
- struct domain *dp = arg;
+ const struct domain *dp = arg;
struct protosw *pr;
if (dp->dom_init)
@@ -172,9 +165,9 @@
* Detach / free a domain instance.
*/
static int
-net_detach_domain(void *arg)
+net_detach_domain(const void *arg)
{
- struct domain *dp = arg;
+ const struct domain *dp = arg;
struct protosw *pr;
if (dp->dom_destroy)
==== //depot/projects/vimage/src/sys/net/if.c#17 (text+ko) ====
@@ -137,9 +137,9 @@
extern void nd6_setmtu(struct ifnet *);
#endif
-static int vnet_net_iattach(void *);
+static int vnet_net_iattach(const void *);
#ifdef VIMAGE
-static int vnet_net_idetach(void *);
+static int vnet_net_idetach(const void *);
#endif
int ifqmaxlen = IFQ_MAXLEN;
@@ -163,8 +163,6 @@
{ 1, NULL, filt_netdetach, filt_netdev };
#ifdef VIMAGE
-struct vnet_net vnet_net_0;
-
static struct vnet_symmap vnet_net_symmap[] = {
VNET_SYMMAP(net, ifnet),
VNET_SYMMAP(net, rt_tables),
@@ -173,15 +171,7 @@
VNET_SYMMAP_END
};
-static struct vnet_modinfo vnet_net_modinfo = {
- .id = VNET_MOD_NET,
- .name = "net",
- .symmap = vnet_net_symmap,
- .i_attach = vnet_net_iattach,
- .i_detach = vnet_net_idetach
-};
-
-MALLOC_DEFINE(M_NET, "net", "NET instance");
+VNET_MOD_DECLARE(NET, net, vnet_net_symmap, vnet_net_iattach, vnet_net_idetach)
#endif
/*
@@ -348,23 +338,10 @@
static int
vnet_net_iattach(unused)
- void *unused;
+ const void *unused;
{
-#ifdef VIMAGE
- struct vnet_net *vnet_net;
+ INIT_VNET_NET(curvnet);
- if (IS_VNET_0(curvnet)) {
- vnet_net = &vnet_net_0;
- } else {
- vnet_net = malloc(sizeof(struct vnet_net),
- M_NET, M_NOWAIT | M_ZERO);
- if (vnet_net == NULL)
- panic("couldn't allocate memory for vnet_net");
- }
- curvnet->mod_data[vnet_net_modinfo.id] = vnet_net;
- vnet_net->parent_vnet = curvnet;
-#endif
-
TAILQ_INIT(&V_ifnet);
TAILQ_INIT(&V_ifg_head);
knlist_init(&V_ifklist, NULL, NULL, NULL, NULL);
@@ -377,7 +354,7 @@
#ifdef VIMAGE
static int
vnet_net_idetach(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_NET(curvnet);
@@ -389,9 +366,6 @@
free((caddr_t)V_ifindex_table, M_IFNET);
- curvnet->mod_data[vnet_net_modinfo.id] = NULL;
- free((caddr_t)vnet_net, M_NET);
-
return 0;
}
#endif
==== //depot/projects/vimage/src/sys/net/if_gif.c#7 (text+ko) ====
@@ -107,8 +107,7 @@
static void gif_start(struct ifnet *);
static int gif_clone_create(struct if_clone *, int, caddr_t);
static void gif_clone_destroy(struct ifnet *);
-static int vnet_gif_iattach(void *);
-static int vnet_gif_idetach(void *);
+static int vnet_gif_iattach(const void *);
IFC_SIMPLE_DECLARE(gif, 0);
@@ -145,14 +144,7 @@
SYSCTL_V_INT(V_NET, vnet_gif, _net_link_gif, OID_AUTO, parallel_tunnels,
CTLFLAG_RW, parallel_tunnels, 0, "Allow parallel tunnels?");
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_gif_modinfo = {
- .id = VNET_MOD_GIF,
- .name = "gif",
- .i_attach = vnet_gif_iattach,
- .i_detach = vnet_gif_idetach
-};
-#endif
+VNET_MOD_DECLARE(GIF, gif, NULL, vnet_gif_iattach, NULL)
static int
gif_clone_create(ifc, unit, params)
@@ -238,17 +230,9 @@
static int
vnet_gif_iattach(unused)
- void *unused;
+ const void *unused;
{
-#ifdef VIMAGE
- struct vnet_gif *vnet_gif;
-
- vnet_gif = malloc(sizeof(*vnet_gif), M_GIF, M_NOWAIT | M_ZERO);
- if (vnet_gif == NULL)
- panic("couldn't allocate memory for vnet_gif");
- curvnet->mod_data[vnet_gif_modinfo.id] = vnet_gif;
- vnet_gif->parent_vnet = curvnet;
-#endif
+ INIT_VNET_GIF(curvnet);
LIST_INIT(&V_gif_softc_list);
V_max_gif_nesting = MAX_GIF_NEST;
@@ -265,20 +249,6 @@
}
static int
-vnet_gif_idetach(unused)
- void *unused;
-{
- INIT_VNET_GIF(curvnet);
-
-#ifdef VIMAGE
- curvnet->mod_data[vnet_gif_modinfo.id] = NULL;
- free(vnet_gif, M_GIF);
-#endif
-
- return 0;
-}
-
-static int
gifmodevent(mod, type, data)
module_t mod;
int type;
@@ -299,8 +269,6 @@
if_clone_detach(&gif_cloner);
#ifdef VIMAGE
vnet_mod_deregister(&vnet_gif_modinfo);
-#else
- vnet_gif_idetach(NULL);
#endif
mtx_destroy(&gif_mtx);
break;
==== //depot/projects/vimage/src/sys/net/if_gif.h#4 (text+ko) ====
@@ -119,8 +119,6 @@
#define VNET_GIF(sym) VSYM(vnet_gif, sym)
struct vnet_gif {
- struct vnet *parent_vnet;
-
LIST_HEAD(, gif_softc) _gif_softc_list;
int _max_gif_nesting;
int _parallel_tunnels;
==== //depot/projects/vimage/src/sys/net/if_loop.c#15 (text+ko) ====
@@ -106,9 +106,9 @@
struct sockaddr *dst, struct rtentry *rt);
static int lo_clone_create(struct if_clone *, int, caddr_t);
static void lo_clone_destroy(struct ifnet *);
-static int vnet_loif_iattach(void *);
+static int vnet_loif_iattach(const void *);
#ifdef VIMAGE
-static int vnet_loif_idetach(void *);
+static int vnet_loif_idetach(const void *);
#endif
#ifndef VIMAGE
@@ -180,17 +180,10 @@
return (0);
}
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_loif_modinfo = {
- .id = VNET_MOD_LOIF,
- .name = "loif",
- .i_attach = vnet_loif_iattach,
- .i_detach = vnet_loif_idetach
-};
-#endif
+VNET_MOD_DECLARE_STATELESS(LOIF, loif, vnet_loif_iattach, vnet_loif_idetach)
static int vnet_loif_iattach(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_NET(curvnet);
@@ -208,7 +201,7 @@
#ifdef VIMAGE
static int vnet_loif_idetach(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_NET(curvnet);
struct lo_softc *sc, *nsc;
==== //depot/projects/vimage/src/sys/net/route.c#9 (text+ko) ====
@@ -60,9 +60,9 @@
static void rt_maskedcopy(struct sockaddr *,
struct sockaddr *, struct sockaddr *);
-static int rtable_init(void *);
+static int rtable_init(const void *);
#ifdef VIMAGE
-static int rtable_idetach(void *);
+static int rtable_idetach(const void *);
#endif
/* compare two sockaddr structures */
@@ -80,18 +80,11 @@
*/
#define RNTORT(p) ((struct rtentry *)(p))
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_rtable_modinfo = {
- .id = VNET_MOD_RTABLE,
- .name = "rtable",
- .i_attach = rtable_init,
- .i_detach = rtable_idetach
-};
-#endif
+VNET_MOD_DECLARE_STATELESS(RTABLE, rtable, rtable_init, rtable_idetach)
static int
rtable_init(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_NET(curvnet);
@@ -106,7 +99,7 @@
#ifdef VIMAGE
static int
rtable_idetach(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_NET(curvnet);
==== //depot/projects/vimage/src/sys/net/vnet.h#7 (text+ko) ====
@@ -45,8 +45,6 @@
#include <net/raw_cb.h>
struct vnet_net {
- struct vnet *parent_vnet;
-
int _if_index;
struct ifindex_entry *_ifindex_table;
struct ifnethead _ifnet;
==== //depot/projects/vimage/src/sys/netgraph/ng_base.c#11 (text+ko) ====
@@ -248,17 +248,9 @@
#define NG_WORKLIST_UNLOCK() \
mtx_unlock(&ng_worklist_mtx)
-static int vnet_netgraph_iattach(void);
+static vnet_attach_fn vnet_netgraph_iattach;
-#ifdef VIMAGE
-struct vnet_netgraph vnet_netgraph_0;
-
-static struct vnet_modinfo vnet_netgraph_modinfo = {
- .id = VNET_MOD_NETGRAPH,
- .name = "netgraph",
- .i_attach = vnet_netgraph_iattach,
-};
-#endif
+VNET_MOD_DECLARE(NETGRAPH, netgraph, NULL, vnet_netgraph_iattach, NULL)
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
/*
@@ -3196,7 +3188,7 @@
#ifdef VIMAGE
vnet_mod_register(&vnet_netgraph_modinfo);
#else
- vnet_netgraph_iattach();
+ vnet_netgraph_iattach(NULL);
#endif
break;
case MOD_UNLOAD:
@@ -3210,22 +3202,9 @@
return (error);
}
-static int vnet_netgraph_iattach(void)
+static int vnet_netgraph_iattach(const void *unused)
{
-#ifdef VIMAGE
- struct vnet_netgraph *vnet_netgraph;
-
- if (IS_VNET_0(curvnet)) {
- vnet_netgraph = &vnet_netgraph_0;
- } else {
- vnet_netgraph = malloc(sizeof(struct vnet_netgraph),
- M_NETGRAPH, M_NOWAIT | M_ZERO);
- if (vnet_netgraph == NULL)
- panic("couldn't allocate memory for vnet_netgraph");
- }
- curvnet->mod_data[vnet_netgraph_modinfo.id] = vnet_netgraph;
- vnet_netgraph->parent_vnet = curvnet;
-#endif
+ INIT_VNET_NETGRAPH(curvnet);
LIST_INIT(&V_ng_nodelist);
==== //depot/projects/vimage/src/sys/netinet/if_ether.c#12 (text+ko) ====
@@ -119,7 +119,7 @@
"Enable proxy ARP for all suitable requests");
static void arp_init(void);
-static int arp_iattach(void *);
+static int arp_iattach(const void *);
static void arp_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
static void arprequest(struct ifnet *,
struct in_addr *, struct in_addr *, u_char *);
@@ -131,14 +131,7 @@
static void in_arpinput(struct mbuf *);
#endif
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_arp_modinfo = {
- .id = VNET_MOD_ARP,
- .name = "arp",
- .i_attach = arp_iattach,
- .i_detach = NULL,
-};
-#endif
+VNET_MOD_DECLARE_STATELESS(ARP, arp, arp_iattach, NULL)
/*
* Timeout routine.
@@ -982,7 +975,7 @@
static int
arp_iattach(unused)
- void *unused;
+ const void *unused;
{
INIT_VNET_INET(curvnet);
==== //depot/projects/vimage/src/sys/netinet/in_proto.c#7 (text+ko) ====
@@ -106,9 +106,6 @@
.pr_domain = &inetdomain,
.pr_protocol = IPPROTO_IP,
.pr_init = ip_init,
-#ifdef VIMAGE
- .pr_destroy = ip_detach,
-#endif
.pr_slowtimo = ip_slowtimo,
.pr_drain = ip_drain,
.pr_usrreqs = &nousrreqs
==== //depot/projects/vimage/src/sys/netinet/ip_fw.h#7 (text+ko) ====
@@ -654,8 +654,6 @@
*/
#ifdef VIMAGE
struct vnet_ipfw {
- struct vnet *parent_vnet;
-
int _fw_one_pass;
int _fw_enable;
int _fw6_enable;
==== //depot/projects/vimage/src/sys/netinet/ip_fw2.c#19 (text+ko) ====
@@ -112,17 +112,10 @@
#include <security/mac/mac_framework.h>
-static int vnet_ipfw_iattach(void);
-static int vnet_ipfw_idetach(void);
+static int vnet_ipfw_iattach(const void *);
+static int vnet_ipfw_idetach(const void *);
-#ifdef VIMAGE
-static struct vnet_modinfo vnet_ipfw_modinfo = {
- .id = VNET_MOD_IPFW,
- .name = "ipfw",
- .i_attach = vnet_ipfw_iattach,
- .i_detach = vnet_ipfw_idetach,
-};
-#endif
+VNET_MOD_DECLARE(IPFW, ipfw, NULL, vnet_ipfw_iattach, vnet_ipfw_idetach)
/*
* set_disable contains one bit per set value (0..31).
@@ -4955,19 +4948,11 @@
ipfw_tick, arg);
}
-static int vnet_ipfw_iattach(void)
+static int vnet_ipfw_iattach(const void *unused)
{
+ INIT_VNET_IPFW(curvnet);
struct ip_fw default_rule;
int error;
-#ifdef VIMAGE
- struct vnet_ipfw *vnet_ipfw;
-
- vnet_ipfw = malloc(sizeof(*vnet_ipfw), M_IPFW, M_NOWAIT | M_ZERO);
- if (vnet_ipfw == NULL)
- panic("couldn't allocate memory for vnet_ipfw");
- curvnet->mod_data[vnet_ipfw_modinfo.id] = vnet_ipfw;
- vnet_ipfw->parent_vnet = curvnet;
-#endif
V_fw_debug = 1;
V_autoinc_step = 100; /* bounded to 1..1000 in add_rule() */
@@ -5057,7 +5042,7 @@
#ifdef VIMAGE
vnet_mod_register(&vnet_ipfw_modinfo);
#else
- vnet_ipfw_iattach();
+ vnet_ipfw_iattach(NULL);
#endif
printf("ipfw2 "
@@ -5104,7 +5089,7 @@
return (0);
}
-static int vnet_ipfw_idetach(void)
+static int vnet_ipfw_idetach(const void *unused)
{
INIT_VNET_IPFW(curvnet);
struct ip_fw *reap;
@@ -5131,11 +5116,6 @@
reap_rules(reap);
IPFW_LOCK_DESTROY(&V_layer3_chain);
-#ifdef VIMAGE
- curvnet->mod_data[vnet_ipfw_modinfo.id] = NULL;
- free(vnet_ipfw, M_IPFW);
-#endif
-
return 0;
}
@@ -5148,7 +5128,7 @@
#ifdef VIMAGE
vnet_mod_deregister(&vnet_ipfw_modinfo);
#else
- vnet_ipfw_idetach();
+ vnet_ipfw_idetach(NULL);
#endif
#ifdef IPFIREWALL_NAT
==== //depot/projects/vimage/src/sys/netinet/ip_input.c#19 (text+ko) ====
@@ -213,22 +213,17 @@
static void ip_freef(struct ipqhead *, struct ipq *);
#ifdef VIMAGE
-static struct vnet_inet vnet_inet_0;
+static void vnet_inet_register(void);
-struct vnet_symmap vnet_inet_symmap[] = {
- VNET_SYMMAP_END
-};
+VNET_MOD_DECLARE(INET, inet, NULL, NULL, NULL)
-static struct vnet_modinfo vnet_inet_modinfo = {
- .id = VNET_MOD_INET,
- .name = "inet",
- .symmap = vnet_inet_symmap,
- .i_attach = NULL,
- .i_detach = NULL,
-};
+static void vnet_inet_register()
+{
+ vnet_mod_register(&vnet_inet_modinfo);
+}
-MALLOC_DEFINE(M_INET, "inet", "INET domain instance");
-#endif /* VIMAGE */
+SYSINIT(inet, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, vnet_inet_register, 0);
+#endif
/*
* IP initialization: fill in IP protocol switch table.
@@ -237,25 +232,10 @@
void
ip_init(void)
{
+ INIT_VNET_INET(curvnet);
struct protosw *pr;
int i;
-#ifdef VIMAGE
- struct vnet_inet *vnet_inet;
-
- if (IS_VNET_0(curvnet)) {
- vnet_mod_register(&vnet_inet_modinfo);
- vnet_inet = &vnet_inet_0;
- } else {
- vnet_inet = malloc(sizeof(struct vnet_inet),
- M_INET, M_NOWAIT | M_ZERO);
- if (vnet_inet == NULL)
- panic("couldn't allocate memory for vnet_inet");
- }
- curvnet->mod_data[vnet_inet_modinfo.id] = vnet_inet;
- vnet_inet->parent_vnet = curvnet;
-#endif
-
TAILQ_INIT(&V_in_ifaddrhead);
V_in_ifaddrhashtbl = hashinit(INADDR_NHASH, M_IFADDR,
&V_in_ifaddrhmask);
@@ -347,17 +327,6 @@
netisr_register(NETISR_IP, ip_input, &ipintrq, NETISR_MPSAFE);
}
-#ifdef VIMAGE
-void
-ip_detach()
-{
- INIT_VNET_INET(curvnet);
-
- free(vnet_inet, M_INET);
- curvnet->mod_data[vnet_inet_modinfo.id] = NULL;
-}
-#endif
-
void
ip_fini(void *xtp)
{
==== //depot/projects/vimage/src/sys/netinet/ip_var.h#7 (text+ko) ====
@@ -201,9 +201,6 @@
u_long if_hwassist_flags, int sw_csum);
void ip_forward(struct mbuf *m, int srcrt);
void ip_init(void);
-#ifdef VIMAGE
-void ip_detach(void);
-#endif
extern int
(*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
struct ip_moptions *);
==== //depot/projects/vimage/src/sys/netinet/tcp_subr.c#24 (text+ko) ====
==== //depot/projects/vimage/src/sys/netinet/tcp_syncache.h#6 (text+ko) ====
==== //depot/projects/vimage/src/sys/netinet/vinet.h#18 (text+ko) ====
@@ -55,8 +55,6 @@
#include <netinet/udp_var.h>
struct vnet_inet {
- struct vnet *parent_vnet;
-
struct in_ifaddrhashhead *_in_ifaddrhashtbl;
struct in_ifaddrhead _in_ifaddrhead;
u_long _in_ifaddrhmask;
==== //depot/projects/vimage/src/sys/netinet6/ip6_input.c#16 (text+ko) ====
@@ -146,21 +146,16 @@
#endif
#ifdef VIMAGE
-static struct vnet_inet6 vnet_inet6_0;
+static void vnet_inet6_register(void);
+
+VNET_MOD_DECLARE(INET6, inet6, NULL, NULL, NULL)
+
+static void vnet_inet6_register()
+{
+ vnet_mod_register(&vnet_inet6_modinfo);
+}
-struct vnet_symmap vnet_inet6_symmap[] = {
- VNET_SYMMAP_END
-};
-
-static struct vnet_modinfo vnet_inet6_modinfo = {
- .id = VNET_MOD_INET6,
- .name = "inet6",
- .symmap = vnet_inet6_symmap,
- .i_attach = NULL,
- .i_detach = NULL,
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list