Merge branch 'issues/152' of https://github.com/JonZeolla/bro into dev/2.7

* 'issues/152' of https://github.com/JonZeolla/bro:
  Bro plugins should support a patch version (x.y.z)
This commit is contained in:
Jon Siwek 2018-10-03 14:32:10 -05:00
commit 92739c1b44
31 changed files with 100 additions and 28 deletions

9
NEWS
View file

@ -19,6 +19,15 @@ New Functionality
- dns_NSEC
- dns_NSEC3
- Bro's Plugin framework now allows a patch version. If a patch version is not
provided, it will default to 0. To specify this, modify the plugin
Configuration class in your ``src/Plugin.cc` and set
``config.version.patch``. Note that the default plugin skeleton
includes a unit test whose Baseline has the plugin version number in
it and that will now fail due to the version number now including a
patch number. For those that want to keep the unit test, simply adapt
the unit test/baseline to include the new plugin patch number.
Changed Functionality
---------------------

@ -1 +1 @@
Subproject commit cdc9303cf497ad0b0cbbe3af8f17ec3628953d0b
Subproject commit db3c064f084090cda60d0511c74908b6cec092f8

View file

@ -99,7 +99,7 @@ option::
# export BRO_PLUGIN_PATH=/path/to/rot13-plugin/build
# bro -N
[...]
Demo::Rot13 - <Insert description> (dynamic, version 0.1)
Demo::Rot13 - <Insert description> (dynamic, version 0.1.0)
[...]
That looks quite good, except for the dummy description that we should
@ -115,6 +115,7 @@ is about. We do this by editing the ``config.description`` line in
config.description = "Caesar cipher rotating a string's characters by 13 places.";
config.version.major = 0;
config.version.minor = 1;
config.version.patch = 0;
return config;
}
[...]
@ -124,14 +125,14 @@ Now rebuild and verify that the description is visible::
# make
[...]
# bro -N | grep Rot13
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1)
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
Bro can also show us what exactly the plugin provides with the
more verbose option ``-NN``::
# bro -NN
[...]
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1)
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
[Function] Demo::rot13
[...]
@ -166,7 +167,7 @@ unpacking.
To distribute the plugin in binary form, the build process
conveniently creates a corresponding tarball in ``build/dist/``. In
this case, it's called ``Demo_Rot13-0.1.tar.gz``, with the version
this case, it's called ``Demo_Rot13-0.1.0.tar.gz``, with the version
number coming out of the ``VERSION`` file that ``init-plugin`` put
into place. The binary tarball has everything needed to run the
plugin, but no further source files. Optionally, one can include
@ -395,7 +396,7 @@ let's get that in place::
% 'btest-diff output' failed unexpectedly (exit code 100)
% cat .diag
== File ===============================
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1)
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
[Function] Demo::rot13
== Error ===============================

View file

@ -445,6 +445,8 @@ void Plugin::Describe(ODesc* d) const
d->Add(config.version.major);
d->Add(".");
d->Add(config.version.minor);
d->Add(".");
d->Add(config.version.patch);
d->Add(")");
}
else

View file

@ -15,7 +15,7 @@
// Increase this when making incompatible changes to the plugin API. Note
// that the constant is never used in C code. It's picked up on by CMake.
#define BRO_PLUGIN_API_VERSION 6
#define BRO_PLUGIN_API_VERSION 7
#define BRO_PLUGIN_BRO_VERSION BRO_VERSION_FUNCTION
@ -67,18 +67,24 @@ extern const char* hook_name(HookType h);
* Helper class to capture a plugin's version.
* */
struct VersionNumber {
int major; //< Major version number;
int minor; //< Minor version number;
int major; //< Major version number.
int minor; //< Minor version number.
int patch; //< Patch version number (available since Bro 2.7).
/**
* Constructor.
*/
VersionNumber() { major = minor = -1; }
VersionNumber() {
// Major and minor versions are required.
major = minor = -1;
// Patch version is optional, and set to 0 if not manually set.
patch = 0;
}
/**
* Returns true if the version is set to a non-negative value.
*/
explicit operator bool() const { return major >= 0 && minor >= 0; }
explicit operator bool() const { return major >= 0 && minor >= 0 && patch >= 0; }
};
/**

View file

@ -1,4 +1,4 @@
Demo::Foo - <Insert description> (dynamic, version 0.1)
Demo::Foo - <Insert description> (dynamic, version 0.1.0)
[Function] hello_plugin_world
[Event] plugin_event

View file

@ -1,4 +1,4 @@
Demo::Foo - <Insert description> (dynamic, version 0.1)
Demo::Foo - <Insert description> (dynamic, version 0.1.0)
[Function] hello_plugin_world
[Event] plugin_event

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test analyzer (dynamic, version 1.0)
Demo::Foo - A Foo test analyzer (dynamic, version 1.0.0)
[File Analyzer] Foo (ANALYZER_FOO)
[Event] foo_piece

View file

@ -1,3 +1,3 @@
Demo::Foo - <Insert description> (dynamic, version 0.1)
Demo::Foo - <Insert description> (dynamic, version 0.1.0)
===

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo packet dumper (dynamic, version 1.0)
Demo::Foo - A Foo packet dumper (dynamic, version 1.0.0)
[Packet Dumper] FooPktDumper (dumper prefix: "foo")
===

View file

@ -0,0 +1 @@
Testing::NoPatchVersion - Testing a plugin without a specified patch version (dynamic, version 0.1.0)

View file

@ -0,0 +1 @@
Testing::WithPatchVersion - Testing a plugin with a specified patch version (dynamic, version 0.1.4)

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test analyzer (dynamic, version 1.0)
Demo::Foo - A Foo test analyzer (dynamic, version 1.0.0)
[Analyzer] Foo (ANALYZER_FOO, enabled)
[Event] foo_message

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test input reader (dynamic, version 1.0)
Demo::Foo - A Foo test input reader (dynamic, version 1.0.0)
[Reader] Foo (Input::READER_FOO)
===

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test logging writer (dynamic, version 1.0)
Demo::Foo - A Foo test logging writer (dynamic, version 1.0.0)
[Writer] Foo (Log::WRITER_FOO)
===

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test analyzer";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -29,6 +29,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercises all plugin hooks";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -21,6 +21,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercises Log hooks";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo packet dumper";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo packet source";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -0,0 +1,16 @@
#include "Plugin.h"
namespace plugin { namespace Testing_NoPatchVersion { Plugin plugin; } }
using namespace plugin::Testing_NoPatchVersion;
plugin::Configuration Plugin::Configure()
{
plugin::Configuration config;
config.name = "Testing::NoPatchVersion";
config.description = "Testing a plugin without a specified patch version";
config.version.major = 0;
config.version.minor = 1;
return config;
}

View file

@ -0,0 +1,5 @@
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Testing NoPatchVersion
# @TEST-EXEC: cp -r %DIR/plugin-nopatchversion-plugin/* .
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
# @TEST-EXEC: BRO_PLUGIN_PATH=$(pwd) bro -N Testing::NoPatchVersion >> output
# @TEST-EXEC: btest-diff output

View file

@ -0,0 +1,17 @@
#include "Plugin.h"
namespace plugin { namespace Testing_WithPatchVersion { Plugin plugin; } }
using namespace plugin::Testing_WithPatchVersion;
plugin::Configuration Plugin::Configure()
{
plugin::Configuration config;
config.name = "Testing::WithPatchVersion";
config.description = "Testing a plugin with a specified patch version";
config.version.major = 0;
config.version.minor = 1;
config.version.patch = 4;
return config;
}

View file

@ -0,0 +1,5 @@
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Testing WithPatchVersion
# @TEST-EXEC: cp -r %DIR/plugin-withpatchversion-plugin/* .
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
# @TEST-EXEC: BRO_PLUGIN_PATH=$(pwd) bro -N Testing::WithPatchVersion >> output
# @TEST-EXEC: btest-diff output

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test analyzer";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -15,5 +15,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test input reader";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -19,6 +19,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercise Reporter Hook";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}

View file

@ -15,5 +15,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test logging writer";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}