suricata
util-dpdk.c
Go to the documentation of this file.
1 /* Copyright (C) 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 Lukas Sismis <lukas.sismis@gmail.com>
22  */
23 
24 #include "suricata.h"
25 #include "util-dpdk.h"
26 #include "util-debug.h"
27 #include "util-byte.h"
28 
29 void DPDKCleanupEAL(void)
30 {
31 #ifdef HAVE_DPDK
32  if (run_mode == RUNMODE_DPDK) {
33  int retval = rte_eal_cleanup();
34  if (retval != 0)
35  SCLogError("EAL cleanup failed: %s", strerror(-retval));
36  }
37 #endif
38 }
39 
41 {
42  (void)ldev; // avoid warnings of unused variable
43 #ifdef HAVE_DPDK
44  if (run_mode == RUNMODE_DPDK) {
45  uint16_t port_id;
46  int retval = rte_eth_dev_get_port_by_name(ldev->dev, &port_id);
47  if (retval < 0) {
48  SCLogError("%s: failed get port id, error: %s", ldev->dev, rte_strerror(-retval));
49  return;
50  }
51 
52  SCLogPerf("%s: closing device", ldev->dev);
53  rte_eth_dev_close(port_id);
54  }
55 #endif
56 }
57 
59 {
60  (void)ldev; // avoid warnings of unused variable
61 #ifdef HAVE_DPDK
62  if (run_mode == RUNMODE_DPDK) {
63  SCLogDebug("%s: releasing packet mempool", ldev->dev);
64  rte_mempool_free(ldev->dpdk_vars.pkt_mp);
65  }
66 #endif
67 }
68 
69 #ifdef HAVE_DPDK
70 /**
71  * Retrieves name of the port from port id
72  * Not thread-safe
73  * @param pid
74  * @return static dev_name on success
75  */
76 const char *DPDKGetPortNameByPortID(uint16_t pid)
77 {
78  static char dev_name[RTE_ETH_NAME_MAX_LEN];
79  int32_t ret = rte_eth_dev_get_name_by_port(pid, dev_name);
80  if (ret < 0) {
81  FatalError("Port %d: Failed to obtain port name (err: %s)", pid, rte_strerror(-ret));
82  }
83  return dev_name;
84 }
85 
86 #endif /* HAVE_DPDK */
util-byte.h
RUNMODE_DPDK
@ RUNMODE_DPDK
Definition: runmodes.h:40
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
LiveDevice_
Definition: util-device.h:50
util-debug.h
LiveDevice_::dev
char * dev
Definition: util-device.h:51
DPDKFreeDevice
void DPDKFreeDevice(LiveDevice *ldev)
Definition: util-dpdk.c:58
DPDKCloseDevice
void DPDKCloseDevice(LiveDevice *ldev)
Definition: util-dpdk.c:40
util-dpdk.h
run_mode
int run_mode
Definition: suricata.c:175
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:230
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
suricata.h
DPDKCleanupEAL
void DPDKCleanupEAL(void)
Definition: util-dpdk.c:29