]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util-ioctl: Add function to get number of RSS queues on iface
authorEric Leblond <eric@regit.org>
Thu, 4 Dec 2014 16:49:31 +0000 (17:49 +0100)
committerEric Leblond <eric@regit.org>
Thu, 4 Dec 2014 17:13:45 +0000 (18:13 +0100)
The number of RSS queues can be fetched via a standard ioctl which
is independant of hardware.

src/util-ioctl.c
src/util-ioctl.h

index f46004213e281e472c37e34ff27f51f281272600..b3a0f224784eee555bd4381ee01a941ac2d25f6a 100644 (file)
@@ -210,3 +210,36 @@ int GetIfaceOffloading(char *pcap_dev)
 #endif
 }
 
+int GetIfaceRSSQueuesNum(const char *pcap_dev)
+{
+#ifdef HAVE_LINUX_ETHTOOL_H
+    struct ifreq ifr;
+    struct ethtool_rxnfc nfccmd;
+    int fd;
+
+    (void)strlcpy(ifr.ifr_name, pcap_dev, sizeof(ifr.ifr_name));
+    fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (fd == -1) {
+        return -1;
+    }
+
+    nfccmd.cmd = ETHTOOL_GRXRINGS;
+    ifr.ifr_data = (void*) &nfccmd;
+
+    if (ioctl(fd, SIOCETHTOOL, (char *)&ifr) < 0) {
+        if (errno != ENOTSUP) {
+            SCLogWarning(SC_ERR_SYSCALL,
+                         "Failure when trying to get number of RSS queue ioctl: %d",
+                         errno);
+        }
+        close(fd);
+        return 0;
+    }
+    close(fd);
+    SCLogInfo("Found %d RX RSS queues for '%s'", (int)nfccmd.data,
+            pcap_dev);
+    return (int)nfccmd.data;
+#else
+    return 0;
+#endif
+}
index 7bc5055710ba98d631f5b882c217d52fd4219345..d293a4d0476017896d3500b9d44c82377c692493 100644 (file)
@@ -24,3 +24,4 @@
 int GetIfaceMTU(char *pcap_dev);
 int GetIfaceMaxPacketSize(char *pcap_dev);
 int GetIfaceOffloading(char *pcap_dev);
+int GetIfaceRSSQueuesNum(const char *pcap_dev);