From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5A1371B972 for ; Tue, 5 Jun 2018 16:16:14 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jun 2018 07:16:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,479,1520924400"; d="scan'208";a="53985936" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by fmsmga002.fm.intel.com with ESMTP; 05 Jun 2018 07:16:11 -0700 From: Konstantin Ananyev To: dev@dpdk.org Cc: Konstantin Ananyev Date: Tue, 5 Jun 2018 15:16:03 +0100 Message-Id: <1528208163-31560-2-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1528208163-31560-1-git-send-email-konstantin.ananyev@intel.com> References: <1528208163-31560-1-git-send-email-konstantin.ananyev@intel.com> To: dev@dpdk.org cc: radu.nicolau@intel.com Subject: [dpdk-dev] [PATCH 2/2] examples/ipsec-secgw: fix portmask option parsing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jun 2018 14:16:14 -0000 parse_portmask() returns both portmask value and possible error code as 32-bit integer. That causes some confusion for callers. Split error code and portmask value into two distinct variables. Also allows to run the app with unprotected_port_mask == 0. Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application") Signed-off-by: Konstantin Ananyev --- examples/ipsec-secgw/ipsec-secgw.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/ipsec-secgw/ipsec-secgw.c b/examples/ipsec-secgw/ipsec-secgw.c index fafb41161..5d7071657 100644 --- a/examples/ipsec-secgw/ipsec-secgw.c +++ b/examples/ipsec-secgw/ipsec-secgw.c @@ -972,20 +972,19 @@ print_usage(const char *prgname) } static int32_t -parse_portmask(const char *portmask) +parse_portmask(const char *portmask, uint32_t *pmv) { - char *end = NULL; + char *end; unsigned long pm; /* parse hexadecimal string */ + errno = 0; pm = strtoul(portmask, &end, 16); - if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) + if (errno != 0 || *end != '\0' || pm > UINT32_MAX) return -1; - if ((pm == 0) && errno) - return -1; - - return pm; + *pmv = pm; + return 0; } static int32_t @@ -1063,6 +1062,7 @@ parse_args(int32_t argc, char **argv) int32_t opt, ret; char **argvopt; int32_t option_index; + uint32_t v; char *prgname = argv[0]; int32_t f_present = 0; @@ -1073,8 +1073,8 @@ parse_args(int32_t argc, char **argv) switch (opt) { case 'p': - enabled_port_mask = parse_portmask(optarg); - if (enabled_port_mask == 0) { + ret = parse_portmask(optarg, &enabled_port_mask); + if (ret < 0 || enabled_port_mask == 0) { printf("invalid portmask\n"); print_usage(prgname); return -1; @@ -1085,8 +1085,8 @@ parse_args(int32_t argc, char **argv) promiscuous_on = 1; break; case 'u': - unprotected_port_mask = parse_portmask(optarg); - if (unprotected_port_mask == 0) { + ret = parse_portmask(optarg, &unprotected_port_mask); + if (ret < 0) { printf("invalid unprotected portmask\n"); print_usage(prgname); return -1; @@ -1147,15 +1147,16 @@ parse_args(int32_t argc, char **argv) single_sa_idx); break; case CMD_LINE_OPT_CRYPTODEV_MASK_NUM: - ret = parse_portmask(optarg); + ret = parse_portmask(optarg, &v); if (ret == -1) { - printf("Invalid argument[portmask]\n"); + printf("Invalid argument[%s]\n", + CMD_LINE_OPT_CRYPTODEV_MASK); print_usage(prgname); return -1; } /* else */ - enabled_cryptodev_mask = ret; + enabled_cryptodev_mask = v; break; default: print_usage(prgname); -- 2.13.6