From: Steve Chew (stechew) Date: Mon, 23 Sep 2019 22:20:16 +0000 (-0400) Subject: Merge pull request #1750 in SNORT/snort3 from ~SBAIGAL/snort3:global_service to master X-Git-Tag: 3.0.0-262~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66c7402d433c5d10283c57bcfcf1618c2cedd135;p=thirdparty%2Fsnort3.git Merge pull request #1750 in SNORT/snort3 from ~SBAIGAL/snort3:global_service to master Squashed commit of the following: commit 678613c91efb1772aa6bec5abcf0c849e99e83cb Author: Steven Baigal (sbaigal) Date: Tue Sep 17 15:52:10 2019 -0400 binder: allow binder to support global level service inspectors removed unused function get_type() add module map --- diff --git a/src/managers/inspector_manager.cc b/src/managers/inspector_manager.cc index 34b141dc9..39cf0918f 100644 --- a/src/managers/inspector_manager.cc +++ b/src/managers/inspector_manager.cc @@ -553,16 +553,6 @@ Inspector* InspectorManager::get_inspector(const char* key, bool dflt_only, Snor return p->handler; } -InspectorType InspectorManager::get_type(const char* key) -{ - Inspector* p = get_inspector(key); - - if ( !p ) - return IT_MAX; - - return p->get_api()->type; -} - bool InspectorManager::delete_inspector(SnortConfig* sc, const char* iname) { bool ok = false; diff --git a/src/managers/inspector_manager.h b/src/managers/inspector_manager.h index b3e993abb..0a3007174 100644 --- a/src/managers/inspector_manager.h +++ b/src/managers/inspector_manager.h @@ -58,7 +58,6 @@ public: static void free_inspector(Inspector*); static InspectSsnFunc get_session(uint16_t proto); - static InspectorType get_type(const char* key); SO_PUBLIC static Inspector* get_inspector(const char* key, bool dflt_only = false, SnortConfig* sc = nullptr); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 99f14682e..4a29c8942 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -68,6 +68,7 @@ struct ModHook typedef std::list ModuleList; static ModuleList s_modules; +static std::unordered_map s_module_map; static unsigned s_errors = 0; std::set ModuleManager::gids; @@ -871,6 +872,7 @@ void ModuleManager::add_module(Module* m, const BaseApi* b) { ModHook* mh = new ModHook(m, b); s_modules.emplace_back(mh); + s_module_map[std::string(m->get_name())] = m; Profiler::register_module(m); @@ -880,11 +882,7 @@ void ModuleManager::add_module(Module* m, const BaseApi* b) Module* ModuleManager::get_module(const char* s) { - for ( auto p : s_modules ) - if ( !strcmp(p->mod->get_name(), s) ) - return p->mod; - - return nullptr; + return s_module_map[std::string(s)]; } Module* ModuleManager::get_default_module(const char* s, SnortConfig* sc) diff --git a/src/network_inspectors/binder/binder.cc b/src/network_inspectors/binder/binder.cc index 229347a36..5829b73a1 100644 --- a/src/network_inspectors/binder/binder.cc +++ b/src/network_inspectors/binder/binder.cc @@ -27,6 +27,7 @@ #include "log/messages.h" #include "main/snort_config.h" #include "managers/inspector_manager.h" +#include "managers/module_manager.h" #include "profiler/profiler.h" #include "protocols/packet.h" #include "protocols/tcp.h" @@ -397,10 +398,15 @@ bool Binding::check_all(const Flow* flow, Packet* p) const //------------------------------------------------------------------------- // helpers //------------------------------------------------------------------------- +static bool is_global(const char* key) +{ + Module* m = ModuleManager::get_module(key); + return m ? m->get_usage() == Module::GLOBAL : false; +} static void set_session(Flow* flow, const char* key) { - Inspector* pin = InspectorManager::get_inspector(key); + Inspector* pin = InspectorManager::get_inspector(key, is_global(key)); if ( pin ) { @@ -430,7 +436,7 @@ static Inspector* get_gadget(Flow* flow) const char* s = SnortConfig::get_conf()->proto_ref->get_name(flow->ssn_state.snort_protocol_id); - return InspectorManager::get_inspector(s); + return InspectorManager::get_inspector(s, is_global(s)); } //------------------------------------------------------------------------- @@ -836,9 +842,9 @@ void Binder::set_binding(SnortConfig*, Binding* pb) else key = pb->use.svc.c_str(); - if ( (pb->use.object = InspectorManager::get_inspector(key)) ) + if ( (pb->use.object = InspectorManager::get_inspector(key, is_global(key))) ) { - switch ( InspectorManager::get_type(key) ) + switch ( ((Inspector*)pb->use.object)->get_api()->type ) { case IT_STREAM: pb->use.what = BindUse::BW_STREAM; break; case IT_WIZARD: pb->use.what = BindUse::BW_WIZARD; break;