#include "util-print.h"
static int g_ippair_expectation_id = -1;
-static int g_flow_expectation_id = -1;
+static FlowStorageId g_flow_expectation_id = { .id = -1 };
SC_ATOMIC_DECLARE(uint32_t, expectation_count);
*
* \return expectation data identifier
*/
-int AppLayerExpectationGetFlowId(void)
+FlowStorageId AppLayerExpectationGetFlowId(void)
{
return g_flow_expectation_id;
}
#ifndef __APP_LAYER_EXPECTATION__H__
#define __APP_LAYER_EXPECTATION__H__
+#include "flow-storage.h"
+
void AppLayerExpectationSetup(void);
int AppLayerExpectationCreate(Flow *f, int direction, Port src, Port dst,
AppProto alproto, void *data);
AppProto AppLayerExpectationHandle(Flow *f, uint8_t flags);
-int AppLayerExpectationGetFlowId(void);
+FlowStorageId AppLayerExpectationGetFlowId(void);
void AppLayerExpectationClean(Flow *f);
have tagged hosts/sessions,
to avoid locking */
static int host_tag_id = -1; /**< Host storage id for tags */
-static int flow_tag_id = -1; /**< Flow storage id for tags */
+static FlowStorageId flow_tag_id = { .id = -1 }; /**< Flow storage id for tags */
void TagInitCtx(void)
{
FatalError(SC_ERR_FATAL, "Can't initiate host storage for tag");
}
flow_tag_id = FlowStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
- if (flow_tag_id == -1) {
+ if (flow_tag_id.id == -1) {
FatalError(SC_ERR_FATAL, "Can't initiate flow storage for tag");
}
}
return StorageGetSize(STORAGE_FLOW);
}
-void *FlowGetStorageById(Flow *f, int id)
+void *FlowGetStorageById(Flow *f, FlowStorageId id)
{
- return StorageGetById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id);
+ return StorageGetById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id.id);
}
-int FlowSetStorageById(Flow *f, int id, void *ptr)
+int FlowSetStorageById(Flow *f, FlowStorageId id, void *ptr)
{
- return StorageSetById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id, ptr);
+ return StorageSetById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id.id, ptr);
}
-void *FlowAllocStorageById(Flow *f, int id)
+void *FlowAllocStorageById(Flow *f, FlowStorageId id)
{
- return StorageAllocByIdPrealloc((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id);
+ return StorageAllocByIdPrealloc((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id.id);
}
-void FlowFreeStorageById(Flow *f, int id)
+void FlowFreeStorageById(Flow *f, FlowStorageId id)
{
- StorageFreeById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id);
+ StorageFreeById((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW, id.id);
}
void FlowFreeStorage(Flow *f)
StorageFreeAll((Storage *)((void *)f + sizeof(Flow)), STORAGE_FLOW);
}
-int FlowStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *)) {
- return StorageRegister(STORAGE_FLOW, name, size, Alloc, Free);
+FlowStorageId FlowStorageRegister(const char *name, const unsigned int size,
+ void *(*Alloc)(unsigned int), void (*Free)(void *))
+{
+ int id = StorageRegister(STORAGE_FLOW, name, size, Alloc, Free);
+ FlowStorageId fsi = { .id = id };
+ return fsi;
}
#ifdef UNITTESTS
StorageInit();
- int id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
- if (id1 < 0)
+ FlowStorageId id1 = FlowStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = FlowStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
- if (id2 < 0)
+ FlowStorageId id2 = FlowStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = FlowStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ FlowStorageId id3 =
+ FlowStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
StorageInit();
- int id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ FlowStorageId id1 = FlowStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
if (StorageFinalize() < 0)
StorageInit();
- int id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ FlowStorageId id1 = FlowStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = FlowStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
- if (id2 < 0)
+ FlowStorageId id2 = FlowStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = FlowStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ FlowStorageId id3 = FlowStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
#include "util-storage.h"
#include "flow.h"
+typedef struct FlowStorageId {
+ int id;
+} FlowStorageId;
+
unsigned int FlowStorageSize(void);
-void *FlowGetStorageById(Flow *h, int id);
-int FlowSetStorageById(Flow *h, int id, void *ptr);
-void *FlowAllocStorageById(Flow *h, int id);
+void *FlowGetStorageById(Flow *h, FlowStorageId id);
+int FlowSetStorageById(Flow *h, FlowStorageId id, void *ptr);
+void *FlowAllocStorageById(Flow *h, FlowStorageId id);
-void FlowFreeStorageById(Flow *h, int id);
+void FlowFreeStorageById(Flow *h, FlowStorageId id);
void FlowFreeStorage(Flow *h);
void RegisterFlowStorageTests(void);
-int 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 *(*Alloc)(unsigned int), void (*Free)(void *));
#endif /* __FLOW_STORAGE_H__ */
SCReturn;
}
-int g_bypass_info_id = -1;
+FlowStorageId g_bypass_info_id = { .id = -1 };
-int GetFlowBypassInfoID(void)
+FlowStorageId GetFlowBypassInfoID(void)
{
return g_bypass_info_id;
}
#ifndef __FLOW_H__
#define __FLOW_H__
+/* forward declaration for macset include */
+typedef struct FlowStorageId FlowStorageId;
+
#include "decode.h"
#include "util-var.h"
#include "util-atomic.h"
uint64_t FlowGetMemcap(void);
uint64_t FlowGetMemuse(void);
-int GetFlowBypassInfoID(void);
+FlowStorageId GetFlowBypassInfoID(void);
void RegisterFlowBypassInfo(void);
void FlowGetLastTimeAsParts(Flow *flow, uint64_t *secs, uint64_t *usecs);
last[2];
};
-int g_macset_storage_id = -1;
+FlowStorageId g_macset_storage_id = { .id = -1 };
void MacSetRegisterFlowStorage(void)
{
bool MacSetFlowStorageEnabled(void)
{
- return (g_macset_storage_id != -1);
+ return (g_macset_storage_id.id != -1);
}
return ms;
}
-int MacSetGetFlowStorageID(void)
+FlowStorageId MacSetGetFlowStorageID(void)
{
return g_macset_storage_id;
}
void MacSetReset(MacSet*);
void MacSetFree(MacSet*);
void MacSetRegisterFlowStorage(void);
-int MacSetGetFlowStorageID(void);
+FlowStorageId MacSetGetFlowStorageID(void);
bool MacSetFlowStorageEnabled(void);
void MacSetRegisterTests(void);
-#endif /* __UTIL_MACSET_H__ */
\ No newline at end of file
+#endif /* __UTIL_MACSET_H__ */