mirror of
https://github.com/OISF/suricata.git
synced 2026-10-12 02:07:10 +00:00
dpdk: move DPDK socket retrieval to utils
This commit is contained in:
committed by
Victor Julien
parent
44948b9e28
commit
e471972a5b
+2
-23
@@ -1295,27 +1295,6 @@ static void DeviceSetMTU(struct rte_eth_conf *port_conf, uint16_t mtu)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \param port_id - queried port
|
||||
* \param socket_id - socket ID of the queried port
|
||||
* \return non-negative number on success, negative on failure (errno)
|
||||
*/
|
||||
static int32_t DeviceSetSocketID(uint16_t port_id, int32_t *socket_id)
|
||||
{
|
||||
rte_errno = 0;
|
||||
int retval = rte_eth_dev_socket_id(port_id);
|
||||
*socket_id = retval;
|
||||
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) // DPDK API changed since 22.11
|
||||
retval = -rte_errno;
|
||||
#else
|
||||
if (retval == SOCKET_ID_ANY)
|
||||
retval = 0; // DPDK couldn't determine socket ID of a port
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void PortConfSetInterruptMode(const DPDKIfaceConfig *iconf, struct rte_eth_conf *port_conf)
|
||||
{
|
||||
SCLogConfig("%s: interrupt mode is %s", iconf->iface,
|
||||
@@ -1567,7 +1546,7 @@ static int DeviceConfigureIPS(DPDKIfaceConfig *iconf)
|
||||
SCReturnInt(-ENODEV);
|
||||
}
|
||||
int32_t out_port_socket_id;
|
||||
int retval = DeviceSetSocketID(iconf->out_port_id, &out_port_socket_id);
|
||||
int retval = DPDKDeviceSetSocketID(iconf->out_port_id, &out_port_socket_id);
|
||||
if (retval < 0) {
|
||||
SCLogError("%s: invalid socket id: %s", iconf->out_iface, rte_strerror(-retval));
|
||||
SCReturnInt(retval);
|
||||
@@ -1646,7 +1625,7 @@ static int DeviceConfigure(DPDKIfaceConfig *iconf)
|
||||
SCReturnInt(-ENODEV);
|
||||
}
|
||||
|
||||
int32_t retval = DeviceSetSocketID(iconf->port_id, &iconf->socket_id);
|
||||
int32_t retval = DPDKDeviceSetSocketID(iconf->port_id, &iconf->socket_id);
|
||||
if (retval < 0) {
|
||||
SCLogError("%s: invalid socket id: %s", iconf->iface, rte_strerror(-retval));
|
||||
SCReturnInt(retval);
|
||||
|
||||
@@ -67,6 +67,49 @@ void DPDKFreeDevice(LiveDevice *ldev)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \param port_id - queried port
|
||||
* \param socket_id - socket ID of the queried port
|
||||
* \return non-negative number on success, negative on failure (errno)
|
||||
*/
|
||||
int32_t DPDKDeviceSetSocketID(uint16_t port_id, int32_t *socket_id)
|
||||
{
|
||||
#ifdef HAVE_DPDK
|
||||
rte_errno = 0;
|
||||
int retval = rte_eth_dev_socket_id(port_id);
|
||||
*socket_id = retval;
|
||||
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) // DPDK API changed since 22.11
|
||||
retval = -rte_errno;
|
||||
#else
|
||||
if (retval == SOCKET_ID_ANY)
|
||||
retval = 0; // DPDK couldn't determine socket ID of a port
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
#endif /* HAVE_DPDK */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* \param iface_name - name of the queried interface
|
||||
* \param socket_id - socket ID of the queried port
|
||||
* \return non-negative number on success, negative on failure (errno)
|
||||
*/
|
||||
int32_t DPDKDeviceNameSetSocketID(char *iface_name, int32_t *socket_id)
|
||||
{
|
||||
#ifdef HAVE_DPDK
|
||||
uint16_t port_id = 0;
|
||||
int r = rte_eth_dev_get_port_by_name(iface_name, &port_id);
|
||||
if (r < 0) {
|
||||
SCLogError("%s: interface not found: %s", iface_name, rte_strerror(-r));
|
||||
SCReturnInt(r);
|
||||
}
|
||||
return DPDKDeviceSetSocketID(port_id, socket_id);
|
||||
#endif /* HAVE_DPDK */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DPDK
|
||||
/**
|
||||
* Retrieves name of the port from port id
|
||||
|
||||
@@ -31,6 +31,8 @@ void DPDKCleanupEAL(void);
|
||||
|
||||
void DPDKCloseDevice(LiveDevice *ldev);
|
||||
void DPDKFreeDevice(LiveDevice *ldev);
|
||||
int32_t DPDKDeviceSetSocketID(uint16_t port_id, int32_t *socket_id);
|
||||
int32_t DPDKDeviceNameSetSocketID(char *iface_name, int32_t *socket_id);
|
||||
|
||||
#ifdef HAVE_DPDK
|
||||
const char *DPDKGetPortNameByPortID(uint16_t pid);
|
||||
|
||||
Reference in New Issue
Block a user