Type and variable usage cleanup in Net.h

This commit is contained in:
Tim Wojtulewicz 2019-10-29 16:21:28 -07:00
parent fa9a568e8f
commit eee2abf729
2 changed files with 28 additions and 29 deletions

View file

@ -42,11 +42,11 @@ extern "C" {
extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
} }
iosource::PktDumper* pkt_dumper = 0; iosource::PktDumper* pkt_dumper = nullptr;
int reading_live = 0; bool reading_live = false;
int reading_traces = 0; bool reading_traces = false;
int have_pending_timers = 0; bool have_pending_timers = false;
double pseudo_realtime = 0.0; double pseudo_realtime = 0.0;
double network_time = 0.0; // time according to last packet timestamp double network_time = 0.0; // time according to last packet timestamp
// (or current time) // (or current time)
@ -57,11 +57,11 @@ double last_watchdog_proc_time = 0.0; // value of above during last watchdog
bool terminating = false; // whether we're done reading and finishing up bool terminating = false; // whether we're done reading and finishing up
bool is_parsing = false; bool is_parsing = false;
const Packet *current_pkt = 0; const Packet *current_pkt = nullptr;
int current_dispatched = 0; int current_dispatched = 0;
double current_timestamp = 0.0; double current_timestamp = 0.0;
iosource::PktSrc* current_pktsrc = 0; iosource::PktSrc* current_pktsrc = nullptr;
iosource::IOSource* current_iosrc = 0; iosource::IOSource* current_iosrc = nullptr;
std::list<ScannedFile> files_scanned; std::list<ScannedFile> files_scanned;
std::vector<string> sig_files; std::vector<string> sig_files;
@ -153,7 +153,7 @@ void net_init(const std::string& interface,
if ( ! pcap_input_file.empty() ) if ( ! pcap_input_file.empty() )
{ {
reading_live = pseudo_realtime > 0.0; reading_live = pseudo_realtime > 0.0;
reading_traces = 1; reading_traces = true;
iosource::PktSrc* ps = iosource_mgr->OpenPktSrc(pcap_input_file, false); iosource::PktSrc* ps = iosource_mgr->OpenPktSrc(pcap_input_file, false);
assert(ps); assert(ps);
@ -164,8 +164,8 @@ void net_init(const std::string& interface,
} }
else if ( ! interface.empty() ) else if ( ! interface.empty() )
{ {
reading_live = 1; reading_live = true;
reading_traces = 0; reading_traces = false;
iosource::PktSrc* ps = iosource_mgr->OpenPktSrc(interface, true); iosource::PktSrc* ps = iosource_mgr->OpenPktSrc(interface, true);
assert(ps); assert(ps);
@ -176,11 +176,11 @@ void net_init(const std::string& interface,
} }
else else
// have_pending_timers = 1, possibly. We don't set // have_pending_timers = true, possibly. We don't set
// that here, though, because at this point we don't know // that here, though, because at this point we don't know
// whether the user's zeek_init() event will indeed set // whether the user's zeek_init() event will indeed set
// a timer. // a timer.
reading_traces = reading_live = 0; reading_traces = reading_live = false;
if ( pcap_output_file ) if ( pcap_output_file )
{ {
@ -192,11 +192,10 @@ void net_init(const std::string& interface,
reporter->FatalError("problem opening dump file %s (%s)", reporter->FatalError("problem opening dump file %s (%s)",
writefile, pkt_dumper->ErrorMsg()); writefile, pkt_dumper->ErrorMsg());
ID* id = global_scope()->Lookup("trace_output_file"); if ( ID* id = global_scope()->Lookup("trace_output_file") )
if ( ! id )
reporter->Error("trace_output_file not defined in bro.init");
else
id->SetVal(new StringVal(writefile)); id->SetVal(new StringVal(writefile));
else
reporter->Error("trace_output_file not defined in bro.init");
} }
init_ip_addr_anonymizers(); init_ip_addr_anonymizers();
@ -239,7 +238,7 @@ void net_packet_dispatch(double t, const Packet* pkt, iosource::PktSrc* src_ps)
expire_timers(src_ps); expire_timers(src_ps);
SegmentProfiler* sp = 0; SegmentProfiler* sp = nullptr;
if ( load_sample ) if ( load_sample )
{ {
@ -266,13 +265,13 @@ void net_packet_dispatch(double t, const Packet* pkt, iosource::PktSrc* src_ps)
{ {
delete sp; delete sp;
delete sample_logger; delete sample_logger;
sample_logger = 0; sample_logger = nullptr;
} }
processing_start_time = 0.0; // = "we're not processing now" processing_start_time = 0.0; // = "we're not processing now"
current_dispatched = 0; current_dispatched = 0;
current_iosrc = 0; current_iosrc = nullptr;
current_pktsrc = 0; current_pktsrc = nullptr;
} }
void net_run() void net_run()
@ -299,20 +298,20 @@ void net_run()
loop_counter = 0; loop_counter = 0;
} }
#endif #endif
current_iosrc = src; current_iosrc = nullptr;
auto communication_enabled = broker_mgr->Active(); auto communication_enabled = broker_mgr->Active();
if ( src ) if ( src )
src->Process(); // which will call net_packet_dispatch() src->Process(); // which will call net_packet_dispatch()
else if ( reading_live && ! pseudo_realtime) else if ( reading_live && ! pseudo_realtime)
{ // live but no source is currently active {
double ct = current_time(); // live but no source is currently active
if ( ! net_is_processing_suspended() ) if ( ! net_is_processing_suspended() )
{ {
// Take advantage of the lull to get up to // Take advantage of the lull to get up to
// date on timers and events. // date on timers and events.
net_update_time(ct); net_update_time(current_time());
expire_timers(); expire_timers();
usleep(1); // Just yield. usleep(1); // Just yield.
} }
@ -353,7 +352,7 @@ void net_run()
processing_start_time = 0.0; // = "we're not processing now" processing_start_time = 0.0; // = "we're not processing now"
current_dispatched = 0; current_dispatched = 0;
current_iosrc = 0; current_iosrc = nullptr;
if ( signal_val == SIGTERM || signal_val == SIGINT ) if ( signal_val == SIGTERM || signal_val == SIGINT )
// We received a signal while processing the // We received a signal while processing the
@ -376,7 +375,7 @@ void net_run()
if ( ! have_active_packet_source ) if ( ! have_active_packet_source )
// Can turn off pseudo realtime now // Can turn off pseudo realtime now
pseudo_realtime = 0; pseudo_realtime = 0.0;
} }
} }

