From 2e043c0ff6e31f4dfaef81ddcddb1fe596fd0850 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 12:11:59 -0800 Subject: [PATCH 01/12] Creating the installation directory for plugins at install time. --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13c6e45006..f13a4a6ebf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -408,6 +408,9 @@ add_dependencies(bro bif_loader_plugins) # Install *.bif.bro. install(DIRECTORY ${CMAKE_BINARY_DIR}/scripts/base/bif DESTINATION ${BRO_SCRIPT_INSTALL_PATH}/base) +# Create plugin directory at install time. +install(DIRECTORY DESTINATION ${BRO_PLUGIN_INSTALL_PATH}) + # Make clean removes the bif directory. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/scripts/base/bif) From ff16f6215ad6f3cf8208b4e35756b75410a38403 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 12:49:54 -0800 Subject: [PATCH 02/12] Removing setting installation plugin path from bro-path-dev.sh . Also, adding to existing BRO_PLUGIN_PATH rather than replacing. Addresses #1312 --- CMakeLists.txt | 4 ++-- aux/bro-aux | 2 +- cmake | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0ff6c09d4..04ac197f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,12 +31,12 @@ configure_file(bro-path-dev.in ${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev.sh "export BROPATH=`${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev`\n" - "export BRO_PLUGIN_PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src:${BRO_PLUGIN_INSTALL_PATH}\"\n" + "export BRO_PLUGIN_PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src\":${BRO_PLUGIN_PATH}\n" "export PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src\":$PATH\n") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev.csh "setenv BROPATH `${CMAKE_CURRENT_BINARY_DIR}/bro-path-dev`\n" - "setenv BRO_PLUGIN_PATH \"${CMAKE_CURRENT_BINARY_DIR}/src:${BRO_PLUGIN_INSTALL_PATH}\"\n" + "setenv BRO_PLUGIN_PATH \"${CMAKE_CURRENT_BINARY_DIR}/src\":${BRO_PLUGIN_PATH}\n" "setenv PATH \"${CMAKE_CURRENT_BINARY_DIR}/src\":$PATH\n") file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1) diff --git a/aux/bro-aux b/aux/bro-aux index 3714d3594c..c011f3a724 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit 3714d3594ce0d2b8a757c04e6e7d901d6b559915 +Subproject commit c011f3a7243a8a1dc8be7eff2f45799be7ee85f4 diff --git a/cmake b/cmake index 1316c07f70..0147a2e05b 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 1316c07f7059647b6c4a496ea36e4b83bb5d8f0f +Subproject commit 0147a2e05b613a044ac30374874acdb8bc216feb From d36422fde156caf7d4f2cddf3883d1812f3fb7e7 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 13:37:59 -0800 Subject: [PATCH 03/12] Explicitly removing some old scripts on install. Some scripts have moved into plugins, but may cause confusion if they stick around from old installations. Explicitl removing them on install. We had this problem before in other cases, and it should be ok to help people upgrading a bit here, even though hardcoding these isn't great. --- src/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f13a4a6ebf..6d24172b97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -414,3 +414,12 @@ install(DIRECTORY DESTINATION ${BRO_PLUGIN_INSTALL_PATH}) # Make clean removes the bif directory. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/scripts/base/bif) +# Remove some stale files and scripts that previous Bro versions put in +# place, yet make confuse us now. This makes upgrading easier. +install(CODE " + file(REMOVE_RECURSE + ${BRO_SCRIPT_INSTALL_PATH}/base/frameworks/logging/writers/dataseries.bro + ${BRO_SCRIPT_INSTALL_PATH}/base/frameworks/logging/writers/elasticsearch.bro + ${BRO_SCRIPT_INSTALL_PATH}/policy/tuning/logs-to-elasticsearch.bro + ) +") From ab3cdf494a216cd20d528f982af3834ff4623695 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 13:40:21 -0800 Subject: [PATCH 04/12] Updating submodules. --- aux/bro-aux | 2 +- cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aux/bro-aux b/aux/bro-aux index c011f3a724..63675de3cc 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit c011f3a7243a8a1dc8be7eff2f45799be7ee85f4 +Subproject commit 63675de3cc7bc3eb2a3645860224c372d3f7f36a diff --git a/cmake b/cmake index 0147a2e05b..9623367210 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 0147a2e05b613a044ac30374874acdb8bc216feb +Subproject commit 962336721040fdf55a6b264f8bbc84153b54d9a5 From 0f96d0625273f748793988f67756b4317c1e074e Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 14:24:32 -0800 Subject: [PATCH 05/12] 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. --- src/plugin/Manager.cc | 22 ++++++++++++---------- src/util.cc | 7 +++++++ src/util.h | 3 +++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index ab0b85676b..b891a0faab 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -79,18 +79,19 @@ void Manager::SearchDynamicPlugins(const std::string& dir) std::string name; std::getline(in, name); strstrip(name); + string lower_name = strtolower(name); if ( name.empty() ) reporter->FatalError("empty plugin magic file %s", magic.c_str()); - if ( dynamic_plugins.find(name) != dynamic_plugins.end() ) + if ( dynamic_plugins.find(lower_name) != dynamic_plugins.end() ) { DBG_LOG(DBG_PLUGINS, "Found already known plugin %s in %s, ignoring", name.c_str(), dir.c_str()); return; } // Record it, so that we can later activate it. - dynamic_plugins.insert(std::make_pair(name, dir)); + dynamic_plugins.insert(std::make_pair(lower_name, dir)); DBG_LOG(DBG_PLUGINS, "Found plugin %s in %s", name.c_str(), dir.c_str()); return; @@ -135,7 +136,7 @@ void Manager::SearchDynamicPlugins(const std::string& dir) bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found) { - dynamic_plugin_map::iterator m = dynamic_plugins.find(name); + dynamic_plugin_map::iterator m = dynamic_plugins.find(strtolower(name)); if ( m == dynamic_plugins.end() ) { @@ -230,7 +231,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_ // Make sure the name the plugin reports is consistent with // what we expect from its magic file. - if ( string(current_plugin->Name()) != name ) + if ( strtolower(current_plugin->Name()) != strtolower(name) ) reporter->FatalError("inconsistent plugin name: %s vs %s", current_plugin->Name().c_str(), name.c_str()); @@ -297,7 +298,7 @@ void Manager::UpdateInputFiles() static bool plugin_cmp(const Plugin* a, const Plugin* b) { - return a->Name() < b->Name(); + return strtolower(a->Name()) < strtolower(b->Name()); } void Manager::RegisterPlugin(Plugin *plugin) @@ -318,10 +319,11 @@ void Manager::RegisterBifFile(const char* plugin, bif_init_func c) { bif_init_func_map* bifs = BifFilesInternal(); - bif_init_func_map::iterator i = bifs->find(plugin); + std::string lower_plugin = strtolower(plugin); + bif_init_func_map::iterator i = bifs->find(lower_plugin); if ( i == bifs->end() ) - i = bifs->insert(std::make_pair(std::string(plugin), new bif_init_func_list())).first; + i = bifs->insert(std::make_pair(lower_plugin, new bif_init_func_list())).first; i->second->push_back(c); } @@ -348,7 +350,7 @@ void Manager::InitBifs() for ( plugin_list::iterator i = Manager::ActivePluginsInternal()->begin(); i != Manager::ActivePluginsInternal()->end(); i++ ) { - bif_init_func_map::const_iterator b = bifs->find((*i)->Name()); + bif_init_func_map::const_iterator b = bifs->find(strtolower((*i)->Name())); if ( b != bifs->end() ) { @@ -397,7 +399,7 @@ Manager::inactive_plugin_list Manager::InactivePlugins() const for ( plugin_list::const_iterator j = all->begin(); j != all->end(); j++ ) { - if ( (*i).first == (*j)->Name() ) + if ( (*i).first == strtolower((*j)->Name()) ) { found = true; break; @@ -434,7 +436,7 @@ Manager::bif_init_func_map* Manager::BifFilesInternal() static bool hook_cmp(std::pair a, std::pair b) { if ( a.first == b.first ) - return a.second->Name() < a.second->Name(); + return strtolower(a.second->Name()) < strtolower(a.second->Name()); // Reverse sort. return a.first > b.first; diff --git a/src/util.cc b/src/util.cc index 60a92af45f..ac2a942ed3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -541,6 +541,13 @@ bool is_printable(const char* s, int len) return true; } +std::string strtolower(const std::string& s) + { + std::string t = s; + std::transform(t.begin(), t.end(), t.begin(), ::tolower); + return t; + } + const char* fmt_bytes(const char* data, int len) { static char buf[1024]; diff --git a/src/util.h b/src/util.h index 50c33d5608..f65e0fb7d0 100644 --- a/src/util.h +++ b/src/util.h @@ -159,6 +159,9 @@ int strstr_n(const int big_len, const unsigned char* big, extern int fputs(int len, const char* s, FILE* fp); extern bool is_printable(const char* s, int len); +// Return a lower-cased version of the string. +extern std::string strtolower(const std::string& s); + extern const char* fmt_bytes(const char* data, int len); // Note: returns a pointer into a shared buffer. From b6bbf90643e272814174b6eb065fdbab60e1d938 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 14:32:08 -0800 Subject: [PATCH 06/12] Updating plugin tests. The init-plugin scripts now expects a destination directory. Normally that would be a new subdirectory, but for the tests to keep working we can also put it right into the current directory. --- testing/btest/Baseline/plugins.api-version-mismatch/output | 2 +- testing/btest/plugins/api-version-mismatch.sh | 2 +- testing/btest/plugins/bifs-and-scripts-install.sh | 4 ++-- testing/btest/plugins/bifs-and-scripts.sh | 2 +- testing/btest/plugins/file.bro | 2 +- testing/btest/plugins/hooks.bro | 2 +- testing/btest/plugins/init-plugin.bro | 2 +- testing/btest/plugins/pktdumper.bro | 2 +- testing/btest/plugins/pktsrc.bro | 2 +- testing/btest/plugins/protocol.bro | 2 +- testing/btest/plugins/reader.bro | 2 +- testing/btest/plugins/writer.bro | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/testing/btest/Baseline/plugins.api-version-mismatch/output b/testing/btest/Baseline/plugins.api-version-mismatch/output index 1e4dae5e65..04f3cdd3a2 100644 --- a/testing/btest/Baseline/plugins.api-version-mismatch/output +++ b/testing/btest/Baseline/plugins.api-version-mismatch/output @@ -1 +1 @@ -fatal error in /home/robin/bro/master/scripts/base/init-bare.bro, line 1: plugin's API version does not match Bro (expected 2, got 42 in /home/robin/bro/master/testing/btest/.tmp/plugins.api-version-mismatch//lib/XXX) +fatal error in /home/robin/bro/plugins/scripts/base/init-bare.bro, line 1: plugin's API version does not match Bro (expected 2, got 42 in /home/robin/bro/plugins/testing/btest/.tmp/plugins.api-version-mismatch/build//lib/XXX) diff --git a/testing/btest/plugins/api-version-mismatch.sh b/testing/btest/plugins/api-version-mismatch.sh index cfb4269946..2483582359 100644 --- a/testing/btest/plugins/api-version-mismatch.sh +++ b/testing/btest/plugins/api-version-mismatch.sh @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: bash %INPUT # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC-FAIL: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >tmp 2>&1 diff --git a/testing/btest/plugins/bifs-and-scripts-install.sh b/testing/btest/plugins/bifs-and-scripts-install.sh index 627eb0f2c5..60c754f8ff 100644 --- a/testing/btest/plugins/bifs-and-scripts-install.sh +++ b/testing/btest/plugins/bifs-and-scripts-install.sh @@ -1,10 +1,10 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: bash %INPUT # @TEST-EXEC: ./configure --bro-dist=${DIST} --install-root=`pwd`/test-install # @TEST-EXEC: make # @TEST-EXEC: make install # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd`/test-install bro -NN Demo::Foo >>output -# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro demo/foo -r $TRACES/empty.trace >>output +# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd`/test-install bro demo/foo -r $TRACES/empty.trace >>output # @TEST-EXEC: TEST_DIFF_CANONIFIER= btest-diff output mkdir -p scripts/demo/foo/base/ diff --git a/testing/btest/plugins/bifs-and-scripts.sh b/testing/btest/plugins/bifs-and-scripts.sh index cf49642766..25f2dbeb5e 100644 --- a/testing/btest/plugins/bifs-and-scripts.sh +++ b/testing/btest/plugins/bifs-and-scripts.sh @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: bash %INPUT # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/file.bro b/testing/btest/plugins/file.bro index 7d25cab538..29724aa8a4 100644 --- a/testing/btest/plugins/file.bro +++ b/testing/btest/plugins/file.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/file-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/hooks.bro b/testing/btest/plugins/hooks.bro index 786e6ccc88..c1dec2f4c3 100644 --- a/testing/btest/plugins/hooks.bro +++ b/testing/btest/plugins/hooks.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Hooks +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Hooks # @TEST-EXEC: cp -r %DIR/hooks-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -r $TRACES/http/get.trace %INPUT 2>&1 | $SCRIPTS/diff-remove-abspath | sort | uniq >output diff --git a/testing/btest/plugins/init-plugin.bro b/testing/btest/plugins/init-plugin.bro index 2fffa88f2c..a4ebf7b00c 100644 --- a/testing/btest/plugins/init-plugin.bro +++ b/testing/btest/plugins/init-plugin.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output # @TEST-EXEC: echo === >>output diff --git a/testing/btest/plugins/pktdumper.bro b/testing/btest/plugins/pktdumper.bro index 29b69acadd..d9bd91a5a6 100644 --- a/testing/btest/plugins/pktdumper.bro +++ b/testing/btest/plugins/pktdumper.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/pktdumper-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/pktsrc.bro b/testing/btest/plugins/pktsrc.bro index 349e361664..a13596e245 100644 --- a/testing/btest/plugins/pktsrc.bro +++ b/testing/btest/plugins/pktsrc.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/pktsrc-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/protocol.bro b/testing/btest/plugins/protocol.bro index 671edb6cf1..8a6c2a6399 100644 --- a/testing/btest/plugins/protocol.bro +++ b/testing/btest/plugins/protocol.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/protocol-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/reader.bro b/testing/btest/plugins/reader.bro index 5065678c2e..ec9b6cf046 100644 --- a/testing/btest/plugins/reader.bro +++ b/testing/btest/plugins/reader.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/reader-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output diff --git a/testing/btest/plugins/writer.bro b/testing/btest/plugins/writer.bro index f2e74ad667..8cecff6843 100644 --- a/testing/btest/plugins/writer.bro +++ b/testing/btest/plugins/writer.bro @@ -1,4 +1,4 @@ -# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo +# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Demo Foo # @TEST-EXEC: cp -r %DIR/writer-plugin/* . # @TEST-EXEC: ./configure --bro-dist=${DIST} && make # @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output From bdb2707a08a5772d9de7371dc1050f0d5db4bb56 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 16 Feb 2015 20:05:30 -0800 Subject: [PATCH 07/12] Updating submodules. --- aux/bro-aux | 2 +- aux/plugins | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aux/bro-aux b/aux/bro-aux index 63675de3cc..8c37b26823 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit 63675de3cc7bc3eb2a3645860224c372d3f7f36a +Subproject commit 8c37b26823ada9c77614b2f8f781c11c8fe3d078 diff --git a/aux/plugins b/aux/plugins index ad600b5bdc..9072e28935 160000 --- a/aux/plugins +++ b/aux/plugins @@ -1 +1 @@ -Subproject commit ad600b5bdcd56a2723e323c0f2c8e1708956ca4f +Subproject commit 9072e28935ba85b6938fe946d7aa23cb58ee1566 From 9025b425344c150b5c06431b63cf3995c60916bb Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Tue, 17 Feb 2015 12:56:36 -0800 Subject: [PATCH 08/12] Updating submodule. --- aux/bro-aux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aux/bro-aux b/aux/bro-aux index 8c37b26823..fa145348ab 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit 8c37b26823ada9c77614b2f8f781c11c8fe3d078 +Subproject commit fa145348abe15dcd5f8e52cc96e1fb758c092e36 From 818ba9127f4856f1e83c5e42eba0117adfeafdbe Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Tue, 17 Feb 2015 13:59:21 -0800 Subject: [PATCH 09/12] Update submodules. --- aux/bro-aux | 2 +- cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aux/bro-aux b/aux/bro-aux index fa145348ab..c409d529cf 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit fa145348abe15dcd5f8e52cc96e1fb758c092e36 +Subproject commit c409d529cf0c3fa851d4720914badb04d0c6b7c2 diff --git a/cmake b/cmake index 9623367210..5e4e3507e2 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 962336721040fdf55a6b264f8bbc84153b54d9a5 +Subproject commit 5e4e3507e280c393778fd55fb0124217067e0078 From 093d4069206b9ae7ced009241cdd8e70aec1c4ec Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Tue, 17 Feb 2015 14:03:05 -0800 Subject: [PATCH 10/12] Updating plugin docs to recent changes. --- doc/devel/plugins.rst | 97 ++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/doc/devel/plugins.rst b/doc/devel/plugins.rst index c703345891..66ffba101f 100644 --- a/doc/devel/plugins.rst +++ b/doc/devel/plugins.rst @@ -3,7 +3,7 @@ Writing Bro Plugins =================== -Bro is internally moving to a plugin structure that enables extending +Bro internally provides plugin API that enables extending the system dynamically, without modifying the core code base. That way custom code remains self-contained and can be maintained, compiled, and installed independently. Currently, plugins can add the following @@ -42,13 +42,13 @@ certain structure. To get started, Bro's distribution provides a helper script ``aux/bro-aux/plugin-support/init-plugin`` that creates a skeleton plugin that can then be customized. Let's use that:: - # mkdir rot13-plugin - # cd rot13-plugin - # init-plugin Demo Rot13 + # init-plugin ./rot13-plugin Demo Rot13 -As you can see the script takes two arguments. The first is a -namespace the plugin will live in, and the second a descriptive name -for the plugin itself. Bro uses the combination of the two to identify +As you can see the script takes three arguments. The first is a +directory inside which the plugin skeleton will be create; it +shouldn't exist it. The second is namespace the plugin will live in, +and the third a descriptive name for the plugin itself relative to the +namespace. Bro uses the combination of namespace and name to identify a plugin. The namespace serves to avoid naming conflicts between plugins written by independent developers; pick, e.g., the name of your organisation. The namespace ``Bro`` is reserved for functionality @@ -82,18 +82,22 @@ The syntax of this file is just like any other ``*.bif`` file; we won't go into it here. Now we can already compile our plugin, we just need to tell the -configure script put in place by ``init-plugin`` where the Bro source -tree is located (Bro needs to have been built there first):: +configure script that ``init-plugin`` put in place where the Bro +source tree is located (Bro needs to have been built there first):: + # cd rot13-plugin # ./configure --bro-dist=/path/to/bro/dist && make [... cmake output ...] -Now our ``rot13-plugin`` directory has everything that it needs -for Bro to recognize it as a dynamic plugin. Once we point Bro to it, -it will pull it in automatically, as we can check with the ``-N`` +This builds the plugin in a subdirectory ``build/``. In fact, that +subdirectory *becomes* the plugin: when ``make`` finishes, ``build/`` +has everything it needs for Bro to recognize it as a dynamic plugin. + +Let's try that. Once we point Bro to the ``build/`` directory, it will +pull in our new plugin automatically, as we can check with the ``-N`` option:: - # export BRO_PLUGIN_PATH=/path/to/rot13-plugin + # export BRO_PLUGIN_PATH=/path/to/rot13-plugin/build # bro -N [...] Plugin: Demo::Rot13 - (dynamic, version 1) @@ -153,24 +157,28 @@ Once we install it, it works again:: The installed version went into ``/lib/bro/plugins/Demo_Rot13``. -We can distribute the plugin in either source or binary form by using -the Makefile's ``sdist`` and ``bdist`` target, respectively. Both -create corrsponding tarballs:: +One can distribute the plugin independently of Bro for others to use. +To distribute in source form, just remove the ``build/`` (``make +distclean`` does that) and then tar up the whole ``rot13-plugin/`` +directory. Others then follow the same process as above after +unpacking. To distribute the plugin in binary form, the build process +conviniently creates a corresponding tarball in ``build/dist/``. In +this case, it's called ``Demo_Rot13-0.1.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 +further files by specifying them in the plugin's ``CMakeLists.txt`` +through the ``bro_plugin_dist_files`` macro; the skeleton does that +for ``README``, ``VERSION``, ``CHANGES``, and ``COPYING``. To use the +plugin through the binary tarball, just unpack it and point +``BRO_PLUGIN_PATH`` there; or copy it into +``/lib/bro/plugins/`` directly. - # make sdist - [...] - Source distribution in build/sdist/Demo_Rot13.tar.gz - - # make bdist - [...] - Binary distribution in build/Demo_Rot13-darwin-x86_64.tar.gz - -The source archive will contain everything in the plugin directory -except any generated files. The binary archive will contain anything -needed to install and run the plugin, i.e., just what ``make install`` -puts into place as well. As the binary distribution is -platform-dependent, its name includes the OS and architecture the -plugin was built on. +Before distributing your plugin, you should edit some of the meta +files that ``init-plugin`` puts in place. Edit ``README`` and +``VERSION``, and update ``CHANGES`` when you make changes. Also put a +license file in place as ``COPYING``; if BSD is fine, you find a +template in ``COPYING.edit-me``. Plugin Directory Layout ======================= @@ -179,7 +187,7 @@ A plugin's directory needs to follow a set of conventions so that Bro (1) recognizes it as a plugin, and (2) knows what to load. While ``init-plugin`` takes care of most of this, the following is the full story. We'll use ```` to represent a plugin's top-level -directory. +directory. With the skeleton, ```` corresponds to ``build/``. ``/__bro_plugin__`` A file that marks a directory as containing a Bro plugin. The file @@ -205,6 +213,8 @@ directory. Directory with auto-generated Bro scripts that declare the plugin's bif elements. The files here are produced by ``bifcl``. +Any other files in ```` are ignored by Bro. + By convention, a plugin should put its custom scripts into sub folders of ``scripts/``, i.e., ``scripts//