Project

General

Profile

Feature #197 ยป 0001-pcap-enable-zero-copy-mode-in-some-running-mode.patch

Eric Leblond, 06/14/2012 12:06 PM

View differences:

src/source-pcap.c
#include "util-optimize.h"
#include "util-checksum.h"
#include "tmqh-packetpool.h"
#include "runmodes.h"
extern uint8_t suricata_ctl_flags;
......
uint64_t bytes;
uint32_t errs;
int flags;
ThreadVars *tv;
TmSlot *slot;
......
(void) SC_ATOMIC_ADD(ptv->livedev->pkts, 1);
p->livedev = ptv->livedev;
if (unlikely(PacketCopyData(p, pkt, h->caplen))) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturn;
if (ptv->flags & PCAP_ZERO_COPY) {
if (unlikely(PacketSetData(p, pkt, h->caplen))) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturn;
}
} else {
if (unlikely(PacketCopyData(p, pkt, h->caplen))) {
TmqhOutputPacketpool(ptv->tv, p);
SCReturn;
}
}
switch (ptv->checksum_mode) {
......
}
#endif /* HAVE_PCAP_SET_BUFF */
char *active_runmode = RunmodeGetActive();
if (active_runmode &&
(!strcmp("workers", active_runmode)
||
!strcmp("single", active_runmode))) {
ptv->flags |= PCAP_ZERO_COPY;
SCLogInfo("Enabling zero copy mode");
}
/* activate the handle */
int pcap_activate_r = pcap_activate(ptv->pcap_handle);
//printf("ReceivePcapThreadInit: pcap_activate(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_activate_r);
src/source-pcap.h
#define LIBPCAP_COPYWAIT 500
#define LIBPCAP_PROMISC 1
#define PCAP_ZERO_COPY (1<<0)
/* per packet Pcap vars */
typedef struct PcapPacketVars_
{
    (1-1/1)