DPDK patches and discussions
 help / color / mirror / Atom feed
From: Wei Zhao <wei.zhao1@intel.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, ferruh.yigit@intel.com, yuan.peng@intel.com,
	Wei Zhao <wei.zhao1@intel.com>
Subject: [dpdk-dev] [PATCH v4] app/testpmd: fix support of hex string parser for flow API
Date: Tue,  9 Apr 2019 16:41:31 +0800	[thread overview]
Message-ID: <1554799291-18471-1-git-send-email-wei.zhao1@intel.com> (raw)
Message-ID: <20190409084131.W4MpfNTnoY_-MR7DIaUGMOW83ZrAlPtA5c1uzqXVPFg@z> (raw)
In-Reply-To: <1553224548-37749-1-git-send-email-wei.zhao1@intel.com>

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 <wei.zhao1@intel.com>
Tested-by: Peng Yuan <yuan.peng@intel.com>

---

v2:
fix bug of string length limite.

v3:
use isxdigit to check char string

v4:
fix bug in set memory to zero and change code for translating
string to hex
---
 app/test-pmd/cmdline_flow.c | 128 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 127 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 1c83bc9..54ff175 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -36,6 +36,7 @@ enum index {
 	PREFIX,
 	BOOLEAN,
 	STRING,
+	HEX,
 	MAC_ADDR,
 	IPV4_ADDR,
 	IPV6_ADDR,
@@ -1123,6 +1124,9 @@ static int parse_boolean(struct context *, const struct token *,
 static int parse_string(struct context *, const struct 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);
@@ -1199,6 +1203,13 @@ static const struct token token_list[] = {
 		.call = parse_string,
 		.comp = comp_none,
 	},
+	[HEX] = {
+		.name = "{hex}",
+		.type = "HEX",
+		.help = "fixed string",
+		.call = parse_hex,
+		.comp = comp_none,
+	},
 	[MAC_ADDR] = {
 		.name = "{MAC address}",
 		.type = "MAC-48",
@@ -2307,7 +2318,7 @@ static const struct token token_list[] = {
 	[ACTION_RSS_KEY] = {
 		.name = "key",
 		.help = "RSS hash key",
-		.next = NEXT(action_rss, NEXT_ENTRY(STRING)),
+		.next = NEXT(action_rss, NEXT_ENTRY(HEX)),
 		.args = ARGS(ARGS_ENTRY_ARB(0, 0),
 			     ARGS_ENTRY_ARB
 			     (offsetof(struct action_rss_data, conf) +
@@ -4476,6 +4487,121 @@ parse_string(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+static int
+parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
+{
+	char *c = NULL;
+	uint32_t i, len;
+	char tmp[3];
+
+	/* Check input parameters */
+	if ((src == NULL) ||
+		(dst == NULL) ||
+		(size == NULL) ||
+		(*size == 0))
+		return -1;
+
+	/* Convert chars to bytes */
+	for (i = 0, len = 0; i < *size; i += 2) {
+		snprintf(tmp, 3, "%s", src + i);
+		dst[len++] = strtoul(tmp, &c, 16);
+		if (*c != 0) {
+			len--;
+			dst[len] = 0;
+			*size = len;
+			return -1;
+		}
+	}
+	dst[len] = 0;
+	*size = len;
+
+	return 0;
+}
+
+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 = pop_args(ctx);
+	const struct arg *arg_len = pop_args(ctx);
+	const struct arg *arg_addr = pop_args(ctx);
+	char tmp[16]; /* Ought to be enough. */
+	int ret;
+	unsigned int hexlen = len;
+	unsigned int length = 256;
+	uint8_t hex_tmp[length];
+
+	/* 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 = arg_data->size;
+	/* Bit-mask fill is not supported. */
+	if (arg_data->mask)
+		goto error;
+	if (!ctx->object)
+		return len;
+
+	/* translate bytes string to array. */
+	if (str[0] == '0' && ((str[1] == 'x') ||
+			(str[1] == 'X'))) {
+		str += 2;
+		hexlen -= 2;
+	}
+	if (hexlen > length)
+		return -1;
+	ret = parse_hex_string(str, hex_tmp, &hexlen);
+	if (ret < 0)
+		goto error;
+	/* Let parse_int() fill length information first. */
+	ret = snprintf(tmp, sizeof(tmp), "%u", hexlen);
+	if (ret < 0)
+		goto error;
+	push_args(ctx, arg_len);
+	ret = parse_int(ctx, token, tmp, ret, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		goto error;
+	}
+	buf = (uint8_t *)ctx->object + arg_data->offset;
+	/* Output buffer is not necessarily NUL-terminated. */
+	memcpy(buf, hex_tmp, hexlen);
+	memset((uint8_t *)buf + hexlen, 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


  parent reply	other threads:[~2019-04-09  9:09 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15  8:43 [dpdk-dev] [PATCH] " Wei Zhao
2019-03-15  8:43 ` Wei Zhao
2019-03-15  9:44 ` Ananyev, Konstantin
2019-03-15  9:44   ` Ananyev, Konstantin
2019-03-18  1:36   ` Zhao1, Wei
2019-03-18  1:36     ` Zhao1, Wei
2019-03-18  8:49   ` Zhao1, Wei
2019-03-18  8:49     ` Zhao1, Wei
2019-03-21 14:03     ` Ananyev, Konstantin
2019-03-21 14:03       ` Ananyev, Konstantin
2019-03-22  1:34       ` Zhao1, Wei
2019-03-22  1:34         ` Zhao1, Wei
2019-03-18  8:16 ` [dpdk-dev] [PATCH v2] " Wei Zhao
2019-03-18  8:16   ` Wei Zhao
2019-03-19  5:23   ` Zhao1, Wei
2019-03-19  5:23     ` Zhao1, Wei
2019-03-22  3:15   ` [dpdk-dev] [PATCH v3] " Wei Zhao
2019-03-22  3:15     ` Wei Zhao
2019-03-22 14:56     ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2019-03-22 14:56       ` Ferruh Yigit
2019-03-25  3:39       ` Zhao1, Wei
2019-03-25  3:39         ` Zhao1, Wei
2019-03-25  8:45         ` Ferruh Yigit
2019-03-25  8:45           ` Ferruh Yigit
2019-03-25  9:25           ` Zhao1, Wei
2019-03-25  9:25             ` Zhao1, Wei
2019-03-25  9:35             ` Ferruh Yigit
2019-03-25  9:35               ` Ferruh Yigit
2019-03-25  9:39               ` Zhao1, Wei
2019-03-25  9:39                 ` Zhao1, Wei
2019-04-09  7:38       ` Zhao1, Wei
2019-04-09  7:38         ` Zhao1, Wei
2019-04-09  8:44         ` Ferruh Yigit
2019-04-09  8:44           ` Ferruh Yigit
2019-04-09  9:12           ` Zhao1, Wei
2019-04-09  9:12             ` Zhao1, Wei
2019-04-09  7:40       ` Zhao1, Wei
2019-04-09  7:40         ` Zhao1, Wei
2019-04-09  7:42       ` Zhao1, Wei
2019-04-09  7:42         ` Zhao1, Wei
2019-04-09  8:41     ` Wei Zhao [this message]
2019-04-09  8:41       ` [dpdk-dev] [PATCH v4] " Wei Zhao
2019-04-11 18:40       ` Ferruh Yigit
2019-04-11 18:40         ` Ferruh Yigit
2019-03-18 15:27 ` [dpdk-dev] [PATCH] " Stephen Hemminger
2019-03-18 15:27   ` Stephen Hemminger
2019-03-22  1:34   ` Zhao1, Wei
2019-03-22  1:34     ` Zhao1, Wei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1554799291-18471-1-git-send-email-wei.zhao1@intel.com \
    --to=wei.zhao1@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=stable@dpdk.org \
    --cc=yuan.peng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).