]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2622 in SNORT/snort3 from ~BBANTWAL/snort3:help_module_itype...
authorBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Tue, 17 Nov 2020 19:10:34 +0000 (19:10 +0000)
committerBhagya Tholpady (bbantwal) <bbantwal@cisco.com>
Tue, 17 Nov 2020 19:10:34 +0000 (19:10 +0000)
Squashed commit of the following:

commit 9316db8c7d65535e9c18bbe2df04914760e8423e
Author: Bhagya Tholpady <bbantwal@cisco.com>
Date:   Mon Nov 16 18:32:09 2020 -0500

    managers: add inspector type in the help module output

src/framework/inspector.cc
src/framework/inspector.h
src/managers/inspector_manager.cc
src/managers/inspector_manager.h
src/managers/module_manager.cc

index 7805927ac65f3df4001f2b541a822b55bdd5c05d..178814fcc2999455aeff9c6d78ad49551a12903c 100644 (file)
@@ -115,3 +115,23 @@ void Inspector::add_ref()
 
 void Inspector::rem_ref()
 { --ref_count[slot]; }
+
+static const char* InspectorTypeNames[IT_MAX] =
+{
+    "passive",
+    "wizard",
+    "packet",
+    "stream",
+    "network",
+    "service",
+    "control",
+    "probe"
+};
+
+const char* InspectApi::get_type(InspectorType type)
+{
+    if ( (type < IT_PASSIVE) or (type >= IT_MAX) )
+        return "";
+
+    return InspectorTypeNames[type];
+}
index a30fe998b72ec6a906286d9e272a36e81b9e3397..52c4ddcd8ff80fa7bc1f5483a497a4e82d845487 100644 (file)
@@ -210,6 +210,8 @@ struct InspectApi
     InspectDelFunc dtor;   // release inspector instance
     InspectSsnFunc ssn;    // get new session tracker
     InspectFunc reset;     // clear stats
+
+    static const char* get_type(InspectorType type);
 };
 
 inline const char* Inspector::get_name() const
index f2c2da64751077e1552be5cbac8493c01e0171f2..7be6c3f058d08bad9d7c9d3dd661ed02294e714d 100644 (file)
@@ -309,6 +309,15 @@ std::vector<const InspectApi*> InspectorManager::get_apis()
     return v;
 }
 
+const char* InspectorManager::get_inspector_type(const char* name)
+{
+    for ( const auto* p : s_handlers )
+        if ( !strcmp(p->api.base.name, name) )
+            return p->api.get_type(p->api.type);
+
+    return "";
+}
+
 void InspectorManager::add_plugin(const InspectApi* api)
 {
     PHGlobal* g = new PHGlobal(*api);
index c76b6f0662c97ead34a9116263772409b9ecdd92..d86dd633f27bb678c94a65d3447e5e4482acd2cb 100644 (file)
@@ -45,6 +45,7 @@ public:
     static void release_plugins();
 
     static std::vector<const InspectApi*> get_apis();
+    static const char* get_inspector_type(const char* name);
 
     static void new_policy(InspectionPolicy*, InspectionPolicy*);
     static void delete_policy(InspectionPolicy*, bool cloned);
index 49a7d7618ac22deea813760a9cae07cd0ce1af44..4b3988b1bd4a1e449b10d4c9079bdd680f0632fa 100644 (file)
@@ -42,6 +42,7 @@
 #include "main/shell.h"
 #include "main/snort.h"
 #include "main/snort_config.h"
+#include "managers/inspector_manager.h"
 #include "parser/parse_conf.h"
 #include "parser/parser.h"
 #include "profiler/profiler.h"
@@ -958,12 +959,21 @@ void ModuleManager::dump_modules()
             d.dump(mh->mod->get_name());
 }
 
-static const char* mod_type(const BaseApi* api)
+static std::string mod_type(const BaseApi* api)
 {
     if ( !api )
         return "basic";
 
-    return PluginManager::get_type_name(api->type);
+    std::string type(PluginManager::get_type_name(api->type));
+
+    if ( api->type == PT_INSPECTOR )
+    {
+        std::string itype = InspectorManager::get_inspector_type(api->name);
+        if ( !itype.empty() )
+            type += " (" + itype + ")";
+    }
+
+    return type;
 }
 
 static const char* mod_use(Module::Usage use)
@@ -1750,7 +1760,7 @@ void ModuleManager::show_modules_json()
         if ( const char* h = mod->get_help() )
             help = h;
 
-        const char* type = mod_type(mh->api);
+        std::string type = mod_type(mh->api);
         const char* usage = mod_use(mod->get_usage());
 
         json.open();