]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: introduce function to generate flow id
authorVictor Julien <victor@inliniac.net>
Wed, 31 Aug 2016 13:04:58 +0000 (15:04 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Sep 2016 07:05:52 +0000 (09:05 +0200)
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

index 0400250e23627b3062b72faebbe55acc6d8321d8..b5dbe570859927809778c48599c10f6e59c16234 100644 (file)
@@ -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);