]> git.ipfire.org Git - thirdparty/dhcp.git/blob - includes/tree.h
e7392fc0339ebcb532e326127d22b9e5762764bf
[thirdparty/dhcp.git] / includes / tree.h
1 /* tree.h
2
3 Definitions for address trees... */
4
5 /*
6 * Copyright (c) 1996-1999 Internet Software Consortium.
7 * Use is subject to license terms which appear in the file named
8 * ISC-LICENSE that should have accompanied this file when you
9 * received it. If a file named ISC-LICENSE did not accompany this
10 * file, or you are not sure the one you have is correct, you may
11 * obtain an applicable copy of the license at:
12 *
13 * http://www.isc.org/isc-license-1.0.html.
14 *
15 * This file is part of the ISC DHCP distribution. The documentation
16 * associated with this file is listed in the file DOCUMENTATION,
17 * included in the top-level directory of this release.
18 *
19 * Support and other services are available for ISC products - see
20 * http://www.isc.org for more information.
21 */
22
23 /* A pair of pointers, suitable for making a linked list. */
24 typedef struct _pair {
25 caddr_t car;
26 struct _pair *cdr;
27 } *pair;
28
29 /* Tree node types... */
30 #define TREE_CONCAT 1
31 #define TREE_HOST_LOOKUP 2
32 #define TREE_CONST 3
33 #define TREE_LIMIT 4
34 #define TREE_DATA_EXPR 5
35
36 /* A data buffer with a reference count. */
37 struct buffer {
38 int refcnt;
39 unsigned char data [1];
40 };
41
42 /* XXX The mechanism by which data strings are returned is currently
43 XXX broken: rather than returning an ephemeral pointer, we create
44 XXX a reference to the data in the caller's space, which the caller
45 XXX then has to dereference - instead, the reference should be
46 XXX ephemeral by default and be made a persistent reference explicitly. */
47 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
48 XXX above comment is meshuggenah. */
49
50 /* A string of data bytes, possibly accompanied by a larger buffer. */
51 struct data_string {
52 struct buffer *buffer;
53 const unsigned char *data;
54 unsigned len; /* Does not include NUL terminator, if any. */
55 int terminated;
56 };
57
58 enum expression_context {
59 context_any, /* indefinite */
60 context_boolean,
61 context_data,
62 context_numeric,
63 context_dns,
64 context_data_or_numeric, /* indefinite */
65 context_function
66 };
67
68 struct fundef {
69 int refcnt;
70 struct string_list *args;
71 struct executable_statement *statements;
72 };
73
74 struct binding_value {
75 int refcnt;
76 enum {
77 binding_boolean,
78 binding_data,
79 binding_numeric,
80 binding_dns,
81 binding_function
82 } type;
83 union value {
84 struct data_string data;
85 unsigned long intval;
86 int boolean;
87 #if defined (NSUPDATE)
88 ns_updrec *dns;
89 #endif
90 struct fundef *fundef;
91 struct binding_value *bv;
92 } value;
93 };
94
95 struct binding {
96 struct binding *next;
97 char *name;
98 struct binding_value *value;
99 };
100
101 struct binding_scope {
102 struct binding_scope *outer;
103 struct binding *bindings;
104 };
105
106 /* Expression tree structure. */
107
108 enum expr_op {
109 expr_none,
110 expr_match,
111 expr_check,
112 expr_equal,
113 expr_substring,
114 expr_suffix,
115 expr_concat,
116 expr_host_lookup,
117 expr_and,
118 expr_or,
119 expr_not,
120 expr_option,
121 expr_hardware,
122 expr_packet,
123 expr_const_data,
124 expr_extract_int8,
125 expr_extract_int16,
126 expr_extract_int32,
127 expr_encode_int8,
128 expr_encode_int16,
129 expr_encode_int32,
130 expr_const_int,
131 expr_exists,
132 expr_encapsulate,
133 expr_known,
134 expr_reverse,
135 expr_leased_address,
136 expr_binary_to_ascii,
137 expr_config_option,
138 expr_host_decl_name,
139 expr_pick_first_value,
140 expr_lease_time,
141 expr_dns_transaction,
142 expr_static,
143 expr_ns_add,
144 expr_ns_delete,
145 expr_ns_exists,
146 expr_ns_not_exists,
147 expr_not_equal,
148 expr_null,
149 expr_variable_exists,
150 expr_variable_reference,
151 expr_filename,
152 expr_sname,
153 expr_arg,
154 expr_funcall,
155 expr_function,
156 expr_add,
157 expr_subtract,
158 expr_multiply,
159 expr_divide,
160 expr_remainder
161 };
162
163 struct expression {
164 int refcnt;
165 enum expr_op op;
166 union {
167 struct {
168 struct expression *expr;
169 struct expression *offset;
170 struct expression *len;
171 } substring;
172 struct expression *equal [2];
173 struct expression *and [2];
174 struct expression *or [2];
175 struct expression *not;
176 struct expression *add;
177 struct expression *subtract;
178 struct expression *multiply;
179 struct expression *divide;
180 struct expression *remainder;
181 struct collection *check;
182 struct {
183 struct expression *expr;
184 struct expression *len;
185 } suffix;
186 struct option *option;
187 struct option *config_option;
188 struct {
189 struct expression *offset;
190 struct expression *len;
191 } packet;
192 struct data_string const_data;
193 struct expression *extract_int;
194 struct expression *encode_int;
195 unsigned long const_int;
196 struct expression *concat [2];
197 struct dns_host_entry *host_lookup;
198 struct option *exists;
199 struct data_string encapsulate;
200 struct {
201 struct expression *base;
202 struct expression *width;
203 struct expression *seperator;
204 struct expression *buffer;
205 } b2a;
206 struct {
207 struct expression *width;
208 struct expression *buffer;
209 } reverse;
210 struct {
211 struct expression *car;
212 struct expression *cdr;
213 } pick_first_value;
214 struct {
215 struct expression *car;
216 struct expression *cdr;
217 } dns_transaction;
218 struct {
219 unsigned rrclass;
220 unsigned rrtype;
221 struct expression *rrname;
222 struct expression *rrdata;
223 struct expression *ttl;
224 } ns_add;
225 struct {
226 unsigned rrclass;
227 unsigned rrtype;
228 struct expression *rrname;
229 struct expression *rrdata;
230 } ns_delete, ns_exists, ns_not_exists;
231 char *variable;
232 struct {
233 struct expression *val;
234 struct expression *next;
235 } arg;
236 struct {
237 char *name;
238 struct expression *arglist;
239 } funcall;
240 struct fundef *func;
241 } data;
242 int flags;
243 # define EXPR_EPHEMERAL 1
244 };
245
246 /* DNS host entry structure... */
247 struct dns_host_entry {
248 int refcnt;
249 TIME timeout;
250 struct data_string data;
251 char hostname [1];
252 };
253
254 struct option_cache; /* forward */
255 struct packet; /* forward */
256 struct option_state; /* forward */
257 struct decoded_option_state; /* forward */
258 struct lease; /* forward */
259
260 struct universe {
261 const char *name;
262 struct option_cache *(*lookup_func) PROTO ((struct universe *,
263 struct option_state *,
264 unsigned));
265 void (*save_func) PROTO ((struct universe *, struct option_state *,
266 struct option_cache *));
267 int (*get_func) PROTO ((struct data_string *, struct universe *,
268 struct packet *, struct lease *,
269 struct option_state *, struct option_state *,
270 struct option_state *, struct binding_scope *,
271 unsigned));
272 void (*set_func) PROTO ((struct universe *, struct option_state *,
273 struct option_cache *, enum statement_op));
274
275 void (*delete_func) PROTO ((struct universe *universe,
276 struct option_state *, int));
277 int (*option_state_dereference) PROTO ((struct universe *,
278 struct option_state *,
279 const char *, int));
280 int (*encapsulate) PROTO ((struct data_string *, struct packet *,
281 struct lease *, struct option_state *,
282 struct option_state *,
283 struct binding_scope *, struct universe *));
284 void (*store_tag) PROTO ((unsigned char *, u_int32_t));
285 void (*store_length) PROTO ((unsigned char *, u_int32_t));
286 int tag_size, length_size;
287 struct hash_table *hash;
288 struct option *options [256];
289 int index;
290 };
291
292 struct option {
293 const char *name;
294 const char *format;
295 struct universe *universe;
296 unsigned code;
297 };