Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Mar 2009 23:32:41 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 160078 for review
Message-ID:  <200903312332.n2VNWfPb017540@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=160078

Change 160078 by zec@zec_tpx32 on 2009/03/31 23:32:25

	Introduce vnet module registration / initialization framework
	with dependency tracking / ordering enforcement.
	
	With this change, per-vnet initialization functions introduced
	@159248 are no longer directly called from old / traditional
	initialization functions (thus in most cases inlined by cc to
	pre-159248 code), but are instead registered to the vnet
	framework first, and are invoked only after the prerequisite
	modules have been initialized.  In the long  run, this
	framework should allow us to both initialize and dismantle
	multiple vnet instances in a correct order.
	
	The problem this change aims to solve is how to reply the
	initialization sequence of various network stack components,
	which are traditionally triggered via different mechanisms
	(SYSINIT, protosw etc.) and which can be quite different
	depending on whether certain chunks of code are statically
	compiled into the kernel, loaded as modules by boot loader,
	or kldloaded at run time, even in presence of multiple already
	existing vnet instances.
	
	The approach is simple - we essentially record the init
	sequence established by existing code whenever
	vnet_mod_register() is called.  vnet_mod_register_multi()
	allows a single initializer function to be registered multiple
	times but with different arguments - currently this is only
	used in kern/uipc_domain.c by net_add_domain() with different
	struct domain * as arguments.  Additional ordering constraints
	may be specified by filling in the prerequisite vnet module ID
	in module's vnet_modinfo structure -> vmi_dependson field.
	Implicitly / unless specified otherwise all vnet modules depend
	on VNET_MOD_NET (container for ifnet list head, rt_tables etc.),
	which has to be initialized first.
	
	Currently, each module can specify only a single prerequisite,
	which may or may not be problematic.  In particular, INET6
	depends on INET being already instantiated, due to TCP / UDP
	structures residing in INET container.  IPSEC also depends on
	INET, which will in turn additionally complicate making
	INET6-only kernel configs a reality.

Affected files ...

.. //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#8 edit
.. //depot/projects/vimage-commit2/src/sys/kern/uipc_domain.c#3 edit
.. //depot/projects/vimage-commit2/src/sys/net/if.c#38 edit
.. //depot/projects/vimage-commit2/src/sys/net/if_gif.c#18 edit
.. //depot/projects/vimage-commit2/src/sys/net/if_loop.c#20 edit
.. //depot/projects/vimage-commit2/src/sys/net/route.c#30 edit
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_base.c#23 edit
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_eiface.c#17 edit
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_ether.c#11 edit
.. //depot/projects/vimage-commit2/src/sys/netgraph/ng_iface.c#15 edit
.. //depot/projects/vimage-commit2/src/sys/netinet/accf_http.c#2 edit
.. //depot/projects/vimage-commit2/src/sys/netinet/if_ether.c#29 edit
.. //depot/projects/vimage-commit2/src/sys/netinet/igmp.c#20 edit
.. //depot/projects/vimage-commit2/src/sys/netinet/ip_fw2.c#36 edit
.. //depot/projects/vimage-commit2/src/sys/netinet/ip_input.c#30 edit
.. //depot/projects/vimage-commit2/src/sys/netinet6/ip6_input.c#25 edit
.. //depot/projects/vimage-commit2/src/sys/netipsec/ipsec.c#25 edit
.. //depot/projects/vimage-commit2/src/sys/netipsec/xform_ah.c#14 edit
.. //depot/projects/vimage-commit2/src/sys/netipsec/xform_esp.c#14 edit
.. //depot/projects/vimage-commit2/src/sys/netipsec/xform_ipcomp.c#12 edit
.. //depot/projects/vimage-commit2/src/sys/netipsec/xform_ipip.c#15 edit
.. //depot/projects/vimage-commit2/src/sys/sys/vimage.h#31 edit

Differences ...

==== //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#8 (text+ko) ====

@@ -41,22 +41,133 @@
 
 #ifndef VIMAGE_GLOBALS
 
