diff --git a/doc/userguide/devguide/extending/flow-lifecycle-callbacks.rst b/doc/userguide/devguide/extending/flow-lifecycle-callbacks.rst index d25359e6d8..601a55be24 100644 --- a/doc/userguide/devguide/extending/flow-lifecycle-callbacks.rst +++ b/doc/userguide/devguide/extending/flow-lifecycle-callbacks.rst @@ -104,21 +104,21 @@ The Rust wrappers register closures or function items and return .. code-block:: rust - use suricata_ffi::flow; + use suricata_ffi::flow::{self, Flow}; use suricata_ffi::packet::Packet; use suricata_ffi::SCLogNotice; - use suricata_sys::sys::{Flow, ThreadVars}; + use suricata_sys::sys::ThreadVars; - fn flow_init(_tv: *mut ThreadVars, f: *mut Flow, _p: Option>) { - SCLogNotice!("flow initialized: {:p}", f); + fn flow_init(_tv: *mut ThreadVars, f: Flow<'_>, _p: Option>) { + SCLogNotice!("flow initialized: {:p}", f.as_ptr()); } - fn flow_update(_tv: *mut ThreadVars, f: *mut Flow, p: Option>) { - SCLogNotice!("flow updated: {:p} has_packet: {}", f, p.is_some()); + fn flow_update(_tv: *mut ThreadVars, f: Flow<'_>, p: Option>) { + SCLogNotice!("flow updated: {:p} has_packet: {}", f.as_ptr(), p.is_some()); } - fn flow_finish(_tv: *mut ThreadVars, f: *mut Flow) { - SCLogNotice!("flow finished: {:p}", f); + fn flow_finish(_tv: *mut ThreadVars, f: Flow<'_>) { + SCLogNotice!("flow finished: {:p}", f.as_ptr()); } fn register_flow_callbacks() -> Result<(), &'static str> { diff --git a/examples/plugins/rust/src/mod.rs b/examples/plugins/rust/src/mod.rs index 4e03a6083a..2d9e5783c3 100644 --- a/examples/plugins/rust/src/mod.rs +++ b/examples/plugins/rust/src/mod.rs @@ -65,24 +65,24 @@ fn log_eve_wrapped( Ok(()) } -fn log_flow_init(_tv: *mut ThreadVars, f: *mut RawFlow, p: Option>) { +fn log_flow_init(_tv: *mut ThreadVars, f: Flow<'_>, p: Option>) { SCLogNotice!( "rust example flow init callback: flow={:p}, has_packet={}", - f, + f.as_ptr(), p.is_some() ); } -fn log_flow_update(_tv: *mut ThreadVars, f: *mut RawFlow, p: Option>) { +fn log_flow_update(_tv: *mut ThreadVars, f: Flow<'_>, p: Option>) { SCLogNotice!( "rust example flow update callback: flow={:p}, has_packet={}", - f, + f.as_ptr(), p.is_some() ); } -fn log_flow_finish(_tv: *mut ThreadVars, f: *mut RawFlow) { - SCLogNotice!("rust example flow finish callback: flow={:p}", f); +fn log_flow_finish(_tv: *mut ThreadVars, f: Flow<'_>) { + SCLogNotice!("rust example flow finish callback: flow={:p}", f.as_ptr()); } #[no_mangle] diff --git a/rust/ffi/src/flow.rs b/rust/ffi/src/flow.rs index 2f78fdd7da..4a483f446b 100644 --- a/rust/ffi/src/flow.rs +++ b/rust/ffi/src/flow.rs @@ -56,7 +56,7 @@ impl<'a> Flow<'a> { /// The callback must not panic. pub fn register_init_callback(callback: F) -> Result<(), &'static str> where - F: for<'a> Fn(*mut ThreadVars, *mut RawFlow, Option>) + F: for<'a> Fn(*mut ThreadVars, Flow<'a>, Option>) + Send + Sync + 'static, @@ -88,7 +88,7 @@ where /// The callback must not panic. pub fn register_update_callback(callback: F) -> Result<(), &'static str> where - F: for<'a> Fn(*mut ThreadVars, *mut RawFlow, Option>) + F: for<'a> Fn(*mut ThreadVars, Flow<'a>, Option>) + Send + Sync + 'static, @@ -118,7 +118,7 @@ where /// The callback must not panic. pub fn register_finish_callback(callback: F) -> Result<(), &'static str> where - F: Fn(*mut ThreadVars, *mut RawFlow) + Send + Sync + 'static, + F: for<'a> Fn(*mut ThreadVars, Flow<'a>) + Send + Sync + 'static, { let user = Box::into_raw(Box::new(callback)) as *mut c_void; if unsafe { SCFlowRegisterFinishCallback(Some(finish_callback_wrapper::), user) } { @@ -134,7 +134,7 @@ where unsafe extern "C" fn init_callback_wrapper( tv: *mut ThreadVars, f: *mut RawFlow, p: *const RawPacket, user: *mut c_void, ) where - F: for<'a> Fn(*mut ThreadVars, *mut RawFlow, Option>) + F: for<'a> Fn(*mut ThreadVars, Flow<'a>, Option>) + Send + Sync + 'static, @@ -145,13 +145,13 @@ unsafe extern "C" fn init_callback_wrapper( } else { Some(crate::packet::Packet::from_ptr(p)) }; - callback(tv, f, packet); + callback(tv, Flow::from_ptr(f), packet); } unsafe extern "C" fn update_callback_wrapper( tv: *mut ThreadVars, f: *mut RawFlow, p: *mut RawPacket, user: *mut c_void, ) where - F: for<'a> Fn(*mut ThreadVars, *mut RawFlow, Option>) + F: for<'a> Fn(*mut ThreadVars, Flow<'a>, Option>) + Send + Sync + 'static, @@ -162,14 +162,14 @@ unsafe extern "C" fn update_callback_wrapper( } else { Some(crate::packet::Packet::from_ptr(p)) }; - callback(tv, f, packet); + callback(tv, Flow::from_ptr(f), packet); } unsafe extern "C" fn finish_callback_wrapper( tv: *mut ThreadVars, f: *mut RawFlow, user: *mut c_void, ) where - F: Fn(*mut ThreadVars, *mut RawFlow) + Send + Sync + 'static, + F: for<'a> Fn(*mut ThreadVars, Flow<'a>) + Send + Sync + 'static, { let callback = &*(user as *const F); - callback(tv, f); + callback(tv, Flow::from_ptr(f)); }