From cejkar@fit.vutbr.cz  Thu Aug 11 22:27:34 2005
Return-Path: <cejkar@fit.vutbr.cz>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 6107316A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 11 Aug 2005 22:27:34 +0000 (GMT)
	(envelope-from cejkar@fit.vutbr.cz)
Received: from kazi.fit.vutbr.cz (kazi.fit.vutbr.cz [147.229.8.12])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2FF7B43D5A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 11 Aug 2005 22:27:32 +0000 (GMT)
	(envelope-from cejkar@fit.vutbr.cz)
Received: from kazi.fit.vutbr.cz (localhost [127.0.0.1])
	by kazi.fit.vutbr.cz (envelope-from cejkar@fit.vutbr.cz) (8.13.4/8.13.4) with ESMTP id j7BMRU1Z011907
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 12 Aug 2005 00:27:30 +0200 (CEST)
Received: (from cejkar@localhost)
	by kazi.fit.vutbr.cz (8.13.4/8.13.1/Submit) id j7BMRUPe011906;
	Fri, 12 Aug 2005 00:27:30 +0200 (CEST)
	(envelope-from cejkar)
Message-Id: <200508112227.j7BMRUPe011906@kazi.fit.vutbr.cz>
Date: Fri, 12 Aug 2005 00:27:30 +0200 (CEST)
From: Rudolf Cejka <cejkar@fit.vutbr.cz>
Reply-To: Rudolf Cejka <cejkar@fit.vutbr.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] bpf in non-blocking mode is broken
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         84823
>Category:       kern
>Synopsis:       [bpf] [patch] bpf in non-blocking mode is broken
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    csjp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 11 22:30:08 GMT 2005
>Closed-Date:    Wed Jun 21 16:06:00 GMT 2006
>Last-Modified:  Wed Jun 21 16:06:00 GMT 2006
>Originator:     Rudolf Cejka
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
FIT, Brno University of Technology, Czech Republic
>Environment:

  Any FreeBSD since Dec 17 2000 with sys/net/bpf.c >= 1.72.

>Description:

  When bpf is in non-blocking mode, it always returns EWOULDBLOCK - it
  never returns any data. The bpf is broken since following commit:

  : Revision 1.72, Sun Dec 17 20:50:22 2000 UTC (4 years, 7 months ago)
  :
  : Fix bug: a read() on a bpf device which was in non-blocking mode
  : and had no data available returned 0.  Now it returns -1 with errno
  : set to EWOULDBLOCK (== EAGAIN) as it should.  This fix makes the bpf
  : device usable in threaded programs.

>How-To-Repeat:
>Fix:

  Following patch should fix the problem:

--- sys/net/bpf.c.orig	Thu Aug 11 23:24:42 2005
+++ sys/net/bpf.c	Thu Aug 11 23:27:10 2005
@@ -489,8 +489,13 @@
 		}
 
 		if (ioflag & O_NONBLOCK) {
-			BPFD_UNLOCK(d);
-			return (EWOULDBLOCK);
+			if (d->bd_slen == 0) {
+				BPFD_UNLOCK(d);
+				return (EWOULDBLOCK);
+			} else {
+				ROTATE_BUFFERS(d);
+				break;
+			}
 		}
 		error = msleep(d, &d->bd_mtx, PRINET|PCATCH,
 		     "bpf", d->bd_rtout);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: csjp 
State-Changed-When: Fri Jun 16 02:15:36 UTC 2006 
State-Changed-Why:  
I will take care of this one. I've been discussing this with the submitter 
offline. Also, I have been doing a lot of BPF work lately. 


Responsible-Changed-From-To: freebsd-bugs->csjp 
Responsible-Changed-By: csjp 
Responsible-Changed-When: Fri Jun 16 02:15:36 UTC 2006 
Responsible-Changed-Why:  
I will take care of this one. I've been discussing this with the submitter 
offline. Also, I have been doing a lot of BPF work lately. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84823 
State-Changed-From-To: analyzed->closed 
State-Changed-By: csjp 
State-Changed-When: Wed Jun 21 16:04:11 UTC 2006 
State-Changed-Why:  
After having some dicussions with the submitter it has been 
decided that this actually isnt a bug, and things are working 
as their design intended. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84823 
>Unformatted:
