xref: /dpdk/examples/ip_pipeline/parser.h (revision 09442498ef736d0a96632cf8b8c15d8ca78a6468)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4 
5 #ifndef __INCLUDE_PARSER_H__
6 #define __INCLUDE_PARSER_H__
7 
8 #include <ctype.h>
9 #include <stdint.h>
10 
11 #include <rte_ip.h>
12 #include <rte_ether.h>
13 
14 #define PARSE_DELIMITER				" \f\n\r\t\v"
15 
16 #define skip_white_spaces(pos)			\
17 ({						\
18 	__typeof__(pos) _p = (pos);		\
19 	for ( ; isspace(*_p); _p++)		\
20 		;				\
21 	_p;					\
22 })
23 
24 static inline size_t
25 skip_digits(const char *src)
26 {
27 	size_t i;
28 
29 	for (i = 0; isdigit(src[i]); i++)
30 		;
31 
32 	return i;
33 }
34 
35 int parser_read_arg_bool(const char *p);
36 
37 int parser_read_uint64(uint64_t *value, const char *p);
38 int parser_read_uint32(uint32_t *value, const char *p);
39 int parser_read_uint16(uint16_t *value, const char *p);
40 int parser_read_uint8(uint8_t *value, const char *p);
41 
42 int parser_read_uint64_hex(uint64_t *value, const char *p);
43 int parser_read_uint32_hex(uint32_t *value, const char *p);
44 int parser_read_uint16_hex(uint16_t *value, const char *p);
45 int parser_read_uint8_hex(uint8_t *value, const char *p);
46 
47 int parse_hex_string(char *src, uint8_t *dst, uint32_t *size);
48 
49 int parse_ipv4_addr(const char *token, struct in_addr *ipv4);
50 int parse_ipv6_addr(const char *token, struct in6_addr *ipv6);
51 int parse_mac_addr(const char *token, struct rte_ether_addr *addr);
52 int parse_mpls_labels(char *string, uint32_t *labels, uint32_t *n_labels);
53 
54 struct cpu_core_params {
55 	uint32_t socket_id;
56 	uint32_t core_id;
57 	uint32_t thread_id;
58 };
59 
60 int parse_cpu_core(const char *entry, struct cpu_core_params *p);
61 
62 int parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens);
63 
64 #endif
65