From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 202975A6B for ; Wed, 11 May 2016 18:29:43 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 11 May 2016 09:29:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,608,1455004800"; d="scan'208";a="700559846" Received: from sie-lab-212-251.ir.intel.com (HELO silpixa00381635.ir.intel.com) ([10.237.212.251]) by FMSMGA003.fm.intel.com with ESMTP; 11 May 2016 09:29:42 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Wed, 11 May 2016 17:36:00 +0100 Message-Id: <1462984560-239866-1-git-send-email-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com> References: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3] ip_pipeline: configuration file parser cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2016 16:29:44 -0000 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 Acked-by: Cristian Dumitrescu --- 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