From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 03/12] net/pcap: use bool for flags
Date: Tue, 6 Jan 2026 10:26:42 -0800 [thread overview]
Message-ID: <20260106182823.192350-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20260106182823.192350-1-stephen@networkplumber.org>
Save some space by using bool for flag values.
Use common code to parse value of a boolean flag.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/pcap/pcap_ethdev.c | 73 +++++++++++++++++-----------------
1 file changed, 36 insertions(+), 37 deletions(-)
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index f4cb444395..6a3e89aeab 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -5,6 +5,7 @@
*/
#include <stdlib.h>
+#include <stdbool.h>
#include <time.h>
#include <pcap.h>
@@ -91,9 +92,9 @@ struct pmd_internals {
char devargs[ETH_PCAP_ARG_MAXLEN];
struct rte_ether_addr eth_addr;
int if_index;
- int single_iface;
- int phy_mac;
- unsigned int infinite_rx;
+ bool single_iface;
+ bool phy_mac;
+ bool infinite_rx;
};
struct pmd_process_private {
@@ -103,25 +104,25 @@ struct pmd_process_private {
};
struct pmd_devargs {
- unsigned int num_of_queue;
+ uint16_t num_of_queue;
+ bool phy_mac;
struct devargs_queue {
pcap_dumper_t *dumper;
pcap_t *pcap;
const char *name;
const char *type;
} queue[RTE_PMD_PCAP_MAX_QUEUES];
- int phy_mac;
};
struct pmd_devargs_all {
struct pmd_devargs rx_queues;
struct pmd_devargs tx_queues;
- int single_iface;
- unsigned int is_tx_pcap;
- unsigned int is_tx_iface;
- unsigned int is_rx_pcap;
- unsigned int is_rx_iface;
- unsigned int infinite_rx;
+ bool single_iface;
+ bool is_tx_pcap;
+ bool is_tx_iface;
+ bool is_rx_pcap;
+ bool is_rx_iface;
+ bool infinite_rx;
};
static const char *valid_arguments[] = {
@@ -858,7 +859,7 @@ eth_dev_close(struct rte_eth_dev *dev)
}
}
- if (internals->phy_mac == 0)
+ if (!internals->phy_mac)
/* not dynamically allocated, must not be freed */
dev->data->mac_addrs = NULL;
@@ -1180,31 +1181,29 @@ open_tx_iface(const char *key, const char *value, void *extra_args)
}
static int
-select_phy_mac(const char *key __rte_unused, const char *value,
- void *extra_args)
+process_bool_flag(const char *key, const char *value, void *extra_args)
{
- if (extra_args) {
- const int phy_mac = atoi(value);
- int *enable_phy_mac = extra_args;
-
- if (phy_mac)
- *enable_phy_mac = 1;
- }
- return 0;
-}
+ bool *flag = extra_args;
+ /* table of possible representation of boolean */
+ static const char * const values[] = {
+ "false", "true",
+ "0", "1",
+ "disable", "enable",
+ "on", "off",
+ };
-static int
-get_infinite_rx_arg(const char *key __rte_unused,
- const char *value, void *extra_args)
-{
- if (extra_args) {
- const int infinite_rx = atoi(value);
- int *enable_infinite_rx = extra_args;
+ for (unsigned int i = 0; i < RTE_DIM(values); i++) {
+ if (strcmp(value, values[i]) == 0) {
+ *flag = !!(i & 1);
- if (infinite_rx > 0)
- *enable_infinite_rx = 1;
+ PMD_LOG(INFO, "%s set to %s",
+ key, *flag ? "true" : "false");
+ return 0;
+ }
}
- return 0;
+
+ PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
+ return -1;
}
static int
@@ -1479,7 +1478,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
dumpers.queue[0] = pcaps.queue[0];
ret = rte_kvargs_process(kvlist, ETH_PCAP_PHY_MAC_ARG,
- &select_phy_mac, &pcaps.phy_mac);
+ &process_bool_flag, &pcaps.phy_mac);
if (ret < 0)
goto free_kvlist;
@@ -1518,9 +1517,9 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
if (infinite_rx_arg_cnt == 1) {
ret = rte_kvargs_process(kvlist,
- ETH_PCAP_INFINITE_RX_ARG,
- &get_infinite_rx_arg,
- &devargs_all.infinite_rx);
+ ETH_PCAP_INFINITE_RX_ARG,
+ &process_bool_flag,
+ &devargs_all.infinite_rx);
if (ret < 0)
goto free_kvlist;
PMD_LOG(INFO, "infinite_rx has been %s for %s",
--
2.51.0
next prev parent reply other threads:[~2026-01-06 18:33 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 18:26 [PATCH 00/12] net/pcap: cleanups and test Stephen Hemminger
2026-01-06 18:26 ` [PATCH 01/12] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-06 18:26 ` [PATCH 02/12] net/pcap: support MTU set Stephen Hemminger
2026-01-06 18:26 ` Stephen Hemminger [this message]
2026-01-07 10:28 ` [PATCH 03/12] net/pcap: use bool for flags Marat Khalili
2026-01-09 0:23 ` Stephen Hemminger
2026-01-06 18:26 ` [PATCH 04/12] net/pcap: support Tx offloads Stephen Hemminger
2026-01-06 18:26 ` [PATCH 05/12] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-06 18:26 ` [PATCH 06/12] net/pcap: remove global variables Stephen Hemminger
2026-01-07 9:48 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 07/12] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-07 10:31 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 08/12] net/pcap: optimize calculation of receive timestamp Stephen Hemminger
2026-01-07 10:58 ` Marat Khalili
2026-01-06 18:26 ` [PATCH 09/12] net/pcap: report receive clock Stephen Hemminger
2026-01-06 18:26 ` [PATCH 10/12] net/pcap: cleanup MAC address handling Stephen Hemminger
2026-01-06 18:26 ` [PATCH 11/12] net/pcap: support MAC address set Stephen Hemminger
2026-01-06 18:26 ` [PATCH 12/12] test: add test for pcap PMD Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 0/9] pcap: cleanup pcap PMD and add test Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 1/9] net/pcap: avoid using rte_malloc and rte_memcpy Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 2/9] net/pcap: support MTU set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 3/9] net/pcap: use bool for flags Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 4/9] net/pcap: support Tx offloads Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 5/9] net/pcap: support nanosecond timestamp precision Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 6/9] net/pcap: remove global variables Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 7/9] net/pcap: avoid use of volatile Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 8/9] net/pcap: support MAC address set Stephen Hemminger
2026-01-09 1:16 ` [PATCH v2 9/9] test: add test for pcap PMD Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260106182823.192350-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).