]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust: define TxDetectFlag struct and binding macros
authorJason Ish <jason.ish@oisf.net>
Tue, 26 Nov 2019 19:25:04 +0000 (13:25 -0600)
committerJason Ish <jason.ish@oisf.net>
Wed, 27 Nov 2019 19:05:17 +0000 (13:05 -0600)
Define a TxDetectFlag type and macros to generating C
bindings for getting and settings the tx detect
flags.

rust/src/applayer.rs

index d15eab17e319c78ebd2043104b6bad20e8848961..d0dd5c81571e69c1826f3111c765842e41840ba6 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 use std;
+use core::{STREAM_TOSERVER};
 
 #[repr(C)]
 pub struct AppLayerGetTxIterTuple {
@@ -96,3 +97,49 @@ macro_rules!export_tx_set_detect_state {
         }
     )
 }
+
+#[derive(Debug,Default)]
+pub struct TxDetectFlags {
+    ts: u64,
+    tc: u64,
+}
+
+impl TxDetectFlags {
+    pub fn set(&mut self, direction: u8, flags: u64) {
+        if direction & STREAM_TOSERVER != 0 {
+            self.ts = flags;
+        } else {
+            self.tc = flags;
+        }
+    }
+
+    pub fn get(&self, direction: u8) -> u64 {
+        if (direction & STREAM_TOSERVER) != 0 {
+            self.ts
+        } else {
+            self.tc
+        }
+    }
+}
+
+#[macro_export]
+macro_rules!export_tx_detect_flags_set {
+    ($name:ident, $type:ty) => {
+        #[no_mangle]
+        pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8, flags: u64) {
+            let tx = &mut *(tx as *mut $type);
+            tx.detect_flags.set(direction, flags);
+        }
+    }
+}
+
+#[macro_export]
+macro_rules!export_tx_detect_flags_get {
+    ($name:ident, $type:ty) => {
+        #[no_mangle]
+        pub unsafe extern "C" fn $name(tx: *mut std::os::raw::c_void, direction: u8) -> u64 {
+            let tx = &mut *(tx as *mut $type);
+            return tx.detect_flags.get(direction);
+        }
+    }
+}