Plugin doesn't seem te get instantiated

Hi all,

I want to create my own bro plugin but I’m stuck in the playing-around phase. Below is my current code and information about my system. I know packet counts are available in the normal logs, this is just my hello world for bro. The problem is that while bro seems to recognize that there is a plugin, it doesn’t seem to instantiate the analyzer when is is processing a pcap. I’ve tried to activate it using the environment variables, the Available function and the EnableHook. I need to process all connections so I can’t use port numbers or signatures.

The only output the plugin creates is ‘hello world!’ from the plugin.cc If the Analyzer gets instantiated, I would expect more output.

Could someone please help me?

Bas

Plugin.cc:

Hi,

In order to find the reason that my plugin isn’t doing anything, I have recompiled with --enable-debug and I run with bro -B plugins. The debug.log now contains

0.000000/1440343663.376984 [plugins] Found plugin mynamespace::myplugin in /usr/local/bro/lib/bro/plugins/mynamespace_myplugin
0.000000/1440343663.383816 [plugins] Activating plugin mynamespace::myplugin
0.000000/1440343663.383855 [plugins] Adding /usr/local/bro/lib/bro/plugins/mynamespace_myplugin/scripts to BROPATH
0.000000/1440343663.383892 [plugins] Loading /usr/local/bro/lib/bro/plugins/mynamespace_myplugin/scripts/preload.bro
0.000000/1440343663.383908 [plugins] Loading /usr/local/bro/lib/bro/plugins/mynamespace_myplugin/lib/bif/load.bro
0.000000/1440343663.383921 [plugins] Loading /usr/local/bro/lib/bro/plugins/mynamespace_myplugin/scripts/load.bro
0.000000/1440343663.383932 [plugins] Searching for shared libraries /usr/local/bro/lib/bro/plugins/mynamespace_myplugin//lib/*.linux-x86_64.so
0.000000/1440343663.384400 [plugins] Registering component PluginAnalyzer (tag 68/0)
0.000000/1440343663.384527 [plugins] Loaded /usr/local/bro/lib/bro/plugins/mynamespace_myplugin//lib/mynamespace-myplugin.linux-x86_64.so

I also added the Available() function to Plugin.h.

Is this all that is required? The plugin still doesn’t do anything… Any hints? Or does anyone have an example non-built-in plugin that work on all connections regardless of ports and signatures?

Best regards,
Bas

Sounds like you're suspecting the right thing already: the analyzer
needs to be explicitly activated for all connections it's supposed to
look at, it's not going to receive everything automatically. There
there 4 ways to activate an analyzer: (1) by port, (2) by signature,
(3) in script-land for a future connection, and (4) with recent git
master you can write a C++ hook function that gets called once at the
beginning of each connection when the default analyzer setup has been
determined; that C++ function can then add the customer analyzer at
that point as well.

The interface for (1)-(3) is documented here
https://www.bro.org/sphinx/scripts/base/frameworks/analyzer/main.bro.html.

For (4), this is the merge commit (not further documented yet).

Robin

Thanks! I still have a lot of work to do, but now at least my UpdateConnVal is being called, so there is progress :slight_smile:

You made my day!

For other people that want to create a dynamic plugin that is invoked for all connections (option 4), this is the progress so far:

In my Plugin.cc I added:
void HookSetupAnalyzerTree(Connection *conn)
{
::analyzer::mynamespace_myplugin::PluginAnalyzer::Instantiate(conn);
}

And in my PluginAnalyzer.cc I now have:
PluginAnalyzer::PluginAnalyzer(Connection* c)
: tcp::TCP_ApplicationAnalyzer(“TEST”, c)
{
TCP()->AddChildAnalyzer(this); // this line took me quite a while :wink:
}

Is this all that is required? The plugin still doesn’t do anything…
Any hints? Or does anyone have an example non-built-in plugin that
work on all connections regardless of ports and signatures?

Sounds like you’re suspecting the right thing already: the analyzer
needs to be explicitly activated for all connections it’s supposed to
look at, it’s not going to receive everything automatically. There
there 4 ways to activate an analyzer: (1) by port, (2) by signature,
(3) in script-land for a future connection, and (4) with recent git
master you can write a C++ hook function that gets called once at the
beginning of each connection when the default analyzer setup has been
determined; that C++ function can then add the customer analyzer at
that point as well.

The interface for (1)-(3) is documented here
https://www.bro.org/sphinx/scripts/base/frameworks/analyzer/main.bro.html.

For (4), this is the merge commit (not further documented yet).

Robin