suricata
device-storage.c
Go to the documentation of this file.
1 /* Copyright (C) 2018-2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Eric Leblond <eric@regit.org>
22  *
23  * Device wrapper around storage api
24  */
25 
26 #include "suricata-common.h"
27 #include "device-storage.h"
28 #include "util-device-private.h"
29 #include "util-storage.h"
30 
31 unsigned int SCLiveDevStorageSize(void)
32 {
34 }
35 
36 /** \defgroup devicestorage Device storage API
37  *
38  * The device storage API is a per-device storage. It is a mean to extend
39  * the LiveDevice structure with arbitrary data.
40  *
41  * You have first to register the storage via SCLiveDevStorageRegister() during
42  * the init of your module. Then you can attach data via SCLiveDevSetStorageById()
43  * and access them via SCLiveDevGetStorageById().
44  * @{
45  */
46 
47 /**
48  * \brief Register a LiveDevice storage
49  *
50  * \param name the name of the storage
51  * \param Free free function for the new storage
52  *
53  * \retval The ID of the newly register storage that will be used to access data
54  *
55  * It has to be called once during the init of the sub system
56  */
57 
58 SCLiveDevStorageId SCLiveDevStorageRegister(const char *name, void (*Free)(void *))
59 {
60  int id = SCStorageRegister(STORAGE_DEVICE, name, Free);
61  SCLiveDevStorageId ldsi = { .id = id };
62  return ldsi;
63 }
64 
65 /**
66  * \brief Store a pointer in a given LiveDevice storage
67  *
68  * \param d a pointer to the LiveDevice
69  * \param id the id of the storage (return of SCHostStorageRegister() call)
70  * \param ptr pointer to the data to store
71  */
72 
74 {
75  return SCStorageSetById(d->storage, STORAGE_DEVICE, id.id, ptr);
76 }
77 
78 /**
79  * \brief Get a value from a given LiveDevice storage
80  *
81  * \param d a pointer to the LiveDevice
82  * \param id the id of the storage (return of SCLiveDevStorageRegister() call)
83  *
84  */
85 
87 {
88  return SCStorageGetById(d->storage, STORAGE_DEVICE, id.id);
89 }
90 
91 /**
92  * @}
93  */
94 
95 /* Start of "private" function */
96 
98 {
99  if (SCLiveDevStorageSize() > 0)
101 }
102 
103 
util-device-private.h
LiveDevStorageId_
Definition: device-storage.h:31
name
const char * name
Definition: detect-engine-proto.c:47
LiveDevice_
Definition: util-device-private.h:32
device-storage.h
SCStorageSetById
int SCStorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
Definition: util-storage.c:217
LiveDevice_::storage
Storage storage[]
Definition: util-device-private.h:53
STORAGE_DEVICE
@ STORAGE_DEVICE
Definition: util-storage.h:33
SCStorageGetById
void * SCStorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:206
SCStorageRegister
int SCStorageRegister(const StorageEnum type, const char *name, void(*Free)(void *))
Register new storage.
Definition: util-storage.c:99
SCStorageGetSize
unsigned int SCStorageGetSize(StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:201
SCLiveDevFreeStorage
void SCLiveDevFreeStorage(LiveDevice *d)
Definition: device-storage.c:97
SCLiveDevGetStorageById
void * SCLiveDevGetStorageById(LiveDevice *d, SCLiveDevStorageId id)
Get a value from a given LiveDevice storage.
Definition: device-storage.c:86
suricata-common.h
SCStorageFreeAll
void SCStorageFreeAll(Storage *storage, StorageEnum type)
Definition: util-storage.c:251
SCLiveDevStorageRegister
SCLiveDevStorageId SCLiveDevStorageRegister(const char *name, void(*Free)(void *))
Register a LiveDevice storage.
Definition: device-storage.c:58
SCLiveDevSetStorageById
int SCLiveDevSetStorageById(LiveDevice *d, SCLiveDevStorageId id, void *ptr)
Store a pointer in a given LiveDevice storage.
Definition: device-storage.c:73
LiveDevStorageId_::id
int id
Definition: device-storage.h:32
util-storage.h
SCLiveDevStorageSize
unsigned int SCLiveDevStorageSize(void)
Definition: device-storage.c:31