From d8801bb9c4bc8c898a6c0b51ddb7a647076237bc Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Wed, 17 Jul 2013 17:31:16 -0700 Subject: [PATCH] Canonifying internal order for plugins and their components to make it deterministic. --- aux/btest | 2 +- src/analyzer/Component.h | 2 +- src/file_analysis/Component.h | 2 +- src/plugin/Component.h | 6 +++++ src/plugin/Manager.cc | 9 +++++++ src/plugin/Plugin.cc | 9 +++++++ .../Baseline/core.print-bpf-filters/conn.log | 4 ++-- .../Baseline/core.print-bpf-filters/output | 24 +++++++++---------- 8 files changed, 41 insertions(+), 17 deletions(-) diff --git a/aux/btest b/aux/btest index c2e73c9e1e..b1d4faf239 160000 --- a/aux/btest +++ b/aux/btest @@ -1 +1 @@ -Subproject commit c2e73c9e1efed6bfdf2d977d716c97773c39492e +Subproject commit b1d4faf23900d4753e93a68abbba45ae3bf96d03 diff --git a/src/analyzer/Component.h b/src/analyzer/Component.h index f3d91c7f90..9e12ed347e 100644 --- a/src/analyzer/Component.h +++ b/src/analyzer/Component.h @@ -72,7 +72,7 @@ public: * from what's passed to the constructor but upper-cased and * canonified to allow being part of a script-level ID. */ - const char* Name() const { return name; } + virtual const char* Name() const { return name; } /** * Returns a canonocalized version of the analyzer's name. The diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 8b79436991..3cdc69efdf 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -64,7 +64,7 @@ public: * from what's passed to the constructor but upper-cased and * canonified to allow being part of a script-level ID. */ - const char* Name() const { return name; } + virtual const char* Name() const { return name; } /** * Returns a canonocalized version of the analyzer's name. The diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 4ac448e466..ad02dc7e4b 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -45,6 +45,12 @@ public: */ component::Type Type() const; + /** + * Returns a descriptive name for the analyzer. This name must be + * unique across all components of the same type. + */ + virtual const char* Name() const = 0; + /** * Returns a textual representation of the component. The default * version just output the type. Derived version should call the diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 93ed3f2b97..67f4dea2bd 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -30,9 +30,18 @@ bool Manager::LoadPluginsFrom(const std::string& dir) return false; } +static bool plugin_cmp(const Plugin* a, const Plugin* b) + { + return a->Name() < b->Name(); + } + bool Manager::RegisterPlugin(Plugin *plugin) { Manager::PluginsInternal()->push_back(plugin); + + // Sort plugins by name to make sure we have a deterministic order. + PluginsInternal()->sort(plugin_cmp); + return true; } diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 084c49f51e..eaac8a3b25 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -156,9 +156,18 @@ Plugin::component_list Plugin::Components() const return components; } +static bool component_cmp(const Component* a, const Component* b) + { + return a->Name() < b->Name(); + } + void Plugin::AddComponent(Component* c) { components.push_back(c); + + // Sort components by name to make sure we have a deterministic + // order. + components.sort(component_cmp); } void Plugin::AddBifInitFunction(bif_init_func c) diff --git a/testing/btest/Baseline/core.print-bpf-filters/conn.log b/testing/btest/Baseline/core.print-bpf-filters/conn.log index 745673c027..166286203e 100644 --- a/testing/btest/Baseline/core.print-bpf-filters/conn.log +++ b/testing/btest/Baseline/core.print-bpf-filters/conn.log @@ -3,8 +3,8 @@ #empty_field (empty) #unset_field - #path conn -#open 2013-07-08-20-05-18 +#open 2013-07-18-00-18-33 #fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p proto service duration orig_bytes resp_bytes conn_state local_orig missed_bytes history orig_pkts orig_ip_bytes resp_pkts resp_ip_bytes tunnel_parents #types time string addr port addr port enum string interval count count string bool count string count count count count table[string] 1278600802.069419 UWkUyAuUGXf 10.20.80.1 50343 10.0.0.15 80 tcp - 0.004152 9 3429 SF - 0 ShADadfF 7 381 7 3801 (empty) -#close 2013-07-08-20-05-18 +#close 2013-07-18-00-18-33 diff --git a/testing/btest/Baseline/core.print-bpf-filters/output b/testing/btest/Baseline/core.print-bpf-filters/output index 8ccc04b1a7..871719bba8 100644 --- a/testing/btest/Baseline/core.print-bpf-filters/output +++ b/testing/btest/Baseline/core.print-bpf-filters/output @@ -3,38 +3,38 @@ #empty_field (empty) #unset_field - #path packet_filter -#open 2013-07-08-20-05-17 +#open 2013-07-18-00-18-33 #fields ts node filter init success #types time string string bool bool -1373313917.926565 - ip or not ip T T -#close 2013-07-08-20-05-17 +1374106713.105591 - ip or not ip T T +#close 2013-07-18-00-18-33 #separator \x09 #set_separator , #empty_field (empty) #unset_field - #path packet_filter -#open 2013-07-08-20-05-18 +#open 2013-07-18-00-18-33 #fields ts node filter init success #types time string string bool bool -1373313918.205206 - port 42 T T -#close 2013-07-08-20-05-18 +1374106713.385541 - port 42 T T +#close 2013-07-18-00-18-33 #separator \x09 #set_separator , #empty_field (empty) #unset_field - #path packet_filter -#open 2013-07-08-20-05-18 +#open 2013-07-18-00-18-33 #fields ts node filter init success #types time string string bool bool -1373313918.491383 - (vlan) and (ip or not ip) T T -#close 2013-07-08-20-05-18 +1374106713.664282 - (vlan) and (ip or not ip) T T +#close 2013-07-18-00-18-33 #separator \x09 #set_separator , #empty_field (empty) #unset_field - #path packet_filter -#open 2013-07-08-20-05-18 +#open 2013-07-18-00-18-33 #fields ts node filter init success #types time string string bool bool -1373313918.795264 - ((((((((((((udp and port 3544) or (udp and port 514)) or ((tcp and port 2811) or (tcp and port 21))) or (tcp and port 502)) or ((((tcp and port 6669) or (tcp and port 6666)) or (tcp and port 6668)) or (tcp and port 6667))) or (tcp and port 1080)) or ((udp and port 2152) or (udp and port 2123))) or ((((((((tcp and port 631) or (tcp and port 8888)) or (tcp and port 3128)) or (tcp and port 80)) or (tcp and port 1080)) or (tcp and port 8000)) or (tcp and port 81)) or (tcp and port 8080))) or (udp and port 5072)) or ((tcp and port 25) or (tcp and port 587))) or (((((((((((tcp and port 5223) or (tcp and port 585)) or (tcp and port 614)) or (tcp and port 993)) or (tcp and port 636)) or (tcp and port 989)) or (tcp and port 995)) or (tcp and port 443)) or (tcp and port 563)) or (tcp and port 990)) or (tcp and port 992))) or (((((udp and port 5355) or (tcp and port 53)) or (udp and port 5353)) or (udp and port 137)) or (udp and port 53))) or (tcp and port 22) T T -#close 2013-07-08-20-05-18 +1374106713.957005 - ((((((((((((((((((((((tcp and port 5223) or (tcp and port 585)) or (tcp and port 614)) or (tcp and port 993)) or (tcp and port 636)) or (tcp and port 989)) or (tcp and port 995)) or (tcp and port 443)) or (tcp and port 563)) or (tcp and port 990)) or (tcp and port 992)) or ((tcp and port 2811) or (tcp and port 21))) or ((((tcp and port 6669) or (tcp and port 6666)) or (tcp and port 6668)) or (tcp and port 6667))) or ((udp and port 2152) or (udp and port 2123))) or (tcp and port 22)) or (tcp and port 1080)) or ((((((((tcp and port 631) or (tcp and port 8888)) or (tcp and port 3128)) or (tcp and port 80)) or (tcp and port 1080)) or (tcp and port 8000)) or (tcp and port 81)) or (tcp and port 8080))) or (udp and port 5072)) or ((tcp and port 25) or (tcp and port 587))) or (tcp and port 502)) or (udp and port 514)) or (((((udp and port 5355) or (tcp and port 53)) or (udp and port 5353)) or (udp and port 137)) or (udp and port 53))) or (udp and port 3544) T T +#close 2013-07-18-00-18-33