]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
device/storage: use dedicated 'id' type
authorJuliana Fajardini <jufajardini@gmail.com>
Wed, 14 Apr 2021 22:16:07 +0000 (23:16 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 15 Apr 2021 09:43:45 +0000 (11:43 +0200)
- Wrap the id in a new LiveDevStorageId struct, to avoid id
 confusion with other storage API calls.
- Formatting fixes by clang.

src/device-storage.c
src/device-storage.h
src/util-device.c
src/util-ebpf.c

index 2035eb8e97cfc89aaaff01181304e1fcfd57f5d5..d01ff41f2bff1c80c8064a09b9cbcfb9d7ee5908 100644 (file)
@@ -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
  * 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
  */
 
-int LiveDevStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *)) {
-    return StorageRegister(STORAGE_DEVICE, name, size, Alloc, Free);
+LiveDevStorageId LiveDevStorageRegister(const char *name, const unsigned int size,
+        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
  */
 
-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 */
 
-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)
index 0c671eac46064acd596ae743e11010ba4a5d5be8..046c8dd45433db16dc5ceeb882c11b7813aeaf8c 100644 (file)
@@ -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
  * the GNU General Public License version 2 as published by the Free
 #include "util-storage.h"
 #include "util-device.h"
 
+typedef struct LiveDevStorageId_ {
+    int id;
+} LiveDevStorageId;
+
 unsigned int LiveDevStorageSize(void);
 
-void *LiveDevGetStorageById(LiveDevice *d, int id);
-int LiveDevSetStorageById(LiveDevice *d, int id, void *ptr);
-void *LiveDevAllocStorageById(LiveDevice *d, int id);
+void *LiveDevGetStorageById(LiveDevice *d, LiveDevStorageId id);
+int LiveDevSetStorageById(LiveDevice *d, LiveDevStorageId id, void *ptr);
+void *LiveDevAllocStorageById(LiveDevice *d, LiveDevStorageId id);
 
-void LiveDevFreeStorageById(LiveDevice *d, int id);
+void LiveDevFreeStorageById(LiveDevice *d, LiveDevStorageId id);
 void LiveDevFreeStorage(LiveDevice *d);
 
 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__ */
index f95696a6c046fab247ffa8bed25dee43733b0091..a303fa835e81012d1f5021fd5a806759f4c52172 100644 (file)
@@ -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
  * the GNU General Public License version 2 as published by the Free
@@ -25,7 +25,7 @@
 
 #define MAX_DEVNAME 10
 
-static int g_bypass_storage_id = -1;
+static LiveDevStorageId g_bypass_storage_id = { .id = -1 };
 
 /**
  * \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 cnt number of flows to add
index b622b6ca00b6cb5882e5e409ce3fcc691606c0f7..94236aff5b8c40c257afbefc7f6244dbcfc9f8d2 100644 (file)
@@ -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
  * the GNU General Public License version 2 as published by the Free
@@ -60,8 +60,8 @@
 
 #define BYPASSED_FLOW_TIMEOUT   60
 
-static int g_livedev_storage_id = -1;
-static int g_flow_storage_id = -1;
+static LiveDevStorageId g_livedev_storage_id = { .id = -1 };
+static int g_flow_storage_id = -1; // TODO change this in a different commit
 
 struct bpf_map_item {
     char iface[IFNAMSIZ];