]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
netmap: fix issue 1717 1950/head
authorgureedo <gureedo@intersvyaz.net>
Mon, 21 Mar 2016 10:14:34 +0000 (15:14 +0500)
committergureedo <gureedo@intersvyaz.net>
Mon, 21 Mar 2016 10:14:34 +0000 (15:14 +0500)
Use packet pool only without packet allocation.
Wait for N packets available in packet pool before netmap ring fetching.

src/source-netmap.c

index 540f2faee308643bc90108ad814eaadf33ad4db8..f55ac86bc885b9584ad45a742a816392adf656dc 100644 (file)
@@ -80,7 +80,7 @@
 
 #endif /* HAVE_NETMAP */
 
-extern int max_pending_packets;
+extern intmax_t max_pending_packets;
 
 #ifndef HAVE_NETMAP
 
@@ -635,6 +635,15 @@ static TmEcode ReceiveNetmapThreadInit(ThreadVars *tv, void *initdata, void **da
         ntv->flags |= NETMAP_FLAG_ZERO_COPY;
         SCLogInfo("Enabling zero copy mode for %s->%s",
                   aconf->iface_name, aconf->out_iface_name);
+    } else {
+        uint16_t ring_size = ntv->ifsrc->rings[0].rx->num_slots;
+        if (ring_size > max_pending_packets) {
+            SCLogError(SC_ERR_NETMAP_CREATE,
+                       "Packet pool size (%" PRIuMAX ") must be greater or equal than %s ring size (%" PRIu16 "). "
+                       "Increase max_pending_packets option.",
+                       max_pending_packets, aconf->iface_name, ring_size);
+            goto error_dst;
+        }
     }
 
     if (aconf->bpf_filter) {
@@ -762,6 +771,10 @@ static int NetmapRingRead(NetmapThreadVars *ntv, int ring_id)
     uint32_t avail = nm_ring_space(rx);
     uint32_t cur = rx->cur;
 
+    if (!(ntv->flags & NETMAP_FLAG_ZERO_COPY)) {
+        PacketPoolWaitForN(avail);
+    }
+
     while (likely(avail-- > 0)) {
         struct netmap_slot *slot = &rx->slot[cur];
         unsigned char *slot_data = (unsigned char *)NETMAP_BUF(rx, slot->buf_idx);
@@ -775,7 +788,7 @@ static int NetmapRingRead(NetmapThreadVars *ntv, int ring_id)
             }
         }
 
-        Packet *p = PacketGetFromQueueOrAlloc();
+        Packet *p = PacketPoolGetPacket();
         if (unlikely(p == NULL)) {
             SCReturnInt(NETMAP_FAILURE);
         }