mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Move enabled/disabled functionality from analyzers into Component
base class API.
The different analyzers types all had their own methods for enabling/disabling their availability. This change abstracts that into a new API inside their base class (`plugin::Component`) so that they can be toggled in a unified way. In principle, other types of components could/should use this as well now, so that, e.g., an input reader's availability could be toggled at runtime. The code doesn't make that broader change for now because it would requires a series of changes wherever these other component types are being used. However, that means that one now could try toggling some other component through the new API without that having any effect. To catch that, there's a runtime check in place that turns any such attempt into an internal error.
This commit is contained in:
parent
d7e30d9ee2
commit
ac1a7508ee
8 changed files with 50 additions and 55 deletions
|
@ -13,8 +13,8 @@ Component::Component(const std::string& name, factory_callback arg_factory, zeek
|
||||||
: plugin::Component(arg_adapter ? plugin::component::SESSION_ADAPTER : plugin::component::ANALYZER, name,
|
: plugin::Component(arg_adapter ? plugin::component::SESSION_ADAPTER : plugin::component::ANALYZER, name,
|
||||||
arg_subtype, analyzer_mgr->GetTagType()) {
|
arg_subtype, analyzer_mgr->GetTagType()) {
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
enabled = arg_enabled;
|
|
||||||
partial = arg_partial;
|
partial = arg_partial;
|
||||||
|
SetEnabled(arg_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::Initialize() {
|
void Component::Initialize() {
|
||||||
|
@ -29,7 +29,7 @@ void Component::DoDescribe(ODesc* d) const {
|
||||||
d->Add(", ");
|
d->Add(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
d->Add(enabled ? "enabled" : "disabled");
|
d->Add(Enabled() ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace zeek::analyzer
|
} // namespace zeek::analyzer
|
||||||
|
|
|
@ -85,20 +85,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool Partial() const { return partial; }
|
bool Partial() const { return partial; }
|
||||||
|
|
||||||
/**
|
|
||||||
* 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:
|
||||||
/**
|
/**
|
||||||
* Overridden from plugin::Component.
|
* Overridden from plugin::Component.
|
||||||
|
@ -108,7 +94,6 @@ protected:
|
||||||
private:
|
private:
|
||||||
factory_callback factory; // The analyzer's factory callback.
|
factory_callback factory; // The analyzer's factory callback.
|
||||||
bool partial; // True if the analyzer supports partial connections.
|
bool partial; // True if the analyzer supports partial connections.
|
||||||
bool enabled; // True if the analyzer is enabled.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace analyzer
|
} // namespace analyzer
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace zeek::file_analysis {
|
||||||
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype, bool arg_enabled)
|
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype, bool arg_enabled)
|
||||||
: plugin::Component(plugin::component::FILE_ANALYZER, name, subtype, file_mgr->GetTagType()) {
|
: plugin::Component(plugin::component::FILE_ANALYZER, name, subtype, file_mgr->GetTagType()) {
|
||||||
factory_func = arg_factory;
|
factory_func = arg_factory;
|
||||||
enabled = arg_enabled;
|
SetEnabled(arg_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::Initialize() {
|
void Component::Initialize() {
|
||||||
|
@ -26,7 +26,7 @@ void Component::DoDescribe(ODesc* d) const {
|
||||||
d->Add(", ");
|
d->Add(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
d->Add(enabled ? "enabled" : "disabled");
|
d->Add(Enabled() ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace zeek::file_analysis
|
} // namespace zeek::file_analysis
|
||||||
|
|
|
@ -70,20 +70,6 @@ public:
|
||||||
*/
|
*/
|
||||||
factory_function FactoryFunction() const { return factory_func; }
|
factory_function FactoryFunction() const { return factory_func; }
|
||||||
|
|
||||||
/**
|
|
||||||
* 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:
|
||||||
/**
|
/**
|
||||||
* Overridden from plugin::Component.
|
* Overridden from plugin::Component.
|
||||||
|
@ -94,7 +80,6 @@ private:
|
||||||
friend class Manager;
|
friend class Manager;
|
||||||
|
|
||||||
factory_function factory_func; // The analyzer's factory callback.
|
factory_function factory_func; // The analyzer's factory callback.
|
||||||
bool enabled; // True if the analyzer is enabled.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace file_analysis
|
} // namespace file_analysis
|
||||||
|
|
|
@ -18,11 +18,11 @@ void Component::Initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::SetEnabled(bool arg_enabled) {
|
void Component::SetEnabled(bool arg_enabled) {
|
||||||
enabled = arg_enabled;
|
plugin::Component::SetEnabled(arg_enabled);
|
||||||
|
|
||||||
// If we already have instantiated an analyzer, update its state.
|
// If we already have instantiated an analyzer, update its state.
|
||||||
if ( auto analyzer = packet_mgr->GetAnalyzer(Tag().AsVal().get()) )
|
if ( auto analyzer = packet_mgr->Lookup(Tag().AsVal().get()) )
|
||||||
analyzer->SetEnabled(enabled);
|
analyzer->SetEnabled(arg_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::DoDescribe(ODesc* d) const {
|
void Component::DoDescribe(ODesc* d) const {
|
||||||
|
@ -32,5 +32,5 @@ void Component::DoDescribe(ODesc* d) const {
|
||||||
d->Add(", ");
|
d->Add(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
d->Add(enabled ? "enabled" : "disabled");
|
d->Add(Enabled() ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,19 +34,7 @@ public:
|
||||||
*/
|
*/
|
||||||
factory_callback Factory() const { return factory; }
|
factory_callback Factory() const { return factory; }
|
||||||
|
|
||||||
/**
|
void SetEnabled(bool arg_enabled) override;
|
||||||
* 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);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +44,6 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
factory_callback factory; // The analyzer's factory callback.
|
factory_callback factory; // The analyzer's factory callback.
|
||||||
bool enabled = true; // True if the analyzer is enabled.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace zeek::packet_analysis
|
} // namespace zeek::packet_analysis
|
||||||
|
|
|
@ -59,12 +59,30 @@ void Component::InitializeTag() {
|
||||||
tag = zeek::Tag(etype, ++type_counter, tag_subtype);
|
tag = zeek::Tag(etype, ++type_counter, tag_subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The component's tag.
|
|
||||||
*/
|
|
||||||
zeek::Tag Component::Tag() const {
|
zeek::Tag Component::Tag() const {
|
||||||
assert(tag_initialized);
|
assert(tag_initialized);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Component::SetEnabled(bool arg_enabled) {
|
||||||
|
switch ( type ) {
|
||||||
|
case component::ANALYZER:
|
||||||
|
case component::PACKET_ANALYZER:
|
||||||
|
case component::FILE_ANALYZER:
|
||||||
|
case component::SESSION_ADAPTER:
|
||||||
|
// For these types we have logic in place to ignore the component
|
||||||
|
// if disabled.
|
||||||
|
enabled = arg_enabled;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// It wouldn't be hard to add support for other component types. We
|
||||||
|
// just need to make sure the enabled flag is checked somewhere to
|
||||||
|
// skip using the component if off.
|
||||||
|
ODesc d;
|
||||||
|
Describe(&d);
|
||||||
|
reporter->InternalError("SetEnabled() called on unsupported component (%s)", d.Description());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace zeek::plugin
|
} // namespace zeek::plugin
|
||||||
|
|
|
@ -118,6 +118,25 @@ public:
|
||||||
*/
|
*/
|
||||||
zeek::Tag Tag() const;
|
zeek::Tag Tag() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the component is currently enabled and hence
|
||||||
|
* available for use.
|
||||||
|
*/
|
||||||
|
bool Enabled() const { return enabled; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables this component. Derived classes may override this if
|
||||||
|
* they need to initiate additional actions, but must then call the base
|
||||||
|
* class version.
|
||||||
|
*
|
||||||
|
* @param arg_enabled True to enabled, false to disable.
|
||||||
|
*
|
||||||
|
* Note: This method is currently supported for protocol, file, and packet
|
||||||
|
* analyzers, as well as session adapters. Using it on other types of
|
||||||
|
* component will result in an internal error.
|
||||||
|
*/
|
||||||
|
virtual void SetEnabled(bool arg_enabled);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Adds type specific information to the output of Describe().
|
* Adds type specific information to the output of Describe().
|
||||||
|
@ -139,6 +158,7 @@ private:
|
||||||
EnumTypePtr etype;
|
EnumTypePtr etype;
|
||||||
Tag::subtype_t tag_subtype;
|
Tag::subtype_t tag_subtype;
|
||||||
bool tag_initialized = false;
|
bool tag_initialized = false;
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
/** Used to generate globally unique tags */
|
/** Used to generate globally unique tags */
|
||||||
static Tag::type_t type_counter;
|
static Tag::type_t type_counter;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue