]> git.ipfire.org Git - thirdparty/dhcp.git/blob - includes/tree.h
Support for asynchronous ddns per ticket 19216 - convert to using isclib and
[thirdparty/dhcp.git] / includes / tree.h
1 /* tree.h
2
3 Definitions for address trees... */
4
5 /*
6 * Copyright (c) 2004,2007-2008 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 * https://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 * ``https://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_OLD)
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 expr_gethostname
202 };
203
204 struct expression {
205 int refcnt;
206 enum expr_op op;
207 union expr_union {
208 struct {
209 struct expression *expr;
210 struct expression *offset;
211 struct expression *len;
212 } substring;
213 struct expression *equal [2];
214 struct expression *and [2];
215 struct expression *or [2];
216 struct expression *not;
217 struct expression *add;
218 struct expression *subtract;
219 struct expression *multiply;
220 struct expression *divide;
221 struct expression *remainder;
222 struct collection *check;
223 struct {
224 struct expression *expr;
225 struct expression *len;
226 } suffix;
227 struct expression *lcase;
228 struct expression *ucase;
229 struct option *option;
230 struct option *config_option;
231 struct {
232 struct expression *offset;
233 struct expression *len;
234 } packet;
235 struct data_string const_data;
236 struct expression *extract_int;
237 struct expression *encode_int;
238 unsigned long const_int;
239 struct expression *concat [2];
240 struct dns_host_entry *host_lookup;
241 struct option *exists;
242 struct data_string encapsulate;
243 struct {
244 struct expression *base;
245 struct expression *width;
246 struct expression *separator;
247 struct expression *buffer;
248 } b2a;
249 struct {
250 struct expression *width;
251 struct expression *buffer;
252 } reverse;
253 struct {
254 struct expression *car;
255 struct expression *cdr;
256 } pick_first_value;
257 struct {
258 struct expression *car;
259 struct expression *cdr;
260 } dns_transaction;
261 struct {
262 unsigned rrclass;
263 unsigned rrtype;
264 struct expression *rrname;
265 struct expression *rrdata;
266 struct expression *ttl;
267 } ns_add;
268 struct {
269 unsigned rrclass;
270 unsigned rrtype;
271 struct expression *rrname;
272 struct expression *rrdata;
273 } ns_delete, ns_exists, ns_not_exists;
274 char *variable;
275 struct {
276 struct expression *val;
277 struct expression *next;
278 } arg;
279 struct {
280 char *name;
281 struct expression *arglist;
282 } funcall;
283 struct fundef *func;
284 } data;
285 int flags;
286 # define EXPR_EPHEMERAL 1
287 };
288
289 /* DNS host entry structure... */
290 struct dns_host_entry {
291 int refcnt;
292 TIME timeout;
293 struct data_string data;
294 char hostname [1];
295 };
296
297 struct option_cache; /* forward */
298 struct packet; /* forward */
299 struct option_state; /* forward */
300 struct decoded_option_state; /* forward */
301 struct lease; /* forward */
302 struct client_state; /* forward */
303
304 struct universe {
305 const char *name;
306 struct option_cache *(*lookup_func) (struct universe *,
307 struct option_state *,
308 unsigned);
309 void (*save_func) (struct universe *, struct option_state *,
310 struct option_cache *, isc_boolean_t);
311 void (*foreach) (struct packet *,
312 struct lease *, struct client_state *,
313 struct option_state *, struct option_state *,
314 struct binding_scope **, struct universe *, void *,
315 void (*) (struct option_cache *, struct packet *,
316 struct lease *, struct client_state *,
317 struct option_state *,
318 struct option_state *,
319 struct binding_scope **,
320 struct universe *, void *));
321 void (*delete_func) (struct universe *universe,
322 struct option_state *, int);
323 int (*option_state_dereference) (struct universe *,
324 struct option_state *,
325 const char *, int);
326 int (*decode) (struct option_state *,
327 const unsigned char *, unsigned, struct universe *);
328 int (*encapsulate) (struct data_string *, struct packet *,
329 struct lease *, struct client_state *,
330 struct option_state *, struct option_state *,
331 struct binding_scope **,
332 struct universe *);
333 u_int32_t (*get_tag) (const unsigned char *);
334 void (*store_tag) PROTO ((unsigned char *, u_int32_t));
335 u_int32_t (*get_length) (const unsigned char *);
336 void (*store_length) PROTO ((unsigned char *, u_int32_t));
337 int tag_size, length_size;
338 unsigned site_code_min, end;
339 option_name_hash_t *name_hash;
340 option_code_hash_t *code_hash;
341 struct option *enc_opt;
342 int index;
343
344 /* Flags should probably become condensed. */
345 int concat_duplicates;
346 };
347
348 struct option {
349 const char *name;
350 const char *format;
351 struct universe *universe;
352 unsigned code;
353 int refcnt;
354 };