diff options
author | Lawrence Stewart <lstewart@FreeBSD.org> | 2012-01-10 00:48:29 +0000 |
---|---|---|
committer | Lawrence Stewart <lstewart@FreeBSD.org> | 2012-01-10 00:48:29 +0000 |
commit | 9a7e6bac47adc1bbff8a3cb38ff74bde8a2cc399 (patch) | |
tree | 163b8ae7160d4b3a8a93f6686be6c70e99d94f01 /sys/net/bpf.c | |
parent | ee5f87f4588609f6770138969c69d36b1c77abcf (diff) | |
download | src-test2-9a7e6bac47adc1bbff8a3cb38ff74bde8a2cc399.tar.gz src-test2-9a7e6bac47adc1bbff8a3cb38ff74bde8a2cc399.zip |
Notes
Diffstat (limited to 'sys/net/bpf.c')
-rw-r--r-- | sys/net/bpf.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 3dd2f9310e5a..80f56360c793 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -2253,33 +2253,42 @@ bpfdetach(struct ifnet *ifp) { struct bpf_if *bp; struct bpf_d *d; +#ifdef INVARIANTS + int ndetached; - /* Locate BPF interface information */ - mtx_lock(&bpf_mtx); - LIST_FOREACH(bp, &bpf_iflist, bif_next) { - if (ifp == bp->bif_ifp) - break; - } + ndetached = 0; +#endif - /* Interface wasn't attached */ - if ((bp == NULL) || (bp->bif_ifp == NULL)) { + /* Find all bpf_if struct's which reference ifp and detach them. */ + do { + mtx_lock(&bpf_mtx); + LIST_FOREACH(bp, &bpf_iflist, bif_next) { + if (ifp == bp->bif_ifp) + break; + } + if (bp != NULL) + LIST_REMOVE(bp, bif_next); mtx_unlock(&bpf_mtx); - printf("bpfdetach: %s was not attached\n", ifp->if_xname); - return; - } - - LIST_REMOVE(bp, bif_next); - mtx_unlock(&bpf_mtx); - while ((d = LIST_FIRST(&bp->bif_dlist)) != NULL) { - bpf_detachd(d); - BPFD_LOCK(d); - bpf_wakeup(d); - BPFD_UNLOCK(d); - } + if (bp != NULL) { +#ifdef INVARIANTS + ndetached++; +#endif + while ((d = LIST_FIRST(&bp->bif_dlist)) != NULL) { + bpf_detachd(d); + BPFD_LOCK(d); + bpf_wakeup(d); + BPFD_UNLOCK(d); + } + mtx_destroy(&bp->bif_mtx); + free(bp, M_BPF); + } + } while (bp != NULL); - mtx_destroy(&bp->bif_mtx); - free(bp, M_BPF); +#ifdef INVARIANTS + if (ndetached == 0) + printf("bpfdetach: %s was not attached\n", ifp->if_xname); +#endif } /* |