From: Jason Ish Date: Tue, 26 Nov 2019 19:25:04 +0000 (-0600) Subject: rust: define TxDetectFlag struct and binding macros X-Git-Tag: suricata-5.0.1~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a232be77e4e766ea5618319b1553e1d2a7749ee;p=thirdparty%2Fsuricata.git rust: define TxDetectFlag struct and binding macros Define a TxDetectFlag type and macros to generating C bindings for getting and settings the tx detect flags. --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index d15eab17e3..d0dd5c8157 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -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); + } + } +}