suricata
util-storage.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum StorageEnum_ StorageEnum
 
typedef void * Storage
 

Enumerations

enum  StorageEnum_ {
  STORAGE_HOST, STORAGE_FLOW, STORAGE_IPPAIR, STORAGE_DEVICE,
  STORAGE_MAX
}
 

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 (const StorageEnum type)
 
unsigned int StorageGetSize (const 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, const StorageEnum type, const int id)
 AllocById func for when we manage the Storage ptr itself. More...
 
void StorageFreeById (Storage *storage, const StorageEnum type, const int id)
 
void StorageFreeAll (Storage *storage, const StorageEnum type)
 
void StorageFree (Storage **storage, const 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.h.

Typedef Documentation

◆ Storage

typedef void* Storage

void ptr array for now

Definition at line 39 of file util-storage.h.

◆ StorageEnum

typedef enum StorageEnum_ StorageEnum

Enumeration Type Documentation

◆ StorageEnum_

Enumerator
STORAGE_HOST 
STORAGE_FLOW 
STORAGE_IPPAIR 
STORAGE_DEVICE 
STORAGE_MAX 

Definition at line 29 of file util-storage.h.

Function Documentation

◆ StorageAllocById()

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

AllocById func for when we manage the Storage ptr itself.

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

References BUG_ON.

◆ StorageAllocByIdPrealloc()

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 240 of file util-storage.c.

References BUG_ON.

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

Here is the caller graph for this function:

◆ StorageCleanup()

void StorageCleanup ( void  )

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

◆ StorageFinalize()

int StorageFinalize ( void  )

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

Referenced by RunUnittests().

Here is the caller graph for this function:

◆ StorageFree()

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

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

References BUG_ON.

◆ StorageFreeAll()

void StorageFreeAll ( Storage storage,
const StorageEnum  type 
)

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

References BUG_ON.

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

Here is the caller graph for this function:

◆ StorageFreeById()

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

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

References BUG_ON.

Referenced by FlowFreeStorageById(), HostFreeStorageById(), IPPairFreeStorageById(), and LiveDevFreeStorageById().

Here is the caller graph for this function:

◆ StorageGetById()

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

get storage for id

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

References BUG_ON.

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

Here is the caller graph for this function:

◆ StorageGetCnt()

unsigned int StorageGetCnt ( const StorageEnum  type)

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

◆ StorageGetSize()

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 212 of file util-storage.c.

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

Here is the caller graph for this function:

◆ StorageInit()

void StorageInit ( void  )

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

Referenced by PostConfLoadedSetup(), and RunUnittests().

Here is the caller graph for this function:

◆ StorageRegister()

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 100 of file util-storage.c.

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

Here is the caller graph for this function:

◆ StorageRegisterTests()

void StorageRegisterTests ( void  )

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

References UtRegisterTest().

Here is the call graph for this function:

◆ StorageSetById()

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

set storage for id

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

References BUG_ON.

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

Here is the caller graph for this function: