mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Fix PktSrc::Statistics returning bogus stats.
When reading from trace files, 'dropped' and 'link' fields are now just zeroed. When reading from an interface, the values filled in by pcap_stats() are now only used when that function indicates success. Closes #500.
This commit is contained in:
parent
c0c8b515f9
commit
d6d34f3a1f
3 changed files with 23 additions and 8 deletions
|
@ -393,21 +393,27 @@ void PktSrc::AddSecondaryTablePrograms()
|
|||
|
||||
void PktSrc::Statistics(Stats* s)
|
||||
{
|
||||
struct pcap_stat pstat;
|
||||
|
||||
if ( reading_traces )
|
||||
s->received = s->dropped = s->link = 0;
|
||||
|
||||
else if ( pcap_stats(pd, &pstat) < 0 )
|
||||
else
|
||||
{
|
||||
reporter->Error("problem getting packet filter statistics: %s",
|
||||
ErrorMsg());
|
||||
s->received = s->dropped = s->link = 0;
|
||||
struct pcap_stat pstat;
|
||||
if ( pcap_stats(pd, &pstat) < 0 )
|
||||
{
|
||||
reporter->Error("problem getting packet filter statistics: %s",
|
||||
ErrorMsg());
|
||||
s->received = s->dropped = s->link = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
s->dropped = pstat.ps_drop;
|
||||
s->link = pstat.ps_recv;
|
||||
}
|
||||
}
|
||||
|
||||
s->received = stats.received;
|
||||
s->dropped = pstat.ps_drop;
|
||||
s->link = pstat.ps_recv;
|
||||
|
||||
if ( pseudo_realtime )
|
||||
s->dropped = 0;
|
||||
|
|
1
testing/btest/Baseline/bifs.net_stats_trace/output
Normal file
1
testing/btest/Baseline/bifs.net_stats_trace/output
Normal file
|
@ -0,0 +1 @@
|
|||
[pkts_recvd=131, pkts_dropped=0, pkts_link=0]
|
8
testing/btest/bifs/net_stats_trace.test
Normal file
8
testing/btest/bifs/net_stats_trace.test
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Checks that accurate stats are returned when reading from a trace file.
|
||||
# @TEST-EXEC: bro -r $TRACES/wikipedia.trace >output %INPUT
|
||||
# @TEST-EXEC: btest-diff output
|
||||
|
||||
event bro_done()
|
||||
{
|
||||
print net_stats();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue