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 3D0C24597C;
	Fri, 13 Sep 2024 14:34:08 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id D5EC44025E;
	Fri, 13 Sep 2024 14:34:07 +0200 (CEST)
Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com
 [209.85.218.52]) by mails.dpdk.org (Postfix) with ESMTP id B677A4003C
 for <dev@dpdk.org>; Fri, 13 Sep 2024 14:34:06 +0200 (CEST)
Received: by mail-ej1-f52.google.com with SMTP id
 a640c23a62f3a-a8d100e9ce0so243144266b.2
 for <dev@dpdk.org>; Fri, 13 Sep 2024 05:34:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=interfacemasters.com; s=google; t=1726230846; x=1726835646; darn=dpdk.org;
 h=in-reply-to:content-disposition:mime-version:references:reply-to
 :message-id:subject:cc:to:date:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=YvGe5R+kRJPNnrQltIfNaIZbNJmhZGBzVEt7XtB64FI=;
 b=Dr739MHWF5VJtHxWbQJwzPzXrjjuSV7z/yOmXMbqLwaqz+sdSb5L2Fmlj8ILDaxmRP
 yry3J7wNMuHJrWTiZDiYZyiLvhKA/29tyBl7ZiL5tqK7z4PbS1rKbAfFecMGbbEeUBMj
 9WN2d9MsROt931FhjEI/gqyURpcDriJXjCZLs=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1726230846; x=1726835646;
 h=in-reply-to:content-disposition:mime-version:references:reply-to
 :message-id:subject:cc:to:date:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=YvGe5R+kRJPNnrQltIfNaIZbNJmhZGBzVEt7XtB64FI=;
 b=rdzeM78MZFOOINqEudSF/4LmRswfT4o2IC1dS8HjlVZ3nkouOiUcmmqTQU3TRtpHZC
 nzOhLhCU9iBhOG2JCtNQW9wmaKIcP4vWhgb14ph2zrvonG/o1ArCeD3/CkgqKER3JWpT
 4/GmSdt7f1IWGIgFNrAXyQfrWvEIgVlPiyi4zc65f1CC3/9QPqoUwzADiLwex+bvpta3
 8aQy01SZKGqO/t1z7JAdHc+Ip12CvlM7vaLDZnpZQ14HllSh5e/0rrcvyPcKX+jDMCNU
 ahMgogz3PU0g8glAKtEDkh21K0E3+TxnJtes8vdx+7uUD7VNKyRMDijsBf1qPOq6t6nC
 ar7Q==
X-Gm-Message-State: AOJu0YwjrdiS7kxrpstW4Kp8oP9ymvb+CnF7cWljCA2BMcTg8UbV/TKl
 Ttmo78h5lQVBqoyJwCCMQYsYw2glBkPyeSgmNWswp4v3hoiVOJjGACAJ6hox8PoTPtGN0Mjy2OV
 x1Kg=
X-Google-Smtp-Source: AGHT+IFJxPcKB78NK70mO+lik1+AeCQcnFT/Co9fEvN3Z5UXS0ES/VyBk8MzlFKrx6zbhTZuRDqW1g==
X-Received: by 2002:a17:907:c7d8:b0:a8d:7b7d:8c48 with SMTP id
 a640c23a62f3a-a9029481771mr602912566b.25.1726230846106; 
 Fri, 13 Sep 2024 05:34:06 -0700 (PDT)
Received: from fedora ([185.143.144.104]) by smtp.gmail.com with ESMTPSA id
 a640c23a62f3a-a901c737f09sm290985966b.30.2024.09.13.05.34.05
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 13 Sep 2024 05:34:05 -0700 (PDT)
From: Oleksandr Nahnybida <oleksandrn@interfacemasters.com>
X-Google-Original-From: Oleksandr Nahnybida <oleksandrn@interfacemaster.com>
Date: Fri, 13 Sep 2024 15:34:03 +0300
To: reshma.pattan@intel.com, stephen@networkplumber.org
Cc: dev@dpdk.org
Subject: [PATCH v2 1/2] pcapng: fix handling of chained mbufs
Message-ID: <rf7wzd6ytwereegdzzfduo46suisj5azxsfgvc3r5ufip6iwqt@bhidb2bsahmy>
References: <7yrjcy7sk4nexcqynikybhjvpxlhhmlwvubngwqvib5o752sys@644loude6vbd>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <7yrjcy7sk4nexcqynikybhjvpxlhhmlwvubngwqvib5o752sys@644loude6vbd>
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>
Reply-To: 7yrjcy7sk4nexcqynikybhjvpxlhhmlwvubngwqvib5o752sys@644loude6vbd
Errors-To: dev-bounces@dpdk.org

The pcapng generates corrupted files when dealing with chained mbufs.
This issue arises because in rte_pcapng_copy the length of the EPB block
is incorrectly calculated using the data_len of the first mbuf instead
of the pkt_len, despite that rte_pcapng_write_packets correctly writing
the mbuf chain to disk.

This fix ensures that the block length is calculated based on the pkt_len,
aligning it with the actual data written to disk.

Signed-off-by: Oleksandr Nahnybida <oleksandrn@interfacemasters.com>
---
v2 - fixed typo in signoff email

 lib/pcapng/rte_pcapng.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 7254defce7..e5326c1d38 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -475,7 +475,7 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
 		const char *comment)
 {
 	struct pcapng_enhance_packet_block *epb;
-	uint32_t orig_len, data_len, padding, flags;
+	uint32_t orig_len, pkt_len, padding, flags;
 	struct pcapng_option *opt;
 	uint64_t timestamp;
 	uint16_t optlen;
@@ -516,8 +516,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
 		    (md->ol_flags & RTE_MBUF_F_RX_RSS_HASH));

 	/* pad the packet to 32 bit boundary */
-	data_len = rte_pktmbuf_data_len(mc);
-	padding = RTE_ALIGN(data_len, sizeof(uint32_t)) - data_len;
+	pkt_len = rte_pktmbuf_pkt_len(mc);
+	padding = RTE_ALIGN(pkt_len, sizeof(uint32_t)) - pkt_len;
 	if (padding > 0) {
 		void *tail = rte_pktmbuf_append(mc, padding);

@@ -584,7 +584,7 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
 		goto fail;

 	epb->block_type = PCAPNG_ENHANCED_PACKET_BLOCK;
-	epb->block_length = rte_pktmbuf_data_len(mc);
+	epb->block_length = rte_pktmbuf_pkt_len(mc);

 	/* Interface index is filled in later during write */
 	mc->port = port_id;
@@ -593,7 +593,7 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
 	timestamp = rte_get_tsc_cycles();
 	epb->timestamp_hi = timestamp >> 32;
 	epb->timestamp_lo = (uint32_t)timestamp;
-	epb->capture_length = data_len;
+	epb->capture_length = pkt_len;
 	epb->original_length = orig_len;

 	/* set trailer of block length */
@@ -623,7 +623,7 @@ rte_pcapng_write_packets(rte_pcapng_t *self,
 		/* sanity check that is really a pcapng mbuf */
 		epb = rte_pktmbuf_mtod(m, struct pcapng_enhance_packet_block *);
 		if (unlikely(epb->block_type != PCAPNG_ENHANCED_PACKET_BLOCK ||
-			     epb->block_length != rte_pktmbuf_data_len(m))) {
+			     epb->block_length != rte_pktmbuf_pkt_len(m))) {
 			rte_errno = EINVAL;
 			return -1;
 		}
--
2.46.0