suricata
util-rohash.c File Reference
#include "suricata-common.h"
#include "util-hash.h"
#include "util-unittest.h"
#include "util-memcmp.h"
#include "util-hash-lookup3.h"
#include "queue.h"
#include "util-rohash.h"
Include dependency graph for util-rohash.c:

Go to the source code of this file.

Data Structures

struct  ROHashTableItem_
 
struct  ROHashTableOffsets_
 

Typedefs

typedef struct ROHashTableItem_ ROHashTableItem
 
typedef struct ROHashTableOffsets_ ROHashTableOffsets
 

Functions

ROHashTableROHashInit (uint8_t hash_bits, uint16_t item_size)
 initialize a new rohash More...
 
void ROHashFree (ROHashTable *table)
 
uint32_t ROHashMemorySize (ROHashTable *table)
 
void * ROHashLookup (ROHashTable *table, void *data, uint16_t size)
 
int ROHashInitQueueValue (ROHashTable *table, void *value, uint16_t size)
 Add a new value to the hash. More...
 
int ROHashInitFinalize (ROHashTable *table)
 create final hash data structure More...
 

Detailed Description

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

Chained read only hash table implementation, meaning that after the initial fill no changes are allowed.

Loading takes 2 stages.

  • stage1 maps data
  • stage2 fills blob
Todo:
a bloomfilter in the ROHashTableOffsets could possibly prevent a lot of cache misses when validating a potential match
Todo:
maybe add a user ctx to be returned instead, something like a 4/8 byte ptr or simply a flag

Definition in file util-rohash.c.

Typedef Documentation

item_size data beyond this header

offset table

Function Documentation

void ROHashFree ( ROHashTable table)

Definition at line 92 of file util-rohash.c.

References ROHashTable_::data, and SCFree.

Referenced by DetectFileMd5Register(), DetectFileSha1Register(), and DetectFileSha256Register().

Here is the caller graph for this function:

ROHashTable* ROHashInit ( uint8_t  hash_bits,
uint16_t  item_size 
)

initialize a new rohash

Parameters
hash_bitshash size as 2^hash_bits, so power of 2, max 31
item_sizesize of the data to store
Return values
tableptr or NULL on error

Definition at line 64 of file util-rohash.c.

References ROHashTable_::hash_bits, hashsize, ROHashTable_::item_size, ROHashTable_::items, SC_ERR_HASH_TABLE_INIT, SCLogError, SCMalloc, TAILQ_INIT, and unlikely.

Referenced by DetectFileMd5Register(), DetectFileSha1Register(), and DetectFileSha256Register().

Here is the caller graph for this function:

int ROHashInitFinalize ( ROHashTable table)

create final hash data structure

Parameters
tablethe hash table
Return values
0error
1ok
Note
after this call the nothing can be added to the hash anymore.

Definition at line 183 of file util-rohash.c.

References ROHashTableOffsets_::cnt, ROHashTable_::data, ROHashTable_::hash_bits, hashmask, hashsize, hashword(), ROHashTable_::item_size, ROHashTable_::items, ROHashTable_::locked, next, ROHashTableOffsets_::offset, offset, ROHashTableItem_::pos, SC_ERR_HASH_TABLE_INIT, SCFree, SCLogError, SCMalloc, TAILQ_FIRST, TAILQ_FOREACH, and TAILQ_REMOVE.

Referenced by DetectFileMd5Register(), DetectFileSha1Register(), and DetectFileSha256Register().

Here is the call graph for this function:

Here is the caller graph for this function:

int ROHashInitQueueValue ( ROHashTable table,
void *  value,
uint16_t  size 
)

Add a new value to the hash.

Note
can only be done when table isn't in a locked state yet
Parameters
tablethe hash table
valuevalue to add
sizevalue size. MUST match table item_size
Return values
0error
1ok

Definition at line 152 of file util-rohash.c.

References ROHashTable_::item_size, ROHashTable_::locked, next, SC_ERR_HASH_TABLE_INIT, SCLogError, SCMalloc, and TAILQ_INSERT_TAIL.

void* ROHashLookup ( ROHashTable table,
void *  data,
uint16_t  size 
)
Return values
NULLnot found
ptrfound

Definition at line 113 of file util-rohash.c.

References ROHashTableOffsets_::cnt, ROHashTable_::data, ROHashTable_::hash_bits, hashmask, hashword(), ROHashTable_::item_size, ROHashTableOffsets_::offset, offset, SCMemcmp, and SCReturnPtr.

Referenced by DetectFileMd5Register(), DetectFileSha1Register(), and DetectFileSha256Register().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t ROHashMemorySize ( ROHashTable table)