tcpdump mailing list archives

Re: pcap_t not writeable on OpenBSD


From: Fernando Gont <fernando () gont com ar>
Date: Tue, 10 Jan 2012 20:15:22 -0300

On 01/10/2012 07:57 PM, Guy Harris wrote:

I'm doing I/O multiplexing with the pcap descriptor, and it turns
out that on OpenBSD the underlying descriptor for a pcap_t is never
writeable.

I presume from "I'm doing I/O multiplexing" that by "writeable"
you're referring to "writeable" as in "a select() or poll() 

Yes.


For injection, on linux anyhow, a PF_PACKET device is always 
writeable, but I'm pretty sure it discards packets if you write
too fast.

the OpenBSD bpfwrite() routine does not appear to block for any "no
room to buffer the packet" reason (it just calls the interface's
if_output routine to send the packet, and I think that routine is
supposed to fail, not block, if there's no buffering space available
in the driver), and the FreeBSD one behaves the same.

So... what would be the portable way to make sure that pcap_inject() or
the like do not block, but also do not discard packets because of my app
sending "too fast"?


So:

it appears that on all of the BSD-flavored platforms there's nothing
to multiplex on the output side - the service offered when sending
raw packets is a "best effort" service with no guarantee that the
packet will even make it onto the wire (which is pretty much what you
get with, for example, Ethernet in any case);

I would expect that if there are no buffers available, pcap_inject() or
blocks, rather than silently fail. (i.e., how do I control the rate at
which I'm sending? how do I know if I should be retransmitting? etc.)



on most platforms select() will always say "you can write", with
OpenBSD as an exception and DragonFly BSD as another possible
exception - poll() might be the same except that it might also fail
on Mac OS X, and kqueues will probably fail with an error on all
platforms if you try to create a EVFILT_WRITE kevent for a BPF
device.

Thanks *so* *much* for your help and analysis. I really appreciate it.

I will post to the relevant OpenBSD list, to hear what they have to say...

Thanks!

Best regards,
-- 
Fernando Gont
e-mail: fernando () gont com ar || fgont () si6networks com
PGP Fingerprint: 7809 84F5 322E 45C7 F1C9 3945 96EE A9EF D076 FFF1



-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: