summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2014-10-27 14:51:20 -0400
committerThomas Markwalder <tmark@isc.org>2014-10-27 14:51:20 -0400
commit0a7e1a8ab06b462095f1aff14d07f83b5ff2e101 (patch)
tree0aeebd289ee185dd7d0f37dcd68b035140b63c02 /common
parente046c826214dbf49bf8a507e4fbdc64f3394edd0 (diff)
downloadisc-dhcp-0a7e1a8ab06b462095f1aff14d07f83b5ff2e101.tar.gz
[master] Add use-host-decl-names support to BOOTP
Merges in rt36233.
Diffstat (limited to 'common')
-rw-r--r--common/options.c19
-rw-r--r--common/tree.c72
2 files changed, 47 insertions, 44 deletions
diff --git a/common/options.c b/common/options.c
index 58610d7e..31506719 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)) {
@@ -3856,12 +3850,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 102d80e6..bf5f0ec3 100644
--- a/common/tree.c
+++ b/common/tree.c
@@ -2072,7 +2072,7 @@ int evaluate_data_expression (result, packet, lease, client_state,
((packet == NULL) ||
(packet->dhcpv6_container_packet == NULL)))) {
#if defined (DEBUG_EXPRESSIONS)
- log_debug("data: v6relay(%d) = NULL", len);
+ log_debug("data: v6relay(%lu) = NULL", len);
#endif
return (0);
}
@@ -2090,7 +2090,7 @@ int evaluate_data_expression (result, packet, lease, client_state,
/* We wanted a specific relay but were unable to find it */
if ((len <= MAX_V6RELAY_HOPS) && (i != 0)) {
#if defined (DEBUG_EXPRESSIONS)
- log_debug("data: v6relay(%d) = NULL", len);
+ log_debug("data: v6relay(%lu) = NULL", len);
#endif
return (0);
}
@@ -2107,7 +2107,7 @@ int evaluate_data_expression (result, packet, lease, client_state,
}
#if defined (DEBUG_EXPRESSIONS)
- log_debug("data: v6relay(%d) = %s", len,
+ log_debug("data: v6relay(%lu) = %s", len,
s1 ? print_hex_3(result->len, result->data, 30)
: "NULL");
#endif
@@ -2664,9 +2664,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)
@@ -2681,36 +2688,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. */