diff --git a/src/util-dpdk.c b/src/util-dpdk.c index 83284411fe..291ab075e0 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -57,3 +57,23 @@ void DPDKCloseDevice(LiveDevice *ldev) } #endif } + +#ifdef HAVE_DPDK + +/** + * Retrieves name of the port from port id + * Not thread-safe + * @param pid + * @return static dev_name on success + */ +const char *DPDKGetPortNameByPortID(uint16_t pid) +{ + static char dev_name[RTE_ETH_NAME_MAX_LEN]; + int32_t ret = rte_eth_dev_get_name_by_port(pid, dev_name); + if (ret < 0) { + FatalError("Port %d: Failed to obtain port name (err: %s)", pid, rte_strerror(-ret)); + } + return dev_name; +} + +#endif /* HAVE_DPDK */ diff --git a/src/util-dpdk.h b/src/util-dpdk.h index 5c793d9921..b0810640db 100644 --- a/src/util-dpdk.h +++ b/src/util-dpdk.h @@ -118,4 +118,8 @@ void DPDKCleanupEAL(void); void DPDKCloseDevice(LiveDevice *ldev); +#ifdef HAVE_DPDK +const char *DPDKGetPortNameByPortID(uint16_t pid); +#endif /* HAVE_DPDK */ + #endif /* UTIL_DPDK_H */