]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust: plugin bootstrap function
authorJason Ish <jason.ish@oisf.net>
Tue, 25 Aug 2020 18:51:26 +0000 (12:51 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 3 Sep 2020 11:04:14 +0000 (13:04 +0200)
Functions written in Rust will need to suricata::plugin::init()
to bootstrap themselves. This bootstrap process sets the log level
within the Rust address space, and hooks up function pointers
that are expected to be set during normal runs of Suricata.

rust/src/core.rs
rust/src/lib.rs
rust/src/plugin.rs [new file with mode: 0644]

index 5026cd8dd4d36ad7c69f0a1267a10642b5f6a8b4..07e49be071cf804563d5ddc52c8c9b5dfd8bcc24 100644 (file)
@@ -84,7 +84,7 @@ pub type AppLayerDecoderEventsSetEventRawFunc =
 pub type AppLayerDecoderEventsFreeEventsFunc =
     extern "C" fn (events: *mut *mut AppLayerDecoderEvents);
 
-pub struct SuricataStreamingBufferConfig;
+pub enum SuricataStreamingBufferConfig {}
 
 pub type SCFileOpenFileWithId = extern "C" fn (
         file_container: &FileContainer,
@@ -145,10 +145,14 @@ pub struct SuricataFileContext {
     pub files_sbcfg: &'static SuricataStreamingBufferConfig,
 }
 
+extern {
+    pub fn SCGetContext() -> &'static mut SuricataContext;
+    pub fn SCLogGetLogLevel() -> i32;
+}
+
 pub static mut SC: Option<&'static SuricataContext> = None;
 
-#[no_mangle]
-pub extern "C" fn rs_init(context: &'static mut SuricataContext)
+pub fn init_ffi(context: &'static mut SuricataContext)
 {
     unsafe {
         SC = Some(context);
@@ -156,6 +160,12 @@ pub extern "C" fn rs_init(context: &'static mut SuricataContext)
     }
 }
 
+#[no_mangle]
+pub extern "C" fn rs_init(context: &'static mut SuricataContext)
+{
+    init_ffi(context);
+}
+
 /// DetectEngineStateFree wrapper.
 pub fn sc_detect_engine_state_free(state: *mut DetectEngineState)
 {
index f0af87bcff3bdb42d558ecae15f1eb3ed8566cbc..abf9d27e5b1af5b796d459fad9c811fa080cccd2 100644 (file)
@@ -82,3 +82,4 @@ pub mod x509;
 pub mod asn1;
 pub mod ssh;
 pub mod http2;
+pub mod plugin;
\ No newline at end of file
diff --git a/rust/src/plugin.rs b/rust/src/plugin.rs
new file mode 100644 (file)
index 0000000..f9daef7
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (C) 2020 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+pub fn init() {
+    unsafe {
+        let context = super::core::SCGetContext();
+        super::core::init_ffi(context);
+
+        let level = super::core::SCLogGetLogLevel();
+        super::log::log_set_level(level);
+    }
+}