Bug 28112

Summary: Packet capture does not work well with -pthead option.
Product: Base System Reporter: jl <jl>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-RELEASE   
Hardware: Any   
OS: Any   

Description jl 2001-06-13 03:00:02 UTC
When a program that uses pcap library is compiled with -pthread
option, the program rarely caputure packets. 

The problem started with 4.3-RELEASE.

How-To-Repeat: The problem occurs with any program that uses pcap library,
eg. trafshow.  Trafshow is in FreeBSD ports collection.

Compile trafshow with -pthread option and run it.
Comment 1 bem 2001-06-16 04:12:02 UTC
The problem is due to how pcap works. It is largely blocking based, and 
will return
packets as it gets them. PCAP was never intended to be multithreaded, 
and the read
of the bpf device will call sys_read() rather than the libc_r wrapper 
for read, so your
other threads will never be scheduled.

If you only want to read packets in 1 thread, and do other things in the 
other threads, compiling pcap with -pthread _may_ be acceptable, but I 
have not looked at the code
recently. As I recall, there was atleast _some_ static data, but as long 
as all the pcap
calls take place in a single thread, you should be ok. YMMV.
Comment 2 Bruce A. Mah freebsd_committer freebsd_triage 2001-11-17 18:54:39 UTC
State Changed
From-To: open->closed
Comment 3 Bruce A. Mah freebsd_committer freebsd_triage 2001-11-17 18:55:15 UTC
State Changed
From-To: closed->open

Closed by mistake.  BTW, I don't think the pcap library was intended 
to support threaded applications anyways...this could *probably* be 
closed.
Comment 4 ashp freebsd_committer freebsd_triage 2002-01-17 03:49:26 UTC
State Changed
From-To: open->suspended

Moved to suspended, based on bmah's comments.  This libary isn't intended 
to work in a threaded fashion.  This can be reopened if anyone has interest 
/intent to solve it.
Comment 5 edwin 2002-01-17 04:52:17 UTC
On Wed, Jan 16, 2002 at 07:50:03PM -0800, ashp@FreeBSD.org wrote:
> Synopsis: Packet capture does not work well with -pthead option.
> 
> State-Changed-From-To: open->suspended
> State-Changed-By: ashp
> State-Changed-When: Wed Jan 16 19:49:26 PST 2002
> State-Changed-Why: 
> Moved to suspended, based on bmah's comments.  This libary isn't intended
> to work in a threaded fashion.  This can be reopened if anyone has interest
> /intent to solve it.
> 
> http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28112

This can be closedi, patches are made and incorperated in -current
and 4.5

See also http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/31649 and
http://www.freebsd.org/cgi/query-pr.cgi?pr=22063

If the originator is interested I will have a look if I can find
the patches and send them to him. Note, they were for 4.4, not 4.3.

Edwin

-- 
Edwin Groothuis   |              Personal website: http://www.MavEtJu.org
edwin@mavetju.org |           Interested in MUDs? Visit Fatal Dimensions:
------------------+                       http://www.FatalDimensions.org/
Comment 6 Sheldon Hearn freebsd_committer freebsd_triage 2002-01-17 08:45:00 UTC
State Changed
From-To: suspended->closed

Closed as per bin/31649 and kern/22063. 

Thanks, Edwin!