Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / isc-dhcp / includes / tree.h
1 /* tree.h
2
3    Definitions for address trees... */
4
5 /*
6  * Copyright (c) 1996-2001 Internet Software Consortium.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of The Internet Software Consortium nor the names
19  *    of its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * This software has been written for the Internet Software Consortium
37  * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38  * To learn more about the Internet Software Consortium, see
39  * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
40  * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
41  * ``http://www.nominum.com''.
42  */
43
44 /* A pair of pointers, suitable for making a linked list. */
45 typedef struct _pair {
46         caddr_t car;
47         struct _pair *cdr;
48 } *pair;
49
50 struct option_chain_head {
51         int refcnt;
52         pair first;
53 };
54
55 struct enumeration_value {
56         const char *name;
57         u_int8_t value;
58 };
59
60 struct enumeration {
61         struct enumeration *next;
62         const char *name;
63         struct enumeration_value *values;
64 };      
65
66 /* Tree node types... */
67 #define TREE_CONCAT             1
68 #define TREE_HOST_LOOKUP        2
69 #define TREE_CONST              3
70 #define TREE_LIMIT              4
71 #define TREE_DATA_EXPR          5
72
73 /* A data buffer with a reference count. */
74 struct buffer {
75         int refcnt;
76         unsigned char data [1];
77 };
78
79 /* XXX The mechanism by which data strings are returned is currently
80    XXX broken: rather than returning an ephemeral pointer, we create
81    XXX a reference to the data in the caller's space, which the caller
82    XXX then has to dereference - instead, the reference should be
83    XXX ephemeral by default and be made a persistent reference explicitly. */
84 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
85    XXX above comment is meshuggenah. */
86
87 /* A string of data bytes, possibly accompanied by a larger buffer. */
88 struct data_string {
89         struct buffer *buffer;
90         const unsigned char *data;
91         unsigned len;   /* Does not include NUL terminator, if any. */
92         int terminated;
93 };
94
95 enum expression_context {
96         context_any, /* indefinite */
97         context_boolean,
98         context_data,
99         context_numeric,
100         context_dns,
101         context_data_or_numeric, /* indefinite */
102         context_function
103 };
104
105 struct fundef {
106         int refcnt;
107         struct string_list *args;
108         struct executable_statement *statements;
109 };
110
111 struct binding_value {
112         int refcnt;
113         enum {
114                 binding_boolean,
115                 binding_data,
116                 binding_numeric,
117                 binding_dns,
118                 binding_function
119         } type;
120         union value {
121                 struct data_string data;
122                 unsigned long intval;
123                 int boolean;
124 #if defined (NSUPDATE)
125                 ns_updrec *dns;
126 #endif
127                 struct fundef *fundef;
128                 struct binding_value *bv;
129         } value;
130 };
131
132 struct binding {
133         struct binding *next;
134         char *name;
135         struct binding_value *value;
136 };
137
138 struct binding_scope {
139         int refcnt;
140         struct binding_scope *outer;
141         struct binding *bindings;
142 };
143
144 /* Expression tree structure. */
145
146 enum expr_op {
147         expr_none,
148         expr_match,
149         expr_check,
150         expr_equal,
151         expr_substring,
152         expr_suffix,
153         expr_concat,
154         expr_host_lookup,
155         expr_and,
156         expr_or,
157         expr_not,
158         expr_option,
159         expr_hardware,
160         expr_packet,
161         expr_const_data,
162         expr_extract_int8,
163         expr_extract_int16,
164         expr_extract_int32,
165         expr_encode_int8,
166         expr_encode_int16,
167         expr_encode_int32,
168         expr_const_int,
169         expr_exists,
170         expr_encapsulate,
171         expr_known,
172         expr_reverse,
173         expr_leased_address,
174         expr_binary_to_ascii,
175         expr_config_option,
176         expr_host_decl_name,
177         expr_pick_first_value,
178         expr_lease_time,
179         expr_dns_transaction,
180         expr_static,
181         expr_ns_add,
182         expr_ns_delete,
183         expr_ns_exists,
184         expr_ns_not_exists,
185         expr_not_equal,
186         expr_null,
187         expr_variable_exists,
188         expr_variable_reference,
189         expr_filename,
190         expr_sname,
191         expr_arg,
192         expr_funcall,
193         expr_function,
194         expr_add,
195         expr_subtract,
196         expr_multiply,
197         expr_divide,
198         expr_remainder,
199         expr_binary_and,
200         expr_binary_or,
201         expr_binary_xor,
202         expr_client_state
203 };
204
205 struct expression {
206         int refcnt;
207         enum expr_op op;
208         union {
209                 struct {
210                         struct expression *expr;
211                         struct expression *offset;
212                         struct expression *len;
213                 } substring;
214                 struct expression *equal [2];
215                 struct expression *and [2];
216                 struct expression *or [2];
217                 struct expression *not;
218                 struct expression *add;
219                 struct expression *subtract;
220                 struct expression *multiply;
221                 struct expression *divide;
222                 struct expression *remainder;
223                 struct collection *check;
224                 struct {
225                         struct expression *expr;
226                         struct expression *len;
227                 } suffix;
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 *seperator;
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 *);
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         void (*store_tag) PROTO ((unsigned char *, u_int32_t));
333         void (*store_length) PROTO ((unsigned char *, u_int32_t));
334         int tag_size, length_size;
335         option_hash_t *hash;
336         struct option *options [256];
337         struct option *enc_opt;
338         int index;
339 };
340
341 struct option {
342         const char *name;
343         const char *format;
344         struct universe *universe;
345         unsigned code;
346 };