Further polishing and cleanup in preparation for merge.

This commit is contained in:
Robin Sommer 2014-07-12 18:12:09 -07:00
parent aeb8e71e8c
commit 9616cd8e61
15 changed files with 79 additions and 60 deletions

View file

@ -1,7 +1,6 @@
project(Bro C CXX) project(Bro C CXX)
# When changing the minimum version here, also adapt # When changing the minimum version here, also adapt
# cmake/BroPluginDynamic and
# aux/bro-aux/plugin-support/skeleton/CMakeLists.txt # aux/bro-aux/plugin-support/skeleton/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR) cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR)

View file

@ -247,10 +247,11 @@ in its search path ``BRO_PLUGIN_PATH``. However, in bare mode (``bro
-b``), no dynamic plugins will be activated by default; instead the -b``), no dynamic plugins will be activated by default; instead the
user can selectively enable individual plugins in scriptland using the user can selectively enable individual plugins in scriptland using the
``@load-plugin <qualified-plugin-name>`` directive (e.g., ``@load-plugin <qualified-plugin-name>`` directive (e.g.,
``@load-plugin Demo::Rot13``). Alternatively, one can also set the ``@load-plugin Demo::Rot13``). Alternatively, one can activate a
environment variable ``BRO_PLUGIN_ACTIVATE`` to a list of plugin from the command-line by specifying its full name
comma(!)-separated names of plugins to unconditionally activate, even (``Demo::Rot13``), or set the environment variable
in bare mode. ``BRO_PLUGIN_ACTIVATE`` to a list of comma(!)-separated names of
plugins to unconditionally activate, even in bare mode.
``bro -N`` shows activated plugins separately from found but not yet ``bro -N`` shows activated plugins separately from found but not yet
activated plugins. Note that plugins compiled statically into Bro are activated plugins. Note that plugins compiled statically into Bro are
@ -323,6 +324,11 @@ Packet Dumpers
Not yet available as plugins. Not yet available as plugins.
Hooks
=====
TODO.
Testing Plugins Testing Plugins
=============== ===============
@ -398,9 +404,20 @@ Run the test-suite::
Debugging Plugins Debugging Plugins
================= =================
..todo:: Plugins can use Bro's standard debug logger by using the
``PLUGIN_DBG_LOG(<plugin>, <args>)`` macro (defined in
``DebugLogger.h``), where ``<plugin>`` is the ``Plugin`` instance and
``<args>`` are printf-style arguments, just as with Bro's standard
debuggging macros.
At runtime, one then activates a plugin's debugging output with ``-B
plugin-<name>``, where ``<name>`` is the name of the plugin as
returned by its ``Configure()`` method, yet with the
namespace-separator ``::`` replaced with a simple dash. Example: If
the plugin is called ``Bro::Demo``, use ``-B plugin-Bro-Dome``. As
usual, the debugging output will be recorded to ``debug.log`` if Bro's
compiled in debug mode.
Document.
Documenting Plugins Documenting Plugins
=================== ===================

View file

@ -154,7 +154,7 @@ export {
args: AnalyzerArgs &default=AnalyzerArgs()): bool; args: AnalyzerArgs &default=AnalyzerArgs()): bool;
## Adds all analyzers associated with a give MIME type to the analysis of ## Adds all analyzers associated with a give MIME type to the analysis of
## a file. Note that analyzers added via MIME types cannot take further ## a file. Note that analyzers added via MIME types cannot take further
## arguments. ## arguments.
## ##
## f: the file. ## f: the file.

View file

@ -426,6 +426,6 @@ add_dependencies(bro bif_loader_plugins)
# Install *.bif.bro. # Install *.bif.bro.
install(DIRECTORY ${CMAKE_BINARY_DIR}/scripts/base/bif DESTINATION ${BRO_SCRIPT_INSTALL_PATH}/base) install(DIRECTORY ${CMAKE_BINARY_DIR}/scripts/base/bif DESTINATION ${BRO_SCRIPT_INSTALL_PATH}/base)
# Make clean removes the bif and plugin directories. # Make clean removes the bif directory.
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/scripts/base/bif) set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/scripts/base/bif)

View file

@ -62,7 +62,7 @@ private:
bool used; // this handler is indeed used somewhere bool used; // this handler is indeed used somewhere
bool enabled; bool enabled;
bool error_handler; // this handler reports error messages. bool error_handler; // this handler reports error messages.
bool generate_always; bool generate_always;
declare(List, SourceID); declare(List, SourceID);
typedef List(SourceID) receiver_list; typedef List(SourceID) receiver_list;

View file

@ -49,7 +49,7 @@ void FlowSrc::Process()
// This is normally done by calling net_packet_dispatch(), // This is normally done by calling net_packet_dispatch(),
// but as we don't have a packet to dispatch ... // but as we don't have a packet to dispatch ...
net_update_time(next_timestamp); net_update_time(next_timestamp);
expire_timers(); expire_timers();
netflow_analyzer->downflow()->set_exporter_ip(exporter_ip); netflow_analyzer->downflow()->set_exporter_ip(exporter_ip);

View file

