Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

kernel/3175: bpf(4) in immediate mode fails to wakeup kevent(2) listeners on first packet

From: <wayne(at)epipe.com.au>
Date: Sat Mar 29 2003 - 23:36:15 EST


>Number: 3175
>Category: kernel
>Synopsis: bpf(4) in immediate mode fails to wakeup kevent(2) listeners on first packet
>Confidential: yes
net
>Environment:

	System      : OpenBSD 3.3
	Architecture: OpenBSD.i386
	Machine     : i386

>Description:
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.
>How-To-Repeat:
Use kevent(2) on bpf in immediate mode.

>Fix:

Index: sys/net/bpf.c



RCS file: /cvs/src/sys/net/bpf.c,v
retrieving revision 1.33
diff -u -r1.33 bpf.c
--- sys/net/bpf.c	2002/06/06 21:34:16	1.33
+++ sys/net/bpf.c	2003/03/30 04:22:39
@@ -1163,13 +1163,6 @@
 		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.
@@ -1185,6 +1178,14 @@
 	 */
 	(*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)) {
 		/*

>Release-Note:
Received on Sat Mar 29 23:54:52 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:52 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library