suricata
util-thash.c File Reference
#include "suricata-common.h"
#include "conf.h"
#include "util-debug.h"
#include "util-thash.h"
#include "util-random.h"
#include "util-misc.h"
#include "util-byte.h"
#include "util-hash-lookup3.h"
#include "util-validate.h"
Include dependency graph for util-thash.c:

Go to the source code of this file.

Macros

#define THASH_DEFAULT_HASHSIZE   4096
 
#define THASH_DEFAULT_MEMCAP   16777216
 
#define THASH_DEFAULT_PREALLOC   1000
 
#define GET_VAR(prefix, name)   snprintf(varname, sizeof(varname), "%s.%s", (prefix), (name))
 

Functions

void THashDataMoveToSpare (THashTableContext *ctx, THashData *h)
 
THashDataQueueTHashDataQueueNew (void)
 
THashTableContextTHashInit (const char *cnf_prefix, size_t data_size, int(*DataSet)(void *, void *), void(*DataFree)(void *), uint32_t(*DataHash)(void *), bool(*DataCompare)(void *, void *), bool(*DataExpired)(void *, SCTime_t), uint32_t(*DataSize)(void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
 
void THashConsolidateMemcap (THashTableContext *ctx)
 
void THashShutdown (THashTableContext *ctx)
 shutdown the flow engine More...
 
int THashWalk (THashTableContext *ctx, THashFormatFunc FormatterFunc, THashOutputFunc OutputterFunc, void *output_ctx)
 Walk the hash. More...
 
uint32_t THashExpire (THashTableContext *ctx, const SCTime_t ts)
 expire data from the hash Walk the hash table and remove data that is exprired according to the DataExpired callback. More...
 
void THashCleanup (THashTableContext *ctx)
 Cleanup the thash engine. More...
 
struct THashDataGetResult THashGetFromHash (THashTableContext *ctx, void *data)
 
THashDataTHashLookupFromHash (THashTableContext *ctx, void *data)
 look up data in the hash More...
 
int THashRemoveFromHash (THashTableContext *ctx, void *data)
 

Detailed Description

Author
Victor Julien victo.nosp@m.r@in.nosp@m.linia.nosp@m.c.ne.nosp@m.t

Definition in file util-thash.c.

Macro Definition Documentation

◆ GET_VAR

#define GET_VAR (   prefix,
  name 
)    snprintf(varname, sizeof(varname), "%s.%s", (prefix), (name))

Definition at line 213 of file util-thash.c.

◆ THASH_DEFAULT_HASHSIZE

#define THASH_DEFAULT_HASHSIZE   4096

Definition at line 209 of file util-thash.c.

◆ THASH_DEFAULT_MEMCAP

#define THASH_DEFAULT_MEMCAP   16777216

Definition at line 210 of file util-thash.c.

◆ THASH_DEFAULT_PREALLOC

#define THASH_DEFAULT_PREALLOC   1000

Definition at line 211 of file util-thash.c.

Function Documentation

◆ THashCleanup()

void THashCleanup ( THashTableContext ctx)

Cleanup the thash engine.

Cleanup the thash engine from tag and threshold.

Definition at line 484 of file util-thash.c.

References ctx, THashData_::data, HRLOCK_LOCK, HRLOCK_UNLOCK, THashData_::next, THashData_::prev, SC_ATOMIC_GET, SC_ATOMIC_SUB, and THashDataMoveToSpare().

Here is the call graph for this function:

◆ THashConsolidateMemcap()

void THashConsolidateMemcap ( THashTableContext ctx)

Definition at line 349 of file util-thash.c.

References ctx, MAX, SC_ATOMIC_GET, and SCLogDebug.

◆ THashDataMoveToSpare()

void THashDataMoveToSpare ( THashTableContext ctx,
THashData h 
)

Definition at line 41 of file util-thash.c.

Referenced by THashCleanup().

Here is the caller graph for this function:

◆ THashDataQueueNew()

THashDataQueue* THashDataQueueNew ( void  )

Definition at line 56 of file util-thash.c.

References SCLogError, and SCMalloc.

◆ THashExpire()

uint32_t THashExpire ( THashTableContext ctx,
const SCTime_t  ts 
)

expire data from the hash Walk the hash table and remove data that is exprired according to the DataExpired callback.

Return values
cntnumber of items successfully expired/removed

Definition at line 426 of file util-thash.c.

References cnt, ctx, HRLOCK_TRYLOCK, next, THashData_::next, and SCLogDebug.

Referenced by HttpRangeContainersTimeoutHash(), and ThresholdsExpire().

Here is the caller graph for this function:

◆ THashGetFromHash()

struct THashDataGetResult THashGetFromHash ( THashTableContext ctx,
void *  data 
)

Definition at line 555 of file util-thash.c.

◆ THashInit()

THashTableContext* THashInit ( const char *  cnf_prefix,
size_t  data_size,
int(*)(void *, void *)  DataSet,
void(*)(void *)  DataFree,
uint32_t(*)(void *)  DataHash,
bool(*)(void *, void *)  DataCompare,
bool(*)(void *, SCTime_t DataExpired,
uint32_t(*)(void *)  DataSize,
bool  reset_memcap,
uint64_t  memcap,
uint32_t  hashsize 
)

Definition at line 302 of file util-thash.c.

References BUG_ON, ctx, hashsize, RandomGet(), SC_ATOMIC_INIT, SCCalloc, THASH_DEFAULT_HASHSIZE, THASH_DEFAULT_MEMCAP, and THASH_DEFAULT_PREALLOC.

Referenced by HttpRangeContainersInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ THashLookupFromHash()

THashData* THashLookupFromHash ( THashTableContext ctx,
void *  data 
)

look up data in the hash

Parameters
datadata to look up
Return values
hLOCKED data or NULL

Definition at line 727 of file util-thash.c.

◆ THashRemoveFromHash()

int THashRemoveFromHash ( THashTableContext ctx,
void *  data 
)
Return values
int-1 not found
int0 found, but it was busy (ref cnt)
int1 found and removed

Definition at line 870 of file util-thash.c.

◆ THashShutdown()

void THashShutdown ( THashTableContext ctx)

shutdown the flow engine

Warning
Not thread safe

Definition at line 357 of file util-thash.c.

Referenced by HttpRangeContainersDestroy().

Here is the caller graph for this function:

◆ THashWalk()

int THashWalk ( THashTableContext ctx,
THashFormatFunc  FormatterFunc,
THashOutputFunc  OutputterFunc,
void *  output_ctx 
)

Walk the hash.

Definition at line 391 of file util-thash.c.

References ctx, THashData_::data, HRLOCK_LOCK, HRLOCK_UNLOCK, and THashData_::next.