]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
netmap: implement 'threads: auto'
authorVictor Julien <victor@inliniac.net>
Thu, 2 Jun 2016 04:41:50 +0000 (06:41 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 2 Jun 2016 04:58:15 +0000 (06:58 +0200)
Add until function for retrieving RSS RX count from netmap. Use the
RSS count to create the threads.

src/runmode-netmap.c
src/source-netmap.c
src/source-netmap.h

index 5d76e417d2f7403b7a111a5ad8b950c3951fedf7..f154e7cf15787669fb34540f77991980ba7f6a28 100644 (file)
@@ -180,7 +180,7 @@ static void *ParseNetmapConfig(const char *iface_name)
         aconf->threads = 1;
     } else {
         if (strcmp(threadsstr, "auto") == 0) {
-            aconf->threads = GetIfaceRSSQueuesNum(aconf->iface);
+            aconf->threads = NetmapGetRSSCount(aconf->iface);
         } else {
             aconf->threads = (uint8_t)atoi(threadsstr);
         }
index fdb4c707e7f98bc08aa2d1128a04d64fe4f16a2b..fff2b26e27d5f24c8761492d1d227be5beedd20c 100644 (file)
@@ -277,6 +277,46 @@ static int NetmapSetIfaceFlags(int fd, const char *ifname, int flags)
     return 0;
 }
 
+/** \brief get RSS RX-queue count
+ *  \retval rx_rings RSS RX queue count or 1 on error
+ */
+int NetmapGetRSSCount(const char *ifname)
+{
+    struct nmreq nm_req;
+    int rx_rings = 1;
+
+    SCMutexLock(&netmap_devlist_lock);
+
+    /* open netmap */
+    int fd = open("/dev/netmap", O_RDWR);
+    if (fd == -1) {
+        SCLogError(SC_ERR_NETMAP_CREATE,
+                "Couldn't open netmap device, error %s",
+                strerror(errno));
+        goto error_open;
+    }
+
+    /* query netmap info */
+    memset(&nm_req, 0, sizeof(nm_req));
+    strlcpy(nm_req.nr_name, ifname, sizeof(nm_req.nr_name));
+    nm_req.nr_version = NETMAP_API;
+
+    if (ioctl(fd, NIOCGINFO, &nm_req) != 0) {
+        SCLogError(SC_ERR_NETMAP_CREATE,
+                "Couldn't query netmap for %s, error %s",
+                ifname, strerror(errno));
+        goto error_fd;
+    };
+
+    rx_rings = nm_req.nr_rx_rings;
+
+error_fd:
+    close(fd);
+error_open:
+    SCMutexUnlock(&netmap_devlist_lock);
+    return rx_rings;
+}
+
 /**
  * \brief Open interface in netmap mode.
  * \param ifname Interface name.
index c52b505079296eca849366509c9c7816a211580e..c6f7b6c23ff6b55a74aecceba8eeff7f9e38ecab 100644 (file)
@@ -67,6 +67,8 @@ typedef struct NetmapPacketVars_
     void *ntv;
 } NetmapPacketVars;
 
+int NetmapGetRSSCount(const char *ifname);
+
 void TmModuleReceiveNetmapRegister (void);
 void TmModuleDecodeNetmapRegister (void);