Go to the documentation of this file.
43 THashDataEnqueue(&ctx->
spare_q, h);
60 SCLogError(
"Fatal error encountered in THashDataQueueNew. Exiting...");
63 q = THashDataQueueInit(q);
86 BUG_ON(q == NULL || h == NULL);
103 if (q->
len > q->dbg_maxlen)
104 q->dbg_maxlen = q->
len;
192 if (h->
data != NULL) {
201 #define THASH_DEFAULT_HASHSIZE 4096
202 #define THASH_DEFAULT_MEMCAP 16777216
203 #define THASH_DEFAULT_PREALLOC 1000
205 #define GET_VAR(prefix,name) \
206 snprintf(varname, sizeof(varname), "%s.%s", (prefix), (name))
217 const char *conf_val;
218 uint32_t configval = 0;
222 if ((
ConfGet(varname, &conf_val)) == 1)
226 "from conf file - %s. Killing engine",
231 GET_VAR(cnf_prefix,
"hash-size");
232 if ((
ConfGet(varname, &conf_val)) == 1)
234 if (
StringParseUint32(&configval, 10, (uint16_t)strlen(conf_val), conf_val) > 0) {
239 GET_VAR(cnf_prefix,
"prealloc");
240 if ((
ConfGet(varname, &conf_val)) == 1)
242 if (
StringParseUint32(&configval, 10, (uint16_t)strlen(conf_val), conf_val) > 0) {
253 "max hash memcap is smaller than projected hash size. "
254 "Memcap: %" PRIu64
", Hash table size %" PRIu64
". Calculate "
255 "total hash size by multiplying \"hash-size\" with %" PRIuMAX
", "
256 "which is the hash bucket size.",
257 ctx->
config.
memcap, hash_size, (uintmax_t)
sizeof(THashHashRow));
262 SCLogError(
"Fatal error encountered in THashInitConfig. Exiting...");
277 "max thash memcap reached. Memcap %" PRIu64
", "
278 "Memuse %" PRIu64
".",
286 SCLogError(
"preallocating data failed: %s", strerror(errno));
289 THashDataEnqueue(&ctx->
spare_q,h);
296 int (*DataSet)(
void *,
void *),
void (*DataFree)(
void *), uint32_t (*DataHash)(
void *),
297 bool (*DataCompare)(
void *,
void *),
bool reset_memcap, uint64_t memcap, uint32_t
hashsize)
313 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
328 THashDataQueueInit(&ctx->
spare_q);
330 if (THashInitConfig(ctx, cnf_prefix) < 0) {
352 while ((h = THashDataDequeue(&ctx->
spare_q))) {
354 THashDataFree(ctx, h);
358 if (ctx->
array != NULL) {
360 h = ctx->
array[u].head;
363 THashDataFree(ctx, h);
373 THashDataQueueDestroy(&ctx->
spare_q);
385 if (ctx->
array == NULL)
390 THashHashRow *hb = &ctx->
array[u];
394 char output_string[1024] =
"";
395 int size = FormatterFunc(h->
data, output_string,
sizeof(output_string));
397 if (OutputterFunc(output_ctx, (
const uint8_t *)output_string, size) < 0) {
420 if (ctx->
array == NULL)
424 THashHashRow *hb = &ctx->
array[u];
458 static uint32_t THashGetKey(
const THashConfig *cnf,
void *data)
468 static inline int THashCompare(
const THashConfig *cnf,
void *a,
void *b)
488 h = THashDataDequeue(&ctx->
spare_q);
492 h = THashGetUsed(ctx);
504 h = THashDataAlloc(ctx);
536 uint32_t key = THashGetKey(&ctx->config,
data);
538 THashHashRow *hb = &ctx->array[key];
542 if (hb->head == NULL) {
543 h = THashDataGetNew(ctx,
data);
566 if (THashCompare(&ctx->config, h->
data,
data) == 0) {
574 h = ph->
next = THashDataGetNew(ctx,
data);
594 if (THashCompare(&ctx->config, h->
data,
data) != 0) {
645 uint32_t key = THashGetKey(&ctx->
config,
data);
647 THashHashRow *hb = &ctx->
array[key];
650 if (hb->head == NULL) {
723 THashHashRow *hb = &ctx->
array[idx];
759 if (h->
data != NULL) {
778 uint32_t key = THashGetKey(&ctx->
config,
data);
780 THashHashRow *hb = &ctx->
array[key];
812 THashDataFree(ctx, h);
#define HRLOCK_DESTROY(fb)
void THashCleanup(THashTableContext *ctx)
Cleanup the thash engine.
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
#define HQLOCK_DESTROY(q)
int(* THashOutputFunc)(void *output_ctx, const uint8_t *data, const uint32_t data_len)
int ParseSizeStringU64(const char *size, uint64_t *res)
int THashRemoveFromHash(THashTableContext *ctx, void *data)
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
void THashConsolidateMemcap(THashTableContext *ctx)
uint32_t(* DataHash)(void *)
bool(* DataCompare)(void *, void *)
int(* DataSet)(void *dst, void *src)
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
#define HRLOCK_UNLOCK(fb)
#define THASH_DEFAULT_HASHSIZE
#define SCMutexUnlock(mut)
#define THASH_DATA_SIZE(ctx)
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
THashTableContext * THashInit(const char *cnf_prefix, size_t data_size, int(*DataSet)(void *, void *), void(*DataFree)(void *), uint32_t(*DataHash)(void *), bool(*DataCompare)(void *, void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
#define GET_VAR(prefix, name)
void THashDataMoveToSpare(THashTableContext *ctx, THashData *h)
#define SCMutexInit(mut, mutattrs)
#define WarnInvalidConfEntry(param_name, format, value)
Generic API that can be used by all to log an invalid conf entry.
void THashShutdown(THashTableContext *ctx)
shutdown the flow engine
#define THASH_DEFAULT_MEMCAP
#define SCMallocAligned(size, align)
struct THashDataGetResult THashGetFromHash(THashTableContext *ctx, void *data)
THashData * THashLookupFromHash(THashTableContext *ctx, void *data)
look up data in the hash
#define THASH_DEFAULT_PREALLOC
#define SCLogError(...)
Macro used to log ERROR messages.
int THashWalk(THashTableContext *ctx, THashFormatFunc FormatterFunc, THashOutputFunc OutputterFunc, void *output_ctx)
Walk the hash.
int(* THashFormatFunc)(const void *in_data, char *output, size_t output_size)
#define HRLOCK_TRYLOCK(fb)
#define THashIncrUsecnt(h)
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define THASH_CHECK_MEMCAP(ctx, size)
check if a memory alloc would fit in the memcap
#define DEBUG_VALIDATE_BUG_ON(exp)
THashDataQueue * THashDataQueueNew(void)
#define SCMutexTrylock(mut)