From 78b4db8a954f5937d07ec494e7113e292228e189 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 31 Aug 2016 15:04:58 +0200 Subject: [PATCH] flow: introduce function to generate flow id The flow id itself is not stored in the flow, but generated based on properties that do not change during the lifetime of the flow. As it's meant for use with the json output, it is limited to a signed 64 bit integer (int64_t) because that is the time json_integer_t uses. --- src/flow.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/flow.h b/src/flow.h index 0400250e23..b5dbe57085 100644 --- a/src/flow.h +++ b/src/flow.h @@ -536,6 +536,18 @@ static inline void FlowDeReference(Flow **d) } } +/** \brief create a flow id that is as unique as possible + * \retval flow_id signed 64bit id + * \note signed because of the signedness of json_integer_t in + * the json output + */ +static inline int64_t FlowGetId(const Flow *f) +{ + return (int64_t)f->flow_hash << 31 | + (int64_t)(f->startts.tv_sec & 0x0000FFFF) << 16 | + (int64_t)(f->startts.tv_usec & 0x0000FFFF); +} + int FlowClearMemory(Flow *,uint8_t ); AppProto FlowGetAppProtocol(const Flow *f);