2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #ifndef _PARSE_UTILS_H_
18 #define _PARSE_UTILS_H_
21 #include "prox_compat.h"
22 #include "ip_subnet.h"
24 #define MAX_STR_LEN_PROC (3 * MAX_PKT_SIZE + 20)
28 enum ctrl_type {CTRL_TYPE_DP, CTRL_TYPE_MSG, CTRL_TYPE_PKT};
36 struct core_task_set {
37 struct core_task core_task[64];
41 int parse_vars(char *val, size_t len, const char *name);
43 int parse_int_mask(uint32_t* val, uint32_t* mask, const char *saddr);
45 int parse_range(uint32_t* lo, uint32_t* hi, const char *saddr);
47 /* parses CIDR notation. Note that bits within the address that are
48 outside the subnet (as specified by the prefix) are set to 0. */
49 int parse_ip4_and_prefix(struct ip4_subnet *val, const char *saddr);
50 int parse_ip4_cidr(struct ip4_subnet *val, const char *saddr);
51 int parse_ip6_cidr(struct ip6_subnet *val, const char *saddr);
53 int parse_ip(uint32_t *paddr, const char *saddr);
55 int parse_ip6(struct ipv6_addr *addr, const char *saddr);
57 int parse_mac(prox_rte_ether_addr *paddr, const char *saddr);
59 /* return error on overflow or invalid suffix*/
60 int parse_kmg(uint32_t* val, const char *str);
62 int parse_bool(uint32_t* val, const char *str);
64 int parse_flag(uint32_t* val, uint32_t flag, const char *str);
66 int parse_list_set(uint32_t *list, const char *str, uint32_t max_limit);
67 int parse_ip_set(struct ip4_subnet *list, const char *str2, uint32_t max_list);
68 int parse_int_set(uint32_t *list, const char *str2, uint32_t max_list);
70 int parse_task_set(struct core_task_set *val, const char *str);
72 int parse_int(uint32_t* val, const char *str);
73 int parse_float(float* val, const char *str);
75 int parse_u64(uint64_t* val, const char *str);
77 int parse_str(char* dst, const char *str, size_t max_len);
79 int parse_path(char *dst, const char *str, size_t max_len);
81 int parse_port_name(uint32_t *val, const char *str);
83 /* The syntax for random fields is X0010101XXX... where X is a
84 randomized bit and 0, 1 are fixed bit. The resulting mask and fixed
85 arguments are in BE order. */
86 int parse_random_str(uint32_t *mask, uint32_t *fixed, uint32_t *len, const char *str);
88 int parse_port_name_list(uint32_t *val, uint32_t *tot, uint8_t max_vals, const char *str);
90 /* Parses a comma separated list containing a remapping of ports
91 specified by their name. Hence, all port names referenced from the
92 list have to be added using add_port_name() before this function
93 can be used. The first elements in the list are mapped to 0, the
94 second to 1, etc. Multiple elements can be mapped to the same
95 index. If multiple elements are used, they are separated by
96 pipes. An example would be p0|p1,p2|p3. In this example, p0 and p1
97 both map to 0 and p2 and p3 map both map to 1. The mapping should
98 contain at least enough entries as port ids. */
99 int parse_remap(uint8_t *mapping, const char *str);
101 /* Convert an lcore_id to socket notation */
102 int lcore_to_socket_core_ht(uint32_t lcore_id, char *dst, size_t len);
104 int add_port_name(uint32_t val, const char *str);
106 /* The $self variable is something that can change its value (i.e. its
107 value represents the core that is currently being parsed). */
108 int set_self_var(const char *str);
110 int add_var(const char* name, const char *val, uint8_t cli);
112 /* Parses str and returns pointer to the key value */
113 char *get_cfg_key(char *str);
115 /* Changes strings in place. */
116 void strip_spaces(char *strings[], const uint32_t count);
118 /* Contains error string if any of the above returned an error. */
119 const char* get_parse_err(void);
121 /* Returns true if running from a virtual machine. */
122 int is_virtualized(void);
124 int parse_single_var(char *val, size_t len, const char *name);
126 #endif /* _PARSE_UTILS_H_ */