mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Prep work for IP changes
- Move all of the time handling code out of PktSrc into RunState - Call packet_mgr->ProcessPacket() from various places to setup layer 2 data in packets
This commit is contained in:
parent
5f1ee35d31
commit
69da2d7b1d
10 changed files with 108 additions and 104 deletions
|
@ -11,6 +11,7 @@
|
|||
#include "Sessions.h"
|
||||
#include "broker/Manager.h"
|
||||
#include "iosource/Manager.h"
|
||||
#include "packet_analysis/Manager.h"
|
||||
#include "BPF_Program.h"
|
||||
|
||||
#include "pcap/pcap.bif.h"
|
||||
|
@ -30,11 +31,6 @@ PktSrc::PktSrc()
|
|||
have_packet = false;
|
||||
errbuf = "";
|
||||
SetClosed(true);
|
||||
|
||||
next_sync_point = 0;
|
||||
first_timestamp = 0.0;
|
||||
current_pseudo = 0.0;
|
||||
first_wallclock = current_wallclock = 0;
|
||||
}
|
||||
|
||||
PktSrc::~PktSrc()
|
||||
|
@ -76,16 +72,12 @@ bool PktSrc::IsLive() const
|
|||
|
||||
double PktSrc::CurrentPacketTimestamp()
|
||||
{
|
||||
return current_pseudo;
|
||||
return run_state::current_packet_timestamp();
|
||||
}
|
||||
|
||||
double PktSrc::CurrentPacketWallClock()
|
||||
{
|
||||
// We stop time when we are suspended.
|
||||
if ( run_state::is_processing_suspended() )
|
||||
current_wallclock = util::current_time(true);
|
||||
|
||||
return current_wallclock;
|
||||
return run_state::current_packet_wallclock();
|
||||
}
|
||||
|
||||
void PktSrc::Opened(const Properties& arg_props)
|
||||
|
@ -151,25 +143,6 @@ void PktSrc::InternalError(const std::string& msg)
|
|||
reporter->InternalError("%s", msg.c_str());
|
||||
}
|
||||
|
||||
void PktSrc::ContinueAfterSuspend()
|
||||
{
|
||||
current_wallclock = util::current_time(true);
|
||||
}
|
||||
|
||||
double PktSrc::CheckPseudoTime()
|
||||
{
|
||||
if ( ! IsOpen() )
|
||||
return 0;
|
||||
|
||||
if ( ! ExtractNextPacketInternal() )
|
||||
return 0;
|
||||
|
||||
double pseudo_time = current_packet.time - first_timestamp;
|
||||
double ct = (util::current_time(true) - first_wallclock) * run_state::pseudo_realtime;
|
||||
|
||||
return pseudo_time <= ct ? run_state::zeek_start_time + pseudo_time : 0;
|
||||
}
|
||||
|
||||
void PktSrc::InitSource()
|
||||
{
|
||||
Open();
|
||||
|
@ -189,19 +162,22 @@ void PktSrc::Process()
|
|||
if ( ! ExtractNextPacketInternal() )
|
||||
return;
|
||||
|
||||
if ( current_packet.l2_valid )
|
||||
{
|
||||
if ( run_state::pseudo_realtime )
|
||||
{
|
||||
current_pseudo = CheckPseudoTime();
|
||||
run_state::detail::dispatch_packet(current_pseudo, ¤t_packet, this);
|
||||
if ( ! first_wallclock )
|
||||
first_wallclock = util::current_time(true);
|
||||
}
|
||||
// This is set here to avoid having to pass the packet source down into the processing
|
||||
// methods unnecessarily.
|
||||
run_state::detail::current_iosrc = this;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
run_state::detail::current_pktsrc = this;
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
else
|
||||
run_state::detail::dispatch_packet(current_packet.time, ¤t_packet, this);
|
||||
}
|
||||
packet_mgr->ProcessPacket(¤t_packet);
|
||||
run_state::detail::dispatch_packet(¤t_packet);
|
||||
|
||||
run_state::detail::current_iosrc = nullptr;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
run_state::detail::current_pktsrc = nullptr;
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
have_packet = false;
|
||||
DoneWithPacket();
|
||||
|
@ -221,11 +197,11 @@ bool PktSrc::ExtractNextPacketInternal()
|
|||
|
||||
// Don't return any packets if processing is suspended (except for the
|
||||
// very first packet which we need to set up times).
|
||||
if ( run_state::is_processing_suspended() && first_timestamp )
|
||||
if ( run_state::is_processing_suspended() && run_state::detail::first_timestamp )
|
||||
return false;
|
||||
|
||||
if ( run_state::pseudo_realtime )
|
||||
current_wallclock = util::current_time(true);
|
||||
run_state::detail::current_wallclock = util::current_time(true);
|
||||
|
||||
if ( ExtractNextPacket(¤t_packet) )
|
||||
{
|
||||
|
@ -235,8 +211,8 @@ bool PktSrc::ExtractNextPacketInternal()
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( ! first_timestamp )
|
||||
first_timestamp = current_packet.time;
|
||||
if ( ! run_state::detail::first_timestamp )
|
||||
run_state::detail::first_timestamp = current_packet.time;
|
||||
|
||||
have_packet = true;
|
||||
return true;
|
||||
|
@ -342,8 +318,9 @@ double PktSrc::GetNextTimeout()
|
|||
if ( ! have_packet )
|
||||
ExtractNextPacketInternal();
|
||||
|
||||
double pseudo_time = current_packet.time - first_timestamp;
|
||||
double ct = (util::current_time(true) - first_wallclock) * run_state::pseudo_realtime;
|
||||
// This duplicates the calculation used in run_state::check_pseudo_time().
|
||||
double pseudo_time = current_packet.time - run_state::detail::first_timestamp;
|
||||
double ct = (util::current_time(true) - run_state::detail::first_wallclock) * run_state::pseudo_realtime;
|
||||
return std::max(0.0, pseudo_time - ct);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue