]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1750 in SNORT/snort3 from ~SBAIGAL/snort3:global_service to master
authorSteve Chew (stechew) <stechew@cisco.com>
Mon, 23 Sep 2019 22:20:16 +0000 (18:20 -0400)
committerSteve Chew (stechew) <stechew@cisco.com>
Mon, 23 Sep 2019 22:20:16 +0000 (18:20 -0400)
Squashed commit of the following:

commit 678613c91efb1772aa6bec5abcf0c849e99e83cb
Author: Steven Baigal (sbaigal) <sbaigal@cisco.com>
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

src/managers/inspector_manager.cc
src/managers/inspector_manager.h
src/managers/module_manager.cc
src/network_inspectors/binder/binder.cc

index 34b141dc92acb753d5788b81613e07a17bb6deb8..39cf0918f93b2345a27ea6015b1bf22911119009 100644 (file)
@@ -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;
index b3e993abb1fb6ed729c2d03d1a3e53ac0d640cd8..0a3007174c25163b2f70f080dbf82e4567827b23 100644 (file)
@@ -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);
 
index 99f14682e8c24cfdaf6713b47cc8be3bb7b5a288..4a29c8942fa2ddd051d6dedea122f999f2fe5cbd 100644 (file)
@@ -68,6 +68,7 @@ struct ModHook
 
 typedef std::list<ModHook*> ModuleList;
 static ModuleList s_modules;
+static std::unordered_map<std::string, Module*> s_module_map;
 static unsigned s_errors = 0;
 
 std::set<uint32_t> 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)
index 229347a360c76939a94eecb48ee285e71c950770..5829b73a1d84026384b6e20005646610e104fc40 100644 (file)
@@ -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;