summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorart <art@openbsd.org>2003-04-01 23:42:24 +0000
committerart <art@openbsd.org>2003-04-01 23:42:24 +0000
commitd412d870e1d9770d99b2c7d9126a61c9b0b53493 (patch)
tree7a0e92dd42514e95129204a13694963299061232
parentuse PAGE_MASK instead of PAGE_SIZE-1 (diff)
downloadwireguard-openbsd-d412d870e1d9770d99b2c7d9126a61c9b0b53493.tar.xz
wireguard-openbsd-d412d870e1d9770d99b2c7d9126a61c9b0b53493.zip
When using bpf(4) in immediate mode, and using kevent(2) to receive
notification of packet arrival, the usermode application isn't notified until a second packet arrives. This is because KNOTE() calls filt_bpfread() before bd_slen has been updated with the newly arrived packet length, so it looks like there is no data there. Moving the bpf_wakeup() call for immediate mode to after bd_slen is set fixes it. From: wayne@epipe.com.au in pr 3175
-rw-r--r--sys/net/bpf.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 707609ad872..b502837083b 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.33 2002/06/06 21:34:16 provos Exp $ */
+/* $OpenBSD: bpf.c,v 1.34 2003/04/01 23:42:24 art Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -1163,13 +1163,6 @@ bpf_catchpacket(d, pkt, pktlen, snaplen, cpfn)
bpf_wakeup(d);
curlen = 0;
}
- 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.
@@ -1186,6 +1179,14 @@ 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_immediate) {
+ /*
+ * Immediate mode is set. A packet arrived so any
+ * reads should be woken up.
+ */
+ bpf_wakeup(d);
+ }
+
if (d->bd_rdStart && (d->bd_rtout + d->bd_rdStart < ticks)) {
/*
* we could be selecting on the bpf, and we