]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: make next_ts unsigned
authorVictor Julien <vjulien@oisf.net>
Tue, 24 Jan 2023 19:54:40 +0000 (20:54 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 25 Jan 2023 11:29:53 +0000 (12:29 +0100)
To silence a coverity warning.

src/flow-hash.c
src/flow-hash.h
src/flow-manager.c

index 9f590f23919d39dfa6d4dd00e0bd2b2c3ce95cb4..b8890bc0b4ad6ecc6e5e36553e097e44e6276f40 100644 (file)
@@ -1120,7 +1120,7 @@ static Flow *FlowGetUsedFlow(ThreadVars *tv, DecodeThreadVars *dtv, const SCTime
 
         FlowBucket *fb = &flow_hash[idx];
 
-        if (SC_ATOMIC_GET(fb->next_ts) == INT_MAX)
+        if (SC_ATOMIC_GET(fb->next_ts) == UINT_MAX)
             continue;
 
         if (GetUsedTryLockBucket(fb) != 0) {
index e109e5531670723b16572328447114f13dda61d0..d489fb5b60878dd7b0b52c9d0866f1452433cf05 100644 (file)
@@ -56,9 +56,9 @@ typedef struct FlowBucket_ {
     /** timestamp in seconds of the earliest possible moment a flow
      *  will time out in this row. Set by the flow manager. Cleared
      *  to 0 by workers, either when new flows are added or when a
-     *  flow state changes. The flow manager sets this to INT_MAX for
+     *  flow state changes. The flow manager sets this to UINT_MAX for
      *  empty buckets. */
-    SC_ATOMIC_DECLARE(int32_t, next_ts);
+    SC_ATOMIC_DECLARE(uint32_t, next_ts);
 } __attribute__((aligned(CLS))) FlowBucket;
 
 #ifdef FBLOCK_SPIN
index 17b1ae988942e8a09d3d510372817b49d784cd1d..25bd114e1e7994ff1aabdb341b054515dbdde525 100644 (file)
@@ -193,9 +193,9 @@ again:
  *  \retval 0 not timed out
  *  \retval 1 timed out
  */
-static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, int32_t *next_ts, const bool emerg)
+static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg)
 {
-    int32_t flow_times_out_at = f->timeout_at;
+    uint32_t flow_times_out_at = f->timeout_at;
     if (emerg) {
         extern FlowProtoTimeout flow_timeouts_delta[FLOW_PROTO_MAX];
         flow_times_out_at -= FlowGetFlowTimeoutDirect(flow_timeouts_delta, f->flow_state, f->protomap);
@@ -204,7 +204,7 @@ static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, int32_t *next_ts, const
         *next_ts = flow_times_out_at;
 
     /* do the timeout check */
-    if (flow_times_out_at >= (time_t)SCTIME_SECS(ts)) {
+    if ((uint64_t)flow_times_out_at >= SCTIME_SECS(ts)) {
         return 0;
     }
 
@@ -319,7 +319,7 @@ static uint32_t ProcessAsideQueue(FlowManagerTimeoutThread *td, FlowTimeoutCount
  *  \param counters ptr to FlowTimeoutCounters structure
  */
 static void FlowManagerHashRowTimeout(FlowManagerTimeoutThread *td, Flow *f, SCTime_t ts,
-        int emergency, FlowTimeoutCounters *counters, int32_t *next_ts)
+        int emergency, FlowTimeoutCounters *counters, uint32_t *next_ts)
 {
     uint32_t checked = 0;
     Flow *prev_f = NULL;
@@ -420,14 +420,14 @@ static uint32_t FlowTimeoutHash(FlowManagerTimeoutThread *td, SCTime_t ts, const
 #define TYPE uint32_t
 #endif
 
-    time_t ts_secs = SCTIME_SECS(ts);
+    const uint32_t ts_secs = SCTIME_SECS(ts);
     for (uint32_t idx = hash_min; idx < hash_max; idx+=BITS) {
         TYPE check_bits = 0;
         const uint32_t check = MIN(BITS, (hash_max - idx));
         for (uint32_t i = 0; i < check; i++) {
             FlowBucket *fb = &flow_hash[idx+i];
-            check_bits |= (TYPE)(SC_ATOMIC_LOAD_EXPLICIT(fb->next_ts,
-                                         SC_ATOMIC_MEMORY_ORDER_RELAXED) <= (int32_t)ts_secs)
+            check_bits |= (TYPE)(SC_ATOMIC_LOAD_EXPLICIT(
+                                         fb->next_ts, SC_ATOMIC_MEMORY_ORDER_RELAXED) <= ts_secs)
                           << (TYPE)i;
         }
         if (check_bits == 0)
@@ -435,8 +435,7 @@ static uint32_t FlowTimeoutHash(FlowManagerTimeoutThread *td, SCTime_t ts, const
 
         for (uint32_t i = 0; i < check; i++) {
             FlowBucket *fb = &flow_hash[idx+i];
-            if ((check_bits & ((TYPE)1 << (TYPE)i)) != 0 &&
-                    SC_ATOMIC_GET(fb->next_ts) <= (int32_t)ts_secs) {
+            if ((check_bits & ((TYPE)1 << (TYPE)i)) != 0 && SC_ATOMIC_GET(fb->next_ts) <= ts_secs) {
                 FBLOCK_LOCK(fb);
                 Flow *evicted = NULL;
                 if (fb->evicted != NULL || fb->head != NULL) {
@@ -447,17 +446,17 @@ static uint32_t FlowTimeoutHash(FlowManagerTimeoutThread *td, SCTime_t ts, const
                         fb->evicted = NULL;
                     }
                     if (fb->head != NULL) {
-                        int32_t next_ts = 0;
+                        uint32_t next_ts = 0;
                         FlowManagerHashRowTimeout(td, fb->head, ts, emergency, counters, &next_ts);
 
                         if (SC_ATOMIC_GET(fb->next_ts) != next_ts)
                             SC_ATOMIC_SET(fb->next_ts, next_ts);
                     }
                     if (fb->evicted == NULL && fb->head == NULL) {
-                        SC_ATOMIC_SET(fb->next_ts, INT_MAX);
+                        SC_ATOMIC_SET(fb->next_ts, UINT_MAX);
                     }
                 } else {
-                    SC_ATOMIC_SET(fb->next_ts, INT_MAX);
+                    SC_ATOMIC_SET(fb->next_ts, UINT_MAX);
                     rows_empty++;
                 }
                 FBLOCK_UNLOCK(fb);