PERFORCE change 177812 for review

Ivor Prebeg iprebeg at FreeBSD.org
Thu May 6 10:57:03 UTC 2010


http://p4web.freebsd.org/@@177812?ac=10

Change 177812 by iprebeg at iprebeg_nxlab_login on 2010/05/06 10:56:11

	V_mcast 2 vimage branch (no compile failz)

Affected files ...

.. //depot/projects/vimage/src/sys/net/vnet.c#10 edit
.. //depot/projects/vimage/src/sys/net/vnet.h#37 edit
.. //depot/projects/vimage/src/sys/netinet/ip_mroute.c#30 edit
.. //depot/projects/vimage/src/sys/netinet/ip_mroute.h#8 edit
.. //depot/projects/vimage/src/sys/netinet/pim_var.h#3 edit

Differences ...

==== //depot/projects/vimage/src/sys/net/vnet.c#10 (text+ko) ====

@@ -169,7 +169,7 @@
  * we want the virtualized global variable space to be page-sized, we may
  * have more space than that in practice.
  */
-#define	VNET_MODMIN	8192
+#define	VNET_MODMIN	(8192<<2)
 #define	VNET_SIZE	roundup2(VNET_BYTES, PAGE_SIZE)
 #define	VNET_MODSIZE	(VNET_SIZE - (VNET_BYTES - VNET_MODMIN))
 

==== //depot/projects/vimage/src/sys/net/vnet.h#37 (text+ko) ====

@@ -254,6 +254,11 @@
 	    CTLTYPE_OPAQUE|CTLFLAG_VNET|(access), ptr,			\
 	    sizeof(struct type), vnet_sysctl_handle_opaque, "S," #type,	\
 	    descr)
