suricata
util-thash.h File Reference
#include "decode.h"
#include "util-storage.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_VERBOSE   0
 
#define THASH_QUIET   1
 
#define THASH_DATA_SIZE(ctx)   (sizeof(THashData) + (ctx)->config.data_size)
 
#define THASH_CHECK_MEMCAP(ctx, size)   ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= (ctx)->config.memcap))
 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)
 
#define THashReference(dst_h_ptr, h)
 
#define THashDeReference(src_h_ptr)
 

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)(void *), _Bool(*DataCompare)(void *, void *))
 
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...
 

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

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

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

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

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

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

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

#define HQLOCK_MUTEX

Spinlocks or Mutex for the queues.

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

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

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

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

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

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

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

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

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

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

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

#define HRLOCK_MUTEX

Spinlocks or Mutex for the buckets.

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

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

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

#define HRLOCK_TYPE   SCMutex

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

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

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

#define THASH_CHECK_MEMCAP (   ctx,
  size 
)    ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= (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 164 of file util-thash.h.

Referenced by THashCleanup(), and THashDataQueueNew().

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

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

Referenced by THashCleanup(), and THashDataQueueNew().

#define THASH_QUIET   1

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

#define THASH_VERBOSE   0

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

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

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

#define THashDeReference (   src_h_ptr)
Value:
do { \
if (*(src_h_ptr) != NULL) { \
THashDecrUsecnt(*(src_h_ptr)); \
*(src_h_ptr) = NULL; \
} \
} while (0)
#define THashDecrUsecnt(h)
Definition: util-thash.h:169

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

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

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

Referenced by THashGetFromHash(), and THashLookupFromHash().

#define THashReference (   dst_h_ptr,
 
)
Value:
do { \
if ((h) != NULL) { \
*(dst_h_ptr) = h; \
} \
} while (0)
#define THashIncrUsecnt(h)
Definition: util-thash.h:167

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

Typedef Documentation

typedef struct THashDataConfig_ THashConfig
typedef struct THashData_ THashData
typedef int(* THashFormatFunc) (const void *in_data, char *output, size_t output_size)

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

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

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

Function Documentation

struct THashHashRow_ __attribute__ ( (aligned(CLS))  )
struct THashDataGetResult THashGetFromHash ( THashTableContext ctx,
void *  data 
)
THashTableContext* THashInit ( const char *  cnf_prefix,
size_t  data_size,
int(*)(void *dst, void *src DataSet,
void(*)(void *)  DataFree,
uint32_t(*)(void *)  DataHash,
_Bool(*)(void *, void *)  DataCompare 
)
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 620 of file util-thash.c.

References THashTableContext_::array, THashTableContext_::config, THashData_::data, THashDataConfig_::hash_size, HRLOCK_LOCK, HRLOCK_TRYLOCK, HRLOCK_UNLOCK, THashData_::m, THashData_::next, THashData_::prev, SC_ATOMIC_ADD, SC_ATOMIC_GET, SCMutexLock, SCMutexTrylock, SCMutexUnlock, and THashIncrUsecnt.

Referenced by DatasetsSave().

Here is the caller graph for this function:

void THashShutdown ( THashTableContext ctx)

shutdown the flow engine

Warning
Not thread safe

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

References THashTableContext_::array, BUG_ON, THashTableContext_::config, THashDataConfig_::hash_size, HRLOCK_DESTROY, THashData_::next, SC_ATOMIC_DESTROY, SC_ATOMIC_GET, SC_ATOMIC_SUB, SCFree, SCFreeAligned, and THashTableContext_::spare_q.

Referenced by DatasetGet(), and DatasetsDestroy().

Here is the caller graph for this function:

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

Walk the hash.

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

References THashTableContext_::array, THashTableContext_::config, THashData_::data, THashDataConfig_::hash_size, HRLOCK_LOCK, HRLOCK_UNLOCK, and THashData_::next.

Referenced by DatasetsSave().

Here is the caller graph for this function:

Variable Documentation

THashData* head

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

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

THashData* tail

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