Index: sys/net/if_epair.c =================================================================== --- sys/net/if_epair.c +++ sys/net/if_epair.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -61,6 +62,9 @@ #include #include #include +#include +#include +#include #include #include @@ -138,6 +142,9 @@ /* Original if_qflush routine. */ }; +/* A system-wide conter for the number of epair interfaces. */ +static counter_u64_t epair_cnt; + /* * Per-CPU list of ifps with data in the ifq that needs to be flushed * to the netisr ``hw'' queue before we allow any further direct queuing @@ -709,7 +716,7 @@ struct epair_softc *sca, *scb; struct ifnet *ifp; char *dp; - int error, unit, wildcard; + int error, unit, wildcard, jid; uint8_t eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */ /* @@ -718,15 +725,20 @@ * for it to do the official insertion procedure the moment we knew * it cannot fail anymore. So just do attach it here. */ + bzero(eaddr, sizeof(eaddr)); + jid = curthread->td_ucred->cr_prison->pr_id; if (params) { scb = (struct epair_softc *)params; ifp = scb->ifp; /* Assign a hopefully unique, locally administered etheraddr. */ eaddr[0] = 0x02; - eaddr[3] = (ifp->if_index >> 8) & 0xff; - eaddr[4] = ifp->if_index & 0xff; + eaddr[1] = (jid >> 8) & 0xff; + eaddr[2] = jid & 0xff; + eaddr[3] = (counter_u64_fetch(epair_cnt) >> 8) & 0xff; + eaddr[4] = counter_u64_fetch(epair_cnt) & 0xff; eaddr[5] = 0x0b; ether_ifattach(ifp, eaddr); + counter_u64_add(epair_cnt, 1); /* Correctly set the name for the cloner list. */ strlcpy(name, scb->ifp->if_xname, len); return (0); @@ -825,10 +837,13 @@ ifp->if_snd.ifq_maxlen = ifqmaxlen; /* Assign a hopefully unique, locally administered etheraddr. */ eaddr[0] = 0x02; - eaddr[3] = (ifp->if_index >> 8) & 0xff; - eaddr[4] = ifp->if_index & 0xff; + eaddr[1] = (jid >> 8) & 0xff; + eaddr[2] = jid & 0xff; + eaddr[3] = (counter_u64_fetch(epair_cnt) >> 8) & 0xff; + eaddr[4] = counter_u64_fetch(epair_cnt) & 0xff; eaddr[5] = 0x0a; ether_ifattach(ifp, eaddr); + counter_u64_add(epair_cnt, 1); sca->if_qflush = ifp->if_qflush; ifp->if_qflush = epair_qflush; ifp->if_transmit = epair_transmit; @@ -919,6 +934,7 @@ */ CURVNET_SET_QUIET(oifp->if_vnet); ether_ifdetach(oifp); + counter_u64_add(epair_cnt, -1); /* * Wait for all packets to be dispatched to if_input. * The numbers can only go down as the interface is @@ -938,6 +954,7 @@ CURVNET_RESTORE(); ether_ifdetach(ifp); + counter_u64_add(epair_cnt, -1); /* * Wait for all packets to be dispatched to if_input. */ @@ -978,6 +995,7 @@ switch (type) { case MOD_LOAD: + epair_cnt = counter_u64_alloc(M_WAITOK); /* For now limit us to one global mutex and one inq. */ epair_dpcpu_init(); epair_nh.nh_qlimit = 42 * ifqmaxlen; /* 42 shall be the number. */ @@ -990,6 +1008,7 @@ case MOD_UNLOAD: netisr_unregister(&epair_nh); epair_dpcpu_detach(); + counter_u64_free(epair_cnt); if (bootverbose) printf("%s unloaded.\n", epairname); break;