diff --git a/rust/Makefile.am b/rust/Makefile.am index 24df1a0b49..ccd7ea721f 100644 --- a/rust/Makefile.am +++ b/rust/Makefile.am @@ -149,6 +149,7 @@ if HAVE_BINDGEN --allowlist-type 'AppLayerGetFileState' \ --allowlist-type 'AppLayerGetTxIterState' \ --allowlist-type 'AppLayerStateData' \ + --allowlist-type 'AppLayerGetTxIterTuple' \ --allowlist-function 'SC.*' \ --allowlist-var 'SC.*' \ --opaque-type 'SCConfNode' \ diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 88f7c6c995..c1534347ee 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -32,7 +32,7 @@ use suricata_sys::sys::{ DetectEngineState, GenericVar, }; -pub use suricata_sys::sys::{AppLayerGetFileState, AppLayerStateData}; +pub use suricata_sys::sys::{AppLayerGetFileState, AppLayerStateData, AppLayerGetTxIterTuple}; #[cfg(not(test))] use suricata_sys::sys::{ SCAppLayerDecoderEventsFreeEvents, SCAppLayerDecoderEventsSetEventRaw, SCDetectEngineStateFree, @@ -544,20 +544,18 @@ pub const _APP_LAYER_TX_INSPECTED_TS: u8 = BIT_U8!(2); pub const _APP_LAYER_TX_INSPECTED_TC: u8 = BIT_U8!(3); pub const APP_LAYER_TX_ACCEPT: u8 = BIT_U8!(4); -#[repr(C)] -pub struct AppLayerGetTxIterTuple { - tx_ptr: *mut std::os::raw::c_void, - tx_id: u64, - has_next: bool, +pub trait AppLayerGetTxIterTupleRust { + fn with_values(tx_ptr: *mut std::os::raw::c_void, tx_id: u64, has_next: bool) -> Self; + fn not_found() -> Self; } -impl AppLayerGetTxIterTuple { - pub fn with_values(tx_ptr: *mut std::os::raw::c_void, tx_id: u64, has_next: bool) -> AppLayerGetTxIterTuple { +impl AppLayerGetTxIterTupleRust for AppLayerGetTxIterTuple { + fn with_values(tx_ptr: *mut std::os::raw::c_void, tx_id: u64, has_next: bool) -> AppLayerGetTxIterTuple { AppLayerGetTxIterTuple { tx_ptr, tx_id, has_next, } } - pub fn not_found() -> AppLayerGetTxIterTuple { + fn not_found() -> AppLayerGetTxIterTuple { AppLayerGetTxIterTuple { tx_ptr: std::ptr::null_mut(), tx_id: 0, has_next: false, } diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index ca3feb3436..9aa9a27a2c 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -1039,6 +1039,22 @@ impl Default for AppLayerGetTxIterState { pub struct AppLayerStateData { pub file_flags: u16, } +#[repr(C)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct AppLayerGetTxIterTuple { + pub tx_ptr: *mut ::std::os::raw::c_void, + pub tx_id: u64, + pub has_next: bool, +} +impl Default for AppLayerGetTxIterTuple { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} extern "C" { pub fn SCAppLayerParserReallocCtx(alproto: AppProto) -> ::std::os::raw::c_int; } diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index dc2d9662ee..9fb91ef1b3 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -141,6 +141,12 @@ typedef struct AppLayerStateData { uint16_t file_flags; } AppLayerStateData; +typedef struct AppLayerGetTxIterTuple { + void *tx_ptr; + uint64_t tx_id; + bool has_next; +} AppLayerGetTxIterTuple; + /** \brief tx iterator prototype */ typedef AppLayerGetTxIterTuple (*AppLayerGetTxIteratorFunc) (const uint8_t ipproto, const AppProto alproto,