Merge remote-tracking branch 'microsoft/master'

* microsoft/master: (71 commits)
  Clang formatting
  Mask ports before inserting them into the map
  Fix compiler warning from applied patch
  Remove statistics plugin in favor of stats bif
  Add EventHandler version of stats plugin
  Mark a few EventHandler methods const
  Changed implementation from std::map to std::unordered_map of Val.cc
  Removed const, Windows build is now working
  Added fixes suggested in PR
  Update src/packet_analysis/protocol/ip/IP.cc
  Apply suggestions from code review
  Clang format again but now with v13.0.1
  Rewrote usages of define(_MSC_VER) to ifdef _MSC_VER
  Clang format it all
  Fixed initial CR comments
  Add NEWS entry about Windows port
  Add a couple of extra unistd.h includes to fix a build failure
  Use std::chrono instead of gettimeofday
  Update libkqueue submodule [nomail]
  Don't call tokenize_string if the input string is empty
  ...
This commit is contained in:
Tim Wojtulewicz 2022-11-11 15:13:47 -07:00
commit a8fc63e182
86 changed files with 1001 additions and 261 deletions

View file

@ -3,8 +3,10 @@
#include "zeek/plugin/Manager.h"
#include <dirent.h>
#ifndef _MSC_VER
#include <dlfcn.h>
#include <glob.h>
#endif
#include <sys/stat.h>
#include <cerrno>
#include <climits> // for PATH_MAX
@ -56,13 +58,13 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
if ( dir.empty() )
return;
if ( dir.find(':') != string::npos )
if ( dir.find(path_list_separator) != string::npos )
{
// Split at ":".
std::stringstream s(dir);
std::string d;
while ( std::getline(s, d, ':') )
while ( std::getline(s, d, path_list_separator[0]) )
SearchDynamicPlugins(d);
return;
@ -160,6 +162,10 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found,
std::vector<std::string>* errors)
{
// Loading dynamic plugins is not currently supported on Windows platform.
#ifdef _MSC_VER
return false;
#else
errors->clear(); // caller should pass it in empty, but just to be sure
dynamic_plugin_map::iterator m = dynamic_plugins.find(util::strtolower(name));
@ -326,6 +332,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
m->second.clear();
return true;
#endif
}
void Manager::ActivateDynamicPlugin(const std::string& name)
@ -346,14 +353,21 @@ void Manager::ActivateDynamicPlugins(bool all)
// Activate plugins that were specifically requested.
for ( const auto& x : requested_plugins )
plugins_to_activate.emplace(x, false);
{
if ( ! x.empty() )
plugins_to_activate.emplace(x, false);
}
// Activate plugins that our environment tells us to.
vector<string> p;
util::tokenize_string(util::zeek_plugin_activate(), ",", &p);
std::string plugin_activate = util::zeek_plugin_activate();
if ( ! plugin_activate.empty() )
{
util::tokenize_string(util::zeek_plugin_activate(), ",", &p);
for ( const auto& x : p )
plugins_to_activate.emplace(x, true);
for ( const auto& x : p )
plugins_to_activate.emplace(x, true);
}
if ( all )
{
@ -911,32 +925,48 @@ void Manager::HookBroObjDtor(void* obj) const
if ( HavePluginForHook(META_HOOK_PRE) )
{
args.push_back(HookArgument(obj));
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
MetaHookPre(HOOK_BRO_OBJ_DTOR, args);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
hook_list* l = hooks[HOOK_BRO_OBJ_DTOR];
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
if ( l )
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
{
Plugin* p = (*i).second;
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
p->HookBroObjDtor(obj);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
if ( HavePluginForHook(META_HOOK_POST) )
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
MetaHookPost(HOOK_BRO_OBJ_DTOR, args, HookArgument());
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
void Manager::HookObjDtor(void* obj) const

View file

@ -77,7 +77,7 @@ public:
* This must be called only before InitPluginsPreScript().
*
* @param dir The directory to search for plugins. Multiple directories
* can be given by splitting them with ':'.
* can be given by separating them with zeek::util::path_list_separator.
*/
void SearchDynamicPlugins(const std::string& dir);

View file

@ -383,10 +383,14 @@ void Plugin::RequestEvent(EventHandlerPtr handler)
void Plugin::RequestBroObjDtor(Obj* obj)
{
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
plugin_mgr->RequestBroObjDtor(obj, this);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
void Plugin::RequestObjDtor(Obj* obj)

View file

@ -25,6 +25,10 @@ struct Field;
namespace zeek
{
#ifdef _MSC_VER
#undef VOID
#endif
// 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.
constexpr int PLUGIN_API_VERSION = 7;
@ -116,17 +120,23 @@ public:
// We force this to inline so that the API version gets hardcoded
// into the external plugin. (Technically, it's not a "force", just a
// strong hint.). The attribute seems generally available.
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
inline Configuration() __attribute__((always_inline))
{
bro_version = ZEEK_PLUGIN_ZEEK_VERSION;
zeek_version = ZEEK_PLUGIN_ZEEK_VERSION;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Configuration(Configuration&& c)
{
bro_version = std::move(c.bro_version);
@ -136,10 +146,14 @@ public:
description = std::move(c.description);
version = std::move(c.version);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Configuration(const Configuration& c)
{
bro_version = c.bro_version;
@ -149,10 +163,14 @@ public:
description = c.description;
version = c.version;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Configuration& operator=(Configuration&& c)
{
bro_version = std::move(c.bro_version);
@ -164,10 +182,14 @@ public:
return *this;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Configuration& operator=(const Configuration& c)
{
bro_version = c.bro_version;
@ -179,12 +201,18 @@ public:
return *this;
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
~Configuration() { }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
/**
* One can assign ZEEK_PLUGIN_ZEEK_VERSION to this to catch