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 774E2A0A0E; Thu, 4 Feb 2021 08:34:41 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F74224057C; Thu, 4 Feb 2021 08:34:41 +0100 (CET) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by mails.dpdk.org (Postfix) with ESMTP id 62726240570 for ; Thu, 4 Feb 2021 08:34:39 +0100 (CET) Received: by mail-wr1-f48.google.com with SMTP id q7so2198746wre.13 for ; Wed, 03 Feb 2021 23:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2UUnEgcL3km4ZOeJvZfMVNfy5nkfEK33AEjLuI3Fb4I=; b=H583xV3xG1okNXTnN+l9UMXxGLAY81u978fOv24/9ZwZYtoIfmlM3nfUxhgtLgXOKM 1Z+XVY5KCpycBDfa9O/TFp+1MbuPMO2OOxK+eqnB4M/qImZQG2uR/VCHELwvYeVfM4/k y6JnfBQsoVR0ka/vT3UEBVwY+WqDjCihUal+1HUCtc8NZeIF7RDp72y5bp5QNSjC7kct ntJ+s0xQld1E2VPm/AFXYVoTn0jrmvUuocurMGtvY+arql8u541gMY5wV0WD4x3mhDXE 7LL81l/cGyG8bmWmPWNzLgGyUwAiJMqlxuJgWJ39UVhm1KSP9y3sqT9D5Qu/rhgwEDyc gCNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2UUnEgcL3km4ZOeJvZfMVNfy5nkfEK33AEjLuI3Fb4I=; b=T5v7dFQSYXkQZbgeWIA3k4cTX/FGeglP2ttM9X/ahukEMBm7w185QP9cVVjpoKA6B1 RbQbmBhlxoyAaTqqg3FBcZH8umfnqeT0r6Vutar2dCkSYuMOgHBXwbKijMKdMJlsbFiM HhKAXLHs0DY670NpaxEHjJPxrPLz40RAe+D+o288UPancTWc8iWnFFDvd6ZmjLDeEqrn BlkfcusUY9kWsn7BXz6kejO3ofOQW7fBURGTn2QODHClPxBkVGT5NGLTrkIbBuu1wUsK AEZ1Peh3lwwqYVAWFiWTNuEI5K0VEwDeMS3hdQc8KWbrsFZISEsVW5haM927w8N6wgVw Q80Q== X-Gm-Message-State: AOAM531UJV4SlT3bFL+y/6VFS9D2wHDcOsUyosbAxywn7d5PP9dy4mEe rmWD6oe7GtgvAoP4uY4CevAvvg== X-Google-Smtp-Source: ABdhPJxQ6yqdCU64FDx1Wu73kofkJiQgJibmfT26pc2urhW08CUZ1ow3qYUI1LkEecM0r8QNu5rvpg== X-Received: by 2002:adf:c413:: with SMTP id v19mr7681450wrf.158.1612424079137; Wed, 03 Feb 2021 23:34:39 -0800 (PST) Received: from localhost.localdomain ([39.33.143.135]) by smtp.gmail.com with ESMTPSA id j11sm7082604wrt.26.2021.02.03.23.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 23:34:38 -0800 (PST) From: Ibtisam Tariq To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, john.mcnamara@intel.com, reshma.pattan@intel.com, konstantin.ananyev@intel.com, marko.kovacevic@intel.com Cc: dev@dpdk.org, Ibtisam Tariq Date: Thu, 4 Feb 2021 07:34:15 +0000 Message-Id: <20210204073420.2421-2-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210204073420.2421-1-ibtisam.tariq@emumba.com> References: <20210204073420.2421-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH v4 2/7] examples/l3fwd-acl: enhance getopt_long usage 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 Sender: "dev" Instead of using getopt_long return value, strcmp was used to compare the input parameters with the struct option array. This patch get rid of all those strcmp by directly binding each longopt with an int enum. This is to improve readability and consistency in all examples. Bugzilla ID: 238 Cc: konstantin.ananyev@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- v4: * Set indentation of preprocessor directives. v3: * None. v2: * Remove extra indentations. * Remove extra block brackets in switch statement. * Change enum names to start with OPT_ and remove KEYWORD from enum names. v1: * enhance getopt_long. --- examples/l3fwd-acl/main.c | 219 +++++++++++++++++++------------------- 1 file changed, 110 insertions(+), 109 deletions(-) diff --git a/examples/l3fwd-acl/main.c b/examples/l3fwd-acl/main.c index 961594f5f..3e71103da 100644 --- a/examples/l3fwd-acl/main.c +++ b/examples/l3fwd-acl/main.c @@ -195,13 +195,24 @@ send_single_packet(struct rte_mbuf *m, uint16_t port); #define ACL_LEAD_CHAR ('@') #define ROUTE_LEAD_CHAR ('R') #define COMMENT_LEAD_CHAR ('#') -#define OPTION_CONFIG "config" -#define OPTION_NONUMA "no-numa" -#define OPTION_ENBJMO "enable-jumbo" -#define OPTION_RULE_IPV4 "rule_ipv4" -#define OPTION_RULE_IPV6 "rule_ipv6" -#define OPTION_ALG "alg" -#define OPTION_ETH_DEST "eth-dest" + +enum { +#define OPT_CONFIG "config" + OPT_CONFIG_NUM = 256, +#define OPT_NONUMA "no-numa" + OPT_NONUMA_NUM, +#define OPT_ENBJMO "enable-jumbo" + OPT_ENBJMO_NUM, +#define OPT_RULE_IPV4 "rule_ipv4" + OPT_RULE_IPV4_NUM, +#define OPT_RULE_IPV6 "rule_ipv6" + OPT_RULE_IPV6_NUM, +#define OPT_ALG "alg" + OPT_ALG_NUM, +#define OPT_ETH_DEST "eth-dest" + OPT_ETH_DEST_NUM, +}; + #define ACL_DENY_SIGNATURE 0xf0000000 #define RTE_LOGTYPE_L3FWDACL RTE_LOGTYPE_USER3 #define acl_log(format, ...) RTE_LOG(ERR, L3FWDACL, format, ##__VA_ARGS__) @@ -1177,9 +1188,9 @@ static void dump_acl_config(void) { printf("ACL option are:\n"); - printf(OPTION_RULE_IPV4": %s\n", parm_config.rule_ipv4_name); - printf(OPTION_RULE_IPV6": %s\n", parm_config.rule_ipv6_name); - printf(OPTION_ALG": %s\n", str_acl_alg(parm_config.alg)); + printf(OPT_RULE_IPV4": %s\n", parm_config.rule_ipv4_name); + printf(OPT_RULE_IPV6": %s\n", parm_config.rule_ipv6_name); + printf(OPT_ALG": %s\n", str_acl_alg(parm_config.alg)); } static int @@ -1608,27 +1619,27 @@ print_usage(const char *prgname) usage_acl_alg(alg, sizeof(alg)); printf("%s [EAL options] -- -p PORTMASK -P" - "--"OPTION_RULE_IPV4"=FILE" - "--"OPTION_RULE_IPV6"=FILE" - " [--"OPTION_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]" - " [--"OPTION_ENBJMO" [--max-pkt-len PKTLEN]]\n" + "--"OPT_RULE_IPV4"=FILE" + "--"OPT_RULE_IPV6"=FILE" + " [--"OPT_CONFIG" (port,queue,lcore)[,(port,queue,lcore]]" + " [--"OPT_ENBJMO" [--max-pkt-len PKTLEN]]\n" " -p PORTMASK: hexadecimal bitmask of ports to configure\n" " -P : enable promiscuous mode\n" - " --"OPTION_CONFIG": (port,queue,lcore): " + " --"OPT_CONFIG": (port,queue,lcore): " "rx queues configuration\n" - " --"OPTION_NONUMA": optional, disable numa awareness\n" - " --"OPTION_ENBJMO": enable jumbo frame" + " --"OPT_NONUMA": optional, disable numa awareness\n" + " --"OPT_ENBJMO": enable jumbo frame" " which max packet len is PKTLEN in decimal (64-9600)\n" - " --"OPTION_RULE_IPV4"=FILE: specify the ipv4 rules entries " + " --"OPT_RULE_IPV4"=FILE: specify the ipv4 rules entries " "file. " "Each rule occupy one line. " "2 kinds of rules are supported. " "One is ACL entry at while line leads with character '%c', " "another is route entry at while line leads with " "character '%c'.\n" - " --"OPTION_RULE_IPV6"=FILE: specify the ipv6 rules " + " --"OPT_RULE_IPV6"=FILE: specify the ipv6 rules " "entries file.\n" - " --"OPTION_ALG": ACL classify method to use, one of: %s\n", + " --"OPT_ALG": ACL classify method to use, one of: %s\n", prgname, ACL_LEAD_CHAR, ROUTE_LEAD_CHAR, alg); } @@ -1747,14 +1758,14 @@ parse_args(int argc, char **argv) int option_index; char *prgname = argv[0]; static struct option lgopts[] = { - {OPTION_CONFIG, 1, 0, 0}, - {OPTION_NONUMA, 0, 0, 0}, - {OPTION_ENBJMO, 0, 0, 0}, - {OPTION_RULE_IPV4, 1, 0, 0}, - {OPTION_RULE_IPV6, 1, 0, 0}, - {OPTION_ALG, 1, 0, 0}, - {OPTION_ETH_DEST, 1, 0, 0}, - {NULL, 0, 0, 0} + {OPT_CONFIG, 1, NULL, OPT_CONFIG_NUM }, + {OPT_NONUMA, 0, NULL, OPT_NONUMA_NUM }, + {OPT_ENBJMO, 0, NULL, OPT_ENBJMO_NUM }, + {OPT_RULE_IPV4, 1, NULL, OPT_RULE_IPV4_NUM }, + {OPT_RULE_IPV6, 1, NULL, OPT_RULE_IPV6_NUM }, + {OPT_ALG, 1, NULL, OPT_ALG_NUM }, + {OPT_ETH_DEST, 1, NULL, OPT_ETH_DEST_NUM }, + {NULL, 0, 0, 0 } }; argvopt = argv; @@ -1772,104 +1783,94 @@ parse_args(int argc, char **argv) return -1; } break; + case 'P': printf("Promiscuous mode selected\n"); promiscuous_on = 1; break; /* long options */ - case 0: - if (!strncmp(lgopts[option_index].name, - OPTION_CONFIG, - sizeof(OPTION_CONFIG))) { - ret = parse_config(optarg); - if (ret) { - printf("invalid config\n"); - print_usage(prgname); - return -1; - } - } - - if (!strncmp(lgopts[option_index].name, - OPTION_NONUMA, - sizeof(OPTION_NONUMA))) { - printf("numa is disabled\n"); - numa_on = 0; - } - - if (!strncmp(lgopts[option_index].name, - OPTION_ENBJMO, sizeof(OPTION_ENBJMO))) { - struct option lenopts = { - "max-pkt-len", - required_argument, - 0, - 0 - }; - - printf("jumbo frame is enabled\n"); - port_conf.rxmode.offloads |= - DEV_RX_OFFLOAD_JUMBO_FRAME; - port_conf.txmode.offloads |= - DEV_TX_OFFLOAD_MULTI_SEGS; - - /* - * if no max-pkt-len set, then use the - * default value RTE_ETHER_MAX_LEN - */ - if (0 == getopt_long(argc, argvopt, "", - &lenopts, &option_index)) { - ret = parse_max_pkt_len(optarg); - if ((ret < 64) || - (ret > MAX_JUMBO_PKT_LEN)) { - printf("invalid packet " - "length\n"); - print_usage(prgname); - return -1; - } - port_conf.rxmode.max_rx_pkt_len = ret; - } - printf("set jumbo frame max packet length " - "to %u\n", - (unsigned int) - port_conf.rxmode.max_rx_pkt_len); + case OPT_CONFIG_NUM: + ret = parse_config(optarg); + if (ret) { + printf("invalid config\n"); + print_usage(prgname); + return -1; } + break; - if (!strncmp(lgopts[option_index].name, - OPTION_RULE_IPV4, - sizeof(OPTION_RULE_IPV4))) - parm_config.rule_ipv4_name = optarg; - - if (!strncmp(lgopts[option_index].name, - OPTION_RULE_IPV6, - sizeof(OPTION_RULE_IPV6))) { - parm_config.rule_ipv6_name = optarg; - } + case OPT_NONUMA_NUM: + printf("numa is disabled\n"); + numa_on = 0; + break; - if (!strncmp(lgopts[option_index].name, - OPTION_ALG, sizeof(OPTION_ALG))) { - parm_config.alg = parse_acl_alg(optarg); - if (parm_config.alg == - RTE_ACL_CLASSIFY_DEFAULT) { - printf("unknown %s value:\"%s\"\n", - OPTION_ALG, optarg); + case OPT_ENBJMO_NUM: + { + struct option lenopts = { + "max-pkt-len", + required_argument, + 0, + 0 + }; + + printf("jumbo frame is enabled\n"); + port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_JUMBO_FRAME; + port_conf.txmode.offloads |= + DEV_TX_OFFLOAD_MULTI_SEGS; + + /* + * if no max-pkt-len set, then use the + * default value RTE_ETHER_MAX_LEN + */ + if (0 == getopt_long(argc, argvopt, "", + &lenopts, &option_index)) { + ret = parse_max_pkt_len(optarg); + if ((ret < 64) || + (ret > MAX_JUMBO_PKT_LEN)) { + printf("invalid packet " + "length\n"); print_usage(prgname); return -1; } + port_conf.rxmode.max_rx_pkt_len = ret; } + printf("set jumbo frame max packet length " + "to %u\n", + (unsigned int) + port_conf.rxmode.max_rx_pkt_len); + break; + } + case OPT_RULE_IPV4_NUM: + parm_config.rule_ipv4_name = optarg; + break; - if (!strncmp(lgopts[option_index].name, OPTION_ETH_DEST, - sizeof(OPTION_ETH_DEST))) { - const char *serr = parse_eth_dest(optarg); - if (serr != NULL) { - printf("invalid %s value:\"%s\": %s\n", - OPTION_ETH_DEST, optarg, serr); - print_usage(prgname); - return -1; - } - } + case OPT_RULE_IPV6_NUM: + parm_config.rule_ipv6_name = optarg; + break; + case OPT_ALG_NUM: + parm_config.alg = parse_acl_alg(optarg); + if (parm_config.alg == + RTE_ACL_CLASSIFY_DEFAULT) { + printf("unknown %s value:\"%s\"\n", + OPT_ALG, optarg); + print_usage(prgname); + return -1; + } break; + case OPT_ETH_DEST_NUM: + { + const char *serr = parse_eth_dest(optarg); + if (serr != NULL) { + printf("invalid %s value:\"%s\": %s\n", + OPT_ETH_DEST, optarg, serr); + print_usage(prgname); + return -1; + } + break; + } default: print_usage(prgname); return -1; -- 2.17.1