Infrastructure for modularizing protocol analyzers.

There's now a new directory "src/protocols/", and the plan is for each
protocol analyzer to eventually have its own subdirectory in there
that contains everything it defines (C++/pac/bif). The infrastructure
to make that happen is in place, and two analyzers have been
converted to the new model, HTTP and SSL; there's no further
HTTP/SSL-specific code anywhere else in the core anymore (I believe :-)

Further changes:

    - -N lists available plugins, -NN lists more details on what these
      plugins provide (analyzers, bif elements). (The latter does not
      work for analyzers that haven't been converted yet).

    - *.bif.bro files now go into scripts/base/bif/; and
      scripts/base/bif/plugins/ for bif files provided by plugins.

    - I've factored out the bifcl/binpac CMake magic from
      src/CMakeLists.txt to cmake/{BifCl,Binpac}

    - There's a new cmake/BroPlugin that contains magic to allow
      plugins to have a simple CMakeLists.txt. The hope is that
      eventually the same CMakeLists.txt can be used for compiling a
      plugin either statically or dynamically.

    - bifcl has a new option -c that changes the code it generates so
      that it can be used with a plugin.

TODOs:
    - "make install" is probably broken.
    - Broxygen is probably broken for plugin-defined events.
    - event groups are broken (do we want to keep them?)
This commit is contained in:
Robin Sommer 2013-03-28 21:47:44 -07:00
parent 2be985433c
commit 19c1816ebb
44 changed files with 974 additions and 663 deletions

View file

@ -2,6 +2,7 @@
#include <cassert>
#include "Plugin.h"
#include "Manager.h"
#include "Component.h"
#include "../Desc.h"
@ -11,11 +12,15 @@ using namespace plugin;
Description::Description()
{
name = "<NAME-NOT-SET>";
api_version = API_VERSION;
// These will be reset by the BRO_PLUGIN_* macros.
version = -9999;
api_version = -9999;
}
Plugin::Plugin()
{
Manager::RegisterPlugin(this);
}
Description Plugin::GetDescription() const
@ -37,6 +42,27 @@ void Plugin::Init()
{
}
void Plugin::InitBif()
{
for ( bif_init_func_list::const_iterator f = bif_inits.begin(); f != bif_inits.end(); f++ )
{
bif_init_func_result items = (**f)();
for ( bif_init_func_result::const_iterator i = items.begin(); i != items.end(); i++ )
{
BifItem bi;
bi.id = (*i).first;
bi.type = (BifItem::Type)(*i).second;
bif_items.push_back(bi);
}
}
}
const Plugin::bif_item_list& Plugin::BifItems()
{
return bif_items;
}
void Plugin::Done()
{
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
@ -55,6 +81,11 @@ void Plugin::AddComponent(Component* c)
components.push_back(c);
}
void Plugin::AddBifInitFunction(bif_init_func c)
{
bif_inits.push_back(c);
}
void Plugin::Describe(ODesc* d)
{
d->Add("Plugin: ");
@ -66,7 +97,7 @@ void Plugin::Describe(ODesc* d)
d->Add(description.description);
}
if ( description.version != API_BUILTIN )
if ( description.version != BRO_PLUGIN_VERSION_BUILTIN )
{
d->Add(" (version ");
d->Add(description.version);
@ -83,12 +114,53 @@ void Plugin::Describe(ODesc* d)
else
d->Add(" (built-in)");
d->NL();
d->Add("\n");
if ( d->IsShort() )
return;
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
{
(*i)->Describe(d);
d->NL();
d->Add("\n");
}
for ( bif_item_list::const_iterator i = bif_items.begin(); i != bif_items.end(); i++ )
{
const char* type = 0;
switch ( (*i).type ) {
case BifItem::FUNCTION:
type = "Function";
break;
case BifItem::EVENT:
type = "Event";
break;
case BifItem::CONSTANT:
type = "Constant";
break;
case BifItem::GLOBAL:
type = "Global";
break;
case BifItem::TYPE:
type = "Type";
break;
default:
type = "<unknown>";
}
d->Add(" ");
d->Add("[");
d->Add(type);
d->Add("] ");
d->Add((*i).id);
d->Add("\n");
}
}