From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id EEB01A046B
	for <public@inbox.dpdk.org>; Wed, 24 Jul 2019 12:59:44 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 266471C1AC;
	Wed, 24 Jul 2019 12:59:43 +0200 (CEST)
Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28])
 by dpdk.org (Postfix) with ESMTP id 612861C11B;
 Wed, 24 Jul 2019 12:59:41 +0200 (CEST)
Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com
 [10.5.11.16])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by mx1.redhat.com (Postfix) with ESMTPS id B5FB6C0A4F66;
 Wed, 24 Jul 2019 10:59:40 +0000 (UTC)
Received: from dmarchan.remote.csb (ovpn-204-235.brq.redhat.com
 [10.40.204.235])
 by smtp.corp.redhat.com (Postfix) with ESMTP id 3DAC65C225;
 Wed, 24 Jul 2019 10:59:37 +0000 (UTC)
From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: olivier.matz@6wind.com, stable@dpdk.org, Wenzhuo Lu <wenzhuo.lu@intel.com>,
 Jingjing Wu <jingjing.wu@intel.com>,
 Bernard Iremonger <bernard.iremonger@intel.com>
Date: Wed, 24 Jul 2019 12:58:56 +0200
Message-Id: <1563965936-1098-1-git-send-email-david.marchand@redhat.com>
X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16
 (mx1.redhat.com [10.5.110.32]); Wed, 24 Jul 2019 10:59:40 +0000 (UTC)
Subject: [dpdk-dev] [PATCH] app/testpmd: fix eth packet dump for small
	buffers
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
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
Sender: "dev" <dev-bounces@dpdk.org>

In the rather unlikely case where the first segment is too small to
contain an ethernet header, we can't go and directly dereference the
mbuf data buffer.

Using rte_pktmbuf_read is a little more expensive but this is still
acceptable for a debugging feature.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 app/test-pmd/util.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/app/test-pmd/util.c b/app/test-pmd/util.c
index a1164b7..18dfdca 100644
--- a/app/test-pmd/util.c
+++ b/app/test-pmd/util.c
@@ -14,7 +14,7 @@
 #include "testpmd.h"
 
 static inline void
-print_ether_addr(const char *what, struct rte_ether_addr *eth_addr)
+print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
 {
 	char buf[RTE_ETHER_ADDR_FMT_SIZE];
 	rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
@@ -26,7 +26,8 @@
 	      uint16_t nb_pkts, int is_rx)
 {
 	struct rte_mbuf  *mb;
-	struct rte_ether_hdr *eth_hdr;
+	const struct rte_ether_hdr *eth_hdr;
+	struct rte_ether_hdr _eth_hdr;
 	uint16_t eth_type;
 	uint64_t ol_flags;
 	uint16_t i, packet_type;
@@ -46,7 +47,7 @@
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
 		mb = pkts[i];
-		eth_hdr = rte_pktmbuf_mtod(mb, struct rte_ether_hdr *);
+		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
 		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
-- 
1.8.3.1