Allow libpcap buffer size to be set manually.

This commit is contained in:
Kris Nielander 2015-08-09 22:08:46 +02:00
parent 4c2aa804e1
commit f5429ee794
6 changed files with 62 additions and 2 deletions

View file

@ -3715,6 +3715,9 @@ module GLOBAL;
## Number of bytes per packet to capture from live interfaces. ## Number of bytes per packet to capture from live interfaces.
const snaplen = 8192 &redef; const snaplen = 8192 &redef;
## Number of bytes for libpcap buffer.
const bufsize = 128 &redef;
## Seed for hashes computed internally for probabilistic data structures. Using ## Seed for hashes computed internally for probabilistic data structures. Using
## the same value here will make the hashes compatible between independent Bro ## the same value here will make the hashes compatible between independent Bro
## instances. If left unset, Bro will use a temporary local seed. ## instances. If left unset, Bro will use a temporary local seed.

View file

@ -73,6 +73,9 @@ extern bool using_communication;
// Snaplen passed to libpcap. // Snaplen passed to libpcap.
extern int snaplen; extern int snaplen;
// Buffer size passed to libpcap.
extern int bufsize;
extern const Packet* current_pkt; extern const Packet* current_pkt;
extern int current_dispatched; extern int current_dispatched;
extern double current_timestamp; extern double current_timestamp;

View file

@ -71,6 +71,11 @@ int PktSrc::SnapLen() const
return snaplen; // That's a global. Change? return snaplen; // That's a global. Change?
} }
int PktSrc::BufSize() const
{
return bufsize; // That's a global too. Change?
}
bool PktSrc::IsLive() const bool PktSrc::IsLive() const
{ {
return props.is_live; return props.is_live;

View file

@ -100,6 +100,11 @@ public:
*/ */
int SnapLen() const; int SnapLen() const;
/**
* Returns the buffer size for this source.
*/
int BufSize() const;
/** /**
* In pseudo-realtime mode, returns the logical timestamp of the * In pseudo-realtime mode, returns the logical timestamp of the
* current packet. Undefined if not running pseudo-realtime mode. * current packet. Undefined if not running pseudo-realtime mode.

View file

@ -89,11 +89,53 @@ void PcapSource::OpenLive()
// broken on FreeBSD: even when select() indicates that we can read // broken on FreeBSD: even when select() indicates that we can read
// something, we may get nothing if the store buffer hasn't filled up // something, we may get nothing if the store buffer hasn't filled up
// yet.) // yet.)
pd = pcap_open_live(props.path.c_str(), SnapLen(), 1, 1, tmp_errbuf); pd = pcap_create(props.path.c_str(), errbuf);
if ( ! pd ) if ( ! pd )
{ {
Error(tmp_errbuf); safe_snprintf(errbuf, sizeof(errbuf),
"pcap_create: %s", pcap_geterr(pd));
Error(errbuf);
return;
}
if ( pcap_set_snaplen(pd, SnapLen()) )
{
safe_snprintf(errbuf, sizeof(errbuf),
"pcap_set_snaplen: %s", pcap_geterr(pd));
Error(errbuf);
return;
}
if ( pcap_set_promisc(pd, 1) )
{
safe_snprintf(errbuf, sizeof(errbuf),
"pcap_set_promisc: %s", pcap_geterr(pd));
Error(errbuf);
return;
}
if ( pcap_set_timeout(pd, 1) )
{
safe_snprintf(errbuf, sizeof(errbuf),
"pcap_set_timeout: %s", pcap_geterr(pd));
Error(errbuf);
return;
}
if ( pcap_set_buffer_size(pd, BufSize()) )
{
safe_snprintf(errbuf, sizeof(errbuf),
"pcap_set_buffer_size: %s", pcap_geterr(pd));
Error(errbuf);
return;
}
if ( pcap_activate(pd) )
{
safe_snprintf(errbuf, sizeof(errbuf),
"pcap_activate: %s", pcap_geterr(pd));
Error(errbuf);
return; return;
} }

View file

@ -122,6 +122,7 @@ vector<string> params;
set<string> requested_plugins; set<string> requested_plugins;
char* proc_status_file = 0; char* proc_status_file = 0;
int snaplen = 0; // this gets set from the scripting-layer's value int snaplen = 0; // this gets set from the scripting-layer's value
int bufsize = 0;
OpaqueType* md5_type = 0; OpaqueType* md5_type = 0;
OpaqueType* sha1_type = 0; OpaqueType* sha1_type = 0;
@ -990,6 +991,7 @@ int main(int argc, char** argv)
} }
snaplen = internal_val("snaplen")->AsCount(); snaplen = internal_val("snaplen")->AsCount();
bufsize = internal_val("bufsize")->AsCount() * 1024 * 1024; // Size in Mbytes
if ( dns_type != DNS_PRIME ) if ( dns_type != DNS_PRIME )
net_init(interfaces, read_files, writefile, do_watchdog); net_init(interfaces, read_files, writefile, do_watchdog);