suricata
util-dpdk-common.c
Go to the documentation of this file.
1 /* Copyright (C) 2025 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 Lukas Sismis <lukas.sismis@oisf.net>
22  */
23 
24 #include "suricata-common.h"
25 #include "util-debug.h"
26 #include "util-dpdk-common.h"
27 
28 #ifdef HAVE_DPDK
29 
30 int DPDKDeviceResourcesInit(DPDKDeviceResources **dpdk_vars, uint16_t mp_cnt)
31 {
32  SCEnter();
33  *dpdk_vars = SCCalloc(1, sizeof(*dpdk_vars[0]));
34  if (*dpdk_vars == NULL) {
35  SCLogError("failed to allocate memory for packet mempools structure");
36  SCReturnInt(-ENOMEM);
37  }
38 
39  (*dpdk_vars)->pkt_mp = SCCalloc(mp_cnt, sizeof((*dpdk_vars)->pkt_mp[0]));
40  if ((*dpdk_vars)->pkt_mp == NULL) {
41  SCLogError("failed to allocate memory for packet mempools");
42  SCReturnInt(-ENOMEM);
43  }
44  (*dpdk_vars)->pkt_mp_capa = mp_cnt;
45  (*dpdk_vars)->pkt_mp_cnt = 0;
46 
47  SCReturnInt(0);
48 }
49 
50 void DPDKDeviceResourcesDeinit(DPDKDeviceResources **dpdk_vars)
51 {
52  if ((*dpdk_vars) != NULL) {
53  if ((*dpdk_vars)->pkt_mp != NULL) {
54  for (int j = 0; j < (*dpdk_vars)->pkt_mp_capa; j++) {
55  if ((*dpdk_vars)->pkt_mp[j] != NULL) {
56  rte_mempool_free((*dpdk_vars)->pkt_mp[j]);
57  }
58  }
59  SCFree((*dpdk_vars)->pkt_mp);
60  (*dpdk_vars)->pkt_mp_capa = 0;
61  (*dpdk_vars)->pkt_mp_cnt = 0;
62  (*dpdk_vars)->pkt_mp = NULL;
63  }
64  SCFree(*dpdk_vars);
65  *dpdk_vars = NULL;
66  }
67 }
68 
69 #endif /* HAVE_DPDK */
util-debug.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
suricata-common.h
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
util-dpdk-common.h
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275