suricata
util-thash.h File Reference
#include "threads.h"
Include dependency graph for util-thash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  THashData_
 
struct  THashHashRow_
 
struct  THashDataQueue_
 
struct  THashDataConfig_
 
struct  THashTableContext_
 
struct  THashDataGetResult
 

Macros

#define HRLOCK_MUTEX
 
#define HRLOCK_TYPE   SCMutex
 
#define HRLOCK_INIT(fb)   SCMutexInit(&(fb)->lock, NULL)
 
#define HRLOCK_DESTROY(fb)   SCMutexDestroy(&(fb)->lock)
 
#define HRLOCK_LOCK(fb)   SCMutexLock(&(fb)->lock)
 
#define HRLOCK_TRYLOCK(fb)   SCMutexTrylock(&(fb)->lock)
 
#define HRLOCK_UNLOCK(fb)   SCMutexUnlock(&(fb)->lock)
 
#define HQLOCK_MUTEX
 
#define HQLOCK_INIT(q)   SCMutexInit(&(q)->m, NULL)
 
#define HQLOCK_DESTROY(q)   SCMutexDestroy(&(q)->m)
 
#define HQLOCK_LOCK(q)   SCMutexLock(&(q)->m)
 
#define HQLOCK_TRYLOCK(q)   SCMutexTrylock(&(q)->m)
 
#define HQLOCK_UNLOCK(q)   SCMutexUnlock(&(q)->m)
 
#define THASH_DATA_SIZE(ctx)   (sizeof(THashData) + (ctx)->config.data_size)
 
#define THASH_CHECK_MEMCAP(ctx, size)
 check if a memory alloc would fit in the memcap More...
 
#define THashIncrUsecnt(h)   (void)SC_ATOMIC_ADD((h)->use_cnt, 1)
 
#define THashDecrUsecnt(h)   (void)SC_ATOMIC_SUB((h)->use_cnt, 1)
 

Typedefs

typedef struct THashData_ THashData
 
typedef struct THashDataQueue_ THashDataQueue
 
typedef int(* THashOutputFunc) (void *output_ctx, const uint8_t *data, const uint32_t data_len)
 
typedef int(* THashFormatFunc) (const void *in_data, char *output, size_t output_size)
 
typedef struct THashDataConfig_ THashConfig
 
typedef struct THashTableContext_ THashTableContext
 

Functions

struct THashHashRow_ __attribute__ ((aligned(CLS))) THashHashRow
 
