From: Bhagya Tholpady (bbantwal) Date: Tue, 17 Nov 2020 19:10:34 +0000 (+0000) Subject: Merge pull request #2622 in SNORT/snort3 from ~BBANTWAL/snort3:help_module_itype... X-Git-Tag: 3.0.3-6~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89690493663af334dba90b15d72db4dde2417979;p=thirdparty%2Fsnort3.git Merge pull request #2622 in SNORT/snort3 from ~BBANTWAL/snort3:help_module_itype to master Squashed commit of the following: commit 9316db8c7d65535e9c18bbe2df04914760e8423e Author: Bhagya Tholpady Date: Mon Nov 16 18:32:09 2020 -0500 managers: add inspector type in the help module output --- diff --git a/src/framework/inspector.cc b/src/framework/inspector.cc index 7805927ac..178814fcc 100644 --- a/src/framework/inspector.cc +++ b/src/framework/inspector.cc @@ -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]; +} diff --git a/src/framework/inspector.h b/src/framework/inspector.h index a30fe998b..52c4ddcd8 100644 --- a/src/framework/inspector.h +++ b/src/framework/inspector.h @@ -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 diff --git a/src/managers/inspector_manager.cc b/src/managers/inspector_manager.cc index f2c2da647..7be6c3f05 100644 --- a/src/managers/inspector_manager.cc +++ b/src/managers/inspector_manager.cc @@ -309,6 +309,15 @@ std::vector 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); diff --git a/src/managers/inspector_manager.h b/src/managers/inspector_manager.h index c76b6f066..d86dd633f 100644 --- a/src/managers/inspector_manager.h +++ b/src/managers/inspector_manager.h @@ -45,6 +45,7 @@ public: static void release_plugins(); static std::vector get_apis(); + static const char* get_inspector_type(const char* name); static void new_policy(InspectionPolicy*, InspectionPolicy*); static void delete_policy(InspectionPolicy*, bool cloned); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 49a7d7618..4b3988b1b 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -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();