]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
ffi: add get_module_version(name, type) for conditional config
authorruss <rucombs@cisco.com>
Mon, 25 Jul 2022 20:20:26 +0000 (16:20 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Sat, 13 Aug 2022 18:39:08 +0000 (18:39 +0000)
src/main/bootstrap.lua
src/managers/module_manager.cc

index c3b498405ba402ec1a6c2ded83ef7048aed94489..ed3a5a00b7f749eaee6b4e5249e8caa5c1ff6f44 100644 (file)
@@ -28,6 +28,7 @@ const char* push_include_path(const char*);
 void pop_include_path();
 void snort_whitelist_append(const char*);
 void snort_whitelist_add_prefix(const char*);
+int get_module_version(const char* name, const char* type);
 ]]
 
 function whitelist_append(list, is_prefix)
@@ -63,6 +64,10 @@ function initialize_whitelist(tab)
     end
 end
 
+function get_module_version(name, type)
+    return ffi.C.get_module_version(name, type)
+end
+
 ---------------------------------------------------------------------------
 -- path magic for includes
 ---------------------------------------------------------------------------
@@ -149,6 +154,7 @@ function create_sandbox_env()
         SNORT_MINOR_VERSION = SNORT_MINOR_VERSION,
         SNORT_PATCH_VERSION = SNORT_PATCH_VERSION,
         SNORT_SUBLEVEL_VERSION = SNORT_SUBLEVEL_VERSION,
+        get_module_version = get_module_version,
         tweaks = tweaks,
     }
 
index 02fa5c99f522d7a5518997d47593af3e94640633..0c9ffbae89343ae0fc89f71f7d19da729f289ba9 100644 (file)
@@ -106,6 +106,8 @@ extern "C"
 
     void snort_whitelist_append(const char*);
     void snort_whitelist_add_prefix(const char*);
+
+    int get_module_version(const char* name, const char* type);
 }
 
 //-------------------------------------------------------------------------
@@ -741,6 +743,25 @@ SO_PUBLIC bool set_includer(const char* fqn, const char* s)
     return true;
 }
 
+// cppcheck-suppress unusedFunction
+SO_PUBLIC int get_module_version(const char* name, const char* type)
+{
+    // not all modules are plugins
+    // not all plugins have modules
+    ModHook* h = get_hook(name);
+
+    if ( !h )
+    {
+        if ( !type )
+            return -1;
+
+        PlugType pt = PluginManager::get_type(type);
+        return PluginManager::get_api(pt, name) ? 0 : -1;
+    }
+
+    return h->api ? (int)h->api->version : 0;
+}
+
 //-------------------------------------------------------------------------
 // ffi methods - also called internally so no cppcheck suppressions
 //-------------------------------------------------------------------------