Skip to content

Commit

Permalink
app/testpmd: fix eth packet dump for small buffers
Browse files Browse the repository at this point in the history
[ upstream commit 3e6b0d5 ]

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: af75078 ("first public release")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
  • Loading branch information
david-marchand authored and kevintraynor committed Sep 4, 2019
1 parent cba7084 commit 87a3fc7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/test-pmd/util.c
Expand Up @@ -14,7 +14,7 @@
#include "testpmd.h"

static inline void
print_ether_addr(const char *what, struct ether_addr *eth_addr)
print_ether_addr(const char *what, const struct ether_addr *eth_addr)
{
char buf[ETHER_ADDR_FMT_SIZE];
ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
Expand All @@ -26,7 +26,8 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
uint16_t nb_pkts, int is_rx)
{
struct rte_mbuf *mb;
struct ether_hdr *eth_hdr;
const struct ether_hdr *eth_hdr;
struct ether_hdr _eth_hdr;
uint16_t eth_type;
uint64_t ol_flags;
uint16_t i, packet_type;
Expand All @@ -45,7 +46,7 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
(unsigned int) nb_pkts);
for (i = 0; i < nb_pkts; i++) {
mb = pkts[i];
eth_hdr = rte_pktmbuf_mtod(mb, struct 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;
Expand Down

0 comments on commit 87a3fc7

Please sign in to comment.