]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: declare and use constansts where possible
authorShivani Bhardwaj <shivani@oisf.net>
Fri, 21 Jun 2024 08:25:59 +0000 (13:55 +0530)
committerVictor Julien <victor@inliniac.net>
Sat, 22 Jun 2024 13:54:34 +0000 (15:54 +0200)
src/flow-manager.c
src/flow-spare-pool.c
src/flow-spare-pool.h
src/flow-worker.c

index 5eeeca15c90beb795cb5d2472dffb4a890d2f518..bd547de95bd138049f9754f589cb217dc47bcfa1 100644 (file)
@@ -573,6 +573,7 @@ static uint32_t FlowManagerHashRowCleanup(Flow *f, FlowQueuePrivate *recycle_q,
     return cnt;
 }
 
+#define RECYCLE_MAX_QUEUE_ITEMS 25
 /**
  *  \brief remove all flows from the hash
  *
@@ -598,12 +599,12 @@ static uint32_t FlowCleanupHash(void)
         }
 
         FBLOCK_UNLOCK(fb);
-        if (local_queue.len >= 25) {
+        if (local_queue.len >= RECYCLE_MAX_QUEUE_ITEMS) {
             FlowQueueAppendPrivate(&flow_recycle_q, &local_queue);
             FlowWakeupFlowRecyclerThread();
         }
     }
-    DEBUG_VALIDATE_BUG_ON(local_queue.len >= 25);
+    DEBUG_VALIDATE_BUG_ON(local_queue.len >= RECYCLE_MAX_QUEUE_ITEMS);
     FlowQueueAppendPrivate(&flow_recycle_q, &local_queue);
     FlowWakeupFlowRecyclerThread();
 
@@ -1066,8 +1067,6 @@ static void Recycler(ThreadVars *tv, FlowRecyclerThreadData *ftd, Flow *f)
     FLOWLOCK_UNLOCK(f);
 }
 
-extern uint32_t flow_spare_pool_block_size;
-
 /** \brief Thread that manages timed out flows.
  *
  *  \param td ThreadVars cast to void ptr
@@ -1108,7 +1107,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
 
             /* for every full sized block, add it to the spare pool */
             FlowQueuePrivateAppendFlow(&ret_queue, f);
-            if (ret_queue.len == flow_spare_pool_block_size) {
+            if (ret_queue.len == FLOW_SPARE_POOL_BLOCK_SIZE) {
                 FlowSparePoolReturnFlows(&ret_queue);
             }
         }
index e47b983b8e04b8c1371490d9c14accfe8d3f4907..1bfd31cac2f15ef3d5644550ef68c847ca7b4827 100644 (file)
@@ -40,7 +40,6 @@ typedef struct FlowSparePool {
 } FlowSparePool;
 
 static uint32_t flow_spare_pool_flow_cnt = 0;
-uint32_t flow_spare_pool_block_size = 100;
 static FlowSparePool *flow_spare_pool = NULL;
 static SCMutex flow_spare_pool_m = SCMUTEX_INITIALIZER;
 
