From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6C998A0550; Fri, 26 Aug 2022 15:19:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2E7C442B8A; Fri, 26 Aug 2022 15:18:14 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 2C7C940146 for ; Fri, 26 Aug 2022 15:18:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661519881; x=1693055881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hhYZpnJbye2whXHor56BZiXrf4sh5xozfMQnlg71bYw=; b=LBI8Gc2s3wv9qiwaTspxxgD5wbT9NnXwiLOzgMbmy+Wttc8b/hzWYqBN csDg8CaOTc3tEngiQ1OJWoF7YBbicyqb/2YD1Dm65gQeEHWys/btfC3GE 8ybXljsjfcTw8MTS0Itd7xwd5cPfsegrEs/LjBZ/X0QDzoPe3N1uB6mio o/tKaOXa0gQDegXJVOxEm/ZZx+STZVpuUKy91VcxVv5z1b5CS1JgtYxeB wg1pwjukNSzQTsw/K6HshwJEoXT0WYelmOWwG17ilSmz8XePDKqj7tsBu o6l894KxITvwK0OOUfvUXxyLqwhhiHnK0vLgXP3HmWrHV0i5XxB432D9m g==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="320598579" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="320598579" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 06:17:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="610561634" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga002.jf.intel.com with ESMTP; 26 Aug 2022 06:17:47 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Yogesh Jangra Subject: [PATCH V2 09/21] net/softnic: remove unused text parsing functions Date: Fri, 26 Aug 2022 13:17:25 +0000 Message-Id: <20220826131737.1741743-10-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220826131737.1741743-1-cristian.dumitrescu@intel.com> References: <20220804165839.1074817-1-cristian.dumitrescu@intel.com> <20220826131737.1741743-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Remove the text parsing functions that are not used. Signed-off-by: Cristian Dumitrescu Signed-off-by: Yogesh Jangra --- drivers/net/softnic/meson.build | 1 - drivers/net/softnic/parser.c | 523 ---------------------- drivers/net/softnic/parser.h | 68 --- drivers/net/softnic/rte_eth_softnic_cli.c | 54 ++- 4 files changed, 46 insertions(+), 600 deletions(-) delete mode 100644 drivers/net/softnic/parser.c delete mode 100644 drivers/net/softnic/parser.h diff --git a/drivers/net/softnic/meson.build b/drivers/net/softnic/meson.build index 0ffe26d671..5dfbd16c77 100644 --- a/drivers/net/softnic/meson.build +++ b/drivers/net/softnic/meson.build @@ -8,7 +8,6 @@ endif headers = files('rte_eth_softnic.h') sources = files( 'conn.c', - 'parser.c', 'rte_eth_softnic.c', 'rte_eth_softnic_cli.c', 'rte_eth_softnic_mempool.c', diff --git a/drivers/net/softnic/parser.c b/drivers/net/softnic/parser.c deleted file mode 100644 index ebcb10268a..0000000000 --- a/drivers/net/softnic/parser.c +++ /dev/null @@ -1,523 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2016 Intel Corporation. - * Copyright (c) 2009, Olivier MATZ - * All rights reserved. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "parser.h" - -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; - } -} - -int -softnic_parser_read_arg_bool(const char *p) -{ - p = skip_white_spaces(p); - int result = -EINVAL; - - if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) || - ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) { - p += 3; - result = 1; - } - - if (((p[0] == 'o') && (p[1] == 'n')) || - ((p[0] == 'O') && (p[1] == 'N'))) { - p += 2; - result = 1; - } - - if (((p[0] == 'n') && (p[1] == 'o')) || - ((p[0] == 'N') && (p[1] == 'O'))) { - p += 2; - result = 0; - } - - if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) || - ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) { - p += 3; - result = 0; - } - - p = skip_white_spaces(p); - - if (p[0] != '\0') - return -EINVAL; - - return result; -} - -int -softnic_parser_read_int32(int32_t *value, const char *p) -{ - char *next; - int32_t val; - - p = skip_white_spaces(p); - if (!isdigit(*p)) - return -EINVAL; - - val = strtol(p, &next, 10); - if (p == next) - return -EINVAL; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint64(uint64_t *value, const char *p) -{ - char *next; - uint64_t val; - - p = skip_white_spaces(p); - if (!isdigit(*p)) - return -EINVAL; - - val = strtoul(p, &next, 10); - if (p == next) - return -EINVAL; - - p = next; - switch (*p) { - case 'T': - val *= 1024ULL; - /* fall through */ - case 'G': - val *= 1024ULL; - /* fall through */ - case 'M': - val *= 1024ULL; - /* fall through */ - case 'k': - case 'K': - val *= 1024ULL; - p++; - break; - } - - p = skip_white_spaces(p); - if (*p != '\0') - return -EINVAL; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint64_hex(uint64_t *value, const char *p) -{ - char *next; - uint64_t val; - - p = skip_white_spaces(p); - - val = strtoul(p, &next, 16); - if (p == next) - return -EINVAL; - - p = skip_white_spaces(next); - if (*p != '\0') - return -EINVAL; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint32(uint32_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT32_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint32_hex(uint32_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64_hex(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT32_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint16(uint16_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT16_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint16_hex(uint16_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64_hex(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT16_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint8(uint8_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT8_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parser_read_uint8_hex(uint8_t *value, const char *p) -{ - uint64_t val = 0; - int ret = softnic_parser_read_uint64_hex(&val, p); - - if (ret < 0) - return ret; - - if (val > UINT8_MAX) - return -ERANGE; - - *value = val; - return 0; -} - -int -softnic_parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) -{ - uint32_t i; - - if (string == NULL || - tokens == NULL || - (*n_tokens < 1)) - return -EINVAL; - - for (i = 0; i < *n_tokens; i++) { - tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); - if (tokens[i] == NULL) - break; - } - - if (i == *n_tokens && - strtok_r(string, PARSE_DELIMITER, &string) != NULL) - return -E2BIG; - - *n_tokens = i; - return 0; -} - -int -softnic_parse_hex_string(char *src, uint8_t *dst, uint32_t *size) -{ - char *c; - uint32_t len, i; - - /* Check input parameters */ - if (src == NULL || - dst == NULL || - size == NULL || - (*size == 0)) - return -1; - - len = strlen(src); - if (((len & 3) != 0) || - (len > (*size) * 2)) - return -1; - *size = len / 2; - - for (c = src; *c != 0; c++) { - if ((((*c) >= '0') && ((*c) <= '9')) || - (((*c) >= 'A') && ((*c) <= 'F')) || - (((*c) >= 'a') && ((*c) <= 'f'))) - continue; - - return -1; - } - - /* Convert chars to bytes */ - for (i = 0; i < *size; i++) - dst[i] = get_hex_val(src[2 * i]) * 16 + - get_hex_val(src[2 * i + 1]); - - return 0; -} - -int -softnic_parse_mpls_labels(char *string, uint32_t *labels, uint32_t *n_labels) -{ - uint32_t n_max_labels = *n_labels, count = 0; - - /* Check for void list of labels */ - if (strcmp(string, "") == 0) { - *n_labels = 0; - return 0; - } - - /* At least one label should be present */ - for ( ; (*string != '\0'); ) { - char *next; - int value; - - if (count >= n_max_labels) - return -1; - - if (count > 0) { - if (string[0] != ':') - return -1; - - string++; - } - - value = strtol(string, &next, 10); - if (next == string) - return -1; - string = next; - - labels[count++] = (uint32_t)value; - } - - *n_labels = count; - return 0; -} - -static struct rte_ether_addr * -my_ether_aton(const char *a) -{ - int i; - char *end; - unsigned long o[RTE_ETHER_ADDR_LEN]; - static struct rte_ether_addr ether_addr; - - i = 0; - do { - errno = 0; - o[i] = strtoul(a, &end, 16); - if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0)) - return NULL; - a = end + 1; - } while (++i != sizeof(o) / sizeof(o[0]) && end[0] != 0); - - /* Junk at the end of line */ - if (end[0] != 0) - return NULL; - - /* Support the format XX:XX:XX:XX:XX:XX */ - if (i == RTE_ETHER_ADDR_LEN) { - while (i-- != 0) { - if (o[i] > UINT8_MAX) - return NULL; - ether_addr.addr_bytes[i] = (uint8_t)o[i]; - } - /* Support the format XXXX:XXXX:XXXX */ - } else if (i == RTE_ETHER_ADDR_LEN / 2) { - while (i-- != 0) { - if (o[i] > UINT16_MAX) - return NULL; - ether_addr.addr_bytes[i * 2] = (uint8_t)(o[i] >> 8); - ether_addr.addr_bytes[i * 2 + 1] = (uint8_t)(o[i] & 0xff); - } - /* unknown format */ - } else - return NULL; - - return (struct rte_ether_addr *)ðer_addr; -} - -int -softnic_parse_ipv4_addr(const char *token, struct in_addr *ipv4) -{ - if (strlen(token) >= INET_ADDRSTRLEN) - return -EINVAL; - - if (inet_pton(AF_INET, token, ipv4) != 1) - return -EINVAL; - - return 0; -} - -int -softnic_parse_ipv6_addr(const char *token, struct in6_addr *ipv6) -{ - if (strlen(token) >= INET6_ADDRSTRLEN) - return -EINVAL; - - if (inet_pton(AF_INET6, token, ipv6) != 1) - return -EINVAL; - - return 0; -} - -int -softnic_parse_mac_addr(const char *token, struct rte_ether_addr *addr) -{ - struct rte_ether_addr *tmp; - - tmp = my_ether_aton(token); - if (tmp == NULL) - return -1; - - memcpy(addr, tmp, sizeof(struct rte_ether_addr)); - return 0; -} - -int -softnic_parse_cpu_core(const char *entry, - struct softnic_cpu_core_params *p) -{ - size_t num_len; - char num[8]; - - uint32_t s = 0, c = 0, h = 0, val; - uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0; - const char *next = skip_white_spaces(entry); - char type; - - if (p == NULL) - return -EINVAL; - - /* Expect or [sX][cY][h]. At least one parameter is required. */ - while (*next != '\0') { - /* If everything parsed nothing should left */ - if (s_parsed && c_parsed && h_parsed) - return -EINVAL; - - type = *next; - switch (type) { - case 's': - case 'S': - if (s_parsed || c_parsed || h_parsed) - return -EINVAL; - s_parsed = 1; - next++; - break; - case 'c': - case 'C': - if (c_parsed || h_parsed) - return -EINVAL; - c_parsed = 1; - next++; - break; - case 'h': - case 'H': - if (h_parsed) - return -EINVAL; - h_parsed = 1; - next++; - break; - default: - /* If it start from digit it must be only core id. */ - if (!isdigit(*next) || s_parsed || c_parsed || h_parsed) - return -EINVAL; - - type = 'C'; - } - - for (num_len = 0; *next != '\0'; next++, num_len++) { - if (num_len == RTE_DIM(num)) - return -EINVAL; - - if (!isdigit(*next)) - break; - - num[num_len] = *next; - } - - if (num_len == 0 && type != 'h' && type != 'H') - return -EINVAL; - - if (num_len != 0 && (type == 'h' || type == 'H')) - return -EINVAL; - - num[num_len] = '\0'; - val = strtol(num, NULL, 10); - - h = 0; - switch (type) { - case 's': - case 'S': - s = val; - break; - case 'c': - case 'C': - c = val; - break; - case 'h': - case 'H': - h = 1; - break; - } - } - - p->socket_id = s; - p->core_id = c; - p->thread_id = h; - return 0; -} diff --git a/drivers/net/softnic/parser.h b/drivers/net/softnic/parser.h deleted file mode 100644 index 6f408b2485..0000000000 --- a/drivers/net/softnic/parser.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2016 Intel Corporation - */ - -#ifndef __INCLUDE_SOFTNIC_PARSER_H__ -#define __INCLUDE_SOFTNIC_PARSER_H__ - -#include - -#include -#include - -#define PARSE_DELIMITER " \f\n\r\t\v" - -#define skip_white_spaces(pos) \ -({ \ - __typeof__(pos) _p = (pos); \ - for ( ; isspace(*_p); _p++) \ - ; \ - _p; \ -}) - -static inline size_t -skip_digits(const char *src) -{ - size_t i; - - for (i = 0; isdigit(src[i]); i++) - ; - - return i; -} - -int softnic_parser_read_arg_bool(const char *p); - -int softnic_parser_read_int32(int32_t *value, const char *p); - -int softnic_parser_read_uint64(uint64_t *value, const char *p); -int softnic_parser_read_uint32(uint32_t *value, const char *p); -int softnic_parser_read_uint16(uint16_t *value, const char *p); -int softnic_parser_read_uint8(uint8_t *value, const char *p); - -int softnic_parser_read_uint64_hex(uint64_t *value, const char *p); -int softnic_parser_read_uint32_hex(uint32_t *value, const char *p); -int softnic_parser_read_uint16_hex(uint16_t *value, const char *p); -int softnic_parser_read_uint8_hex(uint8_t *value, const char *p); - -int softnic_parse_hex_string(char *src, uint8_t *dst, uint32_t *size); - -int softnic_parse_ipv4_addr(const char *token, struct in_addr *ipv4); -int softnic_parse_ipv6_addr(const char *token, struct in6_addr *ipv6); -int softnic_parse_mac_addr(const char *token, struct rte_ether_addr *addr); -int softnic_parse_mpls_labels(char *string, - uint32_t *labels, uint32_t *n_labels); - -struct softnic_cpu_core_params { - uint32_t socket_id; - uint32_t core_id; - uint32_t thread_id; -}; - -int softnic_parse_cpu_core(const char *entry, - struct softnic_cpu_core_params *p); - -int softnic_parse_tokenize_string(char *string, - char *tokens[], uint32_t *n_tokens); - -#endif diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c index ec9ac133b9..9de17fba8f 100644 --- a/drivers/net/softnic/rte_eth_softnic_cli.c +++ b/drivers/net/softnic/rte_eth_softnic_cli.c @@ -12,7 +12,6 @@ #include #include "rte_eth_softnic_internals.h" -#include "parser.h" #ifndef CMD_MAX_TOKENS #define CMD_MAX_TOKENS 256 @@ -30,6 +29,45 @@ #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n" #define MSG_CMD_FAIL "Command \"%s\" failed.\n" +static int +parser_read_uint32(uint32_t *value, char *p) +{ + uint32_t val = 0; + + if (!value || !p || !p[0]) + return -EINVAL; + + val = strtoul(p, &p, 0); + if (p[0]) + return -EINVAL; + + *value = val; + return 0; +} + +#define PARSE_DELIMITER " \f\n\r\t\v" + +static int +parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens) +{ + uint32_t i; + + if (!string || !tokens || !n_tokens || !*n_tokens) + return -EINVAL; + + for (i = 0; i < *n_tokens; i++) { + tokens[i] = strtok_r(string, PARSE_DELIMITER, &string); + if (!tokens[i]) + break; + } + + if (i == *n_tokens && strtok_r(string, PARSE_DELIMITER, &string)) + return -E2BIG; + + *n_tokens = i; + return 0; +} + static int is_comment(char *in) { @@ -70,7 +108,7 @@ cmd_mempool(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&p.buffer_size, tokens[3]) != 0) { + if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size"); return; } @@ -80,7 +118,7 @@ cmd_mempool(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&p.pool_size, tokens[5]) != 0) { + if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "pool_size"); return; } @@ -90,7 +128,7 @@ cmd_mempool(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&p.cache_size, tokens[7]) != 0) { + if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "cache_size"); return; } @@ -129,7 +167,7 @@ cmd_swq(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&p.size, tokens[3]) != 0) { + if (parser_read_uint32(&p.size, tokens[3]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "size"); return; } @@ -161,7 +199,7 @@ cmd_softnic_thread_pipeline_enable(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) { + if (parser_read_uint32(&thread_id, tokens[1]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); return; } @@ -210,7 +248,7 @@ cmd_softnic_thread_pipeline_disable(struct pmd_internals *softnic, return; } - if (softnic_parser_read_uint32(&thread_id, tokens[1]) != 0) { + if (parser_read_uint32(&thread_id, tokens[1]) != 0) { snprintf(out, out_size, MSG_ARG_INVALID, "thread_id"); return; } @@ -251,7 +289,7 @@ softnic_cli_process(char *in, char *out, size_t out_size, void *arg) if (is_comment(in)) return; - status = softnic_parse_tokenize_string(in, tokens, &n_tokens); + status = parse_tokenize_string(in, tokens, &n_tokens); if (status) { snprintf(out, out_size, MSG_ARG_TOO_MANY, ""); return; -- 2.34.1