diff options
author | Thomas Markwalder <tmark@isc.org> | 2014-10-27 15:32:53 -0400 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2014-10-27 15:32:53 -0400 |
commit | e5318f5c9129ff18a633db0ff9c0e99b0de62e91 (patch) | |
tree | c73042f67f7dea40e168c9abe90ed5f6e34a7523 /common | |
parent | e4cfda512d32090eaa6a8cd33779656616adae67 (diff) | |
download | isc-dhcp-e5318f5c9129ff18a633db0ff9c0e99b0de62e91.tar.gz |
[master] Add use-host-decl-names support to BOOTP
Merges in rt36233.
Diffstat (limited to 'common')
-rw-r--r-- | common/options.c | 19 | ||||
-rw-r--r-- | common/tree.c | 68 |
2 files changed, 45 insertions, 42 deletions
diff --git a/common/options.c b/common/options.c index 9420b472..85ec183f 100644 --- a/common/options.c +++ b/common/options.c @@ -43,17 +43,11 @@ static int prepare_option_buffer(struct universe *universe, struct buffer *bp, struct option_cache **opp); /* Parse all available options out of the specified packet. */ - +/* Note, the caller is responsible for allocating packet->options. */ int parse_options (packet) struct packet *packet; { - struct option_cache *op = (struct option_cache *)0; - - /* Allocate a new option state. */ - if (!option_state_allocate (&packet -> options, MDL)) { - packet -> options_valid = 0; - return 0; - } + struct option_cache *op = NULL; /* If we don't see the magic cookie, there's nothing to parse. */ if (memcmp (packet -> raw -> options, DHCP_OPTIONS_COOKIE, 4)) { @@ -3796,12 +3790,15 @@ void do_packet (interface, packet, len, from_port, from, hfrom) return; } + /* Allocate packet->options now so it is non-null for all packets */ + decoded_packet->options_valid = 0; + if (!option_state_allocate (&decoded_packet->options, MDL)) { + return; + } + /* If there's an option buffer, try to parse it. */ if (decoded_packet->packet_length >= DHCP_FIXED_NON_UDP + 4) { if (!parse_options(decoded_packet)) { - if (decoded_packet->options) - option_state_dereference - (&decoded_packet->options, MDL); packet_dereference (&decoded_packet, MDL); return; } diff --git a/common/tree.c b/common/tree.c index e0839a6a..5dc2bb06 100644 --- a/common/tree.c +++ b/common/tree.c @@ -3,7 +3,7 @@ Routines for manipulating parse trees... */ /* - * Copyright (c) 2011-2013 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2011-2013,2014 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2004-2007,2009 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-2003 by Internet Software Consortium * @@ -2931,9 +2931,16 @@ int evaluate_option_cache (result, packet, lease, client_state, oc -> expression, file, line); } -/* Evaluate an option cache and extract a boolean from the result, - returning the boolean. Return false if there is no data. */ - +/* Evaluate an option cache and extract a boolean from the result. + * The boolean option cache is actually a trinary value where: + * + * 0 = return 0, ignore parameter 0 (also the case for no data) + * 1 = return 1, ignore parameter 0 + * 2 = return 0, ignore parameter 1 + * + * This supports both classic boolean flags on/off as well as the + * allow/deny/ignore keywords +*/ int evaluate_boolean_option_cache (ignorep, packet, lease, client_state, in_options, cfg_options, scope, oc, file, line) @@ -2948,36 +2955,35 @@ int evaluate_boolean_option_cache (ignorep, packet, const char *file; int line; { - struct data_string ds; - int result; + int result = 0; + if (ignorep) + *ignorep = 0; - /* So that we can be called with option_lookup as an argument. */ - if (!oc || !in_options) - return 0; - - memset (&ds, 0, sizeof ds); - if (!evaluate_option_cache (&ds, packet, - lease, client_state, in_options, - cfg_options, scope, oc, file, line)) - return 0; + /* Only attempt to evaluate if option_cache is not null. This permits + * us to be called with option_lookup() as an argument. */ + if (oc && in_options) { + struct data_string ds; + + memset(&ds, 0, sizeof ds); + if (evaluate_option_cache(&ds, packet, + lease, client_state, in_options, + cfg_options, scope, oc, file, + line)) { + /* We have a value for the option set result and + * ignore parameter accordingly. */ + if (ds.len) { + if (ds.data[0] == 1) + result = 1; + else if ((ds.data[0] == 2) && (ignorep != NULL)) + *ignorep = 1; + } - /* The boolean option cache is actually a trinary value. Zero is - * off, one is on, and 2 is 'ignore'. - */ - if (ds.len) { - result = ds.data [0]; - if (result == 2) { - result = 0; - if (ignorep != NULL) - *ignorep = 1; - } else if (ignorep != NULL) - *ignorep = 0; - } else - result = 0; - data_string_forget (&ds, MDL); - return result; + data_string_forget(&ds, MDL); + } + } + + return (result); } - /* Evaluate a boolean expression and return the result of the evaluation, or FALSE if it failed. */ |