@ -277,6 +277,49 @@ int BroFunc::IsPure() const
return 1; return 1;
} }
Val* BroFunc::HandlePluginResult(Val* plugin_resul, tval_list* args)
{
// Helper function factoring out this code from BroFunc:Call() for better
// readability.
switch ( Flavor() ) {
case FUNC_FLAVOR_EVENT:
Unref(plugin_result);
plugin_result = 0;
break;
case FUNC_FLAVOR_HOOK:
if ( plugin_result->Type()->Tag() != TYPE_BOOL )
reporter->InternalError("plugin returned non-bool for hook");
break;
case FUNC_FLAVOR_FUNCTION:
{
BroType* yt = FType()->YieldType();
if ( (! yt) || yt->Tag() == TYPE_VOID )
{
Unref(plugin_result);
plugin_result = 0;
}
else
{
if ( plugin_result->Type()->Tag() != yt->Tag() )
reporter->InternalError("plugin returned wrong type for function call");
}
break;
}
}
loop_over_list(*args, i)
Unref((*args)[i]);
return plugin_result;
}
Val* BroFunc::Call(val_list* args, Frame* parent) const Val* BroFunc::Call(val_list* args, Frame* parent) const
{ {
#ifdef PROFILE_BRO_FUNCTIONS #ifdef PROFILE_BRO_FUNCTIONS
@ -286,45 +329,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0); Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0);
if ( plugin_result ) if ( plugin_result )
{ return HandlePluginResult(plugin_result, args);
// TODO: We should factor this out into its own method.
switch ( Flavor() ) {
case FUNC_FLAVOR_EVENT:
Unref(plugin_result);
plugin_result = 0;
break;
case FUNC_FLAVOR_HOOK:
if ( plugin_result->Type()->Tag() != TYPE_BOOL )
reporter->InternalError("plugin returned non-bool for hook");
break;
case FUNC_FLAVOR_FUNCTION:
{
BroType* yt = FType()->YieldType();
if ( (! yt) || yt->Tag() == TYPE_VOID )
{
Unref(plugin_result);
plugin_result = 0;
}
else
{
if ( plugin_result->Type()->Tag() != yt->Tag() )
reporter->InternalError("plugin returned wrong type for function call");
}
break;
}
}
loop_over_list(*args, i)
Unref((*args)[i]);
return plugin_result;
}
if ( bodies.empty() ) if ( bodies.empty() )
{ {

View file

@ -100,6 +100,7 @@ public:
protected: protected:
BroFunc() : Func(BRO_FUNC) {} BroFunc() : Func(BRO_FUNC) {}
Stmt* AddInits(Stmt* body, id_list* inits); Stmt* AddInits(Stmt* body, id_list* inits);
Val* HandlePluginResult(Val* plugin_result, val_list* args);
DECLARE_SERIAL(BroFunc); DECLARE_SERIAL(BroFunc);

View file

@ -94,9 +94,7 @@ int BroObj::suppress_errors = 0;
BroObj::~BroObj() BroObj::~BroObj()
{ {
if ( notify_plugins ) if ( notify_plugins )
{ PLUGIN_HOOK_VOID(HOOK_BRO_OBJ_DTOR, HookBroObjDtor(this));
PLUGIN_HOOK_VOID(HOOK_BRO_OBJ_DTOR, HookBroObjDtor(this));
}
delete location; delete location;
} }

View file

@ -547,7 +547,7 @@ class EnumType : public BroType {
public: public:
typedef std::list<std::pair<string, bro_int_t> > enum_name_list; typedef std::list<std::pair<string, bro_int_t> > enum_name_list;
EnumType(EnumType* e); EnumType(EnumType* e);
EnumType(const string& arg_name); EnumType(const string& arg_name);
~EnumType(); ~EnumType();

View file

@ -242,7 +242,7 @@ public:
// is now fully closed, a connection_finished event will be // is now fully closed, a connection_finished event will be
// generated; otherwise not. // generated; otherwise not.
virtual void ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint, virtual void ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint,
analyzer::tcp::TCP_Endpoint* peer, int gen_event); analyzer::tcp::TCP_Endpoint* peer, int gen_event);
virtual void ConnectionFinished(int half_finished); virtual void ConnectionFinished(int half_finished);
virtual void ConnectionReset(); virtual void ConnectionReset();

View file

@ -444,7 +444,7 @@ Analyzer* Manager::InstantiateAnalyzer(Tag tag, RecordVal* args, File* f) const
if ( ! c->Factory() ) if ( ! c->Factory() )
{ {
reporter->InternalWarning("file analyzer %s cannot be instantiated " reporter->InternalWarning("file analyzer %s cannot be instantiated "
"dynamically", c->CanonicalName().c_str()); "dynamically", c->CanonicalName().c_str());
return 0; return 0;
} }

View file

@ -1,4 +1,4 @@
// See the file in the main distribution directory for copyright. // See the file in the main distribution directory for copyright.
#include "plugin/Plugin.h" #include "plugin/Plugin.h"

View file

@ -23,7 +23,7 @@ namespace plugin {
* @param method_call The \a Manager method corresponding to the hook. * @param method_call The \a Manager method corresponding to the hook.
*/ */
#define PLUGIN_HOOK_VOID(hook, method_call) \ #define PLUGIN_HOOK_VOID(hook, method_call) \
if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call; { if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call; }
/** /**
* Macro to trigger hooks that return a result. * Macro to trigger hooks that return a result.

View file

@ -1626,7 +1626,6 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
unsigned int ret_total; unsigned int ret_total;
#ifdef HAVE_MALLINFO #ifdef HAVE_MALLINFO
// For memory, getrusage() gives bogus results on Linux. Grmpf.
struct mallinfo mi = mallinfo(); struct mallinfo mi = mallinfo();
if ( malloced ) if ( malloced )
@ -1637,7 +1636,7 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
struct rusage r; struct rusage r;
getrusage(RUSAGE_SELF, &r); getrusage(RUSAGE_SELF, &r);
// At least on FreeBSD it's in KB. // In KB.
ret_total = r.ru_maxrss * 1024; ret_total = r.ru_maxrss * 1024;
if ( total ) if ( total )