]> git.ipfire.org Git - thirdparty/dhcp.git/blob - includes/tree.h
- The minimum site code value was set to 224 in 3.1.0 to track RFC3942. This
[thirdparty/dhcp.git] / includes / tree.h
1 /* tree.h
2
3 Definitions for address trees... */
4
5 /*
6 * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1996-2003 by Internet Software Consortium
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 * Internet Systems Consortium, Inc.
22 * 950 Charter Street
23 * Redwood City, CA 94063
24 * <info@isc.org>
25 * http://www.isc.org/
26 *
27 * This software has been written for Internet Systems Consortium
28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29 * To learn more about Internet Systems Consortium, see
30 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
31 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
32 * ``http://www.nominum.com''.
33 */
34
35 /* A pair of pointers, suitable for making a linked list. */
36 typedef struct _pair {
37 caddr_t car;
38 struct _pair *cdr;
39 } *pair;
40
41 struct option_chain_head {
42 int refcnt;
43 pair first;
44 };
45
46 struct enumeration_value {
47 const char *name;
48 u_int8_t value;
49 };
50
51 struct enumeration {
52 struct enumeration *next;
53 const char *name;
54 unsigned width;
55 struct enumeration_value *values;
56 };
57
58 /* Tree node types... */
59 #define TREE_CONCAT 1
60 #define TREE_HOST_LOOKUP 2
61 #define TREE_CONST 3
62 #define TREE_LIMIT 4
63 #define TREE_DATA_EXPR 5
64
65 /* A data buffer with a reference count. */
66 struct buffer {
67 int refcnt;
68 unsigned char data [1];
69 };
70
71 /* XXX The mechanism by which data strings are returned is currently
72 XXX broken: rather than returning an ephemeral pointer, we create
73 XXX a reference to the data in the caller's space, which the caller
74 XXX then has to dereference - instead, the reference should be
75 XXX ephemeral by default and be made a persistent reference explicitly. */
76 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
77 XXX above comment is meshuggenah. */
78 /* XXX I think the above comment tries to say this:
79 XXX http://tinyurl.com/2tjqre */
80
81 /* A string of data bytes, possibly accompanied by a larger buffer. */
82 struct data_string {
83 struct buffer *buffer;
84 const unsigned char *data;
85 unsigned len; /* Does not include NUL terminator, if any. */
86 int terminated;
87 };
88
89 enum expression_context {
90 context_any, /* indefinite */
91 context_boolean,
92 context_data,
93 context_numeric,
94 context_dns,
95 context_data_or_numeric, /* indefinite */
96 context_function
97 };
98
99 struct fundef {
100 int refcnt;
101 struct string_list *args;
102 struct executable_statement *statements;
103 };
104
105 struct binding_value {
106 int refcnt;
107 enum {
108 binding_boolean,
109 binding_data,
110 binding_numeric,
111 binding_dns,
112 binding_function
113 } type;
114 union value {
115 struct data_string data;
116 unsigned long intval;
117 int boolean;
118 #if defined (NSUPDATE)
119 ns_updrec *dns;
120 #endif
121 struct fundef *fundef;
122 struct binding_value *bv;
123 } value;
124 };
125
126 struct binding {
127 struct binding *next;
128 char *name;
129 struct binding_value *value;
130 };
131
132 struct binding_scope {
133 int refcnt;
134 struct binding_scope *outer;
135 struct binding *bindings;
136 };
137
138 /* Expression tree structure. */
139
140 enum expr_op {
141 expr_none,
142 expr_match,
143 expr_check,
144 expr_equal,
145 expr_substring,
146 expr_suffix,
147 expr_concat,
148 expr_host_lookup,
149 expr_and,
150 expr_or,
151 expr_not,
152 expr_option,
153 expr_hardware,
154 expr_packet,
155 expr_const_data,
156 expr_extract_int8,
157 expr_extract_int16,
158 expr_extract_int32,
159 expr_encode_int8,
160 expr_encode_int16,
161 expr_encode_int32,
162 expr_const_int,
163 expr_exists,
164 expr_encapsulate,
165 expr_known,
166 expr_reverse,
167 expr_leased_address,
168 expr_binary_to_ascii,
169 expr_config_option,
170 expr_host_decl_name,
171 expr_pick_first_value,
172 expr_lease_time,
173 expr_dns_transaction,
174 expr_static,
175 expr_ns_add,
176 expr_ns_delete,
177 expr_ns_exists,
178 expr_ns_not_exists,
179 expr_not_equal,
180 expr_null,
181 expr_variable_exists,
182 expr_variable_reference,
183 expr_filename,
184 expr_sname,
185 expr_arg,
186 expr_funcall,
187 expr_function,
188 expr_add,
189 expr_subtract,
190 expr_multiply,
191 expr_divide,
192 expr_remainder,
193 expr_binary_and,
194 expr_binary_or,
195 expr_binary_xor,
196 expr_client_state,
197 expr_ucase,
198 expr_lcase,
199 expr_regex_match,
200 expr_iregex_match
201 };
202
203 struct expression {
204 int refcnt;
205 enum expr_op op;
206 union expr_union {
207 struct {
208 struct expression *expr;
209 struct expression *offset;
210 struct expression *len;
211 } substring;
212 struct expression *equal [2];
213 struct expression *and [2];
214 struct expression *or [2];
215 struct expression *not;
216 struct expression *add;
217 struct expression *subtract;
218 struct expression *multiply;
219 struct expression *divide;
220 struct expression *remainder;
221 struct collection *check;
222 struct {
223 struct expression *expr;
224 struct expression *len;
225 } suffix;
226 struct expression *lcase;
227 struct expression *ucase;
228 struct option *option;
229 struct option *config_option;
230 struct {
231 struct expression *offset;
232 struct expression *len;
233 } packet;
234 struct data_string const_data;
235 struct expression *extract_int;
236 struct expression *encode_int;
237 unsigned long const_int;
238 struct expression *concat [2];
239 struct dns_host_entry *host_lookup;
240 struct option *exists;
241 struct data_string encapsulate;
242 struct {
243 struct expression *base;
244 struct expression *width;
245 struct expression *separator;
246 struct expression *buffer;
247 } b2a;
248 struct {
249 struct expression *width;
250 struct expression *buffer;
251 } reverse;
252 struct {
253 struct expression *car;
254 struct expression *cdr;
255 } pick_first_value;
256 struct {
257 struct expression *car;
258 struct expression *cdr;
259 } dns_transaction;
260 struct {
261 unsigned rrclass;
262 unsigned rrtype;
263 struct expression *rrname;
264 struct expression *rrdata;
265 struct expression *ttl;
266 } ns_add;
267 struct {
268 unsigned rrclass;
269 unsigned rrtype;
270 struct expression *rrname;
271 struct expression *rrdata;
272 } ns_delete, ns_exists, ns_not_exists;
273 char *variable;
274 struct {
275 struct expression *val;
276 struct expression *next;
277 } arg;
278 struct {
279 char *name;
280 struct expression *arglist;
281 } funcall;
282 struct fundef *func;
283 } data;
284 int flags;
285 # define EXPR_EPHEMERAL 1
286 };
287
288 /* DNS host entry structure... */
289 struct dns_host_entry {
290 int refcnt;
291 TIME timeout;
292 struct data_string data;
293 char hostname [1];
294 };
295
296 struct option_cache; /* forward */
297 struct packet; /* forward */
298 struct option_state; /* forward */
299 struct decoded_option_state; /* forward */
300 struct lease; /* forward */
301 struct client_state; /* forward */
302
303 struct universe {
304 const char *name;
305 struct option_cache *(*lookup_func) (struct universe *,
306 struct option_state *,
307 unsigned);
308 void (*save_func) (struct universe *, struct option_state *,
309 struct option_cache *, isc_boolean_t);
310 void (*foreach) (struct packet *,
311 struct lease *, struct client_state *,
312 struct option_state *, struct option_state *,
313 struct binding_scope **, struct universe *, void *,
314 void (*) (struct option_cache *, struct packet *,
315 struct lease *, struct client_state *,
316 struct option_state *,
317 struct option_state *,
318 struct binding_scope **,
319 struct universe *, void *));
320 void (*delete_func) (struct universe *universe,
321 struct option_state *, int);
322 int (*option_state_dereference) (struct universe *,
323 struct option_state *,
324 const char *, int);
325 int (*decode) (struct option_state *,
326 const unsigned char *, unsigned, struct universe *);
327 int (*encapsulate) (struct data_string *, struct packet *,
328 struct lease *, struct client_state *,
329 struct option_state *, struct option_state *,
330 struct binding_scope **,
331 struct universe *);
332 u_int32_t (*get_tag) (const unsigned char *);
333 void (*store_tag) PROTO ((unsigned char *, u_int32_t));
334 u_int32_t (*get_length) (const unsigned char *);
335 void (*store_length) PROTO ((unsigned char *, u_int32_t));
336 int tag_size, length_size;
337 unsigned site_code_min, end;
338 option_name_hash_t *name_hash;
339 option_code_hash_t *code_hash;
340 struct option *enc_opt;
341 int index;
342
343 /* Flags should probably become condensed. */
344 int concat_duplicates;
345 };
346
347 struct option {
348 const char *name;
349 const char *format;
350 struct universe *universe;
351 unsigned code;
352 int refcnt;
353 };