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