mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 09:38:19 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/913-plugin-debug-stream-validation'
One change: turns out that zeek-config isn't in PATH, so I prefixed it with $BUILD. * origin/topic/awelzel/913-plugin-debug-stream-validation: zeek-setup: Validate plugin debug streams during startup
This commit is contained in:
commit
e8e6fa8fed
7 changed files with 64 additions and 4 deletions
5
CHANGES
5
CHANGES
|
@ -1,3 +1,8 @@
|
||||||
|
5.1.0-dev.200 | 2022-07-08 09:29:04 +0200
|
||||||
|
|
||||||
|
* GH-913: zeek-setup: Validate plugin debug streams during startup.
|
||||||
|
(Arne Welzel, Corelight)
|
||||||
|
|
||||||
5.1.0-dev.198 | 2022-07-07 14:19:23 -0700
|
5.1.0-dev.198 | 2022-07-07 14:19:23 -0700
|
||||||
|
|
||||||
* Bump broker and zeek-archiver submodules to pull in CI updates (Christian Kreibich, Corelight)
|
* Bump broker and zeek-archiver submodules to pull in CI updates (Christian Kreibich, Corelight)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
5.1.0-dev.198
|
5.1.0-dev.200
|
||||||
|
|
|
@ -115,7 +115,7 @@ void DebugLogger::EnableStreams(const char* s)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( strncmp(tok, "plugin-", strlen("plugin-")) == 0 )
|
if ( util::starts_with(tok, "plugin-") )
|
||||||
{
|
{
|
||||||
// Cannot verify this at this time, plugins may not
|
// Cannot verify this at this time, plugins may not
|
||||||
// have been loaded.
|
// have been loaded.
|
||||||
|
@ -144,6 +144,29 @@ void DebugLogger::EnableStreams(const char* s)
|
||||||
delete[] tmp;
|
delete[] tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DebugLogger::CheckStreams(const std::set<std::string>& plugin_names)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
std::set<std::string> available_plugin_streams;
|
||||||
|
for ( const auto& p : plugin_names )
|
||||||
|
available_plugin_streams.insert(PluginStreamName(p));
|
||||||
|
|
||||||
|
for ( auto const& stream : enabled_streams )
|
||||||
|
{
|
||||||
|
if ( ! util::starts_with(stream, "plugin-") )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( available_plugin_streams.count(stream) == 0 )
|
||||||
|
{
|
||||||
|
reporter->Error("No plugin debug stream '%s' found", stream.c_str());
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
void DebugLogger::Log(DebugStream stream, const char* fmt, ...)
|
void DebugLogger::Log(DebugStream stream, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
Stream* g = &streams[int(stream)];
|
Stream* g = &streams[int(stream)];
|
||||||
|
@ -168,8 +191,7 @@ void DebugLogger::Log(DebugStream stream, const char* fmt, ...)
|
||||||
|
|
||||||
void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...)
|
void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
std::string tok = std::string("plugin-") + plugin.Name();
|
std::string tok = PluginStreamName(plugin.Name());
|
||||||
tok = util::strreplace(tok, "::", "-");
|
|
||||||
|
|
||||||
if ( enabled_streams.find(tok) == enabled_streams.end() )
|
if ( enabled_streams.find(tok) == enabled_streams.end() )
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "zeek/util.h"
|
||||||
|
|
||||||
#define DBG_LOG(stream, args...) \
|
#define DBG_LOG(stream, args...) \
|
||||||
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
|
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
|
||||||
::zeek::detail::debug_logger.Log(stream, args)
|
::zeek::detail::debug_logger.Log(stream, args)
|
||||||
|
@ -84,6 +86,9 @@ public:
|
||||||
// Takes comma-seperated list of stream prefixes.
|
// Takes comma-seperated list of stream prefixes.
|
||||||
void EnableStreams(const char* streams);
|
void EnableStreams(const char* streams);
|
||||||
|
|
||||||
|
// Check the enabled streams for invalid ones.
|
||||||
|
bool CheckStreams(const std::set<std::string>& plugin_names);
|
||||||
|
|
||||||
bool IsEnabled(DebugStream stream) const { return streams[int(stream)].enabled; }
|
bool IsEnabled(DebugStream stream) const { return streams[int(stream)].enabled; }
|
||||||
|
|
||||||
void SetVerbose(bool arg_verbose) { verbose = arg_verbose; }
|
void SetVerbose(bool arg_verbose) { verbose = arg_verbose; }
|
||||||
|
@ -105,6 +110,11 @@ private:
|
||||||
std::set<std::string> enabled_streams;
|
std::set<std::string> enabled_streams;
|
||||||
|
|
||||||
static Stream streams[NUM_DBGS];
|
static Stream streams[NUM_DBGS];
|
||||||
|
|
||||||
|
const std::string PluginStreamName(const std::string& plugin_name)
|
||||||
|
{
|
||||||
|
return "plugin-" + util::strreplace(plugin_name, "::", "-");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DebugLogger debug_logger;
|
extern DebugLogger debug_logger;
|
||||||
|
|
|
@ -847,6 +847,20 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
||||||
exit(success ? 0 : 1);
|
exit(success ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
// Check debug streams. Specifically that all plugin-
|
||||||
|
// streams are valid now that the active plugins are known.
|
||||||
|
std::set<std::string> active_plugins;
|
||||||
|
for ( const auto p : plugin_mgr->ActivePlugins() )
|
||||||
|
active_plugins.insert(p->Name());
|
||||||
|
|
||||||
|
if ( ! debug_logger.CheckStreams(active_plugins) )
|
||||||
|
{
|
||||||
|
early_shutdown();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
packet_mgr->InitPostScript(options.unprocessed_output_file.value_or(""));
|
packet_mgr->InitPostScript(options.unprocessed_output_file.value_or(""));
|
||||||
analyzer_mgr->InitPostScript();
|
analyzer_mgr->InitPostScript();
|
||||||
file_mgr->InitPostScript();
|
file_mgr->InitPostScript();
|
||||||
|
|
2
testing/btest/Baseline/plugins.debug-streams/zeek.stderr
Normal file
2
testing/btest/Baseline/plugins.debug-streams/zeek.stderr
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <command line>, line 3: No plugin debug stream 'plugin-zeek-http' found
|
7
testing/btest/plugins/debug-streams.zeek
Normal file
7
testing/btest/plugins/debug-streams.zeek
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This requires Zeek with debug streams support.
|
||||||
|
# @TEST-REQUIRES: test "$($BUILD/zeek-config --build_type)" = "debug"
|
||||||
|
|
||||||
|
# @TEST-EXEC: zeek -B plugin-Zeek-HTTP -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
# @TEST-EXEC-FAIL: zeek -B plugin-zeek-http -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
|
||||||
|
# @TEST-EXEC: btest-diff zeek.stderr
|
Loading…
Add table
Add a link
Reference in a new issue