From 222e55847caa4bbe65faa6ae4b025f3982fda615 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 14 May 2021 09:29:54 -0600 Subject: [PATCH] flow: provide flags accessor function 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 | 13 +++++++++++++ src/flow.c | 33 +++++++++++++++++++++++++++++++++ src/flow.h | 3 +++ 3 files changed, 49 insertions(+) diff --git a/rust/src/core.rs b/rust/src/core.rs index 62c8a599d2..2e773e2cfc 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -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)) } + } } diff --git a/src/flow.c b/src/flow.c index 4a94c4ef9b..4b5de49574 100644 --- a/src/flow.c +++ b/src/flow.c @@ -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 diff --git a/src/flow.h b/src/flow.h index e48e5fad54..ff3022856a 100644 --- a/src/flow.h +++ b/src/flow.h @@ -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 ----- */ -- 2.47.2