]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: expose last time as a function
authorJason Ish <jason.ish@oisf.net>
Tue, 3 Dec 2019 20:10:45 +0000 (14:10 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 28 Jan 2020 15:04:23 +0000 (16:04 +0100)
This function returns the individual components
of the timeval in output pointers making it suitable
for use over Rust FFI.

rust/src/core.rs
src/flow.c
src/flow.h

index 06dda376aa1128303d25de0b33b1e1496b519c46..ef892e66e8d1956273e28d748ecebd9087aa51f2 100644 (file)
@@ -21,7 +21,6 @@ use std;
 use crate::filecontainer::*;
 
 /// Opaque C types.
-pub enum Flow {}
 pub enum DetectEngineState {}
 pub enum AppLayerDecoderEvents {}
 
@@ -183,3 +182,26 @@ pub fn sc_app_layer_decoder_events_free_events(
         }
     }
 }
+
+/// Opaque flow type (defined in C)
+pub enum Flow {}
+
+/// Extern functions operating on Flow.
+extern {
+    pub fn FlowGetLastTimeAsParts(flow: &Flow, secs: *mut u64, usecs: *mut u64);
+}
+
+/// Rust implementation of Flow.
+impl Flow {
+
+    /// Return the time of the last flow update as a `Duration`
+    /// since the epoch.
+    pub fn get_last_time(&mut self) -> std::time::Duration {
+        unsafe {
+            let mut secs: u64 = 0;
+            let mut usecs: u64 = 0;
+            FlowGetLastTimeAsParts(self, &mut secs, &mut usecs);
+            std::time::Duration::new(secs, usecs as u32 * 1000)
+        }
+    }
+}
\ No newline at end of file
index 5fcf53135742ccff7275fbafe521b8710e67b3d2..adde85464234aa1dd85ccd299b4b4eb81de13014 100644 (file)
@@ -1113,6 +1113,19 @@ void FlowUpdateState(Flow *f, enum FlowState s)
     }
 }
 
+/**
+ * \brief Get flow last time as individual values.
+ *
+ * Instead of returning a pointer to the timeval copy the timeval
+ * parts into output pointers to make it simpler to call from Rust
+ * over FFI using only basic data types.
+ */
+void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs)
+{
+    *secs = (uint64_t)flow->lastts.tv_sec;
+    *usecs = (uint64_t)flow->lastts.tv_usec;
+}
+
 /************************************Unittests*******************************/
 
 #ifdef UNITTESTS
index cf6e729581cbfa80a60055769c64c7269e33bcff..b2eb217964834aa1a9265764a981e0fb5d00c04f 100644 (file)
@@ -537,6 +537,8 @@ uint64_t FlowGetMemuse(void);
 int GetFlowBypassInfoID(void);
 void RegisterFlowBypassInfo(void);
 
+void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs);
+
 /** ----- Inline functions ----- */
 
 /** \brief Set the No Packet Inspection Flag without locking the flow.