suricata
util-storage.c File Reference
#include "suricata-common.h"
#include "util-unittest.h"
#include "util-storage.h"
Include dependency graph for util-storage.c:

Go to the source code of this file.

Data Structures

struct  StorageMapping_
 
struct  StorageList_
 list of StorageMapping used at registration time More...
 
struct  StorageTest02Data
 

Typedefs

typedef struct StorageMapping_ StorageMapping
 
typedef struct StorageList_ StorageList
 list of StorageMapping used at registration time More...
 

Functions

void StorageInit (void)
 
void StorageCleanup (void)
 
int StorageRegister (const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(void *))
 Register new storage. More...
 
int StorageFinalize (void)
 
unsigned int StorageGetCnt (StorageEnum type)
 
unsigned int StorageGetSize (StorageEnum type)
 get the size of the void array used to store the pointers More...
 
void * StorageGetById (const Storage *storage, const StorageEnum type, const int id)
 get storage for id More...
 
int StorageSetById (Storage *storage, const StorageEnum type, const int id, void *ptr)
 set storage for id More...
 
void * StorageAllocByIdPrealloc (Storage *storage, StorageEnum type, int id)
 AllocById func for prealloc'd base storage (storage ptrs are part of another memory block) More...
 
void * StorageAllocById (Storage **storage, StorageEnum type, int id)
 AllocById func for when we manage the Storage ptr itself. More...
 
void StorageFreeById (Storage *storage, StorageEnum type, int id)
 
void StorageFreeAll (Storage *storage, StorageEnum type)
 
void StorageFree (Storage **storage, StorageEnum type)
 
void StorageRegisterTests (void)
 

Detailed Description

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

Storage API

Definition in file util-storage.c.

Typedef Documentation

typedef struct StorageList_ StorageList

list of StorageMapping used at registration time

Function Documentation

void* StorageAllocById ( Storage **  storage,
StorageEnum  type,
int  id 
)

AllocById func for when we manage the Storage ptr itself.

Definition at line 257 of file util-storage.c.

References StorageMapping_::Alloc, BUG_ON, StorageList_::id, StorageList_::map, SCFree, SCLogDebug, SCMalloc, StorageMapping_::size, StorageMapping_::type, and unlikely.

void* StorageAllocByIdPrealloc ( Storage storage,
StorageEnum  type,
int  id 
)

AllocById func for prealloc'd base storage (storage ptrs are part of another memory block)

Definition at line 239 of file util-storage.c.

References StorageMapping_::Alloc, BUG_ON, StorageList_::id, StorageList_::map, SCLogDebug, StorageMapping_::size, and StorageMapping_::type.

Referenced by FlowAllocStorageById(), HostAllocStorageById(), IPPairAllocStorageById(), and LiveDevAllocStorageById().

Here is the caller graph for this function:

void StorageCleanup ( void  )

Definition at line 75 of file util-storage.c.

References StorageList_::next, next, SCFree, and STORAGE_MAX.

Referenced by DetectHostbitFree(), DetectXbitFree(), FlowStorageRegister(), HostFreeStorage(), IPPairStorageRegister(), StorageFree(), and TagTimeoutCheck().

Here is the caller graph for this function:

void StorageFree ( Storage **  storage,
StorageEnum  type 
)
void StorageFreeAll ( Storage storage,
StorageEnum  type 
)

Definition at line 310 of file util-storage.c.

References BUG_ON, StorageMapping_::Free, StorageList_::map, and StorageMapping_::type.

Referenced by FlowFreeStorage(), HostFreeStorage(), IPPairFreeStorage(), and LiveDevFreeStorage().

Here is the caller graph for this function:

void StorageFreeById ( Storage storage,
StorageEnum  type,
int  id 
)
void* StorageGetById ( const Storage storage,
const StorageEnum  type,
const int  id 
)

get storage for id

Definition at line 216 of file util-storage.c.

References BUG_ON, StorageList_::id, and SCLogDebug.

Referenced by FlowGetStorageById(), HostGetStorageById(), IPPairGetStorageById(), and LiveDevGetStorageById().

Here is the caller graph for this function:

unsigned int StorageGetCnt ( StorageEnum  type)

Definition at line 200 of file util-storage.c.

References StorageMapping_::type.

unsigned int StorageGetSize ( StorageEnum  type)

get the size of the void array used to store the pointers

Return values
sizesize in bytes, can return 0 if not storage is needed
Todo:
we could return -1 when registration isn't closed yet, however this will break lots of tests currently, so not doing it now

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

References StorageMapping_::type.

Referenced by FlowStorageSize(), HostStorageSize(), IPPairStorageSize(), and LiveDevStorageSize().

Here is the caller graph for this function:

void StorageInit ( void  )
int StorageRegister ( const StorageEnum  type,
const char *  name,
const unsigned int  size,
void *(*)(unsigned int)  Alloc,
void(*)(void *)  Free 
)

Register new storage.

Parameters
typetype from StorageEnum
namename
sizesize of the per instance storage
Allocalloc function for per instance storage
Freefree function for per instance storage
Note
if size == ptr size (so sizeof(void *)) and Alloc == NULL the API just gives the caller a ptr to store something it alloc'ed itself.

Definition at line 99 of file util-storage.c.

References StorageMapping_::Alloc, StorageMapping_::Free, StorageList_::id, StorageList_::map, StorageMapping_::name, StorageList_::next, SC_ERR_INVALID_VALUE, SCLogError, SCMalloc, StorageMapping_::size, STORAGE_MAX, StorageMapping_::type, and unlikely.

Referenced by FlowStorageRegister(), HostStorageRegister(), IPPairStorageRegister(), LiveDevStorageRegister(), and StorageFree().

Here is the caller graph for this function:

void StorageRegisterTests ( void  )

Definition at line 545 of file util-storage.c.

References UtRegisterTest().

Here is the call graph for this function:

int StorageSetById ( Storage storage,
const StorageEnum  type,
const int  id,
void *  ptr 
)

set storage for id

Definition at line 227 of file util-storage.c.

References BUG_ON, StorageList_::id, and SCLogDebug.

Referenced by FlowSetStorageById(), HostSetStorageById(), IPPairSetStorageById(), and LiveDevSetStorageById().

Here is the caller graph for this function: