]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: add device name querying function
authorLukas Sismis <lsismis@oisf.net>
Wed, 31 May 2023 11:44:21 +0000 (13:44 +0200)
committerVictor Julien <vjulien@oisf.net>
Mon, 5 Jun 2023 09:07:02 +0000 (11:07 +0200)
src/util-dpdk.c
src/util-dpdk.h

index 83284411fe2a9d4c7b25d56f7c5188c2ac7ebfd6..291ab075e08ff78a341aea32993dbca0e00e15e5 100644 (file)
@@ -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 */
index 5c793d992151bce1c71764fae041f7949712dd96..b0810640db66384d58a3b4fb55c174be68cb1793 100644 (file)
@@ -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 */