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