Project

General

Profile

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
46 46
#include "util-optimize.h"
47 47
#include "util-checksum.h"
48 48
#include "tmqh-packetpool.h"
49
#include "runmodes.h"
49 50

  
50 51
extern uint8_t suricata_ctl_flags;
51 52

  
......
76 77
    uint64_t bytes;
77 78
    uint32_t errs;
78 79

  
80
    int flags;
81

  
79 82
    ThreadVars *tv;
80 83
    TmSlot *slot;
81 84

  
......
219 222
    (void) SC_ATOMIC_ADD(ptv->livedev->pkts, 1);
220 223
    p->livedev = ptv->livedev;
221 224

  
222
    if (unlikely(PacketCopyData(p, pkt, h->caplen))) {
223
        TmqhOutputPacketpool(ptv->tv, p);
224
        SCReturn;
225
    if (ptv->flags & PCAP_ZERO_COPY) {
226
        if (unlikely(PacketSetData(p, pkt, h->caplen))) {
227
            TmqhOutputPacketpool(ptv->tv, p);
228
            SCReturn;
229
        }
230
    } else {
231
        if (unlikely(PacketCopyData(p, pkt, h->caplen))) {
232
            TmqhOutputPacketpool(ptv->tv, p);
233
            SCReturn;
234
        }
225 235
    }
226 236

  
227 237
    switch (ptv->checksum_mode) {
......
418 428
    }
419 429
#endif /* HAVE_PCAP_SET_BUFF */
420 430

  
431
    char *active_runmode = RunmodeGetActive();
432

  
433
    if (active_runmode &&
434
            (!strcmp("workers", active_runmode)
435
             ||
436
             !strcmp("single", active_runmode))) {
437
        ptv->flags |= PCAP_ZERO_COPY;
438
        SCLogInfo("Enabling zero copy mode");
439
    }
440

  
421 441
    /* activate the handle */
422 442
    int pcap_activate_r = pcap_activate(ptv->pcap_handle);
423 443
    //printf("ReceivePcapThreadInit: pcap_activate(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_activate_r);
src/source-pcap.h
37 37
#define LIBPCAP_COPYWAIT    500
38 38
#define LIBPCAP_PROMISC     1
39 39

  
40
#define PCAP_ZERO_COPY (1<<0)
41

  
40 42
/* per packet Pcap vars */
41 43
typedef struct PcapPacketVars_
42 44
{
43
-