Skip to content

Commit 798962c

Browse files
Forty-Bottrini
authored andcommitted
net: Add option for tracing packets
Add an option to trace all packets send/received. This can be helpful when debugging protocol issues, as the packets can then be imported into wireshark [1] and analyzed further. [1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
1 parent a56e30e commit 798962c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/net.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <asm/cache.h>
1717
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
1818
#include <env.h>
19+
#include <hexdump.h>
1920
#include <log.h>
2021
#include <time.h>
2122
#include <linux/if_ether.h>
@@ -29,6 +30,7 @@ struct udevice;
2930
#define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */
3031
#define DEBUG_NET_PKT 0 /* Packets on info on the network at large */
3132
#define DEBUG_INT_STATE 0 /* Internal network state changes */
33+
#define DEBUG_NET_PKT_TRACE 0 /* Trace all packet data */
3234

3335
/*
3436
* The number of receive packet buffers, and the required packet buffer
@@ -640,6 +642,8 @@ uchar * net_get_async_tx_pkt_buf(void);
640642
/* Transmit a packet */
641643
static inline void net_send_packet(uchar *pkt, int len)
642644
{
645+
if (DEBUG_NET_PKT_TRACE)
646+
print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len);
643647
/* Currently no way to return errors from eth_send() */
644648
(void) eth_send(pkt, len);
645649
}

net/net.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,9 @@ void net_process_received_packet(uchar *in_packet, int len)
12011201
ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
12021202

12031203
debug_cond(DEBUG_NET_PKT, "packet received\n");
1204+
if (DEBUG_NET_PKT_TRACE)
1205+
print_hex_dump_bytes("rx: ", DUMP_PREFIX_OFFSET, in_packet,
1206+
len);
12041207

12051208
#if defined(CONFIG_CMD_PCAP)
12061209
pcap_post(in_packet, len, false);

0 commit comments

Comments
 (0)