ISC DHCP  4.4.2b1
A reference DHCPv4 and DHCPv6 implementation
tree.h
Go to the documentation of this file.
1 /* tree.h
2 
3  Definitions for address trees... */
4 
5 /*
6  * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
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  */
28 
29 /* A pair of pointers, suitable for making a linked list. */
30 typedef struct _pair {
31  caddr_t car;
32  struct _pair *cdr;
33 } *pair;
34 
36  int refcnt;
38 };
39 
41  const char *name;
42  u_int8_t value;
43 };
44 
45 struct enumeration {
46  struct enumeration *next;
47  const char *name;
48  unsigned width;
50 };
51 
52 /* Tree node types... */
53 #define TREE_CONCAT 1
54 #define TREE_HOST_LOOKUP 2
55 #define TREE_CONST 3
56 #define TREE_LIMIT 4
57 #define TREE_DATA_EXPR 5
58 
59 /* A data buffer with a reference count. */
60 struct buffer {
61  int refcnt;
62  unsigned char data [1];
63 };
64 
65 /* XXX The mechanism by which data strings are returned is currently
66  XXX broken: rather than returning an ephemeral pointer, we create
67  XXX a reference to the data in the caller's space, which the caller
68  XXX then has to dereference - instead, the reference should be
69  XXX ephemeral by default and be made a persistent reference explicitly. */
70 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
71  XXX above comment is meshuggenah. */
72 /* XXX I think the above comment tries to say this:
73  XXX http://tinyurl.com/2tjqre */
74 
75 /* A string of data bytes, possibly accompanied by a larger buffer. */
76 struct data_string {
77  struct buffer *buffer;
78  const unsigned char *data;
79  unsigned len; /* Does not include NUL terminator, if any. */
81 };
82 
84  context_any, /* indefinite */
89  context_data_or_numeric, /* indefinite */
91 };
92 
93 struct fundef {
94  int refcnt;
95  struct string_list *args;
97 };
98 
99 struct binding_value {
100  int refcnt;
101  enum {
107  } type;
108  union value {
110  unsigned long intval;
111  int boolean;
112  struct fundef *fundef;
113  struct binding_value *bv;
114  } value;
115 };
116 
117 struct binding {
118  struct binding *next;
119  char *name;
121 };
122 
124  int refcnt;
126  struct binding *bindings;
127 };
128 
129 /* Expression tree structure. */
130 
131 enum expr_op {
195 };
196 
197 struct expression {
198  int refcnt;
199  enum expr_op op;
200  union expr_union {
201  struct {
202  struct expression *expr;
204  struct expression *len;
205  } substring;
206  struct expression *equal [2];
207  struct expression *and [2];
208  struct expression *or [2];
209  struct expression *not;
210  struct expression *add;
215  struct collection *check;
216  struct {
217  struct expression *expr;
218  struct expression *len;
219  } suffix;
220  struct expression *lcase;
221  struct expression *ucase;
222  struct option *option;
224  struct {
225  struct expression *offset;
226  struct expression *len;
227  } packet;
231  unsigned long const_int;
232  struct expression *concat [2];
234  struct option *exists;
236  struct {
237  struct expression *base;
238  struct expression *width;
241  } b2a;
242  struct {
243  struct expression *width;
244  struct expression *buffer;
245  } reverse;
246  struct {
247  struct expression *car;
248  struct expression *cdr;
250  struct {
251  struct expression *car;
252  struct expression *cdr;
253  } dns_transaction;
254  struct {
255  unsigned rrclass;
256  unsigned rrtype;
259  struct expression *ttl;
260  } ns_add;
261  struct {
262  unsigned rrclass;
263  unsigned rrtype;
264  struct expression *rrname;
265  struct expression *rrdata;
267  char *variable;
268  struct {
269  struct expression *val;
270  struct expression *next;
271  } arg;
272  struct {
273  char *name;
275  } funcall;
276  struct fundef *func;
277  struct {
278  struct expression *relay;
280  } v6relay;
281  } data;
282  int flags;
283 # define EXPR_EPHEMERAL 1
284 };
285 
286 /* DNS host entry structure... */
288  int refcnt;
291  char hostname [1];
292 };
293 
294 struct option_cache; /* forward */
295 struct packet; /* forward */
296 struct option_state; /* forward */
297 struct decoded_option_state; /* forward */
298 struct lease; /* forward */
299 struct client_state; /* forward */
300 
301 struct universe {
302  const char *name;
303  struct option_cache *(*lookup_func) (struct universe *,
304  struct option_state *,
305  unsigned);
306  void (*save_func) (struct universe *, struct option_state *,
307  struct option_cache *, isc_boolean_t);
308  void (*foreach) (struct packet *,
309  struct lease *, struct client_state *,
310  struct option_state *, struct option_state *,
311  struct binding_scope **, struct universe *, void *,
312  void (*) (struct option_cache *, struct packet *,
313  struct lease *, struct client_state *,
314  struct option_state *,
315  struct option_state *,
316  struct binding_scope **,
317  struct universe *, void *));
318  void (*delete_func) (struct universe *universe,
319  struct option_state *, int);
321  struct option_state *,
322  const char *, int);
323  int (*decode) (struct option_state *,
324  const unsigned char *, unsigned, struct universe *);
325  int (*encapsulate) (struct data_string *, struct packet *,
326  struct lease *, struct client_state *,
327  struct option_state *, struct option_state *,
328  struct binding_scope **,
329  struct universe *);
330  u_int32_t (*get_tag) (const unsigned char *);
331  void (*store_tag) (unsigned char *, u_int32_t);
332  u_int32_t (*get_length) (const unsigned char *);
333  void (*store_length) (unsigned char *, u_int32_t);
335  unsigned site_code_min, end;
338  struct option *enc_opt;
339  int index;
340 
341  /* Flags should probably become condensed. */
343 };
344 
345 struct option {
346  const char *name;
347  const char *format;
349  unsigned code;
350  int refcnt;
351 };
universe::index
int index
Definition: tree.h:339
option_state
Definition: dhcpd.h:396
lease
Definition: dhcpd.h:560
expression::expr_union::divide
struct expression * divide
Definition: tree.h:213
expr_ns_exists
Definition: tree.h:168
expression::expr_union::car
struct expression * car
Definition: tree.h:247
expression::expr_union::buffer
struct expression * buffer
Definition: tree.h:240
expr_binary_xor
Definition: tree.h:186
binding_value::refcnt
int refcnt
Definition: tree.h:100
expr_concat
Definition: tree.h:138
expression::op
enum expr_op op
Definition: tree.h:199
expr_binary_to_ascii
Definition: tree.h:159
expression::expr_union::expr
struct expression * expr
Definition: tree.h:202
expr_op
expr_op
Definition: tree.h:131
universe::encapsulate
int(* encapsulate)(struct data_string *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *)
Definition: tree.h:325
expression::refcnt
int refcnt
Definition: tree.h:198
expression::expr_union::separator
struct expression * separator
Definition: tree.h:239
expression_context
expression_context
Definition: tree.h:83
expr_check
Definition: tree.h:134
binding_value::value::data
struct data_string data
Definition: tree.h:109
expr_lease_time
Definition: tree.h:163
packet
Definition: dhcpd.h:405
expression::expr_union::config_option
struct option * config_option
Definition: tree.h:223
expression::expr_union::func
struct fundef * func
Definition: tree.h:276
binding::name
char * name
Definition: tree.h:119
universe::concat_duplicates
int concat_duplicates
Definition: tree.h:342
expr_binary_and
Definition: tree.h:184
expression::expr_union::encapsulate
struct data_string encapsulate
Definition: tree.h:235
context_any
Definition: tree.h:84
expr_add
Definition: tree.h:179
expression
Definition: tree.h:197
binding_value
Definition: tree.h:99
universe::get_tag
u_int32_t(* get_tag)(const unsigned char *)
Definition: tree.h:330
enumeration::next
struct enumeration * next
Definition: tree.h:46
expression::expr_union::funcall
struct expression::expr_union::@26 funcall
enumeration::width
unsigned width
Definition: tree.h:48
expression::expr_union::base
struct expression * base
Definition: tree.h:237
expression::expr_union::name
char * name
Definition: tree.h:273
expression::expr_union::option
struct option * option
Definition: tree.h:222
expr_config_option
Definition: tree.h:160
expression::expr_union::v6relay
struct expression::expr_union::@27 v6relay
binding_value::binding_function
Definition: tree.h:106
universe::tag_size
int tag_size
Definition: tree.h:334
binding_value::binding_dns
Definition: tree.h:105
universe::enc_opt
struct option * enc_opt
Definition: tree.h:338
isc_boolean_t
isc_boolean_t
Definition: data.h:150
expression::expr_union::add
struct expression * add
Definition: tree.h:210
expression::expr_union::extract_int
struct expression * extract_int
Definition: tree.h:229
binding
Definition: tree.h:117
option_chain_head
Definition: tree.h:35
expr_funcall
Definition: tree.h:177
expression::data
union expression::expr_union data
expr_regex_match
Definition: tree.h:190
collection
Definition: dhcpd.h:1084
binding::value
struct binding_value * value
Definition: tree.h:120
buffer::data
unsigned char data[1]
Definition: tree.h:62
data_string::data
const unsigned char * data
Definition: tree.h:78
binding_value::type
enum binding_value::@15 type
expression::expr_union::reverse
struct expression::expr_union::@20 reverse
expr_or
Definition: tree.h:141
option_cache
Definition: dhcpd.h:385
expression::expr_union::and
struct expression * and[2]
Definition: tree.h:207
expression::expr_union::len
struct expression * len
Definition: tree.h:204
expression::expr_union::not
struct expression * not
Definition: tree.h:209
hash_table
Definition: hash.h:59
expression::expr_union::check
struct collection * check
Definition: tree.h:215
expr_iregex_match
Definition: tree.h:191
expr_ns_delete
Definition: tree.h:167
expression::expr_union::ucase
struct expression * ucase
Definition: tree.h:221
_pair::cdr
struct _pair * cdr
Definition: tree.h:32
expression::expr_union::or
struct expression * or[2]
Definition: tree.h:208
expression::expr_union::ttl
struct expression * ttl
Definition: tree.h:259
expr_function
Definition: tree.h:178
expression::expr_union::remainder
struct expression * remainder
Definition: tree.h:214
universe
Definition: tree.h:301
expression::expr_union::rrdata
struct expression * rrdata
Definition: tree.h:258
binding_scope::bindings
struct binding * bindings
Definition: tree.h:126
expr_exists
Definition: tree.h:154
universe::get_length
u_int32_t(* get_length)(const unsigned char *)
Definition: tree.h:332
expression::expr_union::variable
char * variable
Definition: tree.h:267
expr_ucase
Definition: tree.h:188
expression::expr_union::ns_add
struct expression::expr_union::@23 ns_add
binding_value::binding_numeric
Definition: tree.h:104
expression::expr_union::multiply
struct expression * multiply
Definition: tree.h:212
expr_not_equal
Definition: tree.h:170
expr_divide
Definition: tree.h:182
expr_variable_exists
Definition: tree.h:172
expression::expr_union::pick_first_value
struct expression::expr_union::@21 pick_first_value
option_chain_head::first
pair first
Definition: tree.h:37
expression::expr_union::ns_delete
struct expression::expr_union::@24 ns_delete
expr_leased_address
Definition: tree.h:158
data_string
Definition: tree.h:76
context_data
Definition: tree.h:86
option::code
unsigned code
Definition: tree.h:349
expr_concat_dclist
Definition: tree.h:194
expression::expr_union::arglist
struct expression * arglist
Definition: tree.h:274
universe::name
const char * name
Definition: tree.h:302
expr_client_state
Definition: tree.h:187
dns_host_entry::hostname
char hostname[1]
Definition: tree.h:291
expr_multiply
Definition: tree.h:181
data_string::len
unsigned len
Definition: tree.h:79
binding_value::value::boolean
int boolean
Definition: tree.h:111
expr_equal
Definition: tree.h:135
expr_and
Definition: tree.h:140
expression::flags
int flags
Definition: tree.h:282
TIME
time_t TIME
Definition: dhcpd.h:85
expression::expr_union::equal
struct expression * equal[2]
Definition: tree.h:206
expression::expr_union::roption
struct expression * roption
Definition: tree.h:279
expr_null
Definition: tree.h:171
expression::expr_union::ns_not_exists
struct expression::expr_union::@24 ns_not_exists
data_string::terminated
int terminated
Definition: tree.h:80
expr_lcase
Definition: tree.h:189
binding_value::value::fundef
struct fundef * fundef
Definition: tree.h:112
expression::expr_union::cdr
struct expression * cdr
Definition: tree.h:248
expr_subtract
Definition: tree.h:180
binding_value::binding_data
Definition: tree.h:103
expr_substring
Definition: tree.h:136
client_state
Definition: dhcpd.h:1293
expr_suffix
Definition: tree.h:137
universe::option_state_dereference
int(* option_state_dereference)(struct universe *, struct option_state *, const char *, int)
Definition: tree.h:320
expression::expr_union::rrname
struct expression * rrname
Definition: tree.h:257
enumeration
Definition: tree.h:45
expr_const_data
Definition: tree.h:146
expr_filename
Definition: tree.h:174
option_chain_head::refcnt
int refcnt
Definition: tree.h:36
universe::length_size
int length_size
Definition: tree.h:334
expr_arg
Definition: tree.h:176
universe::site_code_min
unsigned site_code_min
Definition: tree.h:335
buffer
Definition: tree.h:60
universe::end
unsigned end
Definition: tree.h:335
string_list
Definition: dhcpd.h:347
buffer::refcnt
int refcnt
Definition: tree.h:61
expression::expr_union
Definition: tree.h:200
universe::save_func
void(* save_func)(struct universe *, struct option_state *, struct option_cache *, isc_boolean_t)
Definition: tree.h:306
int
const char int
Definition: omapip.h:442
binding::next
struct binding * next
Definition: tree.h:118
enumeration_value::value
u_int8_t value
Definition: tree.h:42
expression::expr_union::arg
struct expression::expr_union::@25 arg
binding_value::binding_boolean
Definition: tree.h:102
universe::decode
int(* decode)(struct option_state *, const unsigned char *, unsigned, struct universe *)
Definition: tree.h:323
binding_value::value
Definition: tree.h:108
expr_ns_add
Definition: tree.h:166
expr_hardware
Definition: tree.h:144
option::name
const char * name
Definition: tree.h:346
expr_ns_not_exists
Definition: tree.h:169
dns_host_entry::data
struct data_string data
Definition: tree.h:290
expr_extract_int16
Definition: tree.h:148
fundef::refcnt
int refcnt
Definition: tree.h:94
fundef::statements
struct executable_statement * statements
Definition: tree.h:96
binding_scope::outer
struct binding_scope * outer
Definition: tree.h:125
context_dns
Definition: tree.h:88
expression::expr_union::offset
struct expression * offset
Definition: tree.h:203
universe::delete_func
void(* delete_func)(struct universe *universe, struct option_state *, int)
Definition: tree.h:318
expression::expr_union::relay
struct expression * relay
Definition: tree.h:278
binding_scope
Definition: tree.h:123
expr_static
Definition: tree.h:165
option::format
const char * format
Definition: tree.h:347
expression::expr_union::const_data
struct data_string const_data
Definition: tree.h:228
binding_value::value::bv
struct binding_value * bv
Definition: tree.h:113
expr_reverse
Definition: tree.h:157
option
Definition: tree.h:345
expression::expr_union::encode_int
struct expression * encode_int
Definition: tree.h:230
universe::store_length
void(* store_length)(unsigned char *, u_int32_t)
Definition: tree.h:333
expr_remainder
Definition: tree.h:183
expression::expr_union::b2a
struct expression::expr_union::@19 b2a
expression::expr_union::host_lookup
struct dns_host_entry * host_lookup
Definition: tree.h:233
fundef
Definition: tree.h:93
expr_encode_int8
Definition: tree.h:150
expr_host_lookup
Definition: tree.h:139
expression::expr_union::subtract
struct expression * subtract
Definition: tree.h:211
expr_encode_int32
Definition: tree.h:152
_pair
Definition: tree.h:30
expression::expr_union::packet
struct expression::expr_union::@18 packet
context_numeric
Definition: tree.h:87
binding_scope::refcnt
int refcnt
Definition: tree.h:124
expression::expr_union::substring
struct expression::expr_union::@16 substring
expression::expr_union::exists
struct option * exists
Definition: tree.h:234
expr_binary_or
Definition: tree.h:185
expression::expr_union::suffix
struct expression::expr_union::@17 suffix
expression::expr_union::lcase
struct expression * lcase
Definition: tree.h:220
enumeration_value
Definition: tree.h:40
expr_pick_first_value
Definition: tree.h:162
expression::expr_union::width
struct expression * width
Definition: tree.h:238
dns_host_entry::timeout
TIME timeout
Definition: tree.h:289
expr_sname
Definition: tree.h:175
expression::expr_union::ns_exists
struct expression::expr_union::@24 ns_exists
expr_gethostname
Definition: tree.h:192
option::refcnt
int refcnt
Definition: tree.h:350
universe::name_hash
option_name_hash_t * name_hash
Definition: tree.h:336
expression::expr_union::next
struct expression * next
Definition: tree.h:270
fundef::args
struct string_list * args
Definition: tree.h:95
data_string::buffer
struct buffer * buffer
Definition: tree.h:77
enumeration_value::name
const char * name
Definition: tree.h:41
expr_packet
Definition: tree.h:145
expr_not
Definition: tree.h:142
expr_match
Definition: tree.h:133
context_data_or_numeric
Definition: tree.h:89
binding_value::value
union binding_value::value value
_pair::car
caddr_t car
Definition: tree.h:31
expression::expr_union::const_int
unsigned long const_int
Definition: tree.h:231
expr_dns_transaction
Definition: tree.h:164
expr_encode_int16
Definition: tree.h:151
expr_variable_reference
Definition: tree.h:173
universe::store_tag
void(* store_tag)(unsigned char *, u_int32_t)
Definition: tree.h:331
expr_const_int
Definition: tree.h:153
context_boolean
Definition: tree.h:85
expression::expr_union::rrtype
unsigned rrtype
Definition: tree.h:256
expr_option
Definition: tree.h:143
expr_none
Definition: tree.h:132
expression::expr_union::dns_transaction
struct expression::expr_union::@22 dns_transaction
context_function
Definition: tree.h:90
expression::expr_union::concat
struct expression * concat[2]
Definition: tree.h:232
enumeration::name
const char * name
Definition: tree.h:47
binding_value::value::intval
unsigned long intval
Definition: tree.h:110
expr_host_decl_name
Definition: tree.h:161
universe::code_hash
option_code_hash_t * code_hash
Definition: tree.h:337
enumeration::values
struct enumeration_value * values
Definition: tree.h:49
expr_encapsulate
Definition: tree.h:155
dns_host_entry::refcnt
int refcnt
Definition: tree.h:288
executable_statement
Definition: statement.h:29
dns_host_entry
Definition: tree.h:287
pair
struct _pair * pair
expr_v6relay
Definition: tree.h:193
expression::expr_union::val
struct expression * val
Definition: tree.h:269
expr_extract_int32
Definition: tree.h:149
expr_extract_int8
Definition: tree.h:147
expr_known
Definition: tree.h:156
expression::expr_union::rrclass
unsigned rrclass
Definition: tree.h:255
option::universe
struct universe * universe
Definition: tree.h:348