From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6EFF84597C; Fri, 13 Sep 2024 14:19:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39E8B4025E; Fri, 13 Sep 2024 14:19:24 +0200 (CEST) Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by mails.dpdk.org (Postfix) with ESMTP id 8BB2B4003C for ; Fri, 13 Sep 2024 14:19:22 +0200 (CEST) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c260b19f71so2373015a12.1 for ; Fri, 13 Sep 2024 05:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interfacemasters.com; s=google; t=1726229962; x=1726834762; darn=dpdk.org; h=content-disposition:mime-version:message-id:subject:cc:to:date:from :from:to:cc:subject:date:message-id:reply-to; bh=otFWMIfeIXqkm6+HMMlIMAsCXeToemW0DCQYopQpLV4=; b=YQoA/Q6W9PaG6zkGK3qbYGPtGKwqBRxCYi4MOWXoRPOvSL3KUm5O1faSJD9GAPlFFO H3W447Y+//gFZ3ksdaz7YIymlp3Wromdt7dOmNwQ3sX8KltcAcJtQ95RAiSNXJwcz+t6 K395qT/3a3x+tgDqFvv5VJC7lDKW5LC5mBgiY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726229962; x=1726834762; h=content-disposition:mime-version:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=otFWMIfeIXqkm6+HMMlIMAsCXeToemW0DCQYopQpLV4=; b=cmdMZ8pnpAnfdDhv/DhHy1JgnIE2EEh19ObFDl77LzYknkesG6q3joZS20KHtd/DEu ys+WIOdoerZKO8d9uuzXpR0AO7cngIluMrtqrvSBJdlKZc13yglDhrz8kcYXAeM0AtQV GdvQvAj07fvOvbCG8QPf2LtH6ijXMIi+1H0Rp33bcSM77ylrHZkfwhChWPxspjrUwGT+ u/k2rxAlp9HYAXaLE92V+7nah7JdzJ/HiaNKMlMQWcTOcwghZotVFmWzk5ijuSk+8STo b2ce9IE4wBtHp4rn9/MIo/H7WkE9ysMWoMbn6Iw5cXr8dhZOTxVUcCVeXUZTBjI67VTu GzYw== X-Gm-Message-State: AOJu0YyIhEf+lHgkoRC/RQ3ZKRVWRiTf18oKEdYSSdY02Xp8+ssajXsX 3kQnJZmhmjAMhmM4A710lXlWz1/ENMPv66a2boBGcFKA+lmSgioYwFPyeOGPxMSbQeZcWXUNwNG a1PI= X-Google-Smtp-Source: AGHT+IFby3SmNAP3wzhiFhnfTncul4BML6mDVjYcrRSrOE9zrUt5tDV3WkcxXkEGFqgXGGOi1QjBGA== X-Received: by 2002:a05:6402:4406:b0:5c3:d8fd:9a49 with SMTP id 4fb4d7f45d1cf-5c413e12224mr3740452a12.10.1726229961773; Fri, 13 Sep 2024 05:19:21 -0700 (PDT) Received: from fedora ([185.143.144.104]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd523casm7598599a12.58.2024.09.13.05.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 05:19:21 -0700 (PDT) From: Oleksandr Nahnybida X-Google-Original-From: Oleksandr Nahnybida Date: Fri, 13 Sep 2024 15:19:18 +0300 To: reshma.pattan@intel.com, stephen@networkplumber.org Cc: dev@dpdk.org Subject: [PATCH 1/2] pcapng: fix handling of chained mbufs Message-ID: <7yrjcy7sk4nexcqynikybhjvpxlhhmlwvubngwqvib5o752sys@644loude6vbd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 --- 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