diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-07-07 16:24:25 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-07-07 16:24:25 +0000 |
commit | 068cc60dc1971ca29006407e7907b017f5b50cc2 (patch) | |
tree | c9f8a5eb73d7303d604b2cb4272ed9676f36ee17 /sbin | |
parent | a502a6d2f5b5cada715d3e6ac68fa7afd7ccf992 (diff) |
Eliminate tree_cache structure in favour of option_data. Eliminate
redundant level of indirection in building and using option_data
arrays while constructing outgoing packets. Make option_data len field
unsigned.
ok henning@. 'cool!' deraadt@.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 83 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 6 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 16 | ||||
-rw-r--r-- | sbin/dhclient/tree.h | 7 |
4 files changed, 44 insertions, 68 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 37f1f181680..59ef98cf280 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.69 2005/07/07 13:33:35 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.70 2005/07/07 16:24:24 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -1356,44 +1356,38 @@ void make_discover(struct interface_info *ip, struct client_lease *lease) { unsigned char discover = DHCPDISCOVER; - struct tree_cache *options[256]; - struct tree_cache option_elements[256]; + struct option_data options[256]; int i; - memset(option_elements, 0, sizeof(option_elements)); memset(options, 0, sizeof(options)); memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */ i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &option_elements[i]; - options[i]->value = &discover; - options[i]->len = sizeof(discover); + options[i].data = &discover; + options[i].len = sizeof(discover); /* Request the options we want */ i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options[i] = &option_elements[i]; - options[i]->value = ip->client->config->requested_options; - options[i]->len = ip->client->config->requested_option_count; + options[i].data = ip->client->config->requested_options; + options[i].len = ip->client->config->requested_option_count; /* If we had an address, try to get it again. */ if (lease) { ip->client->requested_address = lease->address; i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &option_elements[i]; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; + options[i].data = lease->address.iabuf; + options[i].len = lease->address.len; } else ip->client->requested_address.len = 0; /* Send any options requested in the config file. */ for (i = 0; i < 256; i++) - if (!options[i] && + if (!options[i].data && ip->client->config->send_options[i].data) { - options[i] = &option_elements[i]; - options[i]->value = + options[i].data = ip->client->config->send_options[i].data; - options[i]->len = + options[i].len = ip->client->config->send_options[i].len; } @@ -1428,8 +1422,7 @@ void make_request(struct interface_info *ip, struct client_lease * lease) { unsigned char request = DHCPREQUEST; - struct tree_cache *options[256]; - struct tree_cache option_elements[256]; + struct option_data options[256]; int i; memset(options, 0, sizeof(options)); @@ -1437,43 +1430,38 @@ make_request(struct interface_info *ip, struct client_lease * lease) /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */ i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &option_elements[i]; - options[i]->value = &request; - options[i]->len = sizeof(request); + options[i].data = &request; + options[i].len = sizeof(request); /* Request the options we want */ i = DHO_DHCP_PARAMETER_REQUEST_LIST; - options[i] = &option_elements[i]; - options[i]->value = ip->client->config->requested_options; - options[i]->len = ip->client->config->requested_option_count; + options[i].data = ip->client->config->requested_options; + options[i].len = ip->client->config->requested_option_count; /* If we are requesting an address that hasn't yet been assigned to us, use the DHCP Requested Address option. */ if (ip->client->state == S_REQUESTING) { /* Send back the server identifier... */ i = DHO_DHCP_SERVER_IDENTIFIER; - options[i] = &option_elements[i]; - options[i]->value = lease->options[i].data; - options[i]->len = lease->options[i].len; + options[i].data = lease->options[i].data; + options[i].len = lease->options[i].len; } if (ip->client->state == S_REQUESTING || ip->client->state == S_REBOOTING) { ip->client->requested_address = lease->address; i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &option_elements[i]; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; + options[i].data = lease->address.iabuf; + options[i].len = lease->address.len; } else ip->client->requested_address.len = 0; /* Send any options requested in the config file. */ for (i = 0; i < 256; i++) - if (!options[i] && + if (!options[i].data && ip->client->config->send_options[i].data) { - options[i] = &option_elements[i]; - options[i]->value = + options[i].data = ip->client->config->send_options[i].data; - options[i]->len = + options[i].len = ip->client->config->send_options[i].len; } @@ -1517,9 +1505,7 @@ make_request(struct interface_info *ip, struct client_lease * lease) void make_decline(struct interface_info *ip, struct client_lease *lease) { - struct tree_cache *options[256], message_type_tree; - struct tree_cache requested_address_tree; - struct tree_cache server_id_tree, client_id_tree; + struct option_data options[256]; unsigned char decline = DHCPDECLINE; int i; @@ -1528,31 +1514,26 @@ make_decline(struct interface_info *ip, struct client_lease *lease) /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */ i = DHO_DHCP_MESSAGE_TYPE; - options[i] = &message_type_tree; - options[i]->value = &decline; - options[i]->len = sizeof(decline); + options[i].data = &decline; + options[i].len = sizeof(decline); /* Send back the server identifier... */ i = DHO_DHCP_SERVER_IDENTIFIER; - options[i] = &server_id_tree; - options[i]->value = lease->options[i].data; - options[i]->len = lease->options[i].len; + options[i].data = lease->options[i].data; + options[i].len = lease->options[i].len; /* Send back the address we're declining. */ i = DHO_DHCP_REQUESTED_ADDRESS; - options[i] = &requested_address_tree; - options[i]->value = lease->address.iabuf; - options[i]->len = lease->address.len; + options[i].data = lease->address.iabuf; + options[i].len = lease->address.len; /* Send the uid if the user supplied one. */ i = DHO_DHCP_CLIENT_IDENTIFIER; if (ip->client->config->send_options[i].len) { - options[i] = &client_id_tree; - options[i]->value = ip->client->config->send_options[i].data; - options[i]->len = ip->client->config->send_options[i].len; + options[i].data = ip->client->config->send_options[i].data; + options[i].len = ip->client->config->send_options[i].len; } - /* Set up the option buffer... */ ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, options, 0, 0, 0, NULL, 0); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 8097f14b1de..980b060b0ec 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.33 2004/05/06 22:29:15 deraadt Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.34 2005/07/07 16:24:24 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -77,7 +77,7 @@ #define REMOTE_PORT 67 struct option_data { - int len; + unsigned int len; u_int8_t *data; }; @@ -246,7 +246,7 @@ struct hash_table { /* options.c */ int cons_options(struct packet *, struct dhcp_packet *, int, - struct tree_cache **, int, int, int, u_int8_t *, int); + struct option_data *, int, int, int, u_int8_t *, int); char *pretty_print_option(unsigned int, unsigned char *, int, int, int); void do_packet(struct interface_info *, struct dhcp_packet *, diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 9c8e8fc743f..ccbb6acfa09 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.15 2004/12/26 03:17:07 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.16 2005/07/07 16:24:24 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -50,7 +50,7 @@ int bad_options_max = 5; void parse_options(struct packet *); void parse_option_buffer(struct packet *, unsigned char *, int); -int store_options(unsigned char *, int, struct tree_cache **, +int store_options(unsigned char *, int, struct option_data *, unsigned char *, int, int, int, int); @@ -197,7 +197,7 @@ parse_option_buffer(struct packet *packet, */ int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, - int mms, struct tree_cache **options, + int mms, struct option_data *options, int overload, /* Overload flags that may be set. */ int terminate, int bootpp, u_int8_t *prl, int prl_len) { @@ -340,7 +340,7 @@ cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, * Store all the requested options into the requested buffer. */ int -store_options(unsigned char *buffer, int buflen, struct tree_cache **options, +store_options(unsigned char *buffer, int buflen, struct option_data *options, unsigned char *priority_list, int priority_len, int first_cutoff, int second_cutoff, int terminate) { @@ -365,7 +365,7 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options, int length; /* If no data is available for this option, skip it. */ - if (!options[code]) { + if (!options[code].data) { continue; } @@ -378,7 +378,7 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options, option_stored[code] = 1; /* We should now have a constant length for the option. */ - length = options[code]->len; + length = options[code].len; /* Do we add a NUL? */ if (terminate && dhcp_options[code].format[0] == 't') { @@ -428,11 +428,11 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options, buffer[bufix + 1] = incr; if (tto && incr == length) { memcpy(buffer + bufix + 2, - options[code]->value + ix, incr - 1); + options[code].data + ix, incr - 1); buffer[bufix + 2 + incr - 1] = 0; } else memcpy(buffer + bufix + 2, - options[code]->value + ix, incr); + options[code].data + ix, incr); length -= incr; ix += incr; bufix += 2 + incr; diff --git a/sbin/dhclient/tree.h b/sbin/dhclient/tree.h index adda3fbaa11..a4f17e1a5ba 100644 --- a/sbin/dhclient/tree.h +++ b/sbin/dhclient/tree.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.h,v 1.6 2005/07/07 13:34:48 krw Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2005/07/07 16:24:24 krw Exp $ */ /* Definitions for address trees... */ @@ -45,11 +45,6 @@ typedef struct _pair { struct _pair *cdr; } *pair; -struct tree_cache { - unsigned char *value; - int len; -}; - struct universe { char *name; struct hash_table *hash; |