3 * Copyright(c) 2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
34 #include <netinet/in.h>
35 #include <netinet/ip.h>
45 #define APP_CHECK(exp, status, fmt, ...) \
48 sprintf(status->parse_msg, fmt "\n", \
50 status->status = -1; \
55 #define APP_CHECK_PRESENCE(val, str, status) \
56 APP_CHECK(val == 0, status, \
57 "item \"%s\" already present", str)
59 #define APP_CHECK_TOKEN_EQUAL(tokens, index, ref, status) \
60 APP_CHECK(strcmp(tokens[index], ref) == 0, status, \
61 "unrecognized input \"%s\": expect \"%s\"\n", \
65 is_str_num(const char *str)
69 for (i = 0; i < strlen(str); i++)
76 #define APP_CHECK_TOKEN_IS_NUM(tokens, index, status) \
77 APP_CHECK(is_str_num(tokens[index]) == 0, status, \
78 "input \"%s\" is not valid number string", tokens[index])
81 #define INCREMENT_TOKEN_INDEX(index, max_num, status) \
83 APP_CHECK(index + 1 < max_num, status, "reaching the end of " \
89 parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask);
92 parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask);
95 parse_range(const char *token, uint16_t *low, uint16_t *high);
98 parse_sp4_tokens(char **tokens, uint32_t n_tokens,
99 struct parse_status *status);
102 parse_sp6_tokens(char **tokens, uint32_t n_tokens,
103 struct parse_status *status);
106 parse_sa_tokens(char **tokens, uint32_t n_tokens,
107 struct parse_status *status);
110 parse_rt_tokens(char **tokens, uint32_t n_tokens,
111 struct parse_status *status);
114 parse_cfg_file(const char *cfg_filename);