Commit graph

96 commits

Author SHA1 Message Date
Johanna Amann
6d612ced3d Mark one-parameter constructors as explicit & use override where possible
This commit marks (hopefully) ever one-parameter constructor as explicit.

It also uses override in (hopefully) all circumstances where a virtual
method is overridden.

There are a very few other minor changes - most of them were necessary
to get everything to compile (like one additional constructor). In one
case I changed an implicit operation to an explicit string conversion -
I think the automatically chosen conversion was much more convoluted.

This took longer than I want to admit but not as long as I feared :)
2018-03-27 07:17:32 -07:00
Johanna Amann
41285abea5 Make nearly all bool operators explicit.
These are a bit dangerous because the casting can happen in quite
unexpected circumstances and lead to undesirable comparison results.
2018-01-18 14:02:03 -08:00
Jon Siwek
787b1e6bf2 Merge branch 'topic/corelight/reporter-hook' of https://github.com/corelight/bro
* 'topic/corelight/reporter-hook' of https://github.com/corelight/bro:
  Add reporter hook.
2017-11-21 12:28:52 -06:00
Johanna Amann
b852437126 Add reporter hook.
The hook being added is:

bool HookReporter(const std::string& prefix, const EventHandlerPtr event,
                  const Connection* conn, const val_list* addl, bool location,
                  const Location* location1, const Location* location2,
                  bool time, const std::string& buffer) override;

This hook gives access to basically all information that is available in
the function in Reporter.cc that performs the logging. The hook is
called each time when anything passes through the reporter in the cases
in which an event usually would be called. This includes weirds. The
hook can return false to prevent the normal reporter events from being
raised.
2017-11-16 13:02:12 -08:00
Johanna Amann
91dcefe104 Fix and extend behavior of HookLoadFile
This commit fixes and extends the behavior of HookLoadFile. Before this
change, HookLoadFile appended ".bro" to each path that was @loaded, even
if the path specified directory names. Furthermore it only gave the path
of the file as it was specified in the Bro script without revealing the
final path of the file that it was going to load.

This patch changes this behavior - in addition to giving the unmodified
path given in the @load command, the hook now returns the resolved path
of the file or directory it is going to load (if found). The hook is
furthermore raises for @load-sigs and @load-plugin; a enum specifies the
kind of load that is happening.
2017-11-16 12:31:27 -08:00
Johanna Amann
089f87d8da Merge remote-tracking branch 'origin/topic/robin/plugin-version-check'
I added another small change - since we are inlining Configure(), we can
just set bro_plugin directly to BRO_PLUGIN_BRO_VERSION in
src/plugin/Plugin.h, instead of depending on the plugin to do it. This
also means we do not need to change init-plugin in bro-aux at this
moment.

BIT-1828 #closed

* origin/topic/robin/plugin-version-check:
  Adding plugin API number into versioned function name, and removing old runtime API version check.
  Extend plugin infrastructure to catch Bro version mismatches at link time.
2017-07-25 16:14:49 -07:00
Robin Sommer
78f8ff432f Adding plugin API number into versioned function name, and removing
old runtime API version check.
2017-07-21 13:25:56 -07:00
Robin Sommer
8ae30d8aac Extend plugin infrastructure to catch Bro version mismatches at link
time.

People keep running into the problem that they upgrade Bro but forget
to recompile their plugins--which can lead to crashes. While the
plugins' API version was supposed to catch this, it's not reliable as
that check may come too late. This change takes a different tack: We
compile a C function into the Bro binary that has Bro's version number
encoded into its name. A plugin can then reference that function. If
the Bro version changes, the function goes away and the plugin won't
load anymore.

I've integrated that function reference into the plugin skeleton code
so that new plugins get it automatically (unless explicitly removed).
I couldn't see a way to do it transparently for already existing
plugins unfortunately.

The version number used for the function name is slightly normalized
to skip any git revision postfixes (i.e., "2.5-xxx" is always treated
as "2.5-git") so that one doesn't need to recompile all plugins after
every master commit. That seems good enough, usually people run into
this when upgrading to a new release.

