summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/net/bpf.c63
-rw-r--r--sys/net/bpf.h2
2 files changed, 65 insertions, 0 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 466227c..9d562e4 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -477,6 +477,18 @@ bpfread(dev, uio, ioflag)
ROTATE_BUFFERS(d);
break;
}
+
+ /*
+ * No data is available, check to see if the bpf device
+ * is still pointed at a real interface. If not, return
+ * ENXIO so that the userland process knows to rebind
+ * it before using it again.
+ */
+ if (d->bd_bif == NULL) {
+ splx(s);
+ return (ENXIO);
+ }
+
if (ioflag & IO_NDELAY)
error = EWOULDBLOCK;
else
@@ -1035,6 +1047,9 @@ bpfpoll(dev, events, p)
*/
d = dev->si_drv1;
+ if (d->bd_bif == NULL)
+ return (ENXIO);
+
s = splimp();
if (events & (POLLIN | POLLRDNORM)) {
if (d->bd_hlen != 0 || (d->bd_immediate && d->bd_slen != 0))
@@ -1287,6 +1302,54 @@ bpfattach(ifp, dlt, hdrlen)
printf("bpf: %s%d attached\n", ifp->if_name, ifp->if_unit);
}
+/*
+ * Detach bpf from an interface. This involves detaching each descriptor
+ * associated with the interface, and leaving bd_bif NULL. Notify each
+ * descriptor as it's detached so that any sleepers wake up and get
+ * ENXIO.
+ */
+void
+bpfdetach(ifp)
+ struct ifnet *ifp;
+{
+ struct bpf_if *bp, *bp_prev;
+ struct bpf_d *d;
+ int s;
+
+ s = splimp();
+
+ /* Locate BPF interface information */
+ bp_prev = NULL;
+ for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) {
+ if (ifp == bp->bif_ifp)
+ break;
+ bp_prev = bp;
+ }
+
+ /* Interface wasn't attached */
+ if (bp->bif_ifp == NULL) {
+ splx(s);
+ printf("bpfdetach: %s%d was not attached\n", ifp->if_name,
+ ifp->if_unit);
+ return;
+ }
+
+ while ((d = bp->bif_dlist) != NULL) {
+ bpf_detachd(d);
+ bpf_wakeup(d);
+ }
+
+ if (bp_prev) {
+ bp_prev->bif_next = bp->bif_next;
+ } else {
+ bpf_iflist = bp->bif_next;
+ }
+
+ free(bp, M_BPF);
+
+ splx(s);
+}
+
static void bpf_drvinit __P((void *unused));
static void
diff --git a/sys/net/bpf.h b/sys/net/bpf.h
index 9494e83..a173b0a 100644
--- a/sys/net/bpf.h
+++ b/sys/net/bpf.h
@@ -232,6 +232,8 @@ int bpf_validate __P((const struct bpf_insn *, int));
void bpf_tap __P((struct ifnet *, u_char *, u_int));
void bpf_mtap __P((struct ifnet *, struct mbuf *));
void bpfattach __P((struct ifnet *, u_int, u_int));
+void bpfdetach __P((struct ifnet *));
+
void bpfilterattach __P((int));
u_int bpf_filter __P((const struct bpf_insn *, u_char *, u_int, u_int));
#endif
OpenPOWER on IntegriCloud