Coverage Report

Created: 2026-05-16 07:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/util-dpdk.c
Line
Count
Source
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
0
{
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
0
}
39
40
void DPDKCloseDevice(LiveDevice *ldev)
41
0
{
42
0
    (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
0
}
57
58
void DPDKFreeDevice(LiveDevice *ldev)
59
0
{
60
0
    (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
0
}
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 */