[dhcp-agent-commits] dhcp-agent/src dhcp-lease.c,1.3,1.4 dhcp-lease.h,1.3,1.4 dhcp-server.c,1.6,1.7
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2003-07-13 04:53:33
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv2813/src Modified Files: dhcp-lease.c dhcp-lease.h dhcp-server.c dhcp-server.h Log Message: server allows config check now Index: dhcp-lease.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-lease.c 12 Jul 2003 17:42:36 -0000 1.3 --- dhcp-lease.c 13 Jul 2003 04:53:30 -0000 1.4 *************** *** 31,34 **** --- 31,35 ---- #include "dhcp-lease.h" #include "dhcp-option.h" + #include "dhcp-options-strings.h" /* * * * * * * * * * * *************** *** 149,150 **** --- 150,284 ---- } + /* 2string arrays: all indexed against enums in dhcp-lease.h */ + + /* constraint type to string. */ + static const char *lease_constraint2string[] = { + "None", + "Hardware Address", + "Hostname", + }; + + /* lease type to string. */ + static const char *lease_type2string[] = { + "Single Address", + "Range Address", + }; + + /* * * * * * * * + * accessors. * + * * * * * * * */ + + /* lease constraint. */ + + const char *lease_constraint_type_to_string(lease_constraint_t *constraint) + { + int constraint_type = constraint->constraint_type; + + if(constraint_type >= NELMS(lease_constraint2string)) + return "Out of bounds."; + + return lease_constraint2string[constraint_type]; + } + + int lease_constraint_get_type(lease_constraint_t *constraint) + { + return constraint->constraint_type; + } + + const char *lease_constraint_get_hostname(lease_constraint_t *constraint) + { + return constraint->data.hostname; + } + + eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint) + { + return constraint->data.hw_address; + } + + /* lease definition. */ + + const char *lease_type_to_string(lease_definition_t *lease) + { + int lease_type = lease->lease_type; + + if(lease_type >= NELMS(lease_type2string)) + return "Out of bounds."; + + return lease_type2string[lease_type]; + } + + int lease_definition_get_type(lease_definition_t *lease) + { + return lease->lease_type; + } + + lease_constraint_t *lease_definition_get_constraint(lease_definition_t *lease) + { + return lease->constraint; + } + + /* * * * * * * * * * + * misc utilities. * + * * * * * * * * * */ + + void pretty_print_lease_def(lease_definition_t *lease_def) + { + char *hw_address; + const char *opt_name; + 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)); + + switch(lease_def->constraint->constraint_type) { + + case LEASE_CONSTRAINT_NONE: + break; + + case LEASE_CONSTRAINT_HARDWARE_ADDRESS: + hw_address = eth_addr_to_string(lease_def->constraint->data.hw_address); + INFO_MESSAGE("Hardware Address: %s", hw_address); + xfree(hw_address); + break; + + case LEASE_CONSTRAINT_HOSTNAME: + INFO_MESSAGE("Hostname: %s", lease_def->constraint->data.hostname); + break; + + default: + FATAL_MESSAGE("illegal constraint type specified. this is a bug. report me."); + } + + } + + INFO_MESSAGE(" "); + INFO_MESSAGE("Lease options:"); + INFO_MESSAGE(" "); + + if(list_get_len(lease_def->options) == 0) { + + INFO_MESSAGE("No options specified."); + + } else { + + list_rewind(lease_def->options); + while((option = list_next(lease_def->options)) != NULL) { + + opt_name = dhcp_option_printable_string_get(dhcp_opt_get_tag(option)); + opt_val = dhcp_opt_get_user_string(option); + + INFO_MESSAGE("%s = %s", opt_name, opt_val); + xfree(opt_val); + + } + } + + INFO_MESSAGE(" "); + return; + } Index: dhcp-lease.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-lease.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-lease.h 12 Jul 2003 17:42:36 -0000 1.3 --- dhcp-lease.h 13 Jul 2003 04:53:30 -0000 1.4 *************** *** 93,95 **** --- 93,110 ---- extern void lease_definition_destroy(lease_definition_t *lease_def); + extern const char *lease_constraint_type_to_string(lease_constraint_t *constraint); + extern int lease_constraint_get_type(lease_constraint_t *constraint); + 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 const char *lease_constraint_get_hostname(lease_constraint_t *constraint); + extern eth_addr_t lease_constraint_get_hw_address(lease_constraint_t *constraint); + + extern const char *lease_type_to_string(lease_definition_t *lease); + extern int lease_definition_get_type(lease_definition_t *lease); + 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); + #endif /* DHCP_LEASE_H */ Index: dhcp-server.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-server.c 12 Jul 2003 17:44:10 -0000 1.6 --- dhcp-server.c 13 Jul 2003 04:53:30 -0000 1.7 *************** *** 47,53 **** static void do_kill(char *interface_name); static void do_server(char *interface_name); static const char *command_string[] = { ! "version", "kill", "status", "do server" }; --- 47,54 ---- static void do_kill(char *interface_name); static void do_server(char *interface_name); + static void do_check_config(char *interface_name); static const char *command_string[] = { ! "version", "kill", "status", "do server", "checkconfig" }; *************** *** 58,61 **** --- 59,63 ---- do_status, /* do status. */ do_server, /* do server. */ + do_check_config, /* check configuration. */ }; *************** *** 68,72 **** static void usage(char *s) { ! printf("usage: %s [-aks]\n", s); exit(0); } --- 70,74 ---- static void usage(char *s) { ! INFO_MESSAGE("usage: %s [-caks] [-l verbosity level]\n", s); exit(0); } *************** *** 114,117 **** --- 116,147 ---- } + static void do_check_config(char *interface) + { + server_conf_t *server_conf; + lease_definition_t *lease_def; + + server_conf = server_conf_create(interface); + if(server_conf == NULL) { + FATAL_MESSAGE("error while reading server conf."); + } + + /* dump out configuration information. */ + + INFO_MESSAGE("Server configuration:"); + INFO_MESSAGE(" "); + + INFO_MESSAGE("default-rebind-percent: %d", server_conf->default_rebind_percent); + INFO_MESSAGE("default-renew-percent: %d", server_conf->default_renew_percent); + INFO_MESSAGE(" "); + + INFO_MESSAGE("Lease definitions:"); + INFO_MESSAGE(" "); + + list_rewind(server_conf->lease_defs); + while((lease_def = list_next(server_conf->lease_defs)) != NULL) { + pretty_print_lease_def(lease_def); + } + } + /* main function: called from scm_boot_guile */ static void real_main(void *closure, int argc, char *argv[]) *************** *** 125,129 **** INFO_MESSAGE(" "); ! while((c = getopt(argc, argv, "vskai:l:")) != -1) { switch(c) { --- 155,159 ---- INFO_MESSAGE(" "); ! while((c = getopt(argc, argv, "cvskai:l:")) != -1) { switch(c) { *************** *** 135,138 **** --- 165,172 ---- case 's': command_code = DO_STATUS; + break; + + case 'c': + command_code = DO_CHECK_CONFIG; break; Index: dhcp-server.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-server.h 8 Jul 2003 07:03:33 -0000 1.3 --- dhcp-server.h 13 Jul 2003 04:53:30 -0000 1.4 *************** *** 40,44 **** /* constants. */ ! enum command_codes { DO_VERSION = 0, DO_KILL, DO_STATUS, DO_SERVER }; enum server_states { STATE_LISTEN, STATE_SHUTDOWN = 0 }; --- 40,44 ---- /* constants. */ ! enum command_codes { DO_VERSION = 0, DO_KILL, DO_STATUS, DO_SERVER, DO_CHECK_CONFIG }; enum server_states { STATE_LISTEN, STATE_SHUTDOWN = 0 }; |