Conn: Add InitPostScript() and conn_id_ctx singleton

This commit is contained in:
Arne Welzel 2025-07-24 16:00:54 +02:00
parent a2922cdde9
commit eba6355b84
3 changed files with 17 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include <cctype> #include <cctype>
#include "zeek/Desc.h" #include "zeek/Desc.h"
#include "zeek/ID.h"
#include "zeek/NetVar.h" #include "zeek/NetVar.h"
#include "zeek/Reporter.h" #include "zeek/Reporter.h"
#include "zeek/RunState.h" #include "zeek/RunState.h"
@ -22,6 +23,12 @@ namespace zeek {
uint64_t Connection::total_connections = 0; uint64_t Connection::total_connections = 0;
uint64_t Connection::current_connections = 0; uint64_t Connection::current_connections = 0;
zeek::RecordValPtr Connection::conn_id_ctx_singleton;
void Connection::InitPostScript() {
if ( id::conn_id_ctx->NumFields() == 0 )
conn_id_ctx_singleton = zeek::make_intrusive<zeek::RecordVal>(id::conn_id_ctx);
}
Connection::Connection(zeek::IPBasedConnKeyPtr k, double t, uint32_t flow, const Packet* pkt) Connection::Connection(zeek::IPBasedConnKeyPtr k, double t, uint32_t flow, const Packet* pkt)
: Session(t, connection_timeout, connection_status_update, detail::connection_status_update_interval), : Session(t, connection_timeout, connection_status_update, detail::connection_status_update_interval),

View file

@ -209,6 +209,9 @@ public:
// Returns true once Done() is called. // Returns true once Done() is called.
bool IsFinished() { return finished; } bool IsFinished() { return finished; }
// Runs after all scripts have been parsed.
static void InitPostScript();
private: private:
// Common initialization for the constructors. This can move back into the // Common initialization for the constructors. This can move back into the
// (sole) constructor when we remove the deprecated one in 8.1. // (sole) constructor when we remove the deprecated one in 8.1.
@ -244,6 +247,11 @@ private:
// Count number of connections. // Count number of connections.
static uint64_t total_connections; static uint64_t total_connections;
static uint64_t current_connections; static uint64_t current_connections;
// When the conn_id_ctx record type has no fields,
// this holds a singleton record value for it that
// is shared among all conn_id record values.
static RecordValPtr conn_id_ctx_singleton;
}; };
// The following is used by script optimization. // The following is used by script optimization.

View file

@ -25,6 +25,7 @@
#include <binpac.h> #include <binpac.h>
#include "zeek/Conn.h"
#include "zeek/DNS_Mgr.h" #include "zeek/DNS_Mgr.h"
#include "zeek/Debug.h" #include "zeek/Debug.h"
#include "zeek/Desc.h" #include "zeek/Desc.h"
@ -842,6 +843,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
exit(1); exit(1);
RecordType::InitPostScript(); RecordType::InitPostScript();
Connection::InitPostScript();
conn_key_mgr->InitPostScript(); conn_key_mgr->InitPostScript();
telemetry_mgr->InitPostScript(); telemetry_mgr->InitPostScript();