includes/tree.h

Go to the documentation of this file.
00001 /* tree.h
00002 
00003    Definitions for address trees... */
00004 
00005 /*
00006  * Copyright (c) 2011,2013,2014 by Internet Systems Consortium, Inc. ("ISC")
00007  * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC")
00008  * Copyright (c) 1996-2003 by Internet Software Consortium
00009  *
00010  * Permission to use, copy, modify, and distribute this software for any
00011  * purpose with or without fee is hereby granted, provided that the above
00012  * copyright notice and this permission notice appear in all copies.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00015  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00016  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00017  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00018  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00019  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00020  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00021  *
00022  *   Internet Systems Consortium, Inc.
00023  *   950 Charter Street
00024  *   Redwood City, CA 94063
00025  *   <info@isc.org>
00026  *   https://www.isc.org/
00027  *
00028  */
00029 
00030 /* A pair of pointers, suitable for making a linked list. */
00031 typedef struct _pair {
00032         caddr_t car;
00033         struct _pair *cdr;
00034 } *pair;
00035 
00036 struct option_chain_head {
00037         int refcnt;
00038         pair first;
00039 };
00040 
00041 struct enumeration_value {
00042         const char *name;
00043         u_int8_t value;
00044 };
00045 
00046 struct enumeration {
00047         struct enumeration *next;
00048         const char *name;
00049         unsigned width;
00050         struct enumeration_value *values;
00051 };      
00052 
00053 /* Tree node types... */
00054 #define TREE_CONCAT             1
00055 #define TREE_HOST_LOOKUP        2
00056 #define TREE_CONST              3
00057 #define TREE_LIMIT              4
00058 #define TREE_DATA_EXPR          5
00059 
00060 /* A data buffer with a reference count. */
00061 struct buffer {
00062         int refcnt;
00063         unsigned char data [1];
00064 };
00065 
00066 /* XXX The mechanism by which data strings are returned is currently
00067    XXX broken: rather than returning an ephemeral pointer, we create
00068    XXX a reference to the data in the caller's space, which the caller
00069    XXX then has to dereference - instead, the reference should be
00070    XXX ephemeral by default and be made a persistent reference explicitly. */
00071 /* XXX on the other hand, it seems to work pretty nicely, so maybe the
00072    XXX above comment is meshuggenah. */
00073 /* XXX I think the above comment tries to say this: 
00074    XXX    http://tinyurl.com/2tjqre */
00075 
00076 /* A string of data bytes, possibly accompanied by a larger buffer. */
00077 struct data_string {
00078         struct buffer *buffer;
00079         const unsigned char *data;
00080         unsigned len;   /* Does not include NUL terminator, if any. */
00081         int terminated;
00082 };
00083 
00084 enum expression_context {
00085         context_any, /* indefinite */
00086         context_boolean,
00087         context_data,
00088         context_numeric,
00089         context_dns,
00090         context_data_or_numeric, /* indefinite */
00091         context_function
00092 };
00093 
00094 struct fundef {
00095         int refcnt;
00096         struct string_list *args;
00097         struct executable_statement *statements;
00098 };
00099 
00100 struct binding_value {
00101         int refcnt;
00102         enum {
00103                 binding_boolean,
00104                 binding_data,
00105                 binding_numeric,
00106                 binding_dns,
00107                 binding_function
00108         } type;
00109         union value {
00110                 struct data_string data;
00111                 unsigned long intval;
00112                 int boolean;
00113                 struct fundef *fundef;
00114                 struct binding_value *bv;
00115         } value;
00116 };
00117 
00118 struct binding {
00119         struct binding *next;
00120         char *name;
00121         struct binding_value *value;
00122 };
00123 
00124 struct binding_scope {
00125         int refcnt;
00126         struct binding_scope *outer;
00127         struct binding *bindings;
00128 };
00129 
00130 /* Expression tree structure. */
00131 
00132 enum expr_op {
00133         expr_none,
00134         expr_match,
00135         expr_check,
00136         expr_equal,
00137         expr_substring,
00138         expr_suffix,
00139         expr_concat,
00140         expr_host_lookup,
00141         expr_and,
00142         expr_or,
00143         expr_not,
00144         expr_option,
00145         expr_hardware,
00146         expr_packet,
00147         expr_const_data,
00148         expr_extract_int8,
00149         expr_extract_int16,
00150         expr_extract_int32,
00151         expr_encode_int8,
00152         expr_encode_int16,
00153         expr_encode_int32,
00154         expr_const_int,
00155         expr_exists,
00156         expr_encapsulate,
00157         expr_known,
00158         expr_reverse,
00159         expr_leased_address,
00160         expr_binary_to_ascii,
00161         expr_config_option,
00162         expr_host_decl_name,
00163         expr_pick_first_value,
00164         expr_lease_time,
00165         expr_dns_transaction,
00166         expr_static,
00167         expr_ns_add,
00168         expr_ns_delete,
00169         expr_ns_exists,
00170         expr_ns_not_exists,
00171         expr_not_equal,
00172         expr_null,
00173         expr_variable_exists,
00174         expr_variable_reference,
00175         expr_filename,
00176         expr_sname,
00177         expr_arg,
00178         expr_funcall,
00179         expr_function,
00180         expr_add,
00181         expr_subtract,
00182         expr_multiply,
00183         expr_divide,
00184         expr_remainder,
00185         expr_binary_and,
00186         expr_binary_or,
00187         expr_binary_xor,
00188         expr_client_state,
00189         expr_ucase,
00190         expr_lcase,
00191         expr_regex_match,
00192         expr_iregex_match,
00193         expr_gethostname,
00194         expr_v6relay
00195 };
00196 
00197 struct expression {
00198         int refcnt;
00199         enum expr_op op;
00200         union expr_union {
00201                 struct {
00202                         struct expression *expr;
00203                         struct expression *offset;
00204                         struct expression *len;
00205                 } substring;
00206                 struct expression *equal [2];
00207                 struct expression *and [2];
00208                 struct expression *or [2];
00209                 struct expression *not;
00210                 struct expression *add;
00211                 struct expression *subtract;
00212                 struct expression *multiply;
00213                 struct expression *divide;
00214                 struct expression *remainder;
00215                 struct collection *check;
00216                 struct {
00217                         struct expression *expr;
00218                         struct expression *len;
00219                 } suffix;
00220                 struct expression *lcase;
00221                 struct expression *ucase;
00222                 struct option *option;
00223                 struct option *config_option;
00224                 struct {
00225                         struct expression *offset;
00226                         struct expression *len;
00227                 } packet;
00228                 struct data_string const_data;
00229                 struct expression *extract_int;
00230                 struct expression *encode_int;
00231                 unsigned long const_int;
00232                 struct expression *concat [2];
00233                 struct dns_host_entry *host_lookup;
00234                 struct option *exists;
00235                 struct data_string encapsulate;
00236                 struct {
00237                         struct expression *base;
00238                         struct expression *width;
00239                         struct expression *separator;
00240                         struct expression *buffer;
00241                 } b2a;
00242                 struct {
00243                         struct expression *width;
00244                         struct expression *buffer;
00245                 } reverse;
00246                 struct {
00247                         struct expression *car;
00248                         struct expression *cdr;
00249                 } pick_first_value;
00250                 struct {
00251                         struct expression *car;
00252                         struct expression *cdr;
00253                 } dns_transaction;
00254                 struct {
00255                         unsigned rrclass;
00256                         unsigned rrtype;
00257                         struct expression *rrname;
00258                         struct expression *rrdata;
00259                         struct expression *ttl;
00260                 } ns_add;
00261                 struct {
00262                         unsigned rrclass;
00263                         unsigned rrtype;
00264                         struct expression *rrname;
00265                         struct expression *rrdata;
00266                 } ns_delete, ns_exists, ns_not_exists;
00267                 char *variable;
00268                 struct {
00269                         struct expression *val;
00270                         struct expression *next;
00271                 } arg;
00272                 struct {
00273                         char *name;
00274                         struct expression *arglist;
00275                 } funcall;
00276                 struct fundef *func;
00277                 struct {
00278                         struct expression *relay;
00279                         struct expression *roption;
00280                 } v6relay;
00281         } data;
00282         int flags;
00283 #       define EXPR_EPHEMERAL   1
00284 };              
00285 
00286 /* DNS host entry structure... */
00287 struct dns_host_entry {
00288         int refcnt;
00289         TIME timeout;
00290         struct data_string data;
00291         char hostname [1];
00292 };
00293 
00294 struct option_cache; /* forward */
00295 struct packet; /* forward */
00296 struct option_state; /* forward */
00297 struct decoded_option_state; /* forward */
00298 struct lease; /* forward */
00299 struct client_state; /* forward */
00300 
00301 struct universe {
00302         const char *name;
00303         struct option_cache *(*lookup_func) (struct universe *,
00304                                              struct option_state *,
00305                                              unsigned);
00306         void (*save_func) (struct universe *, struct option_state *,
00307                            struct option_cache *, isc_boolean_t);
00308         void (*foreach) (struct packet *,
00309                          struct lease *, struct client_state *,
00310                          struct option_state *, struct option_state *,
00311                          struct binding_scope **, struct universe *, void *,
00312                          void (*) (struct option_cache *, struct packet *,
00313                                    struct lease *, struct client_state *,
00314                                    struct option_state *,
00315                                    struct option_state *,
00316                                    struct binding_scope **,
00317                                    struct universe *, void *));
00318         void (*delete_func) (struct universe *universe,
00319                              struct option_state *, int);
00320         int (*option_state_dereference) (struct universe *,
00321                                          struct option_state *,
00322                                          const char *, int);
00323         int (*decode) (struct option_state *,
00324                        const unsigned char *, unsigned, struct universe *);
00325         int (*encapsulate) (struct data_string *, struct packet *,
00326                             struct lease *, struct client_state *,
00327                             struct option_state *, struct option_state *,
00328                             struct binding_scope **,
00329                             struct universe *);
00330         u_int32_t (*get_tag) (const unsigned char *);
00331         void (*store_tag) (unsigned char *, u_int32_t);
00332         u_int32_t (*get_length) (const unsigned char *);
00333         void (*store_length) (unsigned char *, u_int32_t);
00334         int tag_size, length_size;
00335         unsigned site_code_min, end;
00336         option_name_hash_t *name_hash;
00337         option_code_hash_t *code_hash;
00338         struct option *enc_opt;
00339         int index;
00340 
00341         /* Flags should probably become condensed. */
00342         int concat_duplicates;
00343 };
00344 
00345 struct option {
00346         const char *name;
00347         const char *format;
00348         struct universe *universe;
00349         unsigned code;
00350         int refcnt;
00351 };

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1