[dhcp-agent-commits] dhcp-agent/src dhcp-lease.c,1.4,1.5 dhcp-lease.h,1.4,1.5 dhcp-server-conf.c,1.5
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-13 05:44:33
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv7594/src Modified Files: dhcp-lease.c dhcp-lease.h dhcp-server-conf.c dhcp-server-conf.h Log Message: added lease by hostname Index: dhcp-lease.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-lease.c 13 Jul 2003 04:53:30 -0000 1.4 --- dhcp-lease.c 13 Jul 2003 05:44:30 -0000 1.5 *************** *** 92,96 **** uint32_t rebind_time) { - dhcp_opt_t *opt, *opt_copy; lease_definition_t *lease_def; list_t *addr_range; --- 92,95 ---- *************** *** 98,101 **** --- 97,103 ---- lease_def = xcalloc(sizeof(lease_definition_t)); + /* assign type. */ + lease_def->lease_type = lease_type; + /* assign constraint. */ lease_def->constraint = constraint; *************** *** 118,131 **** } ! /* copy our dhcp options we'll pass. */ ! lease_def->options = list_create(); ! ! list_rewind(options); ! while((opt = list_next(options)) != NULL) { ! ! opt_copy = dhcp_option_copy(opt); ! ! list_add_to_end(lease_def->options, opt_copy); ! } /* FIXME: set renew/rebind to defaults if they are passed as zero. */ --- 120,125 ---- } ! /* options we'll pass. */ ! lease_def->options = options; /* FIXME: set renew/rebind to defaults if they are passed as zero. */ *************** *** 218,221 **** --- 212,230 ---- } + ip_addr_t lease_definition_get_bottom_addr(lease_definition_t *lease) + { + return lease->address_info.address_range.bottom_range; + } + + ip_addr_t lease_definition_get_top_addr(lease_definition_t *lease) + { + return lease->address_info.address_range.top_range; + } + + ip_addr_t lease_definition_get_addr(lease_definition_t *lease) + { + return lease->address_info.address; + } + /* * * * * * * * * * * misc utilities. * *************** *** 228,238 **** char *opt_val; dhcp_opt_t *option; INFO_MESSAGE("Lease type: %s", lease_type_to_string(lease_def)); if(lease_def->constraint == NULL) { INFO_MESSAGE("Lease constraint type: None."); } else { ! INFO_MESSAGE("Lease constraint type: ", lease_constraint_type_to_string(lease_def->constraint)); --- 237,271 ---- char *opt_val; dhcp_opt_t *option; + char *bottom_addr, *top_addr; INFO_MESSAGE("Lease type: %s", lease_type_to_string(lease_def)); + switch(lease_definition_get_type(lease_def)) { + + case LEASE_SINGLE_ADDRESS: + top_addr = ip_addr_to_string(lease_definition_get_addr(lease_def)); + + INFO_MESSAGE("Address: %s", top_addr); + xfree(top_addr); + break; + + case LEASE_RANGE_ADDRESS: + + bottom_addr = ip_addr_to_string(lease_definition_get_bottom_addr(lease_def)); + top_addr = ip_addr_to_string(lease_definition_get_top_addr(lease_def)); + + INFO_MESSAGE("Address Range: %s to %s", bottom_addr, top_addr); + xfree(bottom_addr); + xfree(top_addr); + break; + + default: + FATAL_MESSAGE("illegal lease type specified. this is a bug. report me."); + } + if(lease_def->constraint == NULL) { INFO_MESSAGE("Lease constraint type: None."); } else { ! INFO_MESSAGE("Lease constraint type: %s", lease_constraint_type_to_string(lease_def->constraint)); Index: dhcp-lease.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-lease.h 13 Jul 2003 04:53:30 -0000 1.4 --- dhcp-lease.h 13 Jul 2003 05:44:30 -0000 1.5 *************** *** 104,108 **** extern lease_constraint_t *lease_definition_get_constraint(lease_definition_t *lease); extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); ! extern eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint); extern void pretty_print_lease_def(lease_definition_t *lease_def); --- 104,110 ---- extern lease_constraint_t *lease_definition_get_constraint(lease_definition_t *lease); extern const char *lease_constraint_get_hostname(lease_constraint_t *constraint); ! extern ip_addr_t lease_definition_get_bottom_addr(lease_definition_t *lease); ! extern ip_addr_t lease_definition_get_top_addr(lease_definition_t *lease); ! extern ip_addr_t lease_definition_get_addr(lease_definition_t *lease); extern void pretty_print_lease_def(lease_definition_t *lease_def); Index: dhcp-server-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-server-conf.c 13 Jul 2003 04:52:48 -0000 1.5 --- dhcp-server-conf.c 13 Jul 2003 05:44:30 -0000 1.6 *************** *** 56,59 **** --- 56,63 ---- static const arg_symbol_t *range_lease_arg_symbols[] = { NULL, NULL, NULL }; + static const arg_type_t hostname_lease_arg_types[] = { CONF_STRING, CONF_ADDRESS, CONF_GROUP}; + static const char **hostname_lease_arg_strings[] = { NULL, NULL, NULL }; + static const arg_symbol_t *hostname_lease_arg_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 }; *************** *** 82,85 **** --- 86,99 ---- }; + /* range-lease command. */ + static const command_t command_hostname_lease = { + DIRECTIVE_HOSTNAME_LEASE, + "hostname-lease", + 3, + hostname_lease_arg_strings, + hostname_lease_arg_types, + hostname_lease_arg_symbols, + }; + static const command_t command_option = { DIRECTIVE_OPTION, *************** *** 95,98 **** --- 109,113 ---- &command_range_lease, &command_option, + &command_hostname_lease, NULL, }; *************** *** 103,106 **** --- 118,122 ---- 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); + static int directive_hostname_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 109,112 **** --- 125,129 ---- directive_range_handler, directive_option_handler, + directive_hostname_handler, }; *************** *** 247,262 **** } /* 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. */ --- 264,308 ---- } + static int directive_lease_handler_proc(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data, + list_t *option_list) + { + directive_t *lower_directive; + list_t *lease_directives, *args; + + /* arguments. */ + args = directive->arguments; + + /* 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"); + } + } + + return 0; + } + /* 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; ! list_t *args, *address_pair, *option_list; uint32_t lease_expiry = 0; uint32_t renew_time = 0; uint32_t rebind_time = 0; /* arguments. */ *************** *** 277,313 **** 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. */ --- 323,372 ---- list_add_to_end(address_pair, &bottom_address); ! /* create option handler by calling the general lease handler. */ option_list = list_create(); + directive_lease_handler_proc(server_conf, directive, group_type, group_data, option_list); ! 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); ! return 0; ! } ! static int directive_hostname_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) ! { ! uint32_t lease_expiry = 0; ! uint32_t renew_time = 0; ! uint32_t rebind_time = 0; ! lease_constraint_t *constraint; ! list_t *args, *option_list; ! char *hostname; ! ip_addr_t *ip_address; ! lease_definition_t *lease_def; ! /* arguments. */ ! args = directive->arguments; ! /* first argument is the hostname. */ ! hostname = list_first(args); ! if((constraint = lease_constraint_create(LEASE_CONSTRAINT_HOSTNAME, hostname)) == NULL) { ! ERROR_MESSAGE("illegal hostname constraint specified: %s", hostname); ! return 1; } ! ip_address = list_second(args); ! option_list = list_create(); ! directive_lease_handler_proc(server_conf, directive, group_type, group_data, option_list); + lease_def = lease_definition_create(constraint, LEASE_SINGLE_ADDRESS, ip_address, option_list, + lease_expiry, renew_time, rebind_time); list_add(server_conf->lease_defs, lease_def); return 0; } + /* lease option handler. */ Index: dhcp-server-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-server-conf.h 12 Jul 2003 17:42:36 -0000 1.4 --- dhcp-server-conf.h 13 Jul 2003 05:44:30 -0000 1.5 *************** *** 45,49 **** 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 }; --- 45,49 ---- enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT }; ! enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_OPTION, DIRECTIVE_HOSTNAME_LEASE }; enum group_types { GROUP_NULL = 0, GROUP_LEASE_DEF }; |