host/storage: prefix API with SC

pull/15161/head
Jason Ish 4 months ago committed by Victor Julien
parent 67bd09ba2c
commit 279aa88956

@ -46,14 +46,14 @@
SC_ATOMIC_DECLARE(unsigned int, num_tags); /**< Atomic counter, to know if we
have tagged hosts/sessions,
to avoid locking */
static HostStorageId host_tag_id = { .id = -1 }; /**< Host storage id for tags */
static SCHostStorageId host_tag_id = { .id = -1 }; /**< Host storage id for tags */
static SCFlowStorageId flow_tag_id = { .id = -1 }; /**< Flow storage id for tags */
void TagInitCtx(void)
{
SC_ATOMIC_INIT(num_tags);
host_tag_id = HostStorageRegister("tag", DetectTagDataListFree);
host_tag_id = SCHostStorageRegister("tag", DetectTagDataListFree);
if (host_tag_id.id == -1) {
FatalError("Can't initiate host storage for tag");
}
@ -78,7 +78,7 @@ void TagDestroyCtx(void)
int TagHostHasTag(Host *host)
{
return HostGetStorageById(host, host_tag_id) ? 1 : 0;
return SCHostGetStorageById(host, host_tag_id) ? 1 : 0;
}
static DetectTagDataEntry *DetectTagDataCopy(DetectTagDataEntry *dtd)
@ -191,12 +191,12 @@ int TagHashAddTag(DetectTagDataEntry *tde, Packet *p)
return -1;
}
void *tag = HostGetStorageById(host, host_tag_id);
void *tag = SCHostGetStorageById(host, host_tag_id);
if (tag == NULL) {
/* get a new tde as the one we have is on the stack */
DetectTagDataEntry *new_tde = DetectTagDataCopy(tde);
if (new_tde != NULL) {
HostSetStorageById(host, host_tag_id, new_tde);
SCHostSetStorageById(host, host_tag_id, new_tde);
(void) SC_ATOMIC_ADD(num_tags, 1);
SCLogDebug("host tag added");
}
@ -232,7 +232,7 @@ int TagHashAddTag(DetectTagDataEntry *tde, Packet *p)
(void) SC_ATOMIC_ADD(num_tags, 1);
new_tde->next = tag;
HostSetStorageById(host, host_tag_id, new_tde);
SCHostSetStorageById(host, host_tag_id, new_tde);
}
} else if (ntags == DETECT_TAG_MAX_TAGS) {
SCLogDebug("Max tags for sessions reached (%"PRIu16")", ntags);
@ -377,7 +377,7 @@ static void TagHandlePacketHost(Host *host, Packet *p)
DetectTagDataEntry *iter;
uint8_t flag_added = 0;
iter = HostGetStorageById(host, host_tag_id);
iter = SCHostGetStorageById(host, host_tag_id);
prev = NULL;
while (iter != NULL) {
/* update counters */
@ -414,7 +414,7 @@ static void TagHandlePacketHost(Host *host, Packet *p)
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
HostSetStorageById(host, host_tag_id, iter);
SCHostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
@ -440,7 +440,7 @@ static void TagHandlePacketHost(Host *host, Packet *p)
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
HostSetStorageById(host, host_tag_id, iter);
SCHostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
@ -473,7 +473,7 @@ static void TagHandlePacketHost(Host *host, Packet *p)
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
HostSetStorageById(host, host_tag_id, iter);
SCHostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
@ -569,7 +569,7 @@ int TagTimeoutCheck(Host *host, SCTime_t ts)
DetectTagDataEntry *prev = NULL;
int retval = 1;
tmp = HostGetStorageById(host, host_tag_id);
tmp = SCHostGetStorageById(host, host_tag_id);
if (tmp == NULL)
return 1;
@ -594,7 +594,7 @@ int TagTimeoutCheck(Host *host, SCTime_t ts)
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
} else {
HostSetStorageById(host, host_tag_id, tmp->next);
SCHostSetStorageById(host, host_tag_id, tmp->next);
tde = tmp;
tmp = tde->next;
@ -672,12 +672,12 @@ static int DetectTagTestPacket01 (void)
Host *src = HostLookupHostFromHash(&p[1]->src);
FAIL_IF_NULL(src);
FAIL_IF_NOT_NULL(HostGetStorageById(src, host_tag_id));
FAIL_IF_NOT_NULL(SCHostGetStorageById(src, host_tag_id));
Host *dst = HostLookupHostFromHash(&p[1]->dst);
FAIL_IF_NULL(dst);
void *tag = HostGetStorageById(dst, host_tag_id);
void *tag = SCHostGetStorageById(dst, host_tag_id);
FAIL_IF_NULL(tag);
DetectTagDataEntry *iter = tag;

@ -67,7 +67,7 @@ LiveDevStorageId LiveDevStorageRegister(const char *name, void (*Free)(void *))
* \brief Store a pointer in a given LiveDevice storage
*
* \param d a pointer to the LiveDevice
* \param id the id of the storage (return of HostStorageRegister() call)
* \param id the id of the storage (return of SCHostStorageRegister() call)
* \param ptr pointer to the data to store
*/

@ -38,7 +38,7 @@
#include "util-unittest.h"
#include "host-storage.h"
static HostStorageId host_bit_id = { .id = -1 }; /**< Host storage id for bits */
static SCHostStorageId host_bit_id = { .id = -1 }; /**< Host storage id for bits */
static void HostBitFreeAll(void *store)
{
@ -48,7 +48,7 @@ static void HostBitFreeAll(void *store)
void HostBitInitCtx(void)
{
host_bit_id = HostStorageRegister("bit", HostBitFreeAll);
host_bit_id = SCHostStorageRegister("bit", HostBitFreeAll);
if (host_bit_id.id == -1) {
FatalError("Can't initiate host storage for bits");
}
@ -59,14 +59,14 @@ int HostHasHostBits(Host *host)
{
if (host == NULL)
return 0;
return HostGetStorageById(host, host_bit_id) ? 1 : 0;
return SCHostGetStorageById(host, host_bit_id) ? 1 : 0;
}
/** \retval 1 host timed out wrt xbits
* \retval 0 host still has active (non-expired) xbits */
int HostBitsTimedoutCheck(Host *h, SCTime_t ts)
{
GenericVar *gv = HostGetStorageById(h, host_bit_id);
GenericVar *gv = SCHostGetStorageById(h, host_bit_id);
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS) {
XBit *xb = (XBit *)gv;
@ -80,7 +80,7 @@ int HostBitsTimedoutCheck(Host *h, SCTime_t ts)
/* get the bit with idx from the host */
static XBit *HostBitGet(Host *h, uint32_t idx)
{
GenericVar *gv = HostGetStorageById(h, host_bit_id);
GenericVar *gv = SCHostGetStorageById(h, host_bit_id);
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS && gv->idx == idx) {
return (XBit *)gv;
@ -104,11 +104,11 @@ static void HostBitAdd(Host *h, uint32_t idx, SCTime_t expire)
fb->next = NULL;
fb->expire = expire;
GenericVar *gv = HostGetStorageById(h, host_bit_id);
GenericVar *gv = SCHostGetStorageById(h, host_bit_id);
GenericVarAppend(&gv, (GenericVar *)fb);
HostSetStorageById(h, host_bit_id, gv);
SCHostSetStorageById(h, host_bit_id, gv);
// bit already set, lets update it's time
// bit already set, lets update it's time
} else {
fb->expire = expire;
}
@ -120,11 +120,11 @@ static void HostBitRemove(Host *h, uint32_t idx)
if (fb == NULL)
return;
GenericVar *gv = HostGetStorageById(h, host_bit_id);
GenericVar *gv = SCHostGetStorageById(h, host_bit_id);
if (gv) {
GenericVarRemove(&gv, (GenericVar *)fb);
XBitFree(fb);
HostSetStorageById(h, host_bit_id, gv);
SCHostSetStorageById(h, host_bit_id, gv);
}
}
@ -185,7 +185,7 @@ int HostBitList(Host *h, XBit **iter)
{
GenericVar *gv = (GenericVar *)*iter;
if (gv == NULL) {
gv = HostGetStorageById(h, host_bit_id);
gv = SCHostGetStorageById(h, host_bit_id);
} else {
gv = gv->next;
}

@ -27,7 +27,7 @@
#include "host-storage.h"
#include "util-unittest.h"
unsigned int HostStorageSize(void)
unsigned int SCHostStorageSize(void)
{
return StorageGetSize(STORAGE_HOST);
}
@ -37,9 +37,9 @@ unsigned int HostStorageSize(void)
* The Host storage API is a per-host storage. It is a mean to extend
* the Host structure with arbitrary data.
*
* You have first to register the storage via HostStorageRegister() during
* the init of your module. Then you can attach data via HostSetStorageById()
* and access them via HostGetStorageById().
* You have first to register the storage via SCHostStorageRegister() during
* the init of your module. Then you can attach data via SCHostSetStorageById()
* and access them via SCHostGetStorageById().
* @{
*/
@ -54,10 +54,10 @@ unsigned int HostStorageSize(void)
* It has to be called once during the init of the sub system
*/
HostStorageId HostStorageRegister(const char *name, void (*Free)(void *))
SCHostStorageId SCHostStorageRegister(const char *name, void (*Free)(void *))
{
int id = StorageRegister(STORAGE_HOST, name, Free);
HostStorageId hsi = { .id = id };
SCHostStorageId hsi = { .id = id };
return hsi;
}
@ -65,11 +65,11 @@ HostStorageId HostStorageRegister(const char *name, void (*Free)(void *))
* \brief Store a pointer in a given Host storage
*
* \param h a pointer to the Host
* \param id the id of the storage (return of HostStorageRegister() call)
* \param id the id of the storage (return of SCHostStorageRegister() call)
* \param ptr pointer to the data to store
*/
int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
int SCHostSetStorageById(Host *h, SCHostStorageId id, void *ptr)
{
return StorageSetById(h->storage, STORAGE_HOST, id.id, ptr);
}
@ -78,11 +78,11 @@ int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
* \brief Get a value from a given Host storage
*
* \param h a pointer to the Host
* \param id the id of the storage (return of HostStorageRegister() call)
* \param id the id of the storage (return of SCHostStorageRegister() call)
*
*/
void *HostGetStorageById(Host *h, HostStorageId id)
void *SCHostGetStorageById(Host *h, SCHostStorageId id)
{
return StorageGetById(h->storage, STORAGE_HOST, id.id);
}
@ -93,9 +93,9 @@ void *HostGetStorageById(Host *h, HostStorageId id)
/* Start of "private" function */
void HostFreeStorage(Host *h)
void SCHostFreeStorage(Host *h)
{
if (HostStorageSize() > 0)
if (SCHostStorageSize() > 0)
StorageFreeAll(h->storage, STORAGE_HOST);
}
@ -113,11 +113,11 @@ static int HostStorageTest01(void)
StorageCleanup();
StorageInit();
HostStorageId id1 = HostStorageRegister("test", StorageTestFree);
SCHostStorageId id1 = SCHostStorageRegister("test", StorageTestFree);
FAIL_IF(id1.id < 0);
HostStorageId id2 = HostStorageRegister("variable", StorageTestFree);
SCHostStorageId id2 = SCHostStorageRegister("variable", StorageTestFree);
FAIL_IF(id2.id < 0);
HostStorageId id3 = HostStorageRegister("store", StorageTestFree);
SCHostStorageId id3 = SCHostStorageRegister("store", StorageTestFree);
FAIL_IF(id3.id < 0);
FAIL_IF(StorageFinalize() < 0);
@ -131,28 +131,28 @@ static int HostStorageTest01(void)
Host *h = HostGetHostFromHash(&a);
FAIL_IF_NULL(h);
void *ptr = HostGetStorageById(h, id1);
void *ptr = SCHostGetStorageById(h, id1);
FAIL_IF_NOT_NULL(ptr);
ptr = HostGetStorageById(h, id2);
ptr = SCHostGetStorageById(h, id2);
FAIL_IF_NOT_NULL(ptr);
ptr = HostGetStorageById(h, id3);
ptr = SCHostGetStorageById(h, id3);
FAIL_IF_NOT_NULL(ptr);
void *ptr1a = SCMalloc(8);
FAIL_IF_NULL(ptr1a);
FAIL_IF(HostSetStorageById(h, id1, ptr1a) != 0);
FAIL_IF(SCHostSetStorageById(h, id1, ptr1a) != 0);
void *ptr2a = SCMalloc(24);
FAIL_IF_NULL(ptr2a);
FAIL_IF(HostSetStorageById(h, id2, ptr2a) != 0);
FAIL_IF(SCHostSetStorageById(h, id2, ptr2a) != 0);
void *ptr3a = SCMalloc(16);
FAIL_IF_NULL(ptr3a);
FAIL_IF(HostSetStorageById(h, id3, ptr3a) != 0);
FAIL_IF(SCHostSetStorageById(h, id3, ptr3a) != 0);
void *ptr1b = HostGetStorageById(h, id1);
void *ptr1b = SCHostGetStorageById(h, id1);
FAIL_IF(ptr1a != ptr1b);
void *ptr2b = HostGetStorageById(h, id2);
void *ptr2b = SCHostGetStorageById(h, id2);
FAIL_IF(ptr2a != ptr2b);
void *ptr3b = HostGetStorageById(h, id3);
void *ptr3b = SCHostGetStorageById(h, id3);
FAIL_IF(ptr3a != ptr3b);
HostRelease(h);
@ -167,7 +167,7 @@ static int HostStorageTest02(void)
StorageCleanup();
StorageInit();
HostStorageId id1 = HostStorageRegister("test", StorageTestFree);
SCHostStorageId id1 = SCHostStorageRegister("test", StorageTestFree);
FAIL_IF(id1.id < 0);
FAIL_IF(StorageFinalize() < 0);
@ -181,14 +181,14 @@ static int HostStorageTest02(void)
Host *h = HostGetHostFromHash(&a);
FAIL_IF_NULL(h);
void *ptr = HostGetStorageById(h, id1);
void *ptr = SCHostGetStorageById(h, id1);
FAIL_IF_NOT_NULL(ptr);
void *ptr1a = SCMalloc(128);
FAIL_IF_NULL(ptr1a);
HostSetStorageById(h, id1, ptr1a);
SCHostSetStorageById(h, id1, ptr1a);
void *ptr1b = HostGetStorageById(h, id1);
void *ptr1b = SCHostGetStorageById(h, id1);
FAIL_IF(ptr1a != ptr1b);
HostRelease(h);
@ -203,11 +203,11 @@ static int HostStorageTest03(void)
StorageCleanup();
StorageInit();
HostStorageId id1 = HostStorageRegister("test1", StorageTestFree);
SCHostStorageId id1 = SCHostStorageRegister("test1", StorageTestFree);
FAIL_IF(id1.id < 0);
HostStorageId id2 = HostStorageRegister("test2", StorageTestFree);
SCHostStorageId id2 = SCHostStorageRegister("test2", StorageTestFree);
FAIL_IF(id2.id < 0);
HostStorageId id3 = HostStorageRegister("test3", StorageTestFree);
SCHostStorageId id3 = SCHostStorageRegister("test3", StorageTestFree);
FAIL_IF(id3.id < 0);
FAIL_IF(StorageFinalize() < 0);
@ -221,26 +221,26 @@ static int HostStorageTest03(void)
Host *h = HostGetHostFromHash(&a);
FAIL_IF_NULL(h);
void *ptr = HostGetStorageById(h, id1);
void *ptr = SCHostGetStorageById(h, id1);
FAIL_IF_NOT_NULL(ptr);
void *ptr1a = SCMalloc(128);
FAIL_IF_NULL(ptr1a);
HostSetStorageById(h, id1, ptr1a);
SCHostSetStorageById(h, id1, ptr1a);
void *ptr2a = SCMalloc(256);
FAIL_IF_NULL(ptr2a);
HostSetStorageById(h, id2, ptr2a);
SCHostSetStorageById(h, id2, ptr2a);
void *ptr3a = SCMalloc(32);
FAIL_IF_NULL(ptr3a);
HostSetStorageById(h, id3, ptr3a);
SCHostSetStorageById(h, id3, ptr3a);
void *ptr1b = HostGetStorageById(h, id1);
void *ptr1b = SCHostGetStorageById(h, id1);
FAIL_IF(ptr1a != ptr1b);
void *ptr2b = HostGetStorageById(h, id2);
void *ptr2b = SCHostGetStorageById(h, id2);
FAIL_IF(ptr2a != ptr2b);
void *ptr3b = HostGetStorageById(h, id3);
void *ptr3b = SCHostGetStorageById(h, id3);
FAIL_IF(ptr3a != ptr3b);
HostRelease(h);
@ -251,7 +251,7 @@ static int HostStorageTest03(void)
}
#endif
void RegisterHostStorageTests(void)
void SCRegisterHostStorageTests(void)
{
#ifdef UNITTESTS
UtRegisterTest("HostStorageTest01", HostStorageTest01);

@ -30,17 +30,17 @@
typedef struct HostStorageId_ {
int id;
} HostStorageId;
} SCHostStorageId;
unsigned int HostStorageSize(void);
unsigned int SCHostStorageSize(void);
void *HostGetStorageById(Host *h, HostStorageId id);
int HostSetStorageById(Host *h, HostStorageId id, void *ptr);
void *SCHostGetStorageById(Host *h, SCHostStorageId id);
int SCHostSetStorageById(Host *h, SCHostStorageId id, void *ptr);
void HostFreeStorage(Host *h);
void SCHostFreeStorage(Host *h);
void RegisterHostStorageTests(void);
void SCRegisterHostStorageTests(void);
HostStorageId HostStorageRegister(const char *name, void (*Free)(void *));
SCHostStorageId SCHostStorageRegister(const char *name, void (*Free)(void *));
#endif /* SURICATA_HOST_STORAGE_H */

@ -153,8 +153,8 @@ void HostClearMemory(Host *h)
SRepFreeHostData(h);
}
if (HostStorageSize() > 0)
HostFreeStorage(h);
if (SCHostStorageSize() > 0)
SCHostFreeStorage(h);
BUG_ON(SC_ATOMIC_GET(h->use_cnt) > 0);
}
@ -168,9 +168,9 @@ void HostClearMemory(Host *h)
void HostInitConfig(bool quiet)
{
SCLogDebug("initializing host engine...");
if (HostStorageSize() > 0) {
DEBUG_VALIDATE_BUG_ON(sizeof(Host) + HostStorageSize() > UINT16_MAX);
g_host_size = (uint16_t)(sizeof(Host) + HostStorageSize());
if (SCHostStorageSize() > 0) {
DEBUG_VALIDATE_BUG_ON(sizeof(Host) + SCHostStorageSize() > UINT16_MAX);
g_host_size = (uint16_t)(sizeof(Host) + SCHostStorageSize());
}
memset(&host_config, 0, sizeof(host_config));
@ -339,7 +339,7 @@ void HostCleanup(void)
while (h) {
if ((SC_ATOMIC_GET(h->use_cnt) > 0) && (h->iprep != NULL)) {
/* iprep is attached to host only clear local storage */
HostFreeStorage(h);
SCHostFreeStorage(h);
h = h->hnext;
} else {
Host *n = h->hnext;
@ -716,5 +716,5 @@ static Host *HostGetUsedHost(void)
void HostRegisterUnittests(void)
{
RegisterHostStorageTests();
SCRegisterHostStorageTests();
}

Loading…
Cancel
Save