]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
host/storage: use flex array for host storage
authorVictor Julien <vjulien@oisf.net>
Fri, 24 Nov 2023 18:35:54 +0000 (19:35 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 1 Dec 2023 13:55:37 +0000 (14:55 +0100)
src/host-storage.c
src/host.h

index 72261de99d52b5190430c707eae58007f59cdac8..234c67112edf7353e73f6f957c12f4ab2de23964 100644 (file)
@@ -74,7 +74,7 @@ HostStorageId HostStorageRegister(const char *name, const unsigned int size,
 
 int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
 {
-    return StorageSetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id, ptr);
+    return StorageSetById(h->storage, STORAGE_HOST, id.id, ptr);
 }
 
 /**
@@ -87,7 +87,7 @@ int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
 
 void *HostGetStorageById(Host *h, HostStorageId id)
 {
-    return StorageGetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
+    return StorageGetById(h->storage, STORAGE_HOST, id.id);
 }
 
 /**
@@ -98,18 +98,18 @@ void *HostGetStorageById(Host *h, HostStorageId id)
 
 void *HostAllocStorageById(Host *h, HostStorageId id)
 {
-    return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
+    return StorageAllocByIdPrealloc(h->storage, STORAGE_HOST, id.id);
 }
 
 void HostFreeStorageById(Host *h, HostStorageId id)
 {
-    StorageFreeById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
+    StorageFreeById(h->storage, STORAGE_HOST, id.id);
 }
 
 void HostFreeStorage(Host *h)
 {
     if (HostStorageSize() > 0)
-        StorageFreeAll((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST);
+        StorageFreeAll(h->storage, STORAGE_HOST);
 }
 
 
index 2c6a037edf7d83bb2f4e0f7817488d204c32c7ae..f4f248b5eec657b2024b9b6c74cb963f52555443 100644 (file)
@@ -68,9 +68,6 @@ typedef struct Host_ {
     /** pointers to iprep storage */
     void *iprep;
 
-    /** storage api handle */
-    Storage *storage;
-
     /** hash pointers, protected by hash row mutex/spin */
     struct Host_ *hnext;
     struct Host_ *hprev;
@@ -78,6 +75,9 @@ typedef struct Host_ {
     /** list pointers, protected by host-queue mutex/spin */
     struct Host_ *lnext;
     struct Host_ *lprev;
+
+    /** storage api handle */
+    Storage storage[];
 } Host;
 
 typedef struct HostHashRow_ {