mirror of
https://github.com/OISF/suricata.git
synced 2026-05-28 04:32:12 -04:00
storage: remove alloc callback as its unused
Remove the "Alloc" callback from the storage API, it was only being used in tests without any real usage.
This commit is contained in:
parent
332f47d557
commit
f337cd573b
22 changed files with 105 additions and 166 deletions
|
|
@ -573,13 +573,13 @@ static void NdpiInit(void)
|
|||
SCLogDebug("Initializing nDPI plugin");
|
||||
|
||||
/* Register thread storage. */
|
||||
thread_storage_id = ThreadStorageRegister("ndpi", sizeof(void *), NULL, ThreadStorageFree);
|
||||
thread_storage_id = ThreadStorageRegister("ndpi", sizeof(void *), ThreadStorageFree);
|
||||
if (thread_storage_id.id < 0) {
|
||||
FatalError("Failed to register nDPI thread storage");
|
||||
}
|
||||
|
||||
/* Register flow storage. */
|
||||
flow_storage_id = FlowStorageRegister("ndpi", sizeof(void *), NULL, FlowStorageFree);
|
||||
flow_storage_id = FlowStorageRegister("ndpi", sizeof(void *), FlowStorageFree);
|
||||
if (flow_storage_id.id < 0) {
|
||||
FatalError("Failed to register nDPI flow storage");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,9 +146,8 @@ uint64_t ExpectationGetCounter(void)
|
|||
void AppLayerExpectationSetup(void)
|
||||
{
|
||||
g_ippair_expectation_id =
|
||||
IPPairStorageRegister("expectation", sizeof(void *), NULL, ExpectationListFree);
|
||||
g_flow_expectation_id =
|
||||
FlowStorageRegister("expectation", sizeof(void *), NULL, ExpectationDataFree);
|
||||
IPPairStorageRegister("expectation", sizeof(void *), ExpectationListFree);
|
||||
g_flow_expectation_id = FlowStorageRegister("expectation", sizeof(void *), ExpectationDataFree);
|
||||
SC_ATOMIC_INIT(expectation_count);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,11 +53,11 @@ void TagInitCtx(void)
|
|||
{
|
||||
SC_ATOMIC_INIT(num_tags);
|
||||
|
||||
host_tag_id = HostStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
|
||||
host_tag_id = HostStorageRegister("tag", sizeof(void *), DetectTagDataListFree);
|
||||
if (host_tag_id.id == -1) {
|
||||
FatalError("Can't initiate host storage for tag");
|
||||
}
|
||||
flow_tag_id = FlowStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
|
||||
flow_tag_id = FlowStorageRegister("tag", sizeof(void *), DetectTagDataListFree);
|
||||
if (flow_tag_id.id == -1) {
|
||||
FatalError("Can't initiate flow storage for tag");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ unsigned int LiveDevStorageSize(void)
|
|||
* \brief Register a LiveDevice storage
|
||||
*
|
||||
* \param name the name of the storage
|
||||
* \param size integer coding the size of the stored value (sizeof(void *) is best choice here)
|
||||
* \param Alloc allocation function for the storage (can be null)
|
||||
* \param size integer coding the size of the stored value (sizeof(void *) is expected here)
|
||||
* \param Free free function for the new storage
|
||||
*
|
||||
* \retval The ID of the newly register storage that will be used to access data
|
||||
|
|
@ -58,10 +57,10 @@ unsigned int LiveDevStorageSize(void)
|
|||
* It has to be called once during the init of the sub system
|
||||
*/
|
||||
|
||||
LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
LiveDevStorageId LiveDevStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
int id = StorageRegister(STORAGE_DEVICE, name, size, Alloc, Free);
|
||||
int id = StorageRegister(STORAGE_DEVICE, name, size, Free);
|
||||
LiveDevStorageId ldsi = { .id = id };
|
||||
return ldsi;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr);
|
|||
|
||||
void LiveDevFreeStorage(LiveDevice *d);
|
||||
|
||||
LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
LiveDevStorageId LiveDevStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *));
|
||||
|
||||
#endif /* SURICATA_DEVICE_STORAGE_H */
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@ int FlowSetStorageById(Flow *f, FlowStorageId id, void *ptr)
|
|||
return StorageSetById(f->storage, STORAGE_FLOW, id.id, ptr);
|
||||
}
|
||||
|
||||
void *FlowAllocStorageById(Flow *f, FlowStorageId id)
|
||||
{
|
||||
return StorageAllocByIdPrealloc(f->storage, STORAGE_FLOW, id.id);
|
||||
}
|
||||
|
||||
void FlowFreeStorageById(Flow *f, FlowStorageId id)
|
||||
{
|
||||
StorageFreeById(f->storage, STORAGE_FLOW, id.id);
|
||||
|
|
@ -63,21 +58,15 @@ void FlowFreeStorage(Flow *f)
|
|||
StorageFreeAll(f->storage, STORAGE_FLOW);
|
||||
}
|
||||
|
||||
FlowStorageId FlowStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
FlowStorageId FlowStorageRegister(const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
int id = StorageRegister(STORAGE_FLOW, name, size, Alloc, Free);
|
||||
int id = StorageRegister(STORAGE_FLOW, name, size, Free);
|
||||
FlowStorageId fsi = { .id = id };
|
||||
return fsi;
|
||||
}
|
||||
|
||||
#ifdef UNITTESTS
|
||||
|
||||
static void *StorageTestAlloc(unsigned int size)
|
||||
{
|
||||
void *x = SCMalloc(size);
|
||||
return x;
|
||||
}
|
||||
static void StorageTestFree(void *x)
|
||||
{
|
||||
if (x)
|
||||
|
|
@ -89,12 +78,11 @@ static int FlowStorageTest01(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
FlowStorageId id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
|
||||
FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
FlowStorageId id2 = FlowStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
|
||||
FlowStorageId id2 = FlowStorageRegister("variable", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
FlowStorageId id3 =
|
||||
FlowStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
|
||||
FlowStorageId id3 = FlowStorageRegister("store", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -111,12 +99,15 @@ static int FlowStorageTest01(void)
|
|||
ptr = FlowGetStorageById(f, id3);
|
||||
FAIL_IF_NOT_NULL(ptr);
|
||||
|
||||
void *ptr1a = FlowAllocStorageById(f, id1);
|
||||
void *ptr1a = SCMalloc(8);
|
||||
FAIL_IF_NULL(ptr1a);
|
||||
void *ptr2a = FlowAllocStorageById(f, id2);
|
||||
FAIL_IF(FlowSetStorageById(f, id1, ptr1a) != 0);
|
||||
void *ptr2a = SCMalloc(24);
|
||||
FAIL_IF_NULL(ptr2a);
|
||||
void *ptr3a = FlowAllocStorageById(f, id3);
|
||||
FAIL_IF(FlowSetStorageById(f, id2, ptr2a) != 0);
|
||||
void *ptr3a = SCMalloc(16);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
FAIL_IF(FlowSetStorageById(f, id3, ptr3a) != 0);
|
||||
|
||||
void *ptr1b = FlowGetStorageById(f, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
@ -137,7 +128,7 @@ static int FlowStorageTest02(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
|
||||
FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -168,11 +159,11 @@ static int FlowStorageTest03(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
FlowStorageId id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
|
||||
FlowStorageId id1 = FlowStorageRegister("test1", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
FlowStorageId id2 = FlowStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
|
||||
FlowStorageId id2 = FlowStorageRegister("test2", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
FlowStorageId id3 = FlowStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
|
||||
FlowStorageId id3 = FlowStorageRegister("test3", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -192,8 +183,9 @@ static int FlowStorageTest03(void)
|
|||
FAIL_IF_NULL(ptr2a);
|
||||
FlowSetStorageById(f, id2, ptr2a);
|
||||
|
||||
void *ptr3a = FlowAllocStorageById(f, id3);
|
||||
void *ptr3a = SCMalloc(32);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
FlowSetStorageById(f, id3, ptr3a);
|
||||
|
||||
void *ptr1b = FlowGetStorageById(f, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
|
|||
|
|
@ -36,14 +36,12 @@ unsigned int FlowStorageSize(void);
|
|||
|
||||
void *FlowGetStorageById(const Flow *h, FlowStorageId id);
|
||||
int FlowSetStorageById(Flow *h, FlowStorageId id, void *ptr);
|
||||
void *FlowAllocStorageById(Flow *h, FlowStorageId id);
|
||||
|
||||
void FlowFreeStorageById(Flow *h, FlowStorageId id);
|
||||
void FlowFreeStorage(Flow *h);
|
||||
|
||||
void RegisterFlowStorageTests(void);
|
||||
|
||||
FlowStorageId FlowStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
FlowStorageId FlowStorageRegister(const char *name, const unsigned int size, void (*Free)(void *));
|
||||
|
||||
#endif /* SURICATA_FLOW_STORAGE_H */
|
||||
|
|
|
|||
|
|
@ -239,8 +239,7 @@ static void FlowBypassFree(void *x)
|
|||
|
||||
void RegisterFlowBypassInfo(void)
|
||||
{
|
||||
g_bypass_info_id = FlowStorageRegister("bypass_counters", sizeof(void *),
|
||||
NULL, FlowBypassFree);
|
||||
g_bypass_info_id = FlowStorageRegister("bypass_counters", sizeof(void *), FlowBypassFree);
|
||||
}
|
||||
|
||||
void FlowEndCountersRegister(ThreadVars *t, FlowEndCounters *fec)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ static void HostBitFreeAll(void *store)
|
|||
|
||||
void HostBitInitCtx(void)
|
||||
{
|
||||
host_bit_id = HostStorageRegister("bit", sizeof(void *), NULL, HostBitFreeAll);
|
||||
host_bit_id = HostStorageRegister("bit", sizeof(void *), HostBitFreeAll);
|
||||
if (host_bit_id.id == -1) {
|
||||
FatalError("Can't initiate host storage for bits");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,7 @@ unsigned int HostStorageSize(void)
|
|||
* \brief Register a Host storage
|
||||
*
|
||||
* \param name the name of the storage
|
||||
* \param size integer coding the size of the stored value (sizeof(void *) is best choice here)
|
||||
* \param Alloc allocation function for the storage (can be null)
|
||||
* \param size integer coding the size of the stored value (sizeof(void *) is expected here)
|
||||
* \param Free free function for the new storage
|
||||
*
|
||||
* \retval The ID of the newly register storage that will be used to access data
|
||||
|
|
@ -56,10 +55,9 @@ unsigned int HostStorageSize(void)
|
|||
* It has to be called once during the init of the sub system
|
||||
*/
|
||||
|
||||
HostStorageId HostStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
HostStorageId HostStorageRegister(const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
int id = StorageRegister(STORAGE_HOST, name, size, Alloc, Free);
|
||||
int id = StorageRegister(STORAGE_HOST, name, size, Free);
|
||||
HostStorageId hsi = { .id = id };
|
||||
return hsi;
|
||||
}
|
||||
|
|
@ -96,11 +94,6 @@ void *HostGetStorageById(Host *h, HostStorageId id)
|
|||
|
||||
/* Start of "private" function */
|
||||
|
||||
void *HostAllocStorageById(Host *h, HostStorageId id)
|
||||
{
|
||||
return StorageAllocByIdPrealloc(h->storage, STORAGE_HOST, id.id);
|
||||
}
|
||||
|
||||
void HostFreeStorage(Host *h)
|
||||
{
|
||||
if (HostStorageSize() > 0)
|
||||
|
|
@ -110,11 +103,6 @@ void HostFreeStorage(Host *h)
|
|||
|
||||
#ifdef UNITTESTS
|
||||
|
||||
static void *StorageTestAlloc(unsigned int size)
|
||||
{
|
||||
void *x = SCMalloc(size);
|
||||
return x;
|
||||
}
|
||||
static void StorageTestFree(void *x)
|
||||
{
|
||||
if (x)
|
||||
|
|
@ -126,12 +114,11 @@ static int HostStorageTest01(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
HostStorageId id1 = HostStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
|
||||
HostStorageId id1 = HostStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
HostStorageId id2 = HostStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
|
||||
HostStorageId id2 = HostStorageRegister("variable", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
HostStorageId id3 =
|
||||
HostStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
|
||||
HostStorageId id3 = HostStorageRegister("store", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -152,12 +139,15 @@ static int HostStorageTest01(void)
|
|||
ptr = HostGetStorageById(h, id3);
|
||||
FAIL_IF_NOT_NULL(ptr);
|
||||
|
||||
void *ptr1a = HostAllocStorageById(h, id1);
|
||||
void *ptr1a = SCMalloc(8);
|
||||
FAIL_IF_NULL(ptr1a);
|
||||
void *ptr2a = HostAllocStorageById(h, id2);
|
||||
FAIL_IF(HostSetStorageById(h, id1, ptr1a) != 0);
|
||||
void *ptr2a = SCMalloc(24);
|
||||
FAIL_IF_NULL(ptr2a);
|
||||
void *ptr3a = HostAllocStorageById(h, id3);
|
||||
FAIL_IF(HostSetStorageById(h, id2, ptr2a) != 0);
|
||||
void *ptr3a = SCMalloc(16);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
FAIL_IF(HostSetStorageById(h, id3, ptr3a) != 0);
|
||||
|
||||
void *ptr1b = HostGetStorageById(h, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
@ -178,7 +168,7 @@ static int HostStorageTest02(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
HostStorageId id1 = HostStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
|
||||
HostStorageId id1 = HostStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -214,11 +204,11 @@ static int HostStorageTest03(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
HostStorageId id1 = HostStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
|
||||
HostStorageId id1 = HostStorageRegister("test1", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
HostStorageId id2 = HostStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
|
||||
HostStorageId id2 = HostStorageRegister("test2", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
HostStorageId id3 = HostStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
|
||||
HostStorageId id3 = HostStorageRegister("test3", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -243,8 +233,9 @@ static int HostStorageTest03(void)
|
|||
FAIL_IF_NULL(ptr2a);
|
||||
HostSetStorageById(h, id2, ptr2a);
|
||||
|
||||
void *ptr3a = HostAllocStorageById(h, id3);
|
||||
void *ptr3a = SCMalloc(32);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
HostSetStorageById(h, id3, ptr3a);
|
||||
|
||||
void *ptr1b = HostGetStorageById(h, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
|
|||
|
|
@ -36,13 +36,11 @@ unsigned int HostStorageSize(void);
|
|||
|
||||
void *HostGetStorageById(Host *h, HostStorageId id);
|
||||
int HostSetStorageById(Host *h, HostStorageId id, void *ptr);
|
||||
void *HostAllocStorageById(Host *h, HostStorageId id);
|
||||
|
||||
void HostFreeStorage(Host *h);
|
||||
|
||||
void RegisterHostStorageTests(void);
|
||||
|
||||
HostStorageId HostStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
HostStorageId HostStorageRegister(const char *name, const unsigned int size, void (*Free)(void *));
|
||||
|
||||
#endif /* SURICATA_HOST_STORAGE_H */
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ static void XBitFreeAll(void *store)
|
|||
|
||||
void IPPairBitInitCtx(void)
|
||||
{
|
||||
g_ippair_bit_storage_id = IPPairStorageRegister("bit", sizeof(void *), NULL, XBitFreeAll);
|
||||
g_ippair_bit_storage_id = IPPairStorageRegister("bit", sizeof(void *), XBitFreeAll);
|
||||
if (g_ippair_bit_storage_id.id == -1) {
|
||||
FatalError("Can't initiate ippair storage for bits");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,32 +42,22 @@ int IPPairSetStorageById(IPPair *h, IPPairStorageId id, void *ptr)
|
|||
return StorageSetById(h->storage, STORAGE_IPPAIR, id.id, ptr);
|
||||
}
|
||||
|
||||
void *IPPairAllocStorageById(IPPair *h, IPPairStorageId id)
|
||||
{
|
||||
return StorageAllocByIdPrealloc(h->storage, STORAGE_IPPAIR, id.id);
|
||||
}
|
||||
|
||||
void IPPairFreeStorage(IPPair *h)
|
||||
{
|
||||
if (IPPairStorageSize() > 0)
|
||||
StorageFreeAll(h->storage, STORAGE_IPPAIR);
|
||||
}
|
||||
|
||||
IPPairStorageId IPPairStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
IPPairStorageId IPPairStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
int id = StorageRegister(STORAGE_IPPAIR, name, size, Alloc, Free);
|
||||
int id = StorageRegister(STORAGE_IPPAIR, name, size, Free);
|
||||
IPPairStorageId ippsi = { .id = id };
|
||||
return ippsi;
|
||||
}
|
||||
|
||||
#ifdef UNITTESTS
|
||||
|
||||
static void *StorageTestAlloc(unsigned int size)
|
||||
{
|
||||
void *x = SCMalloc(size);
|
||||
return x;
|
||||
}
|
||||
static void StorageTestFree(void *x)
|
||||
{
|
||||
if (x)
|
||||
|
|
@ -79,12 +69,11 @@ static int IPPairStorageTest01(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
IPPairStorageId id2 = IPPairStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
|
||||
IPPairStorageId id2 = IPPairStorageRegister("variable", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
IPPairStorageId id3 =
|
||||
IPPairStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
|
||||
IPPairStorageId id3 = IPPairStorageRegister("store", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -108,12 +97,15 @@ static int IPPairStorageTest01(void)
|
|||
ptr = IPPairGetStorageById(h, id3);
|
||||
FAIL_IF_NOT_NULL(ptr);
|
||||
|
||||
void *ptr1a = IPPairAllocStorageById(h, id1);
|
||||
void *ptr1a = SCMalloc(8);
|
||||
FAIL_IF(ptr1a == NULL);
|
||||
void *ptr2a = IPPairAllocStorageById(h, id2);
|
||||
FAIL_IF(IPPairSetStorageById(h, id1, ptr1a) != 0);
|
||||
void *ptr2a = SCMalloc(24);
|
||||
FAIL_IF(ptr2a == NULL);
|
||||
void *ptr3a = IPPairAllocStorageById(h, id3);
|
||||
FAIL_IF(IPPairSetStorageById(h, id2, ptr2a) != 0);
|
||||
void *ptr3a = SCMalloc(16);
|
||||
FAIL_IF(ptr3a == NULL);
|
||||
FAIL_IF(IPPairSetStorageById(h, id3, ptr3a) != 0);
|
||||
|
||||
void *ptr1b = IPPairGetStorageById(h, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
@ -133,7 +125,7 @@ static int IPPairStorageTest02(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -172,11 +164,11 @@ static int IPPairStorageTest03(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
|
||||
IPPairStorageId id1 = IPPairStorageRegister("test1", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
IPPairStorageId id2 = IPPairStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
|
||||
IPPairStorageId id2 = IPPairStorageRegister("test2", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
IPPairStorageId id3 = IPPairStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
|
||||
IPPairStorageId id3 = IPPairStorageRegister("test3", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -206,8 +198,9 @@ static int IPPairStorageTest03(void)
|
|||
|
||||
IPPairSetStorageById(h, id2, ptr2a);
|
||||
|
||||
void *ptr3a = IPPairAllocStorageById(h, id3);
|
||||
void *ptr3a = SCMalloc(32);
|
||||
FAIL_IF(ptr3a == NULL);
|
||||
IPPairSetStorageById(h, id3, ptr3a);
|
||||
|
||||
void *ptr1b = IPPairGetStorageById(h, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
@ -230,4 +223,4 @@ void RegisterIPPairStorageTests(void)
|
|||
UtRegisterTest("IPPairStorageTest02", IPPairStorageTest02);
|
||||
UtRegisterTest("IPPairStorageTest03", IPPairStorageTest03);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,13 +36,12 @@ unsigned int IPPairStorageSize(void);
|
|||
|
||||
void *IPPairGetStorageById(IPPair *h, IPPairStorageId id);
|
||||
int IPPairSetStorageById(IPPair *h, IPPairStorageId id, void *ptr);
|
||||
void *IPPairAllocStorageById(IPPair *h, IPPairStorageId id);
|
||||
|
||||
void IPPairFreeStorage(IPPair *h);
|
||||
|
||||
void RegisterIPPairStorageTests(void);
|
||||
|
||||
IPPairStorageId IPPairStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
IPPairStorageId IPPairStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *));
|
||||
|
||||
#endif /* SURICATA_IPPAIR_STORAGE_H */
|
||||
|
|
|
|||
|
|
@ -37,11 +37,6 @@ int ThreadSetStorageById(ThreadVars *tv, ThreadStorageId id, void *ptr)
|
|||
return StorageSetById(tv->storage, storage_type, id.id, ptr);
|
||||
}
|
||||
|
||||
void *ThreadAllocStorageById(ThreadVars *tv, ThreadStorageId id)
|
||||
{
|
||||
return StorageAllocByIdPrealloc(tv->storage, storage_type, id.id);
|
||||
}
|
||||
|
||||
void ThreadFreeStorageById(ThreadVars *tv, ThreadStorageId id)
|
||||
{
|
||||
StorageFreeById(tv->storage, storage_type, id.id);
|
||||
|
|
@ -53,21 +48,16 @@ void ThreadFreeStorage(ThreadVars *tv)
|
|||
StorageFreeAll(tv->storage, storage_type);
|
||||
}
|
||||
|
||||
ThreadStorageId ThreadStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
ThreadStorageId ThreadStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
int id = StorageRegister(storage_type, name, size, Alloc, Free);
|
||||
int id = StorageRegister(storage_type, name, size, Free);
|
||||
ThreadStorageId tsi = { .id = id };
|
||||
return tsi;
|
||||
}
|
||||
|
||||
#ifdef UNITTESTS
|
||||
|
||||
static void *StorageTestAlloc(unsigned int size)
|
||||
{
|
||||
return SCCalloc(1, size);
|
||||
}
|
||||
|
||||
static void StorageTestFree(void *x)
|
||||
{
|
||||
SCFree(x);
|
||||
|
|
@ -78,14 +68,13 @@ static int ThreadStorageTest01(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
ThreadStorageId id2 = ThreadStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
|
||||
ThreadStorageId id2 = ThreadStorageRegister("variable", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
|
||||
ThreadStorageId id3 =
|
||||
ThreadStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
|
||||
ThreadStorageId id3 = ThreadStorageRegister("store", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -102,14 +91,17 @@ static int ThreadStorageTest01(void)
|
|||
ptr = ThreadGetStorageById(tv, id3);
|
||||
FAIL_IF_NOT_NULL(ptr);
|
||||
|
||||
void *ptr1a = ThreadAllocStorageById(tv, id1);
|
||||
void *ptr1a = SCMalloc(8);
|
||||
FAIL_IF_NULL(ptr1a);
|
||||
FAIL_IF(ThreadSetStorageById(tv, id1, ptr1a) != 0);
|
||||
|
||||
void *ptr2a = ThreadAllocStorageById(tv, id2);
|
||||
void *ptr2a = SCMalloc(24);
|
||||
FAIL_IF_NULL(ptr2a);
|
||||
FAIL_IF(ThreadSetStorageById(tv, id2, ptr2a) != 0);
|
||||
|
||||
void *ptr3a = ThreadAllocStorageById(tv, id3);
|
||||
void *ptr3a = SCMalloc(16);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
FAIL_IF(ThreadSetStorageById(tv, id3, ptr3a) != 0);
|
||||
|
||||
void *ptr1b = ThreadGetStorageById(tv, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
@ -131,7 +123,7 @@ static int ThreadStorageTest02(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -161,13 +153,13 @@ static int ThreadStorageTest03(void)
|
|||
StorageCleanup();
|
||||
StorageInit();
|
||||
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
|
||||
ThreadStorageId id1 = ThreadStorageRegister("test1", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id1.id < 0);
|
||||
|
||||
ThreadStorageId id2 = ThreadStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
|
||||
ThreadStorageId id2 = ThreadStorageRegister("test2", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id2.id < 0);
|
||||
|
||||
ThreadStorageId id3 = ThreadStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
|
||||
ThreadStorageId id3 = ThreadStorageRegister("test3", sizeof(void *), StorageTestFree);
|
||||
FAIL_IF(id3.id < 0);
|
||||
|
||||
FAIL_IF(StorageFinalize() < 0);
|
||||
|
|
@ -188,8 +180,9 @@ static int ThreadStorageTest03(void)
|
|||
|
||||
ThreadSetStorageById(tv, id2, ptr2a);
|
||||
|
||||
void *ptr3a = ThreadAllocStorageById(tv, id3);
|
||||
void *ptr3a = SCMalloc(32);
|
||||
FAIL_IF_NULL(ptr3a);
|
||||
ThreadSetStorageById(tv, id3, ptr3a);
|
||||
|
||||
void *ptr1b = ThreadGetStorageById(tv, id1);
|
||||
FAIL_IF(ptr1a != ptr1b);
|
||||
|
|
|
|||
|
|
@ -32,14 +32,13 @@ unsigned int ThreadStorageSize(void);
|
|||
|
||||
void *ThreadGetStorageById(const ThreadVars *tv, ThreadStorageId id);
|
||||
int ThreadSetStorageById(ThreadVars *tv, ThreadStorageId id, void *ptr);
|
||||
void *ThreadAllocStorageById(ThreadVars *tv, ThreadStorageId id);
|
||||
|
||||
void ThreadFreeStorageById(ThreadVars *tv, ThreadStorageId id);
|
||||
void ThreadFreeStorage(ThreadVars *tv);
|
||||
|
||||
void RegisterThreadStorageTests(void);
|
||||
|
||||
ThreadStorageId ThreadStorageRegister(const char *name, const unsigned int size,
|
||||
void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
ThreadStorageId ThreadStorageRegister(
|
||||
const char *name, const unsigned int size, void (*Free)(void *));
|
||||
|
||||
#endif /* SURICATA_THREAD_STORAGE_H */
|
||||
|
|
|
|||
|
|
@ -484,8 +484,8 @@ static void LiveDevExtensionFree(void *x)
|
|||
*/
|
||||
void LiveDevRegisterExtension(void)
|
||||
{
|
||||
g_bypass_storage_id = LiveDevStorageRegister("bypass_stats", sizeof(void *),
|
||||
NULL, LiveDevExtensionFree);
|
||||
g_bypass_storage_id =
|
||||
LiveDevStorageRegister("bypass_stats", sizeof(void *), LiveDevExtensionFree);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -929,8 +929,8 @@ int EBPFCheckBypassedFlowCreate(ThreadVars *th_v, struct timespec *curtime, void
|
|||
|
||||
void EBPFRegisterExtension(void)
|
||||
{
|
||||
g_livedev_storage_id = LiveDevStorageRegister("bpfmap", sizeof(void *), NULL, BpfMapsInfoFree);
|
||||
g_flow_storage_id = FlowStorageRegister("bypassedlist", sizeof(void *), NULL, BypassedListFree);
|
||||
g_livedev_storage_id = LiveDevStorageRegister("bpfmap", sizeof(void *), BpfMapsInfoFree);
|
||||
g_flow_storage_id = FlowStorageRegister("bypassedlist", sizeof(void *), BypassedListFree);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,7 @@ void FlowRateRegisterFlowStorage(void)
|
|||
}
|
||||
flow_rate_config.interval = SCTIME_ADD_SECS(interval, secs);
|
||||
|
||||
g_flowrate_storage_id =
|
||||
FlowStorageRegister("flowrate", sizeof(void *), NULL, FlowRateStoreFree);
|
||||
g_flowrate_storage_id = FlowStorageRegister("flowrate", sizeof(void *), FlowRateStoreFree);
|
||||
}
|
||||
|
||||
bool FlowRateStorageEnabled(void)
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void MacSetRegisterFlowStorage(void)
|
|||
SCConfNodeLookupChildValue(node->head.tqh_first, "ethernet");
|
||||
if (ethernet != NULL && SCConfValIsTrue(ethernet)) {
|
||||
g_macset_storage_id = FlowStorageRegister(
|
||||
"macset", sizeof(void *), NULL, (void (*)(void *))MacSetFree);
|
||||
"macset", sizeof(void *), (void (*)(void *))MacSetFree);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ typedef struct StorageMapping_ {
|
|||
const char *name;
|
||||
StorageEnum type; // host, flow, tx, stream, ssn, etc
|
||||
unsigned int size;
|
||||
void *(*Alloc)(unsigned int);
|
||||
void (*Free)(void *);
|
||||
} StorageMapping;
|
||||
|
||||
|
|
@ -99,13 +98,14 @@ void StorageCleanup(void)
|
|||
storage_list = NULL;
|
||||
}
|
||||
|
||||
int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *))
|
||||
int StorageRegister(
|
||||
const StorageEnum type, const char *name, const unsigned int size, void (*Free)(void *))
|
||||
{
|
||||
if (storage_registration_closed)
|
||||
return -1;
|
||||
|
||||
if (type >= STORAGE_MAX || name == NULL || strlen(name) == 0 ||
|
||||
size == 0 || (size != sizeof(void *) && Alloc == NULL) || Free == NULL)
|
||||
if (type >= STORAGE_MAX || name == NULL || strlen(name) == 0 || size == 0 ||
|
||||
size != sizeof(void *) || Free == NULL)
|
||||
return -1;
|
||||
|
||||
StorageList *list = storage_list;
|
||||
|
|
@ -127,7 +127,6 @@ int StorageRegister(const StorageEnum type, const char *name, const unsigned int
|
|||
entry->map.type = type;
|
||||
entry->map.name = name;
|
||||
entry->map.size = size;
|
||||
entry->map.Alloc = Alloc;
|
||||
entry->map.Free = Free;
|
||||
|
||||
entry->id = storage_max_id[type]++;
|
||||
|
|
@ -170,7 +169,6 @@ int StorageFinalize(void)
|
|||
storage_map[entry->map.type][entry->id].name = entry->map.name;
|
||||
storage_map[entry->map.type][entry->id].type = entry->map.type;
|
||||
storage_map[entry->map.type][entry->id].size = entry->map.size;
|
||||
storage_map[entry->map.type][entry->id].Alloc = entry->map.Alloc;
|
||||
storage_map[entry->map.type][entry->id].Free = entry->map.Free;
|
||||
}
|
||||
|
||||
|
|
@ -235,24 +233,6 @@ int StorageSetById(Storage *storage, const StorageEnum type, const int id, void
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
BUG_ON(!storage_registration_closed);
|
||||
#endif
|
||||
SCLogDebug("storage %p id %d", storage, id);
|
||||
|
||||
StorageMapping *map = &storage_map[type][id];
|
||||
if (storage[id].ptr == NULL && map->Alloc != NULL) {
|
||||
storage[id].ptr = map->Alloc(map->size);
|
||||
if (storage[id].ptr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return storage[id].ptr;
|
||||
}
|
||||
|
||||
void StorageFreeById(Storage *storage, StorageEnum type, int id)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ void StorageCleanup(void);
|
|||
* \param type type from StorageEnum
|
||||
* \param name name
|
||||
* \param size size of the per instance storage
|
||||
* \param Alloc alloc function for per instance storage
|
||||
* \param Free free 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.
|
||||
*/
|
||||
int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
|
||||
int StorageRegister(
|
||||
const StorageEnum type, const char *name, const unsigned int size, void (*Free)(void *));
|
||||
int StorageFinalize(void);
|
||||
|
||||
unsigned int StorageGetCnt(const StorageEnum type);
|
||||
|
|
|
|||
Loading…
Reference in a new issue