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 0A18AA00C4 for ; Mon, 2 Jan 2023 17:25:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6DA0442D36; Mon, 2 Jan 2023 17:25:45 +0100 (CET) Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by mails.dpdk.org (Postfix) with ESMTP id 344C442D25; Mon, 2 Jan 2023 17:25:43 +0100 (CET) Received: by mail-qt1-f172.google.com with SMTP id h26so22743522qtu.2; Mon, 02 Jan 2023 08:25:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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=JiOCt4RhgzdVAPmdZIT0PmFXn6dg91pzan3MBaKrWtM=; b=I4Rpqa5lY2f/vwwD9E4HMxeE7mlGdX/4XsIGNVNtVnqG+axWF1byRgXbZhbQmZf8we 24ap4UaPN0CSFaZB7opmWdBc7gxvNDCS37aOkta5304EIlJhMUFnDPDHaSNLJWnbH1zo fsvO0b3hNPF87vA6H03k3rhVBEDV3tcM7eMlVp6csOnNUrXp4F1/pYC7dq1S5fDHKZd8 tsph8bTa2Gj9+FeYPa1ETzKOdMOcgU37hqQk4bMYN2yX/1pjJCuUCRjY9FgNrC2cWC1r DKGhZWT6x0le1CN1TJKhF+HqNZL+2UrVoLZErY+JaB2xX+uX5IRVA01jvibIZ3hr/vhK mOrQ== 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=JiOCt4RhgzdVAPmdZIT0PmFXn6dg91pzan3MBaKrWtM=; b=vXNja2ybRuf/kIbqCxm0CoaANlORASiugAalGoKgfJoacC6K3mhI8OtF7zNCakszce TYqGrkoXjTJuQeLJoBsM8XQDEzpUSE9EmQaYVbq3VkW6wofs5MBnlI3RarwzwpNWaCQQ +WcROVXcAX7jBUzGIxjbR3Y5mdoQZVWZZ5NhXmWoifTi3IUqIXEN6C2QPltrztMul1Fj wqOARvx/W8gJl6oU1NCQzTCegi2Ya9GSdySLe+3E7p+Y1uTDk3hPauBQeWOis00natv0 LNnaWOicHoDALPnZVQu+PVeVTDtobKGQhS0JXr7lEtYp8n3k+Ma0tXUtm7l3oQDFUkbj vFDQ== X-Gm-Message-State: AFqh2koBbDJrk5/gopvKy7MvwakmH4qNCmM5HNYn9NzbUSzOK+H4HP+U rziRxlT4XLwffiz5OC1isudkYZR9y9E= X-Google-Smtp-Source: AMrXdXvRPTdaK7QsiipflcPLeXAf5rKaJTT1VSbl01/1QQF1+yB5n9i77ezmxWfeEjVadLrwtdIDdQ== X-Received: by 2002:ac8:5295:0:b0:3a8:fdf:8ff8 with SMTP id s21-20020ac85295000000b003a80fdf8ff8mr53477730qtn.36.1672676742489; Mon, 02 Jan 2023 08:25:42 -0800 (PST) Received: from lvdi-01-iad-l.blue.trinitycyber.com ([38.142.224.194]) by smtp.gmail.com with ESMTPSA id u2-20020ac80502000000b003a81eef14efsm17678091qtg.45.2023.01.02.08.25.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2023 08:25:42 -0800 (PST) From: Ben Magistro To: dev@dpdk.org, stephen@networkplumber.org Cc: ben.magistro@trinitycyber.com, Ben Magistro , arshdeep.kaur@intel.com, stable@dpdk.org Subject: [PATCH 4/6] app/dumpcap: fix capturing on multiple interfaces Date: Mon, 2 Jan 2023 16:24:39 +0000 Message-Id: <20230102162441.6205-4-koncept1@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230102162441.6205-1-koncept1@gmail.com> References: <20230102162441.6205-1-koncept1@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org When selecting interfaces to capture traffic on, only the last interface specified was being preserved for selection. This turns the interface argument into an array allowing multiple interfaces to be selected. This also adds checks for the capture format so that if multiple interfaces are selected, the interface information is included in the capture file. Fixes: 7f3623a ("app/dumpcap: fix select interface") Cc: arshdeep.kaur@intel.com Cc: stephen@networkplumber.org Cc: stable@dpdk.org Signed-off-by: Ben Magistro --- app/dumpcap/main.c | 47 +++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 26c641df61..dc4d69ff6b 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -65,8 +65,8 @@ static const char *file_prefix; static uint32_t snaplen = RTE_MBUF_DEFAULT_BUF_SIZE; static bool dump_bpf; static bool show_interfaces; -static bool select_interfaces; -const char *interface_arg; +static uint8_t interface_arg_count = 0; /* count of interfaces configured via -i */ +static const char *interface_arg[RTE_MAX_ETHPORTS]; /*array of interface parameters */ static struct { uint64_t duration; /* nanoseconds */ @@ -242,7 +242,6 @@ static void set_default_interface(void) add_interface(p, name); return; } - rte_exit(EXIT_FAILURE, "No usable interfaces found\n"); } /* Lookup interface by name or port and add it to the list */ @@ -265,6 +264,32 @@ static void select_interface(const char *arg) } } +/** + * builds list of interfacs that capture will occur on + * this also validates the save format based on the number of interfaces + */ +static void collect_interfaces(void) +{ + uint8_t active; + struct interface *intf; + + active = 0; + + if (interface_arg_count == 0) + set_default_interface(); + else + for (uint8_t i = 0; i < interface_arg_count; ++i) + select_interface(interface_arg[i]); + + TAILQ_FOREACH(intf, &interfaces, next) + active++; + + if ((!use_pcapng) && (active > 1)) { + printf("Requested pcap format, but options require pcapng; overriding\n"); + use_pcapng = true; + } +} + /* Display list of possible interfaces that can be used. */ static void dump_interfaces(void) { @@ -406,8 +431,8 @@ static void parse_opts(int argc, char **argv) usage(); exit(0); case 'i': - select_interfaces = true; - interface_arg = optarg; + interface_arg_count++; + interface_arg[interface_arg_count - 1] = optarg; break; case 'n': use_pcapng = true; @@ -840,21 +865,17 @@ int main(int argc, char **argv) parse_opts(argc, argv); dpdk_init(); + if (rte_eth_dev_count_avail() == 0) + rte_exit(EXIT_FAILURE, "No usable ports found\n"); + if (show_interfaces) dump_interfaces(); - if (rte_eth_dev_count_avail() == 0) - rte_exit(EXIT_FAILURE, "No Ethernet ports found\n"); - - if (select_interfaces) - select_interface(interface_arg); + collect_interfaces(); if (filter_str) compile_filter(); - if (TAILQ_EMPTY(&interfaces)) - set_default_interface(); - r = create_ring(); mp = create_mempool(); out = create_output(); -- 2.27.0