Skip to content

Commit

Permalink
app/dumpcap: allow multiple invocations
Browse files Browse the repository at this point in the history
[ upstream commit e0235c0e4d40a6d93dfef8b1316e03c32f2f8b43 ]

If dumpcap is run twice with each instance pointing a different
interface, it would fail because of overlap in ring a pool names.
Fix by putting process id in the name.

It is still not allowed to do multiple invocations on the same
interface because only one callback is allowed and only one copy
of mbuf is done. Dumpcap will fail with error in this case:

   pdump_prepare_client_request(): client request for pdump enable/disable failed
   EAL: Error - exiting with code: 1
     Cause: Packet dump enable on 0:net_null0 failed File exists

Fixes: cbb4414 ("app/dumpcap: add new packet capture application")

Reported-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
  • Loading branch information
shemminger authored and kevintraynor committed Nov 23, 2023
1 parent c9a8aa9 commit 952d702
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions app/dumpcap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <pcap/pcap.h>
#include <pcap/bpf.h>

#define RING_NAME "capture-ring"
#define MONITOR_INTERVAL (500 * 1000)
#define MBUF_POOL_CACHE_SIZE 32
#define BURST_SIZE 32
Expand Down Expand Up @@ -539,6 +538,7 @@ static void dpdk_init(void)
static struct rte_ring *create_ring(void)
{
struct rte_ring *ring;
char ring_name[RTE_RING_NAMESIZE];
size_t size, log2;

/* Find next power of 2 >= size. */
Expand All @@ -552,26 +552,26 @@ static struct rte_ring *create_ring(void)
ring_size = size;
}

ring = rte_ring_lookup(RING_NAME);
if (ring == NULL) {
ring = rte_ring_create(RING_NAME, ring_size,
rte_socket_id(), 0);
if (ring == NULL)
rte_exit(EXIT_FAILURE, "Could not create ring :%s\n",
rte_strerror(rte_errno));
}
/* Want one ring per invocation of program */
snprintf(ring_name, sizeof(ring_name),
"dumpcap-%d", getpid());

ring = rte_ring_create(ring_name, ring_size,
rte_socket_id(), 0);
if (ring == NULL)
rte_exit(EXIT_FAILURE, "Could not create ring :%s\n",
rte_strerror(rte_errno));

return ring;
}

static struct rte_mempool *create_mempool(void)
{
static const char pool_name[] = "capture_mbufs";
char pool_name[RTE_MEMPOOL_NAMESIZE];
size_t num_mbufs = 2 * ring_size;
struct rte_mempool *mp;

mp = rte_mempool_lookup(pool_name);
if (mp)
return mp;
snprintf(pool_name, sizeof(pool_name), "capture_%d", getpid());

mp = rte_pktmbuf_pool_create_by_ops(pool_name, num_mbufs,
MBUF_POOL_CACHE_SIZE, 0,
Expand Down

0 comments on commit 952d702

Please sign in to comment.