summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/dhclient/dhclient.c32
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/options.c6
-rw-r--r--sbin/dhclient/tree.c204
-rw-r--r--sbin/dhclient/tree.h43
5 files changed, 13 insertions, 276 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 251c45d7500..a4d7d040bb0 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.48 2004/05/05 23:07:47 deraadt Exp $ */
+/* $OpenBSD: dhclient.c,v 1.49 2004/05/06 22:29:15 deraadt Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -91,9 +91,7 @@ struct sockaddr_in sockaddr_broadcast;
*/
#define ASSERT_STATE(state_is, state_shouldbe) {}
-#if !defined (TIME_MAX)
#define TIME_MAX 2147483647
-#endif
int log_priority;
int no_daemon;
@@ -411,9 +409,10 @@ state_reboot(void *ipp)
send_request(ip);
}
-/* Called when a lease has completely expired and we've been unable to
- renew it. */
-
+/*
+ * Called when a lease has completely expired and we've
+ * been unable to renew it.
+ */
void
state_init(void *ipp)
{
@@ -435,14 +434,14 @@ state_init(void *ipp)
send_discover(ip);
}
-/* state_selecting is called when one or more DHCPOFFER packets have been
- received and a configurable period of time has passed. */
-
+/*
+ * state_selecting is called when one or more DHCPOFFER packets
+ * have been received and a configurable period of time has passed.
+ */
void
state_selecting(void *ipp)
{
struct interface_info *ip = ipp;
-
struct client_lease *lp, *next, *picked;
ASSERT_STATE(state, S_SELECTING);
@@ -1328,7 +1327,6 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
options[i]->len = sizeof(discover);
options[i]->buf_size = sizeof(discover);
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* Request the options we want */
i = DHO_DHCP_PARAMETER_REQUEST_LIST;
@@ -1338,7 +1336,6 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
options[i]->buf_size =
ip->client->config->requested_option_count;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* If we had an address, try to get it again. */
if (lease) {
@@ -1349,7 +1346,6 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
options[i]->len = lease->address.len;
options[i]->buf_size = lease->address.len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
} else
ip->client->requested_address.len = 0;
@@ -1365,7 +1361,6 @@ make_discover(struct interface_info *ip, struct client_lease *lease)
options[i]->buf_size =
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
}
/* Set up the option buffer... */
@@ -1413,7 +1408,6 @@ make_request(struct interface_info *ip, struct client_lease * lease)
options[i]->len = sizeof(request);
options[i]->buf_size = sizeof(request);
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* Request the options we want */
i = DHO_DHCP_PARAMETER_REQUEST_LIST;
@@ -1423,7 +1417,6 @@ make_request(struct interface_info *ip, struct client_lease * lease)
options[i]->buf_size =
ip->client->config->requested_option_count;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* If we are requesting an address that hasn't yet been assigned
to us, use the DHCP Requested Address option. */
@@ -1435,7 +1428,6 @@ make_request(struct interface_info *ip, struct client_lease * lease)
options[i]->len = lease->options[i].len;
options[i]->buf_size = lease->options[i].len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
}
if (ip->client->state == S_REQUESTING ||
ip->client->state == S_REBOOTING) {
@@ -1446,7 +1438,6 @@ make_request(struct interface_info *ip, struct client_lease * lease)
options[i]->len = lease->address.len;
options[i]->buf_size = lease->address.len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
} else
ip->client->requested_address.len = 0;
@@ -1462,7 +1453,6 @@ make_request(struct interface_info *ip, struct client_lease * lease)
options[i]->buf_size =
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
}
/* Set up the option buffer... */
@@ -1521,7 +1511,6 @@ make_decline(struct interface_info *ip, struct client_lease *lease)
options[i]->len = sizeof(decline);
options[i]->buf_size = sizeof(decline);
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* Send back the server identifier... */
i = DHO_DHCP_SERVER_IDENTIFIER;
@@ -1530,7 +1519,6 @@ make_decline(struct interface_info *ip, struct client_lease *lease)
options[i]->len = lease->options[i].len;
options[i]->buf_size = lease->options[i].len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* Send back the address we're declining. */
i = DHO_DHCP_REQUESTED_ADDRESS;
@@ -1539,7 +1527,6 @@ make_decline(struct interface_info *ip, struct client_lease *lease)
options[i]->len = lease->address.len;
options[i]->buf_size = lease->address.len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
/* Send the uid if the user supplied one. */
i = DHO_DHCP_CLIENT_IDENTIFIER;
@@ -1549,7 +1536,6 @@ make_decline(struct interface_info *ip, struct client_lease *lease)
options[i]->len = ip->client->config->send_options[i].len;
options[i]->buf_size = ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
- options[i]->tree = NULL;
}
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 4c136179c92..8097f14b1de 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.32 2004/05/04 22:23:01 mickey Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.33 2004/05/06 22:29:15 deraadt Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -106,7 +106,6 @@ struct packet {
struct interface_info *interface;
struct hardware *haddr;
struct option_data options[256];
- int got_requested_address;
};
struct hardware {
@@ -284,7 +283,6 @@ void convert_num(unsigned char *, char *, int, int);
time_t parse_date(FILE *);
/* tree.c */
-int tree_evaluate(struct tree_cache *);
pair cons(caddr_t, pair);
/* alloc.c */
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index e77d2215296..b6e571fa456 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.10 2004/05/04 22:23:01 mickey Exp $ */
+/* $OpenBSD: options.c,v 1.11 2004/05/06 22:29:15 deraadt Exp $ */
/* DHCP options parsing and reassembly. */
@@ -377,10 +377,6 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options,
continue;
option_stored[code] = 1;
- /* Find the value of the option... */
- if (!tree_evaluate(options[code]))
- continue;
-
/* We should now have a constant length for the option. */
length = options[code]->len;
diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c
index d812996dfb2..89ac450ac5b 100644
--- a/sbin/dhclient/tree.c
+++ b/sbin/dhclient/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.12 2004/05/04 22:23:01 mickey Exp $ */
+/* $OpenBSD: tree.c,v 1.13 2004/05/06 22:29:15 deraadt Exp $ */
/* Routines for manipulating parse trees... */
@@ -44,13 +44,6 @@
extern int h_errno;
-static time_t tree_evaluate_recurse(int *, unsigned char **, int *,
- struct tree *);
-static time_t do_host_lookup(int *, unsigned char **, int *,
- struct dns_host_entry *);
-static void do_data_copy(int *, unsigned char **, int *, unsigned char *,
- int);
-
pair
cons(caddr_t car, pair cdr)
{
@@ -61,198 +54,3 @@ cons(caddr_t car, pair cdr)
foo->cdr = cdr;
return (foo);
}
-
-int
-tree_evaluate(struct tree_cache *tree_cache)
-{
- unsigned char *bp = tree_cache->value;
- int bc = tree_cache->buf_size;
- int bufix = 0;
-
- /*
- * If there's no tree associated with this cache, it evaluates
- * to a constant and that was detected at startup.
- */
- if (!tree_cache->tree)
- return (1);
-
- /* Try to evaluate the tree without allocating more memory... */
- tree_cache->timeout = tree_evaluate_recurse(&bufix, &bp, &bc,
- tree_cache->tree);
-
- /* No additional allocation needed? */
- if (bufix <= bc) {
- tree_cache->len = bufix;
- return (1);
- }
-
- /*
- * If we can't allocate more memory, return with what we have
- * (maybe nothing).
- */
- if (!(bp = calloc(1, bufix)))
- return (0);
-
- /* Record the change in conditions... */
- bc = bufix;
- bufix = 0;
-
- /*
- * Note that the size of the result shouldn't change on the
- * second call to tree_evaluate_recurse, since we haven't
- * changed the ``current'' time.
- */
- tree_evaluate_recurse(&bufix, &bp, &bc, tree_cache->tree);
-
- /*
- * Free the old buffer if needed, then store the new buffer
- * location and size and return.
- */
- free(tree_cache->value);
- tree_cache->value = bp;
- tree_cache->len = bufix;
- tree_cache->buf_size = bc;
- return (1);
-}
-
-static time_t
-tree_evaluate_recurse(int *bufix, unsigned char **bufp, int *bufcount,
- struct tree *tree)
-{
- int limit;
- time_t t1, t2;
-
- switch (tree->op) {
- case TREE_CONCAT:
- t1 = tree_evaluate_recurse(bufix, bufp, bufcount,
- tree->data.concat.left);
- t2 = tree_evaluate_recurse(bufix, bufp, bufcount,
- tree->data.concat.right);
- if (t1 > t2)
- return (t2);
- return (t1);
-
- case TREE_HOST_LOOKUP:
- return (do_host_lookup(bufix, bufp, bufcount,
- tree->data.host_lookup.host));
-
- case TREE_CONST:
- do_data_copy(bufix, bufp, bufcount,
- tree->data.const_val.data,
- tree->data.const_val.len);
- t1 = MAX_TIME;
- return (t1);
-
- case TREE_LIMIT:
- limit = *bufix + tree->data.limit.limit;
- t1 = tree_evaluate_recurse(bufix, bufp, bufcount,
- tree->data.limit.tree);
- *bufix = limit;
- return (t1);
-
- default:
- warning("Bad node id in tree: %d.", tree->op);
- t1 = MAX_TIME;
- return (t1);
- }
-}
-
-static time_t
-do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount,
- struct dns_host_entry *dns)
-{
- struct hostent *h;
- int i;
- int new_len;
-
- /* If the record hasn't timed out, just copy the data and return. */
- if (cur_time <= dns->timeout) {
- do_data_copy(bufix, bufp, bufcount,
- dns->data, dns->data_len);
- return (dns->timeout);
- }
-
- /* Otherwise, look it up... */
- h = gethostbyname(dns->hostname);
- if (h == NULL) {
- switch (h_errno) {
- case HOST_NOT_FOUND:
- warning("%s: host unknown.", dns->hostname);
- break;
- case TRY_AGAIN:
- warning("%s: temporary name server failure",
- dns->hostname);
- break;
- case NO_RECOVERY:
- warning("%s: name server failed", dns->hostname);
- break;
- case NO_DATA:
- warning("%s: no A record associated with address",
- dns->hostname);
- }
- /* Okay to try again after a minute. */
- return (cur_time + 60);
- }
-
- /* Count the number of addresses we got... */
- for (i = 0; h->h_addr_list[i]; i++)
- ;
-
- /* Do we need to allocate more memory? */
- new_len = i * h->h_length;
- if (dns->buf_len < i) {
- unsigned char *buf = calloc(1, new_len);
- /* If we didn't get more memory, use what we have. */
- if (!buf) {
- new_len = dns->buf_len;
- if (!dns->buf_len) {
- dns->timeout = cur_time + 60;
- return (dns->timeout);
- }
- } else {
- if (dns->data)
- free(dns->data);
- dns->data = buf;
- dns->buf_len = new_len;
- }
- }
-
- /*
- * Addresses are conveniently stored one to the buffer, so we
- * have to copy them out one at a time... :'(
- */
- for (i = 0; i < new_len / h->h_length; i++) {
- memcpy(dns->data + h->h_length * i,
- h->h_addr_list[i], h->h_length);
- }
- dns->data_len = new_len;
-
- /*
- * Set the timeout for an hour from now.
- * XXX: This should really use the time on the DNS reply.
- */
- dns->timeout = cur_time + 3600;
-
- do_data_copy(bufix, bufp, bufcount, dns->data, dns->data_len);
- return (dns->timeout);
-}
-
-static void
-do_data_copy(int *bufix, unsigned char **bufp, int *bufcount,
- unsigned char *data, int len)
-{
- int space = *bufcount - *bufix;
-
- /* If there's more space than we need, use only what we need. */
- if (space > len)
- space = len;
-
- /*
- * Copy as much data as will fit, then increment the buffer
- * index by the amount we actually had to copy, which could be
- * more.
- */
- if (space > 0)
- memcpy(*bufp + *bufix, data, space);
- *bufix += len;
-}
diff --git a/sbin/dhclient/tree.h b/sbin/dhclient/tree.h
index 6d4ea17bb58..04e08e7c820 100644
--- a/sbin/dhclient/tree.h
+++ b/sbin/dhclient/tree.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.h,v 1.4 2004/02/23 20:09:02 deraadt Exp $ */
+/* $OpenBSD: tree.h,v 1.5 2004/05/06 22:29:15 deraadt Exp $ */
/* Definitions for address trees... */
@@ -45,52 +45,11 @@ typedef struct _pair {
struct _pair *cdr;
} *pair;
-/* Tree node types... */
-#define TREE_CONCAT 1
-#define TREE_HOST_LOOKUP 2
-#define TREE_CONST 3
-#define TREE_LIMIT 4
-
-/* Tree structure for deferred evaluation of changing values. */
-struct tree {
- int op;
- union {
- struct concat {
- struct tree *left;
- struct tree *right;
- } concat;
- struct host_lookup {
- struct dns_host_entry *host;
- } host_lookup;
- struct const_val {
- unsigned char *data;
- int len;
- } const_val;
- struct limit {
- struct tree *tree;
- int limit;
- } limit;
- } data;
-};
-
-/* DNS host entry structure... */
-struct dns_host_entry {
- char *hostname;
- unsigned char *data;
- int data_len;
- int buf_len;
- time_t timeout;
-};
-
struct tree_cache {
unsigned char *value;
int len;
int buf_size;
time_t timeout;
- struct tree *tree;
- int flags;
-#define TC_AWAITING_RESOLUTION 1
-#define TC_TEMPORARY 2
};
struct universe {