]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: convert flow_id to uint64 as no signdess is necessary
authorLukas Sismis <lsismis@oisf.net>
Sat, 24 May 2025 00:04:21 +0000 (02:04 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 5 Jun 2025 17:14:30 +0000 (19:14 +0200)
src/flow-hash.c
src/flow-hash.h
src/flow-manager.c
src/flow.h
src/output-json.c
src/util-ebpf.c
src/util-lua-flowlib.c

index fb4892d802c683eeff7595f12464d6c25b6d4ad8..2642dad3056966475e2453ad3ce3ea8578722630 100644 (file)
@@ -1030,7 +1030,7 @@ static inline bool FlowCompareKey(Flow *f, FlowKey *key)
  *  \param flow_id Flow ID of the flow to look for
  *  \retval f *LOCKED* flow or NULL
  */
-Flow *FlowGetExistingFlowFromFlowId(int64_t flow_id)
+Flow *FlowGetExistingFlowFromFlowId(uint64_t flow_id)
 {
     uint32_t hash = flow_id & 0x0000FFFF;
     FlowBucket *fb = &flow_hash[hash % flow_config.hash_size];
index 0f1d9bf1138f70dae50ed1be555d6ebcd26216ce..35c5b61c94cce39b002e7d4d3b9c22e574020173 100644 (file)
@@ -82,7 +82,7 @@ typedef struct FlowBucket_ {
 Flow *FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *tctx, Packet *, Flow **);
 
 Flow *FlowGetFromFlowKey(FlowKey *key, struct timespec *ttime, const uint32_t hash);
-Flow *FlowGetExistingFlowFromFlowId(int64_t flow_id);
+Flow *FlowGetExistingFlowFromFlowId(uint64_t flow_id);
 uint32_t FlowKeyGetHash(FlowKey *flow_key);
 uint32_t FlowGetIpPairProtoHash(const Packet *p);
 
index a91b7906a3aa63a8fdf74adc421f9c73b80af953..26b9485652f9bb3540248803c37bc18775c5218e 100644 (file)
@@ -246,7 +246,7 @@ static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
         uint64_t bytes_todst = fc->todstbytecnt;
         bool update = fc->BypassUpdate(f, fc->bypass_data, SCTIME_SECS(ts));
         if (update) {
-            SCLogDebug("Updated flow: %"PRId64"", FlowGetId(f));
+            SCLogDebug("Updated flow: %" PRIu64 "", FlowGetId(f));
             pkts_tosrc = fc->tosrcpktcnt - pkts_tosrc;
             bytes_tosrc = fc->tosrcbytecnt - bytes_tosrc;
             pkts_todst = fc->todstpktcnt - pkts_todst;
@@ -259,7 +259,7 @@ static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
             counters->bypassed_bytes += bytes_tosrc + bytes_todst;
             return false;
         }
-        SCLogDebug("No new packet, dead flow %" PRId64 "", FlowGetId(f));
+        SCLogDebug("No new packet, dead flow %" PRIu64 "", FlowGetId(f));
         if (f->livedev) {
             if (FLOW_IS_IPV4(f)) {
                 LiveDevSubBypassStats(f->livedev, 1, AF_INET);
index 02d8ee7656b4931697a57b81c62d7a61d54d9992..43e438207cc2dbe839047440ed548ef68b204069 100644 (file)
@@ -634,14 +634,12 @@ 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
+ *  \retval flow_id unsigned 64bit id
  */
-static inline int64_t FlowGetId(const Flow *f)
+static inline uint64_t FlowGetId(const Flow *f)
 {
-    int64_t id = (uint64_t)(SCTIME_SECS(f->startts) & 0x0000FFFF) << 48 |
-                 (uint64_t)(SCTIME_USECS(f->startts) & 0x0000FFFF) << 32 | (int64_t)f->flow_hash;
+    uint64_t id = (uint64_t)(SCTIME_SECS(f->startts) & 0xFFFF) << 48 |
+                  (uint64_t)(SCTIME_USECS(f->startts) & 0xFFFF) << 32 | (uint64_t)f->flow_hash;
     /* reduce to 51 bits as JavaScript and even JSON often seem to
      * max out there. */
     id &= 0x7ffffffffffffLL;
index 512274eeb59f4779fbd98212f530798039ea940c..bf724fc8526ae99a5bcaff3784f728a6fa4e4670 100644 (file)
@@ -702,7 +702,7 @@ void CreateEveFlowId(SCJsonBuilder *js, const Flow *f)
     if (f == NULL) {
         return;
     }
-    int64_t flow_id = FlowGetId(f);
+    uint64_t flow_id = FlowGetId(f);
     SCJbSetUint(js, "flow_id", flow_id);
     if (f->parent_id) {
         SCJbSetUint(js, "parent_id", f->parent_id);
index 3acef3e0a571735ab0b5568137fbb8bc6edddf6d..7b7294d993b4f1e913e088a130a1f70dfd7067ff 100644 (file)
@@ -654,7 +654,7 @@ bool EBPFBypassUpdate(Flow *f, void *data, time_t tsec)
     bool activity = EBPFBypassCheckHalfFlow(f, fc, eb, eb->key[0], 0);
     activity |= EBPFBypassCheckHalfFlow(f, fc, eb, eb->key[1], 1);
     if (!activity) {
-        SCLogDebug("Delete entry: %u (%ld)", FLOW_IS_IPV6(f), FlowGetId(f));
+        SCLogDebug("Delete entry: %u (%" PRIu64 ")", FLOW_IS_IPV6(f), FlowGetId(f));
         /* delete the entries if no time update */
         EBPFDeleteKey(eb->mapfd, eb->key[0]);
         EBPFDeleteKey(eb->mapfd, eb->key[1]);
index 67c429f72c7fb7bf1f4a403baaaaf242fe56ccf9..4ad39a404d8e7aefe2181abe2f82cc7c155d0a0c 100644 (file)
@@ -67,7 +67,7 @@ static int LuaFlowId(lua_State *luastate)
 
     Flow *f = s->f;
 
-    int64_t id = FlowGetId(f);
+    int64_t id = (int64_t)FlowGetId(f);
     lua_pushinteger(luastate, id);
     return 1;
 }