From patchwork Thu Jul 18 18:43:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 1133814 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L06sw6+F"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45qNMK1zRPz9s4Y for ; Fri, 19 Jul 2019 04:43:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5A123C22004; Thu, 18 Jul 2019 18:43:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 66A1BC21EBB; Thu, 18 Jul 2019 18:43:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF6B3C21E8A; Thu, 18 Jul 2019 18:43:45 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id A4336C21EBB for ; Thu, 18 Jul 2019 18:43:45 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id n9so29847679wru.0 for ; Thu, 18 Jul 2019 11:43:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AR3n+aduSsfk0uT2WhJOCfz43YEUUdZSsZx+lrVkCZE=; b=L06sw6+FJSI+SUWPsY4v9BuSgEsQ2I8/+BknaDAwIoxl0vB175/QDUWcmSwOoTbgHz XlTfLfNt3D+N3r5dbntmnblENRn3eUPaPROslMLpDP25fa3pRZdDHRxnrDYnqqjkr53v Z2bfbpp0gER7N7HDyBtXwvPOcMf6dgvwb+1EaRYrnw/D71Js+cxNC0Mdt/chM0LH92Ts o/zWi4SBbOljmPyUSxY5mLaEYW2NJLm2NVaDF9N81p7bi1d/ZvHkjqS1gRNk79PXWEyY s/0nyXrMNq/s5kHLutaaeXq4hELPIDFrA88eLpMRWWBd2xazBj+wJQR6lbRlKNEtqY3t gxzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AR3n+aduSsfk0uT2WhJOCfz43YEUUdZSsZx+lrVkCZE=; b=uWqw0zjVm/+BTycJMa2pUh8CeFeVP8+bMDUPWVCqxoXt6DaedOH7LGieTJYMm2kaaM KvsA+C5/BNjOtC85G59ufwCKvCfImEF57qOHQp2y9H2RjfG2dr4kS2u6tOqL1JNJYpqV bGWWi/2T1pIhc1gsivQUmahna3hDTXKPgTcmE/DfOh2C5nPhsL+dokbADSnAuMO+Zh/M QcI8A7gKAEWmkI9s+a9ukwCU0X6DwPDAe0yh2qd6OSEeWQdYL5cwEHlHqv427LOcirEz bqzYPdMoEGRpaZ9/ag+dveOFst749DjXvlewfpJwPXjAPY/Ro8731ISvqE++fyZAggFj KOqQ== X-Gm-Message-State: APjAAAVELsGxQUrebG5rsww7oMNWWShrRSOSs3ecWjHY6yJkc6wMJ0Yg ZAdtULO0mx5IwxfO5Yd56GEqe5GggWs= X-Google-Smtp-Source: APXvYqzF13WtTs4Va0ysWETYkcPAZjuPsV9J1RRxGnDN8NnMaJZFBw0vsmV3GnhpSq6N2Kt5OZY98A== X-Received: by 2002:a5d:5510:: with SMTP id b16mr14841701wrv.267.1563475424978; Thu, 18 Jul 2019 11:43:44 -0700 (PDT) Received: from localhost.localdomain ([141.226.31.91]) by smtp.gmail.com with ESMTPSA id h14sm27550435wrs.66.2019.07.18.11.43.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 11:43:44 -0700 (PDT) From: Ramon Fried To: u-boot@lists.denx.de Date: Thu, 18 Jul 2019 21:43:30 +0300 Message-Id: <20190718184333.27927-1-rfried.dev@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Cc: Eugeniu Rosca , Boris Brezillon , Joe Hershberger , Heinrich Schuchardt , Michal Simek , Miquel Raynal , Stefan Roese Subject: [U-Boot] [PATCH v4 1/3] net: introduce packet capture support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for capturing ethernet packets and storing them in memory in PCAP(2.4) format, later to be analyzed by any PCAP viewer software (IE. Wireshark) This feature greatly assist debugging network issues such as detecting dropped packets, packet corruption etc. Signed-off-by: Ramon Fried Reviewed-by: Alex Marginean Tested-by: Alex Marginean Acked-by: Joe Hershberger --- Changes in v4: * Move implementation to pcap.c/pcap.h * Display error message when memory is exhausted. * Populate $pcapsize environment variable with actual capture size. * move outgoing pcap_post to eth_send() Changes in v3: * Change to implementation to command based. * Added counters for incoming/outgoing packets. * Support clearing the capture for multiple captures. * Added documentation (separate patch). Changes in v2: Fix type assignmnet to header.ts_sec cmd/Kconfig | 7 ++ cmd/Makefile | 1 + cmd/pcap.c | 71 +++++++++++++++++++++ include/net/pcap.h | 55 ++++++++++++++++ net/Makefile | 1 + net/eth-uclass.c | 7 ++ net/eth_legacy.c | 12 +++- net/net.c | 11 ++++ net/pcap.c | 156 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 cmd/pcap.c create mode 100644 include/net/pcap.h create mode 100644 net/pcap.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 67284d8a5f..86aa5d8c00 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1263,6 +1263,13 @@ config BOOTP_NTPSERVER bool "Request & store 'ntpserverip' from BOOTP/DHCP server" depends on CMD_BOOTP +config CMD_PCAP + bool "pcap capture" + help + Selecting this will allow capturing all Ethernet packets and store + them in physical memory in a PCAP formated file, + later to be analyzed by PCAP reader application (IE. WireShark). + config BOOTP_PXE bool "Send PXE client arch to BOOTP/DHCP server" default y diff --git a/cmd/Makefile b/cmd/Makefile index 0aa3741453..61d5bc885a 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -102,6 +102,7 @@ obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o obj-$(CONFIG_CMD_ONENAND) += onenand.o obj-$(CONFIG_CMD_OSD) += osd.o obj-$(CONFIG_CMD_PART) += part.o +obj-$(CONFIG_CMD_PCAP) += pcap.o ifdef CONFIG_PCI obj-$(CONFIG_CMD_PCI) += pci.o endif diff --git a/cmd/pcap.c b/cmd/pcap.c new file mode 100644 index 0000000000..980603f7bd --- /dev/null +++ b/cmd/pcap.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2019 + * Ramon Fried + */ + +#include +#include +#include +#include + +static int do_pcap_init(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + phys_addr_t addr; + unsigned int size; + + if (argc != 3) + return CMD_RET_USAGE; + + addr = simple_strtoul(argv[1], NULL, 16); + size = simple_strtoul(argv[2], NULL, 10); + + return pcap_init(addr, size) ? CMD_RET_FAILURE : CMD_RET_SUCCESS; +} + +static int do_pcap_start(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return pcap_start_stop(true) ? CMD_RET_FAILURE : CMD_RET_SUCCESS; +} + +static int do_pcap_stop(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return pcap_start_stop(false) ? CMD_RET_FAILURE : CMD_RET_SUCCESS; +} + +static int do_pcap_status(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return pcap_print_status() ? CMD_RET_FAILURE : CMD_RET_SUCCESS; +} + +static int do_pcap_clear(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return pcap_clear() ? CMD_RET_FAILURE : CMD_RET_SUCCESS; +} + +static char pcap_help_text[] = + "- network packet capture\n\n" + "pcap\n" + "pcap init\t\t\t \n" + "pcap start\t\t\tstart capture\n" + "pcap stop\t\t\tstop capture\n" + "pcap status\t\t\tprint status\n" + "pcap clear\t\t\tclear capture buffer\n" + "\n" + "With:\n" + "\t: user address to which pcap will be stored (hexedcimal)\n" + "\t: Maximum size of pcap file (decimal)\n" + "\n"; + +U_BOOT_CMD_WITH_SUBCMDS(pcap, "pcap", pcap_help_text, + U_BOOT_SUBCMD_MKENT(init, 3, 0, do_pcap_init), + U_BOOT_SUBCMD_MKENT(start, 1, 0, do_pcap_start), + U_BOOT_SUBCMD_MKENT(stop, 1, 0, do_pcap_stop), + U_BOOT_SUBCMD_MKENT(status, 1, 0, do_pcap_status), + U_BOOT_SUBCMD_MKENT(clear, 1, 0, do_pcap_clear), +); diff --git a/include/net/pcap.h b/include/net/pcap.h new file mode 100644 index 0000000000..512ba982f1 --- /dev/null +++ b/include/net/pcap.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2019 + * Ramon Fried + */ + +/** + * pcap_init() - Initialize PCAP memory buffer + * + * @paddr physicaly memory address to store buffer + * @size maximum size of capture file in memory + * + * @return 0 on success, -ERROR on error + */ +int pcap_init(phys_addr_t paddr, unsigned long size); + +/** + * pcap_start_stop() - start / stop pcap capture + * + * @start if true, start capture if false stop capture + * + * @return 0 on success, -ERROR on error + */ +int pcap_start_stop(bool start); + +/** + * pcap_clear() - clear pcap capture buffer and statistics + * + * @return 0 on success, -ERROR on error + */ +int pcap_clear(void); + +/** + * pcap_print_status() - print status of pcap capture + * + * @return 0 on success, -ERROR on error + */ +int pcap_print_status(void); + +/** + * pcap_active() - check if pcap is enabled + * + * @return TRUE if active, FALSE if not. + */ +bool pcap_active(void); + +/** + * pcap_post() - Post a packet to PCAP file + * + * @packet: packet to post + * @len: packet length in bytes + * @outgoing packet direction (outgoing/incoming) + * @return 0 on success, -ERROR on error + */ +int pcap_post(const void *packet, size_t len, bool outgoing); diff --git a/net/Makefile b/net/Makefile index 6251ff3991..b975badeda 100644 --- a/net/Makefile +++ b/net/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_CMD_LINK_LOCAL) += link_local.o obj-$(CONFIG_NET) += net.o obj-$(CONFIG_CMD_NFS) += nfs.o obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PCAP) += pcap.o obj-$(CONFIG_CMD_RARP) += rarp.o obj-$(CONFIG_CMD_SNTP) += sntp.o obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 031d558625..4252a02659 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -9,6 +9,9 @@ #include #include #include +#if defined(CONFIG_CMD_PCAP) +#include +#endif #include #include #include "eth_internal.h" @@ -344,6 +347,10 @@ int eth_send(void *packet, int length) /* We cannot completely return the error at present */ debug("%s: send() returned error %d\n", __func__, ret); } +#if defined(CONFIG_CMD_PCAP) + if (ret >= 0) + pcap_post(packet, length, true); +#endif return ret; } diff --git a/net/eth_legacy.c b/net/eth_legacy.c index e250a430f3..0705b7ccea 100644 --- a/net/eth_legacy.c +++ b/net/eth_legacy.c @@ -9,6 +9,9 @@ #include #include #include +#if defined(CONFIG_CMD_PCAP) +#include +#endif #include #include #include "eth_internal.h" @@ -352,10 +355,17 @@ int eth_is_active(struct eth_device *dev) int eth_send(void *packet, int length) { + int ret; + if (!eth_current) return -ENODEV; - return eth_current->send(eth_current, packet, length); + ret = eth_current->send(eth_current, packet, length); +#if defined(CONFIG_CMD_PCAP) + if (ret >= 0) + pcap_post(packet, lengeth, true); +#endif + return ret; } int eth_rx(void) diff --git a/net/net.c b/net/net.c index 58b0417cbe..722fa7a705 100644 --- a/net/net.c +++ b/net/net.c @@ -95,6 +95,9 @@ #include #include #include +#if defined(CONFIG_CMD_PCAP) +#include +#endif #if defined(CONFIG_LED_STATUS) #include #include @@ -671,6 +674,11 @@ done: net_set_icmp_handler(NULL); #endif net_set_state(prev_net_state); + +#if defined(CONFIG_CMD_PCAP) + if (pcap_active()) + pcap_print_status(); +#endif return ret; } @@ -1083,6 +1091,9 @@ void net_process_received_packet(uchar *in_packet, int len) debug_cond(DEBUG_NET_PKT, "packet received\n"); +#if defined(CONFIG_CMD_PCAP) + pcap_post(in_packet, len, false); +#endif net_rx_packet = in_packet; net_rx_packet_len = len; et = (struct ethernet_hdr *)in_packet; diff --git a/net/pcap.c b/net/pcap.c new file mode 100644 index 0000000000..4036d8a3fa --- /dev/null +++ b/net/pcap.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2019 Ramon Fried + */ + +#include +#include +#include +#include +#include + +#define LINKTYPE_ETHERNET 1 + +static bool initialized; +static bool running; +static bool buffer_full; +static void *buf; +static unsigned int max_size; +static unsigned int pos; + +static unsigned long incoming_count; +static unsigned long outgoing_count; + +struct pcap_header { + u32 magic; + u16 version_major; + u16 version_minor; + s32 thiszone; + u32 sigfigs; + u32 snaplen; + u32 network; +}; + +struct pcap_packet_header { + u32 ts_sec; + u32 ts_usec; + u32 incl_len; + u32 orig_len; +}; + +static struct pcap_header file_header = { + .magic = 0xa1b2c3d4, + .version_major = 2, + .version_minor = 4, + .snaplen = 65535, + .network = LINKTYPE_ETHERNET, +}; + +int pcap_init(phys_addr_t paddr, unsigned long size) +{ + buf = map_physmem(paddr, size, 0); + if (!buf) { + printf("Failed mapping PCAP memory\n"); + return -ENOMEM; + } + + printf("PCAP capture initialized: addr: 0x%lx max length: %lu\n", + (unsigned long)buf, size); + + memcpy(buf, &file_header, sizeof(file_header)); + pos = sizeof(file_header); + max_size = size; + initialized = true; + running = false; + buffer_full = false; + incoming_count = 0; + outgoing_count = 0; + return 0; +} + +int pcap_start_stop(bool start) +{ + if (!initialized) { + printf("error: pcap was not initialized\n"); + return -ENODEV; + } + + running = start; + + return 0; +} + +int pcap_clear(void) +{ + if (!initialized) { + printf("error: pcap was not initialized\n"); + return -ENODEV; + } + + pos = sizeof(file_header); + incoming_count = 0; + outgoing_count = 0; + buffer_full = false; + + printf("pcap capture cleared\n"); + return 0; +} + +int pcap_post(const void *packet, size_t len, bool outgoing) +{ + struct pcap_packet_header header; + u64 cur_time = timer_get_us(); + + if (!initialized || !running || !buf) + return -ENODEV; + + if (buffer_full) + return -ENOMEM; + + if ((pos + len + sizeof(header)) >= max_size) { + buffer_full = true; + printf("\n!!! Buffer is full, consider increasing buffer size !!!\n"); + return -ENOMEM; + } + + header.ts_sec = cur_time / 1000000; + header.ts_usec = cur_time % 1000000; + header.incl_len = len; + header.orig_len = len; + + memcpy(buf + pos, &header, sizeof(header)); + pos += sizeof(header); + memcpy(buf + pos, packet, len); + pos += len; + + if (outgoing) + outgoing_count++; + else + incoming_count++; + + env_set_hex("pcapsize", pos); + + return 0; +} + +int pcap_print_status(void) +{ + if (!initialized) { + printf("pcap was not initialized\n"); + return -ENODEV; + } + printf("PCAP status:\n"); + printf("\tInitialized addr: 0x%lx\tmax length: %u\n", + (unsigned long)buf, max_size); + printf("\tStatus: %s.\t file size: %u\n", running ? "Active" : "Idle", + pos); + printf("\tIncoming packets: %lu Outgoing packets: %lu\n", + incoming_count, outgoing_count); + + return 0; +} + +bool pcap_active(void) +{ + return running; +} From patchwork Thu Jul 18 18:43:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 1133815 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DG6E0m1I"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45qNN76g8zz9s7T for ; Fri, 19 Jul 2019 04:44:39 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A0137C21F32; Thu, 18 Jul 2019 18:44:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, LOTS_OF_MONEY, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BFBD2C22016; Thu, 18 Jul 2019 18:43:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E42AFC21EBB; Thu, 18 Jul 2019 18:43:46 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id A6EC1C21E8A for ; Thu, 18 Jul 2019 18:43:46 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id g17so29793620wrr.5 for ; Thu, 18 Jul 2019 11:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nMUhPLPDjvr0N7OMbHwTB3mpuXmt7/CRq7c3RJEwwGQ=; b=DG6E0m1Ip7RGR5afIVMiuMeWtqMlksUtQ9jZ+4Hi1zH3s9Q/LP2naaNyf+DU1qrgZE bW7XapiSDr50I//kNLEpD7WHSRdqmA8g6htM+bDqSN5BI8xlsX0vT6ijeoO+YZrC1ijs jT421UQdF8cUzVdVQJKXDKy/9s6/KvKFDyCf25WUlHT2AcQBBc2ywNq3eS02GXaW7c0i 9c3lqDAvcsAD3Y494wRoakOjs/hN82ZH38xxlMefSGH/GHII8gGQaisUUyGyVzb1bMnx B6dYuinO33AH4f9S9UV3i7zl86GHtsqRZr3ynIpDurQpZmCTfTURqiixZv5tFJKfGis3 mKUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nMUhPLPDjvr0N7OMbHwTB3mpuXmt7/CRq7c3RJEwwGQ=; b=nkIRFWihqabAEES7T2xNb5D8FITeNdgKrQ5VFZa36zxmpryreC1tEl6Uyif/npWdxQ mXhX98/Rteav7PDcde6svnGFWu4UfyzhdrnLQ8NWVm36yBmsk5ZwPFDw6p7BAWwm6KcR WgmUg+OAkiRKX7NZbvm5bRwHxbKgh3wkt5f4vZtVooVrmbmRjpWVih7DPWc/lfkaD1hm IrVKcP6mJ9GYIREpIk49Iob6+kamcLc4WS+HOm9sqriMY+iXx8r0kO8aLgx1vWAOMWSv zpXUcnXHf/GezRIBkIU8AthAa6NdDjQ62GCpTFO1G9zPQ85bNxURUga8nx/+AZIXLKKT /PZA== X-Gm-Message-State: APjAAAUkdYnglA3ZFNw+eHU7fEcZzIui+7nkk676kZRqmu/blzOkUPgN y25OZkCEpoTceRbzPjHkMPyP+qbr1B0= X-Google-Smtp-Source: APXvYqzHZIytjBr8Th/Ax/WN7qSs9R51bX4Y0YSvhiUSnElZnff+i28vgKDbqFX0LFtuPAybA6CW7g== X-Received: by 2002:adf:e552:: with SMTP id z18mr52578757wrm.45.1563475426145; Thu, 18 Jul 2019 11:43:46 -0700 (PDT) Received: from localhost.localdomain ([141.226.31.91]) by smtp.gmail.com with ESMTPSA id h14sm27550435wrs.66.2019.07.18.11.43.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 11:43:45 -0700 (PDT) From: Ramon Fried To: u-boot@lists.denx.de Date: Thu, 18 Jul 2019 21:43:31 +0300 Message-Id: <20190718184333.27927-2-rfried.dev@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718184333.27927-1-rfried.dev@gmail.com> References: <20190718184333.27927-1-rfried.dev@gmail.com> MIME-Version: 1.0 Subject: [U-Boot] [PATCH v4 2/3] doc: pcap: add pcap cmd documentation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add documentation for new "pcap" command. Signed-off-by: Ramon Fried Acked-by: Joe Hershberger --- Changes in v4: * Document the new $pcapsize environment variable. * update doc regarding error message when there's not enough memory left. Changes in v3: None Changes in v2: None doc/README.pcap | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 doc/README.pcap diff --git a/doc/README.pcap b/doc/README.pcap new file mode 100644 index 0000000000..97b3e55fd8 --- /dev/null +++ b/doc/README.pcap @@ -0,0 +1,62 @@ +PCAP: + +U-boot supports live Ethernet packet capture in PCAP(2.4) format. +This is enabled by CONFIG_CMD_PCAP. + +The capture is stored on physical memory, and should be copied to +a machine capable of parsing and displaying PCAP files (IE. wireshark) +If networking works properly one can copy the capture file from physical memory +using tftpput, or save it to local storage with (sf write, mmc write, fatwrite, etc) + +the pcap capturing requires maximum buffer size. +when the buffer is full an error message will be displayed and then packets +will silently drop. +the actual capture file size is populate in the environment variable "pcapsize". + +Usage example: + +# Initialize pcap capture to physical address (0x100000) with maximum size of +# 100000 bytes. + +# Start capture +pcap start + +# Initialize network activity +env set ipaddr 10.0.2.15; env set serverip 10.0.2.2; tftp uImage64 + +# Stop capture +pcap stop + +# pcap init 0x100000 100000 +PCAP capture initialized: addr: 0xffffffff80100000 max length: 100000 + +# pcap start +# env set ipaddr 10.0.2.15; env set serverip 10.0.2.2; tftp uImage64 +eth0@10000000: PHY present at 0 +eth0@10000000: link up, 1000Mbps full-duplex (lpa: 0x7c00) +Using eth0@10000000 device +TFTP from server 10.0.2.2; our IP address is 10.0.2.15 +Filename 'uImage64'. +Load address: 0xffffffff88000000 +Loading: ################################################################# + ################################################################# + ################################################################# + ################################################################# +!!! Buffer is full, consider increasing buffer size !!! + ################################################################# + ################################################################# + ################################################################# + ################################################################# + ################################################################# + # + 18.2 MiB/s +done +Bytes transferred = 8359376 (7f8dd0 hex) +PCAP status: + Initialized addr: 0xffffffff80100000 max length: 100000 + Status: Active. file size: 99991 + Incoming packets: 66 Outgoing packets: 67 + +# pcap stop +# tftpput 0xffffffff80100000 $pcapsize 10.0.2.2:capture.pcap + From patchwork Thu Jul 18 18:43:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 1133816 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CMYzBqZA"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45qNNn63pPz9s7T for ; Fri, 19 Jul 2019 04:45:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 89910C21FB4; Thu, 18 Jul 2019 18:44:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 45595C22022; Thu, 18 Jul 2019 18:43:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 556DDC22005; Thu, 18 Jul 2019 18:43:53 +0000 (UTC) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by lists.denx.de (Postfix) with ESMTPS id DDEECC21F3F for ; Thu, 18 Jul 2019 18:43:47 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id r1so29763457wrl.7 for ; Thu, 18 Jul 2019 11:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L71eTz2WRNhqUcngVEwvIkR4FkBjIu+RPMvcw6Z8jPE=; b=CMYzBqZA30bgieyJHxPZtJAi+kbn6g1dlgh5w9I3ZT9vIJH1OFGi0nTjei/y9HmjaW DQzgi3k1mC6NJl4ZiO8FLK8iyinY5CMYhir2hseEZSHsdttM0eMcMhspY6s2uIuOw/17 nb2ChofPGSxdHFm87vqdbzDLAEc59hqOHnbQ9Apo70I00dptpNq0cjF7eNz0ORG05bFI krXKS5zDyOiBZpDOe6t8iXmegyOsDlyTWAhV4vissZ5UbZnEIT9mB4egK5Z78ST7kOfJ F/nQUBpqpxcFQ1EAVcpsz//8z01DOzvapE8Ex529+3POjYv2BKRQ/ehniDCkTHMYg1Hh vrmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L71eTz2WRNhqUcngVEwvIkR4FkBjIu+RPMvcw6Z8jPE=; b=ocOIUAk/kW4ZGc5hfY5mOOszYAGyzZFXRevTA3pm7EhUBv/J0tb6ajJFRIr8+BJaDm VZJUm4hOEV+qKf9nnRIJYexwChpnV72gWLEDUw/x+mobDcqaO6AQuzrT6ozQggUf6vmR kGrGvKdFWV/nWiXU1WjHIpyEBkEr2XVhbz6ha9GYpnKUHDNL/lDRLqHQUlzAvHZbgTT2 iBoBUjlfIvU+4sdW5X1ql01BEgso21aNaQN2tlyX8JZ1z73bwRrwmei5lCYrzu8w7EW8 cgRjOt7hjMC/2RBldjVHtO/dVra0FA/vkgEMR5NiJd8KEjzWK6PnPPInIOxgmrP55YZl SC9A== X-Gm-Message-State: APjAAAVG0HKegz4xNvgexKpwJb1IaFXNkk25Wb4CN22jwgO8iDZiJnD3 K9+gKFSn+c0hyPyMTU0b0MAPgSH2FYw= X-Google-Smtp-Source: APXvYqygR4+EFlH9qCfmklE06EhpSYMAgWS2ONrV3e5C9p/22Zc9o8EKOufPK5D2HnDAj59R7FFiDg== X-Received: by 2002:a5d:5607:: with SMTP id l7mr53935865wrv.228.1563475427494; Thu, 18 Jul 2019 11:43:47 -0700 (PDT) Received: from localhost.localdomain ([141.226.31.91]) by smtp.gmail.com with ESMTPSA id h14sm27550435wrs.66.2019.07.18.11.43.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 18 Jul 2019 11:43:47 -0700 (PDT) From: Ramon Fried To: u-boot@lists.denx.de Date: Thu, 18 Jul 2019 21:43:32 +0300 Message-Id: <20190718184333.27927-3-rfried.dev@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718184333.27927-1-rfried.dev@gmail.com> References: <20190718184333.27927-1-rfried.dev@gmail.com> MIME-Version: 1.0 Subject: [U-Boot] [PATCH v4 3/3] configs: sandbox: enable PCAP capture cmd X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Enable CONFIG_CMD_PCAP for testing PCAP capture. Signed-off-by: Ramon Fried Acked-by: Joe Hershberger --- Changes in v4: * Patch added to patchset Changes in v3: None Changes in v2: None configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 61391a7acd..1c52b9c51e 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -47,6 +47,7 @@ CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SPI=y CONFIG_CMD_USB=y CONFIG_CMD_AXI=y +CONFIG_CMD_PCAP=y CONFIG_CMD_TFTPPUT=y CONFIG_CMD_TFTPSRV=y CONFIG_CMD_RARP=y