+#define DEBUG_ORDERING
+
 MALLOC_DEFINE(M_VIMAGE, "vimage", "vimage resource container");
 
 static TAILQ_HEAD(vnet_modlink_head, vnet_modlink) vnet_modlink_head;
+static TAILQ_HEAD(vnet_modpending_head, vnet_modlink) vnet_modpending_head;
+static void vnet_mod_complete_registration(struct vnet_modlink *);
+static int vnet_mod_constructor(struct vnet_modlink *);
 
 void
 vnet_mod_register(const struct vnet_modinfo *vmi)
 {
+
+	vnet_mod_register_multi(vmi, NULL, NULL);
+}
+
+void
+vnet_mod_register_multi(const struct vnet_modinfo *vmi, void *iarg,
+    char *iname)
+{
 	struct vnet_modlink *vml, *vml_iter;
 	
 	/* Do not register the same module instance more than once. */
 	TAILQ_FOREACH(vml_iter, &vnet_modlink_head, vml_mod_le)
-		if (vml_iter->vml_modinfo == vmi)
-			panic("%s: %s", __func__, vmi->vmi_name);
+		if (vml_iter->vml_modinfo == vmi && vml_iter->vml_iarg == iarg)
+			break;
+	if (vml_iter != NULL)
+		panic("attempt to register an already registered vnet module");
 	vml = malloc(sizeof(struct vnet_modlink), M_VIMAGE, M_NOWAIT);
+
+	/*
+	 * XXX we support only statically assigned module IDs at the time.
+	 * In principle modules should be able to get a dynamically
+	 * assigned ID at registration time.
+	 */
+	VNET_ASSERT(vmi->vmi_id > 0 || vmi->vmi_id < VNET_MOD_MAX);
+	VNET_ASSERT(!((iarg == NULL) ^ (iname == NULL)));
+
 	vml->vml_modinfo = vmi;
+	vml->vml_iarg = iarg;
+	vml->vml_iname = iname;
+
+	/* Check whether the module we depend on is already registered */
+	if (vmi->vmi_dependson != vmi->vmi_id) {
+		TAILQ_FOREACH(vml_iter, &vnet_modlink_head, vml_mod_le)
+			if (vml_iter->vml_modinfo->vmi_id ==
+			    vmi->vmi_dependson)
+				break;	/* Depencency found, we are done */
+		if (vml_iter == NULL) {
+#ifdef DEBUG_ORDERING
+			printf("dependency %d missing for vnet mod %s,"
+			    "postponing registration\n",
+			    vmi->vmi_dependson, vmi->vmi_name);
+#endif /* DEBUG_ORDERING */
+			TAILQ_INSERT_TAIL(&vnet_modpending_head, vml,
+			    vml_mod_le);
+			return;
+		}
+	}
+
+	vnet_mod_complete_registration(vml);
+}
+	
+void
+vnet_mod_complete_registration(struct vnet_modlink *vml)
+{
+	VNET_ITERATOR_DECL(vnet_iter);
+	struct vnet_modlink *vml_iter;
+
 	TAILQ_INSERT_TAIL(&vnet_modlink_head, vml, vml_mod_le);
+
+	VNET_FOREACH(vnet_iter) {
+		CURVNET_SET_QUIET(vnet_iter);
+		vnet_mod_constructor(vml);
+		CURVNET_RESTORE();
+	}
+
+	/* Check for pending modules depending on us */
+	do {
+		TAILQ_FOREACH(vml_iter, &vnet_modpending_head, vml_mod_le)
+			if (vml_iter->vml_modinfo->vmi_dependson ==
+			    vml->vml_modinfo->vmi_id)
+				break;
+		if (vml_iter != NULL) {
+#ifdef DEBUG_ORDERING
+			printf("vnet mod %s now registering,"
+			    "dependency %d loaded\n",
+			    vml_iter->vml_modinfo->vmi_name,
+			    vml->vml_modinfo->vmi_id);
+#endif /* DEBUG_ORDERING */
+			TAILQ_REMOVE(&vnet_modpending_head, vml_iter,
+			    vml_mod_le);
+			vnet_mod_complete_registration(vml_iter);
+		}
+	} while (vml_iter != NULL);
+}
+
+static int vnet_mod_constructor(struct vnet_modlink *vml)
+{
+	const struct vnet_modinfo *vmi = vml->vml_modinfo;
+
+#ifdef DEBUG_ORDERING
+	printf("instatiating vnet_%s", vmi->vmi_name);
+	if (vml->vml_iarg)
+		printf("/%s", vml->vml_iname);
+	printf(": ");
+	if (vmi->vmi_struct_size)
+		printf("malloc(%d); ", vmi->vmi_struct_size);
+	if (vmi->vmi_iattach != NULL)
+		printf("iattach()");
+	printf("\n");
+#endif
+
+#ifdef VIMAGE
+	if (vmi->vmi_struct_size) {
+		void *mem = malloc(vmi->vmi_struct_size, M_VNET,
+		    M_NOWAIT | M_ZERO);
+		if (mem == NULL) /* XXX should return error, not panic */
+			panic("vi_alloc: malloc for %s\n", vmi->vmi_name);
+		curvnet->mod_data[vmi->vmi_id] = mem;
+	}
+#endif
+
+	if (vmi->vmi_iattach != NULL)
+		vmi->vmi_iattach(vml->vml_iarg);
+
+	return (0);
 }
 
 /*

==== //depot/projects/vimage-commit2/src/sys/kern/uipc_domain.c#3 (text+ko) ====

@@ -43,6 +43,7 @@
 #include <sys/mutex.h>
 #include <sys/socketvar.h>
 #include <sys/systm.h>
+#include <sys/vimage.h>
 #include <vm/uma.h>
 
 /*
@@ -64,6 +65,8 @@
 SYSINIT(domainfin, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, domainfinalize,
     NULL);
 
+static vnet_attach_fn net_init_domain;
+
 static struct callout pffast_callout;
 static struct callout pfslow_callout;
 
@@ -100,6 +103,14 @@
 	.pru_sopoll =		pru_sopoll_notsupp,
 };
 
+#ifndef VIMAGE_GLOBALS
+vnet_modinfo_t vnet_domain_modinfo = {
+	.vmi_id		= VNET_MOD_DOMAIN,
+	.vmi_name	= "domain",
+	.vmi_iattach	= net_init_domain
+};
+#endif
+
 static void
 protosw_init(struct protosw *pr)
 {
@@ -159,9 +170,10 @@
  * Note: you cant unload it again because a socket may be using it.
  * XXX can't fail at this time.
  */
