Merge remote-tracking branch 'origin/master' into topic/seth/radiotap

This commit is contained in:
Seth Hall 2016-01-18 12:17:07 -05:00
commit 7d5acfd8c8
128 changed files with 949 additions and 530 deletions

View file

@ -36,9 +36,7 @@ PktSrc::PktSrc()
PktSrc::~PktSrc()
{
BPF_Program* code;
IterCookie* cookie = filters.InitForIteration();
while ( (code = filters.NextEntry(cookie)) )
for ( auto code : filters )
delete code;
}
@ -335,16 +333,16 @@ bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter)
return 0;
}
// Store it in hash.
HashKey* hash = new HashKey(HashKey(bro_int_t(index)));
BPF_Program* oldcode = filters.Lookup(hash);
if ( oldcode )
delete oldcode;
// Store it in vector.
if ( index >= static_cast<int>(filters.size()) )
filters.resize(index + 1);
filters.Insert(hash, code);
delete hash;
if ( auto old = filters[index] )
delete old;
return 1;
filters[index] = code;
return true;
}
BPF_Program* PktSrc::GetBPFFilter(int index)
@ -352,10 +350,7 @@ BPF_Program* PktSrc::GetBPFFilter(int index)
if ( index < 0 )
return 0;
HashKey* hash = new HashKey(HashKey(bro_int_t(index)));
BPF_Program* code = filters.Lookup(hash);
delete hash;
return code;
return (static_cast<int>(filters.size()) > index ? filters[index] : 0);
}
bool PktSrc::ApplyBPFFilter(int index, const struct pcap_pkthdr *hdr, const u_char *pkt)

View file

@ -3,6 +3,8 @@
#ifndef IOSOURCE_PKTSRC_PKTSRC_H
#define IOSOURCE_PKTSRC_PKTSRC_H
#include <vector>
#include "IOSource.h"
#include "BPF_Program.h"
#include "Dict.h"
@ -362,7 +364,7 @@ private:
Packet current_packet;
// For BPF filtering support.
PDict(BPF_Program) filters;
std::vector<BPF_Program *> filters;
// Only set in pseudo-realtime mode.
double first_timestamp;

View file

@ -13,10 +13,6 @@
#include <pcap-int.h>
#endif
#ifdef HAVE_PACKET_FANOUT
#include <linux/if_packet.h>
#endif
using namespace iosource::pcap;
PcapSource::~PcapSource()
@ -156,24 +152,6 @@ void PcapSource::OpenLive()
// Was closed, couldn't get header size.
return;
#ifdef HAVE_PACKET_FANOUT
// Turn on cluster mode for the device.
if ( BifConst::Pcap::packet_fanout_enable )
{
uint32_t packet_fanout_arg = (PACKET_FANOUT_HASH << 16)
| (BifConst::Pcap::packet_fanout_id & 0xffff);
if ( BifConst::Pcap::packet_fanout_defrag )
packet_fanout_arg |= (PACKET_FANOUT_FLAG_DEFRAG << 16);
if ( setsockopt(props.selectable_fd, SOL_PACKET, PACKET_FANOUT, &packet_fanout_arg, sizeof(packet_fanout_arg)) == -1 )
{
Error(fmt("packet fanout: %s", strerror(errno)));
return;
}
}
#endif
props.is_live = true;
Opened(props);

View file

@ -2,8 +2,3 @@
const Pcap::snaplen: count;
const Pcap::bufsize: count;
const Pcap::packet_fanout_enable: bool;
const Pcap::packet_fanout_id: count;
const Pcap::packet_fanout_defrag: bool;

View file

@ -21,6 +21,15 @@ module Pcap;
## pcap_error
function precompile_pcap_filter%(id: PcapFilterID, s: string%): bool
%{
if ( id->AsEnum() >= 100 )
{
// We use a vector as underlying data structure for fast
// lookups and limit the ID space so that that doesn't grow too
// large.
builtin_error(fmt("PCAP filter ids must remain below 100 (is %ld)", id->AsInt()));
return new Val(false, TYPE_BOOL);
}
bool success = true;
const iosource::Manager::PktSrcList& pkt_srcs(iosource_mgr->GetPktSrcs());