summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-06-26 09:13:14 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-06-26 09:13:14 +0000
commita12e9c046bba20015516fbd9444e1a63f4e25ca9 (patch)
tree86345410ae79dbde220e2bdd5357ac11d89f9423 /sys
parent9441a3641199e3d097a07b89fdc9eed521026b79 (diff)
fix bpf select(); from mts@rare.net
Diffstat (limited to 'sys')
-rw-r--r--sys/net/bpf.c59
-rw-r--r--sys/net/bpf.h7
-rw-r--r--sys/net/bpfdesc.h3
3 files changed, 59 insertions, 10 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index d8fb4798ae1..19a1cde28de 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.12 1997/09/30 02:31:04 millert Exp $ */
+/* $OpenBSD: bpf.c,v 1.13 1998/06/26 09:13:10 deraadt Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -89,7 +89,7 @@ caddr_t bpf_alloc();
#define UIOMOVE(cp, len, code, uio) uiomove(cp, len, uio)
#endif
-#define PRINET 26 /* interruptible */
+#define PRINET 6 /* interruptible */
/*
* The default read buffer size is patchable.
@@ -450,6 +450,16 @@ bpfread(dev, uio, ioflag)
return (EINVAL);
s = splimp();
+
+ /*
+ * bd_rdStart is tagged when we start the read, iff there's a timeout.
+ * we can then figure out when we're done reading.
+ */
+ if (d->bd_rtout != -1 && d->bd_rdStart == 0)
+ d->bd_rdStart = ticks;
+ else
+ d->bd_rdStart = 0;
+
/*
* If the hold buffer is empty, then do a timed sleep, which
* ends when the timeout expires or when enough packets
@@ -465,11 +475,16 @@ bpfread(dev, uio, ioflag)
ROTATE_BUFFERS(d);
break;
}
- if (d->bd_rtout != -1)
+ if ((d->bd_rtout != -1) || (d->bd_rdStart + d->bd_rtout) < ticks) {
error = BPF_SLEEP((caddr_t)d, PRINET|PCATCH, "bpf",
- d->bd_rtout);
- else
- error = EWOULDBLOCK; /* User requested non-blocking I/O */
+ d->bd_rtout);
+ } else {
+ if (d->bd_rtout == -1) {
+ /* User requested non-blocking I/O */
+ error = EWOULDBLOCK;
+ } else
+ error = 0;
+ }
if (error == EINTR || error == ERESTART) {
splx(s);
return (error);
@@ -996,6 +1011,13 @@ bpfselect(dev, rw)
register dev_t dev;
int rw;
{
+ /*
+ * if there isn't data waiting, and there's a timeout,
+ * mark the time we started waiting.
+ */
+ if (b->db_rtout != -1 && (d->bd_rdStart == 0)
+ d->bd_rdStart = ticks;
+
return (bpf_select(dev, rw, u.u_procp));
}
#endif
@@ -1030,6 +1052,14 @@ bpf_select(dev, rw, p)
splx(s);
return (1);
}
+
+ /*
+ * if there isn't data waiting, and there's a timeout,
+ * mark the time we started waiting.
+ */
+ if (d->bd_rtout != -1 && d->bd_rdStart == 0)
+ d->bd_rdStart = ticks;
+
#if BSD >= 199103
selrecord(p, &d->bd_sel);
#else
@@ -1183,12 +1213,13 @@ bpf_catchpacket(d, pkt, pktlen, snaplen, cpfn)
bpf_wakeup(d);
curlen = 0;
}
- else if (d->bd_immediate)
+ else if (d->bd_immediate) {
/*
* Immediate mode is set. A packet arrived so any
* reads should be woken up.
*/
bpf_wakeup(d);
+ }
/*
* Append the bpf header.
@@ -1208,6 +1239,20 @@ bpf_catchpacket(d, pkt, pktlen, snaplen, cpfn)
*/
(*cpfn)(pkt, (u_char *)hp + hdrlen, (hp->bh_caplen = totlen - hdrlen));
d->bd_slen = curlen + totlen;
+
+ if (d->bd_rdStart && (d->bd_rtout + d->bd_rdStart < ticks)) {
+ /*
+ * we could be selecting on the bpf, and we
+ * may have timeouts set. We got here by getting
+ * a packet, so wake up the reader.
+ */
+ if (d->bd_fbuf) {
+ d->bd_rdStart = 0;
+ ROTATE_BUFFERS(d);
+ bpf_wakeup(d);
+ curlen = 0;
+ }
+ }
}
/*
diff --git a/sys/net/bpf.h b/sys/net/bpf.h
index 0db69a51dd9..a6bfd36a2c1 100644
--- a/sys/net/bpf.h
+++ b/sys/net/bpf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.h,v 1.7 1998/06/10 23:57:09 provos Exp $ */
+/* $OpenBSD: bpf.h,v 1.8 1998/06/26 09:13:11 deraadt Exp $ */
/* $NetBSD: bpf.h,v 1.15 1996/12/13 07:57:33 mikel Exp $ */
/*
@@ -57,7 +57,7 @@ typedef u_int32_t bpf_u_int32;
#define BPF_WORDALIGN(x) (((x) + (BPF_ALIGNMENT - 1)) & ~(BPF_ALIGNMENT - 1))
#define BPF_MAXINSNS 512
-#define BPF_MAXBUFSIZE 0x8000
+#define BPF_MAXBUFSIZE 0x80000
#define BPF_MINBUFSIZE 32
/*
@@ -268,4 +268,7 @@ u_int bpf_filter __P((struct bpf_insn *, u_char *, u_int, u_int));
*/
#define BPF_MEMWORDS 16
+extern int ticks; /* from kern/kern_clock.c; incremented each */
+ /* clock tick. */
+
#endif /* _NET_BPF_H_ */
diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h
index bd5f50179a9..0494ed28cb5 100644
--- a/sys/net/bpfdesc.h
+++ b/sys/net/bpfdesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpfdesc.h,v 1.3 1997/08/31 20:42:30 deraadt Exp $ */
+/* $OpenBSD: bpfdesc.h,v 1.4 1998/06/26 09:13:13 deraadt Exp $ */
/* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */
/*
@@ -67,6 +67,7 @@ struct bpf_d {
struct bpf_if * bd_bif; /* interface descriptor */
u_long bd_rtout; /* Read timeout in 'ticks' */
+ u_long bd_rdStart; /* when the read started */
struct bpf_insn *bd_filter; /* filter code */
u_long bd_rcount; /* number of packets received */
u_long bd_dcount; /* number of packets dropped */