From: Marat Khalili <marat.khalili@huawei.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH 03/12] net/pcap: use bool for flags
Date: Wed, 7 Jan 2026 10:28:32 +0000 [thread overview]
Message-ID: <4b0f415322e2457d93b695469847b113@huawei.com> (raw)
In-Reply-To: <20260106182823.192350-4-stephen@networkplumber.org>
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Tuesday 6 January 2026 18:27
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>
> Subject: [PATCH 03/12] net/pcap: use bool for flags
>
> Save some space by using bool for flag values.
> Use common code to parse value of a boolean flag.
Note that there might technically be some performance cost of this. Said that,
since original code did not leave any comments why ints were used, let's think
it was not on purpose, while bools are cleaner and less error-prone.
I however think that proper bool conversion should use true or false on
assignment/initialization, not 1 or 0.
// snip
> @@ -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)
This function probably belongs in some common library. There is a similar code
in lib/argparse/rte_argparse.c and lib/cmdline/cmdline_parse_bool.c that might
benefit. Having some tests could also be useful.
I would also think of naming more, word "process" does not really convey much
meaning. How about "parse_bool"?
> {
> - 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",
Last pair is swapped.
> + };
>
> -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) {
Maybe strcasecmp (just suggesting)?
> + *flag = !!(i & 1);
>
> - if (infinite_rx > 0)
> - *enable_infinite_rx = 1;
> + PMD_LOG(INFO, "%s set to %s",
> + key, *flag ? "true" : "false");
Should we have a common use {"false", "true"} inline function somewhere?
Logging of infinite_rx in the same file could use it, as well as a few other
places.
> + return 0;
> + }
> }
> - return 0;
> +
> + PMD_LOG(ERR, "Invalid '%s' value '%s'", key, value);
> + return -1;
> }
next prev parent reply other threads:[~2026-01-07 10:28 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 ` [PATCH 03/12] net/pcap: use bool for flags Stephen Hemminger
2026-01-07 10:28 ` Marat Khalili [this message]
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=4b0f415322e2457d93b695469847b113@huawei.com \
--to=marat.khalili@huawei.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.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).