From: Shivani Bhardwaj Date: Fri, 21 Jun 2024 08:25:59 +0000 (+0530) Subject: flow: declare and use constansts where possible X-Git-Tag: suricata-8.0.0-beta1~1116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=903283d76e27b66b57be1a5fb8a3ae9e9c10a0f7;p=thirdparty%2Fsuricata.git flow: declare and use constansts where possible --- diff --git a/src/flow-manager.c b/src/flow-manager.c index 5eeeca15c9..bd547de95b 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -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); } } diff --git a/src/flow-spare-pool.c b/src/flow-spare-pool.c index e47b983b8e..1bfd31cac2 100644 --- a/src/flow-spare-pool.c +++ b/src/flow-spare-pool.c @@ -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++) { diff --git a/src/flow-spare-pool.h b/src/flow-spare-pool.h index 0fdf723ac3..9932ae5cc3 100644 --- a/src/flow-spare-pool.h +++ b/src/flow-spare-pool.h @@ -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); diff --git a/src/flow-worker.c b/src/flow-worker.c index 61a3811f09..3bb91adf5a 100644 --- a/src/flow-worker.c +++ b/src/flow-worker.c @@ -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 {