View file

@ -43,19 +43,19 @@ inline bool net_is_processing_suspended()
{ return _processing_suspended > 0; } { return _processing_suspended > 0; }
// Whether we're reading live traffic. // Whether we're reading live traffic.
extern int reading_live; extern bool reading_live;
// Same but for reading from traces instead. We have two separate // Same but for reading from traces instead. We have two separate
// variables because it's possible that neither is true, and we're // variables because it's possible that neither is true, and we're
// instead just running timers (per the variable after this one). // instead just running timers (per the variable after this one).
extern int reading_traces; extern bool reading_traces;
// True if we have timers scheduled for the future on which we need // True if we have timers scheduled for the future on which we need
// to wait. "Need to wait" here means that we're running live (though // to wait. "Need to wait" here means that we're running live (though
// perhaps not reading_live, but just running in real-time) as opposed // perhaps not reading_live, but just running in real-time) as opposed
// to reading a trace (in which case we don't want to wait in real-time // to reading a trace (in which case we don't want to wait in real-time
// on future timers). // on future timers).
extern int have_pending_timers; extern bool have_pending_timers;
// If > 0, we are reading from traces but trying to mimic real-time behavior. // If > 0, we are reading from traces but trying to mimic real-time behavior.
// (In this case, both reading_traces and reading_live are true.) The value // (In this case, both reading_traces and reading_live are true.) The value