]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust/app-layer: macros to export de_state functions
authorJason Ish <ish@unx.ca>
Thu, 31 May 2018 22:39:22 +0000 (16:39 -0600)
committerJason Ish <ish@unx.ca>
Fri, 15 Jun 2018 21:48:52 +0000 (15:48 -0600)
These macros generate the extern "C" functions for transactions
structs that need provide functions for setting and getting
the de_state. The idea is to provide macros do avoid code
duplication and make it simpler to create an app-layer.

A trait would be the correct solution, but it doesn't look like
you can use traits to export extern "C" functions.

rust/src/applayer.rs
rust/src/lib.rs

index 6a0a8e0fced813b77e22271e6a92414365be853e..641c5e0003be09d0d89fbfda14b6bd6270927386 100644 (file)
@@ -61,3 +61,39 @@ impl LoggerFlags {
     }
 
 }
+
+/// Export a function to get the DetectEngineState on a struct.
+#[macro_export]
+macro_rules!export_tx_get_detect_state {
+    ($name:ident, $type:ty) => (
+        #[no_mangle]
+        pub extern "C" fn $name(tx: *mut libc::c_void)
+            -> *mut core::DetectEngineState
+        {
+            let tx = cast_pointer!(tx, $type);
+            match tx.de_state {
+                Some(ds) => {
+                    return ds;
+                },
+                None => {
+                    return std::ptr::null_mut();
+                }
+            }
+        }
+    )
+}
+
+/// Export a function to set the DetectEngineState on a struct.
+#[macro_export]
+macro_rules!export_tx_set_detect_state {
+    ($name:ident, $type:ty) => (
+        #[no_mangle]
+        pub extern "C" fn $name(tx: *mut libc::c_void,
+                de_state: &mut core::DetectEngineState) -> libc::c_int
+        {
+            let tx = cast_pointer!(tx, $type);
+            tx.de_state = Some(de_state);
+            0
+        }
+    )
+}
index 0a6e0652cca933fc367d72b7e0f0dd100dc9055f..00b0a5c9ec68a573a4057395e67c91211d92cb94 100644 (file)
@@ -35,6 +35,7 @@ pub mod core;
 
 pub mod conf;
 pub mod json;
+#[macro_use]
 pub mod applayer;
 pub mod filecontainer;
 pub mod filetracker;