+#define SYSCTL_VNET_OPAQUE(parent, nbr, name, access, ptr, len, fmt,    \
+	    descr) 							\
+	SYSCTL_OID(parent, nbr, name,					\
+	    CTLTYPE_OPAQUE|CTLFLAG_VNET|(access), ptr, len, 		\
+	    sysctl_handle_opaque, fmt, descr)
 #define	SYSCTL_VNET_UINT(parent, nbr, name, access, ptr, val, descr)	\
 	SYSCTL_OID(parent, nbr, name,					\
 	    CTLTYPE_UINT|CTLFLAG_MPSAFE|CTLFLAG_VNET|(access),		\

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

@@ -121,6 +121,9 @@
 #define		VIFI_INVALID	((vifi_t) -1)
 #define		M_HASCL(m)	((m)->m_flags & M_EXT)
 
+static VNET_DEFINE(uint32_t, last_tv_sec); /* last time we processed this */
+#define V_last_tv_sec     VNET(last_tv_sec)
+
 static MALLOC_DEFINE(M_MRTABLE, "mroutetbl", "multicast forwarding cache");
 
 /*
@@ -139,21 +142,25 @@
 	mtx_init(&mrouter_mtx, "IPv4 multicast forwarding", NULL, MTX_DEF)
 #define	MROUTER_LOCK_DESTROY()	mtx_destroy(&mrouter_mtx)
 
-static struct mrtstat	mrtstat;
-SYSCTL_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW,
-    &mrtstat, mrtstat,
+static VNET_DEFINE(struct mrtstat, mrtstat);
+#define V_mrtstat         VNET(mrtstat)
+SYSCTL_VNET_STRUCT(_net_inet_ip, OID_AUTO, mrtstat, CTLFLAG_RW,
+    &VNET_NAME(mrtstat), mrtstat,
     "IPv4 Multicast Forwarding Statistics (struct mrtstat, "
     "netinet/ip_mroute.h)");
 
-static u_long			 mfchash;
+static VNET_DEFINE(u_long, mfchash);
+#define V_mfchash         VNET(mfchash)
 #define MFCHASH(a, g)							\
 	((((a).s_addr >> 20) ^ ((a).s_addr >> 10) ^ (a).s_addr ^ \
-	  ((g).s_addr >> 20) ^ ((g).s_addr >> 10) ^ (g).s_addr) & mfchash)
+	  ((g).s_addr >> 20) ^ ((g).s_addr >> 10) ^ (g).s_addr) & V_mfchash)
 #define MFCHASHSIZE	256
 
-static u_char			*nexpire;	/* 0..mfchashsize-1 */
-static u_long			 mfchashsize;	/* Hash size */
-LIST_HEAD(mfchashhdr, mfc)	*mfchashtbl;
+static VNET_DEFINE(u_char*, nexpire);
+#define V_nexpire         VNET(nexpire)
+static u_long mfchashsize;	/* Hash size */
+static VNET_DEFINE(LIST_HEAD(mfchashhdr, mfc)*, mfchashtbl);
+#define V_mfchashtbl      VNET(mfchashtbl)
 
 static struct mtx mfc_mtx;
 #define	MFC_LOCK()		mtx_lock(&mfc_mtx)
@@ -163,10 +170,12 @@
 	mtx_init(&mfc_mtx, "IPv4 multicast forwarding cache", NULL, MTX_DEF)
 #define	MFC_LOCK_DESTROY()	mtx_destroy(&mfc_mtx)
 
-static vifi_t		numvifs;
-static struct vif	viftable[MAXVIFS];
-SYSCTL_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD,
-    &viftable, sizeof(viftable), "S,vif[MAXVIFS]",
+static VNET_DEFINE(vifi_t, numvifs);
+#define V_numvifs         VNET(numvifs)
+static VNET_DEFINE(struct vif, viftable[MAXVIFS]);
+#define V_viftable        VNET(viftable)
+SYSCTL_VNET_OPAQUE(_net_inet_ip, OID_AUTO, viftable, CTLFLAG_RD,
+    &VNET_NAME(viftable), sizeof(V_viftable), "S,vif[MAXVIFS]",
     "IPv4 Multicast Interfaces (struct vif[MAXVIFS], netinet/ip_mroute.h)");
 
 static struct mtx vif_mtx;
@@ -192,7 +201,8 @@
  * expiration time. Periodically, the entries are analysed and processed.
  */
 #define BW_METER_BUCKETS	1024
-static struct bw_meter *bw_meter_timers[BW_METER_BUCKETS];
+static VNET_DEFINE(struct bw_meter*, bw_meter_timers[BW_METER_BUCKETS]);
+#define V_bw_meter_timers VNET(bw_meter_timers)
 static struct callout bw_meter_ch;
 #define BW_METER_PERIOD (hz)		/* periodical handling of bw meters */
 
@@ -200,16 +210,19 @@
  * Pending upcalls are stored in a vector which is flushed when
  * full, or periodically
  */
-static struct bw_upcall	bw_upcalls[BW_UPCALLS_MAX];
-static u_int	bw_upcalls_n; /* # of pending upcalls */
+static VNET_DEFINE(struct bw_upcall, bw_upcalls[BW_UPCALLS_MAX]);
+#define V_bw_upcalls      VNET(bw_upcalls)
+static VNET_DEFINE(u_int, bw_upcalls_n); /* # of pending upcalls */
+#define V_bw_upcalls_n    VNET(bw_upcalls_n)
 static struct callout bw_upcalls_ch;
 #define BW_UPCALLS_PERIOD (hz)		/* periodical flush of bw upcalls */
 
-static struct pimstat pimstat;
+static VNET_DEFINE(struct pimstat, pimstat);
+#define V_pimstat         VNET(pimstat)
 
 SYSCTL_NODE(_net_inet, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
-SYSCTL_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD,
-    &pimstat, pimstat,
+SYSCTL_VNET_STRUCT(_net_inet_pim, PIMCTL_STATS, stats, CTLFLAG_RD,
+    &VNET_NAME(pimstat), pimstat,
     "PIM Statistics (struct pimstat, netinet/pim_var.h)");
 
 static u_long	pim_squelch_wholepkt = 0;
@@ -275,8 +288,10 @@
     0				/* flags */
 };
 
-static struct ifnet multicast_register_if;
-static vifi_t reg_vif_num = VIFI_INVALID;
+static VNET_DEFINE(vifi_t, reg_vif_num) = VIFI_INVALID;
+#define V_reg_vif_num     VNET(reg_vif_num)
+static VNET_DEFINE(struct ifnet, multicast_register_if);
+#define V_multicast_register_if	VNET(multicast_register_if)
 
 /*
  * Private variables.
@@ -360,7 +375,7 @@
 
 	MFC_LOCK_ASSERT();
 
-	LIST_FOREACH(rt, &mfchashtbl[MFCHASH(*o, *g)], mfc_hash) {
+	LIST_FOREACH(rt, &V_mfchashtbl[MFCHASH(*o, *g)], mfc_hash) {
 		if (in_hosteq(rt->mfc_origin, *o) &&
 		    in_hosteq(rt->mfc_mcastgrp, *g) &&
 		    TAILQ_EMPTY(&rt->mfc_stall))
@@ -566,15 +581,15 @@
     vifi_t vifi = req->vifi;
 
     VIF_LOCK();
-    if (vifi >= numvifs) {
+    if (vifi >= V_numvifs) {
 	VIF_UNLOCK();
 	return EINVAL;
     }
 
-    req->icount = viftable[vifi].v_pkt_in;
-    req->ocount = viftable[vifi].v_pkt_out;
-    req->ibytes = viftable[vifi].v_bytes_in;
-    req->obytes = viftable[vifi].v_bytes_out;
+    req->icount = V_viftable[vifi].v_pkt_in;
+    req->ocount = V_viftable[vifi].v_pkt_out;
+    req->ibytes = V_viftable[vifi].v_bytes_in;
+    req->obytes = V_viftable[vifi].v_bytes_out;
     VIF_UNLOCK();
 
     return 0;
@@ -589,8 +604,8 @@
 
     callout_init(&expire_upcalls_ch, CALLOUT_MPSAFE);
 
-    bw_upcalls_n = 0;
-    bzero((caddr_t)bw_meter_timers, sizeof(bw_meter_timers));
+    V_bw_upcalls_n = 0;
+    bzero((caddr_t)V_bw_meter_timers, sizeof(V_bw_meter_timers));
     callout_init(&bw_upcalls_ch, CALLOUT_MPSAFE);
     callout_init(&bw_meter_ch, CALLOUT_MPSAFE);
 }
@@ -619,12 +634,12 @@
      * 3. Expire any matching multicast forwarding cache entries.
      * 4. Free vif state. This should disable ALLMULTI on the interface.
      */
-    for (vifi = 0; vifi < numvifs; vifi++) {
-	if (viftable[vifi].v_ifp != ifp)
+    for (vifi = 0; vifi < V_numvifs; vifi++) {
+	if (V_viftable[vifi].v_ifp != ifp)
 		continue;
 	for (i = 0; i < mfchashsize; i++) {
 		struct mfc *rt, *nrt;
-		for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
+		for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) {
 			nrt = LIST_NEXT(rt, mfc_hash);
 			if (rt->mfc_parent == vifi) {
 				expire_mfc(rt);
@@ -670,13 +685,13 @@
 	return (ENOMEM);
     }
 
-    mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &mfchash, HASH_NOWAIT);
+    V_mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &V_mfchash, HASH_NOWAIT);
 
-    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
+    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, curvnet);
 
     callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
-	expire_bw_upcalls_send, NULL);
-    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL);
+	expire_bw_upcalls_send, curvnet);
+    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, curvnet);
 
     V_ip_mrouter = so;
 
