[dhcp-agent-commits] dhcp-agent/src dhcp-client-conf.c,1.7,1.8 dhcp-client-conf.h,1.4,1.5 dhcp-clien
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-12-18 05:40:41
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv23391 Modified Files: dhcp-client-conf.c dhcp-client-conf.h dhcp-client-states.c dhcp-conf.c dhcp-options-strings.c Log Message: more code; more fun Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-conf.c 16 Dec 2002 07:20:41 -0000 1.7 --- dhcp-client-conf.c 18 Dec 2002 05:40:38 -0000 1.8 *************** *** 53,56 **** --- 53,62 ---- }; + /* strings for ip address or mac address with server command. */ + static const char *server_strings[] = { + "ip-address", + "mac-address", + }; + /* symbol arrays. */ *************** *** 63,66 **** --- 69,77 ---- }; + static const arg_symbol_t server_symbols[] = { + CLIENT_SERVER_IP, + CLIENT_SERVER_MAC, + }; + /* argument types, string array pointers, and symbol array pointers */ *************** *** 73,76 **** --- 84,95 ---- static const arg_symbol_t *request_arg_symbols[] = { NULL }; + static const arg_type_t require_arg_types[] = { CONF_STRING_LIST }; + static const char **require_arg_strings[] = { NULL }; + static const arg_symbol_t *require_arg_symbols[] = { 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 }; + static const arg_symbol_t *server_arg_symbols[] = { server_symbols, NULL, NULL }; + /* command structures. */ *************** *** 95,101 **** --- 114,142 ---- }; + /* request command. */ + static const command_t command_require = { + DIRECTIVE_REQUIRE, + "require", + 1, + require_arg_strings, + require_arg_types, + require_arg_symbols, + }; + + /* server command. */ + static const command_t command_server = { + DIRECTIVE_SERVER_GROUP, + "server", + 3, + server_arg_strings, + server_arg_types, + server_arg_symbols, + }; + static const command_t *commands[] = { &command_set, &command_request, + &command_require, + &command_server, NULL, }; *************** *** 105,109 **** * passed us by the user. */ - static const int default_config_options[] = { TAG_DHCP_SUBNET_MASK, /* Subnet Mask */ --- 146,149 ---- *************** *** 119,125 **** /* forward declaration of directive handlers. */ ! static int directive_group_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data); ! static int directive_set_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data); ! static int directive_request_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ --- 159,167 ---- /* forward declaration of directive handlers. */ ! static int directive_group_handler(conf_params_t *cc, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_set_handler(conf_params_t *cc, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_request_handler(conf_params_t *cc, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_require_handler(conf_params_t *cc, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_server_handler(conf_params_t *cc, void *directive_data, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 128,131 **** --- 170,175 ---- directive_set_handler, directive_request_handler, + directive_require_handler, + directive_server_handler, }; *************** *** 136,155 **** uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) { ! return cc->options; } int client_conf_get_dhcp_retries(client_conf_t *cc) { ! return cc->dhcp_retries; } int client_conf_get_icmp_retries(client_conf_t *cc) { ! return cc->icmp_retries; } const char *client_conf_get_hostname(client_conf_t *cc) { ! return cc->client_hostname; } --- 180,199 ---- uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) { ! return cc->parameters.request_options; } int client_conf_get_dhcp_retries(client_conf_t *cc) { ! return cc->parameters.dhcp_retries; } int client_conf_get_icmp_retries(client_conf_t *cc) { ! return cc->parameters.icmp_retries; } const char *client_conf_get_hostname(client_conf_t *cc) { ! return cc->parameters.client_hostname; } *************** *** 158,162 **** * * * * * * * * * * */ ! static int client_conf_set_variable(client_conf_t *cc, arg_symbol_t var_symbol, const char *var_value) { --- 202,232 ---- * * * * * * * * * * */ ! static int fill_option_bit_array_from_string_list(list_t *strings, uint8_t *option_bit_array) ! { ! char *option_string; ! const char **option_strings = dhcp_option_conf_string_get_array(); ! int i; ! ! for(;strings; strings = strings->next) { ! ! option_string = strings->data; ! ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { ! ! if(!strcmp(option_strings[i], option_string)) { ! option_bit_array[i] = 1; ! break; ! } ! } ! ! if(i > MAX_OPTIONS_HANDLED) ! return 1; ! } ! ! return 0; ! } ! ! ! static int client_conf_set_variable(conf_params_t *params, arg_symbol_t var_symbol, const char *var_value) { *************** *** 166,175 **** case CLIENT_VAR_HOSTNAME: ! if(cc->client_hostname != NULL) { ! xfree(cc->client_hostname); ! cc->client_hostname = NULL; } ! cc->client_hostname = xstrdup(var_value); break; --- 236,245 ---- case CLIENT_VAR_HOSTNAME: ! if(params->client_hostname != NULL) { ! xfree(params->client_hostname); ! params->client_hostname = NULL; } ! params->client_hostname = xstrdup(var_value); break; *************** *** 177,186 **** case CLIENT_VAR_DHCP_RETRIES: ! cc->dhcp_retries = atoi(var_value); break; case CLIENT_VAR_ICMP_RETRIES: ! cc->icmp_retries = atoi(var_value); break; --- 247,256 ---- case CLIENT_VAR_DHCP_RETRIES: ! params->dhcp_retries = atoi(var_value); break; case CLIENT_VAR_ICMP_RETRIES: ! params->icmp_retries = atoi(var_value); break; *************** *** 192,201 **** } - /* reset requested options. */ - static void client_conf_reset_options(client_conf_t *cc) - { - memset(cc->options, 0, sizeof(cc->options)); - } - static char *get_conf_options_fname(client_conf_t *cc) { --- 262,265 ---- *************** *** 210,230 **** } - static int client_conf_apply_directives(client_conf_t *cc, list_t *directives) - { - list_t *directive_list_ptr; - directive_t *directive; - - for(directive_list_ptr = directives; directive_list_ptr; - directive_list_ptr = directive_list_ptr->next) { - - directive = directive_list_ptr->data; - - if(directive_handlers[directive->command_code](cc, directive, GROUP_DIRECTIVE_NULL, NULL)) - return 1; - } - - return 0; - } - static int client_conf_load_options(client_conf_t *cc) { --- 274,277 ---- *************** *** 246,250 **** /* read compiled directives. */ ! if(client_conf_apply_directives(cc, conf->directives)) { conf_destroy(conf); return 1; --- 293,297 ---- /* read compiled directives. */ ! if(directive_group_handler(&cc->parameters, conf->directives, DIRECTIVE_GROUP_NULL, NULL)) { conf_destroy(conf); return 1; *************** *** 258,271 **** * * * * * * * * * * * */ ! static int directive_group_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data) { ! /* we ignore group_type and group_data for now. we don't support nested groups just yet. */ - /* FIXME: todo. */ return 0; } ! static int directive_set_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data) { list_t *args; arg_symbol_t *var_symbol; --- 305,350 ---- * * * * * * * * * * * */ ! static int directive_group_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! list_t *directive_list; ! directive_t *directive; ! ! /* setup group before handling directives under it. */ ! params->group_type = group_type; ! ! /* copy over data if applicable. */ ! switch(group_type) { ! ! case DIRECTIVE_GROUP_IP_ADDRESS: ! ! memcpy(¶ms->server_ip, group_data, IP_ADDR_LEN); ! break; ! ! case DIRECTIVE_GROUP_MAC_ADDRESS: ! ! memcpy(¶ms->server_hw_addr, group_data, ETH_ADDR_LEN); ! break; ! ! case DIRECTIVE_GROUP_NULL: /* fall through. */ ! default: ! break; ! ! } ! ! /* now process group. */ ! for(directive_list = directive_data; ! directive_list;directive_list = directive_list->next) { ! ! directive = directive_list->data; ! if(directive_handlers[directive->command_code](params, directive, group_type, group_data)) ! return 1; ! } return 0; } ! 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; list_t *args; arg_symbol_t *var_symbol; *************** *** 277,281 **** var_value = args->next->next->data; ! if(client_conf_set_variable(cc, *var_symbol, var_value)) { return 1; } --- 356,360 ---- var_value = args->next->next->data; ! if(client_conf_set_variable(params, *var_symbol, var_value)) { return 1; } *************** *** 284,312 **** } ! static int directive_request_handler(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data) { list_t *args; list_t *string_list; - const char **option_strings = dhcp_option_conf_string_get_array(); - char *option_requested; - uint8_t i; args = directive->arguments; ! for(string_list = args->data; string_list; string_list = string_list->next) { ! option_requested = string_list->data; ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { ! if(!strcmp(option_strings[i], option_requested)) { ! cc->options[i] = 1; ! break; ! } ! } ! if(i == MAX_OPTIONS_HANDLED) ! return 1; } return 0; } --- 363,441 ---- } ! 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 = args->data; ! 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 = args->data; ! ! if(fill_option_bit_array_from_string_list(string_list, params->required_options)) ! return 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; ! const arg_symbol_t *server_symbol; ! void *address_data; ! void *directives; ! conf_params_t *new_params; ! directive_group_t new_group_type; ! ! /* FIXME: check for the same group specified twice. ! * this gives us a bit of compression in the unlikely ! * case of a broken config file. */ ! ! args = directive_data; ! server_symbol = args->data; ! ! switch(*server_symbol) { ! ! case CLIENT_SERVER_IP: ! /* ip address. */ ! ! new_group_type = DIRECTIVE_GROUP_IP_ADDRESS; ! break; ! ! ! case CLIENT_SERVER_MAC: ! /* mac address. */ ! ! new_group_type = DIRECTIVE_GROUP_MAC_ADDRESS; ! break; ! ! default: ! FATAL_MESSAGE("illegal server directive group type. this is a bug report me."); ! exit(1); /* get rid of pesky compiler warnings. */ } + address_data = args->next->data; + directives = args->next->next->data; + new_params = xcalloc(sizeof(conf_params_t)); + + if(directive_group_handler(new_params, directives, new_group_type, address_data) < 0) + return 1; + + params->lower_params = add_to_list(params->lower_params, new_params); + return 0; } *************** *** 320,326 **** client_conf_t *cc; ! cc = xmalloc(sizeof(client_conf_t)); cc->interface = interface; ! client_conf_reset_options(cc); if(client_conf_load_options(cc)) { --- 449,455 ---- client_conf_t *cc; ! cc = xcalloc(sizeof(client_conf_t)); cc->interface = interface; ! cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */ if(client_conf_load_options(cc)) { *************** *** 334,337 **** --- 463,467 ---- void client_conf_destroy(client_conf_t *cc) { + /* FIXME: more to cleanup. */ xfree(cc); } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-conf.h 16 Dec 2002 07:20:41 -0000 1.4 --- dhcp-client-conf.h 18 Dec 2002 05:40:38 -0000 1.5 *************** *** 33,55 **** typedef struct { - char *conf_file; - const char *interface; /* points to dhcp_client_control->interface */ ! /* specific configurations */ ! unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ ! /* the option variables. */ char *client_hostname; /* setting for the hostname option. */ int dhcp_retries; /* amount of times we should retry dhcp operations. */ int icmp_retries; /* amount of times we should retry icmp operations. */ ! uint8_t do_icmp_router_discovery; /* perform router discovery via icmp. */ } client_conf_t; ! typedef int (*directive_handler_t)(client_conf_t *cc, directive_t *directive, directive_group_t group_type, void *group_data); ! enum directive_types { DIRECTIVE_GROUP = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST}; /* symbols for variable substitution. */ --- 33,64 ---- typedef struct { ! directive_group_t group_type; ! ip_addr_t server_ip; ! eth_addr_t server_hw_addr; ! uint8_t request_options[MAX_OPTIONS_HANDLED + 1]; /* which options we request. */ ! uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */ char *client_hostname; /* setting for the hostname option. */ int dhcp_retries; /* amount of times we should retry dhcp operations. */ int icmp_retries; /* amount of times we should retry icmp operations. */ ! uint8_t do_icmp_router_discovery; /* perform router 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 int (*directive_handler_t)(conf_params_t *param, void *directive_data, directive_group_t group_type, void *group_data); ! enum directive_types { DIRECTIVE_GROUP = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP }; /* symbols for variable substitution. */ *************** *** 57,61 **** CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY }; ! enum directive_group_t { GROUP_DIRECTIVE_NULL = 0, DIRECTIVE_GROUP_IP_ADDRESS, DIRECTIVE_GROUP_ETH_ADDRESS }; /* prototypes. */ --- 66,72 ---- CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY }; ! enum server_symbols { CLIENT_SERVER_IP = 0, CLIENT_SERVER_MAC }; ! ! enum directive_group_t { DIRECTIVE_GROUP_NULL = 0, DIRECTIVE_GROUP_IP_ADDRESS, DIRECTIVE_GROUP_MAC_ADDRESS }; /* prototypes. */ Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-states.c 16 Dec 2002 10:14:31 -0000 1.9 --- dhcp-client-states.c 18 Dec 2002 05:40:38 -0000 1.10 *************** *** 100,104 **** option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); ! options = add_to_list(options, option); /* dhcp message type. */ --- 100,106 ---- option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); ! if(option != NULL) ! options = add_to_list(options, option); ! /* dhcp message type. */ *************** *** 163,182 **** { /* FIXME: we default to at least. we need an actual policy in client_conf though. */ - const char *policy = NULL; - return 1; - if(policy == NULL) - policy = "atleast"; - - if(string_matches(policy, "exact")) - return (dhcp_have_exact_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); - else if(string_matches(policy, "atleast")) - return (dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); - else { /* bad policy : warn and use atleast */ - - WARN_MESSAGE("%s : set to bad value %s : going to use \"atleast\""); - return (dhcp_have_atleast_requested_options(dc->rawnet->dhcp_p, dc->conf->options)); - } - } --- 165,169 ---- Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-conf.c 16 Dec 2002 07:20:42 -0000 1.3 --- dhcp-conf.c 18 Dec 2002 05:40:38 -0000 1.4 *************** *** 485,489 **** list_t *list = data; ! purge_list(list, directive_destroy_l); return; --- 485,489 ---- list_t *list = data; ! purge_list(list, directive_destroy_l); /* free up a list of directives. */ return; Index: dhcp-options-strings.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-options-strings.c 16 Dec 2002 07:20:42 -0000 1.5 --- dhcp-options-strings.c 18 Dec 2002 05:40:38 -0000 1.6 *************** *** 79,83 **** "X-Windows Font Servers", /* 48 */ "X-Windows System Display Manager", /* 49 */ ! "Request IP Address", /* 50 */ "IP Address Lease Time", /* 51 */ "Option Overload", /* 52 */ --- 79,83 ---- "X-Windows Font Servers", /* 48 */ "X-Windows System Display Manager", /* 49 */ ! "Requested IP Address", /* 50 */ "IP Address Lease Time", /* 51 */ "Option Overload", /* 52 */ *************** *** 158,162 **** "x-windows-font-servers", /* 48 */ "x-windows-system-display-manager", /* 49 */ ! "request-ip-address", /* 50 */ "ip-address-lease-time", /* 51 */ "option-overload", /* 52 */ --- 158,162 ---- "x-windows-font-servers", /* 48 */ "x-windows-system-display-manager", /* 49 */ ! "requested-ip-address", /* 50 */ "ip-address-lease-time", /* 51 */ "option-overload", /* 52 */ *************** *** 186,190 **** /* accessors. */ - const char *dhcp_option_printable_string_get(int index) { --- 186,189 ---- |