diff --git a/src/flow-hash.c b/src/flow-hash.c index bf2f022184..36a0f78b8a 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -306,7 +306,7 @@ static Flow *FlowGetNew(Packet *p) { * 2- by emergency mode timeouts * 3- by last time seen */ - if (SC_ATOMIC_GET(flow_memuse) + sizeof(Flow) > flow_config.memcap) { + if ((SC_ATOMIC_GET(flow_memuse) + sizeof(Flow)) > flow_config.memcap) { uint32_t not_released = 0; SCLogDebug("We need to prune some flows(1)"); diff --git a/src/flow-private.h b/src/flow-private.h index fb48791de1..dac216e8f5 100644 --- a/src/flow-private.h +++ b/src/flow-private.h @@ -99,12 +99,12 @@ FlowConfig flow_config; uint8_t flow_flags; /** flow memuse counter (atomic), for enforcing memcap limit */ -SC_ATOMIC_DECLARE(unsigned int, flow_memuse); +SC_ATOMIC_DECLARE(long long unsigned int, flow_memuse); //#define FLOWBITS_STATS #ifdef FLOWBITS_STATS -uint32_t flowbits_memuse; -uint32_t flowbits_memuse_max; +uint64_t flowbits_memuse; +uint64_t flowbits_memuse_max; uint32_t flowbits_added; uint32_t flowbits_removed; SCMutex flowbits_mutex; diff --git a/src/flow-util.c b/src/flow-util.c index d0a45013d4..f0443bc77e 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -49,7 +49,7 @@ Flow *FlowAlloc(void) { Flow *f; - if (SC_ATOMIC_GET(flow_memuse) + sizeof(Flow) > flow_config.memcap) { + if ((SC_ATOMIC_GET(flow_memuse) + sizeof(Flow)) > flow_config.memcap) { return NULL; } @@ -61,12 +61,7 @@ Flow *FlowAlloc(void) return NULL; } - FLOW_INITIALIZE(f); - - f->alproto = 0; - f->aldata = NULL; - return f; } diff --git a/src/flow.c b/src/flow.c index b65f981334..c07ae66eb1 100644 --- a/src/flow.c +++ b/src/flow.c @@ -883,13 +883,14 @@ void FlowInitConfig(char quiet) /* Check if we have memcap and hash_size defined at config */ char *conf_val; uint32_t configval = 0; + uint64_t configval64 = 0; /** set config values for memcap, prealloc and hash_size */ if ((ConfGet("flow.memcap", &conf_val)) == 1) { - if (ByteExtractStringUint32(&configval, 10, strlen(conf_val), + if (ByteExtractStringUint64(&configval64, 10, strlen(conf_val), conf_val) > 0) { - flow_config.memcap = configval; + flow_config.memcap = configval64; } } if ((ConfGet("flow.hash_size", &conf_val)) == 1) @@ -906,7 +907,7 @@ void FlowInitConfig(char quiet) flow_config.prealloc = configval; } } - SCLogDebug("Flow config from suricata.yaml: memcap: %"PRIu32", hash_size: " + SCLogDebug("Flow config from suricata.yaml: memcap: %"PRIu64", hash_size: " "%"PRIu32", prealloc: %"PRIu32, flow_config.memcap, flow_config.hash_size, flow_config.prealloc); @@ -925,7 +926,7 @@ void FlowInitConfig(char quiet) SC_ATOMIC_ADD(flow_memuse, (flow_config.hash_size * sizeof(FlowBucket))); if (quiet == FALSE) { - SCLogInfo("allocated %" PRIu32 " bytes of memory for the flow hash... " + SCLogInfo("allocated %" PRIu64 " bytes of memory for the flow hash... " "%" PRIu32 " buckets of size %" PRIuMAX "", SC_ATOMIC_GET(flow_memuse), flow_config.hash_size, (uintmax_t)sizeof(FlowBucket)); @@ -933,7 +934,7 @@ void FlowInitConfig(char quiet) /* pre allocate flows */ for (i = 0; i < flow_config.prealloc; i++) { - if (SC_ATOMIC_GET(flow_memuse) + sizeof(Flow) > flow_config.memcap) { + if ((SC_ATOMIC_GET(flow_memuse) + sizeof(Flow)) > flow_config.memcap) { printf("ERROR: FlowAlloc failed (max flow memcap reached): %s\n", strerror(errno)); exit(1); } @@ -949,7 +950,7 @@ void FlowInitConfig(char quiet) if (quiet == FALSE) { SCLogInfo("preallocated %" PRIu32 " flows of size %" PRIuMAX "", flow_spare_q.len, (uintmax_t)sizeof(Flow)); - SCLogInfo("flow memory usage: %" PRIu32 " bytes, maximum: %" PRIu32 "", + SCLogInfo("flow memory usage: %"PRIu64" bytes, maximum: %"PRIu64, SC_ATOMIC_GET(flow_memuse), flow_config.memcap); } diff --git a/src/flow.h b/src/flow.h index 777a8f5cf6..25aa13b6b8 100644 --- a/src/flow.h +++ b/src/flow.h @@ -106,8 +106,8 @@ typedef struct FlowCnf_ { uint32_t hash_rand; uint32_t hash_size; + uint64_t memcap; uint32_t max_flows; - uint32_t memcap; uint32_t prealloc; uint32_t timeout_new;