From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 5B4061BA58 for ; Tue, 5 Jun 2018 17:36:32 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jun 2018 08:36:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,479,1520924400"; d="scan'208";a="47479383" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by orsmga006.jf.intel.com with ESMTP; 05 Jun 2018 08:36:29 -0700 Received: from irsmsx112.ger.corp.intel.com (10.108.20.5) by IRSMSX101.ger.corp.intel.com (163.33.3.153) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 5 Jun 2018 16:36:28 +0100 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.139]) by irsmsx112.ger.corp.intel.com ([169.254.1.22]) with mapi id 14.03.0319.002; Tue, 5 Jun 2018 16:36:28 +0100 From: "Iremonger, Bernard" To: "Ananyev, Konstantin" , "dev@dpdk.org" , "dev@dpdk.org" CC: "Nicolau, Radu" Thread-Topic: [dpdk-dev] [PATCH 2/2] examples/ipsec-secgw: fix portmask option parsing Thread-Index: AQHT/NfTH7Zb3uQVB06CE6KfkwNe4qRRyrGg Date: Tue, 5 Jun 2018 15:36:27 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C260CAD8FE@IRSMSX108.ger.corp.intel.com> References: <1528208163-31560-1-git-send-email-konstantin.ananyev@intel.com> <1528208163-31560-2-git-send-email-konstantin.ananyev@intel.com> In-Reply-To: <1528208163-31560-2-git-send-email-konstantin.ananyev@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYjI2YjQyMGMtYTgyNS00YWFmLWE2ZTItMzRjMDFlZDAxY2U2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiMjFOWHJKTXBQTTJ3eW11OW5IY281VGlUTkNEVHA1eGZ5cEpOTVRvNGsxRGh0U3cyZUVDRmV3R3RETGVIa1R3MyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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 15:36:32 -0000 Hi Konstantin, > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Konstantin Ananyev > Sent: Tuesday, June 5, 2018 3:16 PM > To: dev@dpdk.org; dev@dpdk.org > Cc: Ananyev, Konstantin ; Nicolau, Radu > > Subject: [dpdk-dev] [PATCH 2/2] examples/ipsec-secgw: fix portmask option > parsing >=20 > parse_portmask() returns both portmask value and possible error code as 3= 2-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 =3D=3D 0. >=20 > Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application"= ) >=20 > Signed-off-by: Konstantin Ananyev > --- > examples/ipsec-secgw/ipsec-secgw.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) >=20 > 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) } >=20 > static int32_t > -parse_portmask(const char *portmask) > +parse_portmask(const char *portmask, uint32_t *pmv) > { > - char *end =3D NULL; > + char *end; > unsigned long pm; >=20 > /* parse hexadecimal string */ > + errno =3D 0; > pm =3D strtoul(portmask, &end, 16); > - if ((portmask[0] =3D=3D '\0') || (end =3D=3D NULL) || (*end !=3D '\0')) > + if (errno !=3D 0 || *end !=3D '\0' || pm > UINT32_MAX) > return -1; >=20 > - if ((pm =3D=3D 0) && errno) > - return -1; > - > - return pm; > + *pmv =3D pm; > + return 0; > } >=20 > 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; The variable "v" seems a bit cryptic to me, how about "pmv" or "mask_val" o= r "value"? =20 > char *prgname =3D argv[0]; > int32_t f_present =3D 0; >=20 > @@ -1073,8 +1073,8 @@ parse_args(int32_t argc, char **argv) >=20 > switch (opt) { > case 'p': > - enabled_port_mask =3D parse_portmask(optarg); > - if (enabled_port_mask =3D=3D 0) { > + ret =3D parse_portmask(optarg, &enabled_port_mask); > + if (ret < 0 || enabled_port_mask =3D=3D 0) { > printf("invalid portmask\n"); > print_usage(prgname); > return -1; > @@ -1085,8 +1085,8 @@ parse_args(int32_t argc, char **argv) > promiscuous_on =3D 1; > break; > case 'u': > - unprotected_port_mask =3D parse_portmask(optarg); > - if (unprotected_port_mask =3D=3D 0) { > + ret =3D 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 =3D parse_portmask(optarg); > + ret =3D parse_portmask(optarg, &v); > if (ret =3D=3D -1) { > - printf("Invalid argument[portmask]\n"); > + printf("Invalid argument[%s]\n", > + CMD_LINE_OPT_CRYPTODEV_MASK); > print_usage(prgname); > return -1; > } >=20 > /* else */ > - enabled_cryptodev_mask =3D ret; > + enabled_cryptodev_mask =3D v; > break; > default: > print_usage(prgname); > -- > 2.13.6 Regards, Bernard.