Save some space by using bool for flag values. Use common code to parse value of a boolean flag.
Signed-off-by: Stephen Hemminger <[email protected]> --- 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

