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