[dhcp-agent-commits] dhcp-agent/src Makefile.am,1.30,1.31 dhcp-conf.c,1.10,1.11 dhcp-conf.h,1.3,1.4
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9986/src Modified Files: Makefile.am dhcp-conf.c dhcp-conf.h dhcp-lease.h dhcp-lease.c dhcp-server-conf.c dhcp-server-conf.h Log Message: added lease-range directive to dhcp server conf Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Makefile.am 8 Jul 2003 07:02:12 -0000 1.30 --- Makefile.am 12 Jul 2003 17:42:36 -0000 1.31 *************** *** 17,21 **** ! noinst_HEADERS = dhcp-align.h dhcp-client-cache.h dhcp-client.h dhcp-daemon.h dhcp-interface.h \ dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h dhcp-tokenizer.h \ --- 17,21 ---- ! noinst_HEADERS = dhcp-align.h dhcp-client-cache.h dhcp-client.h dhcp-interface.h \ dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h dhcp-tokenizer.h \ *************** *** 52,56 **** dhcp-option.c \ dhcp-option-convert.c \ ! dhcp-daemon.c dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 52,58 ---- dhcp-option.c \ dhcp-option-convert.c \ ! dhcp-daemon.c \ ! dhcp-options-strings.c ! dhcp_sniff_SOURCES = dhcp-sniff.c \ *************** *** 64,68 **** dhcp-client-conf.c \ dhcp-client-states.c \ - dhcp-options-strings.c \ dhcp-sysconf.c \ dhcp-client-guile.c --- 66,69 ---- *************** *** 80,82 **** install-exec-am: ! mkdir -p ${dhcplocalstatedir} ${dhcplocalstate_clientdir} --- 81,83 ---- install-exec-am: ! mkdir -p ${dhcplocalstatedir} ${dhcplocalstate_clientdir} ${dhcplocalstate_serverdir} Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-conf.c 3 Jan 2003 21:29:22 -0000 1.10 --- dhcp-conf.c 12 Jul 2003 17:42:36 -0000 1.11 *************** *** 41,45 **** static void *compile_arg_identifier(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); ! static void *compile_arg_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_assignment(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_boolean(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); --- 41,46 ---- static void *compile_arg_identifier(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); ! static void *compile_arg_ip_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); ! static void *compile_arg_hw_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_assignment(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_boolean(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); *************** *** 58,62 **** argument_compiler_t argument_compilers[] = { compile_arg_identifier, ! compile_arg_address, compile_arg_assignment, compile_arg_boolean, --- 59,64 ---- argument_compiler_t argument_compilers[] = { compile_arg_identifier, ! compile_arg_ip_address, ! compile_arg_hw_address, compile_arg_assignment, compile_arg_boolean, *************** *** 221,228 **** } ! static void *compile_arg_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { ip_addr_t *ip_addr = NULL; - eth_addr_t *eth_addr = NULL; const char *string; token_t token; --- 223,229 ---- } ! static void *compile_arg_ip_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { ip_addr_t *ip_addr = NULL; const char *string; token_t token; *************** *** 234,256 **** string = tokenizer_get_data(conf->tokenizer); ! if(strchr(string, '.') != NULL) { ! ! /* ip addr. */ ! ip_addr = string_ip_to_ip_addr(string); ! return ip_addr; ! ! } else if(strchr(string, ':') != NULL) { ! ! /* eth addr. */ ! eth_addr = string_eth_addr_to_eth_addr(string); ! return eth_addr; ! } else { ! ERROR_MESSAGE("unable to parse: %s into address", string); return NULL; ! } ! } --- 235,256 ---- string = tokenizer_get_data(conf->tokenizer); + ip_addr = string_ip_to_ip_addr(string); + return ip_addr; + } ! static void *compile_arg_hw_address(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) ! { ! eth_addr_t *eth_addr = NULL; ! const char *string; ! token_t token; ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_STRING) return NULL; ! ! string = tokenizer_get_data(conf->tokenizer); ! eth_addr = string_eth_addr_to_eth_addr(string); ! return eth_addr; } Index: dhcp-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-conf.h 16 Dec 2002 07:20:42 -0000 1.3 --- dhcp-conf.h 12 Jul 2003 17:42:36 -0000 1.4 *************** *** 34,38 **** /* conf argument types -- these index the argument drivers. */ ! enum conf_argument_type { CONF_IDENTIFIER = 0, CONF_ADDRESS, CONF_ASSIGNMENT, CONF_BOOLEAN, CONF_STRING, CONF_STRING_LIST, CONF_GROUP }; --- 34,38 ---- /* conf argument types -- these index the argument drivers. */ ! enum conf_argument_type { CONF_IDENTIFIER = 0, CONF_ADDRESS, CONF_MAC_ADDRESS, CONF_ASSIGNMENT, CONF_BOOLEAN, CONF_STRING, CONF_STRING_LIST, CONF_GROUP }; Index: dhcp-lease.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-lease.h 6 Jul 2003 05:37:44 -0000 1.2 --- dhcp-lease.h 12 Jul 2003 17:42:36 -0000 1.3 *************** *** 35,42 **** eth_addr_t hw_address; /* hardware address. */ char *hostname; /* hostname. */ - struct { - ip_addr_t bottom_range; - ip_addr_t top_range; - } range; /* range of addresses. */ } data; --- 35,38 ---- *************** *** 46,53 **** typedef struct { ! lease_constraint_t *constraint; /* constraints if any. */ ! ip_addr_t addr_net; /* network_address. */ ! ip_addr_t netmask; /* network netmask. */ list_t *options; /* options to be passed. */ --- 42,58 ---- typedef struct { ! int lease_type; ! lease_constraint_t *constraint; /* constraints if any. */ ! union { ! ! ip_addr_t address; /* single ip address. */ ! ! struct { ! ip_addr_t bottom_range; ! ip_addr_t top_range; ! } address_range; /* range of addresses. */ ! ! } address_info; list_t *options; /* options to be passed. */ *************** *** 62,66 **** typedef struct { ! lease_definition_t *defintion; /* lease definition. */ time_t ini_assigned; /* initially assigned timestamp. */ --- 67,71 ---- typedef struct { ! lease_definition_t *definition; /* lease definition. */ time_t ini_assigned; /* initially assigned timestamp. */ *************** *** 71,75 **** /* constants. */ ! enum lease_constraint_type { LEASE_CONSTRAINT_NONE = 0, LEASE_CONSTRAINT_HARDWARE_ADDRESS, LEASE_CONSTRAINT_HOSTNAME, LEASE_CONSTRAINT_ADDRESS_RANGE }; /* prototypes. */ --- 76,81 ---- /* constants. */ ! enum lease_constraint_type { LEASE_CONSTRAINT_NONE = 0, LEASE_CONSTRAINT_HARDWARE_ADDRESS, LEASE_CONSTRAINT_HOSTNAME }; ! enum lease_type { LEASE_SINGLE_ADDRESS = 0, LEASE_RANGE_ADDRESS }; /* prototypes. */ *************** *** 78,86 **** extern void lease_constraint_destroy(lease_constraint_t *lease_constraint); extern lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ! ip_addr_t ip_addr_range, list_t *options, uint32_t lease_expiry, uint32_t renew_time, uint32_t rebind_time); extern void lease_definition_destroy(lease_definition_t *lease_def); --- 84,94 ---- extern void lease_constraint_destroy(lease_constraint_t *lease_constraint); extern lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ! int lease_type, ! void *data, list_t *options, uint32_t lease_expiry, uint32_t renew_time, uint32_t rebind_time); + extern void lease_definition_destroy(lease_definition_t *lease_def); Index: dhcp-lease.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-lease.c 6 Jul 2003 05:37:44 -0000 1.2 --- dhcp-lease.c 12 Jul 2003 17:42:36 -0000 1.3 *************** *** 36,46 **** * * * * * * * * * * */ lease_constraint_t *lease_constraint_create(int constraint_type, void *data) { - lease_constraint_t *constraint = xcalloc(sizeof(lease_constraint_t)); char *hostname; ! list_t *address_range; ! // ip_addr_t range_top, range_bottom; constraint->constraint_type = constraint_type; --- 36,46 ---- * * * * * * * * * * */ + /* create a constraint for a lease based on constraint type, and data passed. */ lease_constraint_t *lease_constraint_create(int constraint_type, void *data) { char *hostname; ! lease_constraint_t *constraint; + constraint = xcalloc(sizeof(lease_constraint_t)); constraint->constraint_type = constraint_type; *************** *** 56,66 **** break; - case LEASE_CONSTRAINT_ADDRESS_RANGE: - address_range = data; - - hostname = data; - constraint->data.hostname = xstrdup(hostname); - break; - default: FATAL_MESSAGE("illegal constraint type passed. this is a bug report me."); --- 56,59 ---- *************** *** 70,73 **** --- 63,67 ---- } + /* destroy a lease constraint. */ void lease_constraint_destroy(lease_constraint_t *constraint) { *************** *** 78,82 **** break; - case LEASE_CONSTRAINT_ADDRESS_RANGE: /* fall through. */ case LEASE_CONSTRAINT_HARDWARE_ADDRESS: /* fall through. */ case LEASE_CONSTRAINT_NONE: /* fall through. */ --- 72,75 ---- *************** *** 91,95 **** lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ! ip_addr_t ip_addr_range, list_t *options, uint32_t lease_expiry, --- 84,89 ---- lease_definition_t *lease_definition_create(lease_constraint_t *constraint, ! int lease_type, ! void *data, list_t *options, uint32_t lease_expiry, *************** *** 99,110 **** dhcp_opt_t *opt, *opt_copy; lease_definition_t *lease_def; lease_def = xcalloc(sizeof(lease_definition_t)); lease_def->constraint = constraint; - // lease_def->addr_range = ip_addr_range; ! /* copy our dhcp options we'll pass. */ lease_def->options = list_create(); --- 93,121 ---- dhcp_opt_t *opt, *opt_copy; lease_definition_t *lease_def; + list_t *addr_range; lease_def = xcalloc(sizeof(lease_definition_t)); + /* assign constraint. */ lease_def->constraint = constraint; ! /* setup addresses. */ ! switch(lease_type) { ! ! case LEASE_SINGLE_ADDRESS: ! lease_def->address_info.address = *(ip_addr_t *)data; ! break; ! ! case LEASE_RANGE_ADDRESS: ! addr_range = data; ! lease_def->address_info.address_range.bottom_range = *(ip_addr_t *)list_first(addr_range); ! lease_def->address_info.address_range.top_range = *(ip_addr_t *)list_second(addr_range); ! break; ! ! default: ! FATAL_MESSAGE("invalid lease type specified for creation. this is a bug. report me."); ! } + /* copy our dhcp options we'll pass. */ lease_def->options = list_create(); *************** *** 137,138 **** --- 148,150 ---- return; } + Index: dhcp-server-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-server-conf.c 8 Jul 2003 07:03:52 -0000 1.3 --- dhcp-server-conf.c 12 Jul 2003 17:42:36 -0000 1.4 *************** *** 30,33 **** --- 30,34 ---- #include "dhcp-librawnet.h" #include "dhcp-option.h" + #include "dhcp-lease.h" #include "dhcp-conf.h" *************** *** 35,38 **** --- 36,40 ---- #include "dhcp-server-conf.h" #include "dhcp-server-defaults.h" + #include "dhcp-options-strings.h" static const char *var_strings[] = { *************** *** 51,56 **** static const arg_type_t range_lease_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_ADDRESS, CONF_GROUP}; ! static const char **range_lease_arg_strings[] = { var_strings, NULL, NULL }; ! static const arg_symbol_t *range_lease_arg_symbols[] = { var_symbols, NULL, NULL }; /* command structures. */ --- 53,62 ---- static const arg_type_t range_lease_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_ADDRESS, CONF_GROUP}; ! static const char **range_lease_arg_strings[] = { var_strings, NULL, NULL, NULL }; ! static const arg_symbol_t *range_lease_arg_symbols[] = { var_symbols, NULL, NULL, NULL }; ! ! static const arg_type_t option_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST }; ! static const char **option_arg_strings[] = { NULL, NULL, NULL }; ! static const arg_symbol_t *option_arg_symbols[] = { NULL, NULL, NULL }; /* command structures. */ *************** *** 66,71 **** }; ! /* set command. */ ! static const command_t range_lease = { DIRECTIVE_RANGE_LEASE, "range-lease", --- 72,77 ---- }; ! /* range-lease command. */ ! static const command_t command_range_lease = { DIRECTIVE_RANGE_LEASE, "range-lease", *************** *** 76,82 **** }; static const command_t *commands[] = { &command_set, ! &range_lease, NULL, }; --- 82,98 ---- }; + static const command_t command_option = { + DIRECTIVE_OPTION, + "option", + 3, + option_arg_strings, + option_arg_types, + option_arg_symbols, + }; + static const command_t *commands[] = { &command_set, ! &command_range_lease, ! &command_option, NULL, }; *************** *** 84,89 **** /* forward declaration of directive handlers. */ ! static int directive_set_handler(server_conf_t *server_conf, directive_t *directive); ! static int directive_range_handler(server_conf_t *server_conf, directive_t *directive); /* indexed by directive types in dhcp-client-conf.h . */ --- 100,106 ---- /* forward declaration of directive handlers. */ ! static int directive_set_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); ! static int directive_range_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); ! static int directive_option_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 91,94 **** --- 108,112 ---- directive_set_handler, directive_range_handler, + directive_option_handler, }; *************** *** 198,202 **** /* read in the compiled directives. */ ! if(directive_handlers[directive->command_code](sc, directive)) return 1; } --- 216,220 ---- /* read in the compiled directives. */ ! if(directive_handlers[directive->command_code](sc, directive, GROUP_NULL, NULL)) return 1; } *************** *** 209,213 **** * * * * * * * * * * * */ ! static int directive_set_handler(server_conf_t *server_conf, directive_t *directive) { list_t *args; --- 227,232 ---- * * * * * * * * * * * */ ! /* variable set handler. */ ! static int directive_set_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) { list_t *args; *************** *** 228,233 **** } ! static int directive_range_handler(server_conf_t *server_conf, directive_t *directive) { return 0; } --- 247,342 ---- } ! /* lease range handler */ ! static int directive_range_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) { + lease_definition_t *lease_def; + + ip_addr_t bottom_address, top_address; + directive_t *lower_directive; + uint32_t lease_expiry = 0; + uint32_t renew_time = 0; + uint32_t rebind_time = 0; + list_t *args, *address_pair, *lease_directives; + list_t *option_list; + + /* arguments. */ + args = directive->arguments; + + /* get address pair, and create pair. */ + bottom_address = *(ip_addr_t *)list_first(args); + top_address = *(ip_addr_t *)list_second(args); + + address_pair = list_create(); + list_add(address_pair, &top_address); + list_add_to_end(address_pair, &bottom_address); + + /* create option list. */ + option_list = list_create(); + + /* parse lower directives. */ + lease_directives = list_get_by_index(args, 2); + + list_rewind(lease_directives); + while((lower_directive = list_next(lease_directives)) != NULL) { + + switch(lower_directive->command_code) { + + case DIRECTIVE_OPTION: + + if(directive_option_handler(server_conf, lower_directive, GROUP_LEASE_DEF, &option_list)) + return 1; + + break; + + default: + ERROR_MESSAGE("illegal directive specified in a range lease definition"); + } + } + + lease_def = lease_definition_create(NULL, LEASE_RANGE_ADDRESS, address_pair, option_list, lease_expiry, renew_time, rebind_time); + list_add(server_conf->lease_defs, lease_def); + + /* clean up. */ + list_destroy(address_pair, NULL); + dhcp_opt_destroy_option_list(option_list); + + return 0; + } + + /* lease option handler. */ + static int directive_option_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) + { + dhcp_opt_t *option = NULL; /* get rid of compiler warning. */ + list_t *option_list, *option_data_list; + char *option_name; + int i; + const char **option_strings; + + if(group_type == GROUP_NULL) { + ERROR_MESSAGE("dhcp option setting found outside of lease defintion"); + return 1; + } + + option_name = list_first(directive->arguments); + option_data_list = list_get_by_index(directive->arguments, 2); + option_strings = dhcp_option_conf_string_get_array(); + + for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { + + if(!strcmp(option_strings[i], option_name)) { + + option = dhcp_opt_create_from_user_string(i, option_data_list); + break; + } + } + + if(i == MAX_OPTIONS_HANDLED) { + ERROR_MESSAGE("unrecognized dhcp option specified by user config: %s", option_name); + return 1; + } + + option_list = group_data; + list_add_to_end(option_list, option); + return 0; } Index: dhcp-server-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-server-conf.h 8 Jul 2003 07:03:52 -0000 1.3 --- dhcp-server-conf.h 12 Jul 2003 17:42:36 -0000 1.4 *************** *** 40,49 **** } server_conf_t; ! typedef int (*directive_handler_t)(server_conf_t *server_conf, directive_t *directive_data); /* constants. */ enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT }; ! enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE }; /* prototypes. */ --- 40,50 ---- } server_conf_t; ! typedef int (*directive_handler_t)(server_conf_t *server_conf, directive_t *directive_data, int group_type, void *group_data); /* constants. */ enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT }; ! enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_OPTION }; ! enum group_types { GROUP_NULL = 0, GROUP_LEASE_DEF }; /* prototypes. */ |