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 C39C9A00C2; Mon, 2 Jan 2023 17:26:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AEC0F42D3F; Mon, 2 Jan 2023 17:25:48 +0100 (CET) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by mails.dpdk.org (Postfix) with ESMTP id 4E25442D29 for ; Mon, 2 Jan 2023 17:25:47 +0100 (CET) Received: by mail-qt1-f180.google.com with SMTP id i20so22711836qtw.9 for ; Mon, 02 Jan 2023 08:25:47 -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=BF1mUY7A/zN96ubkRAr/TTL6Ea216ssTqlumP6n1NfM=; b=JJXtcmEeGi+6OELvKRFFBP9DqhbaD+Mb1iIn8VEL1DnCtbZbO1WDizyMKs4j5TIvPw 4SbtWCbeog5GME+uiswJfMNdHDjaAZaqj69kZEyv0AuNTN7bLBlM5v6ZNqJn0/esVC+v dUf52VA1ngjh8EOpYLrabnNNSr0GB72tu9DXm7Upl1kcB/Czmm2u7YW++fLiIcMOWKzE OU63MMGz7DMcdVhOOs3Cvjv+kzEsRsTD2Mt1Wf1G8j3QpRM3hkbZfwMuqkhj7Lydjxir 6koYBnDDsVOcmwNs9ry7wLpwKQIlAsoVcjYSxiEaxviYz7Hv7AmBdsqhLW7JsevJFlG2 aLeg== 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=BF1mUY7A/zN96ubkRAr/TTL6Ea216ssTqlumP6n1NfM=; b=yffoR99NLIIV1x29J/t0wNjWX5q3Rg8NTNfgtKeudGQhfcjULWNc6eOUqQbfaEaOIP liaggrZzddjQ79uvPLG3ghvWVLe7CJtlfwfFRLJvnwo1lojk85yK0Km9iL7gdS5/db5T INa5MnoJ5O4adhqbUGuP4I28m8CQN/7h3ll++EjTZlEyxL7buaH6ee5qmq/eJ2NJaf7p 0XpD6aGEy8vyQ6I9mfchXem697oGdxcAibstgsoTKqXhwhPzu0MV+KsRZ0uVKW5/fXEk HfhAVVQlBXR1eALsFOHrI6ySj8O47D3CjusVsFjfS/LTrVieIwRa1LE4FizpLcgSmjFa I+WA== X-Gm-Message-State: AFqh2kr5ep7isuCdG1+E6oRyIjtPEvCXA5Zgc6493FbZVMfgMT1/cajr Cb0jVBItOaTQLwE4Ep+nS7XvatIfYVM= X-Google-Smtp-Source: AMrXdXvr+4x0+FHtg1R14jN18U/p4I5bxMgEoqGYuOHsaZ7dNjkVboV1/ExTYxH/xUEYD/4HuZejvA== X-Received: by 2002:a05:622a:5143:b0:3ab:4221:44e9 with SMTP id ew3-20020a05622a514300b003ab422144e9mr65819058qtb.36.1672676746588; Mon, 02 Jan 2023 08:25:46 -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.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2023 08:25:46 -0800 (PST) From: Ben Magistro To: dev@dpdk.org, stephen@networkplumber.org Cc: ben.magistro@trinitycyber.com, Ben Magistro Subject: [PATCH 6/6] app/dumpcap: refactor add all and default Date: Mon, 2 Jan 2023 16:24:41 +0000 Message-Id: <20230102162441.6205-6-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: 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 This refactors the add all and default interface functions to reduce code duplication. Cc: stephen@networkplumber.org Signed-off-by: Ben Magistro --- app/dumpcap/main.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 1dc4a38adb..d85839a550 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -230,33 +230,20 @@ static void add_interface(uint16_t port, const char *name, struct interface_opts TAILQ_INSERT_TAIL(&interfaces, intf, next); } -/* Select all valid DPDK interfaces */ -static void select_all_interfaces(struct interface_opts *opts) +/* Select available DPDK interfaces up to the limit */ +static void select_available_interfaces(uint8_t limit, struct interface_opts *opts) { char name[RTE_ETH_NAME_MAX_LEN]; uint16_t p; + uint8_t added = 0; RTE_ETH_FOREACH_DEV(p) { if (rte_eth_dev_get_name_by_port(p, name) < 0) continue; add_interface(p, name, opts); - } -} - -/* - * Choose interface to capture if no -i option given. - * Select the first DPDK port, this matches what dumpcap does. - */ -static void set_default_interface(struct interface_opts *opts) -{ - char name[RTE_ETH_NAME_MAX_LEN]; - uint16_t p; - - RTE_ETH_FOREACH_DEV(p) { - if (rte_eth_dev_get_name_by_port(p, name) < 0) - continue; - add_interface(p, name, opts); - return; + added++; + if (added == limit) + break; } } @@ -266,7 +253,7 @@ static void select_interface(struct interface_opts *opts) uint16_t port; if (strcmp(opts->intf_arg, "*") == 0) - select_all_interfaces(opts); + select_available_interfaces(RTE_MAX_ETHPORTS, opts); else if (rte_eth_dev_get_port_by_name(opts->intf_arg, &port) == 0) add_interface(port, opts->intf_arg, opts); else { @@ -292,7 +279,7 @@ static void collect_interfaces(void) active = 0; if (interface_arg_count == 0) - set_default_interface(&interface_defaults); + select_available_interfaces(1, &interface_defaults); else for (uint8_t i = 0; i < interface_arg_count; ++i) select_interface(&interface_args[i]); -- 2.27.0