Deprecate Connection::ConnectionEvent methods

And update usages to Connection::EnqueueEvent
This commit is contained in:
Jon Siwek 2020-03-25 16:08:32 -07:00
parent 6980f63a91
commit de47a50dde
6 changed files with 80 additions and 41 deletions

4
NEWS
View file

@ -55,6 +55,10 @@ Deprecated Functionality
- The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods - The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods
are now deprecated, use ``EventMgr::Enqueue()`` instead. are now deprecated, use ``EventMgr::Enqueue()`` instead.
- The ``Connection::ConnectionEvent()`` and
``Connection::ConnectionEventFast()`` methods are now deprecated, use
``Connection::EnqueueEvent()`` instead.
Zeek 3.1.0 Zeek 3.1.0
========== ==========

View file

@ -203,7 +203,7 @@ void Connection::NextPacket(double t, int is_orig,
is_successful = true; is_successful = true;
if ( ! was_successful && is_successful && connection_successful ) if ( ! was_successful && is_successful && connection_successful )
ConnectionEventFast(connection_successful, nullptr, {BuildConnVal()}); EnqueueEvent(connection_successful, nullptr, IntrusivePtr{AdoptRef{}, BuildConnVal()});
} }
else else
last_time = t; last_time = t;
@ -259,11 +259,11 @@ void Connection::HistoryThresholdEvent(EventHandlerPtr e, bool is_orig,
// and at this stage it's not a *multiple* instance. // and at this stage it's not a *multiple* instance.
return; return;
ConnectionEventFast(e, 0, { EnqueueEvent(e, nullptr,
BuildConnVal(), IntrusivePtr{AdoptRef{}, BuildConnVal()},
val_mgr->GetBool(is_orig), IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)},
val_mgr->GetCount(threshold) IntrusivePtr{AdoptRef{}, val_mgr->GetCount(threshold)}
}); );
} }
void Connection::DeleteTimer(double /* t */) void Connection::DeleteTimer(double /* t */)
@ -323,7 +323,7 @@ void Connection::EnableStatusUpdateTimer()
void Connection::StatusUpdateTimer(double t) void Connection::StatusUpdateTimer(double t)
{ {
ConnectionEventFast(connection_status_update, 0, { BuildConnVal() }); EnqueueEvent(connection_status_update, nullptr, IntrusivePtr{AdoptRef{}, BuildConnVal()});
ADD_TIMER(&Connection::StatusUpdateTimer, ADD_TIMER(&Connection::StatusUpdateTimer,
network_time + connection_status_update_interval, 0, network_time + connection_status_update_interval, 0,
TIMER_CONN_STATUS_UPDATE); TIMER_CONN_STATUS_UPDATE);
@ -446,15 +446,13 @@ void Connection::Match(Rule::PatternType type, const u_char* data, int len, bool
void Connection::RemovalEvent() void Connection::RemovalEvent()
{ {
auto cv = BuildConnVal(); auto cv = IntrusivePtr{AdoptRef{}, BuildConnVal()};
if ( connection_state_remove ) if ( connection_state_remove )
ConnectionEventFast(connection_state_remove, nullptr, {cv->Ref()}); EnqueueEvent(connection_state_remove, nullptr, cv);
if ( is_successful && successful_connection_remove ) if ( is_successful && successful_connection_remove )
ConnectionEventFast(successful_connection_remove, nullptr, {cv->Ref()}); EnqueueEvent(successful_connection_remove, nullptr, cv);
Unref(cv);
} }
void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const char* name) void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const char* name)
@ -463,10 +461,9 @@ void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const ch
return; return;
if ( name ) if ( name )
ConnectionEventFast(f, analyzer, {new StringVal(name), BuildConnVal()}); EnqueueEvent(f, analyzer, make_intrusive<StringVal>(name), IntrusivePtr{AdoptRef{}, BuildConnVal()});
else else
ConnectionEventFast(f, analyzer, {BuildConnVal()}); EnqueueEvent(f, analyzer, IntrusivePtr{AdoptRef{}, BuildConnVal()});
} }
void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1, Val* v2) void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1, Val* v2)
@ -479,25 +476,27 @@ void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1,
} }
if ( v2 ) if ( v2 )
ConnectionEventFast(f, analyzer, {BuildConnVal(), v1, v2}); EnqueueEvent(f, analyzer,
IntrusivePtr{AdoptRef{}, BuildConnVal()},
IntrusivePtr{AdoptRef{}, v1},
IntrusivePtr{AdoptRef{}, v2});
else else
ConnectionEventFast(f, analyzer, {BuildConnVal(), v1}); EnqueueEvent(f, analyzer,
IntrusivePtr{AdoptRef{}, BuildConnVal()},
IntrusivePtr{AdoptRef{}, v1});
} }
void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list vl) void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list vl)
{ {
auto args = zeek::val_list_to_args(&vl);
if ( ! f ) if ( ! f )
{
// This may actually happen if there is no local handler // This may actually happen if there is no local handler
// and a previously existing remote handler went away. // and a previously existing remote handler went away.
for ( const auto& v : vl)
Unref(v);
return; return;
}
// "this" is passed as a cookie for the event // "this" is passed as a cookie for the event
mgr.Enqueue(f, zeek::val_list_to_args(&vl), SOURCE_LOCAL, mgr.Enqueue(f, std::move(args), SOURCE_LOCAL,
a ? a->GetID() : 0, timer_mgr, this); a ? a->GetID() : 0, timer_mgr, this);
} }
@ -510,12 +509,15 @@ void Connection::ConnectionEventFast(EventHandlerPtr f, analyzer::Analyzer* a, v
void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list* vl) void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list* vl)
{ {
ConnectionEvent(f, a, std::move(*vl)); auto args = zeek::val_list_to_args(vl);
delete vl; delete vl;
if ( f )
EnqueueEvent(f, a, std::move(args));
} }
void Connection::EnqueueEvent(EventHandlerPtr f, zeek::Args args, void Connection::EnqueueEvent(EventHandlerPtr f, analyzer::Analyzer* a,
analyzer::Analyzer* a) zeek::Args args)
{ {
// "this" is passed as a cookie for the event // "this" is passed as a cookie for the event
mgr.Enqueue(f, std::move(args), SOURCE_LOCAL, a ? a->GetID() : 0, mgr.Enqueue(f, std::move(args), SOURCE_LOCAL, a ? a->GetID() : 0,
@ -696,12 +698,12 @@ void Connection::CheckFlowLabel(bool is_orig, uint32_t flow_label)
if ( connection_flow_label_changed && if ( connection_flow_label_changed &&
(is_orig ? saw_first_orig_packet : saw_first_resp_packet) ) (is_orig ? saw_first_orig_packet : saw_first_resp_packet) )
{ {
ConnectionEventFast(connection_flow_label_changed, 0, { EnqueueEvent(connection_flow_label_changed, 0,
BuildConnVal(), IntrusivePtr{AdoptRef{}, BuildConnVal()},
val_mgr->GetBool(is_orig), IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)},
val_mgr->GetCount(my_flow_label), IntrusivePtr{AdoptRef{}, val_mgr->GetCount(my_flow_label)},
val_mgr->GetCount(flow_label), IntrusivePtr{AdoptRef{}, val_mgr->GetCount(flow_label)}
}); );
} }
my_flow_label = flow_label; my_flow_label = flow_label;

View file

@ -5,6 +5,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <string> #include <string>
#include <tuple>
#include <type_traits>
#include "Dict.h" #include "Dict.h"
#include "Timer.h" #include "Timer.h"
@ -188,7 +190,7 @@ public:
// If a handler exists for 'f', an event will be generated. In any case, // If a handler exists for 'f', an event will be generated. In any case,
// reference count for each element in the 'vl' list are decremented. The // reference count for each element in the 'vl' list are decremented. The
// arguments used for the event are whatevever is provided in 'vl'. // arguments used for the event are whatevever is provided in 'vl'.
// TODO: deprecate [[deprecated("Remove in v4.1. Use EnqueueEvent() instead.")]]
void ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* analyzer, void ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* analyzer,
val_list vl); val_list vl);
@ -196,7 +198,7 @@ public:
// pointer instead of by value. This function takes ownership of the // pointer instead of by value. This function takes ownership of the
// memory pointed to by 'vl' and also for decrementing the reference count // memory pointed to by 'vl' and also for decrementing the reference count
// of each of its elements. // of each of its elements.
// TODO: deprecate [[deprecated("Remove in v4.1. Use EnqueueEvent() instead.")]]
void ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* analyzer, void ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* analyzer,
val_list* vl); val_list* vl);
@ -208,15 +210,25 @@ public:
// the case where there's no handlers (one usually also does that because // the case where there's no handlers (one usually also does that because
// it would be a waste of effort to construct all the event arguments when // it would be a waste of effort to construct all the event arguments when
// there's no handlers to consume them). // there's no handlers to consume them).
// TODO: deprecate [[deprecated("Remove in v4.1. Use EnqueueEvent() instead.")]]
void ConnectionEventFast(EventHandlerPtr f, analyzer::Analyzer* analyzer, void ConnectionEventFast(EventHandlerPtr f, analyzer::Analyzer* analyzer,
val_list vl); val_list vl);
/** /**
* Enqueues an event associated with this connection and given analyzer. * Enqueues an event associated with this connection and given analyzer.
*/ */
void EnqueueEvent(EventHandlerPtr f, zeek::Args args, void EnqueueEvent(EventHandlerPtr f, analyzer::Analyzer* analyzer,
analyzer::Analyzer* analyzer = nullptr); zeek::Args args);
/**
* A version of EnqueueEvent() taking a variable number of arguments.
*/
template <class... Args>
std::enable_if_t<
std::is_convertible_v<
std::tuple_element_t<0, std::tuple<Args...>>, IntrusivePtr<Val>>>
EnqueueEvent(EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args)
{ return EnqueueEvent(h, analyzer, zeek::Args{std::forward<Args>(args)...}); }
void Weird(const char* name, const char* addl = ""); void Weird(const char* name, const char* addl = "");
bool DidWeird() const { return weird != 0; } bool DidWeird() const { return weird != 0; }

