Convert flow memcap to u64. Bug #332.

remotes/origin/master-1.1.x
Victor Julien 14 years ago
parent 8208eacd79
commit 9baa16af63

@ -306,7 +306,7 @@ static Flow *FlowGetNew(Packet *p) {
* 2- by emergency mode timeouts * 2- by emergency mode timeouts
* 3- by last time seen * 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; uint32_t not_released = 0;
SCLogDebug("We need to prune some flows(1)"); SCLogDebug("We need to prune some flows(1)");

@ -99,12 +99,12 @@ FlowConfig flow_config;
uint8_t flow_flags; uint8_t flow_flags;
/** flow memuse counter (atomic), for enforcing memcap limit */ /** 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 //#define FLOWBITS_STATS
#ifdef FLOWBITS_STATS #ifdef FLOWBITS_STATS
uint32_t flowbits_memuse; uint64_t flowbits_memuse;
uint32_t flowbits_memuse_max; uint64_t flowbits_memuse_max;
uint32_t flowbits_added; uint32_t flowbits_added;
uint32_t flowbits_removed; uint32_t flowbits_removed;
SCMutex flowbits_mutex; SCMutex flowbits_mutex;

@ -49,7 +49,7 @@ Flow *FlowAlloc(void)
{ {
Flow *f; 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; return NULL;
} }
@ -61,12 +61,7 @@ Flow *FlowAlloc(void)
return NULL; return NULL;
} }
FLOW_INITIALIZE(f); FLOW_INITIALIZE(f);
f->alproto = 0;
f->aldata = NULL;
return f; return f;
} }

@ -883,13 +883,14 @@ void FlowInitConfig(char quiet)
/* Check if we have memcap and hash_size defined at config */ /* Check if we have memcap and hash_size defined at config */
char *conf_val; char *conf_val;
uint32_t configval = 0; uint32_t configval = 0;
uint64_t configval64 = 0;
/** set config values for memcap, prealloc and hash_size */ /** set config values for memcap, prealloc and hash_size */
if ((ConfGet("flow.memcap", &conf_val)) == 1) if ((ConfGet("flow.memcap", &conf_val)) == 1)
{ {
if (ByteExtractStringUint32(&configval, 10, strlen(conf_val), if (ByteExtractStringUint64(&configval64, 10, strlen(conf_val),
conf_val) > 0) { conf_val) > 0) {
flow_config.memcap = configval; flow_config.memcap = configval64;
} }
} }
if ((ConfGet("flow.hash_size", &conf_val)) == 1) if ((ConfGet("flow.hash_size", &conf_val)) == 1)
@ -906,7 +907,7 @@ void FlowInitConfig(char quiet)
flow_config.prealloc = configval; 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, "%"PRIu32", prealloc: %"PRIu32, flow_config.memcap,
flow_config.hash_size, flow_config.prealloc); 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))); SC_ATOMIC_ADD(flow_memuse, (flow_config.hash_size * sizeof(FlowBucket)));
if (quiet == FALSE) { 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 "", "%" PRIu32 " buckets of size %" PRIuMAX "",
SC_ATOMIC_GET(flow_memuse), flow_config.hash_size, SC_ATOMIC_GET(flow_memuse), flow_config.hash_size,
(uintmax_t)sizeof(FlowBucket)); (uintmax_t)sizeof(FlowBucket));
@ -933,7 +934,7 @@ void FlowInitConfig(char quiet)
/* pre allocate flows */ /* pre allocate flows */
for (i = 0; i < flow_config.prealloc; i++) { 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)); printf("ERROR: FlowAlloc failed (max flow memcap reached): %s\n", strerror(errno));
exit(1); exit(1);
} }
@ -949,7 +950,7 @@ void FlowInitConfig(char quiet)
if (quiet == FALSE) { if (quiet == FALSE) {
SCLogInfo("preallocated %" PRIu32 " flows of size %" PRIuMAX "", SCLogInfo("preallocated %" PRIu32 " flows of size %" PRIuMAX "",
flow_spare_q.len, (uintmax_t)sizeof(Flow)); 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); SC_ATOMIC_GET(flow_memuse), flow_config.memcap);
} }

@ -106,8 +106,8 @@ typedef struct FlowCnf_
{ {
uint32_t hash_rand; uint32_t hash_rand;
uint32_t hash_size; uint32_t hash_size;
uint64_t memcap;
uint32_t max_flows; uint32_t max_flows;
uint32_t memcap;
uint32_t prealloc; uint32_t prealloc;
uint32_t timeout_new; uint32_t timeout_new;

Loading…
Cancel
Save