From: Jason Ish Date: Thu, 31 May 2018 22:39:22 +0000 (-0600) Subject: rust/app-layer: macros to export de_state functions X-Git-Tag: suricata-4.1.0-rc1~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ec33816007ee27163e433fa6832b95f0695afb7;p=thirdparty%2Fsuricata.git rust/app-layer: macros to export de_state functions 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. --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 6a0a8e0fce..641c5e0003 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -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 + } + ) +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0a6e0652cc..00b0a5c9ec 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -35,6 +35,7 @@ pub mod core; pub mod conf; pub mod json; +#[macro_use] pub mod applayer; pub mod filecontainer; pub mod filetracker;