If one loads an old plugin into a new Bro, the error message looks
like this:

    $ bro -NN Demo::Foo
    fatal error in /home/robin/bro/master/scripts/base/init-bare.bro, line 1:
    cannot load plugin library /home/robin/tmp/p/build//lib/Demo-Foo.linux-x86_64.so:
    /home/robin/tmp/p/build//lib/Demo-Foo.linux-x86_64.so: undefined symbol: bro_version_2_5_git_debug

Not the prettiest, but better than a crash!

TODO: I'm still unsure if we should remove the plugin API version
altogetger now. This link-time check should catch everything the API
version does, except for master commits.
2017-07-07 15:58:05 -07:00
Jon Siwek
874d2b9fb0 Merge branch 'topic/corelight/logging-hooks' of https://github.com/corelight/bro
* 'topic/corelight/logging-hooks' of https://github.com/corelight/bro:
  Plugin: Add hooks for log init and writing.
2017-05-04 11:44:43 -05:00
Johanna Amann
684ea8aa37 Plugin: Add hooks for log init and writing.
The two hooks being added are:

void HookLogInit(const std::string& writer, const std::string& instantiating_filter, bool local, bool remote, const logging::WriterBackend::WriterInfo& info, int num_fields, const threading::Field* const* fields);

which is called when a writer is being instantiated and contains
information about the fields being logged, as well as

bool HookLogWrite(const std::string& writer, const std::string& filter, const logging::WriterBackend::WriterInfo& info, int num_fields, const threading::Field* const* fields, threading::Value** vals);

which is called for each log line being written by each writer. It
contains all the data being written. The data can be changed in the
function call and lines can be prevented from being written.

This commit also fixes a few small problems with plugin hooks itself,
and extends the tests that were already there, besides introducing tests
for the added functionality.
2017-04-24 14:02:05 -07:00
Johanna Amann
5b76366199 Plugin: add/fix documentation for HookSetupAnalyzerTree 2017-02-23 15:00:27 -08:00
Robin Sommer
8479298e04 Merge branch 'master' of git.bro.org:bro 2016-10-06 14:33:36 -07:00
Robin Sommer
7a981eff0f Merge remote-tracking branch 'origin/topic/vladg/bit-1671'
Nice, thanks!

BIT-1671 #merged

* origin/topic/vladg/bit-1671:
  Add descriptions for what the SMB1 events do, and references to the specification.
  Add descriptions for what the SMB2 events do, and references to the specification.
  Improve the SMB2 documentation.
  Improve the SMB1 documentation a bit. Clean it up, make it more consistent, and add references to similar events.
  Add DCE-RPC and NTLM abbreviation documentation for their events.
  Remove reference to epm_map_response in RPC documentation. Addresses BIT-1671.
  Rename events referenced in SMB1::Header documentation with new SMB analyzer. Addresses BIT-1671.
2016-10-06 14:02:04 -07:00
Robin Sommer
8acf995361 Fixing Broxygen indexing confusion for plugins.
Because plugins register their script directories with the BROPATH,
Broxygen stripped them out from plugin script paths it was indexing.
That then led to multiple plugins ending up with the same script
paths, triggering warnings about duplicates.

I fixed this by checking if a script comes out of a plugin. If so, it
gets an artifcial index prefix "<plugin-name>:", followed by the
script's relative path inside the plugin's top-level directory. For
example, "/opt/bro/lib/bro/plugins/Bro_Netmap/scripts/init.bro" now
turns into "Bro::Netmap:scripts/init.bro" for Broxygen purposes
(whereas it used to be just "init.bro").

Addresses BIT-1663.

