From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 39FB04331C;
	Mon, 13 Nov 2023 17:15:46 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 7A71840A7A;
	Mon, 13 Nov 2023 17:15:36 +0100 (CET)
Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com
 [209.85.215.180])
 by mails.dpdk.org (Postfix) with ESMTP id C4DDC4069D
 for <dev@dpdk.org>; Mon, 13 Nov 2023 17:15:33 +0100 (CET)
Received: by mail-pg1-f180.google.com with SMTP id
 41be03b00d2f7-5bda105206fso3038814a12.3
 for <dev@dpdk.org>; Mon, 13 Nov 2023 08:15:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1699892132;
 x=1700496932; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=0MaO/0MG9UJV3dgitduxB67mqwREYVEtxDOzyLfA4Cc=;
 b=lvLflIU+YggoHPjJ06AwQABmbcxgCzo8TNExl3P+3IAIGAq0SkZWcLYonQIExdwmCt
 FUgijIuje89RGLdDqIouktf8LsSUsw1TZh105Xs8GscrBVjyYrvs/eTZ4D50MQ6sbd7d
 VLOYWpkdV81Pjhb5ry5LI4QxZLorZ/dNW+o3Tr4bf7ZGg576t7JIGzyeI3K6mAnv5dtM
 cGqbYgpJ/PZE8X4bNBbMcBBJzEmIiyYFJdQ7ardsOU8fV+EB5N0BrkCqR9reS8XoaJ5Y
 xjGo91t4K/P1dEvtu+VxbrJu0y9HTG/Ts/pOqdUg2EYRlmAmlkJpqF2zUz+7N2AmQwcO
 doXg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1699892132; x=1700496932;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=0MaO/0MG9UJV3dgitduxB67mqwREYVEtxDOzyLfA4Cc=;
 b=uuE6CxsiDRCKtgDha4DvKh1jlXYD7q0XSZyfXfBQ28oH9TKpAZjSLJeciGa/Ezw53i
 /5z5GTK+/xXW7+0liOFhdWEnsZc3fvp1m4aa/+L344tt1K/Hc6ikp2BxYxkDVyj2kc2j
 ImCnu4MvBIGmxhtHUwV1sHrirI5SDvHR4NQ3y1/zQxOQkDMNtNPJDhK7EcR+bZup3vNq
 MgWJmV0L5yIaokTOC3QumUbrKU02kRQ3poB6FeMiYmahpIXQOFMtygC4Nleym2I1G3R1
 9khYF06uj1JH+6jZgUxMl9GsLmDsKOyWSC+PxbsQq+j8UUTnV+K9zqqojvsOLZHStajE
 uzTg==
X-Gm-Message-State: AOJu0YybRyIFmwsItLE3PdwONPnHFxJcCK6I5xaa0o71KpFk/PMfWWWp
 BSXuU+jPA5JWRxvHFan26lCJ3eHmPiaCVxzUAJA=
X-Google-Smtp-Source: AGHT+IF+2XL7FnrIUSGHv4JV9sIWKYwqUZrsFcMIVJIr9e/qiTbDjFlEUdz6NZPaltBlbDRzsLsIvw==
X-Received: by 2002:a05:6a20:4c86:b0:180:febc:8ecb with SMTP id
 fq6-20020a056a204c8600b00180febc8ecbmr4083995pzb.54.1699892132413; 
 Mon, 13 Nov 2023 08:15:32 -0800 (PST)
Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141])
 by smtp.gmail.com with ESMTPSA id
 hq11-20020a056a00680b00b006c69bbf03e2sm3350043pfb.192.2023.11.13.08.15.31
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 13 Nov 2023 08:15:31 -0800 (PST)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
 Isaac Boukris <iboukris@gmail.com>, Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH v6 2/5] dumpcap: allow multiple invocations
Date: Mon, 13 Nov 2023 08:15:16 -0800
Message-Id: <20231113161519.242272-3-stephen@networkplumber.org>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20231113161519.242272-1-stephen@networkplumber.org>
References: <20230921042349.104150-1-stephen@networkplumber.org>
 <20231113161519.242272-1-stephen@networkplumber.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

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: cbb44143be74 ("app/dumpcap: add new packet capture application")
Reported-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 4f581bd341d8..d05dddac0071 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -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
@@ -647,6 +646,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. */
@@ -660,28 +660,28 @@ 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)
 {
 	const struct interface *intf;
-	static const char pool_name[] = "capture_mbufs";
+	char pool_name[RTE_MEMPOOL_NAMESIZE];
 	size_t num_mbufs = 2 * ring_size;
 	struct rte_mempool *mp;
 	uint32_t data_size = 128;
 
-	mp = rte_mempool_lookup(pool_name);
-	if (mp)
-		return mp;
+	snprintf(pool_name, sizeof(pool_name), "capture_%d", getpid());
 
 	/* Common pool so size mbuf for biggest snap length */
 	TAILQ_FOREACH(intf, &interfaces, next) {
@@ -826,7 +826,7 @@ static void enable_pdump(struct rte_ring *r, struct rte_mempool *mp)
 			rte_exit(EXIT_FAILURE,
 				"Packet dump enable on %u:%s failed %s\n",
 				intf->port, intf->name,
-				rte_strerror(-ret));
+				rte_strerror(rte_errno));
 		}
 
 		if (intf->opts.promisc_mode) {
-- 
2.39.2