/* Run mode selected at suricata.c */
extern int run_mode;
+/**
+ * \brief Update memcap value
+ *
+ * \param size new memcap value
+ */
+int FlowSetMemcap(uint64_t size)
+{
+ if ((uint64_t)SC_ATOMIC_GET(flow_memuse) < size) {
+ SC_ATOMIC_SET(flow_config.memcap, size);
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
+ * \brief Return memcap value
+ *
+ * \retval memcap value
+ */
+uint64_t FlowGetMemcap(void)
+{
+ uint64_t memcapcopy = SC_ATOMIC_GET(flow_config.memcap);
+ return memcapcopy;
+}
+
+uint64_t FlowGetMemuse(void)
+{
+ uint64_t memusecopy = SC_ATOMIC_GET(flow_memuse);
+ return memusecopy;
+}
+
void FlowCleanupAppLayer(Flow *f)
{
if (f == NULL || f->proto == 0)
SC_ATOMIC_INIT(flow_flags);
SC_ATOMIC_INIT(flow_memuse);
SC_ATOMIC_INIT(flow_prune_idx);
+ SC_ATOMIC_INIT(flow_config.memcap);
FlowQueueInit(&flow_spare_q);
FlowQueueInit(&flow_recycle_q);
/* set defaults */
flow_config.hash_rand = (uint32_t)RandomGet();
flow_config.hash_size = FLOW_DEFAULT_HASHSIZE;
- flow_config.memcap = FLOW_DEFAULT_MEMCAP;
flow_config.prealloc = FLOW_DEFAULT_PREALLOC;
+ SC_ATOMIC_SET(flow_config.memcap, FLOW_DEFAULT_MEMCAP);
/* If we have specific config, overwrite the defaults with them,
* otherwise, leave the default values */
uint32_t configval = 0;
/** set config values for memcap, prealloc and hash_size */
+ uint64_t flow_memcap_copy;
if ((ConfGet("flow.memcap", &conf_val)) == 1)
{
if (conf_val == NULL) {
exit(EXIT_FAILURE);
}
- if (ParseSizeStringU64(conf_val, &flow_config.memcap) < 0) {
+ if (ParseSizeStringU64(conf_val, &flow_memcap_copy) < 0) {
SCLogError(SC_ERR_SIZE_PARSE, "Error parsing flow.memcap "
"from conf file - %s. Killing engine",
conf_val);
exit(EXIT_FAILURE);
+ } else {
+ SC_ATOMIC_SET(flow_config.memcap, flow_memcap_copy);
}
}
if ((ConfGet("flow.hash-size", &conf_val)) == 1)
}
}
SCLogDebug("Flow config from suricata.yaml: memcap: %"PRIu64", hash-size: "
- "%"PRIu32", prealloc: %"PRIu32, flow_config.memcap,
+ "%"PRIu32", prealloc: %"PRIu32, SC_ATOMIC_GET(flow_config.memcap),
flow_config.hash_size, flow_config.prealloc);
/* alloc hash memory */
"max flow memcap is smaller than projected hash size. "
"Memcap: %"PRIu64", Hash table size %"PRIu64". Calculate "
"total hash size by multiplying \"flow.hash-size\" with %"PRIuMAX", "
- "which is the hash bucket size.", flow_config.memcap, hash_size,
+ "which is the hash bucket size.", SC_ATOMIC_GET(flow_config.memcap), hash_size,
(uintmax_t)sizeof(FlowBucket));
exit(EXIT_FAILURE);
}
if (!(FLOW_CHECK_MEMCAP(sizeof(Flow) + FlowStorageSize()))) {
SCLogError(SC_ERR_FLOW_INIT, "preallocating flows failed: "
"max flow memcap reached. Memcap %"PRIu64", "
- "Memuse %"PRIu64".", flow_config.memcap,
+ "Memuse %"PRIu64".", SC_ATOMIC_GET(flow_config.memcap),
((uint64_t)SC_ATOMIC_GET(flow_memuse) + (uint64_t)sizeof(Flow)));
exit(EXIT_FAILURE);
}
SCLogConfig("preallocated %" PRIu32 " flows of size %" PRIuMAX "",
flow_spare_q.len, (uintmax_t)(sizeof(Flow) + + FlowStorageSize()));
SCLogConfig("flow memory usage: %"PRIu64" bytes, maximum: %"PRIu64,
- SC_ATOMIC_GET(flow_memuse), flow_config.memcap);
+ SC_ATOMIC_GET(flow_memuse), SC_ATOMIC_GET(flow_config.memcap));
}
FlowInitFlowProto();
FlowQueueDestroy(&flow_spare_q);
FlowQueueDestroy(&flow_recycle_q);
+ SC_ATOMIC_DESTROY(flow_config.memcap);
SC_ATOMIC_DESTROY(flow_prune_idx);
SC_ATOMIC_DESTROY(flow_memuse);
SC_ATOMIC_DESTROY(flow_flags);
uint32_t ini = 0;
uint32_t end = flow_spare_q.len;
- flow_config.memcap = 10000;
+ SC_ATOMIC_SET(flow_config.memcap, 10000);
flow_config.prealloc = 100;
/* Let's get the flow_spare_q empty */
uint32_t ini = 0;
uint32_t end = flow_spare_q.len;
- flow_config.memcap = 10000;
+ SC_ATOMIC_SET(flow_config.memcap, 10000);
flow_config.prealloc = 100;
/* Let's get the flow_spare_q empty */
uint32_t ini = 0;
uint32_t end = flow_spare_q.len;
- flow_config.memcap = 10000;
+ SC_ATOMIC_SET(flow_config.memcap, 10000);
flow_config.prealloc = 100;
/* Let's get the flow_spare_q empty */