tcpdump mailing list archives
Re: What's the correct new API to request pcap_linux to not open an eventfd
From: Bill Fenner via tcpdump-workers <tcpdump-workers () lists tcpdump org>
Date: Fri, 1 Jul 2022 13:55:30 -0400
--- Begin Message --- From: Bill Fenner <fenner () gmail com>
Date: Fri, 1 Jul 2022 13:55:30 -0400
On Fri, May 20, 2022 at 6:10 PM Bill Fenner <fenner () gmail com> wrote:On Fri, May 20, 2022 at 12:36 PM Guy Harris <gharris () sonic net> wrote:If it's putting them in non-blocking mode, and using some select/poll/epoll/etc. mechanism in a single event loop, then the right name for the API is pcap_setnonblock(). There's no need for an eventfd to wake up the blocking poll() if there *is* no blocking poll(), so: if non-blocking mode is on before pcap_activate() is called, no eventfd should be opened, and poll_breakloop_fd should be set to -1; if non-blocking mode is turned on after pcap_activate() is called, the eventfd should be closed, and poll_breakloop_fd should be set to -1; if non-blocking mode is turned *off* afterwards, an eventfd should be opened, and poll_breakloop_fd should be set to it; if poll_breakloop_fd is -1, the poll() should only wait on the socket FD; so this can be handled without API changes.Thank you for the excellent observation, Guy. It is indeed setting non-block before pcap_activate(). I'll work on this plan.A slight variation of this plan is at https://github.com/the-tcpdump-group/libpcap/pull/1113 I wrote a test program that doesn't do much, but does demonstrate that the blocking-ness API on Linux is at least a little weird. If we set pcap_nonblock after pcap_create and before pcap_activate, we get -3 - which I don't get at all, unless, -3 means "you didn't activate the pcap yet". My naive reading of the Linux pcap_getnonblock code says it'll return the integer value of a bool, and I don't know how that can be -3. The sequence ends up being: pcap_create() -> open eventfd pcap_setnonblock() -> close eventfd pcap_activate() I didn't want to move the eventfd creation out of pcap_create without having a deeper understanding of the strangeness around the nonblock API. I ran 15,645 internal Arista tests using these changes, in an infrastructure that relies on nonblocking pcap for packet exchange, and they all passed. Obviously this doesn't really say much about its general applicability, and kind of is a no-brainer "when you don't need the eventfd you don't notice if it's not there", but at least it says that things aren't drastically broken. Bill
--- End Message ---
_______________________________________________ tcpdump-workers mailing list tcpdump-workers () lists tcpdump org https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers
Current thread:
- Re: What's the correct new API to request pcap_linux to not open an eventfd Bill Fenner via tcpdump-workers (Jul 01)
- Re: What's the correct new API to request pcap_linux to not open an eventfd Denis Ovsienko via tcpdump-workers (Jul 05)
- Message not available
- Re: What's the correct new API to request pcap_linux to not open an eventfd Bill Fenner via tcpdump-workers (Jul 05)