#include "util-print.h"
#include "queue.h"
-static int g_ippair_expectation_id = -1;
+static IPPairStorageId g_ippair_expectation_id = { .id = -1 };
static FlowStorageId g_flow_expectation_id = { .id = -1 };
SC_ATOMIC_DECLARE(uint32_t, expectation_count);
-/* Copyright (C) 2017 Open Information Security Foundation
+/* Copyright (C) 2017-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
-/* Copyright (C) 2007-2015 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "tm-threads.h"
static int host_threshold_id = -1; /**< host storage id for thresholds */
-static int ippair_threshold_id = -1; /**< ip pair storage id for thresholds */
+static IPPairStorageId ippair_threshold_id = { .id = -1 }; /**< ip pair storage id for thresholds */
int ThresholdHostStorageId(void)
{
"Can't initiate host storage for thresholding");
}
ippair_threshold_id = IPPairStorageRegister("threshold", sizeof(void *), NULL, ThresholdListFree);
- if (ippair_threshold_id == -1) {
+ if (ippair_threshold_id.id == -1) {
FatalError(SC_ERR_FATAL,
"Can't initiate IP pair storage for thresholding");
}
-/* Copyright (C) 2014 Open Information Security Foundation
+/* Copyright (C) 2014-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-unittest.h"
#include "ippair-storage.h"
-static int ippair_bit_id = -1; /**< IPPair storage id for bits */
+static IPPairStorageId g_ippair_bit_storage_id = { .id = -1 }; /**< IPPair storage id for bits */
static void XBitFreeAll(void *store)
{
void IPPairBitInitCtx(void)
{
- ippair_bit_id = IPPairStorageRegister("bit", sizeof(void *), NULL, XBitFreeAll);
- if (ippair_bit_id == -1) {
+ g_ippair_bit_storage_id = IPPairStorageRegister("bit", sizeof(void *), NULL, XBitFreeAll);
+ if (g_ippair_bit_storage_id.id == -1) {
FatalError(SC_ERR_FATAL, "Can't initiate ippair storage for bits");
}
}
{
if (ippair == NULL)
return 0;
- return IPPairGetStorageById(ippair, ippair_bit_id) ? 1 : 0;
+ return IPPairGetStorageById(ippair, g_ippair_bit_storage_id) ? 1 : 0;
}
/** \retval 1 ippair timed out wrt xbits
* \retval 0 ippair still has active (non-expired) xbits */
int IPPairBitsTimedoutCheck(IPPair *h, struct timeval *ts)
{
- GenericVar *gv = IPPairGetStorageById(h, ippair_bit_id);
+ GenericVar *gv = IPPairGetStorageById(h, g_ippair_bit_storage_id);
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS) {
XBit *xb = (XBit *)gv;
/* get the bit with idx from the ippair */
static XBit *IPPairBitGet(IPPair *h, uint32_t idx)
{
- GenericVar *gv = IPPairGetStorageById(h, ippair_bit_id);
+ GenericVar *gv = IPPairGetStorageById(h, g_ippair_bit_storage_id);
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS && gv->idx == idx) {
return (XBit *)gv;
fb->next = NULL;
fb->expire = expire;
- GenericVar *gv = IPPairGetStorageById(h, ippair_bit_id);
+ GenericVar *gv = IPPairGetStorageById(h, g_ippair_bit_storage_id);
GenericVarAppend(&gv, (GenericVar *)fb);
- IPPairSetStorageById(h, ippair_bit_id, gv);
+ IPPairSetStorageById(h, g_ippair_bit_storage_id, gv);
// bit already set, lets update it's timer
} else {
if (fb == NULL)
return;
- GenericVar *gv = IPPairGetStorageById(h, ippair_bit_id);
+ GenericVar *gv = IPPairGetStorageById(h, g_ippair_bit_storage_id);
if (gv) {
GenericVarRemove(&gv, (GenericVar *)fb);
XBitFree(fb);
- IPPairSetStorageById(h, ippair_bit_id, gv);
+ IPPairSetStorageById(h, g_ippair_bit_storage_id, gv);
}
}
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
return StorageGetSize(STORAGE_IPPAIR);
}
-void *IPPairGetStorageById(IPPair *h, int id)
+void *IPPairGetStorageById(IPPair *h, IPPairStorageId id)
{
- return StorageGetById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id);
+ return StorageGetById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id.id);
}
-int IPPairSetStorageById(IPPair *h, int id, void *ptr)
+int IPPairSetStorageById(IPPair *h, IPPairStorageId id, void *ptr)
{
- return StorageSetById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id, ptr);
+ return StorageSetById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id.id, ptr);
}
-void *IPPairAllocStorageById(IPPair *h, int id)
+void *IPPairAllocStorageById(IPPair *h, IPPairStorageId id)
{
- return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id);
+ return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id.id);
}
-void IPPairFreeStorageById(IPPair *h, int id)
+void IPPairFreeStorageById(IPPair *h, IPPairStorageId id)
{
- StorageFreeById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id);
+ StorageFreeById((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR, id.id);
}
void IPPairFreeStorage(IPPair *h)
StorageFreeAll((Storage *)((void *)h + sizeof(IPPair)), STORAGE_IPPAIR);
}
-int IPPairStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *)) {
- return StorageRegister(STORAGE_IPPAIR, name, size, Alloc, Free);
+IPPairStorageId IPPairStorageRegister(const char *name, const unsigned int size,
+ void *(*Alloc)(unsigned int), void (*Free)(void *))
+{
+ int id = StorageRegister(STORAGE_IPPAIR, name, size, Alloc, Free);
+ IPPairStorageId ippsi = { .id = id };
+ return ippsi;
}
#ifdef UNITTESTS
{
StorageInit();
- int id1 = IPPairStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
- if (id1 < 0)
+ IPPairStorageId id1 = IPPairStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = IPPairStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
- if (id2 < 0)
+ IPPairStorageId id2 = IPPairStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = IPPairStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ IPPairStorageId id3 =
+ IPPairStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
{
StorageInit();
- int id1 = IPPairStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ IPPairStorageId id1 = IPPairStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
if (StorageFinalize() < 0)
{
StorageInit();
- int id1 = IPPairStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ IPPairStorageId id1 = IPPairStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = IPPairStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
- if (id2 < 0)
+ IPPairStorageId id2 = IPPairStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = IPPairStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ IPPairStorageId id3 = IPPairStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-storage.h"
#include "ippair.h"
+typedef struct IPPairStorageId {
+ int id;
+} IPPairStorageId;
+
unsigned int IPPairStorageSize(void);
-void *IPPairGetStorageById(IPPair *h, int id);
-int IPPairSetStorageById(IPPair *h, int id, void *ptr);
-void *IPPairAllocStorageById(IPPair *h, int id);
+void *IPPairGetStorageById(IPPair *h, IPPairStorageId id);
+int IPPairSetStorageById(IPPair *h, IPPairStorageId id, void *ptr);
+void *IPPairAllocStorageById(IPPair *h, IPPairStorageId id);
-void IPPairFreeStorageById(IPPair *h, int id);
+void IPPairFreeStorageById(IPPair *h, IPPairStorageId id);
void IPPairFreeStorage(IPPair *h);
void RegisterIPPairStorageTests(void);
-int 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 *(*Alloc)(unsigned int), void (*Free)(void *));
#endif /* __IPPAIR_STORAGE_H__ */