DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jasvinder Singh <jasvinder.singh@intel.com>
To: dev@dpdk.org
Cc: cristian.dumitrescu@intel.com
Subject: [dpdk-dev] [PATCH v3] ip_pipeline: configuration file parser cleanup
Date: Wed, 11 May 2016 17:36:00 +0100	[thread overview]
Message-ID: <1462984560-239866-1-git-send-email-jasvinder.singh@intel.com> (raw)
In-Reply-To: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com>

This patch updates the parsing routines related to packet queues
(pktq_in/out fields in the PIPELINE section) and message queues
(msgq_in/out fields of in the MSGQ Section) specified in ip_pipeline
configuration file.

In the updated routines, function "strtok_r()" is used for parsing the
string instead of manually checking the string termination, white
spaces, tabs etc., between the string tokens. Each call to strtok_r()
returns a pointer to a null-terminated string containing the next token.
If no more tokens are found, strtok_r() returns NULL. As a result of
using strtok_r(), the code size of the parsing routines is reduced
significantly.

Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
---
v3
- add check on the number of pktq_in/out entries
- add check on the number of msgq_in/out entries
 
v2
- update the commit message
- change the local variable name from "token" to "name"

 examples/ip_pipeline/config_parse.c | 190 +++++++++---------------------------
 1 file changed, 44 insertions(+), 146 deletions(-)

