mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 05:58:20 +00:00
Allow setting packet and byte thresholds for connections.
This extends the ConnSize analyzer to be able to raise events when each direction of a connection crosses a certain amount of bytes or packets. Thresholds are set using set_conn_bytes_threshold(c$id, [num-bytes], [direction]); and set_conn_packets_threshold(c$id, [num-packets], [direction]); respectively. They raise the event event conn_bytes_threshold_crossed(c: connection, threshold: count, is_orig: bool) and event conn_packets_threshold_crossed(c: connection, threshold: count, is_orig: bool) respectively. Current thresholds can be examined using get_conn_bytes_threshold and get_conn_packets_threshold Currently only one threshold can be set per connection. This also fixes a bug where child packet analyzers of the TCP analyzer where not found using FindChild.
This commit is contained in:
parent
a129911272
commit
f7edf70882
10 changed files with 321 additions and 4 deletions
|
@ -29,6 +29,11 @@ void ConnSize_Analyzer::Init()
|
|||
orig_pkts = 0;
|
||||
resp_bytes = 0;
|
||||
resp_pkts = 0;
|
||||
|
||||
orig_bytes_thresh = 0;
|
||||
orig_pkts = 0;
|
||||
resp_bytes_thresh = 0;
|
||||
resp_pkts = 0;
|
||||
}
|
||||
|
||||
void ConnSize_Analyzer::Done()
|
||||
|
@ -36,6 +41,18 @@ void ConnSize_Analyzer::Done()
|
|||
Analyzer::Done();
|
||||
}
|
||||
|
||||
void ConnSize_Analyzer::ThresholdEvent(EventHandlerPtr f, uint64 threshold, bool is_orig)
|
||||
{
|
||||
if ( ! f )
|
||||
return;
|
||||
|
||||
val_list* vl = new val_list;
|
||||
vl->append(BuildConnVal());
|
||||
vl->append(new Val(threshold, TYPE_COUNT));
|
||||
vl->append(new Val(is_orig, TYPE_BOOL));
|
||||
ConnectionEvent(f, vl);
|
||||
}
|
||||
|
||||
void ConnSize_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, uint64 seq, const IP_Hdr* ip, int caplen)
|
||||
{
|
||||
Analyzer::DeliverPacket(len, data, is_orig, seq, ip, caplen);
|
||||
|
@ -44,11 +61,71 @@ void ConnSize_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig,
|
|||
{
|
||||
orig_bytes += ip->TotalLen();
|
||||
orig_pkts ++;
|
||||
|
||||
if ( orig_bytes_thresh && orig_bytes >= orig_bytes_thresh )
|
||||
{
|
||||
ThresholdEvent(conn_bytes_threshold_crossed, orig_bytes_thresh, is_orig);
|
||||
orig_bytes_thresh = 0;
|
||||
}
|
||||
|
||||
if ( orig_pkts_thresh && orig_pkts >= orig_pkts_thresh )
|
||||
{
|
||||
ThresholdEvent(conn_packets_threshold_crossed, orig_pkts_thresh, is_orig);
|
||||
orig_pkts_thresh = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
resp_bytes += ip->TotalLen();
|
||||
resp_pkts ++;
|
||||
|
||||
if ( resp_bytes_thresh && resp_bytes >= resp_bytes_thresh )
|
||||
{
|
||||
ThresholdEvent(conn_bytes_threshold_crossed, resp_bytes_thresh, is_orig);
|
||||
resp_bytes_thresh = 0;
|
||||
}
|
||||
|
||||
if ( resp_pkts_thresh && resp_pkts >= resp_pkts_thresh )
|
||||
{
|
||||
ThresholdEvent(conn_packets_threshold_crossed, resp_pkts_thresh, is_orig);
|
||||
resp_pkts_thresh = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnSize_Analyzer::SetThreshold(uint64 threshold, bool bytes, bool orig)
|
||||
{
|
||||
if ( bytes )
|
||||
{
|
||||
if ( orig )
|
||||
orig_bytes_thresh = threshold;
|
||||
else
|
||||
resp_bytes_thresh = threshold;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( orig )
|
||||
orig_pkts_thresh = threshold;
|
||||
else
|
||||
resp_pkts_thresh = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ConnSize_Analyzer::GetThreshold(bool bytes, bool orig)
|
||||
{
|
||||
if ( bytes )
|
||||
{
|
||||
if ( orig )
|
||||
return orig_bytes_thresh;
|
||||
else
|
||||
return resp_bytes_thresh;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( orig )
|
||||
return orig_pkts_thresh;
|
||||
else
|
||||
return resp_pkts_thresh;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue