tcpdump mailing list archives
Libpcap reentrancy and PF_RING patch
From: Luca Deri <deri () ntop org>
Date: Sun, 30 Dec 2007 12:09:46 +0100
Dear all,please find enclosed a patch (against the code that's in CVS) that adds reentrancy in pcap.
IMHO libpcap has been designed for single-threaded applications, so when using threads it is necessary to add a mutex around pcap_next/ pcap_next_ex calls. According to some tests I have performed, the mutex (even when using spinlocks) is a real performance killer. In my patch I have added a new function called pcap_next_pkt defined as follows
const u_char * pcap_next_pkt(pcap_t *p, struct pcap_pkthdr *h, u_char *buf, u_short bufsize);
This function is the same as pcap_next with the difference that a buffer + buffersize is added. This allows libpcap not to use the shared buffer (e.g. allocated in pcap_open_xxx) so that replacing in applications calls of pcap_next with calls to pcap_next_pkt adds reentrancy without the need to use a mutex. Although this change is pretty simple, many files have been affected due to the way the library works and to the many different platforms that are supported. I have tested the code on Linux and OSX but patched all the supported platforms. I have decided not to change the behavior of other pcap functions (e.g. pcap_next, pcap_loop..) this to avoid compatibility issues with existing applications.
My patch also adds support for PF_RING (http://www.ntop.org/PF_RING.html ) that is a Linux packet acceleration technique that uses a shared ring buffer between the kernel and user-space. In addition to packet acceleration, it features also packet filtering and classification. As PF_RING code has been around for some years now and used by many users, if you include this patch into the mainstream code you will allow me to stop keeping a patched version of the library. As PF_RING is a kernel module, if the module is not present, the library will fallback to standard libpcap.
If you think my work is valuable, I would appreciate if you could include my contribution to the pcap library.
Thanks in advance, Luca
Attachment:
libpcap_reentrancy_pfring.diff.gz
Description:
- This is the tcpdump-workers list. Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- Libpcap reentrancy and PF_RING patch Luca Deri (Dec 30)
- Re: Libpcap reentrancy and PF_RING patch Gregor Maier (Dec 31)
- Re: Libpcap reentrancy and PF_RING patch Guy Harris (Dec 31)
- Re: Libpcap reentrancy and PF_RING patch Guy Harris (Dec 31)
- Re: Libpcap reentrancy and PF_RING patch Guy Harris (Dec 31)
- Re: Libpcap reentrancy and PF_RING patch Gregor Maier (Dec 31)