]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: provide flags accessor function
authorJason Ish <jason.ish@oisf.net>
Fri, 14 May 2021 15:29:54 +0000 (09:29 -0600)
committerShivani Bhardwaj <shivanib134@gmail.com>
Thu, 5 Aug 2021 15:09:49 +0000 (20:39 +0530)
Add an accessor function for flow flags. To be used by Rust where
the flow struct is an opaque data type.

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

index 62c8a599d22b55ce6efd12bb52b33a70e7b16ec2..2e773e2cfcf01455e6bc94c1f2987127f37f9420 100644 (file)
@@ -226,6 +226,9 @@ pub enum Flow {}
 /// Extern functions operating on Flow.
 extern {
     pub fn FlowGetLastTimeAsParts(flow: &Flow, secs: *mut u64, usecs: *mut u64);
+    pub fn FlowGetFlags(flow: &Flow) -> u32;
+    pub fn FlowGetSourcePort(flow: &Flow) -> u16;
+    pub fn FlowGetDestinationPort(flow: &Flow) -> u16;
 }
 
 /// Rust implementation of Flow.
@@ -241,4 +244,14 @@ impl Flow {
             std::time::Duration::new(secs, usecs as u32 * 1000)
         }
     }
+
+    /// Return the flow flags.
+    pub fn get_flags(&self) -> u32 {
+        unsafe { FlowGetFlags(self) }
+    }
+
+    /// Return flow ports
+    pub fn get_ports(&self) -> (u16, u16) {
+        unsafe { (FlowGetSourcePort(self), FlowGetDestinationPort(self)) }
+    }
 }
index 4a94c4ef9bb8e1db64014c9ba20c49fda2a054ac..4b5de495740b3979119a9d54d44ab97ec95ecdc6 100644 (file)
@@ -1171,6 +1171,39 @@ void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs)
     *usecs = (uint64_t)flow->lastts.tv_usec;
 }
 
+/**
+ * \brief Get flow source port.
+ *
+ * A function to get the flow sport useful when the caller only has an
+ * opaque pointer to the flow structure.
+ */
+uint16_t FlowGetSourcePort(Flow *flow)
+{
+    return flow->sp;
+}
+
+/**
+ * \brief Get flow destination port.
+ *
+ * A function to get the flow dport useful when the caller only has an
+ * opaque pointer to the flow structure.
+ */
+
+uint16_t FlowGetDestinationPort(Flow *flow)
+{
+    return flow->dp;
+}
+/**
+ * \brief Get flow flags.
+ *
+ * A function to get the flow flags useful when the caller only has an
+ * opaque pointer to the flow structure.
+ */
+
+uint32_t FlowGetFlags(Flow *flow)
+{
+    return flow->flags;
+}
 /************************************Unittests*******************************/
 
 #ifdef UNITTESTS
index e48e5fad541a06dde06543f668bf97e445738d11..ff3022856ac7ce7b3c92ed8b960a1ddf4d2a8d33 100644 (file)
@@ -586,6 +586,9 @@ FlowStorageId GetFlowBypassInfoID(void);
 void RegisterFlowBypassInfo(void);
 
 void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs);
+uint32_t FlowGetFlags(Flow *flow);
+uint16_t FlowGetSourcePort(Flow *flow);
+uint16_t FlowGetDestinationPort(Flow *flow);
 
 /** ----- Inline functions ----- */