View file

@ -499,7 +499,7 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out,
vl.emplace_back(AdoptRef{}, v); vl.emplace_back(AdoptRef{}, v);
if ( conn ) if ( conn )
conn->EnqueueEvent(event, std::move(vl)); conn->EnqueueEvent(event, nullptr, std::move(vl));
else else
mgr.Enqueue(event, std::move(vl)); mgr.Enqueue(event, std::move(vl));
} }

View file

@ -803,17 +803,29 @@ void Analyzer::Event(EventHandlerPtr f, Val* v1, Val* v2)
void Analyzer::ConnectionEvent(EventHandlerPtr f, val_list* vl) void Analyzer::ConnectionEvent(EventHandlerPtr f, val_list* vl)
{ {
conn->ConnectionEvent(f, this, vl); auto args = zeek::val_list_to_args(vl);
if ( f )
conn->EnqueueEvent(f, this, std::move(args));
} }
void Analyzer::ConnectionEvent(EventHandlerPtr f, val_list vl) void Analyzer::ConnectionEvent(EventHandlerPtr f, val_list vl)
{ {
conn->ConnectionEvent(f, this, std::move(vl)); auto args = zeek::val_list_to_args(&vl);
if ( f )
conn->EnqueueEvent(f, this, std::move(args));
} }
void Analyzer::ConnectionEventFast(EventHandlerPtr f, val_list vl) void Analyzer::ConnectionEventFast(EventHandlerPtr f, val_list vl)
{ {
conn->ConnectionEventFast(f, this, std::move(vl)); auto args = zeek::val_list_to_args(&vl);
conn->EnqueueEvent(f, this, std::move(args));
}
void Analyzer::EnqueueConnEvent(EventHandlerPtr f, zeek::Args args)
{
conn->EnqueueEvent(f, this, std::move(args));
} }
void Analyzer::Weird(const char* name, const char* addl) void Analyzer::Weird(const char* name, const char* addl)

