From b4bb6e67ba10a432c84f2e81fcbbebc911999110 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Thu, 4 Dec 2014 17:49:31 +0100 Subject: [PATCH] util-ioctl: Add function to get number of RSS queues on iface The number of RSS queues can be fetched via a standard ioctl which is independant of hardware. --- src/util-ioctl.c | 33 +++++++++++++++++++++++++++++++++ src/util-ioctl.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/util-ioctl.c b/src/util-ioctl.c index f46004213e..b3a0f22478 100644 --- a/src/util-ioctl.c +++ b/src/util-ioctl.c @@ -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 +} diff --git a/src/util-ioctl.h b/src/util-ioctl.h index 7bc5055710..d293a4d047 100644 --- a/src/util-ioctl.h +++ b/src/util-ioctl.h @@ -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);