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) \
86 PSTR_INITIALIZER1((__ps), (__name), (__defexec), (__defkey), \
89 #define PSTR_INITIALIZER1(__ps, __name, __defexec, __defkey, __defhexok,\
92 .ps_parser = {.p_name = (__name), .p_methods = &pstr_methods, \
93 .p_exec = (__defexec), \
94 .p_nextparser = (__defnext)}, \
95 .ps_key = (__defkey), \
96 .ps_hexok = (__defhexok) \
99 #define PADDR_INITIALIZER(__pa, __name, __defexec, __addrkey, \
100 __maskkey, __activator, __deactivator, __defnext) \
102 .pa_parser = {.p_name = (__name), .p_methods = &paddr_methods, \
103 .p_exec = (__defexec), \
104 .p_nextparser = (__defnext)}, \
105 .pa_addrkey = (__addrkey), \
106 .pa_maskkey = (__maskkey), \
107 .pa_activator = (__activator), \
108 .pa_deactivator = (__deactivator), \
111 #define PIFACE_INITIALIZER(__pif, __name, __defexec, __defkey, __defnext)\
113 .pif_parser = {.p_name = (__name), .p_methods = &piface_methods,\
114 .p_exec = (__defexec), \
115 .p_nextparser = (__defnext)}, \
116 .pif_key = (__defkey) \
119 #define PINTEGER_INITIALIZER1(__pi, __name, __min, __max, __base, \
120 __defexec, __defkey, __defnext) \
122 .pi_parser = {.p_name = (__name), .p_methods = &pinteger_methods,\
123 .p_exec = (__defexec), \
124 .p_nextparser = (__defnext), \
125 .p_initialized = false}, \
128 .pi_base = (__base), \
129 .pi_key = (__defkey) \
132 #define PINTEGER_INITIALIZER(__pi, __name, __base, __defexec, __defkey, \
134 PINTEGER_INITIALIZER1(__pi, __name, INTMAX_MIN, INTMAX_MAX, \
135 __base, __defexec, __defkey, __defnext)
137 #define PKW_INITIALIZER(__pk, __name, __defexec, __defkey, __kws, __nkw,\
140 .pk_parser = {.p_name = (__name), \
141 .p_exec = (__defexec), \
142 .p_methods = &pkw_methods, \
143 .p_initialized = false}, \
144 .pk_keywords = SIMPLEQ_HEAD_INITIALIZER((__pk)->pk_keywords), \
145 .pk_kwinit = (__kws), \
146 .pk_nkwinit = (__nkw), \
147 .pk_keyinit = (__defkey), \
148 .pk_nextinit = (__defnext) \
151 #define IFKW(__word, __flag) \
153 .k_word = (__word), .k_neg = true, .k_type = KW_T_INT, \
155 .k_negint = -(__flag) \
166 SIMPLEQ_ENTRY(kwinst
) k_next
;
172 const char *k_altdeact
;
173 parser_exec_t k_exec
;
181 #define k_int k_u.u_sint
182 #define k_uint k_u.u_uint
183 #define k_str k_u.u_str
184 #define k_obj k_u.u_obj
185 #define k_bool k_u.u_bool
187 #define k_negint k_negu.u_sint
188 #define k_neguint k_negu.u_uint
189 #define k_negstr k_negu.u_str
190 #define k_negobj k_negu.u_obj
191 #define k_negbool k_negu.u_bool
193 bool k_neg
; /* allow negative form, -keyword */
194 struct parser
*k_nextparser
;
198 struct parser pk_parser
;
200 const char *pk_keyinit
;
201 const struct kwinst
*pk_kwinit
;
203 SIMPLEQ_HEAD(, kwinst
) pk_keywords
;
206 #define pk_nextinit pk_parser.p_nextparser
207 #define pk_execinit pk_parser.p_exec
210 struct parser ps_parser
;
216 struct parser pi_parser
;
224 SIMPLEQ_ENTRY(intrange
) r_next
;
227 struct parser
*r_nextparser
;
231 struct parser pr_parser
;
232 SIMPLEQ_HEAD(, intrange
) pr_ranges
;
235 struct paddr_prefix
{
237 struct sockaddr pfx_addr
;
241 paddr_prefix_size(const struct paddr_prefix
*pfx
)
243 return offsetof(struct paddr_prefix
, pfx_addr
) + pfx
->pfx_addr
.sa_len
;
247 struct parser pa_parser
;
248 const char *pa_addrkey
;
249 const char *pa_maskkey
;
250 const char *pa_activator
;
251 const char *pa_deactivator
;
255 struct parser pif_parser
;
260 struct parser pr_parser
;
263 struct prest
*prest_create(const char *);
264 struct paddr
*paddr_create(const char *, parser_exec_t
, const char *,
265 const char *, struct parser
*);
266 struct pstr
*pstr_create(const char *, parser_exec_t
, const char *,
267 bool, struct parser
*);
268 struct piface
*piface_create(const char *, parser_exec_t
, const char *,
270 struct pkw
*pkw_create(const char *, parser_exec_t
,
271 const char *, const struct kwinst
*, size_t, struct parser
*);
272 struct pranges
*pranges_create(const char *, parser_exec_t
, const char *,
273 const struct intrange
*, size_t, struct parser
*);
274 struct pbranch
*pbranch_create(const char *, const struct branch
*, size_t,
276 int pbranch_addbranch(struct pbranch
*, struct parser
*);
277 int pbranch_setbranches(struct pbranch
*, const struct branch
*, size_t);
279 int parse(int, char **, const struct parser
*, struct match
*, size_t *, int *);
281 int matches_exec(const struct match
*, prop_dictionary_t
, size_t);
282 int parser_init(struct parser
*);
284 #endif /* _IFCONFIG_PARSE_H */