THashTableContextTHashInit (const char *cnf_prefix, size_t data_size, int(*DataSet)(void *dst, void *src), void(*DataFree)(void *), uint32_t(*DataHash)(uint32_t, void *), bool(*DataCompare)(void *, void *), bool(*DataExpired)(void *, SCTime_t), uint32_t(*DataSize)(void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
 
void THashShutdown (THashTableContext *ctx)
 shutdown the flow engine More...
 
struct THashDataGetResult THashGetFromHash (THashTableContext *ctx, void *data)
 
THashDataTHashLookupFromHash (THashTableContext *ctx, void *data)
 look up data in the hash More...
 
THashDataQueueTHashDataQueueNew (void)
 
void THashCleanup (THashTableContext *ctx)
 Cleanup the thash engine. More...
 
int THashWalk (THashTableContext *, THashFormatFunc, THashOutputFunc, void *)
 Walk the hash. More...
 
int THashRemoveFromHash (THashTableContext *ctx, void *data)
 
void THashConsolidateMemcap (THashTableContext *ctx)
 
void THashDataMoveToSpare (THashTableContext *ctx, THashData *h)
 
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...
 

Variables

HRLOCK_TYPE lock
 
THashDatahead
 
THashDatatail
 

Detailed Description

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

thash -> thread hash. Hash table with locking handling.

Definition in file util-thash.h.

Macro Definition Documentation

◆ HQLOCK_DESTROY

#define HQLOCK_DESTROY (   q)    SCMutexDestroy(&(q)->m)

Definition at line 78 of file util-thash.h.

◆ HQLOCK_INIT

#define HQLOCK_INIT (   q)    SCMutexInit(&(q)->m, NULL)

Definition at line 77 of file util-thash.h.

◆ HQLOCK_LOCK

#define HQLOCK_LOCK (   q)    SCMutexLock(&(q)->m)

Definition at line 79 of file util-thash.h.

◆ HQLOCK_MUTEX

#define HQLOCK_MUTEX

Spinlocks or Mutex for the queues.

Definition at line 62 of file util-thash.h.

◆ HQLOCK_TRYLOCK

#define HQLOCK_TRYLOCK (   q)    SCMutexTrylock(&(q)->m)

Definition at line 80 of file util-thash.h.

◆ HQLOCK_UNLOCK

#define HQLOCK_UNLOCK (   q)    SCMutexUnlock(&(q)->m)

Definition at line 81 of file util-thash.h.

◆ HRLOCK_DESTROY

#define HRLOCK_DESTROY (   fb)    SCMutexDestroy(&(fb)->lock)

Definition at line 52 of file util-thash.h.

◆ HRLOCK_INIT

#define HRLOCK_INIT (   fb)    SCMutexInit(&(fb)->lock, NULL)

Definition at line 51 of file util-thash.h.

◆ HRLOCK_LOCK

#define HRLOCK_LOCK (   fb)    SCMutexLock(&(fb)->lock)

Definition at line 53 of file util-thash.h.

◆ HRLOCK_MUTEX

#define HRLOCK_MUTEX

Spinlocks or Mutex for the buckets.

Definition at line 34 of file util-thash.h.

◆ HRLOCK_TRYLOCK

#define HRLOCK_TRYLOCK (   fb)    SCMutexTrylock(&(fb)->lock)

Definition at line 54 of file util-thash.h.

◆ HRLOCK_TYPE

#define HRLOCK_TYPE   SCMutex

Definition at line 50 of file util-thash.h.

◆ HRLOCK_UNLOCK

#define HRLOCK_UNLOCK (   fb)    SCMutexUnlock(&(fb)->lock)

Definition at line 55 of file util-thash.h.

◆ THASH_CHECK_MEMCAP

#define THASH_CHECK_MEMCAP (   ctx,
  size 
)
Value:
((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= \
SC_ATOMIC_GET((ctx)->config.memcap)))

check if a memory alloc would fit in the memcap

Parameters
sizememory allocation size to check
Return values
1it fits
0no fit

Definition at line 165 of file util-thash.h.

◆ THASH_DATA_SIZE

#define THASH_DATA_SIZE (   ctx)    (sizeof(THashData) + (ctx)->config.data_size)

Definition at line 140 of file util-thash.h.

◆ THashDecrUsecnt

#define THashDecrUsecnt (   h)    (void)SC_ATOMIC_SUB((h)->use_cnt, 1)

Definition at line 171 of file util-thash.h.

◆ THashIncrUsecnt

#define THashIncrUsecnt (   h)    (void)SC_ATOMIC_ADD((h)->use_cnt, 1)

Definition at line 169 of file util-thash.h.

Typedef Documentation

◆ THashConfig

typedef struct THashDataConfig_ THashConfig

◆ THashData

typedef struct THashData_ THashData

◆ THashDataQueue

◆ THashFormatFunc

typedef int(* THashFormatFunc) (const void *in_data, char *output, size_t output_size)

Definition at line 122 of file util-thash.h.

◆ THashOutputFunc

typedef int(* THashOutputFunc) (void *output_ctx, const uint8_t *data, const uint32_t data_len)

Definition at line 121 of file util-thash.h.

◆ THashTableContext

Function Documentation

◆ __attribute__()

struct THashHashRow_ __attribute__ ( (aligned(CLS))  )

◆ THashCleanup()

void THashCleanup ( THashTableContext ctx)

Cleanup the thash engine.

Cleanup the thash engine from tag and threshold.

Definition at line 489 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 353 of file util-thash.c.

References ctx, MAX, SC_ATOMIC_GET, SC_ATOMIC_SET, 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 431 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 560 of file util-thash.c.

◆ THashInit()

THashTableContext* THashInit ( const char *  cnf_prefix,
size_t  data_size,
int(*)(void *dst, void *src DataSet,
void(*)(void *)  DataFree,
uint32_t(*)(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 
)

◆ 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 732 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 875 of file util-thash.c.

◆ THashShutdown()

void THashShutdown ( THashTableContext ctx)

shutdown the flow engine

Warning
Not thread safe

Definition at line 362 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 396 of file util-thash.c.

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

Variable Documentation

◆ head

THashData* head

Definition at line 1 of file util-thash.h.

◆ lock

Definition at line 0 of file util-thash.h.

◆ tail

THashData* tail

Definition at line 2 of file util-thash.h.

ctx
struct Thresholds ctx
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375