View file

@ -567,20 +567,29 @@ public:
* Convenience function that forwards directly to * Convenience function that forwards directly to
* Connection::ConnectionEvent(). * Connection::ConnectionEvent().
*/ */
// TODO: deprecate
void ConnectionEvent(EventHandlerPtr f, val_list* vl); void ConnectionEvent(EventHandlerPtr f, val_list* vl);
/** /**
* Convenience function that forwards directly to * Convenience function that forwards directly to
* Connection::ConnectionEvent(). * Connection::ConnectionEvent().
*/ */
// TODO: deprecate
void ConnectionEvent(EventHandlerPtr f, val_list vl); void ConnectionEvent(EventHandlerPtr f, val_list vl);
/** /**
* Convenience function that forwards directly to * Convenience function that forwards directly to
* Connection::ConnectionEventFast(). * Connection::ConnectionEventFast().
*/ */
// TODO: deprecate
void ConnectionEventFast(EventHandlerPtr f, val_list vl); void ConnectionEventFast(EventHandlerPtr f, val_list vl);
/**
* Convenience function that forwards directly to
* Connection::EnqueueEvent().
*/
void EnqueueConnEvent(EventHandlerPtr f, zeek::Args args);
/** /**
* Convenience function that forwards directly to the corresponding * Convenience function that forwards directly to the corresponding
* Connection::Weird(). * Connection::Weird().