@@ -717,20 +732,20 @@
      * For each phyint in use, disable promiscuous reception of all IP
      * multicasts.
      */
-    for (vifi = 0; vifi < numvifs; vifi++) {
-	if (!in_nullhost(viftable[vifi].v_lcl_addr) &&
-		!(viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) {
+    for (vifi = 0; vifi < V_numvifs; vifi++) {
+	if (!in_nullhost(V_viftable[vifi].v_lcl_addr) &&
+		!(V_viftable[vifi].v_flags & (VIFF_TUNNEL | VIFF_REGISTER))) {
 	    struct sockaddr_in *so = (struct sockaddr_in *)&(ifr.ifr_addr);
 
 	    so->sin_len = sizeof(struct sockaddr_in);
 	    so->sin_family = AF_INET;
 	    so->sin_addr.s_addr = INADDR_ANY;
-	    ifp = viftable[vifi].v_ifp;
+	    ifp = V_viftable[vifi].v_ifp;
 	    if_allmulti(ifp, 0);
 	}
     }
-    bzero((caddr_t)viftable, sizeof(viftable));
-    numvifs = 0;
+    bzero((caddr_t)V_viftable, sizeof(V_viftable));
+    V_numvifs = 0;
     pim_assert_enabled = 0;
 
     VIF_UNLOCK();
@@ -749,22 +764,22 @@
      */
     for (i = 0; i < mfchashsize; i++) {
 	struct mfc *rt, *nrt;
-	for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
+	for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) {
 		nrt = LIST_NEXT(rt, mfc_hash);
 		expire_mfc(rt);
 	}
     }
-    free(mfchashtbl, M_MRTABLE);
-    mfchashtbl = NULL;
+    free(V_mfchashtbl, M_MRTABLE);
+    V_mfchashtbl = NULL;
 
-    bzero(nexpire, sizeof(nexpire[0]) * mfchashsize);
+    bzero(V_nexpire, sizeof(V_nexpire[0]) * mfchashsize);
 
-    bw_upcalls_n = 0;
-    bzero(bw_meter_timers, sizeof(bw_meter_timers));
+    V_bw_upcalls_n = 0;
+    bzero(V_bw_meter_timers, sizeof(V_bw_meter_timers));
 
     MFC_UNLOCK();
 
-    reg_vif_num = VIFI_INVALID;
+    V_reg_vif_num = VIFI_INVALID;
 
     MROUTER_UNLOCK();
 
@@ -802,7 +817,7 @@
      *  - pim_assert is not enabled
      *  - the MFC table is empty
      */
-    if (numvifs > 0) {
+    if (V_numvifs > 0) {
 	*apival = 0;
 	return EPERM;
     }
@@ -814,7 +829,7 @@
     MFC_LOCK();
 
     for (i = 0; i < mfchashsize; i++) {
-	if (LIST_FIRST(&mfchashtbl[i]) != NULL) {
+	if (LIST_FIRST(&V_mfchashtbl[i]) != NULL) {
 	    *apival = 0;
 	    return EPERM;
 	}
@@ -834,7 +849,7 @@
 static int
 add_vif(struct vifctl *vifcp)
 {
-    struct vif *vifp = viftable + vifcp->vifc_vifi;
+    struct vif *vifp = V_viftable + vifcp->vifc_vifi;
     struct sockaddr_in sin = {sizeof sin, AF_INET};
     struct ifaddr *ifa;
     struct ifnet *ifp;
@@ -884,12 +899,12 @@
 	VIF_UNLOCK();
 	return EOPNOTSUPP;
     } else if (vifcp->vifc_flags & VIFF_REGISTER) {
-	ifp = &multicast_register_if;
+	ifp = &V_multicast_register_if;
 	CTR2(KTR_IPMF, "%s: add register vif for ifp %p", __func__, ifp);
-	if (reg_vif_num == VIFI_INVALID) {
-	    if_initname(&multicast_register_if, "register_vif", 0);
-	    multicast_register_if.if_flags = IFF_LOOPBACK;
-	    reg_vif_num = vifcp->vifc_vifi;
+	if (V_reg_vif_num == VIFI_INVALID) {
+	    if_initname(&V_multicast_register_if, "register_vif", 0);
+	    V_multicast_register_if.if_flags = IFF_LOOPBACK;
+	    V_reg_vif_num = vifcp->vifc_vifi;
 	}
     } else {		/* Make sure the interface supports multicast */
 	if ((ifp->if_flags & IFF_MULTICAST) == 0) {
@@ -918,8 +933,8 @@
     bzero(&vifp->v_route, sizeof(vifp->v_route));
 
     /* Adjust numvifs up if the vifi is higher than numvifs */
-    if (numvifs <= vifcp->vifc_vifi)
-	numvifs = vifcp->vifc_vifi + 1;
+    if (V_numvifs <= vifcp->vifc_vifi)
+	V_numvifs = vifcp->vifc_vifi + 1;
 
     VIF_UNLOCK();
 
@@ -940,10 +955,10 @@
 
     VIF_LOCK_ASSERT();
 
-    if (vifi >= numvifs) {
+    if (vifi >= V_numvifs) {
 	return EINVAL;
     }
-    vifp = &viftable[vifi];
+    vifp = &V_viftable[vifi];
     if (in_nullhost(vifp->v_lcl_addr)) {
 	return EADDRNOTAVAIL;
     }
@@ -952,17 +967,17 @@
 	if_allmulti(vifp->v_ifp, 0);
 
     if (vifp->v_flags & VIFF_REGISTER)
-	reg_vif_num = VIFI_INVALID;
+	V_reg_vif_num = VIFI_INVALID;
 
     bzero((caddr_t)vifp, sizeof (*vifp));
 
     CTR2(KTR_IPMF, "%s: delete vif %d", __func__, (int)vifi);
 
     /* Adjust numvifs down */
-    for (vifi = numvifs; vifi > 0; vifi--)
-	if (!in_nullhost(viftable[vifi-1].v_lcl_addr))
+    for (vifi = V_numvifs; vifi > 0; vifi--)
+	if (!in_nullhost(V_viftable[vifi-1].v_lcl_addr))
 	    break;
-    numvifs = vifi;
+    V_numvifs = vifi;
 
     return 0;
 }
@@ -988,7 +1003,7 @@
     int i;
 
     rt->mfc_parent = mfccp->mfcc_parent;
-    for (i = 0; i < numvifs; i++) {
+    for (i = 0; i < V_numvifs; i++) {
 	rt->mfc_ttls[i] = mfccp->mfcc_ttls[i];
 	rt->mfc_flags[i] = mfccp->mfcc_flags[i] & mrt_api_config &
 	    MRT_MFC_FLAGS_ALL;
@@ -1070,7 +1085,7 @@
      */
     nstl = 0;
     hash = MFCHASH(mfccp->mfcc_origin, mfccp->mfcc_mcastgrp);
-    LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) {
+    LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) {
 	if (in_hosteq(rt->mfc_origin, mfccp->mfcc_origin) &&
 	    in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp) &&
 	    !TAILQ_EMPTY(&rt->mfc_stall)) {
@@ -1085,7 +1100,7 @@
 
 		init_mfc_params(rt, mfccp);
 		rt->mfc_expire = 0;	/* Don't clean this guy up */
-		nexpire[hash]--;
+		V_nexpire[hash]--;
 
 		/* Free queued packets, but attempt to forward them first. */
 		TAILQ_FOREACH_SAFE(rte, &rt->mfc_stall, rte_link, nrte) {
@@ -1104,12 +1119,12 @@
      */
     if (nstl == 0) {
 	CTR1(KTR_IPMF, "%s: adding mfc w/o upcall", __func__);
-	LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) {
+	LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) {
 		if (in_hosteq(rt->mfc_origin, mfccp->mfcc_origin) &&
 		    in_hosteq(rt->mfc_mcastgrp, mfccp->mfcc_mcastgrp)) {
 			init_mfc_params(rt, mfccp);
 			if (rt->mfc_expire)
-			    nexpire[hash]--;
+			    V_nexpire[hash]--;
 			rt->mfc_expire = 0;
 			break; /* XXX */
 		}
@@ -1131,7 +1146,7 @@
 	    rt->mfc_bw_meter = NULL;
 
 	    /* insert new entry at head of hash chain */
-	    LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash);
+	    LIST_INSERT_HEAD(&V_mfchashtbl[hash], rt, mfc_hash);
 	}
     }
 
@@ -1238,7 +1253,7 @@
 
     VIF_LOCK();
     MFC_LOCK();
-    if (imo && ((vifi = imo->imo_multicast_vif) < numvifs)) {
+    if (imo && ((vifi = imo->imo_multicast_vif) < V_numvifs)) {
 	if (ip->ip_ttl < MAXTTL)
 	    ip->ip_ttl++;	/* compensate for -1 in *_send routines */
 	error = ip_mdq(m, ifp, NULL, vifi);
@@ -1310,7 +1325,7 @@
 
 	/* is there an upcall waiting for this flow ? */
 	hash = MFCHASH(ip->ip_src, ip->ip_dst);
-	LIST_FOREACH(rt, &mfchashtbl[hash], mfc_hash) {
+	LIST_FOREACH(rt, &V_mfchashtbl[hash], mfc_hash) {
 		if (in_hosteq(ip->ip_src, rt->mfc_origin) &&
 		    in_hosteq(ip->ip_dst, rt->mfc_mcastgrp) &&
 		    !TAILQ_EMPTY(&rt->mfc_stall))
@@ -1327,10 +1342,10 @@
 	     * Locate the vifi for the incoming interface for this packet.
 	     * If none found, drop packet.
 	     */
-	    for (vifi = 0; vifi < numvifs &&
-		    viftable[vifi].v_ifp != ifp; vifi++)
+	    for (vifi = 0; vifi < V_numvifs &&
+		    V_viftable[vifi].v_ifp != ifp; vifi++)
 		;
-	    if (vifi >= numvifs)	/* vif not found, drop packet */
+	    if (vifi >= V_numvifs)	/* vif not found, drop packet */
 		goto non_fatal;
 
 	    /* no upcall, so make a new entry */
@@ -1373,8 +1388,8 @@
 	    rt->mfc_origin.s_addr     = ip->ip_src.s_addr;
 	    rt->mfc_mcastgrp.s_addr   = ip->ip_dst.s_addr;
 	    rt->mfc_expire	      = UPCALL_EXPIRE;
-	    nexpire[hash]++;
-	    for (i = 0; i < numvifs; i++) {
+	    V_nexpire[hash]++;
+	    for (i = 0; i < V_numvifs; i++) {
 		rt->mfc_ttls[i] = 0;
 		rt->mfc_flags[i] = 0;
 	    }
@@ -1394,7 +1409,7 @@
 	    rt->mfc_nstall = 0;
 
 	    /* link into table */
-	    LIST_INSERT_HEAD(&mfchashtbl[hash], rt, mfc_hash);
+	    LIST_INSERT_HEAD(&V_mfchashtbl[hash], rt, mfc_hash);
 	    TAILQ_INSERT_HEAD(&rt->mfc_stall, rte, rte_link);
 	    rt->mfc_nstall++;
 
@@ -1427,19 +1442,21 @@
  * Clean up the cache entry if upcall is not serviced
  */
 static void
-expire_upcalls(void *unused)
+expire_upcalls(void *arg)
 {
     int i;
 
+    CURVNET_SET((struct vnet *) arg);
+
     MFC_LOCK();
 
     for (i = 0; i < mfchashsize; i++) {
 	struct mfc *rt, *nrt;
 
-	if (nexpire[i] == 0)
+	if (V_nexpire[i] == 0)
 	    continue;
 
-	for (rt = LIST_FIRST(&mfchashtbl[i]); rt; rt = nrt) {
+	for (rt = LIST_FIRST(&V_mfchashtbl[i]); rt; rt = nrt) {
 		nrt = LIST_NEXT(rt, mfc_hash);
 
 		if (TAILQ_EMPTY(&rt->mfc_stall))
@@ -1469,7 +1486,9 @@
 
     MFC_UNLOCK();
 
-    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, NULL);
+    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, curvnet);
+
+    CURVNET_RESTORE();
 }
 
 /*
@@ -1489,11 +1508,11 @@
      *
      * (since vifi_t is u_short, -1 becomes MAXUSHORT, which > numvifs.)
      */
-    if (xmt_vif < numvifs) {
-	if (viftable[xmt_vif].v_flags & VIFF_REGISTER)
-		pim_register_send(ip, viftable + xmt_vif, m, rt);
+    if (xmt_vif < V_numvifs) {
+	if (V_viftable[xmt_vif].v_flags & VIFF_REGISTER)
+		pim_register_send(ip, V_viftable + xmt_vif, m, rt);
 	else
-		phyint_send(ip, viftable + xmt_vif, m);
+		phyint_send(ip, V_viftable + xmt_vif, m);
 	return 1;
     }
 
@@ -1501,9 +1520,9 @@
      * Don't forward if it didn't arrive from the parent vif for its origin.
      */
     vifi = rt->mfc_parent;
-    if ((vifi >= numvifs) || (viftable[vifi].v_ifp != ifp)) {
+    if ((vifi >= V_numvifs) || (V_viftable[vifi].v_ifp != ifp)) {
 	CTR4(KTR_IPMF, "%s: rx on wrong ifp %p (vifi %d, v_ifp %p)",
-	    __func__, ifp, (int)vifi, viftable[vifi].v_ifp);
+	    __func__, ifp, (int)vifi, V_viftable[vifi].v_ifp);
 	MRTSTAT_INC(mrts_wrong_if);
 	++rt->mfc_wrong_if;
 	/*
@@ -1514,15 +1533,15 @@
 	 * can complete the SPT switch, regardless of the type
 	 * of the iif (broadcast media, GRE tunnel, etc).
 	 */
-	if (pim_assert_enabled && (vifi < numvifs) && viftable[vifi].v_ifp) {
+	if (pim_assert_enabled && (vifi < V_numvifs) && V_viftable[vifi].v_ifp) {
 
-	    if (ifp == &multicast_register_if)
+	    if (ifp == &V_multicast_register_if)
 		PIMSTAT_INC(pims_rcv_registers_wrongiif);
 
 	    /* Get vifi for the incoming packet */
-	    for (vifi=0; vifi < numvifs && viftable[vifi].v_ifp != ifp; vifi++)
+	    for (vifi=0; vifi < V_numvifs && V_viftable[vifi].v_ifp != ifp; vifi++)
 		;
-	    if (vifi >= numvifs)
+	    if (vifi >= V_numvifs)
 		return 0;	/* The iif is not found: ignore the packet. */
 
 	    if (rt->mfc_flags[vifi] & MRT_MFC_FLAGS_DISABLE_WRONGVIF)
@@ -1559,12 +1578,12 @@
 
 
     /* If I sourced this packet, it counts as output, else it was input. */
-    if (in_hosteq(ip->ip_src, viftable[vifi].v_lcl_addr)) {
-	viftable[vifi].v_pkt_out++;
-	viftable[vifi].v_bytes_out += plen;
+    if (in_hosteq(ip->ip_src, V_viftable[vifi].v_lcl_addr)) {
+	V_viftable[vifi].v_pkt_out++;
+	V_viftable[vifi].v_bytes_out += plen;
     } else {
-	viftable[vifi].v_pkt_in++;
-	viftable[vifi].v_bytes_in += plen;
+	V_viftable[vifi].v_pkt_in++;
+	V_viftable[vifi].v_bytes_in += plen;
     }
     rt->mfc_pkt_cnt++;
     rt->mfc_byte_cnt += plen;
@@ -1575,14 +1594,14 @@
      *		- the ttl exceeds the vif's threshold
      *		- there are group members downstream on interface
      */
-    for (vifi = 0; vifi < numvifs; vifi++)
+    for (vifi = 0; vifi < V_numvifs; vifi++)
 	if ((rt->mfc_ttls[vifi] > 0) && (ip->ip_ttl > rt->mfc_ttls[vifi])) {
-	    viftable[vifi].v_pkt_out++;
-	    viftable[vifi].v_bytes_out += plen;
-	    if (viftable[vifi].v_flags & VIFF_REGISTER)
-		pim_register_send(ip, viftable + vifi, m, rt);
+	    V_viftable[vifi].v_pkt_out++;
+	    V_viftable[vifi].v_bytes_out += plen;
+	    if (V_viftable[vifi].v_flags & VIFF_REGISTER)
+		pim_register_send(ip, V_viftable + vifi, m, rt);
 	    else
-		phyint_send(ip, viftable + vifi, m);
+		phyint_send(ip, V_viftable + vifi, m);
 	}
 
     /*
@@ -1614,7 +1633,7 @@
 		return (ret);
 
 	VIF_LOCK();
-	if (vif < numvifs)
+	if (vif < V_numvifs)
 		ret = 1;
 	VIF_UNLOCK();
 
@@ -1634,8 +1653,8 @@
 		return (addr);
 
 	VIF_LOCK();
-	if (vifi < numvifs)
-		addr = viftable[vifi].v_lcl_addr.s_addr;
+	if (vifi < V_numvifs)
+		addr = V_viftable[vifi].v_lcl_addr.s_addr;
 	VIF_UNLOCK();
 
 	return (addr);
@@ -1688,7 +1707,7 @@
 	 */
 	error = ip_output(m, NULL, &vifp->v_route, IP_FORWARDING, &imo, NULL);
 	CTR3(KTR_IPMF, "%s: vif %td err %d", __func__,
-	    (ptrdiff_t)(vifp - viftable), error);
+	    (ptrdiff_t)(vifp - V_viftable), error);
 }
 
 /*
@@ -2013,13 +2032,13 @@
     /*
      * If there are too many pending upcalls, deliver them now
      */
-    if (bw_upcalls_n >= BW_UPCALLS_MAX)
+    if (V_bw_upcalls_n >= BW_UPCALLS_MAX)
 	bw_upcalls_send();
 
     /*
      * Set the bw_upcall entry
      */
-    u = &bw_upcalls[bw_upcalls_n++];
+    u = &V_bw_upcalls[V_bw_upcalls_n++];
     u->bu_src = x->bm_mfc->mfc_origin;
     u->bu_dst = x->bm_mfc->mfc_mcastgrp;
     u->bu_threshold.b_time = x->bm_threshold.b_time;
@@ -2046,7 +2065,7 @@
 bw_upcalls_send(void)
 {
     struct mbuf *m;
-    int len = bw_upcalls_n * sizeof(bw_upcalls[0]);
+    int len = V_bw_upcalls_n * sizeof(V_bw_upcalls[0]);
     struct sockaddr_in k_igmpsrc = { sizeof k_igmpsrc, AF_INET };
     static struct igmpmsg igmpmsg = { 0,		/* unused1 */
 				      0,		/* unused2 */
@@ -2058,11 +2077,12 @@
 				      { 0 } };		/* im_dst  */
 
     MFC_LOCK_ASSERT();
+    MFC_LOCK_ASSERT();
 
-    if (bw_upcalls_n == 0)
+    if (V_bw_upcalls_n == 0)
 	return;			/* No pending upcalls */
 
-    bw_upcalls_n = 0;
+    V_bw_upcalls_n = 0;
 
     /*
      * Allocate a new mbuf, initialize it with the header and
@@ -2076,7 +2096,7 @@
 
     m->m_len = m->m_pkthdr.len = 0;
     m_copyback(m, 0, sizeof(struct igmpmsg), (caddr_t)&igmpmsg);
-    m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&bw_upcalls[0]);
+    m_copyback(m, sizeof(struct igmpmsg), len, (caddr_t)&V_bw_upcalls[0]);
 
     /*
      * Send the upcalls
@@ -2129,8 +2149,8 @@
      * Compute the timeout hash value and insert the entry
      */
     BW_METER_TIMEHASH(x, time_hash);
-    x->bm_time_next = bw_meter_timers[time_hash];
-    bw_meter_timers[time_hash] = x;
+    x->bm_time_next = V_bw_meter_timers[time_hash];
+    V_bw_meter_timers[time_hash] = x;
     x->bm_time_hash = time_hash;
 }
 
@@ -2156,7 +2176,7 @@
     if (time_hash >= BW_METER_BUCKETS)
 	return;		/* Entry was not scheduled */
 
-    for (prev = NULL, tmp = bw_meter_timers[time_hash];
+    for (prev = NULL, tmp = V_bw_meter_timers[time_hash];
 	     tmp != NULL; prev = tmp, tmp = tmp->bm_time_next)
 	if (tmp == x)
 	    break;
@@ -2167,7 +2187,7 @@
     if (prev != NULL)
 	prev->bm_time_next = x->bm_time_next;
     else
-	bw_meter_timers[time_hash] = x->bm_time_next;
+	V_bw_meter_timers[time_hash] = x->bm_time_next;
 
     x->bm_time_next = NULL;
     x->bm_time_hash = BW_METER_BUCKETS;
@@ -2186,18 +2206,16 @@
 static void
 bw_meter_process()
 {
-    static uint32_t last_tv_sec;	/* last time we processed this */
-
     uint32_t loops;
     int i;
     struct timeval now, process_endtime;
 
     microtime(&now);
-    if (last_tv_sec == now.tv_sec)
+    if (V_last_tv_sec == now.tv_sec)
 	return;		/* nothing to do */
 
-    loops = now.tv_sec - last_tv_sec;
-    last_tv_sec = now.tv_sec;
+    loops = now.tv_sec - V_last_tv_sec;
+    V_last_tv_sec = now.tv_sec;
     if (loops > BW_METER_BUCKETS)
 	loops = BW_METER_BUCKETS;
 
@@ -2214,8 +2232,8 @@
 	    i = 0;
 
 	/* Disconnect the list of bw_meter entries from the bin */
-	tmp_list = bw_meter_timers[i];
-	bw_meter_timers[i] = NULL;
+	tmp_list = V_bw_meter_timers[i];
+	V_bw_meter_timers[i] = NULL;
 
 	/* Process the list of bw_meter entries */
 	while (tmp_list != NULL) {
@@ -2238,8 +2256,8 @@
 		    if (++time_hash >= BW_METER_BUCKETS)
 			time_hash = 0;
 		}
-		x->bm_time_next = bw_meter_timers[time_hash];
-		bw_meter_timers[time_hash] = x;
+		x->bm_time_next = V_bw_meter_timers[time_hash];
+		V_bw_meter_timers[time_hash] = x;
 		x->bm_time_hash = time_hash;
 
 		continue;
@@ -2273,14 +2291,17 @@
  * A periodic function for sending all upcalls that are pending delivery
  */
 static void
-expire_bw_upcalls_send(void *unused)
+expire_bw_upcalls_send(void *arg)
 {
+    CURVNET_SET((struct vnet *) arg);
+
     MFC_LOCK();
     bw_upcalls_send();
     MFC_UNLOCK();
 
     callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
-	expire_bw_upcalls_send, NULL);
+	expire_bw_upcalls_send, curvnet);
+    CURVNET_RESTORE();
 }
 
 /*
@@ -2288,12 +2309,15 @@
  * table for processing all "<=" bw_meter entries.
  */
 static void
-expire_bw_meter_process(void *unused)
+expire_bw_meter_process(void *arg)
 {
+    CURVNET_SET((struct vnet *) arg);
+
     if (mrt_api_config & MRT_MFC_BW_UPCALL)
 	bw_meter_process();
 
-    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, NULL);
+    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, curvnet);
+    CURVNET_RESTORE();
 }
 
 /*
@@ -2425,7 +2449,7 @@
     im = mtod(mb_first, struct igmpmsg *);
     im->im_msgtype	= IGMPMSG_WHOLEPKT;
     im->im_mbz		= 0;
-    im->im_vif		= vifp - viftable;
+    im->im_vif		= vifp - V_viftable;
     im->im_src		= ip->ip_src;
     im->im_dst		= ip->ip_dst;
 
@@ -2461,7 +2485,7 @@
 
     VIF_LOCK_ASSERT();
 
-    if ((vifi >= numvifs) || in_nullhost(viftable[vifi].v_lcl_addr)) {
+    if ((vifi >= V_numvifs) || in_nullhost(V_viftable[vifi].v_lcl_addr)) {
 	m_freem(mb_copy);
 	return EADDRNOTAVAIL;		/* The iif vif is invalid */
     }
@@ -2487,7 +2511,7 @@
     *ip_outer = pim_encap_iphdr;
     ip_outer->ip_id = ip_newid();
     ip_outer->ip_len = len + sizeof(pim_encap_iphdr) + sizeof(pim_encap_pimhdr);
-    ip_outer->ip_src = viftable[vifi].v_lcl_addr;
+    ip_outer->ip_src = V_viftable[vifi].v_lcl_addr;
     ip_outer->ip_dst = rt->mfc_rp;
     /*
      * Copy the inner header TOS to the outer header, and take care of the
@@ -2637,15 +2661,15 @@
 	struct ifnet *vifp;
 
 	VIF_LOCK();
-	if ((reg_vif_num >= numvifs) || (reg_vif_num == VIFI_INVALID)) {
+	if ((V_reg_vif_num >= V_numvifs) || (V_reg_vif_num == VIFI_INVALID)) {
 	    VIF_UNLOCK();
 	    CTR2(KTR_IPMF, "%s: register vif not set: %d", __func__,
-		(int)reg_vif_num);
+		(int)V_reg_vif_num);
 	    m_freem(m);
 	    return;
 	}
 	/* XXX need refcnt? */
-	vifp = viftable[reg_vif_num].v_ifp;
+	vifp = V_viftable[V_reg_vif_num].v_ifp;
 	VIF_UNLOCK();
 
 	/*
@@ -2736,7 +2760,7 @@
 	    __func__,
 	    (u_long)ntohl(encap_ip->ip_src.s_addr),
 	    (u_long)ntohl(encap_ip->ip_dst.s_addr),
-	    (int)reg_vif_num);
+	    (int)V_reg_vif_num);
 
 	/* NB: vifp was collected above; can it change on us? */
 	if_simloop(vifp, m, dst.sin_family, 0);
@@ -2767,7 +2791,7 @@
 
 	if (req->newptr)
 		return (EPERM);
-	if (mfchashtbl == NULL)	/* XXX unlocked */
+	if (V_mfchashtbl == NULL)	/* XXX unlocked */
 		return (0);
 	error = sysctl_wire_old_buffer(req, 0);
 	if (error)
@@ -2775,7 +2799,7 @@
 
 	MFC_LOCK();
 	for (i = 0; i < mfchashsize; i++) {
-		LIST_FOREACH(rt, &mfchashtbl[i], mfc_hash) {
+		LIST_FOREACH(rt, &V_mfchashtbl[i], mfc_hash) {
 			error = SYSCTL_OUT(req, rt, sizeof(struct mfc));
 			if (error)
 				goto out_locked;
@@ -2790,6 +2814,32 @@
     "IPv4 Multicast Forwarding Table (struct *mfc[mfchashsize], "
     "netinet/ip_mroute.h)");
 
+static void
+vnet_mroute_init(const void *unused __unused)
+{
+
+	MALLOC(V_nexpire, u_char *, mfchashsize, M_MRTABLE, M_WAITOK|M_ZERO);
+}
+
+VNET_SYSINIT(vnet_mroute_init, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, vnet_mroute_init,
+	NULL);
+
+static void
+vnet_mroute_uninit(const void *unused __unused)
+{
+    	/*
+	callout_stop(&V_expire_upcalls_ch);
+    	callout_stop(&V_bw_upcalls_ch);
+    	callout_stop(&V_bw_meter_ch);
+	*/
+	FREE(V_nexpire, M_MRTABLE);
+	V_nexpire = NULL;
+	X_ip_mrouter_done();
+}
+
+VNET_SYSUNINIT(vnet_mroute_uninit, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, 
+	vnet_mroute_uninit, NULL);
+
 static int
 ip_mroute_modevent(module_t mod, int type, void *unused)
 {
@@ -2807,7 +2857,6 @@
 		    "net.inet.ip.mfchashsize");
 		mfchashsize = MFCHASHSIZE;
 	}
-	MALLOC(nexpire, u_char *, mfchashsize, M_MRTABLE, M_WAITOK|M_ZERO);
 
 	pim_squelch_wholepkt = 0;
 	TUNABLE_ULONG_FETCH("net.inet.pim.squelch_wholepkt",
@@ -2854,10 +2903,6 @@
 	    encap_detach(pim_encap_cookie);
 	    pim_encap_cookie = NULL;
 	}
-	X_ip_mrouter_done();
-
-	FREE(nexpire, M_MRTABLE);
-	nexpire = NULL;
 
 	ip_mcast_src = NULL;
 	ip_mforward = NULL;

==== //depot/projects/vimage/src/sys/netinet/ip_mroute.h#8 (text+ko) ====

@@ -222,7 +222,7 @@
 };
 
 #ifdef _KERNEL
-#define	MRTSTAT_ADD(name, val)	mrtstat.name += (val)
+#define	MRTSTAT_ADD(name, val)	V_mrtstat.name += (val)
 #define	MRTSTAT_INC(name)	MRTSTAT_ADD(name, 1)
 #endif
 

==== //depot/projects/vimage/src/sys/netinet/pim_var.h#3 (text+ko) ====

@@ -60,7 +60,7 @@
 };
 
 #ifdef _KERNEL
-#define	PIMSTAT_ADD(name, val)	pimstat.name += (val)
+#define	PIMSTAT_ADD(name, val)	V_pimstat.name += (val)
 #define	PIMSTAT_INC(name)	PIMSTAT_ADD(name, 1)
 #endif
 


More information about the p4-projects mailing list