4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
5 * Copyright(c) 2017 Cavium, Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #include <rte_errno.h>
49 #include <rte_string_fns.h>
57 case '0': case '1': case '2': case '3': case '4': case '5':
58 case '6': case '7': case '8': case '9':
60 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
62 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
70 parser_read_arg_bool(const char *p)
72 p = skip_white_spaces(p);
75 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
76 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
81 if (((p[0] == 'o') && (p[1] == 'n')) ||
82 ((p[0] == 'O') && (p[1] == 'N'))) {
87 if (((p[0] == 'n') && (p[1] == 'o')) ||
88 ((p[0] == 'N') && (p[1] == 'O'))) {
93 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
94 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
99 p = skip_white_spaces(p);
108 parser_read_uint64(uint64_t *value, const char *p)
113 p = skip_white_spaces(p);
117 val = strtoul(p, &next, 10);
139 p = skip_white_spaces(p);
148 parser_read_int32(int32_t *value, const char *p)
153 p = skip_white_spaces(p);
157 val = strtol(p, &next, 10);
166 parser_read_uint64_hex(uint64_t *value, const char *p)
171 p = skip_white_spaces(p);
173 val = strtoul(p, &next, 16);
177 p = skip_white_spaces(next);
186 parser_read_uint32(uint32_t *value, const char *p)
189 int ret = parser_read_uint64(&val, p);
194 if (val > UINT32_MAX)
202 parser_read_uint32_hex(uint32_t *value, const char *p)
205 int ret = parser_read_uint64_hex(&val, p);
210 if (val > UINT32_MAX)
218 parser_read_uint16(uint16_t *value, const char *p)
221 int ret = parser_read_uint64(&val, p);
226 if (val > UINT16_MAX)
234 parser_read_uint16_hex(uint16_t *value, const char *p)
237 int ret = parser_read_uint64_hex(&val, p);
242 if (val > UINT16_MAX)
250 parser_read_uint8(uint8_t *value, const char *p)
253 int ret = parser_read_uint64(&val, p);
266 parser_read_uint8_hex(uint8_t *value, const char *p)
269 int ret = parser_read_uint64_hex(&val, p);
282 parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens)
286 if ((string == NULL) ||
291 for (i = 0; i < *n_tokens; i++) {
292 tokens[i] = strtok_r(string, PARSE_DELIMITER, &string);
293 if (tokens[i] == NULL)
297 if ((i == *n_tokens) &&
298 (strtok_r(string, PARSE_DELIMITER, &string) != NULL))
306 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
311 /* Check input parameters */
319 if (((len & 3) != 0) ||
324 for (c = src; *c != 0; c++) {
325 if ((((*c) >= '0') && ((*c) <= '9')) ||
326 (((*c) >= 'A') && ((*c) <= 'F')) ||
327 (((*c) >= 'a') && ((*c) <= 'f')))
333 /* Convert chars to bytes */
334 for (i = 0; i < *size; i++)
335 dst[i] = get_hex_val(src[2 * i]) * 16 +
336 get_hex_val(src[2 * i + 1]);
342 parse_lcores_list(bool lcores[], const char *corelist)
348 if (corelist == NULL)
350 while (isblank(*corelist))
352 i = strlen(corelist);
353 while ((i > 0) && isblank(corelist[i - 1]))
356 /* Get list of lcores */
359 while (isblank(*corelist))
361 if (*corelist == '\0')
363 idx = strtoul(corelist, &end, 10);
367 while (isblank(*end))
371 } else if ((*end == ',') || (*end == '\0')) {
373 if (min == RTE_MAX_LCORE)
375 for (idx = min; idx <= max; idx++) {
376 if (lcores[idx] == 1)
385 } while (*end != '\0');