Remove enabled state from Components, ability to enable/disable from Manager

This commit is contained in:
Tim Wojtulewicz 2020-07-16 08:40:46 -07:00
parent f39d6bb4c4
commit bd6d3e0112
6 changed files with 4 additions and 170 deletions

View file

@ -6,12 +6,11 @@
using namespace zeek::packet_analysis; using namespace zeek::packet_analysis;
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled) Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype)
: plugin::Component(plugin::component::PACKET_ANALYZER, name), : plugin::Component(plugin::component::PACKET_ANALYZER, name),
plugin::TaggedComponent<packet_analysis::Tag>(arg_subtype) plugin::TaggedComponent<packet_analysis::Tag>(arg_subtype)
{ {
factory = arg_factory; factory = arg_factory;
enabled = arg_enabled;
} }
void Component::Initialize() void Component::Initialize()
@ -26,8 +25,5 @@ void Component::DoDescribe(ODesc* d) const
{ {
d->Add("ANALYZER_"); d->Add("ANALYZER_");
d->Add(CanonicalName()); d->Add(CanonicalName());
d->Add(", ");
} }
d->Add(enabled ? "enabled" : "disabled");
} }

View file

@ -19,7 +19,7 @@ class Component : public plugin::Component,
public: public:
typedef AnalyzerPtr (*factory_callback)(); typedef AnalyzerPtr (*factory_callback)();
Component(const std::string& name, factory_callback factory, Tag::subtype_t subtype = 0, bool enabled = true); Component(const std::string& name, factory_callback factory, Tag::subtype_t subtype = 0);
~Component() override = default; ~Component() override = default;
/** /**
@ -34,20 +34,6 @@ public:
*/ */
factory_callback Factory() const { return factory; } factory_callback Factory() const { return factory; }
/**
* Returns true if the analyzer is currently enabled and hence
* available for use.
*/
bool Enabled() const { return enabled; }
/**
* Enables or disables this analyzer.
*
* @param arg_enabled True to enabled, false to disable.
*
*/
void SetEnabled(bool arg_enabled) { enabled = arg_enabled; }
protected: protected:
/** /**
* Overriden from plugin::Component. * Overriden from plugin::Component.
@ -56,7 +42,6 @@ protected:
private: private:
factory_callback factory; // The analyzer's factory callback. factory_callback factory; // The analyzer's factory callback.
bool enabled; // True if the analyzer is enabled.
}; };
} }

View file

@ -88,7 +88,7 @@ void Manager::DumpDebug()
DBG_LOG(DBG_PACKET_ANALYSIS, "Available packet analyzers after zeek_init():"); DBG_LOG(DBG_PACKET_ANALYSIS, "Available packet analyzers after zeek_init():");
for ( auto& current : GetComponents() ) for ( auto& current : GetComponents() )
{ {
DBG_LOG(DBG_PACKET_ANALYSIS, " %s (%s)", current->Name().c_str(), IsEnabled(current->Tag()) ? "enabled" : "disabled"); DBG_LOG(DBG_PACKET_ANALYSIS, " %s", current->Name().c_str());
} }
DBG_LOG(DBG_PACKET_ANALYSIS, "ProtocolAnalyzerSet FSM:"); DBG_LOG(DBG_PACKET_ANALYSIS, "ProtocolAnalyzerSet FSM:");
@ -100,87 +100,6 @@ void Manager::DumpDebug()
#endif #endif
} }
bool Manager::EnableAnalyzer(const Tag& tag)
{
if ( Component* p = Lookup(tag) )
{
DBG_LOG(DBG_PACKET_ANALYSIS, "Enabling analyzer %s", p->Name().c_str());
p->SetEnabled(true);
return true;
}
return false;
}
bool Manager::EnableAnalyzer(EnumVal* val)
{
if ( Component* p = Lookup(val) )
{
DBG_LOG(DBG_PACKET_ANALYSIS, "Enabling analyzer %s", p->Name().c_str());
p->SetEnabled(true);
return true;
}
return false;
}
bool Manager::DisableAnalyzer(const Tag& tag)
{
if ( Component* p = Lookup(tag) )
{
DBG_LOG(DBG_PACKET_ANALYSIS, "Disabling analyzer %s", p->Name().c_str());
p->SetEnabled(false);
return true;
}
return false;
}
bool Manager::DisableAnalyzer(EnumVal* val)
{
if ( Component* p = Lookup(val) )
{
DBG_LOG(DBG_PACKET_ANALYSIS, "Disabling analyzer %s", p->Name().c_str());
p->SetEnabled(false);
return true;
}
return false;
}
void Manager::DisableAllAnalyzers()
{
DBG_LOG(DBG_PACKET_ANALYSIS, "Disabling all analyzers");
std::list<Component*> all_analyzers = GetComponents();
for ( const auto& analyzer : all_analyzers )
analyzer->SetEnabled(false);
}
zeek::packet_analysis::Tag Manager::GetAnalyzerTag(const char* name)
{
return GetComponentTag(name);
}
bool Manager::IsEnabled(Tag tag)
{
if ( ! tag )
return false;
if ( Component* p = Lookup(tag) )
return p->Enabled();
return false;
}
bool Manager::IsEnabled(EnumVal* val)
{
if ( Component* p = Lookup(val) )
return p->Enabled();
return false;
}
AnalyzerPtr Manager::InstantiateAnalyzer(const Tag& tag) AnalyzerPtr Manager::InstantiateAnalyzer(const Tag& tag)
{ {
Component* c = Lookup(tag); Component* c = Lookup(tag);
@ -191,9 +110,6 @@ AnalyzerPtr Manager::InstantiateAnalyzer(const Tag& tag)
return nullptr; return nullptr;
} }
if ( ! c->Enabled() )
return nullptr;
if ( ! c->Factory() ) if ( ! c->Factory() )
{ {
reporter->InternalWarning("analyzer %s cannot be instantiated dynamically", GetComponentName(tag).c_str()); reporter->InternalWarning("analyzer %s cannot be instantiated dynamically", GetComponentName(tag).c_str());

View file

@ -50,53 +50,6 @@ public:
*/ */
void DumpDebug(); // Called after zeek_init() events. void DumpDebug(); // Called after zeek_init() events.
/**
* Enables an analyzer type. Only enabled analyzers will be
* instantiated for new connections.
*
* @param tag The analyzer's tag.
*
* @return True if successful.
*/
bool EnableAnalyzer(const Tag& tag);
/**
* Enables an analyzer type. Only enabled analyzers will be
* instantiated for new connections.
*
* @param tag The analyzer's tag as an enum of script type \c
* Analyzer::Tag.
*
* @return True if successful.
*/
bool EnableAnalyzer(EnumVal* tag);
/**
* Enables an analyzer type. Disabled analyzers will not be
* instantiated for new connections.
*
* @param tag The analyzer's tag.
*
* @return True if successful.
*/
bool DisableAnalyzer(const Tag& tag);
/**
* Disables an analyzer type. Disabled analyzers will not be
* instantiated for new connections.
*
* @param tag The analyzer's tag as an enum of script type \c
* Analyzer::Tag.
*
* @return True if successful.
*/
bool DisableAnalyzer(EnumVal* tag);
/**
* Disables all currently registered analyzers.
*/
void DisableAllAnalyzers();
/** /**
* Returns the tag associated with an analyer name, or the tag * Returns the tag associated with an analyer name, or the tag
* associated with an error if no such analyzer exists. * associated with an error if no such analyzer exists.
@ -105,21 +58,6 @@ public:
*/ */
Tag GetAnalyzerTag(const char* name); Tag GetAnalyzerTag(const char* name);
/**
* Returns true if an analyzer is enabled.
*
* @param tag The analyzer's tag.
*/
bool IsEnabled(Tag tag);
/**
* Returns true if an analyzer is enabled.
*
* @param tag The analyzer's tag as an enum of script type \c
* Analyzer::Tag.
*/
bool IsEnabled(EnumVal* tag);
/** /**
* Instantiates a new analyzer instance. * Instantiates a new analyzer instance.
* *

View file

@ -1,5 +1,5 @@
PacketDemo::Bar - A Bar packet analyzer. (dynamic, version 1.0.0) PacketDemo::Bar - A Bar packet analyzer. (dynamic, version 1.0.0)
[Packet Analyzer] Bar (ANALYZER_BAR, enabled) [Packet Analyzer] Bar (ANALYZER_BAR)
[Event] bar_message [Event] bar_message
=== ===

View file

@ -1,4 +1,3 @@
#include "Plugin.h" #include "Plugin.h"
#include "packet_analysis/Component.h" #include "packet_analysis/Component.h"