diff --git a/examples/ip_pipeline/config_parse.c b/examples/ip_pipeline/config_parse.c
index ab2f637..f09e04f 100644
--- a/examples/ip_pipeline/config_parse.c
+++ b/examples/ip_pipeline/config_parse.c
@@ -1,4 +1,4 @@
-/*-
+/*-
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
@@ -307,6 +307,10 @@ APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n",	\
 	section, entry, message)
 
+#define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max)		\
+APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": "	\
+	"maximum number of elements allowed is %lu\n",	\
+	section, entry, max)
 
 #define PARSE_ERROR_MALLOC(exp)						\
 APP_CHECK(exp, "Parse error: no free memory\n")
@@ -1128,48 +1132,19 @@ parse_pipeline_pcap_sink(struct app_params *app,
 static int
 parse_pipeline_pktq_in(struct app_params *app,
 	struct app_pipeline_params *p,
-	const char *value)
+	char *value)
 {
-	const char *next = value;
-	char *end;
-	char name[APP_PARAM_NAME_SIZE];
-	size_t name_len;
 
-	while (*next != '\0') {
+	while (1) {
 		enum app_pktq_in_type type;
 		int id;
-		char *end_space;
-		char *end_tab;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == NULL)
 			break;
 
-		end_space = strchr(next, ' ');
-		end_tab = strchr(next, '	');
-
-		if (end_space && (!end_tab))
-			end = end_space;
-		else if ((!end_space) && end_tab)
-			end = end_tab;
-		else if (end_space && end_tab)
-			end = RTE_MIN(end_space, end_tab);
-		else
-			end = NULL;
-
-		if (!end)
-			name_len = strlen(next);
-		else
-			name_len = end - next;
-
-		if (name_len == 0 || name_len == sizeof(name))
-			return -EINVAL;
-
-		strncpy(name, next, name_len);
-		name[name_len] = '\0';
-		next += name_len;
-		if (*next != '\0')
-			next++;
+		if (p->n_pktq_in == RTE_DIM(p->pktq_in))
+			return -ENOMEM;
 
 		if (validate_name(name, "RXQ", 2) == 0) {
 			type = APP_PKTQ_IN_HWQ;
@@ -1200,48 +1175,19 @@ parse_pipeline_pktq_in(struct app_params *app,
 static int
 parse_pipeline_pktq_out(struct app_params *app,
 	struct app_pipeline_params *p,
-	const char *value)
+	char *value)
 {
-	const char *next = value;
-	char *end;
-	char name[APP_PARAM_NAME_SIZE];
-	size_t name_len;
-
-	while (*next != '\0') {
-		enum app_pktq_out_type type;
+	while (1) {
+		enum app_pktq_in_type type;
 		int id;
-		char *end_space;
-		char *end_tab;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == NULL)
 			break;
 
-		end_space = strchr(next, ' ');
-		end_tab = strchr(next, '	');
-
-		if (end_space && (!end_tab))
-			end = end_space;
-		else if ((!end_space) && end_tab)
-			end = end_tab;
-		else if (end_space && end_tab)
-			end = RTE_MIN(end_space, end_tab);
-		else
-			end = NULL;
-
-		if (!end)
-			name_len = strlen(next);
-		else
-			name_len = end - next;
-
-		if (name_len == 0 || name_len == sizeof(name))
-			return -EINVAL;
+		if (p->n_pktq_out == RTE_DIM(p->pktq_out))
+			return -ENOMEM;
 
-		strncpy(name, next, name_len);
-		name[name_len] = '\0';
-		next += name_len;
-		if (*next != '\0')
-			next++;
 		if (validate_name(name, "TXQ", 2) == 0) {
 			type = APP_PKTQ_OUT_HWQ;
 			id = APP_PARAM_ADD(app->hwq_out_params, name);
@@ -1271,47 +1217,17 @@ parse_pipeline_pktq_out(struct app_params *app,
 static int
 parse_pipeline_msgq_in(struct app_params *app,
 	struct app_pipeline_params *p,
-	const char *value)
+	char *value)
 {
-	const char *next = value;
-	char *end;
-	char name[APP_PARAM_NAME_SIZE];
-	size_t name_len;
-	ssize_t idx;
-
-	while (*next != '\0') {
-		char *end_space;
-		char *end_tab;
+	while (1) {
+		int idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == NULL)
 			break;
 
-		end_space = strchr(next, ' ');
-		end_tab = strchr(next, '	');
-
-		if (end_space && (!end_tab))
-			end = end_space;
-		else if ((!end_space) && end_tab)
-			end = end_tab;
-		else if (end_space && end_tab)
-			end = RTE_MIN(end_space, end_tab);
-		else
-			end = NULL;
-
-		if (!end)
-			name_len = strlen(next);
-		else
-			name_len = end - next;
-
-		if (name_len == 0 || name_len == sizeof(name))
-			return -EINVAL;
-
-		strncpy(name, next, name_len);
-		name[name_len] = '\0';
-		next += name_len;
-		if (*next != '\0')
-			next++;
+		if (p->n_msgq_in == RTE_DIM(p->msgq_in))
+			return -ENOMEM;
 
 		if (validate_name(name, "MSGQ", 1) != 0)
 			return -EINVAL;
@@ -1330,47 +1246,17 @@ parse_pipeline_msgq_in(struct app_params *app,
 static int
 parse_pipeline_msgq_out(struct app_params *app,
 	struct app_pipeline_params *p,
-	const char *value)
+	char *value)
 {
-	const char *next = value;
-	char *end;
-	char name[APP_PARAM_NAME_SIZE];
-	size_t name_len;
-	ssize_t idx;
-
-	while (*next != '\0') {
-		char *end_space;
-		char *end_tab;
+	while (1) {
+		int idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == NULL)
 			break;
 
-		end_space = strchr(next, ' ');
-		end_tab = strchr(next, '	');
-
-		if (end_space && (!end_tab))
-			end = end_space;
-		else if ((!end_space) && end_tab)
-			end = end_tab;
-		else if (end_space && end_tab)
-			end = RTE_MIN(end_space, end_tab);
-		else
-			end = NULL;
-
-		if (!end)
-			name_len = strlen(next);
-		else
-			name_len = end - next;
-
-		if (name_len == 0 || name_len == sizeof(name))
-			return -EINVAL;
-
-		strncpy(name, next, name_len);
-		name[name_len] = '\0';
-		next += name_len;
-		if (*next != '\0')
-			next++;
+		if (p->n_msgq_out == RTE_DIM(p->msgq_out))
+			return -ENOMEM;
 
 		if (validate_name(name, "MSGQ", 1) != 0)
 			return -EINVAL;
@@ -1438,6 +1324,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_pktq_in(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->pktq_in));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1447,6 +1336,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_pktq_out(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->pktq_out));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1456,6 +1348,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_msgq_in(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->msgq_in));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1465,6 +1360,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_msgq_out(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->msgq_out));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
-- 
2.5.5

  reply	other threads:[~2016-05-11 16:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02 11:53 [dpdk-dev] [PATCH] " Jasvinder Singh
2016-05-03  9:43 ` Bruce Richardson
2016-05-03 13:58 ` [dpdk-dev] [PATCH v2] " Jasvinder Singh
2016-05-11 16:36   ` Jasvinder Singh [this message]
2016-05-30 14:33     ` [dpdk-dev] [PATCH v4] " Jasvinder Singh
2016-06-08 14:48       ` Thomas Monjalon
2016-06-08 16:24         ` Singh, Jasvinder
2016-06-08 16:30       ` [dpdk-dev] [PATCH v5] " Jasvinder Singh
2016-06-08 18:05         ` Thomas Monjalon

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=1462984560-239866-1-git-send-email-jasvinder.singh@intel.com \
    --to=jasvinder.singh@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /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).