kernel - Fix issue w/ buffer ortation when doing non-blocking read from bpf
authorMatthew Dillon <dillon@apollo.backplane.com>
Mon, 15 Feb 2010 17:32:27 +0000 (09:32 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Mon, 15 Feb 2010 17:32:27 +0000 (09:32 -0800)
* Non-blocking reads from a BPF device not in immediate mode would not
  rotate the buffers even if the was data in the store buffer, but not in
  the hold buffer.  So until the store buffer fills up, the reads would
  return -1 and set errno to EWOULDBLOCK.

Submitted-by: Guy Harris <guy@alum.mit.edu>
Taken-from: FreeBSD

sys/net/bpf.c

index a92c207..fc762d6 100644 (file)
@@ -421,9 +421,13 @@ bpfread(struct dev_read_args *ap)
         * have arrived to fill the store buffer.
         */
        while (d->bd_hbuf == NULL) {
-               if ((d->bd_immediate || timed_out) && d->bd_slen != 0) {
+               if ((d->bd_immediate || (ap->a_ioflag & IO_NDELAY) || timed_out)
+                   && d->bd_slen != 0) {
                        /*
-                        * A packet(s) either arrived since the previous
+                        * A packet(s) either arrived since the previous,
+                        * We're in immediate mode, or are reading
+                        * in non-blocking mode, and a packet(s)
+                        * either arrived since the previous
                         * read or arrived while we were asleep.
                         * Rotate the buffers and return what's here.
                         */