Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 May 2010 13:22:50 GMT
From:      Ivor Prebeg <iprebeg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 178142 for review
Message-ID:  <201005121322.o4CDMoRS011248@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178142?ac=10

Change 178142 by iprebeg@iprebeg_nxlab_login on 2010/05/12 13:22:36

	Virtualizing static vars

Affected files ...

.. //depot/projects/vimage/src/sys/netinet6/ip6_mroute.c#32 edit

Differences ...

==== //depot/projects/vimage/src/sys/netinet6/ip6_mroute.c#32 (text+ko) ====

@@ -81,7 +81,14 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/sys/netinet6/ip6_mroute.c,v 1.64 2010/04/29 11:52:42 bz Exp $");
 
-#include "opt_inet.h"
+#define VIMAGE
+#define DIAGNOSTIC
+//#define MRT6DEBUG
+//#define MRT6_OINIT
+#define PIM6_CHECKSUM
+#define UPCALL_TIMING
+
+//#include "opt_inet.h"
 #include "opt_inet6.h"
 
 #include <sys/param.h>
@@ -158,9 +165,10 @@
 SYSCTL_DECL(_net_inet6_ip6);
 SYSCTL_NODE(_net_inet6, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
 
-static struct mrt6stat mrt6stat;
-SYSCTL_STRUCT(_net_inet6_ip6, OID_AUTO, mrt6stat, CTLFLAG_RW,
-    &mrt6stat, mrt6stat,
+static VNET_DEFINE(struct mrt6stat, mrt6stat);
+#define V_mrt6stat		VNET(mrt6stat)
+SYSCTL_VNET_STRUCT(_net_inet6_ip6, OID_AUTO, mrt6stat, CTLFLAG_RW,
+    &VNET_NAME(mrt6stat), mrt6stat,
     "Multicast Routing Statistics (struct mrt6stat, netinet6/ip6_mroute.h)");
 
 #define NO_RTE_FOUND	0x1
@@ -177,9 +185,10 @@
 	mtx_init(&mrouter6_mtx, "IPv6 multicast forwarding", NULL, MTX_DEF)
 #define	MROUTER6_LOCK_DESTROY()	mtx_destroy(&mrouter6_mtx)
 
-static struct mf6c *mf6ctable[MF6CTBLSIZ];
+static VNET_DEFINE(struct mf6c *, mf6ctable[MF6CTBLSIZ]);
+#define V_mf6ctable		VNET(mf6ctable)
 SYSCTL_OPAQUE(_net_inet6_ip6, OID_AUTO, mf6ctable, CTLFLAG_RD,
-    &mf6ctable, sizeof(mf6ctable), "S,*mf6ctable[MF6CTBLSIZ]",
+    &VNET_NAME(mf6ctable), sizeof(V_mf6ctable), "S,*mf6ctable[MF6CTBLSIZ]",
     "IPv6 Multicast Forwarding Table (struct *mf6ctable[MF6CTBLSIZ], "
     "netinet6/ip6_mroute.h)");
 
@@ -194,11 +203,13 @@
 	mtx_init(&mfc6_mtx, "IPv6 multicast forwarding cache", NULL, MTX_DEF)
 #define	MFC6_LOCK_DESTROY()	mtx_destroy(&mfc6_mtx)
 
-static u_char n6expire[MF6CTBLSIZ];
+static VNET_DEFINE(u_char, n6expire[MF6CTBLSIZ]);
+#define V_n6expire		VNET(n6expire)
 
-static struct mif6 mif6table[MAXMIFS];
+static VNET_DEFINE(struct mif6, mif6table[MAXMIFS]);
+#define V_mif6table		VNET(mif6table)
 SYSCTL_OPAQUE(_net_inet6_ip6, OID_AUTO, mif6table, CTLFLAG_RD,
-    &mif6table, sizeof(mif6table), "S,mif6[MAXMIFS]",
+    &VNET_NAME(mif6table), sizeof(V_mif6table), "S,mif6[MAXMIFS]",
     "IPv6 Multicast Interfaces (struct mif6[MAXMIFS], netinet6/ip6_mroute.h)");
 
 static struct mtx mif6_mtx;
@@ -246,12 +257,15 @@
 /*
  * Private variables.
  */
-static mifi_t nummifs = 0;
-static mifi_t reg_mif_num = (mifi_t)-1;
+static VNET_DEFINE(mifi_t, nummifs) = 0;
+#define V_nummifs		VNET(nummifs)
+static VNET_DEFINE(mifi_t, reg_mif_num) = (mifi_t)-1;
+#define V_reg_mif_num		VNET(reg_mif_num)
 
-static struct pim6stat pim6stat;
-SYSCTL_STRUCT(_net_inet6_pim, PIM6CTL_STATS, stats, CTLFLAG_RD,
-    &pim6stat, pim6stat,
+static VNET_DEFINE(struct pim6stat, pim6stat);
+#define V_pim6stat		VNET(pim6stat)
+SYSCTL_VNET_STRUCT(_net_inet6_pim, PIM6CTL_STATS, stats, CTLFLAG_RD,
+    &VNET_NAME(pim6stat), pim6stat,
     "PIM Statistics (struct pim6stat, netinet6/pim_var.h)");
 
 static VNET_DEFINE(int, pim6);
@@ -269,9 +283,9 @@
  * Find a route for a given origin IPv6 address and Multicast group address.
  */
 #define MF6CFIND(o, g, rt) do { \
-	struct mf6c *_rt = mf6ctable[MF6CHASH(o,g)]; \
+	struct mf6c *_rt = V_mf6ctable[MF6CHASH(o,g)]; \
 	rt = NULL; \
-	mrt6stat.mrt6s_mfc_lookups++; \
+	V_mrt6stat.mrt6s_mfc_lookups++; \
 	while (_rt) { \
 		if (IN6_ARE_ADDR_EQUAL(&_rt->mf6c_origin.sin6_addr, &(o)) && \
 		    IN6_ARE_ADDR_EQUAL(&_rt->mf6c_mcastgrp.sin6_addr, &(g)) && \
@@ -282,7 +296,7 @@
 		_rt = _rt->mf6c_next; \
 	} \
 	if (rt == NULL) { \
-		mrt6stat.mrt6s_mfc_misses++; \
+		V_mrt6stat.mrt6s_mfc_misses++; \
 	} \
 } while (/*CONSTCOND*/ 0)
 
@@ -316,7 +330,7 @@
 #ifdef UPCALL_TIMING
 #define UPCALL_MAX	50
 static u_long upcall_data[UPCALL_MAX + 1];
-static void collate();
+static void collate(struct timeval *t);
 #endif /* UPCALL_TIMING */
 
 static int ip6_mrouter_init(struct socket *, int, int);
@@ -490,13 +504,13 @@
 
 	MIF6_LOCK();
 
-	if (mifi >= nummifs) {
+	if (mifi >= V_nummifs) {
 		ret = EINVAL;
 	} else {
-		req->icount = mif6table[mifi].m6_pkt_in;
-		req->ocount = mif6table[mifi].m6_pkt_out;
-		req->ibytes = mif6table[mifi].m6_bytes_in;
-		req->obytes = mif6table[mifi].m6_bytes_out;
+		req->icount = V_mif6table[mifi].m6_pkt_in;
+		req->ocount = V_mif6table[mifi].m6_pkt_out;
+		req->ibytes = V_mif6table[mifi].m6_bytes_in;
+		req->obytes = V_mif6table[mifi].m6_bytes_out;
 	}
 
 	MIF6_UNLOCK();
@@ -546,8 +560,8 @@
 	V_ip6_mrouter = so;
 	V_ip6_mrouter_ver = cmd;
 
-	bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
-	bzero((caddr_t)n6expire, sizeof(n6expire));
+	bzero((caddr_t)V_mf6ctable, sizeof(V_mf6ctable));
+	bzero((caddr_t)V_n6expire, sizeof(V_n6expire));
 
 	V_pim6 = 0;/* used for stubbing out/in pim stuff */
 
@@ -587,14 +601,14 @@
 	 * For each phyint in use, disable promiscuous reception of all IPv6
 	 * multicasts.
 	 */
-	for (mifi = 0; mifi < nummifs; mifi++) {
-		if (mif6table[mifi].m6_ifp &&
-		    !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
-			if_allmulti(mif6table[mifi].m6_ifp, 0);
+	for (mifi = 0; mifi < V_nummifs; mifi++) {
+		if (V_mif6table[mifi].m6_ifp &&
+		    !(V_mif6table[mifi].m6_flags & MIFF_REGISTER)) {
+			if_allmulti(V_mif6table[mifi].m6_ifp, 0);
 		}
 	}
-	bzero((caddr_t)mif6table, sizeof(mif6table));
-	nummifs = 0;
+	bzero((caddr_t)V_mif6table, sizeof(V_mif6table));
+	V_nummifs = 0;
 
 	V_pim6 = 0; /* used to stub out/in pim specific code */
 
@@ -605,7 +619,7 @@
 	 */
 	MFC6_LOCK();
 	for (i = 0; i < MF6CTBLSIZ; i++) {
-		rt = mf6ctable[i];
+		rt = V_mf6ctable[i];
 		while (rt) {
 			struct mf6c *frt;
 
@@ -621,16 +635,16 @@
 			free(frt, M_MRTABLE6);
 		}
 	}
-	bzero((caddr_t)mf6ctable, sizeof(mf6ctable));
+	bzero((caddr_t)V_mf6ctable, sizeof(V_mf6ctable));
 	MFC6_UNLOCK();
 
 	/*
 	 * Reset register interface
 	 */
-	if (reg_mif_num != (mifi_t)-1 && multicast_register_if6 != NULL) {
+	if (V_reg_mif_num != (mifi_t)-1 && multicast_register_if6 != NULL) {
 		if_detach(multicast_register_if6);
 		if_free(multicast_register_if6);
-		reg_mif_num = (mifi_t)-1;
+		V_reg_mif_num = (mifi_t)-1;
 		multicast_register_if6 = NULL;
 	}
 
@@ -647,7 +661,8 @@
 	return (0);
 }
 
-static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
+static VNET_DEFINE(struct sockaddr_in6, sin6) = { sizeof(VNET(sin6)), AF_INET6 };
+#define V_sin6		VNET(sin6)
 
 /*
  * Add a mif to the mif table
@@ -665,7 +680,7 @@
 		MIF6_UNLOCK();
 		return (EINVAL);
 	}
-	mifp = mif6table + mifcp->mif6c_mifi;
+	mifp = V_mif6table + mifcp->mif6c_mifi;
 	if (mifp->m6_ifp != NULL) {
 		MIF6_UNLOCK();
 		return (EADDRINUSE); /* XXX: is it appropriate? */
@@ -678,14 +693,14 @@
 	ifp = ifnet_byindex(mifcp->mif6c_pifi);
 
 	if (mifcp->mif6c_flags & MIFF_REGISTER) {
-		if (reg_mif_num == (mifi_t)-1) {
+		if (V_reg_mif_num == (mifi_t)-1) {
 			ifp = if_alloc(IFT_OTHER);
 
 			if_initname(ifp, "register_mif", 0);
 			ifp->if_flags |= IFF_LOOPBACK;
 			if_attach(ifp);
 			multicast_register_if6 = ifp;
-			reg_mif_num = mifcp->mif6c_mifi;
+			V_reg_mif_num = mifcp->mif6c_mifi;
 			/*
 			 * it is impossible to guess the ifindex of the
 			 * register interface.  So mif6c_pifi is automatically
@@ -720,8 +735,8 @@
 	bzero(&mifp->m6_route, sizeof(mifp->m6_route));
 
 	/* Adjust nummifs up if the mifi is higher than nummifs */
-	if (nummifs <= mifcp->mif6c_mifi)
-		nummifs = mifcp->mif6c_mifi + 1;
+	if (V_nummifs <= mifcp->mif6c_mifi)
+		V_nummifs = mifcp->mif6c_mifi + 1;
 
 	MIF6_UNLOCK();
 
@@ -742,13 +757,13 @@
 static int
 del_m6if_locked(mifi_t *mifip)
 {
-	struct mif6 *mifp = mif6table + *mifip;
+	struct mif6 *mifp = V_mif6table + *mifip;
 	mifi_t mifi;
 	struct ifnet *ifp;
 
 	MIF6_LOCK_ASSERT();
 
-	if (*mifip >= nummifs)
+	if (*mifip >= V_nummifs)
 		return (EINVAL);
 	if (mifp->m6_ifp == NULL)
 		return (EINVAL);
@@ -758,11 +773,11 @@
 		ifp = mifp->m6_ifp;
 		if_allmulti(ifp, 0);
 	} else {
-		if (reg_mif_num != (mifi_t)-1 &&
+		if (V_reg_mif_num != (mifi_t)-1 &&
 		    multicast_register_if6 != NULL) {
 			if_detach(multicast_register_if6);
 			if_free(multicast_register_if6);
-			reg_mif_num = (mifi_t)-1;
+			V_reg_mif_num = (mifi_t)-1;
 			multicast_register_if6 = NULL;
 		}
 	}
@@ -770,14 +785,14 @@
 	bzero((caddr_t)mifp, sizeof(*mifp));
 
 	/* Adjust nummifs down */
-	for (mifi = nummifs; mifi > 0; mifi--)
-		if (mif6table[mifi - 1].m6_ifp)
+	for (mifi = V_nummifs; mifi > 0; mifi--)
+		if (V_mif6table[mifi - 1].m6_ifp)
 			break;
-	nummifs = mifi;
+	V_nummifs = mifi;
 
 #ifdef MRT6DEBUG
 	if (V_mrt6debug)
-		log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, nummifs);
+		log(LOG_DEBUG, "del_m6if %d, nummifs %d\n", *mifip, V_nummifs);
 #endif
 
 	return (0);
@@ -817,7 +832,8 @@
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & DEBUG_MFC) {
 		    log(LOG_DEBUG,
-			"add_m6fc no upcall h %d o %s g %s p %x\n",
+			"add_m6fc no upcall h %d o %s g %s p %p\n",
+			hash,
 			ip6_sprintf(ip6bufo, &mfccp->mf6cc_origin.sin6_addr),
 			ip6_sprintf(ip6bufg, &mfccp->mf6cc_mcastgrp.sin6_addr),
 			mfccp->mf6cc_parent);
@@ -836,7 +852,7 @@
 	 */
 	hash = MF6CHASH(mfccp->mf6cc_origin.sin6_addr,
 			mfccp->mf6cc_mcastgrp.sin6_addr);
-	for (rt = mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
+	for (rt = V_mf6ctable[hash], nstl = 0; rt; rt = rt->mf6c_next) {
 		if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
 				       &mfccp->mf6cc_origin.sin6_addr) &&
 		    IN6_ARE_ADDR_EQUAL(&rt->mf6c_mcastgrp.sin6_addr,
@@ -874,7 +890,7 @@
 			rt->mf6c_wrong_if   = 0;
 
 			rt->mf6c_expire = 0;	/* Don't clean this guy up */
-			n6expire[hash]--;
+			V_n6expire[hash]--;
 
 			/* free packets Qed at the end of this entry */
 			for (rte = rt->mf6c_stall; rte != NULL; ) {
@@ -905,7 +921,7 @@
 			mfccp->mf6cc_parent);
 #endif
 
-		for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
+		for (rt = V_mf6ctable[hash]; rt; rt = rt->mf6c_next) {
 
 			if (IN6_ARE_ADDR_EQUAL(&rt->mf6c_origin.sin6_addr,
 					       &mfccp->mf6cc_origin.sin6_addr)&&
@@ -922,7 +938,7 @@
 				rt->mf6c_wrong_if   = 0;
 
 				if (rt->mf6c_expire)
-					n6expire[hash]--;
+					V_n6expire[hash]--;
 				rt->mf6c_expire	   = 0;
 			}
 		}
@@ -948,8 +964,8 @@
 			rt->mf6c_stall = NULL;
 
 			/* link into table */
-			rt->mf6c_next  = mf6ctable[hash];
-			mf6ctable[hash] = rt;
+			rt->mf6c_next  = V_mf6ctable[hash];
+			V_mf6ctable[hash] = rt;
 		}
 	}
 
@@ -1010,7 +1026,7 @@
 
 	MFC6_LOCK();
 
-	nptr = &mf6ctable[hash];
+	nptr = &V_mf6ctable[hash];
 	while ((rt = *nptr) != NULL) {
 		if (IN6_ARE_ADDR_EQUAL(&origin.sin6_addr,
 				       &rt->mf6c_origin.sin6_addr) &&
@@ -1144,7 +1160,7 @@
 		GET_TIME(tp);
 #endif /* UPCALL_TIMING */
 
-		mrt6stat.mrt6s_no_route++;
+		V_mrt6stat.mrt6s_no_route++;
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & (DEBUG_FORWARD | DEBUG_MFC))
 			log(LOG_DEBUG, "ip6_mforward: no rte s %s g %s\n",
@@ -1178,7 +1194,7 @@
 
 		/* is there an upcall waiting for this packet? */
 		hash = MF6CHASH(ip6->ip6_src, ip6->ip6_dst);
-		for (rt = mf6ctable[hash]; rt; rt = rt->mf6c_next) {
+		for (rt = V_mf6ctable[hash]; rt; rt = rt->mf6c_next) {
 			if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src,
 					       &rt->mf6c_origin.sin6_addr) &&
 			    IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
@@ -1219,7 +1235,7 @@
 			/*
 			 * Send message to routing daemon
 			 */
-			sin6.sin6_addr = ip6->ip6_src;
+			V_sin6.sin6_addr = ip6->ip6_src;
 
 			im = NULL;
 #ifdef MRT6_OINIT
@@ -1252,8 +1268,8 @@
 				    "getting the iif info in the kernel\n");
 #endif
 
-			for (mifp = mif6table, mifi = 0;
-			     mifi < nummifs && mifp->m6_ifp != ifp;
+			for (mifp = V_mif6table, mifi = 0;
+			     mifi < V_nummifs && mifp->m6_ifp != ifp;
 			     mifp++, mifi++)
 				;
 
@@ -1268,10 +1284,10 @@
 				break;
 			}
 
-			if (socket_send(V_ip6_mrouter, mm, &sin6) < 0) {
+			if (socket_send(V_ip6_mrouter, mm, &V_sin6) < 0) {
 				log(LOG_WARNING, "ip6_mforward: ip6_mrouter "
 				    "socket queue full\n");
-				mrt6stat.mrt6s_upq_sockfull++;
+				V_mrt6stat.mrt6s_upq_sockfull++;
 				free(rte, M_MRTABLE6);
 				m_freem(mb0);
 				free(rt, M_MRTABLE6);
@@ -1279,7 +1295,7 @@
 				return (ENOBUFS);
 			}
 
-			mrt6stat.mrt6s_upcalls++;
+			V_mrt6stat.mrt6s_upcalls++;
 
 			/* insert new entry at head of hash chain */
 			bzero(rt, sizeof(*rt));
@@ -1290,12 +1306,12 @@
 			rt->mf6c_mcastgrp.sin6_len = sizeof(struct sockaddr_in6);
 			rt->mf6c_mcastgrp.sin6_addr = ip6->ip6_dst;
 			rt->mf6c_expire = UPCALL_EXPIRE;
-			n6expire[hash]++;
+			V_n6expire[hash]++;
 			rt->mf6c_parent = MF6C_INCOMPLETE_PARENT;
 
 			/* link into table */
-			rt->mf6c_next  = mf6ctable[hash];
-			mf6ctable[hash] = rt;
+			rt->mf6c_next  = V_mf6ctable[hash];
+			V_mf6ctable[hash] = rt;
 			/* Add this entry to the end of the queue */
 			rt->mf6c_stall = rte;
 		} else {
@@ -1305,7 +1321,7 @@
 
 			for (p = &rt->mf6c_stall; *p != NULL; p = &(*p)->next)
 				if (++npkts > MAX_UPQ6) {
-					mrt6stat.mrt6s_upq_ovflw++;
+					V_mrt6stat.mrt6s_upq_ovflw++;
 					free(rte, M_MRTABLE6);
 					m_freem(mb0);
 					MFC6_UNLOCK();
@@ -1342,9 +1358,9 @@
 
 	MFC6_LOCK();
 	for (i = 0; i < MF6CTBLSIZ; i++) {
-		if (n6expire[i] == 0)
+		if (V_n6expire[i] == 0)
 			continue;
-		nptr = &mf6ctable[i];
+		nptr = &V_mf6ctable[i];
 		while ((mfc = *nptr) != NULL) {
 			rte = mfc->mf6c_stall;
 			/*
@@ -1374,8 +1390,8 @@
 					free(rte, M_MRTABLE6);
 					rte = n;
 				} while (rte != NULL);
-				mrt6stat.mrt6s_cache_cleanups++;
-				n6expire[i]--;
+				V_mrt6stat.mrt6s_cache_cleanups++;
+				V_n6expire[i]--;
 
 				*nptr = mfc->mf6c_next;
 				free(mfc, M_MRTABLE6);
@@ -1421,16 +1437,16 @@
 	 * for its origin.
 	 */
 	mifi = rt->mf6c_parent;
-	if ((mifi >= nummifs) || (mif6table[mifi].m6_ifp != ifp)) {
+	if ((mifi >= V_nummifs) || (V_mif6table[mifi].m6_ifp != ifp)) {
 		/* came in the wrong interface */
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & DEBUG_FORWARD)
 			log(LOG_DEBUG,
 			    "wrong if: ifid %d mifi %d mififid %x\n",
 			    ifp->if_index, mifi,
-			    mif6table[mifi].m6_ifp->if_index);
+			    V_mif6table[mifi].m6_ifp->if_index);
 #endif
-		mrt6stat.mrt6s_wrong_if++;
+		V_mrt6stat.mrt6s_wrong_if++;
 		rt->mf6c_wrong_if++;
 		/*
 		 * If we are doing PIM processing, and we are forwarding
@@ -1438,15 +1454,13 @@
 		 * routing daemon.
 		 */
 		/* have to make sure this is a valid mif */
-		if (mifi < nummifs && mif6table[mifi].m6_ifp)
+		if (mifi < V_nummifs && V_mif6table[mifi].m6_ifp)
 			if (V_pim6 && (m->m_flags & M_LOOP) == 0) {
 				/*
 				 * Check the M_LOOP flag to avoid an
 				 * unnecessary PIM assert.
 				 * XXX: M_LOOP is an ad-hoc hack...
 				 */
-				static struct sockaddr_in6 sin6 =
-				{ sizeof(sin6), AF_INET6 };
 
 				struct mbuf *mm;
 				struct mrt6msg *im;
@@ -1484,8 +1498,8 @@
 					return (EINVAL);
 				}
 
-				for (mifp = mif6table, iif = 0;
-				     iif < nummifs && mifp &&
+				for (mifp = V_mif6table, iif = 0;
+				     iif < V_nummifs && mifp &&
 					     mifp->m6_ifp != ifp;
 				     mifp++, iif++)
 					;
@@ -1494,23 +1508,23 @@
 #ifdef MRT6_OINIT
 				case MRT6_OINIT:
 					oim->im6_mif = iif;
-					sin6.sin6_addr = oim->im6_src;
+					V_sin6.sin6_addr = oim->im6_src;
 					break;
 #endif
 				case MRT6_INIT:
 					im->im6_mif = iif;
-					sin6.sin6_addr = im->im6_src;
+					V_sin6.sin6_addr = im->im6_src;
 					break;
 				}
 
-				mrt6stat.mrt6s_upcalls++;
+				V_mrt6stat.mrt6s_upcalls++;
 
-				if (socket_send(V_ip6_mrouter, mm, &sin6) < 0) {
+				if (socket_send(V_ip6_mrouter, mm, &V_sin6) < 0) {
 #ifdef MRT6DEBUG
 					if (V_mrt6debug)
 						log(LOG_WARNING, "mdq, ip6_mrouter socket queue full\n");
 #endif
-					++mrt6stat.mrt6s_upq_sockfull;
+					++V_mrt6stat.mrt6s_upq_sockfull;
 					return (ENOBUFS);
 				}	/* if socket Q full */
 			}		/* if PIM */
@@ -1520,11 +1534,11 @@
 	/* If I sourced this packet, it counts as output, else it was input. */
 	if (m->m_pkthdr.rcvif == NULL) {
 		/* XXX: is rcvif really NULL when output?? */
-		mif6table[mifi].m6_pkt_out++;
-		mif6table[mifi].m6_bytes_out += plen;
+		V_mif6table[mifi].m6_pkt_out++;
+		V_mif6table[mifi].m6_bytes_out += plen;
 	} else {
-		mif6table[mifi].m6_pkt_in++;
-		mif6table[mifi].m6_bytes_in += plen;
+		V_mif6table[mifi].m6_pkt_in++;
+		V_mif6table[mifi].m6_bytes_in += plen;
 	}
 	rt->mf6c_pkt_cnt++;
 	rt->mf6c_byte_cnt += plen;
@@ -1540,7 +1554,7 @@
 		V_ip6stat.ip6s_badscope++;
 		return (error);
 	}
-	for (mifp = mif6table, mifi = 0; mifi < nummifs; mifp++, mifi++) {
+	for (mifp = V_mif6table, mifi = 0; mifi < V_nummifs; mifp++, mifi++) {
 		if (IF_ISSET(mifi, &rt->mf6c_ifset)) {
 			/*
 			 * check if the outgoing packet is going to break
@@ -1548,12 +1562,12 @@
 			 * XXX For packets through PIM register tunnel
 			 * interface, we believe a routing daemon.
 			 */
-			if (!(mif6table[rt->mf6c_parent].m6_flags &
+			if (!(V_mif6table[rt->mf6c_parent].m6_flags &
 			      MIFF_REGISTER) &&
-			    !(mif6table[mifi].m6_flags & MIFF_REGISTER)) {
-				if (in6_setscope(&src0, mif6table[mifi].m6_ifp,
+			    !(V_mif6table[mifi].m6_flags & MIFF_REGISTER)) {
+				if (in6_setscope(&src0, V_mif6table[mifi].m6_ifp,
 				    &oszone) ||
-				    in6_setscope(&dst0, mif6table[mifi].m6_ifp,
+				    in6_setscope(&dst0, V_mif6table[mifi].m6_ifp,
 				    &odzone) ||
 				    iszone != oszone ||
 				    idzone != odzone) {
@@ -1616,7 +1630,7 @@
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & DEBUG_XMIT)
 			log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
-			    mifp - mif6table, error);
+			    mifp - V_mif6table, error);
 #endif
 		return;
 	}
@@ -1650,7 +1664,7 @@
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & DEBUG_XMIT)
 			log(LOG_DEBUG, "phyint_send on mif %d err %d\n",
-			    mifp - mif6table, error);
+			    mifp - V_mif6table, error);
 #endif
 	} else {
 		/*
@@ -1678,13 +1692,12 @@
 		}
 	}
 }
-
+	
 static int
 register_send(struct ip6_hdr *ip6, struct mif6 *mif, struct mbuf *m)
 {
 	struct mbuf *mm;
 	int i, len = m->m_pkthdr.len;
-	static struct sockaddr_in6 sin6 = { sizeof(sin6), AF_INET6 };
 	struct mrt6msg *im6;
 
 #ifdef MRT6DEBUG
@@ -1695,7 +1708,7 @@
 		    ip6_sprintf(ip6bufd, &ip6->ip6_dst));
 	}
 #endif
-	++pim6stat.pim6s_snd_registers;
+	++V_pim6stat.pim6s_snd_registers;
 
 	/* Make a copy of the packet to send to the user level process */
 	MGETHDR(mm, M_DONTWAIT, MT_HEADER);
@@ -1721,24 +1734,24 @@
 	/*
 	 * Send message to routing daemon
 	 */
-	sin6.sin6_addr = ip6->ip6_src;
+	V_sin6.sin6_addr = ip6->ip6_src;
 
 	im6 = mtod(mm, struct mrt6msg *);
 	im6->im6_msgtype      = MRT6MSG_WHOLEPKT;
 	im6->im6_mbz          = 0;
 
-	im6->im6_mif = mif - mif6table;
+	im6->im6_mif = mif - V_mif6table;
 
 	/* iif info is not given for reg. encap.n */
-	mrt6stat.mrt6s_upcalls++;
+	V_mrt6stat.mrt6s_upcalls++;
 
-	if (socket_send(V_ip6_mrouter, mm, &sin6) < 0) {
+	if (socket_send(V_ip6_mrouter, mm, &V_sin6) < 0) {
 #ifdef MRT6DEBUG
 		if (V_mrt6debug)
 			log(LOG_WARNING,
 			    "register_send: ip6_mrouter socket queue full\n");
 #endif
-		++mrt6stat.mrt6s_upq_sockfull;
+		++V_mrt6stat.mrt6s_upq_sockfull;
 		return (ENOBUFS);
 	}
 	return (0);
@@ -1779,7 +1792,7 @@
 	int minlen;
 	int off = *offp;
 
-	++pim6stat.pim6s_rcv_total;
+	++V_pim6stat.pim6s_rcv_total;
 
 	ip6 = mtod(m, struct ip6_hdr *);
 	pimlen = m->m_pkthdr.len - *offp;
@@ -1788,7 +1801,7 @@
 	 * Validate lengths
 	 */
 	if (pimlen < PIM_MINLEN) {
-		++pim6stat.pim6s_rcv_tooshort;
+		++V_pim6stat.pim6s_rcv_tooshort;
 #ifdef MRT6DEBUG
 		if (V_mrt6debug & DEBUG_PIM)
 			log(LOG_DEBUG,"pim6_input: PIM packet too short\n");
@@ -1821,7 +1834,7 @@
 #else
 	IP6_EXTHDR_GET(pim, struct pim *, m, off, minlen);
 	if (pim == NULL) {
-		pim6stat.pim6s_rcv_tooshort++;
+		V_pim6stat.pim6s_rcv_tooshort++;
 		return (IPPROTO_DONE);
 	}
 #endif
@@ -1841,7 +1854,7 @@
 			cksumlen = pimlen;
 
 		if (in6_cksum(m, IPPROTO_PIM, off, cksumlen)) {
-			++pim6stat.pim6s_rcv_badsum;
+			++V_pim6stat.pim6s_rcv_badsum;
 #ifdef MRT6DEBUG
 			if (V_mrt6debug & DEBUG_PIM)
 				log(LOG_DEBUG,
@@ -1855,7 +1868,7 @@
 
 	/* PIM version check */
 	if (pim->pim_ver != PIM_VERSION) {
-		++pim6stat.pim6s_rcv_badversion;
+		++V_pim6stat.pim6s_rcv_badversion;
 #ifdef MRT6DEBUG
 		log(LOG_ERR,
 		    "pim6_input: incorrect version %d, expecting %d\n",
@@ -1881,14 +1894,14 @@
 		char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN];
 #endif
 
-		++pim6stat.pim6s_rcv_registers;
+		++V_pim6stat.pim6s_rcv_registers;
 
-		if ((reg_mif_num >= nummifs) || (reg_mif_num == (mifi_t) -1)) {
+		if ((V_reg_mif_num >= V_nummifs) || (V_reg_mif_num == (mifi_t) -1)) {
 #ifdef MRT6DEBUG
 			if (V_mrt6debug & DEBUG_PIM)
 				log(LOG_DEBUG,
 				    "pim6_input: register mif not set: %d\n",
-				    reg_mif_num);
+				    V_reg_mif_num);
 #endif
 			m_freem(m);
 			return (IPPROTO_DONE);
@@ -1903,8 +1916,8 @@
 		 * Validate length
 		 */
 		if (pimlen < PIM6_REG_MINLEN) {
-			++pim6stat.pim6s_rcv_tooshort;
-			++pim6stat.pim6s_rcv_badregisters;
+			++V_pim6stat.pim6s_rcv_tooshort;
+			++V_pim6stat.pim6s_rcv_badregisters;
 #ifdef MRT6DEBUG
 			log(LOG_ERR,
 			    "pim6_input: register packet size too "
@@ -1928,7 +1941,7 @@
 
 		/* verify the version number of the inner packet */
 		if ((eip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
-			++pim6stat.pim6s_rcv_badregisters;
+			++V_pim6stat.pim6s_rcv_badregisters;
 #ifdef MRT6DEBUG
 			log(LOG_DEBUG, "pim6_input: invalid IP version (%d) "
 			    "of the inner packet\n",
@@ -1940,7 +1953,7 @@
 
 		/* verify the inner packet is destined to a mcast group */
 		if (!IN6_IS_ADDR_MULTICAST(&eip6->ip6_dst)) {
-			++pim6stat.pim6s_rcv_badregisters;
+			++V_pim6stat.pim6s_rcv_badregisters;
 #ifdef MRT6DEBUG
 			if (V_mrt6debug & DEBUG_PIM)
 				log(LOG_DEBUG,
@@ -1977,11 +1990,11 @@
 			    "src %s, dst %s, mif %d\n",
 			    ip6_sprintf(ip6bufs, &eip6->ip6_src),
 			    ip6_sprintf(ip6bufd, &eip6->ip6_dst),
-			    reg_mif_num);
+			    V_reg_mif_num);
 		}
 #endif
 
-		rc = if_simloop(mif6table[reg_mif_num].m6_ifp, m,
+		rc = if_simloop(V_mif6table[V_reg_mif_num].m6_ifp, m,
 				dst.sin6_family, 0);
 
 		/* prepare the register head to send to the mrouting daemon */
@@ -1999,6 +2012,25 @@
 	return (IPPROTO_DONE);
 }
 
+static void
+vnet_mroute6_init(const void *unused __unused)
+{
+
+}
+
+VNET_SYSINIT(vnet_mroute6_init, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, vnet_mroute6_init,
+        NULL);
+                
+static void
+vnet_mroute6_uninit(const void *unused __unused)
+{
+
+        X_ip6_mrouter_done();
+}
+
+VNET_SYSUNINIT(vnet_mroute6_uninit, SI_SUB_PSEUDO, SI_ORDER_MIDDLE,
+        vnet_mroute6_uninit, NULL);
+
 static int
 ip6_mroute_modevent(module_t mod, int type, void *unused)
 {
@@ -2035,7 +2067,7 @@
 			encap_detach(pim6_encap_cookie);
 			pim6_encap_cookie = NULL;
 		}
-		X_ip6_mrouter_done();
+		// moving to uninit()  X_ip6_mrouter_done();
 		ip6_mforward = NULL;
 		ip6_mrouter_done = NULL;
 		ip6_mrouter_get = NULL;



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