Add optional bare-mode boolean flag to Supervisor's node configuration

When omitted, the node inherits the Supervisor's bare-mode
status. When true/false, the new Zeek node will enable/disable bare
mode, respectively. It continues to load any scripts passed at the
command line and in the additional scripts list already provided in
the node configuration.

Includes testcase.
This commit is contained in:
Christian Kreibich 2021-07-07 15:17:39 -07:00
parent efaa9ec3be
commit 7bee79b400
7 changed files with 108 additions and 0 deletions

View file

@ -1251,6 +1251,11 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node)
if ( affinity_val )
rval.cpu_affinity = affinity_val->AsInt();
const auto& bare_mode_val = node->GetField("bare_mode");
if ( bare_mode_val )
rval.bare_mode = bare_mode_val->AsBool();
auto scripts_val = node->GetField("scripts")->AsVectorVal();
for ( auto i = 0u; i < scripts_val->Size(); ++i )
@ -1324,6 +1329,9 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromJSON(std::string_view json)
if ( auto it = j.FindMember("cpu_affinity"); it != j.MemberEnd() )
rval.cpu_affinity = it->value.GetInt();
if ( auto it = j.FindMember("bare_mode"); it != j.MemberEnd() )
rval.bare_mode = it->value.GetBool();
auto& scripts = j["scripts"];
for ( auto it = scripts.Begin(); it != scripts.End(); ++it )
@ -1385,6 +1393,9 @@ RecordValPtr Supervisor::NodeConfig::ToRecord() const
if ( cpu_affinity )
rval->AssignField("cpu_affinity", *cpu_affinity);
if ( bare_mode )
rval->AssignField("bare_mode", *bare_mode);
auto st = rt->GetFieldType<VectorType>("scripts");
auto scripts_val = make_intrusive<VectorVal>(std::move(st));
@ -1590,6 +1601,9 @@ void SupervisedNode::Init(Options* options) const
options->filter_supervised_node_options();
if ( config.bare_mode )
options->bare_mode = *config.bare_mode;
if ( config.interface )
options->interface = *config.interface;

View file

@ -186,6 +186,11 @@ public:
* A cpu/core number to which the node will try to pin itself.
*/
std::optional<int> cpu_affinity;
/**
* Whether to start the node in bare mode. When not present, the
* node inherits the bare-mode status of the supervisor.
*/
std::optional<bool> bare_mode;
/**
* Additional script filename/paths that the node should load.
*/