From: Russ Combs (rucombs) Date: Wed, 22 Feb 2017 21:41:55 +0000 (-0500) Subject: Merge pull request #823 in SNORT/snort3 from free_the_gids-vjr to master X-Git-Tag: 3.0.0-233~61 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef85d5200e33b6d8ac097e6978dfe9c2edbce25d;p=thirdparty%2Fsnort3.git Merge pull request #823 in SNORT/snort3 from free_the_gids-vjr to master Squashed commit of the following: commit 9403cbcdf2a16ec768325102b7a4e97e79f0a740 Author: Victor Roemer Date: Tue Feb 21 15:09:38 2017 -0500 Only emplace non-zero gids commit 2db5bc3e5222e927828446294de1394303773972 Author: Victor Roemer Date: Mon Feb 20 11:42:49 2017 -0500 Keep track of GID's in use. commit 99636e1116c862d0f0d5b73c0042c6de0c62c340 Author: Russ Combs Date: Wed Feb 15 11:05:51 2017 -0500 poc - allow arbitrary gid use; test and perf tbd --- diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 1b52a60c0..cbc4307d8 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -63,6 +63,8 @@ typedef std::list ModuleList; static ModuleList s_modules; static unsigned s_errors = 0; +std::set ModuleManager::gids; + static string s_current; static string s_name; static string s_type; @@ -793,6 +795,9 @@ void ModuleManager::add_module(Module* m, const BaseApi* b) std::lock_guard lock(stats_mutex); m->reset_stats(); + + if ( m->get_gid() ) + gids.emplace(m->get_gid()); } Module* ModuleManager::get_module(const char* s) @@ -1054,6 +1059,11 @@ void ModuleManager::show_commands(const char* pfx, bool exact) cout << "no match" << endl; } +bool ModuleManager::gid_in_use(uint32_t gid) +{ + return gids.find(gid) != gids.end(); +} + void ModuleManager::show_gids(const char* pfx, bool exact) { s_modules.sort(comp_gids); diff --git a/src/managers/module_manager.h b/src/managers/module_manager.h index bd91df938..2ca570391 100644 --- a/src/managers/module_manager.h +++ b/src/managers/module_manager.h @@ -23,6 +23,8 @@ // Factory for Modules, including all builtin and plugin modules. // Modules are strictly used during parse time. +#include +#include #include //------------------------------------------------------------------------- @@ -46,6 +48,8 @@ public: static void show_modules(); static void show_module(const char*); + static bool gid_in_use(uint32_t); + // output for matching module name; prefix is sufficient if not exact static void show_configs(const char* = nullptr, bool exact = false); static void show_commands(const char* = nullptr, bool exact = false); @@ -66,6 +70,8 @@ public: static void dump_stats(SnortConfig*, const char* skip = nullptr); static void accumulate(SnortConfig*); static void reset_stats(SnortConfig*); + + static std::set gids; }; #endif diff --git a/src/parser/parse_rule.cc b/src/parser/parse_rule.cc index ea4ed0449..87de0a0c1 100644 --- a/src/parser/parse_rule.cc +++ b/src/parser/parse_rule.cc @@ -33,6 +33,7 @@ #include "main/snort_debug.h" #include "main/thread_config.h" #include "managers/ips_manager.h" +#include "managers/module_manager.h" #include "managers/so_manager.h" #include "ports/rule_port_tables.h" #include "sfip/sf_ipvar.h" @@ -1263,11 +1264,8 @@ const char* parse_rule_close(SnortConfig* sc, RuleTreeNode& rtn, OptTreeNode* ot otn->sigInfo.text_rule = true; so_rule_count++; } - else + else if ( ModuleManager::gid_in_use(otn->sigInfo.generator) ) { - if ( !otn->sigInfo.generator ) - ParseError("gid must set in builtin rules"); - if ( otn->num_detection_opts ) ParseError("%u:%u builtin rules do not support detection options", otn->sigInfo.generator, otn->sigInfo.id);