[1/6] app/dumpcap: add additional dump info

Message ID 20230102162441.6205-1-koncept1@gmail.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series [1/6] app/dumpcap: add additional dump info |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Ben Magistro Jan. 2, 2023, 4:24 p.m. UTC
  This change increases the information returned when listing interfaces
to include link state and promiscuous mode. Additionally, the
information is formatted to be easily consumed by a machine or a person.

This change is/was utilized while troubleshooting and developing the
subsequent patches to address the issues identified on the mailing
list [1].

[1] http://mails.dpdk.org/archives/dev/2022-December/258317.html

Signed-off-by: Ben Magistro <koncept1@gmail.com>
---
 app/dumpcap/main.c           | 27 ++++++++++++++++++++++++++-
 doc/guides/tools/dumpcap.rst |  9 ++++++---
 2 files changed, 32 insertions(+), 4 deletions(-)
  

Comments

Stephen Hemminger Jan. 2, 2023, 4:57 p.m. UTC | #1
On Mon,  2 Jan 2023 16:24:36 +0000
Ben Magistro <koncept1@gmail.com> wrote:

> This change increases the information returned when listing interfaces
> to include link state and promiscuous mode. Additionally, the
> information is formatted to be easily consumed by a machine or a person.
> 
> This change is/was utilized while troubleshooting and developing the
> subsequent patches to address the issues identified on the mailing
> list [1].
> 
> [1] http://mails.dpdk.org/archives/dev/2022-December/258317.html
> 
> Signed-off-by: Ben Magistro <koncept1@gmail.com>

The output format was designed to be the same as dumpcap,
if you want more info use procinfo.


$ dumpcap -D
1. enp2s0
2. any
3. lo (Loopback)
4. wlo1
5. bluetooth0
6. bluetooth-monitor
7. nflog
8. nfqueue
9. dbus-system
10. dbus-session

Testing a fix now for multiple interfaces.
  
Stephen Hemminger Jan. 4, 2023, 2:58 a.m. UTC | #2
On Mon,  2 Jan 2023 16:24:36 +0000
Ben Magistro <koncept1@gmail.com> wrote:

> This change increases the information returned when listing interfaces
> to include link state and promiscuous mode. Additionally, the
> information is formatted to be easily consumed by a machine or a person.
> 
> This change is/was utilized while troubleshooting and developing the
> subsequent patches to address the issues identified on the mailing
> list [1].
> 
> [1] http://mails.dpdk.org/archives/dev/2022-December/258317.html
> 
> Signed-off-by: Ben Magistro <koncept1@gmail.com>


I prefer to keep the similar output format to wireshark dumpcap

I.e:

$ dumpcap -D
1. enp2s0
2. any
3. lo (Loopback)
4. wlo1
5. bluetooth0
6. bluetooth-monitor
7. nflog
8. nfqueue
9. dbus-system
10. dbus-session

With testpmd running with three interfaces

# dpdk-dumpcap -D
0. net_null0
1. net_null1
2. net_null2
  

Patch

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 2eb8414efa..b9096f050c 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -266,11 +266,36 @@  static void dump_interfaces(void)
 {
 	char name[RTE_ETH_NAME_MAX_LEN];
 	uint16_t p;
+	struct rte_eth_link link_info;
+	char link_state[8];
+	char promisc_mode[9];
 
+	printf("%-4s\t%-40s\t%-8s\t%-12s\n",
+		"Port", "Name", "Link", "Promiscuous");
 	RTE_ETH_FOREACH_DEV(p) {
 		if (rte_eth_dev_get_name_by_port(p, name) < 0)
 			continue;
-		printf("%u. %s\n", p, name);
+
+		if (rte_eth_link_get_nowait(p, &link_info) < 0) {
+			rte_strscpy(link_state, "Unknown", sizeof(link_state));
+		}
+		else if (link_info.link_status == RTE_ETH_LINK_UP) {
+			rte_strscpy(link_state, "Up", sizeof(link_state));
+		}
+		else {
+			rte_strscpy(link_state, "Down", sizeof(link_state));
+		}
+
+		// not checking error here; should only error if given an invalid port id
+		if (rte_eth_promiscuous_get(p) == 1) {
+			rte_strscpy(promisc_mode, "Enabled", sizeof(promisc_mode));
+		}
+		else {
+			rte_strscpy(promisc_mode, "Disabled", sizeof(promisc_mode));
+		}
+
+		printf("%-4u\t%-40s\t%-8s\t%-12s\n",
+			p, name, link_state, promisc_mode);
 	}
 
 	exit(0);
diff --git a/doc/guides/tools/dumpcap.rst b/doc/guides/tools/dumpcap.rst
index d8a137b1cd..0f89e6c5ca 100644
--- a/doc/guides/tools/dumpcap.rst
+++ b/doc/guides/tools/dumpcap.rst
@@ -39,7 +39,7 @@  If ``-w`` option is specified, then that file is used.
 Running the Application
 -----------------------
 
-To list interfaces available for capture, use ``--list-interfaces``.
+To list interfaces available for capture, use ``-D`` or ``--list-interfaces``.
 
 To filter packets in style of *tshark*, use the ``-f`` flag.
 
@@ -52,8 +52,11 @@  Example
 .. code-block:: console
 
    # <build_dir>/app/dpdk-dumpcap --list-interfaces
-   0. 000:00:03.0
-   1. 000:00:03.1
+   Port    Name                                        Link        Promiscuous
+   0       0000:00:03.0                                Up          Enabled
+   1       0000:00:03.1                                Up          Disabled
+   2       0000:00:03.2                                Down        Disabled
+   3       0000:00:03.3                                Down        Disabled
 
    # <build_dir>/app/dpdk-dumpcap -i 0000:00:03.0 -c 6 -w /tmp/sample.pcapng
    Packets captured: 6