[dhcp-agent-commits] dhcp-agent/src dhcp-client-conf.c,1.18,1.19 dhcp-client-conf.h,1.10,1.11
Status: Alpha
Brought to you by:
actmodern
|
From: <act...@us...> - 2003-03-25 03:06:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src
In directory sc8-pr-cvs1:/tmp/cvs-serv12432
Modified Files:
dhcp-client-conf.c dhcp-client-conf.h
Log Message:
client-conf code redo
Index: dhcp-client-conf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** dhcp-client-conf.c 3 Jan 2003 22:09:44 -0000 1.18
--- dhcp-client-conf.c 25 Mar 2003 03:06:18 -0000 1.19
***************
*** 31,47 ****
#include "dhcp-conf.h"
#include "dhcp-client-conf.h"
#include "dhcp-cache-entry.h"
#include "dhcp-client-cache.h"
#include "dhcp-options-strings.h"
#include "dhcp-client-defaults.h"
- /* FIXME: check for destroy params mem leak. */
-
/* * * * * * * * * * * * * * * * * * *
* configuration grammar structures. *
* * * * * * * * * * * * * * * * * * */
/* string arrays for commands. */
--- 31,58 ----
#include "dhcp-conf.h"
+ #include "dhcp-conf-var.h"
#include "dhcp-client-conf.h"
#include "dhcp-cache-entry.h"
#include "dhcp-client-cache.h"
#include "dhcp-options-strings.h"
+ #include "dhcp-convert.h"
#include "dhcp-client-defaults.h"
/* * * * * * * * * * * * * * * * * * *
* configuration grammar structures. *
* * * * * * * * * * * * * * * * * * */
+ /*
+ * We construct the tree for client-conf code to handle the
+ * grammar for us.
+ *
+ * The one limitation we have now is that the tree has branches
+ * from the top, the command name itself, and everything else is
+ * linear. This is fine for what we want to do now but it may
+ * need to support a more proper grammer tree for more complex
+ * parsing in the future. */
+
+
/* string arrays for commands. */
***************
*** 105,108 ****
--- 116,127 ----
static const arg_symbol_t *configure_arg_symbols[] = { NULL };
+ static const arg_type_t append_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST };
+ static const char **append_arg_strings[] = { NULL, NULL, NULL };
+ static const arg_symbol_t *append_arg_symbols[] = { NULL, NULL, NULL };
+
+ static const arg_type_t prepend_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST };
+ static const char **prepend_arg_strings[] = { NULL, NULL, NULL };
+ static const arg_symbol_t *prepend_arg_symbols[] = { NULL, NULL, NULL };
+
static const arg_type_t server_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_GROUP };
static const char **server_arg_strings[] = { server_strings, NULL, NULL };
***************
*** 151,155 ****
};
! /* request command. */
static const command_t command_configure = {
DIRECTIVE_CONFIGURE,
--- 170,174 ----
};
! /* configure command. */
static const command_t command_configure = {
DIRECTIVE_CONFIGURE,
***************
*** 171,174 ****
--- 190,214 ----
};
+ /* append command. */
+ static const command_t command_append = {
+ DIRECTIVE_APPEND,
+ "append",
+ 3,
+ append_arg_strings,
+ append_arg_types,
+ append_arg_symbols,
+ };
+
+
+ /* prepend command. */
+ static const command_t command_prepend = {
+ DIRECTIVE_PREPEND,
+ "prepend",
+ 3,
+ prepend_arg_strings,
+ prepend_arg_types,
+ prepend_arg_symbols,
+ };
+
static const command_t *commands[] = {
&command_set_boolean,
***************
*** 178,181 ****
--- 218,223 ----
&command_server,
&command_configure,
+ &command_append,
+ &command_prepend,
NULL,
};
***************
*** 198,208 ****
/* forward declaration of directive handlers. */
! static int directive_group_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_set_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_set_boolean_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_request_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_require_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_server_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
/* indexed by directive types in dhcp-client-conf.h . */
--- 240,252 ----
/* forward declaration of directive handlers. */
! static int directive_group_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_set_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_set_boolean_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_request_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_require_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_server_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_configure_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
! static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data);
/* indexed by directive types in dhcp-client-conf.h . */
***************
*** 214,217 ****
--- 258,263 ----
directive_server_handler,
directive_configure_handler,
+ directive_append_handler,
+ directive_prepend_handler,
};
***************
*** 220,224 ****
* * * * * * * * * * */
! static int fill_option_bit_array_from_string_list(list_t *strings, uint8_t *option_bit_array)
{
char *option_string;
--- 266,349 ----
* * * * * * * * * * */
! /* search through a list of conf variables and return if the type
! * is found. this is useful for overwriting variables: this is
! * slow however we assume we're not doing configuration variables
! * in excess of twenty or so in most situations. */
!
! static conf_var_t *find_conf_var(var_type_t var_type, list_t *var_list)
! {
! conf_var_t *var;
!
! list_rewind(var_list);
! while((var = list_next(var_list)) != NULL) {
!
! if(var->type == var_type)
! return var;
! }
!
! return NULL;
! }
!
! static void add_or_replace_var(list_t *variables, conf_var_t *var)
! {
! conf_var_t *cur_var;
!
! /* see if this is already set.*/
! cur_var = find_conf_var(var->type, variables);
!
! /* if not add. */
! if(cur_var == NULL) {
!
! list_add(variables, var);
!
! } else {
!
! /* otherwise overwrite. */
! dhcp_conf_var_overwrite(cur_var, var->type, var->val);
! dhcp_conf_var_destroy_no_val_free(var); /* we need to keep the value so don't free val. */
!
! }
! }
!
! /* search through lower params and return the first match. */
! static client_conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr)
! {
! client_conf_params_t *params = NULL;
!
! list_rewind(lower_params);
! while((params = list_next(lower_params)) != NULL) {
!
! if((memcmp(&ip, ¶ms->server_ip, sizeof(ip_addr_t)) == 0)
! || (memcmp(ð_addr, ¶ms->server_hw_addr, sizeof(eth_addr_t)) == 0)) {
! /* if a match is found break out. */
! break;
! } else {
! /* check lower parameters too. */
! if((params = get_params_for(params->lower_params, ip, eth_addr)) != NULL)
! break;
! }
!
! /* otherwise we keep looping. */
!
! }
!
! return params;
! }
!
! /* utility routine to call on client_conf to find the best
! * param. this calls get_params_for on all lower parameters which is in of itself recursive. */
! static client_conf_params_t *find_best_params_for(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
! {
! client_conf_params_t *params;
!
! params = get_params_for(cc->params->lower_params, ip_addr, eth_addr);
! if(params == NULL)
! params = cc->params;
!
! return params;
! }
!
! /* given a list of strings identifying options we fill a bit array that references the option by the index. */
! static int client_conf_fill_option_bit_array_from_string_list(list_t *strings, uint8_t *option_bit_array)
{
char *option_string;
***************
*** 227,231 ****
list_rewind(strings);
! for(option_string = list_next(strings); option_string; option_string = list_next(strings)) {
for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) {
--- 352,356 ----
list_rewind(strings);
! while((option_string = list_next(strings)) != NULL) {
for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) {
***************
*** 246,304 ****
}
! static int client_conf_set_variable(conf_params_t *params, arg_symbol_t var_symbol, const char *var_value)
{
- /* FIXME: insert sanity checks on data. */
switch(var_symbol) {
! case CLIENT_VAR_HOSTNAME:
!
! if(params->client_hostname != NULL) {
! xfree(params->client_hostname);
! params->client_hostname = NULL;
! }
! params->client_hostname = xstrdup(var_value);
break;
-
! case CLIENT_VAR_DHCP_DISCOVERY_RETRIES:
!
! params->dhcp_discovery_retries = atoi(var_value);
! break;
case CLIENT_VAR_ICMP_RETRIES:
! params->icmp_retries = atoi(var_value);
! params->icmp_retries_set = 1;
break;
case CLIENT_VAR_INTERFACE_MTU:
!
! params->default_interface_mtu = atoi(var_value);
break;
default:
return 1;
}
return 0;
}
! static int client_conf_set_variable_boolean(conf_params_t *params, arg_symbol_t var_symbol, uint8_t bool_val)
{
! switch(var_symbol) {
!
! case CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP:
!
! params->do_measure_router_latency_icmp = bool_val;
! params->do_measure_router_latency_icmp_set = 1;
! break;
!
! default:
! return 1;
! }
return 0;
--- 371,432 ----
}
! /* setup a variable in params_t. */
! static int client_conf_set_variable(client_conf_params_t *params, arg_symbol_t var_symbol, const char *var_value)
{
+ conf_var_t *var = NULL;
+ int *int_val;
+ uint16_t *uint16_val;
switch(var_symbol) {
! /* string types can be created with no checking.
! * just attempt a copy (will exit on failure). */
! case CLIENT_VAR_HOSTNAME:
! var = dhcp_conf_var_create(var_symbol, xstrdup(var_value));
break;
! /* integer values greater than zero. use unsigned check
! * to prevent negative values. */
+ case CLIENT_VAR_DHCP_DISCOVERY_RETRIES:
case CLIENT_VAR_ICMP_RETRIES:
! if(!is_signed_numeric(var_value)) {
! ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value);
! return 1;
! }
!
! int_val = xmalloc(sizeof(int));
! *int_val = atoi(var_value);
!
! var = dhcp_conf_var_create(var_symbol, int_val);
break;
case CLIENT_VAR_INTERFACE_MTU:
! uint16_val = string_to_uint16(var_value);
! var = dhcp_conf_var_create(var_symbol, uint16_val);
break;
default:
+
+ ERROR_MESSAGE("unable to understand assignment value of : %s\n", var_value);
return 1;
}
+ add_or_replace_var(params->variables, var);
return 0;
}
! static int client_conf_set_variable_boolean(client_conf_params_t *params, arg_symbol_t var_symbol, uint8_t bool_val)
{
+ conf_var_t *var = NULL;
+ uint8_t *val;
! val = xmalloc(sizeof(uint8_t));
! *val = bool_val;
! var = dhcp_conf_var_create(var_symbol, val);
! add_or_replace_var(params->variables, var);
return 0;
***************
*** 319,322 ****
--- 447,524 ----
}
+ static uint8_t *get_conf_bit_array_var(client_conf_params_t *params, var_type_t var_type)
+ {
+ conf_var_t *var;
+ uint8_t *bit_array = NULL;
+
+ var = find_conf_var(var_type, params->variables);
+
+ if(var != NULL)
+ bit_array = dhcp_conf_var_get_val(var);
+
+ return bit_array;
+ }
+
+ static int get_conf_int_var(client_conf_params_t *params, var_type_t var_type, int default_val)
+ {
+ conf_var_t *var;
+ int *retries = NULL;
+
+ var = find_conf_var(var_type, params->variables);
+
+ if(var != NULL)
+ retries = dhcp_conf_var_get_val(var);
+
+ if(retries)
+ return *retries;
+ else
+ return default_val;
+ }
+
+ static uint8_t get_conf_bool_val(client_conf_params_t *params, var_type_t var_type, uint8_t default_val)
+ {
+ conf_var_t *var;
+ uint8_t *bool_val = NULL;
+
+ var = find_conf_var(var_type, params->variables);
+
+ if(var != NULL)
+ bool_val = dhcp_conf_var_get_val(var);
+
+ if(bool_val)
+ return *bool_val;
+ else
+ return default_val;
+ }
+
+ static uint16_t get_conf_uint16_val(client_conf_params_t *params, var_type_t var_type, uint16_t default_val)
+ {
+ conf_var_t *var;
+ uint16_t *uint16_val = NULL;
+
+ var = find_conf_var(var_type, params->variables);
+
+ if(var != NULL)
+ uint16_val = dhcp_conf_var_get_val(var);
+
+ if(uint16_val)
+ return *uint16_val;
+ else
+ return default_val;
+ }
+
+ static const char *get_conf_string_val(client_conf_params_t *params, var_type_t var_type)
+ {
+ conf_var_t *var;
+ const char *string_val = NULL;
+
+ var = find_conf_var(var_type, params->variables);
+
+ if(var != NULL)
+ string_val = dhcp_conf_var_get_val(var);
+
+ return string_val;
+ }
+
static int client_conf_load_options(client_conf_t *cc)
{
***************
*** 336,340 ****
/* read compiled directives. */
! if(directive_group_handler(&cc->parameters, conf->directives, DIRECTIVE_GROUP_NULL, NULL)) {
conf_destroy(conf);
return 1;
--- 538,542 ----
/* read compiled directives. */
! if(directive_group_handler(cc->params, conf->directives, DIRECTIVE_GROUP_NULL, NULL)) {
conf_destroy(conf);
return 1;
***************
*** 345,373 ****
}
! /* search through lower params and return best match. */
! static conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr)
{
! /* FIXME: this is broken -- needs to be fixed up. */
! conf_params_t *params;
! list_rewind(lower_params);
! while((params = list_next(lower_params)) != NULL) {
! if(params->group_type == DIRECTIVE_GROUP_IP_ADDRESS &&
! (ip == params->server_ip)) {
! return params;
! }
! if(params->group_type == DIRECTIVE_GROUP_MAC_ADDRESS &&
! (!memcmp(eth_addr.data, params->server_hw_addr.data, ETH_ADDR_LEN))) {
! return params;
! }
! /* recursively check lower parameters too. */
! if((params = get_params_for(params->lower_params, ip, eth_addr)) != NULL)
! return params;
! }
! return NULL;
}
--- 547,582 ----
}
! /* * * * * * * * * * * * * * * * * * *
! * params constructors/destructors *
! * * * * * * * * * * * * * * * * * * */
!
! static client_conf_params_t *params_create(void)
{
! client_conf_params_t *params;
! params = xmalloc(sizeof(client_conf_params_t));
! params->group_type = DIRECTIVE_GROUP_NULL;
! params->variables = list_create();
! params->lower_params = list_create();
! return params;
! }
! static void params_destroy_l(void *data)
! {
! client_conf_params_t *params = data;
! list_destroy(params->variables, dhcp_conf_var_destroy_l);
! list_destroy(params->lower_params, params_destroy_l);
! xfree(params);
! }
!
!
! static void params_destroy(client_conf_params_t *params)
! {
! /* call recursive function to destroy it and everything under it. */
! params_destroy_l(params);
! return;
}
***************
*** 376,389 ****
* * * * * * */
! /* get parameters to request: ip and eth addr silently ignored. */
! uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc)
{
! return cc->parameters.request_options;
}
! /* get number of retries for dhcp: ip and eth addr silently ignored. */
int client_conf_get_dhcp_discovery_retries(client_conf_t *cc)
{
! return cc->parameters.dhcp_discovery_retries;
}
--- 585,598 ----
* * * * * * */
! /* get parameters to request: this is always from the top level. */
! uint8_t *client_conf_get_request_opt_bit_array(client_conf_t *cc)
{
! return get_conf_bit_array_var(cc->params, CLIENT_VAR_REQUEST_OPTIONS);
}
! /* get number of retries for dhcp: this is always from the top level. */
int client_conf_get_dhcp_discovery_retries(client_conf_t *cc)
{
! return get_conf_int_var(cc->params, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_DEFAULT_DHCP_DISCOVERY_RETRIES);
}
***************
*** 391,414 ****
uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! conf_params_t *params;
!
! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr);
!
! if(params != NULL && params->required_set)
! return params->required_options;
! else
! return cc->parameters.required_options;
! }
!
! uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
! {
! conf_params_t *params;
!
! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr);
!
! if(params != NULL && params->configure_set)
! return 1;
! else
! return cc->parameters.configure_set;
}
--- 600,605 ----
uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr);
! return get_conf_bit_array_var(params, CLIENT_VAR_REQUIRE_OPTIONS);
}
***************
*** 416,427 ****
uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! conf_params_t *params;
!
! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr);
!
! if(params != NULL && params->configure_set)
! return params->configure_options;
! else
! return cc->parameters.configure_options;
}
--- 607,612 ----
uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr);
! return get_conf_bit_array_var(params, CLIENT_VAR_CONFIGURE_OPTIONS);
}
***************
*** 429,459 ****
int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! conf_params_t *params;
!
! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr);
!
! if(params != NULL && params->icmp_retries_set)
! return params->icmp_retries;
! else
! return cc->parameters.icmp_retries;
}
! /* get the hostname option the client should set. */
const char *client_conf_get_hostname(client_conf_t *cc)
{
! return cc->parameters.client_hostname;
}
! /* get the hostname option the client should set. */
uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! conf_params_t *params;
!
! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr);
!
! if(params != NULL && params->do_measure_router_latency_icmp_set)
! return params->do_measure_router_latency_icmp;
! else
! return cc->parameters.do_measure_router_latency_icmp;
}
--- 614,632 ----
int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr);
! return get_conf_int_var(params, CLIENT_VAR_ICMP_RETRIES, CLIENT_DEFAULT_ICMP_RETRIES);
}
! /* get the hostname option the client should set: always from the top level */
const char *client_conf_get_hostname(client_conf_t *cc)
{
! return get_conf_string_val(cc->params, CLIENT_VAR_HOSTNAME);
}
! /* find out whether or not we should attempt to measure router latency. */
uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr)
{
! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr);
! return get_conf_bool_val(params, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP);
}
***************
*** 461,465 ****
int client_conf_get_default_mtu(client_conf_t *cc)
{
! return cc->parameters.default_interface_mtu;
}
--- 634,638 ----
int client_conf_get_default_mtu(client_conf_t *cc)
{
! return get_conf_uint16_val(cc->params, CLIENT_VAR_INTERFACE_MTU, CLIENT_DEFAULT_MTU);
}
***************
*** 468,472 ****
* * * * * * * * * * * */
! static int directive_group_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
list_t *directive_list;
--- 641,645 ----
* * * * * * * * * * * */
! static int directive_group_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
list_t *directive_list;
***************
*** 507,511 ****
}
! static int directive_set_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
directive_t *directive = directive_data;
--- 680,684 ----
}
! static int directive_set_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
directive_t *directive = directive_data;
***************
*** 527,562 ****
}
! static int directive_request_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
directive_t *directive = directive_data;
list_t *args;
list_t *string_list;
args = directive->arguments;
string_list = list_first(args);
! if(fill_option_bit_array_from_string_list(string_list, params->request_options))
return 1;
return 0;
}
! static int directive_require_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
! directive_t *directive = directive_data;
! list_t *args;
! list_t *string_list;
! args = directive->arguments;
! string_list = list_first(args);
! if(fill_option_bit_array_from_string_list(string_list, params->required_options))
! return 1;
! params->required_set = 1;
return 0;
}
! static int directive_server_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
list_t *args;
--- 700,765 ----
}
! /* procified routine for request/require/configure etc: these all deal with bit arrays. */
! static int directive_option_array_handler_proc(client_conf_params_t *params, void *directive_data,
! directive_group_t group_type, void *group_data,
! var_type_t type)
{
directive_t *directive = directive_data;
list_t *args;
list_t *string_list;
+ uint8_t *options;
+ conf_var_t *var;
+ /* the first argument is the string list we want. */
args = directive->arguments;
string_list = list_first(args);
! /* create bit array. */
! options = xmalloc(sizeof(uint8_t) * MAX_OPTIONS_HANDLED);
!
! if(client_conf_fill_option_bit_array_from_string_list(string_list, options)) {
! xfree(options);
return 1;
+ }
+ var = dhcp_conf_var_create(type, options);
+ add_or_replace_var(params->variables, var);
return 0;
+
}
! static int directive_request_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
! return directive_option_array_handler_proc(params, directive_data,
! group_type, group_data,
! CLIENT_VAR_REQUEST_OPTIONS);
! }
! static int directive_require_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
! {
! return directive_option_array_handler_proc(params, directive_data,
! group_type, group_data,
! CLIENT_VAR_REQUIRE_OPTIONS);
! }
! static int directive_configure_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
! {
! return directive_option_array_handler_proc(params, directive_data,
! group_type, group_data,
! CLIENT_VAR_CONFIGURE_OPTIONS);
! }
!
! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
! {
return 0;
}
! static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
! {
! return 0;
! }
!
! static int directive_server_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
list_t *args;
***************
*** 564,568 ****
void *address_data;
void *directives;
! conf_params_t *new_params;
directive_group_t new_group_type;
directive_t *directive;
--- 767,771 ----
void *address_data;
void *directives;
! client_conf_params_t *new_params;
directive_group_t new_group_type;
directive_t *directive;
***************
*** 594,605 ****
address_data = list_get_by_index(args, 1);
directives = list_get_by_index(args, 2);
- new_params = xcalloc(sizeof(conf_params_t));
if(directive_group_handler(new_params, directives, new_group_type, address_data) < 0)
return 1;
- if(params->lower_params == NULL)
- params->lower_params = list_create();
-
list_add_to_end(params->lower_params, new_params);
--- 797,805 ----
address_data = list_get_by_index(args, 1);
directives = list_get_by_index(args, 2);
+ new_params = params_create();
if(directive_group_handler(new_params, directives, new_group_type, address_data) < 0)
return 1;
list_add_to_end(params->lower_params, new_params);
***************
*** 607,611 ****
}
! static int directive_set_boolean_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
{
directive_t *directive = directive_data;
--- 807,812 ----
}
! static int directive_set_boolean_handler(client_conf_params_t *params, void *directive_data,
! directive_group_t group_type, void *group_data)
{
directive_t *directive = directive_data;
***************
*** 627,656 ****
}
- static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data)
- {
- directive_t *directive = directive_data;
- list_t *args;
- list_t *string_list;
-
- args = directive->arguments;
- string_list = list_first(args);
-
- if(fill_option_bit_array_from_string_list(string_list, params->configure_options))
- return 1;
-
- /* always default with the timers. these must be set irregardless of what the user sets. */
- params->configure_options[TAG_DHCP_IP_ADDRESS_LEASE_TIME] = 1;
- params->configure_options[TAG_DHCP_REBINDING_TIME] = 1;
- params->configure_options[TAG_DHCP_RENEWAL_TIME] = 1;
-
- params->configure_set = 1;
- return 0;
-
- }
-
- /* * * * * * * * * * * * * * *
- * constructors/destructors *
- * * * * * * * * * * * * * * */
-
client_conf_t *create_client_conf(const char *interface)
{
--- 828,831 ----
***************
*** 660,675 ****
cc->interface = interface;
cc->conf_file = get_conf_options_fname(cc);
! cc->parameters.lower_params = list_create();
!
! cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */
!
! /* setup the defaults in the top level param datum.
! * these are all set in dhcp-client-defaults.h */
!
! cc->parameters.client_hostname = CLIENT_DEFAULT_HOSTNAME;
! cc->parameters.dhcp_discovery_retries = CLIENT_DEFAULT_DHCP_DISCOVERY_OFFER_RETRIES;
! cc->parameters.icmp_retries = CLIENT_DEFAULT_ICMP_RETRIES;
! cc->parameters.default_interface_mtu = CLIENT_DEFAULT_MTU;
! cc->parameters.do_measure_router_latency_icmp = CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP;
if(client_conf_load_options(cc)) {
--- 835,840 ----
cc->interface = interface;
cc->conf_file = get_conf_options_fname(cc);
! cc->params = params_create(); /* set top level to catchall group. */
! cc->params->group_type = DIRECTIVE_GROUP_NULL;
if(client_conf_load_options(cc)) {
***************
*** 681,711 ****
}
- static void params_destroy(conf_params_t *params, uint8_t topflag)
- {
- list_t *params_list;
- conf_params_t *lower_params;
-
- params_list = params->lower_params;
- list_rewind(params_list);
- for(lower_params = list_next(params_list); lower_params;
- lower_params = list_next(params_list)) {
- params_destroy(lower_params, 0);
- }
-
- if(params->client_hostname)
- xfree(params->client_hostname);
-
- list_destroy(params->lower_params, NULL);
- params->lower_params = NULL;
-
- if(!topflag)
- xfree(params);
- }
-
void client_conf_destroy(client_conf_t *cc)
{
! /* recursively kill all the parameters we've collected. */
! params_destroy(&cc->parameters, 1);
/* free up the client conf structure. */
--- 846,854 ----
}
void client_conf_destroy(client_conf_t *cc)
{
! /* destroy loaded parameters. */
! params_destroy(cc->params);
/* free up the client conf structure. */
Index: dhcp-client-conf.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** dhcp-client-conf.h 3 Jan 2003 22:05:07 -0000 1.10
--- dhcp-client-conf.h 25 Mar 2003 03:06:19 -0000 1.11
***************
*** 41,90 ****
typedef struct {
! directive_group_t group_type;
!
! ip_addr_t server_ip;
! eth_addr_t server_hw_addr;
!
! /* these are never used in lower params so no _set variable. */
!
! uint8_t request_options[MAX_OPTIONS_HANDLED + 1]; /* which options we request. */
! int dhcp_discovery_retries; /* amount of times we should retry dhcp operations. */
! int default_interface_mtu; /* our default interface mtu. */
! char *client_hostname; /* setting for the hostname option. */
!
! uint8_t required_set;
! uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */
!
! uint8_t configure_set;
! uint8_t configure_options[MAX_OPTIONS_HANDLED + 1]; /* which options we actually handle. */
! uint8_t icmp_retries_set; /* whether the icmp retries is explicitly set. */
! int icmp_retries; /* amount of times we should retry icmp operations. */
! uint8_t do_measure_router_latency_icmp_set; /* whether the router latency is explicitly set. */
! uint8_t do_measure_router_latency_icmp; /* perform router latency discovery via icmp. */
! list_t *lower_params; /* linked list to child parameters. */
! } conf_params_t;
typedef struct {
! char *conf_file;
const char *interface; /* points to dhcp_client_control->interface */
! conf_params_t parameters;
} client_conf_t;
/* typedef of directive handler. */
! typedef int (*directive_handler_t)(conf_params_t *param, void *directive_data, directive_group_t group_type, void *group_data);
/* directive types. */
! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, DIRECTIVE_CONFIGURE };
/* symbols for variable substitution. */
! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU };
!
! /* symbols for boolean variable substitution */
! enum var_boolean_symbols { CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP = 0 };
/* server symbol substitution. */
--- 41,81 ----
typedef struct {
! /* server specific options. may be set to hardware address or
! * IP address matching. */
! directive_group_t group_type;
! /* depending on what kind of grouping these two addresses may be used. */
! ip_addr_t server_ip; /* server ip address. */
! eth_addr_t server_hw_addr; /* server hw address. */
! list_t *variables; /* variables of type var_t. */
! list_t *lower_params; /* linked list to child parameters. */
!
! } client_conf_params_t;
typedef struct {
!
! char *conf_file; /* name of conf file. */
const char *interface; /* points to dhcp_client_control->interface */
! /* the top level conf_params_t -- top level is for any server.
! * we have lower level ones pointed from the top level. */
! client_conf_params_t *params;
!
} client_conf_t;
/* typedef of directive handler. */
! typedef int (*directive_handler_t)(client_conf_params_t *param, void *directive_data, directive_group_t group_type, void *group_data);
/* directive types. */
! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP,
! DIRECTIVE_CONFIGURE, DIRECTIVE_APPEND, DIRECTIVE_PREPEND };
/* symbols for variable substitution. */
! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU,
! CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS,
! CLIENT_VAR_CONFIGURE_OPTIONS };
/* server symbol substitution. */
***************
*** 99,113 ****
extern int client_conf_reread(client_conf_t *cc);
! extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc);
extern int client_conf_get_dhcp_discovery_retries(client_conf_t *cc);
- extern int client_conf_get_default_mtu(client_conf_t *cc);
extern const char *client_conf_get_hostname(client_conf_t *cc);
extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
- extern uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
!
#endif /* DHCP_CLIENT_CONF_H */
--- 90,103 ----
extern int client_conf_reread(client_conf_t *cc);
! extern uint8_t *client_conf_get_request_opt_bit_array(client_conf_t *cc);
extern int client_conf_get_dhcp_discovery_retries(client_conf_t *cc);
extern const char *client_conf_get_hostname(client_conf_t *cc);
+ extern int client_conf_get_default_mtu(client_conf_t *cc);
extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr);
! extern int client_conf_get_default_mtu(client_conf_t *cc);
#endif /* DHCP_CLIENT_CONF_H */
|