device/storage: use dedicated 'id' type

- Wrap the id in a new LiveDevStorageId struct, to avoid id
 confusion with other storage API calls.
- Formatting fixes by clang.
pull/6058/head
Juliana Fajardini 5 years ago committed by Victor Julien
parent 68b8b3d63e
commit 3b1a653467

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Open Information Security Foundation /* Copyright (C) 2018-2021 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -56,8 +56,12 @@ unsigned int LiveDevStorageSize(void)
* It has to be called once during the init of the sub system * It has to be called once during the init of the sub system
*/ */
int LiveDevStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *)) { LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size,
return StorageRegister(STORAGE_DEVICE, name, size, Alloc, Free); void *(*Alloc)(unsigned int), void (*Free)(void *))
{
int id = StorageRegister(STORAGE_DEVICE, name, size, Alloc, Free);
LiveDevStorageId ldsi = { .id = id };
return ldsi;
} }
/** /**
@ -68,9 +72,9 @@ int LiveDevStorageRegister(const char *name, const unsigned int size, void *(*Al
* \param ptr pointer to the data to store * \param ptr pointer to the data to store
*/ */
int LiveDevSetStorageById(LiveDevice *d, int id, void *ptr) int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr)
{ {
return StorageSetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id, ptr); return StorageSetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id, ptr);
} }
/** /**
@ -81,9 +85,9 @@ int LiveDevSetStorageById(LiveDevice *d, int id, void *ptr)
* *
*/ */
void *LiveDevGetStorageById(LiveDevice *d, int id) void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
return StorageGetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id); return StorageGetById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id);
} }
/** /**
@ -92,14 +96,15 @@ void *LiveDevGetStorageById(LiveDevice *d, int id)
/* Start of "private" function */ /* Start of "private" function */
void *LiveDevAllocStorageById(LiveDevice *d, int id) void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
return StorageAllocByIdPrealloc((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id); return StorageAllocByIdPrealloc(
(Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id);
} }
void LiveDevFreeStorageById(LiveDevice *d, int id) void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id)
{ {
StorageFreeById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id); StorageFreeById((Storage *)((void *)d + sizeof(LiveDevice)), STORAGE_DEVICE, id.id);
} }
void LiveDevFreeStorage(LiveDevice *d) void LiveDevFreeStorage(LiveDevice *d)

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Open Information Security Foundation /* Copyright (C) 2018-2021 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -29,17 +29,22 @@
#include "util-storage.h" #include "util-storage.h"
#include "util-device.h" #include "util-device.h"
typedef struct LiveDevStorageId_ {
int id;
} LiveDevStorageId;
unsigned int LiveDevStorageSize(void); unsigned int LiveDevStorageSize(void);
void *LiveDevGetStorageById(LiveDevice *d, int id); void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id);
int LiveDevSetStorageById(LiveDevice *d, int id, void *ptr); int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr);
void *LiveDevAllocStorageById(LiveDevice *d, int id); void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id);
void LiveDevFreeStorageById(LiveDevice *d, int id); void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id);
void LiveDevFreeStorage(LiveDevice *d); void LiveDevFreeStorage(LiveDevice *d);
void RegisterLiveDevStorageTests(void); void RegisterLiveDevStorageTests(void);
int 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 *(*Alloc)(unsigned int), void (*Free)(void *));
#endif /* __DEVICE_STORAGE_H__ */ #endif /* __DEVICE_STORAGE_H__ */

@ -1,4 +1,4 @@
/* Copyright (C) 2011-2016 Open Information Security Foundation /* Copyright (C) 2011-2021 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -25,7 +25,7 @@
#define MAX_DEVNAME 10 #define MAX_DEVNAME 10
static int g_bypass_storage_id = -1; static LiveDevStorageId g_bypass_storage_id = { .id = -1 };
/** /**
* \file * \file
@ -590,7 +590,7 @@ void LiveDevAddBypassFail(LiveDevice *dev, uint64_t cnt, int family)
} }
/** /**
* Increase number of currently succesfully bypassed flows for a protocol family * Increase number of currently successfully bypassed flows for a protocol family
* *
* \param dev pointer to LiveDevice to set stats for * \param dev pointer to LiveDevice to set stats for
* \param cnt number of flows to add * \param cnt number of flows to add

@ -1,4 +1,4 @@
/* Copyright (C) 2018-2019 Open Information Security Foundation /* Copyright (C) 2018-2021 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -60,8 +60,8 @@
#define BYPASSED_FLOW_TIMEOUT 60 #define BYPASSED_FLOW_TIMEOUT 60
static int g_livedev_storage_id = -1; static LiveDevStorageId g_livedev_storage_id = { .id = -1 };
static int g_flow_storage_id = -1; static int g_flow_storage_id = -1; // TODO change this in a different commit
struct bpf_map_item { struct bpf_map_item {
char iface[IFNAMSIZ]; char iface[IFNAMSIZ];

Loading…
Cancel
Save