Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Nov 2001 22:55:32 +1100
From:      Edwin Groothuis <edwin@mavetju.org>
To:        freebsd-hackers@freebsd.org
Subject:   pcap/bpf in a multi-threaded environment
Message-ID:  <20011109225532.A3919@k7.mavetju.org>

next in thread | raw e-mail | index | archive | help
Greetings,

The past couple of days I've been plagued by a strange behaviour
of something between libpcap and the bpf-device. As you can read
in PR bin/31649, the behaviour of libpcap is very different if you
compile it on gcc with or without -pthread:

Without -pthread, it calls the callback function everytime it has
received a packet.
With -pthread, it calls the callback function only when the
input-buffer (about 32Kb) is nearly full.

I've done some investigation (with my limited knowledge of what
happens between a call to read() and when it ends up in bpfread())
and saw the difference between a call with and without the -pthreads
option:

in /usr/src/contrib/libpcap/pcap-bpf.c, line 81, the function pcap_read():
		cc = read(p->fd, (char *)p->buffer, p->bufsize);

at a certain moment, in the read()-code, bpfread() is called:
/sys/net/bpf.c, line 491

In a non-threaded environment, this if-statement is false
                if (ioflag & IO_NDELAY) {
			splx(s);
			return (EWOULDBLOCK);
		}

In a threaded environment, the if-statement is true, splx(s) is
called and EWOULDBLOCK is returned. Then it's silent for a while,
while the packets are being collected (somewhere) and at a certain
moment the buffer is nearly full and the read() in pcap_read() is
finished.

So yeah, I'm stuck. All I want is in threaded mode to have the same
behaviour as I have in non-threaded mode. Anybody any ideas on how
to fix this?

Thanks in advance,
Edwin

-- 
Edwin Groothuis   |              Personal website: http://www.MavEtJu.org
edwin@mavetju.org |           Interested in MUDs? Visit Fatal Dimensions:
------------------+                       http://www.FatalDimensions.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011109225532.A3919>