From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jasvinder Singh Subject: [PATCH v3] ip_pipeline: configuration file parser cleanup Date: Wed, 11 May 2016 17:36:00 +0100 Message-ID: <1462984560-239866-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: quoted-printable Cc: cristian.dumitrescu@intel.com To: dev@dpdk.org 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) In-Reply-To: <1462283918-108334-1-git-send-email-jasvinder.singh@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 =20 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/c= onfig_parse.c index ab2f637..f09e04f 100644 --- a/examples/ip_pipeline/config_parse.c +++ b/examples/ip_pipeline/config_parse.c @@ -1,4 +1,4 @@ -/*- +=EF=BB=BF/*- * 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) =20 +#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) =20 #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 =3D value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; =20 - while (*next !=3D '\0') { + while (1) { enum app_pktq_in_type type; int id; - char *end_space; - char *end_tab; + char *name =3D strtok_r(value, PARSE_DELIMITER, &value); =20 - next =3D skip_white_spaces(next); - if (!next) + if (name =3D=3D NULL) break; =20 - end_space =3D strchr(next, ' '); - end_tab =3D strchr(next, ' '); - - if (end_space && (!end_tab)) - end =3D end_space; - else if ((!end_space) && end_tab) - end =3D end_tab; - else if (end_space && end_tab) - end =3D RTE_MIN(end_space, end_tab); - else - end =3D NULL; - - if (!end) - name_len =3D strlen(next); - else - name_len =3D end - next; - - if (name_len =3D=3D 0 || name_len =3D=3D sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] =3D '\0'; - next +=3D name_len; - if (*next !=3D '\0') - next++; + if (p->n_pktq_in =3D=3D RTE_DIM(p->pktq_in)) + return -ENOMEM; =20 if (validate_name(name, "RXQ", 2) =3D=3D 0) { type =3D 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 =3D value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - - while (*next !=3D '\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 =3D strtok_r(value, PARSE_DELIMITER, &value); =20 - next =3D skip_white_spaces(next); - if (!next) + if (name =3D=3D NULL) break; =20 - end_space =3D strchr(next, ' '); - end_tab =3D strchr(next, ' '); - - if (end_space && (!end_tab)) - end =3D end_space; - else if ((!end_space) && end_tab) - end =3D end_tab; - else if (end_space && end_tab) - end =3D RTE_MIN(end_space, end_tab); - else - end =3D NULL; - - if (!end) - name_len =3D strlen(next); - else - name_len =3D end - next; - - if (name_len =3D=3D 0 || name_len =3D=3D sizeof(name)) - return -EINVAL; + if (p->n_pktq_out =3D=3D RTE_DIM(p->pktq_out)) + return -ENOMEM; =20 - strncpy(name, next, name_len); - name[name_len] =3D '\0'; - next +=3D name_len; - if (*next !=3D '\0') - next++; if (validate_name(name, "TXQ", 2) =3D=3D 0) { type =3D APP_PKTQ_OUT_HWQ; id =3D 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 =3D value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - ssize_t idx; - - while (*next !=3D '\0') { - char *end_space; - char *end_tab; + while (1) { + int idx; + char *name =3D strtok_r(value, PARSE_DELIMITER, &value); =20 - next =3D skip_white_spaces(next); - if (!next) + if (name =3D=3D NULL) break; =20 - end_space =3D strchr(next, ' '); - end_tab =3D strchr(next, ' '); - - if (end_space && (!end_tab)) - end =3D end_space; - else if ((!end_space) && end_tab) - end =3D end_tab; - else if (end_space && end_tab) - end =3D RTE_MIN(end_space, end_tab); - else - end =3D NULL; - - if (!end) - name_len =3D strlen(next); - else - name_len =3D end - next; - - if (name_len =3D=3D 0 || name_len =3D=3D sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] =3D '\0'; - next +=3D name_len; - if (*next !=3D '\0') - next++; + if (p->n_msgq_in =3D=3D RTE_DIM(p->msgq_in)) + return -ENOMEM; =20 if (validate_name(name, "MSGQ", 1) !=3D 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 =3D value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - ssize_t idx; - - while (*next !=3D '\0') { - char *end_space; - char *end_tab; + while (1) { + int idx; + char *name =3D strtok_r(value, PARSE_DELIMITER, &value); =20 - next =3D skip_white_spaces(next); - if (!next) + if (name =3D=3D NULL) break; =20 - end_space =3D strchr(next, ' '); - end_tab =3D strchr(next, ' '); - - if (end_space && (!end_tab)) - end =3D end_space; - else if ((!end_space) && end_tab) - end =3D end_tab; - else if (end_space && end_tab) - end =3D RTE_MIN(end_space, end_tab); - else - end =3D NULL; - - if (!end) - name_len =3D strlen(next); - else - name_len =3D end - next; - - if (name_len =3D=3D 0 || name_len =3D=3D sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] =3D '\0'; - next +=3D name_len; - if (*next !=3D '\0') - next++; + if (p->n_msgq_out =3D=3D RTE_DIM(p->msgq_out)) + return -ENOMEM; =20 if (validate_name(name, "MSGQ", 1) !=3D 0) return -EINVAL; @@ -1438,6 +1324,9 @@ parse_pipeline(struct app_params *app, int status =3D parse_pipeline_pktq_in(app, param, ent->value); =20 + PARSE_ERROR_TOO_MANY_ELEMENTS((status !=3D -ENOMEM), + section_name, ent->name, + RTE_DIM(param->pktq_in)); PARSE_ERROR((status =3D=3D 0), section_name, ent->name); continue; @@ -1447,6 +1336,9 @@ parse_pipeline(struct app_params *app, int status =3D parse_pipeline_pktq_out(app, param, ent->value); =20 + PARSE_ERROR_TOO_MANY_ELEMENTS((status !=3D -ENOMEM), + section_name, ent->name, + RTE_DIM(param->pktq_out)); PARSE_ERROR((status =3D=3D 0), section_name, ent->name); continue; @@ -1456,6 +1348,9 @@ parse_pipeline(struct app_params *app, int status =3D parse_pipeline_msgq_in(app, param, ent->value); =20 + PARSE_ERROR_TOO_MANY_ELEMENTS((status !=3D -ENOMEM), + section_name, ent->name, + RTE_DIM(param->msgq_in)); PARSE_ERROR((status =3D=3D 0), section_name, ent->name); continue; @@ -1465,6 +1360,9 @@ parse_pipeline(struct app_params *app, int status =3D parse_pipeline_msgq_out(app, param, ent->value); =20 + PARSE_ERROR_TOO_MANY_ELEMENTS((status !=3D -ENOMEM), + section_name, ent->name, + RTE_DIM(param->msgq_out)); PARSE_ERROR((status =3D=3D 0), section_name, ent->name); continue; --=20 2.5.5