Thread: [dhcp-agent-commits] dhcp-agent/src dhcp-server-conf.c,1.9,1.10 dhcp-server-conf.h,1.7,1.8
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-26 23:46:55
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv4988/src Modified Files: dhcp-server-conf.c dhcp-server-conf.h Log Message: added local-subnet variable; added subnet declaration before lease definition Index: dhcp-server-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-server-conf.c 20 Jul 2003 05:51:35 -0000 1.9 --- dhcp-server-conf.c 26 Jul 2003 23:46:51 -0000 1.10 *************** *** 70,73 **** --- 70,81 ---- static const arg_symbol_t *option_arg_symbols[] = { NULL, NULL, NULL }; + static const arg_type_t local_subnet_arg_types[] = { CONF_ADDRESS, CONF_ADDRESS }; + static const char **local_subnet_arg_strings[] = { NULL, NULL }; + static const arg_symbol_t *local_subnet_arg_symbols[] = { NULL, NULL }; + + static const arg_type_t subnet_arg_types[] = { CONF_ADDRESS, CONF_ADDRESS, CONF_GROUP }; + static const char **subnet_arg_strings[] = { NULL, NULL }; + static const arg_symbol_t *subnet_arg_symbols[] = { NULL, NULL }; + /* command structures. */ *************** *** 121,124 **** --- 129,150 ---- }; + static const command_t command_local_subnet = { + DIRECTIVE_LOCAL_SUBNET, + "local-subnet", + 2, + local_subnet_arg_strings, + local_subnet_arg_types, + local_subnet_arg_symbols, + }; + + static const command_t command_subnet = { + DIRECTIVE_SUBNET, + "subnet", + 3, + subnet_arg_strings, + subnet_arg_types, + subnet_arg_symbols, + }; + static const command_t *commands[] = { &command_set, *************** *** 127,130 **** --- 153,158 ---- &command_mac_lease, &command_option, + &command_local_subnet, + &command_subnet, NULL, }; *************** *** 137,140 **** --- 165,170 ---- static int directive_hostname_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); static int directive_hw_address_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); + static int directive_local_subnet_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); + static int directive_subnet_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 145,148 **** --- 175,180 ---- directive_hw_address_handler, directive_option_handler, + directive_local_subnet_handler, + directive_subnet_handler, }; *************** *** 300,303 **** --- 332,336 ---- } + /* procified lease handler. */ static int directive_lease_handler_proc(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data, list_t *option_list) *************** *** 342,345 **** --- 375,391 ---- uint32_t renew_time = 0; uint32_t rebind_time = 0; + list_t *subnet_data; + ip_addr_t subnet_address, subnet_mask; + + if(group_type != GROUP_SUBNET_DEF) { + ERROR_MESSAGE("lease definition specified outside of subnet declaration."); + return 1; + } + + subnet_data = group_data; + + /* get subnet information. */ + subnet_address = *(ip_addr_t *)list_first(subnet_data); + subnet_mask = *(ip_addr_t *)list_second(subnet_data); /* arguments. */ *************** *** 364,368 **** directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, 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); --- 410,415 ---- directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, group_data, option_list); ! lease_def = lease_definition_create(NULL, subnet_address, subnet_mask, LEASE_RANGE_ADDRESS, ! address_pair, option_list, lease_expiry, renew_time, rebind_time); list_add(server_conf->lease_defs, lease_def); *************** *** 384,387 **** --- 431,447 ---- uint32_t renew_time = 0; uint32_t rebind_time = 0; + list_t *subnet_data; + ip_addr_t subnet_address, subnet_mask; + + if(group_type != GROUP_SUBNET_DEF) { + ERROR_MESSAGE("lease definition specified outside of subnet declaration."); + return 1; + } + + subnet_data = group_data; + + /* get subnet information. */ + subnet_address = *(ip_addr_t *)list_first(subnet_data); + subnet_mask = *(ip_addr_t *)list_second(subnet_data); /* arguments. */ *************** *** 400,405 **** directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, 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); --- 460,465 ---- directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, group_data, option_list); ! lease_def = lease_definition_create(constraint, subnet_address, subnet_mask, LEASE_SINGLE_ADDRESS, ! ip_address, option_list, lease_expiry, renew_time, rebind_time); list_add(server_conf->lease_defs, lease_def); *************** *** 419,422 **** --- 479,495 ---- uint32_t renew_time = 0; uint32_t rebind_time = 0; + list_t *subnet_data; + ip_addr_t subnet_address, subnet_mask; + + if(group_type != GROUP_SUBNET_DEF) { + ERROR_MESSAGE("lease definition specified outside of subnet declaration."); + return 1; + } + + subnet_data = group_data; + + /* get subnet information. */ + subnet_address = *(ip_addr_t *)list_first(subnet_data); + subnet_mask = *(ip_addr_t *)list_second(subnet_data); /* arguments. */ *************** *** 437,442 **** directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, 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); --- 510,515 ---- directive_lease_handler_proc(server_conf, directive, GROUP_LEASE_DEF, group_data, option_list); ! lease_def = lease_definition_create(constraint, subnet_address, subnet_mask, LEASE_SINGLE_ADDRESS, ! ip_address, option_list, lease_expiry, renew_time, rebind_time); list_add(server_conf->lease_defs, lease_def); *************** *** 487,490 **** --- 560,634 ---- } + /* handle subnet specification. */ + static int directive_local_subnet_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) + { + ip_addr_t *network, *mask; + list_t *subnet_data; + + + network = xcalloc(sizeof(ip_addr_t)); + mask = xcalloc(sizeof(ip_addr_t)); + + memcpy(network, list_first(directive->arguments), IP_ADDR_LEN); + memcpy(mask, list_second(directive->arguments), IP_ADDR_LEN); + + subnet_data = list_create(); + + list_add(subnet_data, network); + list_add(subnet_data, mask); + + list_add(server_conf->local_subnets, subnet_data); + + return 0; + } + + static int directive_subnet_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data) + { + directive_t *subnet_directive; + list_t *subnet_directives; + list_t *subnet_data; + ip_addr_t *network, *mask; + + /* copy out subnet information. */ + network = xcalloc(sizeof(ip_addr_t)); + mask = xcalloc(sizeof(ip_addr_t)); + + memcpy(network, list_first(directive->arguments), IP_ADDR_LEN); + memcpy(mask, list_second(directive->arguments), IP_ADDR_LEN); + + subnet_data = list_create(); + + list_add(subnet_data, mask); + list_add(subnet_data, network); + + /* parse lower directives. */ + subnet_directives = list_get_by_index(directive->arguments, 2); + + list_rewind(subnet_directives); + while((subnet_directive = list_next(subnet_directives)) != NULL) { + + switch(subnet_directive->command_code) { + + case DIRECTIVE_RANGE_LEASE: + case DIRECTIVE_HOSTNAME_LEASE: + case DIRECTIVE_MAC_LEASE: + + if(directive_handlers[subnet_directive->command_code](server_conf, subnet_directive, GROUP_SUBNET_DEF, subnet_data)) + return 1; + + break; + + default: + ERROR_MESSAGE("illegal directive specified in a subnet definition"); + return 1; + } + } + + /* we don't need the subnet information anymore. */ + list_destroy(subnet_data, xfree); + + return 0; + } + /* * * * * * * * * * * * public interface * *************** *** 501,504 **** --- 645,649 ---- /* setup lease definitions. */ sc->lease_defs = list_create(); + sc->local_subnets = list_create(); /* set defaults. */ *************** *** 510,513 **** --- 655,662 ---- server_conf_destroy(sc); return NULL; + } + + if(list_get_len(sc->local_subnets) == 0) { + WARN_MESSAGE("no local subnets specified. may assume all subnets as local."); } Index: dhcp-server-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-server-conf.h 15 Jul 2003 10:56:34 -0000 1.7 --- dhcp-server-conf.h 26 Jul 2003 23:46:51 -0000 1.8 *************** *** 39,42 **** --- 39,43 ---- uint16_t poll_timeout; /* poll timeout -- used in server event processing. */ + list_t *local_subnets; /* list of subnets. */ } server_conf_t; *************** *** 46,51 **** enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT, SERVER_VAR_POLL_TIMEOUT }; ! enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_HOSTNAME_LEASE, DIRECTIVE_MAC_LEASE, DIRECTIVE_OPTION }; ! enum group_types { GROUP_NULL = 0, GROUP_LEASE_DEF }; /* prototypes. */ --- 47,53 ---- enum var_symbols { SERVER_VAR_RENEW_PERCENT = 0, SERVER_VAR_REBIND_PERCENT, SERVER_VAR_POLL_TIMEOUT }; ! enum directive_types { DIRECTIVE_SET = 0, DIRECTIVE_RANGE_LEASE, DIRECTIVE_HOSTNAME_LEASE, ! DIRECTIVE_MAC_LEASE, DIRECTIVE_OPTION, DIRECTIVE_LOCAL_SUBNET, DIRECTIVE_SUBNET }; ! enum group_types { GROUP_NULL = 0, GROUP_LEASE_DEF, GROUP_SUBNET_DEF }; /* prototypes. */ |