]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: use bool wherever possible
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 13 Jun 2024 13:03:30 +0000 (18:33 +0530)
committerVictor Julien <victor@inliniac.net>
Sat, 22 Jun 2024 13:54:34 +0000 (15:54 +0200)
src/flow-manager.c
src/flow-timeout.c
src/flow-timeout.h
src/flow-worker.c

index b81b2dd9ffa1cf8e1ece217d9b81a5c6892c4a56..92eeea6b4a5899dd231a3453c835540f11b0699c 100644 (file)
@@ -175,10 +175,10 @@ again:
  *  \param f flow
  *  \param ts timestamp
  *
- *  \retval 0 not timed out
- *  \retval 1 timed out
+ *  \retval false not timed out
+ *  \retval true timed out
  */
-static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg)
+static bool FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const bool emerg)
 {
     uint32_t flow_times_out_at = f->timeout_at;
     if (emerg) {
@@ -190,10 +190,10 @@ static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const
 
     /* do the timeout check */
     if ((uint64_t)flow_times_out_at >= SCTIME_SECS(ts)) {
-        return 0;
+        return false;
     }
 
-    return 1;
+    return true;
 }
 
 /** \internal
@@ -203,14 +203,14 @@ static int FlowManagerFlowTimeout(Flow *f, SCTime_t ts, uint32_t *next_ts, const
  *  \param ts timestamp
  *  \param counters Flow timeout counters
  *
- *  \retval 0 not timeout
- *  \retval 1 timeout (or not capture bypassed)
+ *  \retval false not timeout
+ *  \retval true timeout (or not capture bypassed)
  */
-static inline int FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters *counters)
+static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters *counters)
 {
 #ifdef CAPTURE_OFFLOAD
     if (f->flow_state != FLOW_STATE_CAPTURE_BYPASSED) {
-        return 1;
+        return true;
     }
 
     FlowBypassInfo *fc = FlowGetStorageById(f, GetFlowBypassInfoID());
@@ -233,22 +233,20 @@ static inline int FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
             }
             counters->bypassed_pkts += pkts_tosrc + pkts_todst;
             counters->bypassed_bytes += bytes_tosrc + bytes_todst;
-            return 0;
-        } else {
-            SCLogDebug("No new packet, dead flow %"PRId64"", FlowGetId(f));
-            if (f->livedev) {
-                if (FLOW_IS_IPV4(f)) {
-                    LiveDevSubBypassStats(f->livedev, 1, AF_INET);
-                } else if (FLOW_IS_IPV6(f)) {
-                    LiveDevSubBypassStats(f->livedev, 1, AF_INET6);
-                }
+            return false;
+        }
+        SCLogDebug("No new packet, dead flow %" PRId64 "", FlowGetId(f));
+        if (f->livedev) {
+            if (FLOW_IS_IPV4(f)) {
+                LiveDevSubBypassStats(f->livedev, 1, AF_INET);
+            } else if (FLOW_IS_IPV6(f)) {
+                LiveDevSubBypassStats(f->livedev, 1, AF_INET6);
             }
-            counters->bypassed_count++;
-            return 1;
         }
+        counters->bypassed_count++;
     }
 #endif /* CAPTURE_OFFLOAD */
-    return 1;
+    return true;
 }
 
 typedef struct FlowManagerTimeoutThread {
@@ -269,7 +267,7 @@ static uint32_t ProcessAsideQueue(FlowManagerTimeoutThread *td, FlowTimeoutCount
 
         if (f->proto == IPPROTO_TCP &&
                 !(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) &&
-                !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f) == 1) {
+                !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f)) {
             /* Send the flow to its thread */
             FlowForceReassemblyForFlow(f);
             FLOWLOCK_UNLOCK(f);
@@ -319,8 +317,7 @@ static void FlowManagerHashRowTimeout(FlowManagerTimeoutThread *td, Flow *f, SCT
          * be modified when we have both the flow and hash row lock */
 
         /* timeout logic goes here */
-        if (FlowManagerFlowTimeout(f, ts, next_ts, emergency) == 0) {
-
+        if (FlowManagerFlowTimeout(f, ts, next_ts, emergency) == false) {
             counters->flows_notimeout++;
 
             prev_f = f;
index 5c75e242cb9476d9d150a695183993d2bee5800f..01d60fe251aa8b5d0b5a0a9567483f8f4261c902 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2017 Open Information Security Foundation
+/* Copyright (C) 2007-2024 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -281,14 +281,14 @@ Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSess
  *
  *  \param f *LOCKED* flow
  *
- *  \retval 0 no
- *  \retval 1 yes
+ *  \retval false no
+ *  \retval true yes
  */
-int FlowForceReassemblyNeedReassembly(Flow *f)
+bool FlowForceReassemblyNeedReassembly(Flow *f)
 {
 
     if (f == NULL || f->protoctx == NULL) {
-        SCReturnInt(0);
+        return false;
     }
 
     TcpSession *ssn = (TcpSession *)f->protoctx;
@@ -320,12 +320,12 @@ int FlowForceReassemblyNeedReassembly(Flow *f)
     /* nothing to do */
     if (client == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE &&
         server == STREAM_HAS_UNPROCESSED_SEGMENTS_NONE) {
-        SCReturnInt(0);
+        return false;
     }
 
     f->ffr_ts = client;
     f->ffr_tc = server;
-    SCReturnInt(1);
+    return true;
 }
 
 /**
@@ -392,7 +392,7 @@ static inline void FlowForceReassemblyForHash(void)
 
             /* in case of additional work, we pull the flow out of the
              * hash and xfer ownership to the injected packet(s) */
-            if (FlowForceReassemblyNeedReassembly(f) == 1) {
+            if (FlowForceReassemblyNeedReassembly(f)) {
                 RemoveFromHash(f, prev_f);
                 f->flow_end_flags |= FLOW_END_FLAG_SHUTDOWN;
                 FlowForceReassemblyForFlow(f);
index 7ca895e72821eac12cde29f38283b50228c2c357..467fd821cdd32baffec84b7404c3d29ea7e0cd8b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2012 Open Information Security Foundation
+/* Copyright (C) 2007-2024 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -27,7 +27,7 @@
 #include "stream-tcp-private.h"
 
 void FlowForceReassemblyForFlow(Flow *f);
-int FlowForceReassemblyNeedReassembly(Flow *f);
+bool FlowForceReassemblyNeedReassembly(Flow *f);
 void FlowForceReassembly(void);
 Packet *FlowForceReassemblyPseudoPacketGet(int direction, Flow *f, const TcpSession *ssn);
 
index 3efb290da44cd217e7156e76e5d22c852edd6714..1983111a1b44019b1a7f5a438f9dd01ad1e4ac90 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2016-2020 Open Information Security Foundation
+/* Copyright (C) 2016-2024 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -166,8 +166,7 @@ static void CheckWorkQueue(ThreadVars *tv, FlowWorkerThreadData *fw, FlowTimeout
 
         if (f->proto == IPPROTO_TCP) {
             if (!(f->flags & (FLOW_TIMEOUT_REASSEMBLY_DONE | FLOW_ACTION_DROP)) &&
-                    !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f) == 1 &&
-                    f->ffr != 0) {
+                    !FlowIsBypassed(f) && FlowForceReassemblyNeedReassembly(f) && f->ffr != 0) {
                 /* read detect thread in case we're doing a reload */
                 void *detect_thread = SC_ATOMIC_GET(fw->detect_thread);
                 int cnt = FlowFinish(tv, f, fw, detect_thread);