Move API for disabling packet analyzers into component.

Before, that API was part of the analyzers themselves, which meant we
couldn't disable a packet analyzer before it had been instantiated.
That's different from protocol/file analyzers, where we disable them
through the corresponding component. The lack of the component-side
API prevented Spicy from replacing packet analyzers at startup.

The reason we had put this into analyzer originally was performance so
that we don't need a component lookup for every packet. This change
keeps that optimization by caching the on/off state in the analyzer
itself as well, but now with the component being the one controlling
it.
This commit is contained in:
Robin Sommer 2022-10-07 13:02:49 +02:00
parent a84d06a2c3
commit b114850283
5 changed files with 44 additions and 19 deletions

View file

@ -3,6 +3,7 @@
#include "zeek/packet_analysis/Component.h"
#include "zeek/Desc.h"
#include "zeek/packet_analysis/Analyzer.h"
#include "zeek/packet_analysis/Manager.h"
using namespace zeek::packet_analysis;
@ -21,11 +22,23 @@ void Component::Initialize()
packet_mgr->RegisterComponent(this, "ANALYZER_");
}
void Component::SetEnabled(bool arg_enabled)
{
enabled = arg_enabled;
// If we already have instantiated an analyzer, update its state.
if ( auto analyzer = packet_mgr->GetAnalyzer(Tag().AsVal().get()) )
analyzer->SetEnabled(enabled);
}
void Component::DoDescribe(ODesc* d) const
{
if ( factory )
{
d->Add("ANALYZER_");
d->Add(CanonicalName());
d->Add(", ");
}
d->Add(enabled ? "enabled" : "disabled");
}