--- //depot/projects/netperf_socket/sys/net/bpf.c 2004/08/16 02:44:45 +++ //depot/user/rwatson/netperf/sys/net/bpf.c 2004/09/08 01:58:19 @@ -91,7 +91,7 @@ /* * bpf_iflist is the list of interfaces; each corresponds to an ifnet */ -static struct bpf_if *bpf_iflist; +static LIST_HEAD(, bpf_if) bpf_iflist; static struct mtx bpf_mtx; /* bpf global lock */ static int bpf_allocbufs(struct bpf_d *); @@ -256,8 +256,7 @@ */ BPFIF_LOCK(bp); d->bd_bif = bp; - d->bd_next = bp->bif_dlist; - bp->bif_dlist = d; + LIST_INSERT_HEAD(&bp->bif_dlist, d, bd_next); *bp->bif_driverp = bp; BPFIF_UNLOCK(bp); @@ -271,7 +270,6 @@ struct bpf_d *d; { int error; - struct bpf_d **p; struct bpf_if *bp; /* XXX locking */ @@ -297,14 +295,8 @@ } /* Remove d from the interface's descriptor list. */ BPFIF_LOCK(bp); - p = &bp->bif_dlist; - while (*p != d) { - p = &(*p)->bd_next; - if (*p == NULL) - panic("bpf_detachd: descriptor not in list"); - } - *p = (*p)->bd_next; - if (bp->bif_dlist == NULL) + LIST_REMOVE(d, bd_next); + if (LIST_EMPTY(&bp->bif_dlist)) /* * Let the driver know that there are no more listeners. */ @@ -332,7 +324,7 @@ * Each minor can be opened by only one process. If the requested * minor is in use, return EBUSY. */ - if (d) { + if (d != NULL) { mtx_unlock(&bpf_mtx); return (EBUSY); } @@ -343,7 +335,6 @@ make_dev(&bpf_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600, "bpf%d", dev2unit(dev)); MALLOC(d, struct bpf_d *, sizeof(*d), M_BPF, M_WAITOK | M_ZERO); - dev->si_drv1 = d; d->bd_bufsize = bpf_bufsize; d->bd_sig = SIGIO; d->bd_seesent = 1; @@ -354,6 +345,7 @@ mtx_init(&d->bd_mtx, devtoname(dev), "bpf cdev lock", MTX_DEF); callout_init(&d->bd_callout, debug_mpsafenet ? CALLOUT_MPSAFE : 0); knlist_init(&d->bd_sel.si_note, &d->bd_mtx); + dev->si_drv1 = d; return (0); } @@ -387,7 +379,7 @@ #endif /* MAC */ knlist_destroy(&d->bd_sel.si_note); bpf_freed(d); - dev->si_drv1 = 0; + dev->si_drv1 = NULL; free(d, M_BPF); return (0); @@ -404,7 +396,7 @@ (d)->bd_hlen = (d)->bd_slen; \ (d)->bd_sbuf = (d)->bd_fbuf; \ (d)->bd_slen = 0; \ - (d)->bd_fbuf = 0; + (d)->bd_fbuf = NULL; /* * bpfread - read next chunk of packets from buffers */ @@ -993,7 +985,7 @@ * Look through attached interfaces for the named one. */ mtx_lock(&bpf_mtx); - for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) { + LIST_FOREACH(bp, &bpf_iflist, bif_next) { struct ifnet *ifp = bp->bif_ifp; if (ifp == NULL || ifp != theywant) @@ -1149,11 +1141,11 @@ * Lockless read to avoid cost of locking the interface if there are * no descriptors attached. */ - if (bp->bif_dlist == NULL) + if (LIST_EMPTY(&bp->bif_dlist)) return; BPFIF_LOCK(bp); - for (d = bp->bif_dlist; d != NULL; d = d->bd_next) { + LIST_FOREACH(d, &bp->bif_dlist, bd_next) { BPFD_LOCK(d); ++d->bd_rcount; slen = bpf_filter(d->bd_filter, pkt, pktlen, pktlen); @@ -1210,7 +1202,7 @@ * Lockless read to avoid cost of locking the interface if there are * no descriptors attached. */ - if (bp->bif_dlist == NULL) + if (LIST_EMPTY(&bp->bif_dlist)) return; pktlen = m_length(m, NULL); @@ -1220,7 +1212,7 @@ } BPFIF_LOCK(bp); - for (d = bp->bif_dlist; d != NULL; d = d->bd_next) { + LIST_FOREACH(d, &bp->bif_dlist, bd_next) { if (!d->bd_seesent && (m->m_pkthdr.rcvif == NULL)) continue; BPFD_LOCK(d); @@ -1256,7 +1248,7 @@ * Lockless read to avoid cost of locking the interface if there are * no descriptors attached. */ - if (bp->bif_dlist == NULL) + if (LIST_EMPTY(&bp->bif_dlist)) return; pktlen = m_length(m, NULL); @@ -1271,7 +1263,7 @@ pktlen += dlen; BPFIF_LOCK(bp); - for (d = bp->bif_dlist; d != NULL; d = d->bd_next) { + LIST_FOREACH(d, &bp->bif_dlist, bd_next) { if (!d->bd_seesent && (m->m_pkthdr.rcvif == NULL)) continue; BPFD_LOCK(d); @@ -1436,15 +1428,14 @@ if (bp == NULL) panic("bpfattach"); - bp->bif_dlist = NULL; + LIST_INIT(&bp->bif_dlist); bp->bif_driverp = driverp; bp->bif_ifp = ifp; bp->bif_dlt = dlt; mtx_init(&bp->bif_mtx, "bpf interface lock", NULL, MTX_DEF); mtx_lock(&bpf_mtx); - bp->bif_next = bpf_iflist; - bpf_iflist = bp; + LIST_INSERT_HEAD(&bpf_iflist, bp, bif_next); mtx_unlock(&bpf_mtx); *bp->bif_driverp = NULL; @@ -1471,17 +1462,14 @@ bpfdetach(ifp) struct ifnet *ifp; { - struct bpf_if *bp, *bp_prev; + struct bpf_if *bp; struct bpf_d *d; /* Locate BPF interface information */ - bp_prev = NULL; - mtx_lock(&bpf_mtx); - for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) { + LIST_FOREACH(bp, &bpf_iflist, bif_next) { if (ifp == bp->bif_ifp) break; - bp_prev = bp; } /* Interface wasn't attached */ @@ -1491,14 +1479,10 @@ return; } - if (bp_prev) { - bp_prev->bif_next = bp->bif_next; - } else { - bpf_iflist = bp->bif_next; - } + LIST_REMOVE(bp, bif_next); mtx_unlock(&bpf_mtx); - while ((d = bp->bif_dlist) != NULL) { + while ((d = LIST_FIRST(&bp->bif_dlist)) != NULL) { bpf_detachd(d); BPFD_LOCK(d); bpf_wakeup(d); @@ -1525,7 +1509,7 @@ n = 0; error = 0; mtx_lock(&bpf_mtx); - for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) { + LIST_FOREACH(bp, &bpf_iflist, bif_next) { if (bp->bif_ifp != ifp) continue; if (bfl->bfl_list != NULL) { @@ -1559,7 +1543,7 @@ return (0); ifp = d->bd_bif->bif_ifp; mtx_lock(&bpf_mtx); - for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) { + LIST_FOREACH(bp, &bpf_iflist, bif_next) { if (bp->bif_ifp == ifp && bp->bif_dlt == dlt) break; } @@ -1613,6 +1597,7 @@ { mtx_init(&bpf_mtx, "bpf global lock", NULL, MTX_DEF); + LIST_INIT(&bpf_iflist); EVENTHANDLER_REGISTER(dev_clone, bpf_clone, 0, 1000); } --- //depot/projects/netperf_socket/sys/net/bpfdesc.h 2004/04/08 02:39:15 +++ //depot/user/rwatson/netperf/sys/net/bpfdesc.h 2004/09/08 01:58:19 @@ -41,12 +41,13 @@ #include #include +#include /* * Descriptor associated with each open bpf file. */ struct bpf_d { - struct bpf_d *bd_next; /* Linked list of descriptors */ + LIST_ENTRY(bpf_d) bd_next; /* Linked list of descriptors */ /* * Buffer slots: two mbuf clusters buffer the incoming packets. * The model has three slots. Sbuf is always occupied. @@ -113,8 +114,8 @@ * Descriptor associated with each attached hardware interface. */ struct bpf_if { - struct bpf_if *bif_next; /* list of all interfaces */ - struct bpf_d *bif_dlist; /* descriptor list */ + LIST_ENTRY(bpf_if) bif_next; /* list of all interfaces */ + LIST_HEAD(, bpf_d) bif_dlist; /* descriptor list */ struct bpf_if **bif_driverp; /* pointer into softc */ u_int bif_dlt; /* link layer type */ u_int bif_hdrlen; /* length of header (with padding) */