From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B9F67A00C2; Wed, 4 Jan 2023 04:38:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8937A42D3B; Wed, 4 Jan 2023 04:38:27 +0100 (CET) Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mails.dpdk.org (Postfix) with ESMTP id 46E4C42D16 for ; Wed, 4 Jan 2023 04:38:25 +0100 (CET) Received: by mail-pj1-f50.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so33068099pjj.4 for ; Tue, 03 Jan 2023 19:38:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3I6d0eSH1K0rHR9wz2F3NPU2pmpP1RBrH2aPW013/j4=; b=PYqezmti0fAYGf1Q5zmabEbPRC0MSmCe73QqxFuTndMTmy5zPm4BXxZbkjPzUq8tkX AIFC9wBzkSF0r0x9v8c2/Wsy53xsyjNVzkS5ukTft0S/ZtSFsSi8Aspc3FHnsKg4CHj7 I1ITeWerK0XPhW/Db8EOOEt0CZ42ouY8beOJIs7ewyUhYL8eVT5CeVeZb5u3SN6lHi2j 0TLE7QO23XV37QFoCmUf8jjlyuOrIrFTR70+QV3TOPUHS5AqwzTBAtqKdx22rjJie+hg b6bu35EyNdHOziOvjrTxU0UzGar1pepKCq3ZIXDtqIt6fhrTPcIFm3JsIxHQQlYkRIlL Dknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3I6d0eSH1K0rHR9wz2F3NPU2pmpP1RBrH2aPW013/j4=; b=DCvqM97MmExOJ6ND8Mco/qvaYqQC+B3znYfIxtqhJSto0i5ngbY9kM/0cRGEi8uuhG eujNNjT5GYIvnrHMney+OzQlOlWtCt6IUennr/MLYpKe4pXdWLzeWSAwwC7D6ARSvLfZ +bwIM8AjuCsUOJGJO3cMWQJOuVZGDG6ghMGpdF+kTH578dXsK5mbaGWND3hzMlVlQZbz PO4iZBFUc5+UROCF5vSAHPgXh7sLlrx2AeffnyxoPjQHolGQ6RDMkMGdQEKbgP+rdhKl GTQM/ivQHTy2ItpQD+xJO7XlGugyoGwlYwAJDrSLWTUBRveettmlcqJtLtxTBnFggXL9 XcyQ== X-Gm-Message-State: AFqh2krsyMaJ4AW/R/emxiveugpRSsSnVkRlpsXncBtKTr5SdMzaXerS rPj24BR6PhusxnzkvJTN+nbryULgYmD746JvsjU= X-Google-Smtp-Source: AMrXdXsr/CbgZk7UKQbR6MxPRPHoYuOmU1JVMBY6/XDTbOzIU0hRg+qBK/p4eulyFpYTUWa6cx4iPg== X-Received: by 2002:a17:902:8a88:b0:192:ace6:9cf3 with SMTP id p8-20020a1709028a8800b00192ace69cf3mr17731829plo.65.1672803504479; Tue, 03 Jan 2023 19:38:24 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b0017f73caf588sm23091347plh.218.2023.01.03.19.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 19:38:23 -0800 (PST) From: Stephen Hemminger To: Ben Magistro Cc: dev@dpdk.org, Stephen Hemminger Subject: [PATCH v2 6/6] app/dumpcap: support interface name and description Date: Tue, 3 Jan 2023 19:38:15 -0800 Message-Id: <20230104033815.35496-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230104033815.35496-1-stephen@networkplumber.org> References: <20230102162441.6205-1-koncept1@gmail.com> <20230104033815.35496-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Support setting --ifname and --ifdescr options to record information in the start of the pcapng interface description block. Also, records filter (if any) used in the file. This also makes sure only the interfaces being recorded in the capture file are in the interface block. Signed-off-by: Stephen Hemminger --- app/dumpcap/main.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 86a4423b6de1..fdabc14b02c6 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -93,6 +93,8 @@ struct interface { char name[RTE_ETH_NAME_MAX_LEN]; struct rte_rxtx_callback *rx_cb[RTE_MAX_QUEUES_PER_PORT]; + const char *ifname; + const char *ifdescr; }; TAILQ_HEAD(interface_list, interface); @@ -110,6 +112,9 @@ static void usage(void) printf("Capture Interface:\n" " -i name or port index of interface\n" " -f packet filter in libpcap filter syntax\n"); + printf(" --ifname name to use in the capture file\n"); + printf(" --ifdescr \n"); + printf(" description to use in the capture file\n"); printf(" -s , --snapshot-length \n" " packet snapshot length (def: %u)\n", RTE_MBUF_DEFAULT_BUF_SIZE); @@ -330,6 +335,8 @@ static void parse_opts(int argc, char **argv) { "capture-comment", required_argument, NULL, 0 }, { "file-prefix", required_argument, NULL, 0 }, { "help", no_argument, NULL, 'h' }, + { "ifdescr", required_argument, NULL, 0 }, + { "ifname", required_argument, NULL, 0 }, { "interface", required_argument, NULL, 'i' }, { "list-interfaces", no_argument, NULL, 'D' }, { "no-promiscuous-mode", no_argument, NULL, 'p' }, @@ -350,18 +357,30 @@ static void parse_opts(int argc, char **argv) break; switch (c) { - case 0: - if (!strcmp(long_options[option_index].name, - "capture-comment")) { + case 0: { + const char *longopt + = long_options[option_index].name; + + if (!strcmp(longopt, "capture-comment")) { capture_comment = optarg; - } else if (!strcmp(long_options[option_index].name, - "file-prefix")) { + } else if (!strcmp(longopt,"file-prefix")) { file_prefix = optarg; + } else if (!strcmp(longopt, "ifdescr")) { + if (last_intf == NULL) + rte_exit(EXIT_FAILURE, + "--ifdescr must be specified after a -i option\n"); + last_intf->ifdescr = optarg; + } else if (!strcmp(longopt, "ifname")) { + if (last_intf == NULL) + rte_exit(EXIT_FAILURE, + "--ifname must be specified after a -i option\n"); + last_intf->ifname = optarg; } else { usage(); exit(1); } break; + } case 'a': auto_stop(optarg); break; @@ -700,6 +719,7 @@ static dumpcap_out_t create_output(void) } if (use_pcapng) { + struct interface *intf; char *os = get_os_info(); ret.pcapng = rte_pcapng_fdopen(fd, os, NULL, @@ -708,6 +728,12 @@ static dumpcap_out_t create_output(void) rte_exit(EXIT_FAILURE, "pcapng_fdopen failed: %s\n", strerror(rte_errno)); free(os); + + TAILQ_FOREACH(intf, &interfaces, next) { + rte_pcapng_add_interface(ret.pcapng, intf->port, + intf->ifname, intf->ifdescr, + intf->opts.filter); + } } else { pcap_t *pcap; -- 2.39.0