From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 42D474CC5; Thu, 21 Mar 2019 15:03:48 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Mar 2019 07:03:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,253,1549958400"; d="scan'208";a="128923623" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by orsmga006.jf.intel.com with ESMTP; 21 Mar 2019 07:03:45 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.210]) by IRSMSX153.ger.corp.intel.com ([169.254.9.83]) with mapi id 14.03.0415.000; Thu, 21 Mar 2019 14:03:44 +0000 From: "Ananyev, Konstantin" To: "Zhao1, Wei" , "dev@dpdk.org" CC: "stable@dpdk.org" , "Zhang, Qi Z" , "adrien.mazarguil@6wind.com" Thread-Topic: [dpdk-dev] [PATCH] app/testpmd: fix support of hex string parser for flow API Thread-Index: AQHU2w8m9CqXDwnc9ka7SEdDUAG4IKYMcQOAgASnz4CABQ5LgA== Date: Thu, 21 Mar 2019 14:03:43 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258013655E531@irsmsx105.ger.corp.intel.com> References: <1552639435-68184-1-git-send-email-wei.zhao1@intel.com> <2601191342CEEE43887BDE71AB977258013655BE6C@irsmsx105.ger.corp.intel.com> In-Reply-To: Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmU0NTA5NjYtNDkxNy00ZWNkLThhNmYtNzVhYWE2MmE5NGU3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSW51NU9IWGJ3YkdNUXBOXC9TeDZhcmxhMVB2WnBcL1JEQUc1UnIrS0pSd3NndkFiUVU0UkFWUWtVaXROVHc1T05vIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 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] app/testpmd: fix support of hex string parser for flow API 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: Thu, 21 Mar 2019 14:03:49 -0000 Hi Wei, > > > > > > > > There is need for users to set configuration of HEX number for RSS > > > key. The key byte should be pass down as hex number not as char > > > string. This patch enable cmdline flow parse HEX number, in order to > > > not using string which pass ASIC number. > > > > > > Fixes: f4d623f96119 ("app/testpmd: fix missing RSS fields in flow > > > action") > > > Cc: stable@dpdk.org > > > > > > Signed-off-by: Wei Zhao > > > --- > > > app/test-pmd/cmdline_flow.c | 141 > > > +++++++++++++++++++++++++++++++++++++++++++- > > > 1 file changed, 140 insertions(+), 1 deletion(-) > > > > > > diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.= c > > > index 36659a6..2445731 100644 > > > --- a/app/test-pmd/cmdline_flow.c > > > +++ b/app/test-pmd/cmdline_flow.c > > > @@ -35,6 +35,7 @@ enum index { > > > PREFIX, > > > BOOLEAN, > > > STRING, > > > + HEX, > > > MAC_ADDR, > > > IPV4_ADDR, > > > IPV6_ADDR, > > > @@ -1122,6 +1123,9 @@ static int parse_boolean(struct context *, cons= t > > > struct token *, static int parse_string(struct context *, const stru= ct token *, > > > const char *, unsigned int, > > > void *, unsigned int); > > > +static int parse_hex(struct context *ctx, const struct token *token, > > > + const char *str, unsigned int len, > > > + void *buf, unsigned int size); > > > static int parse_mac_addr(struct context *, const struct token *, > > > const char *, unsigned int, > > > void *, unsigned int); > > > @@ -1198,6 +1202,13 @@ static const struct token token_list[] =3D { > > > .call =3D parse_string, > > > .comp =3D comp_none, > > > }, > > > + [HEX] =3D { > > > + .name =3D "{hex}", > > > + .type =3D "HEX", > > > + .help =3D "fixed string", > > > + .call =3D parse_hex, > > > + .comp =3D comp_none, > > > + }, > > > [MAC_ADDR] =3D { > > > .name =3D "{MAC address}", > > > .type =3D "MAC-48", > > > @@ -1544,7 +1555,7 @@ static const struct token token_list[] =3D { > > > .name =3D "pattern", > > > .help =3D "byte string to look for", > > > .next =3D NEXT(item_raw, > > > - NEXT_ENTRY(STRING), > > > + NEXT_ENTRY(HEX), > > > NEXT_ENTRY(ITEM_PARAM_IS, > > > ITEM_PARAM_SPEC, > > > ITEM_PARAM_MASK)), > > > @@ -4475,6 +4486,134 @@ parse_string(struct context *ctx, const struc= t > > token *token, > > > return -1; > > > } > > > > > > +static uint32_t > > > +get_hex_val(char c) > > > +{ > > > + switch (c) { > > > + case '0': case '1': case '2': case '3': case '4': case '5': > > > + case '6': case '7': case '8': case '9': > > > + return c - '0'; > > > + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': > > > + return c - 'A' + 10; > > > + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': > > > + return c - 'a' + 10; > > > + default: > > > + return 0; > > > + } > > > +} > > > + > > > +static int > > > +parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) { > > > + const char *c; > > > + uint32_t i; > > > + > > > + /* Check input parameters */ > > > + if ((src =3D=3D NULL) || > > > + (dst =3D=3D NULL) || > > > + (size =3D=3D NULL) || > > > + (*size =3D=3D 0)) > > > + return -1; > > > + if ((*size & 1) !=3D 0) > > > + return -1; > > > + > > > + for (c =3D src, i =3D 0; i < *size; c++, i++) { > > > + if ((((*c) >=3D '0') && ((*c) <=3D '9')) || > > > + (((*c) >=3D 'A') && ((*c) <=3D 'F')) || > > > + (((*c) >=3D 'a') && ((*c) <=3D 'f'))) > > > + continue; > > > + > > > + return -1; > > > + } > > > + *size =3D *size / 2; > > > + > > > + /* Convert chars to bytes */ > > > + for (i =3D 0; i < *size; i++) > > > + dst[i] =3D get_hex_val(src[2 * i]) * 16 + > > > + get_hex_val(src[2 * i + 1]); > > > + > > > + return 0; > > > +} > > > > What's wrong with strtoul() and friends? > > Why you need to write your own version? > > Konstantin >=20 >=20 > I have try to use strtoul(), but it do not work, because > I want to pars char byte on bye one, not the long string by one time, and= also > RSS KEY can be as long as 100 byte long for i40e, but strtoul() return = only 64 bit long. > app\test-eventdev and examples\ip_pipeline , drivers\net\softnic also use= get_hex_val(), so I will it also. Ok, thanks for explanation. Probably at least you can use isxdigit(), isdigit, toupper(), etc. as Steph= en already suggested. Konstantin >=20 >=20 > > > > > + > > > +static int > > > +parse_hex(struct context *ctx, const struct token *token, > > > + const char *str, unsigned int len, > > > + void *buf, unsigned int size) > > > +{ > > > + const struct arg *arg_data =3D pop_args(ctx); > > > + const struct arg *arg_len =3D pop_args(ctx); > > > + const struct arg *arg_addr =3D pop_args(ctx); > > > + char tmp[16]; /* Ought to be enough. */ > > > + int ret; > > > + unsigned int hexlen =3D len; > > > + uint8_t hex_tmp[16]; > > > + > > > + /* Arguments are expected. */ > > > + if (!arg_data) > > > + return -1; > > > + if (!arg_len) { > > > + push_args(ctx, arg_data); > > > + return -1; > > > + } > > > + if (!arg_addr) { > > > + push_args(ctx, arg_len); > > > + push_args(ctx, arg_data); > > > + return -1; > > > + } > > > + size =3D arg_data->size; > > > + /* Bit-mask fill is not supported. */ > > > + if (arg_data->mask || size < len) > > > + goto error; > > > + if (!ctx->object) > > > + return len; > > > + > > > + /* translate bytes string to array. */ > > > + if (str[0] =3D=3D '0' && ((str[1] =3D=3D 'x') || > > > + (str[1] =3D=3D 'X'))) { > > > + str +=3D 2; > > > + hexlen -=3D 2; > > > + } > > > + parse_hex_string(str, hex_tmp, &hexlen); > > > + /* Let parse_int() fill length information first. */ > > > + ret =3D snprintf(tmp, sizeof(tmp), "%u", hexlen); > > > + if (ret < 0) > > > + goto error; > > > + push_args(ctx, arg_len); > > > + ret =3D parse_int(ctx, token, tmp, ret, NULL, 0); > > > + if (ret < 0) { > > > + pop_args(ctx); > > > + goto error; > > > + } > > > + buf =3D (uint8_t *)ctx->object + arg_data->offset; > > > + /* Output buffer is not necessarily NUL-terminated. */ > > > + memcpy(buf, hex_tmp, hexlen); > > > + memset((uint8_t *)buf + len, 0x00, size - hexlen); > > > + if (ctx->objmask) > > > + memset((uint8_t *)ctx->objmask + arg_data->offset, > > > + 0xff, hexlen); > > > + /* Save address if requested. */ > > > + if (arg_addr->size) { > > > + memcpy((uint8_t *)ctx->object + arg_addr->offset, > > > + (void *[]){ > > > + (uint8_t *)ctx->object + arg_data->offset > > > + }, > > > + arg_addr->size); > > > + if (ctx->objmask) > > > + memcpy((uint8_t *)ctx->objmask + arg_addr->offset, > > > + (void *[]){ > > > + (uint8_t *)ctx->objmask + arg_data->offset > > > + }, > > > + arg_addr->size); > > > + } > > > + return len; > > > +error: > > > + push_args(ctx, arg_addr); > > > + push_args(ctx, arg_len); > > > + push_args(ctx, arg_data); > > > + return -1; > > > + > > > +} > > > + > > > /** > > > * Parse a MAC address. > > > * > > > -- > > > 2.7.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 27379A00E6 for ; Thu, 21 Mar 2019 15:03:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F33511B13C; Thu, 21 Mar 2019 15:03:49 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 42D474CC5; Thu, 21 Mar 2019 15:03:48 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Mar 2019 07:03:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,253,1549958400"; d="scan'208";a="128923623" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by orsmga006.jf.intel.com with ESMTP; 21 Mar 2019 07:03:45 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.210]) by IRSMSX153.ger.corp.intel.com ([169.254.9.83]) with mapi id 14.03.0415.000; Thu, 21 Mar 2019 14:03:44 +0000 From: "Ananyev, Konstantin" To: "Zhao1, Wei" , "dev@dpdk.org" CC: "stable@dpdk.org" , "Zhang, Qi Z" , "adrien.mazarguil@6wind.com" Thread-Topic: [dpdk-dev] [PATCH] app/testpmd: fix support of hex string parser for flow API Thread-Index: AQHU2w8m9CqXDwnc9ka7SEdDUAG4IKYMcQOAgASnz4CABQ5LgA== Date: Thu, 21 Mar 2019 14:03:43 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258013655E531@irsmsx105.ger.corp.intel.com> References: <1552639435-68184-1-git-send-email-wei.zhao1@intel.com> <2601191342CEEE43887BDE71AB977258013655BE6C@irsmsx105.ger.corp.intel.com> In-Reply-To: Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmU0NTA5NjYtNDkxNy00ZWNkLThhNmYtNzVhYWE2MmE5NGU3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSW51NU9IWGJ3YkdNUXBOXC9TeDZhcmxhMVB2WnBcL1JEQUc1UnIrS0pSd3NndkFiUVU0UkFWUWtVaXROVHc1T05vIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] app/testpmd: fix support of hex string parser for flow API 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190321140343.fNT_V2Sh9sravnwMrYj5oSIdr80xYaQZ0NRa3Loi_VU@z> Hi Wei, > > > > > > > > There is need for users to set configuration of HEX number for RSS > > > key. The key byte should be pass down as hex number not as char > > > string. This patch enable cmdline flow parse HEX number, in order to > > > not using string which pass ASIC number. > > > > > > Fixes: f4d623f96119 ("app/testpmd: fix missing RSS fields in flow > > > action") > > > Cc: stable@dpdk.org > > > > > > Signed-off-by: Wei Zhao > > > --- > > > app/test-pmd/cmdline_flow.c | 141 > > > +++++++++++++++++++++++++++++++++++++++++++- > > > 1 file changed, 140 insertions(+), 1 deletion(-) > > > > > > diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.= c > > > index 36659a6..2445731 100644 > > > --- a/app/test-pmd/cmdline_flow.c > > > +++ b/app/test-pmd/cmdline_flow.c > > > @@ -35,6 +35,7 @@ enum index { > > > PREFIX, > > > BOOLEAN, > > > STRING, > > > + HEX, > > > MAC_ADDR, > > > IPV4_ADDR, > > > IPV6_ADDR, > > > @@ -1122,6 +1123,9 @@ static int parse_boolean(struct context *, cons= t > > > struct token *, static int parse_string(struct context *, const stru= ct token *, > > > const char *, unsigned int, > > > void *, unsigned int); > > > +static int parse_hex(struct context *ctx, const struct token *token, > > > + const char *str, unsigned int len, > > > + void *buf, unsigned int size); > > > static int parse_mac_addr(struct context *, const struct token *, > > > const char *, unsigned int, > > > void *, unsigned int); > > > @@ -1198,6 +1202,13 @@ static const struct token token_list[] =3D { > > > .call =3D parse_string, > > > .comp =3D comp_none, > > > }, > > > + [HEX] =3D { > > > + .name =3D "{hex}", > > > + .type =3D "HEX", > > > + .help =3D "fixed string", > > > + .call =3D parse_hex, > > > + .comp =3D comp_none, > > > + }, > > > [MAC_ADDR] =3D { > > > .name =3D "{MAC address}", > > > .type =3D "MAC-48", > > > @@ -1544,7 +1555,7 @@ static const struct token token_list[] =3D { > > > .name =3D "pattern", > > > .help =3D "byte string to look for", > > > .next =3D NEXT(item_raw, > > > - NEXT_ENTRY(STRING), > > > + NEXT_ENTRY(HEX), > > > NEXT_ENTRY(ITEM_PARAM_IS, > > > ITEM_PARAM_SPEC, > > > ITEM_PARAM_MASK)), > > > @@ -4475,6 +4486,134 @@ parse_string(struct context *ctx, const struc= t > > token *token, > > > return -1; > > > } > > > > > > +static uint32_t > > > +get_hex_val(char c) > > > +{ > > > + switch (c) { > > > + case '0': case '1': case '2': case '3': case '4': case '5': > > > + case '6': case '7': case '8': case '9': > > > + return c - '0'; > > > + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': > > > + return c - 'A' + 10; > > > + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': > > > + return c - 'a' + 10; > > > + default: > > > + return 0; > > > + } > > > +} > > > + > > > +static int > > > +parse_hex_string(const char *src, uint8_t *dst, uint32_t *size) { > > > + const char *c; > > > + uint32_t i; > > > + > > > + /* Check input parameters */ > > > + if ((src =3D=3D NULL) || > > > + (dst =3D=3D NULL) || > > > + (size =3D=3D NULL) || > > > + (*size =3D=3D 0)) > > > + return -1; > > > + if ((*size & 1) !=3D 0) > > > + return -1; > > > + > > > + for (c =3D src, i =3D 0; i < *size; c++, i++) { > > > + if ((((*c) >=3D '0') && ((*c) <=3D '9')) || > > > + (((*c) >=3D 'A') && ((*c) <=3D 'F')) || > > > + (((*c) >=3D 'a') && ((*c) <=3D 'f'))) > > > + continue; > > > + > > > + return -1; > > > + } > > > + *size =3D *size / 2; > > > + > > > + /* Convert chars to bytes */ > > > + for (i =3D 0; i < *size; i++) > > > + dst[i] =3D get_hex_val(src[2 * i]) * 16 + > > > + get_hex_val(src[2 * i + 1]); > > > + > > > + return 0; > > > +} > > > > What's wrong with strtoul() and friends? > > Why you need to write your own version? > > Konstantin >=20 >=20 > I have try to use strtoul(), but it do not work, because > I want to pars char byte on bye one, not the long string by one time, and= also > RSS KEY can be as long as 100 byte long for i40e, but strtoul() return = only 64 bit long. > app\test-eventdev and examples\ip_pipeline , drivers\net\softnic also use= get_hex_val(), so I will it also. Ok, thanks for explanation. Probably at least you can use isxdigit(), isdigit, toupper(), etc. as Steph= en already suggested. Konstantin >=20 >=20 > > > > > + > > > +static int > > > +parse_hex(struct context *ctx, const struct token *token, > > > + const char *str, unsigned int len, > > > + void *buf, unsigned int size) > > > +{ > > > + const struct arg *arg_data =3D pop_args(ctx); > > > + const struct arg *arg_len =3D pop_args(ctx); > > > + const struct arg *arg_addr =3D pop_args(ctx); > > > + char tmp[16]; /* Ought to be enough. */ > > > + int ret; > > > + unsigned int hexlen =3D len; > > > + uint8_t hex_tmp[16]; > > > + > > > + /* Arguments are expected. */ > > > + if (!arg_data) > > > + return -1; > > > + if (!arg_len) { > > > + push_args(ctx, arg_data); > > > + return -1; > > > + } > > > + if (!arg_addr) { > > > + push_args(ctx, arg_len); > > > + push_args(ctx, arg_data); > > > + return -1; > > > + } > > > + size =3D arg_data->size; > > > + /* Bit-mask fill is not supported. */ > > > + if (arg_data->mask || size < len) > > > + goto error; > > > + if (!ctx->object) > > > + return len; > > > + > > > + /* translate bytes string to array. */ > > > + if (str[0] =3D=3D '0' && ((str[1] =3D=3D 'x') || > > > + (str[1] =3D=3D 'X'))) { > > > + str +=3D 2; > > > + hexlen -=3D 2; > > > + } > > > + parse_hex_string(str, hex_tmp, &hexlen); > > > + /* Let parse_int() fill length information first. */ > > > + ret =3D snprintf(tmp, sizeof(tmp), "%u", hexlen); > > > + if (ret < 0) > > > + goto error; > > > + push_args(ctx, arg_len); > > > + ret =3D parse_int(ctx, token, tmp, ret, NULL, 0); > > > + if (ret < 0) { > > > + pop_args(ctx); > > > + goto error; > > > + } > > > + buf =3D (uint8_t *)ctx->object + arg_data->offset; > > > + /* Output buffer is not necessarily NUL-terminated. */ > > > + memcpy(buf, hex_tmp, hexlen); > > > + memset((uint8_t *)buf + len, 0x00, size - hexlen); > > > + if (ctx->objmask) > > > + memset((uint8_t *)ctx->objmask + arg_data->offset, > > > + 0xff, hexlen); > > > + /* Save address if requested. */ > > > + if (arg_addr->size) { > > > + memcpy((uint8_t *)ctx->object + arg_addr->offset, > > > + (void *[]){ > > > + (uint8_t *)ctx->object + arg_data->offset > > > + }, > > > + arg_addr->size); > > > + if (ctx->objmask) > > > + memcpy((uint8_t *)ctx->objmask + arg_addr->offset, > > > + (void *[]){ > > > + (uint8_t *)ctx->objmask + arg_data->offset > > > + }, > > > + arg_addr->size); > > > + } > > > + return len; > > > +error: > > > + push_args(ctx, arg_addr); > > > + push_args(ctx, arg_len); > > > + push_args(ctx, arg_data); > > > + return -1; > > > + > > > +} > > > + > > > /** > > > * Parse a MAC address. > > > * > > > -- > > > 2.7.5