@@ -65,8 +64,7 @@ static bool FlowSparePoolUpdateBlock(FlowSparePool *p)
 {
     DEBUG_VALIDATE_BUG_ON(p == NULL);
 
-    for (uint32_t i = p->queue.len; i < flow_spare_pool_block_size; i++)
-    {
+    for (uint32_t i = p->queue.len; i < FLOW_SPARE_POOL_BLOCK_SIZE; i++) {
         Flow *f = FlowAlloc();
         if (f == NULL)
             return false;
@@ -84,8 +82,8 @@ static void Validate(FlowSparePool *top, const uint32_t target)
     }
 
     assert(top->queue.len >= 1);
-    //if (top->next != NULL)
-    //    assert(top->next->queue.len == flow_spare_pool_block_size);
+    // if (top->next != NULL)
+    //     assert(top->next->queue.len == FLOW_SPARE_POOL_BLOCK_SIZE);
 
     uint32_t cnt = 0;
     for (FlowSparePool *p = top; p != NULL; p = p->next)
@@ -106,7 +104,7 @@ void FlowSparePoolReturnFlow(Flow *f)
     DEBUG_VALIDATE_BUG_ON(flow_spare_pool == NULL);
 
     /* if the top is full, get a new block */
-    if (flow_spare_pool->queue.len >= flow_spare_pool_block_size) {
+    if (flow_spare_pool->queue.len >= FLOW_SPARE_POOL_BLOCK_SIZE) {
         FlowSparePool *p = FlowSpareGetPool();
         DEBUG_VALIDATE_BUG_ON(p == NULL);
         p->next = flow_spare_pool;
@@ -128,10 +126,10 @@ void FlowSparePoolReturnFlows(FlowQueuePrivate *fqp)
     SCMutexLock(&flow_spare_pool_m);
     flow_spare_pool_flow_cnt += fqp->len;
     if (flow_spare_pool != NULL) {
-        if (p->queue.len == flow_spare_pool_block_size) {
+        if (p->queue.len == FLOW_SPARE_POOL_BLOCK_SIZE) {
             /* full block insert */
 
-            if (flow_spare_pool->queue.len < flow_spare_pool_block_size) {
+            if (flow_spare_pool->queue.len < FLOW_SPARE_POOL_BLOCK_SIZE) {
                 p->next = flow_spare_pool->next;
                 flow_spare_pool->next = p;
                 p = NULL;
@@ -143,7 +141,7 @@ void FlowSparePoolReturnFlows(FlowQueuePrivate *fqp)
         } else {
             /* incomplete block insert */
 
-            if (p->queue.len + flow_spare_pool->queue.len <= flow_spare_pool_block_size) {
+            if (p->queue.len + flow_spare_pool->queue.len <= FLOW_SPARE_POOL_BLOCK_SIZE) {
                 FlowQueuePrivateAppendPrivate(&flow_spare_pool->queue, &p->queue);
                 /* free 'p' outside of lock below */
             } else {
@@ -182,7 +180,7 @@ FlowQueuePrivate FlowSpareGetFromPool(void)
     }
 
     /* top if full or its the only block we have */
-    if (flow_spare_pool->queue.len >= flow_spare_pool_block_size || flow_spare_pool->next == NULL) {
+    if (flow_spare_pool->queue.len >= FLOW_SPARE_POOL_BLOCK_SIZE || flow_spare_pool->next == NULL) {
         FlowSparePool *p = flow_spare_pool;
         flow_spare_pool = p->next;
         DEBUG_VALIDATE_BUG_ON(flow_spare_pool_flow_cnt < p->queue.len);
@@ -222,7 +220,7 @@ void FlowSparePoolUpdate(uint32_t size)
     if (todo < 0) {
         uint32_t to_remove = (uint32_t)(todo * -1) / 10;
         while (to_remove) {
-            if (to_remove < flow_spare_pool_block_size)
+            if (to_remove < FLOW_SPARE_POOL_BLOCK_SIZE)
                 return;
 
             FlowSparePool *p = NULL;
@@ -246,7 +244,7 @@ void FlowSparePoolUpdate(uint32_t size)
     } else if (todo > 0) {
         FlowSparePool *head = NULL, *tail = NULL;
 
-        uint32_t blocks = ((uint32_t)todo / flow_spare_pool_block_size) + 1;
+        uint32_t blocks = ((uint32_t)todo / FLOW_SPARE_POOL_BLOCK_SIZE) + 1;
 
         uint32_t flow_cnt = 0;
         for (uint32_t cnt = 0; cnt < blocks; cnt++) {
index 0fdf723ac37ba90e7b6c3dd7efdb2de4a52ceea3..9932ae5cc3633ab979d8e9c9c76990caa2827bb3 100644 (file)
@@ -27,6 +27,8 @@
 #include "suricata-common.h"
 #include "flow.h"
 
+#define FLOW_SPARE_POOL_BLOCK_SIZE 100
+
 void FlowSparePoolInit(void);
 void FlowSparePoolDestroy(void);
 void FlowSparePoolUpdate(uint32_t size);
index 61a3811f09a193b0a475b078be446b6dd4732af4..3bb91adf5aa2a61cf98c31506e06ab92b50d1a05 100644 (file)
@@ -151,8 +151,6 @@ static int FlowFinish(ThreadVars *tv, Flow *f, FlowWorkerThreadData *fw, void *d
     return cnt;
 }
 
-extern uint32_t flow_spare_pool_block_size;
-
 /** \param[in] max_work Max flows to process. 0 if unlimited. */
 static void CheckWorkQueue(ThreadVars *tv, FlowWorkerThreadData *fw, FlowTimeoutCounters *counters,
         FlowQueuePrivate *fq, const uint32_t max_work)
@@ -190,9 +188,9 @@ static void CheckWorkQueue(ThreadVars *tv, FlowWorkerThreadData *fw, FlowTimeout
         FlowClearMemory (f, f->protomap);
         FLOWLOCK_UNLOCK(f);
 
-        if (fw->fls.spare_queue.len >= (flow_spare_pool_block_size * 2)) {
+        if (fw->fls.spare_queue.len >= (FLOW_SPARE_POOL_BLOCK_SIZE * 2)) {
             FlowQueuePrivatePrependFlow(&ret_queue, f);
-            if (ret_queue.len == flow_spare_pool_block_size) {
+            if (ret_queue.len == FLOW_SPARE_POOL_BLOCK_SIZE) {
                 FlowSparePoolReturnFlows(&ret_queue);
             }
         } else {