1 #ifndef _IFCONFIG_PARSE_H
2 #define _IFCONFIG_PARSE_H
8 #include <prop/proplib.h>
9 #include <sys/socket.h>
14 extern struct pbranch command_root
;
16 typedef int (*parser_exec_t
)(prop_dictionary_t
, prop_dictionary_t
);
17 typedef int (*parser_match_t
)(const struct parser
*, const struct match
*,
18 struct match
*, int, const char *);
19 typedef int (*parser_init_t
)(struct parser
*);
22 prop_dictionary_t m_env
;
23 const struct parser
*m_nextparser
;
24 const struct parser
*m_parser
;
30 struct parser_methods
{
31 parser_match_t pm_match
;
32 parser_init_t pm_init
;
36 const struct parser_methods
*p_methods
;
39 struct parser
*p_nextparser
;
44 SIMPLEQ_ENTRY(branch
) b_next
;
45 struct parser
*b_nextparser
;
49 struct parser pb_parser
;
50 SIMPLEQ_HEAD(, branch
) pb_branches
;
52 const struct branch
*pb_brinit
;
57 struct parser pt_parser
;
61 extern const struct parser_methods paddr_methods
;
62 extern const struct parser_methods pbranch_methods
;
63 extern const struct parser_methods piface_methods
;
64 extern const struct parser_methods pinteger_methods
;
65 extern const struct parser_methods pstr_methods
;
66 extern const struct parser_methods pkw_methods
;
67 extern const struct parser_methods pterm_methods
;
69 #define PTERM_INITIALIZER(__pt, __name, __exec, __key) \
71 .pt_parser = {.p_name = (__name), .p_methods = &pterm_methods, \
72 .p_exec = (__exec)}, \
76 #define PBRANCH_INITIALIZER(__pb, __name, __brs, __nbr, __match_first) \
78 .pb_parser = {.p_name = (__name), .p_methods = &pbranch_methods},\
79 .pb_branches = SIMPLEQ_HEAD_INITIALIZER((__pb)->pb_branches), \
80 .pb_brinit = (__brs), \
81 .pb_nbrinit = (__nbr), \
82 .pb_match_first = (__match_first) \
85 #define PSTR_INITIALIZER(__ps, __name, __defexec, __defkey, __defnext) \
87 .ps_parser = {.p_name = (__name), .p_methods = &pstr_methods, \
88 .p_exec = (__defexec), \
89 .p_nextparser = (__defnext)}, \
90 .ps_key = (__defkey) \
93 #define PADDR_INITIALIZER(__pa, __name, __defexec, __addrkey, \
94 __maskkey, __activator, __deactivator, __defnext) \
96 .pa_parser = {.p_name = (__name), .p_methods = &paddr_methods, \
97 .p_exec = (__defexec), \
98 .p_nextparser = (__defnext)}, \
99 .pa_addrkey = (__addrkey), \
100 .pa_maskkey = (__maskkey), \
101 .pa_activator = (__activator), \
102 .pa_deactivator = (__deactivator), \
105 #define PIFACE_INITIALIZER(__pif, __name, __defexec, __defkey, __defnext)\
107 .pif_parser = {.p_name = (__name), .p_methods = &piface_methods,\
108 .p_exec = (__defexec), \
109 .p_nextparser = (__defnext)}, \
110 .pif_key = (__defkey) \
113 #define PINTEGER_INITIALIZER1(__pi, __name, __min, __max, __base, \
114 __defexec, __defkey, __defnext) \
116 .pi_parser = {.p_name = (__name), .p_methods = &pinteger_methods,\
117 .p_exec = (__defexec), \
118 .p_nextparser = (__defnext), \
119 .p_initialized = false}, \
122 .pi_base = (__base), \
123 .pi_key = (__defkey) \
126 #define PINTEGER_INITIALIZER(__pi, __name, __base, __defexec, __defkey, \
128 PINTEGER_INITIALIZER1(__pi, __name, INTMAX_MIN, INTMAX_MAX, \
129 __base, __defexec, __defkey, __defnext)
131 #define PKW_INITIALIZER(__pk, __name, __defexec, __defkey, __kws, __nkw,\
134 .pk_parser = {.p_name = (__name), \
135 .p_exec = (__defexec), \
136 .p_methods = &pkw_methods, \
137 .p_initialized = false}, \
138 .pk_keywords = SIMPLEQ_HEAD_INITIALIZER((__pk)->pk_keywords), \
139 .pk_kwinit = (__kws), \
140 .pk_nkwinit = (__nkw), \
141 .pk_keyinit = (__defkey), \
142 .pk_nextinit = (__defnext) \
145 #define IFKW(__word, __flag) \
147 .k_word = (__word), .k_neg = true, .k_type = KW_T_INT, \
149 .k_negint = -(__flag) \
160 SIMPLEQ_ENTRY(kwinst
) k_next
;
166 const char *k_altdeact
;
167 parser_exec_t k_exec
;
175 #define k_int k_u.u_sint
176 #define k_uint k_u.u_uint
177 #define k_str k_u.u_str
178 #define k_obj k_u.u_obj
179 #define k_bool k_u.u_bool
181 #define k_negint k_negu.u_sint
182 #define k_neguint k_negu.u_uint
183 #define k_negstr k_negu.u_str
184 #define k_negobj k_negu.u_obj
185 #define k_negbool k_negu.u_bool
187 bool k_neg
; /* allow negative form, -keyword */
188 struct parser
*k_nextparser
;
192 struct parser pk_parser
;
194 const char *pk_keyinit
;
195 const struct kwinst
*pk_kwinit
;
197 SIMPLEQ_HEAD(, kwinst
) pk_keywords
;
200 #define pk_nextinit pk_parser.p_nextparser
201 #define pk_execinit pk_parser.p_exec
204 struct parser ps_parser
;
209 struct parser pi_parser
;
217 SIMPLEQ_ENTRY(intrange
) r_next
;
220 struct parser
*r_nextparser
;
224 struct parser pr_parser
;
225 SIMPLEQ_HEAD(, intrange
) pr_ranges
;
228 struct paddr_prefix
{
230 struct sockaddr pfx_addr
;
234 paddr_prefix_size(const struct paddr_prefix
*pfx
)
236 return offsetof(struct paddr_prefix
, pfx_addr
) + pfx
->pfx_addr
.sa_len
;
240 struct parser pa_parser
;
241 const char *pa_addrkey
;
242 const char *pa_maskkey
;
243 const char *pa_activator
;
244 const char *pa_deactivator
;
248 struct parser pif_parser
;
253 struct parser pr_parser
;
256 struct prest
*prest_create(const char *);
257 struct paddr
*paddr_create(const char *, parser_exec_t
, const char *,
258 const char *, struct parser
*);
259 struct pstr
*pstr_create(const char *, parser_exec_t
, const char *,
261 struct piface
*piface_create(const char *, parser_exec_t
, const char *,
263 struct pkw
*pkw_create(const char *, parser_exec_t
,
264 const char *, const struct kwinst
*, size_t, struct parser
*);
265 struct pranges
*pranges_create(const char *, parser_exec_t
, const char *,
266 const struct intrange
*, size_t, struct parser
*);
267 struct pbranch
*pbranch_create(const char *, const struct branch
*, size_t,
269 int pbranch_addbranch(struct pbranch
*, struct parser
*);
270 int pbranch_setbranches(struct pbranch
*, const struct branch
*, size_t);
272 int parse(int, char **, const struct parser
*, struct match
*, size_t *, int *);
274 int matches_exec(const struct match
*, prop_dictionary_t
, size_t);
275 int parser_init(struct parser
*);
277 #endif /* _IFCONFIG_PARSE_H */