-static void
-net_init_domain(struct domain *dp)
+static int
+net_init_domain(const void *arg)
 {
+	const struct domain *dp = arg;
 	struct protosw *pr;
 
 	if (dp->dom_init)
@@ -175,6 +187,7 @@
 	max_datalen = MHLEN - max_hdr;
 	if (max_datalen < 1)
 		panic("%s: max_datalen < 1", __func__);
+	return (0);
 }
 
 /*
@@ -210,7 +223,11 @@
 		    "domainfinalize()\n", dp->dom_name);
 #endif
 	mtx_unlock(&dom_mtx);
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register_multi(&vnet_domain_modinfo, dp, dp->dom_name);
+#else
 	net_init_domain(dp);
+#endif
 }
 
 static void

==== //depot/projects/vimage-commit2/src/sys/net/if.c#38 (text+ko) ====

@@ -182,9 +182,13 @@
 	VNET_SYMMAP_END
 };
 
-VNET_MOD_DECLARE(NET, net, vnet_net_iattach, vnet_net_idetach,
-    NONE, vnet_net_symmap)
-#endif
+static const vnet_modinfo_t vnet_net_modinfo = {
+	.vmi_id		= VNET_MOD_NET,
+	.vmi_name	= "net",
+	.vmi_symmap	= vnet_net_symmap,
+	.vmi_iattach	= vnet_net_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
 
 /*
  * System initialization

==== //depot/projects/vimage-commit2/src/sys/net/if_gif.c#18 (text+ko) ====

@@ -123,6 +123,15 @@
 static void	gif_clone_destroy(struct ifnet *);
 static int	vnet_gif_iattach(const void *);
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_gif_modinfo = {
+	.vmi_id		= VNET_MOD_GIF,
+	.vmi_name	= "gif",
+	.vmi_dependson	= VNET_MOD_NET,
+	.vmi_iattach	= vnet_gif_iattach
+};
+#endif
+
 IFC_SIMPLE_DECLARE(gif, 0);
 
 static int gifmodevent(module_t, int, void *);
@@ -282,7 +291,12 @@
 	case MOD_LOAD:
 		mtx_init(&gif_mtx, "gif_mtx", NULL, MTX_DEF);
 
+#ifndef VIMAGE_GLOBALS
+		vnet_mod_register(&vnet_gif_modinfo);
+#else
 		vnet_gif_iattach(NULL);
+#endif
+
 		if_clone_attach(&gif_cloner);
 
 		break;

==== //depot/projects/vimage-commit2/src/sys/net/if_loop.c#20 (text+ko) ====

@@ -106,6 +106,14 @@
 struct ifnet *loif;			/* Used externally */
 #endif
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_loif_modinfo = {
+	.vmi_id		= VNET_MOD_LOIF,
+	.vmi_name	= "loif",
+	.vmi_iattach	= vnet_loif_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 IFC_SIMPLE_DECLARE(lo, 1);
 
 static void
@@ -150,7 +158,7 @@
 static int vnet_loif_iattach(const void *unused __unused)
 {
 	INIT_VNET_NET(curvnet);
-                         
+
 	V_loif = NULL;
 	if_clone_attach(&lo_cloner);
 	return (0);
@@ -163,7 +171,11 @@
 
 	switch (type) {
 	case MOD_LOAD:
+#ifndef VIMAGE_GLOBALS
+		vnet_mod_register(&vnet_loif_modinfo);
+#else
 		vnet_loif_iattach(NULL);
+#endif
 		break;
 
 	case MOD_UNLOAD:

==== //depot/projects/vimage-commit2/src/sys/net/route.c#30 (text+ko) ====

@@ -108,6 +108,14 @@
 	    struct sockaddr *, struct sockaddr *);
 static int vnet_route_iattach(const void *);
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_rtable_modinfo = {
+	.vmi_id		= VNET_MOD_RTABLE,
+	.vmi_name	= "rtable",
+	.vmi_iattach	= vnet_route_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 /* compare two sockaddr structures */
 #define	sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0)
 
@@ -161,7 +169,11 @@
 		rt_numfibs = 1;
 	rn_init();	/* initialize all zeroes, all ones, mask table */
 
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_rtable_modinfo);
+#else
 	vnet_route_iattach(NULL);
+#endif
 }
 
 static int vnet_route_iattach(const void *unused __unused)

==== //depot/projects/vimage-commit2/src/sys/netgraph/ng_base.c#23 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netgraph/ng_eiface.c#17 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netgraph/ng_ether.c#11 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netgraph/ng_iface.c#15 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netinet/accf_http.c#2 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netinet/if_ether.c#29 (text+ko) ====

@@ -120,6 +120,15 @@
 static void	in_arpinput(struct mbuf *);
 #endif
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_arp_modinfo = {
+	.vmi_id		= VNET_MOD_ARP,
+	.vmi_name	= "arp",
+	.vmi_dependson	= VNET_MOD_INET,
+	.vmi_iattach	= arp_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 #ifdef AF_INET
 void arp_ifscrub(struct ifnet *ifp, uint32_t addr);
 
@@ -808,7 +817,11 @@
 arp_init(void)
 {
 
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_arp_modinfo);
+#else
 	arp_iattach(NULL);
+#endif
 
 	arpintrq.ifq_maxlen = 50;
 	mtx_init(&arpintrq.ifq_mtx, "arp_inq", NULL, MTX_DEF);

==== //depot/projects/vimage-commit2/src/sys/netinet/igmp.c#20 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netinet/ip_fw2.c#36 (text+ko) ====


==== //depot/projects/vimage-commit2/src/sys/netinet/ip_input.c#30 (text+ko) ====

@@ -224,6 +224,23 @@
 
 static void	ip_freef(struct ipqhead *, struct ipq *);
 
+#ifndef VIMAGE_GLOBALS
+static void vnet_inet_register(void);
+ 
+static const vnet_modinfo_t vnet_inet_modinfo = {
+	.vmi_id		= VNET_MOD_INET,
+	.vmi_name	= "inet",
+};
+ 
+static void vnet_inet_register()
+{
+  
+	vnet_mod_register(&vnet_inet_modinfo);
+}
+ 
+SYSINIT(inet, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, vnet_inet_register, 0);
+#endif
+
 /*
  * IP initialization: fill in IP protocol switch table.
  * All protocols not implemented in kernel go to raw IP protocol handler.

==== //depot/projects/vimage-commit2/src/sys/netinet6/ip6_input.c#25 (text+ko) ====

@@ -155,6 +155,25 @@
 static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
 #endif
 
+#ifndef VIMAGE_GLOBALS
+static void vnet_inet6_register(void);
+ 
+static const vnet_modinfo_t vnet_inet6_modinfo = {
+	.vmi_id		= VNET_MOD_INET6,
+	.vmi_name	= "inet6",
+	.vmi_dependson	= VNET_MOD_INET	/* XXX revisit - TCP/UDP needs this? */
+};
+ 
+static void
+vnet_inet6_register(void)
+{
+
+	vnet_mod_register(&vnet_inet6_modinfo);
+}
+ 
+SYSINIT(inet6, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, vnet_inet6_register, 0);
+#endif
+
 /*
  * IP6 initialization: fill in IP6 protocol switch table.
  * All protocols not implemented in kernel go to raw IP6 protocol handler.

==== //depot/projects/vimage-commit2/src/sys/netipsec/ipsec.c#25 (text+ko) ====

@@ -244,6 +244,15 @@
 
 MALLOC_DEFINE(M_IPSEC_INPCB, "inpcbpolicy", "inpcb-resident ipsec policy");
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_ipsec_modinfo = {
+	.vmi_id		= VNET_MOD_IPSEC,
+	.vmi_name	= "ipsec",
+	.vmi_dependson	= VNET_MOD_INET,	/* XXX revisit - INET6 ? */
+	.vmi_iattach	= ipsec_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 void
 ipsec_init(void)
 {
@@ -1760,7 +1769,12 @@
 ipsec_attach(void)
 {
 
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_ipsec_modinfo);
+#else
 	ipsec_iattach(NULL);
+#endif
+
 }
 
 static int

==== //depot/projects/vimage-commit2/src/sys/netipsec/xform_ah.c#14 (text+ko) ====

@@ -75,6 +75,15 @@
 
 static int ah_iattach(const void *);
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_ah_modinfo = {
+	.vmi_id		= VNET_MOD_AH,
+	.vmi_name	= "ipsec_ah",
+	.vmi_dependson	= VNET_MOD_IPSEC,
+	.vmi_iattach	= ah_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 /*
  * Return header size in bytes.  The old protocol did not support
  * the replay counter; the new protocol always includes the counter.
@@ -1223,7 +1232,11 @@
 {
 
 	xform_register(&ah_xformsw);
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_ah_modinfo);
+#else
 	ah_iattach(NULL);
+#endif
 }
 
 static int

==== //depot/projects/vimage-commit2/src/sys/netipsec/xform_esp.c#14 (text+ko) ====

@@ -92,6 +92,15 @@
 static int esp_output_cb(struct cryptop *crp);
 static int esp_iattach(const void *);
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_esp_modinfo = {
+	.vmi_id		= VNET_MOD_ESP,
+	.vmi_name	= "ipsec_esp",
+	.vmi_dependson	= VNET_MOD_IPSEC,
+	.vmi_iattach	= esp_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 /*
  * NB: this is public for use by the PF_KEY support.
  * NB: if you add support here; be sure to add code to esp_attach below!
@@ -993,7 +1002,11 @@
 {
 
 	xform_register(&esp_xformsw);
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_esp_modinfo);
+#else
 	esp_iattach(NULL);
+#endif
 }
 
 static int

==== //depot/projects/vimage-commit2/src/sys/netipsec/xform_ipcomp.c#12 (text+ko) ====

@@ -82,6 +82,15 @@
 static int ipcomp_output_cb(struct cryptop *crp);
 static int ipcomp_iattach(const void *);
 
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_ipcomp_modinfo = {
+	.vmi_id		= VNET_MOD_IPCOMP,
+	.vmi_name	= "ipsec_ipcomp",
+	.vmi_dependson	= VNET_MOD_IPSEC,
+	.vmi_iattach	= ipcomp_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
+
 struct comp_algo *
 ipcomp_algorithm_lookup(int alg)
 {
@@ -602,7 +611,11 @@
 {
 
 	xform_register(&ipcomp_xformsw);
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_ipcomp_modinfo);
+#else
 	ipcomp_iattach(NULL);
+#endif
 }
 
 static int

==== //depot/projects/vimage-commit2/src/sys/netipsec/xform_ipip.c#15 (text+ko) ====

@@ -108,6 +108,16 @@
 #define	M_IPSEC	(M_AUTHIPHDR|M_AUTHIPDGM|M_DECRYPTED)
 
 static void _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp);
+static int ipe4_iattach(const void *);
+
+#ifndef VIMAGE_GLOBALS
+static const vnet_modinfo_t vnet_ipip_modinfo = {
+	.vmi_id		= VNET_MOD_IPIP,
+	.vmi_name	= "ipsec_ipip",
+	.vmi_dependson	= VNET_MOD_IPSEC,
+	.vmi_iattach	= ipe4_iattach
+};
+#endif /* !VIMAGE_GLOBALS */
 
 #ifdef INET6
 /*
@@ -719,7 +729,11 @@
 	(void) encap_attach_func(AF_INET6, -1,
 		ipe4_encapcheck, (struct protosw *)&ipe6_protosw, NULL);
 #endif
+#ifndef VIMAGE_GLOBALS
+	vnet_mod_register(&vnet_ipip_modinfo);
+#else
 	ipe4_iattach(NULL);
+#endif
 }
 SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
 #endif	/* IPSEC */

==== //depot/projects/vimage-commit2/src/sys/sys/vimage.h#31 (text+ko) ====

@@ -35,34 +35,94 @@
 
 #include <sys/queue.h>
 
+#if defined(VIMAGE) && defined(VIMAGE_GLOBALS)
+#error "You cannot have both option VIMAGE and option VIMAGE_GLOBALS!"
+#endif
+
+#ifndef VIMAGE_GLOBALS
+
 struct kld_sym_lookup;
 
+typedef int vnet_attach_fn(const void *);
+typedef int vnet_detach_fn(const void *);
+
 struct vnet_symmap {
 	char	*name;
 	void	*base;
 	size_t	size;
 };
+typedef struct vnet_symmap vnet_symmap_t;
 
 struct vnet_modinfo {
+	u_int				 vmi_id;
+	u_int				 vmi_dependson;
 	char				*vmi_name;
+	vnet_attach_fn			*vmi_iattach;
+	vnet_detach_fn			*vmi_idetach;
+	size_t				 vmi_struct_size;
 	struct vnet_symmap		*vmi_symmap;
 };
+typedef struct vnet_modinfo vnet_modinfo_t;
 
 struct vnet_modlink {
-	TAILQ_ENTRY(vnet_modlink)	vml_mod_le;
+	TAILQ_ENTRY(vnet_modlink)	 vml_mod_le;
 	const struct vnet_modinfo	*vml_modinfo;
+	const void			*vml_iarg;
+	const char			*vml_iname;
 };
 
-#define VNET_MOD_DECLARE(m_name_uc, m_name_lc, m_iattach, m_idetach, 	\
-    m_dependson, m_symmap)						\
-	static const struct vnet_modinfo vnet_##m_name_lc##_modinfo = {	\
-		.vmi_name		= #m_name_lc,			\
-		.vmi_symmap		= m_symmap			\
-};
+#define VNET_SYMMAP(mod, name)						\
+	{ #name, &(vnet_ ## mod ## _0._ ## name),			\
+	sizeof(vnet_ ## mod ## _0._ ## name) }
+
+#define VNET_SYMMAP_END		{ NULL, 0 }
+
+/* statefull modules */
+#define VNET_MOD_NET		 0
+#define VNET_MOD_NETGRAPH	 1
+#define VNET_MOD_INET		 2
+#define VNET_MOD_INET6		 3
+#define VNET_MOD_IPSEC		 4
+#define VNET_MOD_IPFW		 5
+#define VNET_MOD_DUMMYNET	 6
+#define VNET_MOD_PF		 7
+#define VNET_MOD_ALTQ		 8
+#define VNET_MOD_IPX		 9
+#define VNET_MOD_ATALK		10
+#define VNET_MOD_ACCF_HTTP	11
+#define VNET_MOD_IGMP		12
+
+/* stateless modules */
+#define VNET_MOD_NG_ETHER	20
+#define VNET_MOD_NG_IFACE	21
+#define VNET_MOD_NG_EIFACE	22
+#define VNET_MOD_ESP		23
+#define VNET_MOD_IPIP		24
+#define VNET_MOD_AH		25
+#define VNET_MOD_IPCOMP	 	26	
+#define VNET_MOD_GIF		27
+#define VNET_MOD_ARP		28
+#define VNET_MOD_RTABLE		29
+#define VNET_MOD_LOIF		30
+#define VNET_MOD_DOMAIN		31
+#define VNET_MOD_DYNAMIC_START	32
+#define VNET_MOD_MAX		64
+
+/* Sysctl virtualization macros need these name mappings bellow */
+#define V_MOD_vnet_net		VNET_MOD_NET
+#define V_MOD_vnet_netgraph	VNET_MOD_NETGRAPH
+#define V_MOD_vnet_inet		VNET_MOD_INET
+#define V_MOD_vnet_inet6	VNET_MOD_INET6
+#define V_MOD_vnet_ipfw		VNET_MOD_IPFW
+#define V_MOD_vnet_pf		VNET_MOD_PF
+#define V_MOD_vnet_gif		VNET_MOD_GIF
+#define V_MOD_vnet_ipsec	VNET_MOD_IPSEC
+
+int	vi_symlookup(struct kld_sym_lookup *, char *);
+void	vnet_mod_register(const struct vnet_modinfo *);
+void	vnet_mod_register_multi(const struct vnet_modinfo *, void *, char *);
 
-#if defined(VIMAGE) && defined(VIMAGE_GLOBALS)
-#error "You cannot have both option VIMAGE and option VIMAGE_GLOBALS!"
-#endif
+#endif /* !VIMAGE_GLOBALS */
 
 #ifdef VIMAGE_GLOBALS
 #define	VSYM(base, sym) (sym)
@@ -74,12 +134,6 @@
 #endif
 #endif
 
-#define VNET_SYMMAP(mod, name)						\
-	{ #name, &(vnet_ ## mod ## _0._ ## name),			\
-	sizeof(vnet_ ## mod ## _0._ ## name) }
-
-#define VNET_SYMMAP_END		{ NULL, 0 }
-
 /* Non-VIMAGE null-macros */
 #define	IS_DEFAULT_VNET(arg) 1
 #define	CURVNET_SET(arg)
@@ -110,9 +164,6 @@
 #define	G_hostname		VPROCG(hostname) /* global hostname */
 #define	V_domainname		VPROCG(domainname)
 
-int	vi_symlookup(struct kld_sym_lookup *, char *);
-void	vnet_mod_register(const struct vnet_modinfo *);
-
 /*
  * Size-guards for the vimage structures.
  * If you need to update the values you MUST increment __FreeBSD_version.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903312332.n2VNWfPb017540>