From e4443fac53969f810a1713a0cd7dc73e71eaaf23 Mon Sep 17 00:00:00 2001 From: gureedo Date: Mon, 21 Mar 2016 15:14:34 +0500 Subject: [PATCH] netmap: fix issue 1717 Use packet pool only without packet allocation. Wait for N packets available in packet pool before netmap ring fetching. --- src/source-netmap.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/source-netmap.c b/src/source-netmap.c index 540f2faee3..f55ac86bc8 100644 --- a/src/source-netmap.c +++ b/src/source-netmap.c @@ -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); }