Fix registration of protocol analyzers from inside plugins.

With the recent packet manager work, it broke to register a protocol
analyzer for a specific port from inside a plugin's initialization code.
That's because that registration now depends on the packet manager being
set up, which isn't case at that time a plugin's `InitPostInit()` runs.
This fix contains two parts:

    - Initialize the packet manager before the analyzer manager, so that
      the latter's `InitPostScript()` can rely on the former being
      ready.

    - Change the analyzer manager to (only) record port registrations
      happening before it's fully initialized. Its `InitPostScript()`
      then performs the actual registrations, knowing it can use the
      packet manager now.

This comes with a `cmake/` to add a missing include directory.
This commit is contained in:
Robin Sommer 2021-07-15 09:42:34 +02:00
parent 6e3d2d4516
commit a7343ee019
9 changed files with 59 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#include "Plugin.h"
#include "analyzer/Component.h"
#include "analyzer/Manager.h"
#include "Foo.h"
@ -20,3 +21,13 @@ zeek::plugin::Configuration Plugin::Configure()
config.version.patch = 0;
return config;
}
void Plugin::InitPostScript()
{
auto tag = ::zeek::analyzer_mgr->GetAnalyzerTag("Foo");
if ( ! tag )
::zeek::reporter->FatalError("cannot get analyzer Tag");
zeek::analyzer_mgr->RegisterAnalyzerForPort(tag, TransportProto::TRANSPORT_TCP, 4243);
}

View file

@ -10,6 +10,8 @@ class Plugin : public zeek::plugin::Plugin
protected:
// Overridden from zeek::plugin::Plugin.
zeek::plugin::Configuration Configure() override;
void InitPostScript() override;
};
extern Plugin plugin;