From 103396f6d32fa92e4087fe700b10854aa4488979 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 8 Aug 2011 13:49:50 -0700 Subject: [PATCH] Communication must now be enabled explicitly. The communication subsystem is now disabled until a new BiF, enable_communication(), is called. The base scripts do this automatically when either a Communication::Node is defined, or Bro is asked to listen for incoming connections. --- .../base/frameworks/communication/main.bro | 3 +++ .../frameworks/communication/listen-clear.bro | 1 + .../frameworks/communication/listen-ssl.bro | 1 + src/Expr.cc | 26 ------------------- src/Expr.h | 1 - src/RemoteSerializer.cc | 7 ----- src/RemoteSerializer.h | 4 --- src/bro.bif | 24 +++++++++++++++-- src/main.cc | 3 --- 9 files changed, 27 insertions(+), 43 deletions(-) diff --git a/scripts/base/frameworks/communication/main.bro b/scripts/base/frameworks/communication/main.bro index 6cc9812b47..73e6086f97 100644 --- a/scripts/base/frameworks/communication/main.bro +++ b/scripts/base/frameworks/communication/main.bro @@ -108,6 +108,9 @@ const src_names = { event bro_init() { Log::create_stream(COMMUNICATION, [$columns=Info]); + + if ( |nodes| > 0 ) + enable_communication(); } function do_script_log_common(level: count, src: count, msg: string) diff --git a/scripts/policy/frameworks/communication/listen-clear.bro b/scripts/policy/frameworks/communication/listen-clear.bro index 4f96414172..1854e12f56 100644 --- a/scripts/policy/frameworks/communication/listen-clear.bro +++ b/scripts/policy/frameworks/communication/listen-clear.bro @@ -13,5 +13,6 @@ export { event bro_init() &priority=-10 { + enable_communication(); listen(listen_if_clear, listen_port_clear, F); } diff --git a/scripts/policy/frameworks/communication/listen-ssl.bro b/scripts/policy/frameworks/communication/listen-ssl.bro index 32c5f747c2..fe6304206f 100644 --- a/scripts/policy/frameworks/communication/listen-ssl.bro +++ b/scripts/policy/frameworks/communication/listen-ssl.bro @@ -14,5 +14,6 @@ export { event bro_init() &priority=-10 { + enable_communication(); listen(listen_if_ssl, listen_port_ssl, T); } diff --git a/src/Expr.cc b/src/Expr.cc index c142026123..54cd8f6ff4 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -231,7 +231,6 @@ bool Expr::DoUnserialize(UnserialInfo* info) NameExpr::NameExpr(ID* arg_id) : Expr(EXPR_NAME) { id = arg_id; - ReferenceID(); SetType(id->Type()->Ref()); EventHandler* h = event_registry->Lookup(id->Name()); @@ -244,29 +243,6 @@ NameExpr::~NameExpr() Unref(id); } -void NameExpr::ReferenceID() - { - // ### This is a hack. We check whether one of the remote serializer's - // built-in functions is referenced. If so, we activate the serializer. - // A better solution would be to either (1) a generic mechanism in - // which have (internal) attributes associated with identifiers and - // as we see references to the identifiers, we do bookkeeping - // associated with their attribute (so in this case the attribute - // would be "flag that inter-Bro communication is being used"), - // or (2) after the parse is done, we'd query whether these - // particular identifiers were seen, rather than doing the test - // here for every NameExpr we create. - if ( id->Type()->Tag() == TYPE_FUNC ) - { - const char* const* builtins = remote_serializer->GetBuiltins(); - while( *builtins ) - { - if ( streq(id->Name(), *builtins++) ) - using_communication = true; - } - } - } - Expr* NameExpr::Simplify(SimplifyType simp_type) { if ( simp_type != SIMPLIFY_LHS && id->IsConst() ) @@ -393,8 +369,6 @@ bool NameExpr::DoUnserialize(UnserialInfo* info) if ( ! id ) return false; - ReferenceID(); - return true; } diff --git a/src/Expr.h b/src/Expr.h index 0f6ee67106..2e5d5b637a 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -217,7 +217,6 @@ protected: friend class Expr; NameExpr() { id = 0; } - void ReferenceID(); void ExprDescribe(ODesc* d) const; DECLARE_SERIAL(NameExpr); diff --git a/src/RemoteSerializer.cc b/src/RemoteSerializer.cc index a80157767f..814f387718 100644 --- a/src/RemoteSerializer.cc +++ b/src/RemoteSerializer.cc @@ -3060,13 +3060,6 @@ bool RemoteSerializer::IsActive() return false; } - -const char* const* RemoteSerializer::GetBuiltins() const - { - static const char* builtins[] = { "connect", "listen", 0 }; - return builtins; - } - void RemoteSerializer::ReportError(const char* msg) { if ( current_peer && current_peer->phase != Peer::SETUP ) diff --git a/src/RemoteSerializer.h b/src/RemoteSerializer.h index 18284463a1..5374e6f931 100644 --- a/src/RemoteSerializer.h +++ b/src/RemoteSerializer.h @@ -128,10 +128,6 @@ public: // Log some statistics. void LogStats(); - // Return a 0-terminated array of built-in functions which, - // when referenced, trigger the remote serializer's initialization. - const char* const* GetBuiltins() const; - // Tries to sent out all remaining data. // FIXME: Do we still need this? void Finish(); diff --git a/src/bro.bif b/src/bro.bif index 240eeed9dd..d3bbd7c072 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -3632,7 +3632,27 @@ function piped_exec%(program: string, to_write: string%): bool } fprintf(f, "%s", to_write->CheckString()); - pclose(f); + pclose(f); - return new Val(true, TYPE_BOOL); + return new Val(true, TYPE_BOOL); + %} + +## Enables the communication system. Note that by default, +## communication is off until explicitly enabled, and all other calls +## to communication-related BiFs' will be ignored until done so. +function enable_communication%(%): any + %{ + if ( bro_start_network_time != 0.0 ) + { + builtin_error("communication must be enabled in bro_init"); + return 0; + } + + if ( using_communication ) + // Ignore duplicate calls. + return 0; + + using_communication = 1; + remote_serializer->Init(); + return 0; %} diff --git a/src/main.cc b/src/main.cc index 2a36b4019a..f1b393310b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -880,9 +880,6 @@ int main(int argc, char** argv) exit(0); } - if ( using_communication ) - remote_serializer->Init(); - persistence_serializer->SetDir((const char *)state_dir->AsString()->CheckString()); // Print the ID.