DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Tianli Lai <laitianli@tom.com>
Subject: [PATCH] app/dumpcap: fix handling of jumbo frames
Date: Thu,  3 Oct 2024 15:09:03 -0700	[thread overview]
Message-ID: <20241003221051.34924-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20240301104129.3725-1-laitianli@tom.com>

If dumpcap (in legacy pcap mode) tried to handle a large segmented
frame it would core dump because rte_pktmbuf_read() would return NULL.
Fix by using same logic as in pcap PMD.

Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application")
Reported-by: Tianli Lai <laitianli@tom.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---

 app/dumpcap/main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 6feb8f5672..fcfaa19951 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -902,7 +902,7 @@ static ssize_t
 pcap_write_packets(pcap_dumper_t *dumper,
 		   struct rte_mbuf *pkts[], uint16_t n)
 {
-	uint8_t temp_data[RTE_MBUF_DEFAULT_BUF_SIZE];
+	uint8_t temp_data[RTE_ETHER_MAX_JUMBO_FRAME_LEN];
 	struct pcap_pkthdr header;
 	uint16_t i;
 	size_t total = 0;
@@ -911,14 +911,19 @@ pcap_write_packets(pcap_dumper_t *dumper,
 
 	for (i = 0; i < n; i++) {
 		struct rte_mbuf *m = pkts[i];
+		size_t len, caplen;
 
-		header.len = rte_pktmbuf_pkt_len(m);
-		header.caplen = RTE_MIN(header.len, sizeof(temp_data));
+		len = caplen = rte_pktmbuf_pkt_len(m);
+		if (unlikely(!rte_pktmbuf_is_contiguous(m) && len > sizeof(temp_data)))
+			caplen = sizeof(temp_data);
+
+		header.len = len;
+		header.caplen = caplen;
 
 		pcap_dump((u_char *)dumper, &header,
-			  rte_pktmbuf_read(m, 0, header.caplen, temp_data));
+			  rte_pktmbuf_read(m, 0, caplen, temp_data));
 
-		total += sizeof(header) + header.len;
+		total += sizeof(header) + caplen;
 	}
 
 	return total;
-- 
2.45.2


  parent reply	other threads:[~2024-10-03 22:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 10:41 [PATCH] app/dumpcap:fix coredump problem because pcap_dump 3th argument is null Tianli Lai
2024-03-01  3:36 ` Stephen Hemminger
2024-10-03 22:09 ` Stephen Hemminger [this message]
2024-10-11 12:46   ` [PATCH] app/dumpcap: fix handling of jumbo frames David Marchand
2024-10-11 14:30 ` [PATCH] app/dumpcap:fix coredump problem because pcap_dump 3th argument is null Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241003221051.34924-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=laitianli@tom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).