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.
pull/6285/head
Jason Ish 4 years ago committed by Shivani Bhardwaj
parent cb8bd8c669
commit 222e55847c

@ -226,6 +226,9 @@ pub enum Flow {}
/// Extern functions operating on Flow. /// Extern functions operating on Flow.
extern { extern {
pub fn FlowGetLastTimeAsParts(flow: &Flow, secs: *mut u64, usecs: *mut u64); 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. /// Rust implementation of Flow.
@ -241,4 +244,14 @@ impl Flow {
std::time::Duration::new(secs, usecs as u32 * 1000) 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)) }
}
} }

@ -1171,6 +1171,39 @@ void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs)
*usecs = (uint64_t)flow->lastts.tv_usec; *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*******************************/ /************************************Unittests*******************************/
#ifdef UNITTESTS #ifdef UNITTESTS

@ -586,6 +586,9 @@ FlowStorageId GetFlowBypassInfoID(void);
void RegisterFlowBypassInfo(void); void RegisterFlowBypassInfo(void);
void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs); 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 ----- */ /** ----- Inline functions ----- */

Loading…
Cancel
Save