(Can't think of a good way to add a test for this unfortunately.)
2016-09-29 16:18:53 -07:00
Johanna Amann
b11d9b5ccd Add missing include directive. 2016-08-12 06:54:53 -07:00
Johanna Amann
fb3bc05df5 Merge remote-tracking branch 'origin/topic/johanna/component-initialization-order'
* origin/topic/johanna/component-initialization-order:
  Make tags generated during component initialization stable.
2016-08-11 21:50:53 -07:00
Johanna Amann
65d977f278 Make tags generated during component initialization stable.
The order in which the plugin initializers are executed is compiler
dependent. With this change, Tags will always be generated in
alphabetical ordering, not in compiler-dependent order.
2016-08-11 19:48:53 -07:00
Robin Sommer
c91792b762 Merge branch 'topic/jswaro/feature/HookAddToAnalyzer-tcprs-support' of https://github.com/jswaro/bro
Making two changes here:

    - Renaming the hook to SetupAnalyzerTree.

    - Reverting the reversal of the script load order. Instead, I'm
      adding an additional script that Bro looks for to load first,
      "__preload__.bro". Also extending the plugin docs to cover this.

    - Increasing plugin API version, as I suppose adding a new virtual
      function may invalidate binary compatibility.

* 'topic/jswaro/feature/HookAddToAnalyzer-tcprs-support' of https://github.com/jswaro/bro:
  Add hook 'HookAddToAnalyzerTree' to support TCPRS plugin
2015-08-10 15:05:48 -07:00
Robin Sommer
3957091e1b Renaming config.h to bro-config.h.
A couple times now I had this conflicting with files of the same name
in other projects.
2015-07-28 11:57:04 -07:00
James Swaro
85fd1c9fa7 Add hook 'HookAddToAnalyzerTree' to support TCPRS plugin
This commit introduces a new hook, HookAddToAnalyzerTree, which
allows plugins to add a new analyzer to the analyzer tree during
analyzer tree creation. This hook is necessary to support the
TCPRS plugin.

Additionally, the order in which the scripts were loaded has been
changed to address a problem with undefined variable errors due
to load order issues.

Signed-off-by: James Swaro <james.swaro@gmail.com>
2015-07-26 13:32:24 -05:00
Robin Sommer
10b61b1d16 Increasing plugin API version.
The layer 2 updates introduced some API changes.
2015-07-22 06:53:20 -07:00
Robin Sommer
7d95ebb48a Fix -N option to work with builtin plugins as well. 2015-04-23 07:10:55 -07:00
Robin Sommer
6fa03abdbc Merge remote-tracking branch 'origin/topic/gilbert/plugin-api-tweak'
* origin/topic/gilbert/plugin-api-tweak:
  Updating plugin.hooks baseline so that test succeeds
  Revert spacing change that shouldn't have been included with the previous changeset ... should fix all of the plugin tests save hooks, which needs to be updated.
  More small fixes
  Small fixes
  Incremental
  Re-updating plugin.hooks test to include new argument output (after merge).
  Fixing logic errors in HandlePluginResult
  Updating tests and tweaking HookArgument to include Frame support.
  Incremental commit: implementing a wrapper for the Val class.
  Reverting change to const status of network_time.  Also, see FIXME: in Func.cc / HandlePluginResult ...
  Tweaks to result handling to make things a little more sane.
  Plugin API: minor change (adding parent frame) to support calling methods from hook.  Also declare network time update argument to be const because good practice.

BIT-1270 #merged

Conflicts:
	testing/btest/Baseline/plugins.hooks/output
2015-03-02 18:17:52 -08:00
Gilbert Clark
8e1bc8674b Revert spacing change that shouldn't have been included with the previous changeset ... should fix all of the plugin tests save hooks, which needs to be updated. 2015-02-26 11:12:45 -05:00
Gilbert Clark
d3a5440cff Merge branch 'master' into topic/gilbert/plugin-api-tweak 2015-02-23 13:22:47 -05:00
Gilbert Clark
ce18a2867e Merge branch 'master' of ssh://git.bro-ids.org/bro into topic/gilbert/plugin-api-tweak 2015-02-23 00:00:38 -05:00
Robin Sommer
0f96d06252 Making plugin names case-insensitive for some internal comparisions.
Makes the plugin system a bit more tolerant against spelling
inconsistencies that would be hard to catch otherwise.
2015-02-16 20:26:23 -08:00
Robin Sommer
530c3c0c6b Changing load order for plugin scripts.
This can be need if they depends on each other.
2015-02-08 18:22:59 -08:00
Jon Siwek
87962a48dd Add a new attribute: &deprecated.
While scripts are parsed, a warning is raised for each usage of an
identifier marked as &deprecated.  This also works for BIFs.

Addresses BIT-924, BIT-757.
2015-01-21 09:40:50 -06:00
Gilbert Clark
cda7c93704 More small fixes 2014-11-24 16:35:26 -05:00
Gilbert Clark
616ed22572 Small fixes 2014-11-24 16:30:12 -05:00
Gilbert Clark
7eadcad674 Merge branch 'master' into topic/gilbert/plugin-api-tweak
Conflicts:
	testing/btest/Baseline/plugins.api-version-mismatch/output
	testing/btest/Baseline/plugins.hooks/output
	testing/btest/plugins/api-version-mismatch.sh
2014-11-24 16:21:23 -05:00
Gilbert Clark
6055b56f5c Incremental 2014-11-24 14:28:17 -05:00
Robin Sommer
3e508d316a Plugins: Change order in which plugins' scripts are loaded at startup.
We now load the top-level  __init__.bro before the internal bif.bro so
that the former can define types used by the latter.
2014-10-23 14:22:26 -07:00
Gilbert Clark
70c7258dfa Updating tests and tweaking HookArgument to include Frame support.
* Add frame support to HookArgument, since it's a new argument to HookCallFunction
* Fix test in api-version-mismatch to remove absolute paths from output
* Update test plugin to use new HookCallFunction interface
2014-10-02 19:23:59 -04:00
Gilbert Clark
0104d7147d Merging master into branch.
Merge branch 'master' into topic/gilbert/plugin-api-tweak
2014-10-01 21:19:02 -04:00
Gilbert Clark
d639488d36 Incremental commit: implementing a wrapper for the Val class.
Just a checkpoint: need to add / update tests to make sure things work as expected.  Should build / pass core btests, though.
2014-09-27 08:03:30 -04:00
Gilbert Clark
8d04f58eda Reverting change to const status of network_time. Also, see FIXME: in Func.cc / HandlePluginResult ... 2014-09-19 21:55:47 -04:00
Gilbert Clark
2446a942e0 Plugin API: minor change (adding parent frame) to support calling methods from hook. Also declare network time update argument to be const because good practice. 2014-09-04 20:41:44 -04:00
Robin Sommer
caa55ad352 Moving Pkt{Src,Dumper} a directory level up.
Also renaming PktSourceComponent to PktSrcComponent.
2014-08-22 16:46:15 -07:00
Robin Sommer
93e6a4a9db Removing netmap, remaining pieces of the 2ndary path, and left-over
files of packet sorter.

Netmap will move to a plugin.
2014-08-22 16:24:39 -07:00
Robin Sommer
bf6dd2e9ca Merge remote-tracking branch 'origin/master' into topic/robin/pktsrc
Conflicts:
	configure
	src/CMakeLists.txt
	src/Net.cc
	src/PacketSort.cc
	src/PacketSort.h
	src/RemoteSerializer.cc
	src/Sessions.cc
	src/Sessions.h
2014-08-22 15:41:42 -07:00
Robin Sommer
355314718b Merge remote-tracking branch 'origin/master' into topic/robin/reader-writer-plugins 2014-08-08 18:32:45 -07:00
Robin Sommer
8031da4ee7 More polishing of some of the branche's changes. 2014-08-08 18:32:05 -07:00
Jon Siwek
f8bb17bcb8 Fix possible null ptr derefs reported by Coverity. 2014-08-04 10:53:36 -05:00
Robin Sommer
0ba4b768cd Merge remote-tracking branch 'origin/master' into topic/robin/reader-writer-plugins 2014-07-31 14:45:38 -07:00
Robin Sommer
2b505b07c1 Merge remote-tracking branch 'origin/master' into topic/robin/reader-writer-plugins 2014-07-31 10:10:39 -07:00
Robin Sommer
382b946098 Adding missing check that a plugin's API version matches what Bro defines. 2014-07-31 10:09:03 -07:00
Jon Siwek
69b1ba653d Minor adjustments to plugin code/docs.
Mostly whitespace/typos.
Moved some Plugin methods out from public access.
2014-07-30 16:48:23 -05:00
Robin Sommer
48b251abd1 Merge branch 'topic/robin/dynamic-plugins-2.3' into topic/robin/reader-writer-plugins 2014-07-22 17:27:16 -07:00