diff --git a/CHANGES b/CHANGES index a72d7e2b9d..46e096b0d3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,20 @@ +1.6-dev-1366 | 2011-10-06 17:05:21 -0700 + + * Make CompHash computation/recovery for functions deterministic. + Closes #636. (Jon Siwek) + + * Removing unnecessary @load in local.bro. (Robin Sommer) + + * Optimizing some MIME code. (Robin Sommer) + + * Speed improvements in logging code. (Robin Sommer) + + * Consolidating some node-specific functionality from scripts in + broctl repo. (Jon Siwek) + + * Another fix the for 1xx script code. (Robin Sommer) + 1.6-dev-1352 | 2011-10-05 16:20:51 -0700 * Fix for optional HTTP::Info status_code. (Jon Siwek) diff --git a/VERSION b/VERSION index 38c6890095..8df34a2cc2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6-dev-1352 +1.6-dev-1366 diff --git a/aux/bro-aux b/aux/bro-aux index a152760509..2ac49c4d5a 160000 --- a/aux/bro-aux +++ b/aux/bro-aux @@ -1 +1 @@ -Subproject commit a152760509e63e85360d5512aecf8ee772e9afe1 +Subproject commit 2ac49c4d5add9ffa48e10395393cc862517c50f9 diff --git a/src/CompHash.cc b/src/CompHash.cc index 916ca124ac..fcd5f61e53 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -5,6 +5,7 @@ #include "CompHash.h" #include "Val.h" #include "Reporter.h" +#include "Func.h" CompositeHash::CompositeHash(TypeList* composite_type) { @@ -156,10 +157,8 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0, { if ( v->Type()->Tag() == TYPE_FUNC ) { - Val** kp = AlignAndPadType(kp0); - v->Ref(); - // Ref((BroObj*) v->AsFunc()); - *kp = v; + uint32* kp = AlignAndPadType(kp0); + *kp = v->AsFunc()->GetUniqueFuncID(); kp1 = reinterpret_cast(kp+1); } @@ -311,7 +310,7 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, int type_check) const case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: if ( v->Type()->Tag() == TYPE_FUNC ) - return new HashKey(v); + return new HashKey(v->AsFunc()->GetUniqueFuncID()); reporter->InternalError("bad index type in CompositeHash::ComputeSingletonHash"); return 0; @@ -377,7 +376,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, case TYPE_INTERNAL_OTHER: { if ( bt->Tag() == TYPE_FUNC ) - sz = SizeAlign(sz, sizeof(Val*)); + sz = SizeAlign(sz, sizeof(uint32)); else if ( bt->Tag() == TYPE_RECORD ) { @@ -639,30 +638,29 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, { if ( t->Tag() == TYPE_FUNC ) { - Val* const * const kp = AlignType(kp0); + const uint32* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); - Val* v = *kp; + Func* f = Func::GetFuncPtrByID(*kp); - if ( ! v || ! v->Type() ) + if ( ! f ) + reporter->InternalError("failed to look up unique function id %"PRIu32" in CompositeHash::RecoverOneVal()"); + + pval = new Val(f); + + if ( ! pval->Type() ) reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()"); - if ( t->Tag() != TYPE_FUNC && - // ### Maybe fix later, but may be fundamentally - // un-checkable --US - ! same_type(v->Type(), t) ) - { + else if ( t->Tag() != TYPE_FUNC && + ! same_type(pval->Type(), t) ) + // ### Maybe fix later, but may be fundamentally + // un-checkable --US reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); - } // ### A crude approximation for now. - if ( t->Tag() == TYPE_FUNC && - v->Type()->Tag() != TYPE_FUNC ) - { + else if ( t->Tag() == TYPE_FUNC && + pval->Type()->Tag() != TYPE_FUNC ) reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); - } - - pval = v->Ref(); } else if ( t->Tag() == TYPE_RECORD ) diff --git a/src/Func.cc b/src/Func.cc index d73717ed50..65cb22b09d 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -53,6 +53,19 @@ extern RETSIGTYPE sig_handler(int signo); const Expr* calling_expr = 0; bool did_builtin_init = false; +vector Func::unique_ids; + +Func::Func() : scope(0), id(0), return_value(0) + { + unique_id = unique_ids.size(); + unique_ids.push_back(this); + } + +Func::Func(Kind arg_kind) : scope(0), kind(arg_kind), id(0), return_value(0) + { + unique_id = unique_ids.size(); + unique_ids.push_back(this); + } Func::~Func() { diff --git a/src/Func.h b/src/Func.h index b9f6ffe808..909b2a9802 100644 --- a/src/Func.h +++ b/src/Func.h @@ -20,8 +20,7 @@ public: enum Kind { BRO_FUNC, BUILTIN_FUNC }; - Func(Kind arg_kind) - { scope = 0; kind = arg_kind; id = 0; return_value = 0; } + Func(Kind arg_kind); virtual ~Func(); @@ -68,8 +67,12 @@ public: ID* GetReturnValueID() const; virtual TraversalCode Traverse(TraversalCallback* cb) const; + uint32 GetUniqueFuncID() const { return unique_id; } + static Func* GetFuncPtrByID(uint32 id) + { return id >= unique_ids.size() ? 0 : unique_ids[id]; } + protected: - Func() { scope = 0; id = 0; return_value = 0; } + Func(); DECLARE_ABSTRACT_SERIAL(Func); @@ -78,6 +81,8 @@ protected: Kind kind; ID* id; ID* return_value; + uint32 unique_id; + static vector unique_ids; }; diff --git a/testing/btest/Baseline/scripts.base.frameworks.notice.default-policy-order/notice_policy.log b/testing/btest/Baseline/scripts.base.frameworks.notice.default-policy-order/notice_policy.log new file mode 100644 index 0000000000..d242616bd3 --- /dev/null +++ b/testing/btest/Baseline/scripts.base.frameworks.notice.default-policy-order/notice_policy.log @@ -0,0 +1,11 @@ +#separator \x09 +#path notice_policy +#fields position priority result pred halt suppress_for +#types count count enum func bool interval +0 10 Notice::ACTION_NONE anonymous-function\x0a{ \x0areturn ((Notice::n$note in Notice::lookup_location_types));\x0a} F - +1 9 Notice::ACTION_NO_SUPPRESS anonymous-function\x0a{ \x0areturn ((Notice::n$note in Notice::not_suppressed_types));\x0a} F - +2 9 Notice::ACTION_NONE anonymous-function\x0a{ \x0areturn ((Notice::n$note in Notice::ignored_types));\x0a} T - +3 8 Notice::ACTION_EMAIL anonymous-function\x0a{ \x0areturn ((Notice::n$note in Notice::emailed_types));\x0a} F - +4 8 Notice::ACTION_ALARM anonymous-function\x0a{ \x0areturn ((Notice::n$note in Notice::alarmed_types));\x0a} F - +5 8 Notice::ACTION_NONE anonymous-function\x0a{ \x0aif (Notice::n$note in Notice::type_suppression_intervals) \x0a\x09{ \x0a\x09Notice::n$suppress_for = Notice::type_suppression_intervals[Notice::n$note];\x0a\x09return (T);\x0a\x09}\x0a\x0areturn (F);\x0a} F - +6 0 Notice::ACTION_LOG - F - diff --git a/testing/btest/Baseline/scripts.base.frameworks.notice.suppression-disable/notice.log b/testing/btest/Baseline/scripts.base.frameworks.notice.suppression-disable/notice.log index e4e62babfd..90ff7cff57 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.notice.suppression-disable/notice.log +++ b/testing/btest/Baseline/scripts.base.frameworks.notice.suppression-disable/notice.log @@ -2,5 +2,5 @@ #path notice #fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude #types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double -1316950520.397561 - - - - - Test_Notice test - - - - - bro Notice::ACTION_NO_SUPPRESS,Notice::ACTION_LOG 6,1 3600.000000 - - - - - - -1316950520.397561 - - - - - Test_Notice another test - - - - - bro Notice::ACTION_NO_SUPPRESS,Notice::ACTION_LOG 6,1 3600.000000 - - - - - - +1317927277.508920 - - - - - Test_Notice test - - - - - bro Notice::ACTION_NO_SUPPRESS,Notice::ACTION_LOG 6,1 3600.000000 - - - - - - +1317927277.508920 - - - - - Test_Notice another test - - - - - bro Notice::ACTION_NO_SUPPRESS,Notice::ACTION_LOG 6,1 3600.000000 - - - - - - diff --git a/testing/btest/scripts/base/frameworks/notice/default-policy-order.test b/testing/btest/scripts/base/frameworks/notice/default-policy-order.test new file mode 100644 index 0000000000..4ce5ce614d --- /dev/null +++ b/testing/btest/scripts/base/frameworks/notice/default-policy-order.test @@ -0,0 +1,4 @@ +# This test checks that the default notice policy ordering is the same +# as a known baseline. +# @TEST-EXEC: bro -e '' +# @TEST-EXEC: btest-diff notice_policy.log