~ubuntu-branches/ubuntu/saucy/suricata/saucy-proposed

« back to all changes in this revision

Viewing changes to src/source-pcap.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2013-05-21 12:42:45 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20130521124245-f083fzuw7z2w1db4
Tags: 1.4.1-1
* Imported Upstream version 1.4.1
* Install python control script (add dependency on python, and use
  dh_python2 for build)
* Bump Standards Version to 3.9.4
* Fix removal of pid file in init script (Closes: #700547)
  Thanks to Игорь Козинов <madvampik@gmail.com>.
* Add support for af-packet mode in init script (Closes: #697928).
  Thanks to Jamie Strandboge <jamie@ubuntu.com>.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "util-device.h"
40
40
#include "util-optimize.h"
41
41
#include "util-checksum.h"
 
42
#include "util-ioctl.h"
42
43
#include "tmqh-packetpool.h"
43
44
 
44
45
extern uint8_t suricata_ctl_flags;
82
83
 
83
84
    /* pcap buffer size */
84
85
    int pcap_buffer_size;
 
86
    int pcap_snaplen;
85
87
 
86
88
    ChecksumValidationMode checksum_mode;
87
89
 
181
183
    ptv->pcap_state = PCAP_STATE_DOWN;
182
184
    pcap_close(ptv->pcap_handle);
183
185
 
184
 
    ptv->pcap_handle = pcap_open_live((char *)ptv->iface, LIBPCAP_SNAPLEN,
 
186
    ptv->pcap_handle = pcap_open_live((char *)ptv->iface, ptv->pcap_snaplen,
185
187
            LIBPCAP_PROMISC, LIBPCAP_COPYWAIT, errbuf);
186
188
    if (ptv->pcap_handle == NULL) {
187
189
        SCLogError(SC_ERR_PCAP_OPEN_LIVE, "Problem creating pcap handler for live mode, error %s", errbuf);
399
401
        SCReturnInt(TM_ECODE_FAILED);
400
402
    }
401
403
 
402
 
    /* set Snaplen, Promisc, and Timeout. Must be called before pcap_activate */
403
 
    int pcap_set_snaplen_r = pcap_set_snaplen(ptv->pcap_handle,LIBPCAP_SNAPLEN);
404
 
    //printf("ReceivePcapThreadInit: pcap_set_snaplen(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_snaplen_r);
405
 
    if (pcap_set_snaplen_r != 0) {
406
 
        SCLogError(SC_ERR_PCAP_SET_SNAPLEN, "Couldn't set snaplen, error: %s", pcap_geterr(ptv->pcap_handle));
407
 
        SCFree(ptv);
408
 
        pcapconfig->DerefFunc(pcapconfig);
409
 
        SCReturnInt(TM_ECODE_FAILED);
 
404
    if (pcapconfig->snaplen == 0) {
 
405
        /* We set snaplen if we can get the MTU */
 
406
        ptv->pcap_snaplen = GetIfaceMTU(pcapconfig->iface);
 
407
    } else {
 
408
        ptv->pcap_snaplen = pcapconfig->snaplen;
 
409
    }
 
410
    if (ptv->pcap_snaplen > 0) {
 
411
        /* set Snaplen. Must be called before pcap_activate */
 
412
        int pcap_set_snaplen_r = pcap_set_snaplen(ptv->pcap_handle, ptv->pcap_snaplen);
 
413
        if (pcap_set_snaplen_r != 0) {
 
414
            SCLogError(SC_ERR_PCAP_SET_SNAPLEN, "Couldn't set snaplen, error: %s", pcap_geterr(ptv->pcap_handle));
 
415
            SCFree(ptv);
 
416
            pcapconfig->DerefFunc(pcapconfig);
 
417
            SCReturnInt(TM_ECODE_FAILED);
 
418
        }
 
419
        SCLogInfo("Set snaplen to %d for '%s'", ptv->pcap_snaplen,
 
420
                  pcapconfig->iface);
410
421
    }
411
422
 
412
 
    int pcap_set_promisc_r = pcap_set_promisc(ptv->pcap_handle,LIBPCAP_PROMISC);
 
423
    /* set Promisc, and Timeout. Must be called before pcap_activate */
 
424
    int pcap_set_promisc_r = pcap_set_promisc(ptv->pcap_handle, pcapconfig->promisc);
413
425
    //printf("ReceivePcapThreadInit: pcap_set_promisc(%p) returned %" PRId32 "\n", ptv->pcap_handle, pcap_set_promisc_r);
414
426
    if (pcap_set_promisc_r != 0) {
415
427
        SCLogError(SC_ERR_PCAP_SET_PROMISC, "Couldn't set promisc mode, error %s", pcap_geterr(ptv->pcap_handle));
536
548
    }
537
549
    strlcpy(ptv->iface, pcapconfig->iface, PCAP_IFACE_NAME_LENGTH);
538
550
 
 
551
    if (pcapconfig->snaplen == 0) {
 
552
        /* We try to set snaplen from MTU value */
 
553
        ptv->pcap_snaplen = GetIfaceMTU(pcapconfig->iface);
 
554
        /* be conservative with old pcap lib to mimic old tcpdump behavior
 
555
           when MTU was not available. */
 
556
        if (ptv->pcap_snaplen <= 0)
 
557
            ptv->pcap_snaplen = LIBPCAP_SNAPLEN;
 
558
    } else {
 
559
        ptv->pcap_snaplen = pcapconfig->snaplen;
 
560
    }
 
561
 
539
562
    char errbuf[PCAP_ERRBUF_SIZE] = "";
540
 
    ptv->pcap_handle = pcap_open_live(ptv->iface, LIBPCAP_SNAPLEN,
 
563
    ptv->pcap_handle = pcap_open_live(ptv->iface, ptv->pcap_snaplen,
541
564
                                        LIBPCAP_PROMISC, LIBPCAP_COPYWAIT, errbuf);
542
565
    if (ptv->pcap_handle == NULL) {
543
566
        SCLogError(SC_ERR_PCAP_OPEN_LIVE, "Problem creating pcap handler for live mode, error %s", errbuf);