From 8a232be77e4e766ea5618319b1553e1d2a7749ee Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 26 Nov 2019 13:25:04 -0600 Subject: [PATCH] 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. --- rust/src/applayer.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index d15eab17e..d0dd5c815 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); + } + } +} -- 2.47.2