dhcp-agent-commits Mailing List for dhcp-agent (Page 24)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv14122 Modified Files: Makefile.am dhcp-client-cache.c dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-com.c dhcp-conf.c dhcp-conf.h dhcp-convert.c dhcp-librawnet.h dhcp-libutil.h dhcp-limits.h dhcp-options-strings.c dhcp-options-strings.h dhcp-print.c dhcp-sysconf.c Removed Files: dhcp-globconf.c dhcp-globconf.h Log Message: initial import of new client configuration code Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile.am 15 Dec 2002 00:22:02 -0000 1.10 --- Makefile.am 16 Dec 2002 07:20:41 -0000 1.11 *************** *** 15,19 **** 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-convert.h dhcp-globconf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ dhcp-parser.h dhcp-sysconf.h dhcp-conf.h --- 15,19 ---- 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-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ dhcp-parser.h dhcp-sysconf.h dhcp-conf.h *************** *** 42,46 **** dhcp-icmp.c \ dhcp-route.c \ ! dhcp-interrupt.c dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 42,47 ---- dhcp-icmp.c \ dhcp-route.c \ ! dhcp-interrupt.c \ ! dhcp-conf.c dhcp_sniff_SOURCES = dhcp-sniff.c \ *************** *** 57,62 **** dhcp-options-strings.c \ dhcp-convert.c \ ! dhcp-sysconf.c \ ! dhcp-globconf.c dhcp_client_LDADD = -ldhcputil --- 58,62 ---- dhcp-options-strings.c \ dhcp-convert.c \ ! dhcp-sysconf.c dhcp_client_LDADD = -ldhcputil Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client-cache.c 24 Nov 2002 01:12:12 -0000 1.8 --- dhcp-client-cache.c 16 Dec 2002 07:20:41 -0000 1.9 *************** *** 249,253 **** if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_option_string_get(tag)); return NULL; } --- 249,253 ---- if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_option_printable_string_get(tag)); return NULL; } *************** *** 267,271 **** tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { ! ce = create_cache_entry(tag, dhcp_option_string_get(tag), string); return ce; } --- 267,271 ---- tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { ! ce = create_cache_entry(tag, dhcp_option_printable_string_get(tag), string); return ce; } *************** *** 278,282 **** cache_entry_t *ce; ! ce = create_cache_entry(tag, dhcp_option_string_get(tag), string); return ce; } --- 278,282 ---- cache_entry_t *ce; ! ce = create_cache_entry(tag, dhcp_option_printable_string_get(tag), string); return ce; } *************** *** 351,355 **** } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_option_string_get(opt->tag)); xfree(val); } --- 351,355 ---- } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_option_printable_string_get(opt->tag)); xfree(val); } Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-conf.c 24 Nov 2002 01:10:00 -0000 1.6 --- dhcp-client-conf.c 16 Dec 2002 07:20:41 -0000 1.7 *************** *** 32,35 **** --- 32,36 ---- #include "dhcp-librawnet.h" + #include "dhcp-conf.h" #include "dhcp-client-conf.h" #include "dhcp-cache-entry.h" *************** *** 37,74 **** #include "dhcp-options-strings.h" ! /* Basic network configuration. ! * Here we keep the options we want by default. */ static const int default_config_options[] = { ! TAG_DHCP_SUBNET_MASK, /* Subnet Mask */ ! TAG_DHCP_ROUTER, /* Routers. */ ! TAG_DHCP_INTERFACE_MTU, /* Interface MTU */ ! TAG_DHCP_DOMAIN_NAME_SERVER, /* Domain Name Servers. */ ! TAG_DHCP_DOMAIN_NAME, /* Domain Name. */ ! TAG_DHCP_REQUESTED_IP_ADDRESS, /* Requested IP Address. */ TAG_DHCP_IP_ADDRESS_LEASE_TIME, /* IP Address lease time. */ ! TAG_DHCP_RENEWAL_TIME, /* Renewal time. */ ! TAG_DHCP_REBINDING_TIME, /* Rebinding time. */ ! TAG_DHCP_SERVER_IDENTIFIER, /* Server Identifier. */ }; ! static void client_conf_reset_options(client_conf_t *cc) { ! memset(cc->options, 0, sizeof(cc->options)); } ! client_conf_t *create_client_conf(const char *interface) { ! client_conf_t *cc; ! cc = xmalloc(sizeof(client_conf_t)); ! client_conf_reset_options(cc); ! cc->interface = interface; ! return cc; } ! void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } --- 38,199 ---- #include "dhcp-options-strings.h" ! ! /* * * * * * * * * * * * * * * * * * * ! * configuration grammar structures. * ! * * * * * * * * * * * * * * * * * * */ ! ! /* string arrays for commands. */ ! ! /* variables the client will accept to be set. */ ! static const char *var_strings[] = { ! "hostname", ! "dhcp-retries", ! "icmp-retries", ! "do-icmp-router-discovery", ! }; ! ! /* symbol arrays. */ ! ! /* symbols for string substitution. */ ! static const arg_symbol_t var_symbols[] = { ! CLIENT_VAR_HOSTNAME, ! CLIENT_VAR_DHCP_RETRIES, ! CLIENT_VAR_ICMP_RETRIES, ! CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY, ! }; ! ! /* argument types, string array pointers, and symbol array pointers */ ! ! static const arg_type_t var_arg_types[] = { CONF_IDENTIFIER, CONF_ASSIGNMENT, CONF_STRING }; ! static const char **var_arg_strings[] = { var_strings, NULL, NULL }; ! static const arg_symbol_t *var_arg_symbols[] = { var_symbols, NULL, NULL }; ! ! static const arg_type_t request_arg_types[] = { CONF_STRING_LIST }; ! static const char **request_arg_strings[] = { NULL }; ! static const arg_symbol_t *request_arg_symbols[] = { NULL }; ! ! /* command structures. */ ! ! /* set command. */ ! static const command_t command_set = { ! DIRECTIVE_SET, ! "set", ! 3, ! var_arg_strings, ! var_arg_types, ! var_arg_symbols, ! }; ! ! /* request command. */ ! static const command_t command_request = { ! DIRECTIVE_REQUEST, ! "request", ! 1, ! request_arg_strings, ! request_arg_types, ! request_arg_symbols, ! }; ! ! static const command_t *commands[] = { ! &command_set, ! &command_request, ! NULL, ! }; ! ! /* Basic network configuration. Here we keep the options we want ! * by default. We always want these and will override the config ! * passed us by the user. */ ! static const int default_config_options[] = { ! TAG_DHCP_SUBNET_MASK, /* Subnet Mask */ ! TAG_DHCP_ROUTER, /* Routers. */ ! TAG_DHCP_INTERFACE_MTU, /* Interface MTU */ ! TAG_DHCP_REQUESTED_IP_ADDRESS, /* Requested IP Address. */ TAG_DHCP_IP_ADDRESS_LEASE_TIME, /* IP Address lease time. */ ! TAG_DHCP_RENEWAL_TIME, /* Renewal time. */ ! TAG_DHCP_REBINDING_TIME, /* Rebinding time. */ ! TAG_DHCP_SERVER_IDENTIFIER, /* Server Identifier. */ }; ! /* 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 . */ ! directive_handler_t directive_handlers[] = { ! directive_group_handler, ! directive_set_handler, ! directive_request_handler, ! }; ! ! /* * * * * * * ! * accessors * ! * * * * * * */ ! ! 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; ! } ! ! /* * * * * * * * * * * ! * utility routines * ! * * * * * * * * * * */ ! ! static int client_conf_set_variable(client_conf_t *cc, arg_symbol_t var_symbol, const char *var_value) ! { ! ! /* FIXME: insert sanity checks on data. */ ! switch(var_symbol) { ! ! case CLIENT_VAR_HOSTNAME: ! ! if(cc->client_hostname != NULL) { ! xfree(cc->client_hostname); ! cc->client_hostname = NULL; ! } ! ! cc->client_hostname = xstrdup(var_value); ! break; ! ! ! case CLIENT_VAR_DHCP_RETRIES: ! ! cc->dhcp_retries = atoi(var_value); ! break; ! ! case CLIENT_VAR_ICMP_RETRIES: ! ! cc->icmp_retries = atoi(var_value); ! break; ! ! default: ! return 1; ! } ! ! return 0; ! } ! ! /* reset requested options. */ ! static void client_conf_reset_options(client_conf_t *cc) ! { ! memset(cc->options, 0, sizeof(cc->options)); } *************** *** 77,81 **** char *fname; stringbuffer *sb = create_stringbuffer(); ! stringbuffer_aprintf(sb, "%s.%s", cc->interface, "opts"); fname = xstrdup(stringbuffer_getstring(sb)); --- 202,206 ---- char *fname; stringbuffer *sb = create_stringbuffer(); ! stringbuffer_aprintf(sb, "%s.%s", cc->interface, "conf"); fname = xstrdup(stringbuffer_getstring(sb)); *************** *** 85,223 **** } ! static int dump_config_options(client_conf_t *cc, char *fname) { ! int i; ! FILE *fp; ! ! fp = file_open_or_create_safe(fname, "a+"); ! if(fp == NULL) ! return -1; ! for(i = 0; i < NELMS(default_config_options); i++) { ! if(fprintf(fp, "\"%s\"\n", dhcp_option_string_get(i)) < 0) { ! WARN_MESSAGE("could not dump options to file. I'm going to continue anyway."); ! fclose(fp); ! return -1; ! } } - fclose(fp); return 0; } ! static void use_default_options(client_conf_t *cc) { ! int i; ! for(i = 0; i < NELMS(default_config_options); i++) { ! cc->options[default_config_options[i]] = 1; ! } ! return; ! } ! static int client_conf_load_options(client_conf_t *cc, char *fname) ! { ! varfile_t *varfile; ! int i; ! unsigned char match; ! int retval; ! varfile = create_varfile(fname, VARFILE_VARNAMES_MODE); ! if(varfile == NULL) { ! ERROR_MESSAGE("could not open varfile: %s", fname); ! return -1; } ! while(1) { ! retval = varfile_get_next_var(varfile); ! switch (retval) { ! case VARFILE_SUCCESS: ! match = 0; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! /* as long as no error was returned from file_parse_string ! * we can just do a file_get_var_name() safely. */ ! if(string_matches(dhcp_option_string_get(i), varfile_get_name(varfile))) { ! cc->options[i] = 1; ! match = 1; ! break; ! } ! } ! if(match != 1) ! WARN_MESSAGE("encountered illegal DHCP option in %s: %s : %d", fname, ! varfile_get_name(varfile), varfile_get_lineno(varfile)); ! break; ! case VARFILE_EOF: ! destroy_varfile(varfile); ! return 0; ! case VARFILE_PARSE_ERROR: ! ERROR_MESSAGE("parse error in opts file: %s : %d", ! varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return -1; ! default: ! FATAL_MESSAGE("client-conf: load_options: internal error -- please report this."); ! } ! } ! } ! /* load configuration file or call applicable default setter, ! also call dump_defaults if file does not exist */ ! static int load_client_conf_proc(char *fname, ! client_conf_t *cc, int (*load_conf) (client_conf_t *cc, ! char *fname), ! void (*use_defaults) (client_conf_t *cc), ! int (*dump_defaults) (client_conf_t *cc, char *fname)) ! { ! int retval; ! if(!file_exists(fname)) { ! /* it doesn't exist. strap default. */ ! use_defaults(cc); ! /* and dump to file. */ ! retval = dump_config_options(cc, fname); ! } else { ! /* read conf data from file. */ ! retval = load_conf(cc, fname); } ! return retval; } ! int load_client_conf(client_conf_t *cc) ! { ! ! char *fname; ! int retval; ! /* load up options file. */ client_conf_reset_options(cc); - /* check for options file. */ - fname = get_conf_options_fname(cc); - retval = load_client_conf_proc(fname, cc, client_conf_load_options, - use_default_options, dump_config_options); - xfree(fname); ! return (retval); } ! /* return the bit array indexing the options we want. */ ! uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) { ! return cc->options; } --- 210,337 ---- } ! 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) { ! char *fname; ! conf_t *conf; ! list_t *directives; ! fname = get_conf_options_fname(cc); ! conf = conf_create(commands, fname); ! if(conf_compile_directives(conf) == CONF_ERROR) { ! conf_destroy(conf); ! return 1; ! } ! directives = conf_get_directives(conf); ! /* read compiled directives. */ ! ! if(client_conf_apply_directives(cc, conf->directives)) { ! conf_destroy(conf); ! return 1; } ! return 0; ! } ! /* * * * * * * * * * * * ! * directive handlers. * ! * * * * * * * * * * * */ ! 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; ! char *var_value; ! args = directive->arguments; ! var_symbol = args->data; ! var_value = args->next->next->data; ! if(client_conf_set_variable(cc, *var_symbol, var_value)) { ! return 1; ! } ! return 0; ! } ! 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; } ! /* * * * * * * * * * * * * * * ! * constructors/destructors * ! * * * * * * * * * * * * * * */ ! client_conf_t *create_client_conf(const char *interface) ! { ! client_conf_t *cc; + cc = xmalloc(sizeof(client_conf_t)); + cc->interface = interface; client_conf_reset_options(cc); ! if(client_conf_load_options(cc)) { ! client_conf_destroy(cc); ! return NULL; ! } ! ! return cc; } ! void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-conf.h 19 Nov 2002 19:44:44 -0000 1.3 --- dhcp-client-conf.h 16 Dec 2002 07:20:41 -0000 1.4 *************** *** 26,29 **** --- 26,33 ---- #define DHCP_CLIENT_CONF_H + /* typdefs. */ + + typedef uint8_t directive_group_t; + /* data structures. */ *************** *** 35,44 **** unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ } client_conf_t; extern client_conf_t *create_client_conf(const char *interface); extern void client_conf_destroy(client_conf_t *cc); ! extern int load_client_conf(client_conf_t *cc); extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ --- 39,70 ---- 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. */ + enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, + CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY }; + + enum directive_group_t { GROUP_DIRECTIVE_NULL = 0, DIRECTIVE_GROUP_IP_ADDRESS, DIRECTIVE_GROUP_ETH_ADDRESS }; + + /* prototypes. */ extern client_conf_t *create_client_conf(const char *interface); extern void client_conf_destroy(client_conf_t *cc); ! extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); + extern int client_conf_get_dhcp_retries(client_conf_t *cc); + extern int client_conf_get_icmp_retries(client_conf_t *cc); + extern const char *client_conf_get_hostname(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-control.c 19 Nov 2002 19:44:44 -0000 1.5 --- dhcp-client-control.c 16 Dec 2002 07:20:41 -0000 1.6 *************** *** 34,38 **** #include "dhcp-client.h" #include "dhcp-client-conf.h" - #include "dhcp-globconf.h" /* Utility routines to update counters and time stamps. */ --- 34,37 ---- *************** *** 61,68 **** int dhcp_client_discover_offer_can_retry(dhcp_client_control_t *dc) { ! uint32_t *discover_offer_retries = glob_conf_get_val(CLIENT_DHCP_RETRIES); dc->discover_offer_retries++; ! if(dc->discover_offer_retries > *(discover_offer_retries)) return 1; --- 60,67 ---- int dhcp_client_discover_offer_can_retry(dhcp_client_control_t *dc) { ! uint32_t discover_offer_retries = client_conf_get_dhcp_retries(dc->conf); dc->discover_offer_retries++; ! if(dc->discover_offer_retries > discover_offer_retries); return 1; *************** *** 139,147 **** dc->state = 0; dc->interface = xstrdup(interface); - dc->conf = create_client_conf(dc->interface); dc->cache = client_cache_create(dc->interface); dc->timer = create_timer(); ! if(load_client_conf(dc->conf) < 0) { ERROR_MESSAGE("could not read client conf."); destroy_dhcp_client_control(dc); --- 138,146 ---- dc->state = 0; dc->interface = xstrdup(interface); dc->cache = client_cache_create(dc->interface); dc->timer = create_timer(); ! dc->conf = create_client_conf(dc->interface); ! if(dc->conf == NULL) { ERROR_MESSAGE("could not read client conf."); destroy_dhcp_client_control(dc); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-states.c 24 Nov 2002 01:12:12 -0000 1.7 --- dhcp-client-states.c 16 Dec 2002 07:20:41 -0000 1.8 *************** *** 37,41 **** #include "dhcp-client-cache.h" #include "dhcp-client.h" - #include "dhcp-globconf.h" #include "dhcp-sysconf.h" --- 37,40 ---- *************** *** 67,71 **** list_t *options = NULL; dhcp_option_t *option; ! char *hostname; /* dhcp max DHCP message size: --- 66,70 ---- list_t *options = NULL; dhcp_option_t *option; ! const char *hostname; /* dhcp max DHCP message size: *************** *** 83,87 **** /* hostname if available */ ! hostname = glob_conf_get_val(CLIENT_HOSTNAME); if(hostname != NULL) { /* if we have one set it. */ --- 82,86 ---- /* hostname if available */ ! hostname = client_conf_get_hostname(dc->conf); if(hostname != NULL) { /* if we have one set it. */ *************** *** 163,167 **** static int client_check_requested_options(dhcp_client_control_t *dc) { ! const char *policy = glob_conf_get_val(CLIENT_OPTION_POLICY); return 1; --- 162,167 ---- static int client_check_requested_options(dhcp_client_control_t *dc) { ! /* FIXME: we default to at least. we need an actual policy in client_conf though. */ ! const char *policy = NULL; return 1; Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client.c 15 Dec 2002 00:22:02 -0000 1.8 --- dhcp-client.c 16 Dec 2002 07:20:42 -0000 1.9 *************** *** 34,38 **** #include "dhcp-client-cache.h" #include "dhcp-client.h" - #include "dhcp-globconf.h" #include "dhcp-daemon.h" --- 34,37 ---- *************** *** 105,125 **** /* Utility routines. */ - /* read up on our global conf. */ - static void read_global_conf(const char *interface) - { - stringbuffer *sb; - - sb = create_stringbuffer(); - stringbuffer_aprintf(sb, "%s.%s", interface, "conf"); - - if(init_glob_conf(stringbuffer_getstring(sb))) { - FATAL_MESSAGE("could not read nor create global configuration file: %s", - stringbuffer_getstring(sb)); - } - - destroy_stringbuffer(sb); - return; - } - /* initialize state per contents of cache. */ static int initialize_client_state(dhcp_client_control_t *dc) --- 104,107 ---- *************** *** 151,155 **** pid_t pid; ! if(!get_pid_file(interface, &pid)) return 0; /* no pid file -- therefore no process. */ --- 133,137 ---- pid_t pid; ! if(get_pid_file(interface, &pid)) return 0; /* no pid file -- therefore no process. */ *************** *** 388,394 **** INFO_MESSAGE("starting for interface %s", interface); - /* We need to read our global configuration right after we change to work directory. */ - read_global_conf(interface); - /* Now see if another client is running on the same interface. */ --- 370,373 ---- *************** *** 535,539 **** /* dhcp options which can be set on the command line. */ case 'H': ! glob_conf_set_val(optarg, CLIENT_HOSTNAME); break; --- 514,520 ---- /* dhcp options which can be set on the command line. */ case 'H': ! /* glob_conf_set_val(optarg, CLIENT_HOSTNAME); */ ! /* heh no more globconf -- FIXME: set this in client_conf later. */ ! break; Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-com.c 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-com.c 16 Dec 2002 07:20:42 -0000 1.5 *************** *** 394,398 **** int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len) { ! if(tag_len < 1 || tag >= MAX_OPTIONS_HANDLED) return 0; else --- 394,398 ---- int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len) { ! if(tag_len < 1 || tag > MAX_OPTIONS_HANDLED) return 0; else *************** *** 464,468 **** int i; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(options[i] && !dhcp_have_option(dhcp, i)) return 1; --- 464,468 ---- int i; ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(options[i] && !dhcp_have_option(dhcp, i)) return 1; *************** *** 476,480 **** int i; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(options[i] && !dhcp_have_option(dhcp, i)) return 1; --- 476,480 ---- int i; ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(options[i] && !dhcp_have_option(dhcp, i)) return 1; *************** *** 521,525 **** /* Grab length so we can just malloc all at once. */ ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) len++; --- 521,525 ---- /* Grab length so we can just malloc all at once. */ ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) len++; *************** *** 537,541 **** j = 0; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { option->data[j] = i; --- 537,541 ---- j = 0; ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { option->data[j] = i; *************** *** 581,585 **** } ! dhcp_option_t *dhcp_build_hostname(char *hostname) { return (create_dhcp_option --- 581,585 ---- } ! dhcp_option_t *dhcp_build_hostname(const char *hostname) { return (create_dhcp_option Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-conf.c 15 Dec 2002 05:15:44 -0000 1.2 --- dhcp-conf.c 16 Dec 2002 07:20:42 -0000 1.3 *************** *** 144,148 **** } ! conf_t *conf_create(command_t **commands, const char *filename) { conf_t *conf; --- 144,148 ---- } ! conf_t *conf_create(const command_t **commands, const char *filename) { conf_t *conf; *************** *** 351,355 **** /* compile the command. follow the command argument types and store them. */ ! static directive_t *compile_command(conf_t *conf, command_t *command) { directive_t *directive; --- 351,355 ---- /* compile the command. follow the command argument types and store them. */ ! static directive_t *compile_command(conf_t *conf, const command_t *command) { directive_t *directive; *************** *** 395,399 **** const char *token_string; directive_t *directive; ! command_t *command; int i; --- 395,399 ---- const char *token_string; directive_t *directive; ! const command_t *command; int i; Index: dhcp-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-conf.h 15 Dec 2002 05:15:44 -0000 1.2 --- dhcp-conf.h 16 Dec 2002 07:20:42 -0000 1.3 *************** *** 26,64 **** #define DHCP_CONF_H - /* native types. */ - - typedef uint32_t command_code_t; - typedef uint32_t arg_len_t; - typedef uint32_t arg_type_t; - typedef uint32_t arg_symbol_t; - - /* compiled directive. */ - typedef struct { - command_code_t command_code; /* the command code. */ - list_t *argument_types; /* type of argument: need this to free up arguments later. */ - list_t *arguments; /* argument data. */ - } directive_t; - - /* command syntax object. */ - typedef struct { - - const command_code_t command_code; - const char *command_name; - - const arg_len_t argument_len; - const char ***argument_strings; - const arg_type_t *argument_types; - const arg_symbol_t **argument_symbols; - - } command_t; - - /* conf object. */ - typedef struct { - char *filename; - parser_t *parser; - command_t **commands; /* list of permissible commands. */ - list_t *directives; - } conf_t; - /* typedef of configuration drivers. */ typedef void *(*argument_compiler_t)(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); --- 26,29 ---- *************** *** 72,83 **** CONF_ASSIGNMENT, CONF_BOOLEAN, CONF_STRING, CONF_STRING_LIST, CONF_GROUP }; - - /* prototypes. */ - - extern conf_t *conf_create(command_t **commands, const char *filename); - extern void conf_destroy(conf_t *conf); - - extern int conf_compile_directives(conf_t *conf); - extern list_t *conf_get_directives(conf_t *conf); - #endif /* DHCP_CONF_H */ --- 37,39 ---- Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-convert.c 24 Nov 2002 01:10:00 -0000 1.4 --- dhcp-convert.c 16 Dec 2002 07:20:42 -0000 1.5 *************** *** 237,243 **** , /* 59 *//* Rebinding time. */ {NULL, NULL, NULL, NULL} ! , /* 60 *//* Server identifier */ {NULL, NULL, NULL, NULL} ! , /* 61 *//* Client identifier */ }; --- 237,269 ---- , /* 59 *//* Rebinding time. */ {NULL, NULL, NULL, NULL} ! , /* 60 *//* Class ID */ {NULL, NULL, NULL, NULL} ! , /* 61 *//* Client ID */ ! {NULL, NULL, NULL, NULL} ! , /* 62 NIS+ Domain */ ! {NULL, NULL, NULL, NULL} ! , /* 63 NIS+ Servers */ ! {NULL, NULL, NULL, NULL} ! , /* 64 TFTP Servers */ ! {NULL, NULL, NULL, NULL} ! , /* 65 Boot File Name */ ! {NULL, NULL, NULL, NULL} ! , /* 66 IP Home Agent */ ! {NULL, NULL, NULL, NULL} ! , /* 67 SMTP Server */ ! {NULL, NULL, NULL, NULL} ! , /* 69 POP Server */ ! {NULL, NULL, NULL, NULL} ! , /* 69 NNTP Server */ ! {NULL, NULL, NULL, NULL} ! , /* 70 Default WWW Server */ ! {NULL, NULL, NULL, NULL} ! , /* 71 Default Finger Server */ ! {NULL, NULL, NULL, NULL} ! , /* 72 Default IRC Server */ ! {NULL, NULL, NULL, NULL} ! , /* 73 Default ST Server */ ! {NULL, NULL, NULL, NULL} ! , /* 74 Default STDA Server */ }; Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-librawnet.h 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-librawnet.h 16 Dec 2002 07:20:42 -0000 1.5 *************** *** 442,446 **** extern dhcp_option_t *dhcp_build_requested_ip_address(uint32_t address); extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); ! extern dhcp_option_t *dhcp_build_hostname(char *hostname); --- 442,446 ---- extern dhcp_option_t *dhcp_build_requested_ip_address(uint32_t address); extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); ! extern dhcp_option_t *dhcp_build_hostname(const char *hostname); Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-libutil.h 15 Dec 2002 00:22:02 -0000 1.10 --- dhcp-libutil.h 16 Dec 2002 07:20:42 -0000 1.11 *************** *** 29,32 **** --- 29,39 ---- #define DHCP_LIBUTIL_H + /* types. */ + + typedef uint32_t command_code_t; + typedef uint32_t arg_len_t; + typedef uint32_t arg_type_t; + typedef uint8_t arg_symbol_t; + /* * * * * * * * * * * * Data structures. * *************** *** 86,89 **** --- 93,124 ---- } varfile_t; + /* compiled directive. */ + typedef struct { + command_code_t command_code; /* the command code. */ + list_t *argument_types; /* type of argument: need this to free up arguments later. */ + list_t *arguments; /* argument data. */ + } directive_t; + + /* command syntax object. */ + typedef struct { + + const command_code_t command_code; + const char *command_name; + + const arg_len_t argument_len; + const char ***argument_strings; + const arg_type_t *argument_types; + const arg_symbol_t **argument_symbols; + + } command_t; + + /* conf object. */ + typedef struct { + char *filename; + parser_t *parser; + const command_t **commands; /* list of permissible commands. */ + list_t *directives; + } conf_t; + /* prototypes. */ *************** *** 228,231 **** --- 263,272 ---- extern RETSIGTYPE handle_shutdown(int i); extern int got_interrupt_type(void); + + /* configuration grammar parser */ + extern conf_t *conf_create(const command_t **commands, const char *filename); + extern void conf_destroy(conf_t *conf); + extern int conf_compile_directives(conf_t *conf); + extern list_t *conf_get_directives(conf_t *conf); /* constants. */ Index: dhcp-limits.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-limits.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-limits.h 16 Nov 2002 00:23:43 -0000 1.2 --- dhcp-limits.h 16 Dec 2002 07:20:42 -0000 1.3 *************** *** 50,55 **** /* max options handled. */ ! #define MAX_OPTIONS_HANDLED 62 ! #endif /* DHCP_LIMITS_H */ --- 50,54 ---- /* max options handled. */ ! #define MAX_OPTIONS_HANDLED 74 /* including 0 for PAD which we never care about. */ #endif /* DHCP_LIMITS_H */ Index: dhcp-options-strings.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-options-strings.c 22 Nov 2002 15:30:38 -0000 1.4 --- dhcp-options-strings.c 16 Dec 2002 07:20:42 -0000 1.5 *************** *** 27,31 **** #define MODULE_NAME "dhcp-option-strings" ! static char *dhcp_options_strings[] = { "Pad", /* 0 */ "Subnet Mask", /* 1 */ --- 27,32 ---- #define MODULE_NAME "dhcp-option-strings" ! /* these we use to print out with. */ ! static const char *dhcp_options_printable_strings[] = { "Pad", /* 0 */ "Subnet Mask", /* 1 */ *************** *** 85,97 **** "Parameter Request List", /* 55 */ "Message", /* 56 */ ! "Max DHP Message Size", /* 57 */ "Renewal Time", /* 58 */ "Rebinding Time", /* 59 */ "Class ID", /* 60 */ "Client ID", /* 61 */ }; ! const char *dhcp_option_string_get(int index) { ! return dhcp_options_strings[index]; } --- 86,203 ---- "Parameter Request List", /* 55 */ "Message", /* 56 */ ! "Max DHCP Message Size", /* 57 */ "Renewal Time", /* 58 */ "Rebinding Time", /* 59 */ "Class ID", /* 60 */ "Client ID", /* 61 */ + "NIS+ Domain" , /* 62 */ + "NIS+ Servers", /* 63 */ + "TFTP Servers", /* 64 */ + "Boot File Name", /* 65 */ + "IP Home Agent", /* 66 */ + "SMTP Server", /* 67 */ + "POP Server", /* 68 */ + "NNTP Server", /* 69 */ + "Default WWW Server", /* 70 */ + "Default Finger Server", /* 71 */ + "Default IRC Server", /* 72 */ + "Default ST Server", /* 73 */ + "Default STDA Server" /* 74 */ }; ! /* these we use for configuration: lowercase with hyphen. */ ! static const char *dhcp_options_conf_strings[] = { ! "pad", /* 0 */ ! "subnet-mask", /* 1 */ ! "time-offset", /* 2 */ ! "routers", /* 3 */ ! "time-servers", /* 4 */ ! "name-servers", /* 5 */ ! "domain-name-servers", /* 6 */ ! "log-servers", /* 7 */ ! "cookie-servers", /* 8 */ ! "lpr-servers", /* 9 */ ! "impress-servers", /* 10 */ ! "rl-servers", /* 11 */ ! "hostname", /* 12 */ ! "boot-file-size", /* 13 */ ! "merit-dump-file", /* 14 */ ! "domain-name", /* 15 */ ! "swap-server", /* 16 */ ! "root-path", /* 17 */ ! "extensions-path", /* 18 */ ! "ip-forwarding", /* 19 */ ! "source-routing", /* 20 */ ! "policy-filter", /* 21 */ ! "maximum-dgram-reassmbly", /* 22 */ ! "default-ip-time-to-live", /* 23 */ ! "path-mtu-aging-timeout", /* 24 */ ! "path-mtu-plateau-table", /* 25 */ ! "interface-mtu", /* 26 */ ! "all-subnets", /* 27 */ ! "broadcast-address", /* 28 */ ! "perform-mask-discovery", /* 29 */ ! "mask-supplier", /* 30 */ ! "perform-router-discovery", /* 31 */ ! "router-solicitation-address", /* 32 */ ! "static-route", /* 33 */ ! "trailer-encapsulation", /* 34 */ ! "arp-cache-timeout", /* 35 */ ! "ethernet-encapsulation", /* 36 */ ! "tcp-default-ttl", /* 37 */ ! "tcp-keepalive-interval", /* 38 */ ! "tcp-keepalive-garbage", /* 39 */ ! "network-information-service-domain", /* 40 */ ! "network-information-servers", /* 41 */ ! "network-time-protocol-servers", /* 42 */ ! "vendor-specific-information", /* 43 */ ! "netbios-over-tcp-name servers", /* 44 */ ! "netbios-over-tcp-datagram-distribution-servers", /* 45 */ ! "netbios-over-tcp-node-type", /* 46 */ ! "netbios-over-tcp-scope", /* 47 */ ! "x-windows-font-servers", /* 48 */ ! "x-windows-system-display-manager", /* 49 */ ! "request-ip-address", /* 50 */ ! "ip-address-lease-time", /* 51 */ ! "option-overload", /* 52 */ ! "dhcp-message-type", /* 53 */ ! "server-identifier", /* 54 */ ! "parameter-request-list", /* 55 */ ! "message", /* 56 */ ! "max-dhcp-message-size", /* 57 */ ! "renewal-time", /* 58 */ ! "rebinding-time", /* 59 */ ! "class-id", /* 60 */ ! "client-id", /* 61 */ ! "nisplus-domain", /* 62 */ ! "nisplus-servers", /* 63 */ ! "tftp-server", /* 64 */ ! "boot-file-name", /* 65 */ ! "ip-home-agent", /* 66 */ ! "smtp-server", /* 67 */ ! "pop-server", /* 68 */ ! "nntp-server", /* 69 */ ! "default-www-server", /* 70 */ ! "default-finger-server", /* 71 */ ! "default-irc-server", /* 72 */ ! "default-st-server", /* 73 */ ! "default-stda-server" /* 74 */ ! }; ! ! /* accessors. */ ! ! const char *dhcp_option_printable_string_get(int index) { ! return dhcp_options_printable_strings[index]; ! } ! ! const char *dhcp_option_conf_string_get(int index) ! { ! return dhcp_options_conf_strings[index]; ! } ! ! /* retrieve entire array for configuration strings. */ ! const char **dhcp_option_conf_string_get_array(void) ! { ! return dhcp_options_conf_strings; } Index: dhcp-options-strings.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-options-strings.h 22 Nov 2002 15:30:38 -0000 1.3 --- dhcp-options-strings.h 16 Dec 2002 07:20:42 -0000 1.4 *************** *** 26,30 **** #define DHCP_OPTION_STRINGS_H ! extern const char *dhcp_option_string_get(int index); #endif /* DHCP_OPTION_STRINGS_H */ --- 26,32 ---- #define DHCP_OPTION_STRINGS_H ! extern const char *dhcp_option_printable_string_get(int index); ! extern const char *dhcp_option_conf_string_get(int index); ! extern const char **dhcp_option_conf_string_get_array(void); #endif /* DHCP_OPTION_STRINGS_H */ Index: dhcp-print.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-print.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-print.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-print.c 16 Dec 2002 07:20:42 -0000 1.4 *************** *** 279,283 **** for(i = 0; i < len; i++) { ! if(data[i] >= MAX_OPTIONS_HANDLED) continue; --- 279,283 ---- for(i = 0; i < len; i++) { ! if(data[i] > MAX_OPTIONS_HANDLED) continue; Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-sysconf.c 24 Nov 2002 01:12:12 -0000 1.8 --- dhcp-sysconf.c 16 Dec 2002 07:20:42 -0000 1.9 *************** *** 39,43 **** #include "dhcp-convert.h" #include "dhcp-sysconf.h" - #include "dhcp-globconf.h" #include "dhcp-options-strings.h" --- 39,42 ---- *************** *** 183,189 **** , /* 59 Rebind Time (T2). */ {NULL, NULL, SYSCONF_UNSET,} ! , /* 60 */ {NULL, NULL, SYSCONF_UNSET,} ! , /* 61 */ }; --- 182,214 ---- , /* 59 Rebind Time (T2). */ {NULL, NULL, SYSCONF_UNSET,} ! , /* 60 Class ID */ {NULL, NULL, SYSCONF_UNSET,} ! , /* 61 Client ID */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 62 NIS+ Domain */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 63 NIS+ Servers */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 64 TFTP Servers */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 65 Boot File Name */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 66 IP Home Agent */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 67 SMTP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 69 POP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 69 NNTP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 70 Default WWW Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 71 Default Finger Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 72 Default IRC Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 73 Default ST Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 74 Default STDA Server */ }; *************** *** 225,237 **** int lowest_latency; int *latency; ! int *sends; memset(&r_entry.route_dst, 0, sizeof(r_entry.route_dst)); memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); ! sends = glob_conf_get_val(CLIENT_ICMP_RETRIES); routers = value; ! average_latencies = icmp_rtt_discovery(dc->rawnet, routers, *sends); /* Even if all routers fail to respond to the ICMP echo query, --- 250,262 ---- int lowest_latency; int *latency; ! int sends; memset(&r_entry.route_dst, 0, sizeof(r_entry.route_dst)); memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); ! sends = client_conf_get_icmp_retries(dc->conf); routers = value; ! average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends); /* Even if all routers fail to respond to the ICMP echo query, *************** *** 364,368 **** ce = list_ptr->data; ! if(string_matches(dhcp_option_string_get(TAG_DHCP_REQUESTED_IP_ADDRESS), ce->name)) { data = --- 389,393 ---- ce = list_ptr->data; ! if(TAG_DHCP_REQUESTED_IP_ADDRESS == ce->tag) { data = *************** *** 376,380 **** } ! if(string_matches(dhcp_option_string_get(TAG_DHCP_SUBNET_MASK), ce->name)) { data = option_convert_handlers[TAG_DHCP_SUBNET_MASK].serialize_to_internal(ce->value); --- 401,405 ---- } ! if(TAG_DHCP_SUBNET_MASK == ce->tag) { data = option_convert_handlers[TAG_DHCP_SUBNET_MASK].serialize_to_internal(ce->value); *************** *** 386,390 **** } ! if(string_matches(dhcp_option_string_get(TAG_DHCP_INTERFACE_MTU), ce->name)) { data = option_convert_handlers[TAG_DHCP_INTERFACE_MTU].serialize_to_internal(ce->value); --- 411,415 ---- } ! if(TAG_DHCP_INTERFACE_MTU == ce->tag) { data = option_convert_handlers[TAG_DHCP_INTERFACE_MTU].serialize_to_internal(ce->value); *************** *** 449,457 **** (sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_option_string_get(ce->tag)); if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_string_get(ce->tag)); } --- 474,482 ---- (sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(ce->tag)); if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_conf_string_get(ce->tag)); } *************** *** 459,468 **** * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_option_string_get(ce->tag)); if(sysconf_handlers[ce->tag].setup(data, dc)) { sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_option_string_get(ce->tag)); } else { --- 484,493 ---- * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_option_printable_string_get(ce->tag)); if(sysconf_handlers[ce->tag].setup(data, dc)) { sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_option_printable_string_get(ce->tag)); } else { *************** *** 508,516 **** data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); ! INFO_MESSAGE("cleanup option: %s", dhcp_option_string_get(ce->tag)); if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_string_get(ce->tag)); option_convert_handlers[ce->tag].free_internal(data); --- 533,541 ---- data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(ce->tag)); if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_printable_string_get(ce->tag)); option_convert_handlers[ce->tag].free_internal(data); --- dhcp-globconf.c DELETED --- --- dhcp-globconf.h DELETED --- |
From: <act...@us...> - 2002-12-15 05:15:47
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv29093 Modified Files: dhcp-conf.c dhcp-conf.h Log Message: added destruction routines Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-conf.c 15 Dec 2002 00:22:02 -0000 1.1 --- dhcp-conf.c 15 Dec 2002 05:15:44 -0000 1.2 *************** *** 48,51 **** --- 48,57 ---- static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); + /* forward declaration of argument destroyers */ + + /* we only need these two. */ + static void destroy_arg_string_list(void *data); + static void destroy_arg_group(void *data); + /* argument_compiler_dispatch table -- these are indexed by the types in dhcp-conf.h */ *************** *** 60,92 **** }; /* * * * * * * * * * * * * * * * constructors/destructors * * * * * * * * * * * * * * * */ - conf_t *conf_create(command_t **commands, const char *filename) - { - conf_t *conf; - - conf = xmalloc(sizeof(conf_t)); - conf->parser = create_parser(filename); - - if(conf->parser == NULL) { - ERROR_MESSAGE("could not open configuration file: %s", filename); - xfree(conf); - return NULL; - } - - conf->filename = xstrdup(filename); - conf->commands = commands; - conf->directives = NULL; - - return conf; - } - - void conf_destroy(conf_t *conf) - { - return; /* TODO: write cleanup code. */ - } - static directive_t *directive_create(void) { --- 66,85 ---- }; + /* argument destroyer dispatch table -- these are indexed by the types in dhcp-conf.h */ + + argument_destroy_t argument_destroyers[] = { + xfree, + xfree, + xfree, + xfree, + xfree, + destroy_arg_string_list, + destroy_arg_group, + }; + /* * * * * * * * * * * * * * * * constructors/destructors * * * * * * * * * * * * * * * */ static directive_t *directive_create(void) { *************** *** 113,117 **** static void directive_destroy(directive_t *directive) { ! arg_type_destroy(NULL); return; } --- 106,139 ---- static void directive_destroy(directive_t *directive) { ! list_t *type_ptr, *arg_ptr; ! list_t *tmp; ! arg_type_t arg_type; ! ! arg_ptr = directive->arguments; ! type_ptr = directive->argument_types; ! ! /* iterate through the list of arguments. ! * and call the destroy routine per argument. */ ! ! while(type_ptr) { ! ! /* FIXME: one of the limitations of the list code we're ! * using is that we cannot perform single purges. fix ! * later. just do raw list code here. */ ! ! arg_type = *(arg_type_t *)type_ptr->data; ! ! argument_destroyers[arg_type](arg_ptr->data); ! arg_type_destroy((arg_type_t *)type_ptr->data); ! ! tmp = type_ptr->next; ! xfree(type_ptr); ! type_ptr = tmp; ! ! tmp = arg_ptr->next; ! xfree(arg_ptr); ! arg_ptr = tmp; ! } ! return; } *************** *** 122,125 **** --- 144,177 ---- } + conf_t *conf_create(command_t **commands, const char *filename) + { + conf_t *conf; + + conf = xmalloc(sizeof(conf_t)); + conf->parser = create_parser(filename); + + if(conf->parser == NULL) { + ERROR_MESSAGE("could not open configuration file: %s", filename); + xfree(conf); + return NULL; + } + + conf->filename = xstrdup(filename); + conf->commands = commands; + conf->directives = NULL; + + return conf; + } + + void conf_destroy(conf_t *conf) + { + xfree(conf->filename); + destroy_parser(conf->parser); + purge_list(conf->directives, directive_destroy_l); + xfree(conf); + + return; + } + /* * * * * * * * * * * * * argument compilers * *************** *** 249,253 **** atom_t atom; - atom = get_next_atom_ignore_newlines(conf->parser); --- 301,304 ---- *************** *** 414,417 **** --- 465,491 ---- purge_list(directive_list, directive_destroy_l); return NULL; + } + + /* * * * * * * * * * * * * * * * * + * argument destruction routines * + * * * * * * * * * * * * * * * * */ + + /* most are just freed with xfree. these two are special because + * they contain lists. */ + + static void destroy_arg_string_list(void *data) + { + list_t *list = data; + + purge_list(list, NULL); /* just free up a list of strings. */ + } + + static void destroy_arg_group(void *data) + { + list_t *list = data; + + purge_list(list, directive_destroy_l); + + return; } Index: dhcp-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-conf.h 15 Dec 2002 00:22:02 -0000 1.1 --- dhcp-conf.h 15 Dec 2002 05:15:44 -0000 1.2 *************** *** 63,66 **** --- 63,67 ---- /* typedef of configuration drivers. */ typedef void *(*argument_compiler_t)(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); + typedef void (*argument_destroy_t)(void *); /* conf return types. */ |
From: <act...@us...> - 2002-12-15 04:59:26
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv14870 Modified Files: dhcp-stringbuffer.c Log Message: blah: misnamed var Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-stringbuffer.c 15 Dec 2002 04:37:02 -0000 1.5 --- dhcp-stringbuffer.c 15 Dec 2002 04:59:23 -0000 1.6 *************** *** 65,69 **** new_string = allocate_string(len); ! memcpy(newstring, begin, len); new_string[len] = 0; --- 65,69 ---- new_string = allocate_string(len); ! memcpy(new_string, begin, len); new_string[len] = 0; |
From: <act...@us...> - 2002-12-15 04:37:05
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv25172 Modified Files: dhcp-stringbuffer.c Log Message: memcpy instead of strncat Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-stringbuffer.c 16 Nov 2002 00:23:44 -0000 1.4 --- dhcp-stringbuffer.c 15 Dec 2002 04:37:02 -0000 1.5 *************** *** 65,69 **** new_string = allocate_string(len); ! strncpy(new_string, begin, len); new_string[len] = 0; --- 65,69 ---- new_string = allocate_string(len); ! memcpy(newstring, begin, len); new_string[len] = 0; |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv28336/src Modified Files: Makefile.am dhcp-client.c dhcp-libutil.h dhcp-parser.c dhcp-parser.h dhcp-util.c Added Files: dhcp-conf.c dhcp-conf.h Log Message: new recursive configuration parser --- NEW FILE: dhcp-conf.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v 1.1 2002/12/15 00:22:02 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Configuration file parser. * * Our parsing is more complicated than what the varfile does. * Here we accept an array of structures which tell us what to * expect. We build directive lists from these structures and * pass them up. * */ #define MODULE_NAME "dhcp-conf.c" #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-parser.h" #include "dhcp-conf.h" /* forward declaration of argument drivers. */ 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); static void *compile_arg_string(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_string_list(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); /* argument_compiler_dispatch table -- these are indexed by the types in dhcp-conf.h */ argument_compiler_t argument_compilers[] = { compile_arg_identifier, compile_arg_address, compile_arg_assignment, compile_arg_boolean, compile_arg_string, compile_arg_string_list, compile_arg_group, }; /* * * * * * * * * * * * * * * * constructors/destructors * * * * * * * * * * * * * * * */ conf_t *conf_create(command_t **commands, const char *filename) { conf_t *conf; conf = xmalloc(sizeof(conf_t)); conf->parser = create_parser(filename); if(conf->parser == NULL) { ERROR_MESSAGE("could not open configuration file: %s", filename); xfree(conf); return NULL; } conf->filename = xstrdup(filename); conf->commands = commands; conf->directives = NULL; return conf; } void conf_destroy(conf_t *conf) { return; /* TODO: write cleanup code. */ } static directive_t *directive_create(void) { directive_t *directive; directive = xcalloc(sizeof(directive_t)); return directive; } static arg_type_t *arg_type_create(arg_type_t arg) { arg_type_t *arg_type = xmalloc(sizeof(arg_type_t)); *arg_type = arg; return arg_type; } static void arg_type_destroy(arg_type_t *arg) { xfree(arg); return; } static void directive_destroy(directive_t *directive) { arg_type_destroy(NULL); return; } static void directive_destroy_l(void *p) { directive_destroy(p); } /* * * * * * * * * * * * * argument compilers * * * * * * * * * * * * */ static void *compile_arg_identifier(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { arg_symbol_t *identifier_symbol = NULL; const char *string; atom_t atom; const char **ptr; int i; atom = get_next_atom_ignore_newlines(conf->parser); /* identifiers are strings. so check for that type and do * a comparison against our data. */ if(atom != PARSER_ATOM_STRING) return NULL; string = parser_get_data(conf->parser); i = 0; for(ptr = argument_strings; *ptr != NULL; ptr++) { if(!strcmp(string, *ptr)) { identifier_symbol = xmalloc(sizeof(arg_symbol_t)); *identifier_symbol = argument_symbols[i]; break; } i++; } return identifier_symbol; } 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; atom_t atom; atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_STRING) return NULL; string = parser_get_data(conf->parser); 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 { return NULL; } } static void *compile_arg_assignment(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { uint8_t *placeholder; atom_t atom; /* this is fairly easy check if the atom is an assignment and just return an empty placeholder. * we really don't care what kind of assignment it is since we only have one. in the future * we may create more. */ atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_ASSIGNMENT) return NULL; placeholder = xmalloc(sizeof(uint8_t)); *placeholder = 1; return placeholder; } static void *compile_arg_boolean(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { uint8_t *bool_val; atom_t atom; const char *string; atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_STRING) return NULL; string = parser_get_data(conf->parser); if(!strcmp(string, "yes")) { bool_val = xmalloc(sizeof(uint8_t)); *bool_val = 1; } else if(!strcmp(string, "no")) { bool_val = xmalloc(sizeof(uint8_t)); *bool_val = 0; } else { bool_val = NULL; } return bool_val; } static void *compile_arg_string(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { char *string_arg; const char *string; atom_t atom; atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_STRING) return NULL; string = parser_get_data(conf->parser); string_arg = xstrdup(string); return string_arg; } static void *compile_arg_string_list(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { list_t *string_list = NULL; char *string; atom_t atom; /* ask compile_arg_string_list to do the work for us. * we peek for commas but that's about it. */ while(1) { /* next one should be string or it's a parser error. */ string = compile_arg_string(conf, argument_strings, argument_symbols); if(string == NULL) { purge_list(string_list, NULL); return NULL; } string_list = add_to_end_of_list(string_list, string); /* now peek for a comma, if available keep going. */ atom = parser_peek_next_atom(conf->parser); if(atom == PARSER_ATOM_COMMA) { atom = get_next_atom_ignore_newlines(conf->parser); } else { break; } } return string_list; } /* compile the command. follow the command argument types and store them. */ static directive_t *compile_command(conf_t *conf, command_t *command) { directive_t *directive; void *args; atom_t atom; int i; arg_type_t *arg_type; /* create a new directive. */ directive = directive_create(); /* set the command code. */ directive->command_code = command->command_code; for(i = 0;i < command->argument_len; i++) { /* now try to compile the arguments based on the type. */ args = argument_compilers[command->argument_types[i]](conf, command->argument_strings[i], command->argument_symbols[i]); if(args == NULL) { directive_destroy(directive); return NULL; } arg_type = arg_type_create(command->argument_types[i]); directive->argument_types = add_to_end_of_list(directive->argument_types, arg_type); directive->arguments = add_to_end_of_list(directive->arguments, args); } /* we're done. now we need a semicolon to end this directive. */ atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_SEMICOLON) { directive_destroy(directive); return NULL; } return directive; } static directive_t *compile_directive(conf_t *conf) { const char *token_string; directive_t *directive; command_t *command; int i; /* we expect the string is already read from the parser * before we're called. */ token_string = parser_get_data(conf->parser); /* now do a comparison and find our command_t. */ for(i = 0;;i++) { command = conf->commands[i]; if(command == NULL) break; if(!strcmp(command->command_name, token_string)) { /* we have a match. try to parse the rest so we have a new command_t filled out. */ directive = compile_command(conf, command); if(command == NULL) continue; /* try to compile any other matching command: this lets us set the same command name with different arguments. */ return directive; } } /* we didn't match a command name. */ return NULL; } /* a group is just a grouping of additional commands. we create a directive list and pass it up.*/ static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { atom_t atom; directive_t *directive; list_t *directive_list = NULL; /* if we have a brace, go ahead and read in a command list. by compiling each command under it * as per the commands allowed in the group. */ atom = get_next_atom_ignore_newlines(conf->parser); if(atom != PARSER_ATOM_BLOCK_OPEN) return NULL; /* FIXME: currently empty groups are going to return the same error as a missing brace. */ while(1) { atom = get_next_atom_ignore_newlines(conf->parser); if(atom == PARSER_ATOM_BLOCK_CLOSE) return directive_list; /* we should always start with a string. */ if(atom != PARSER_ATOM_STRING) goto error; directive = compile_directive(conf); if(directive == NULL) goto error; directive_list = add_to_end_of_list(directive_list, directive); } error: purge_list(directive_list, directive_destroy_l); return NULL; } /* compile the file into a list of directives. */ int conf_compile_directives(conf_t *conf) { atom_t atom; directive_t *directive; while(1) { atom = get_next_atom_ignore_newlines(conf->parser); if(atom == PARSER_ATOM_EOF) /* end of file */ return CONF_OK; /* we should always start with a string. */ if(atom != PARSER_ATOM_STRING) return CONF_ERROR; directive = compile_directive(conf); if(directive == NULL) return CONF_ERROR; /* if we got a string it should match or error. */ conf->directives = add_to_end_of_list(conf->directives, directive); } /* we should never get here. */ FATAL_MESSAGE("i don't know why i'm here. this is a bug. report me."); exit(1); /* do away with compiler warning. */ } list_t *conf_get_directives(conf_t *conf) { return conf->directives; } --- NEW FILE: dhcp-conf.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.h,v 1.1 2002/12/15 00:22:02 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef DHCP_CONF_H #define DHCP_CONF_H /* native types. */ typedef uint32_t command_code_t; typedef uint32_t arg_len_t; typedef uint32_t arg_type_t; typedef uint32_t arg_symbol_t; /* compiled directive. */ typedef struct { command_code_t command_code; /* the command code. */ list_t *argument_types; /* type of argument: need this to free up arguments later. */ list_t *arguments; /* argument data. */ } directive_t; /* command syntax object. */ typedef struct { const command_code_t command_code; const char *command_name; const arg_len_t argument_len; const char ***argument_strings; const arg_type_t *argument_types; const arg_symbol_t **argument_symbols; } command_t; /* conf object. */ typedef struct { char *filename; parser_t *parser; command_t **commands; /* list of permissible commands. */ list_t *directives; } conf_t; /* typedef of configuration drivers. */ typedef void *(*argument_compiler_t)(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols); /* conf return types. */ enum conf_return_types { CONF_OK = 0, CONF_ERROR }; /* 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 }; /* prototypes. */ extern conf_t *conf_create(command_t **commands, const char *filename); extern void conf_destroy(conf_t *conf); extern int conf_compile_directives(conf_t *conf); extern list_t *conf_get_directives(conf_t *conf); #endif /* DHCP_CONF_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.am 24 Nov 2002 01:10:35 -0000 1.9 --- Makefile.am 15 Dec 2002 00:22:02 -0000 1.10 *************** *** 16,20 **** dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-globconf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-parser.h dhcp-sysconf.h --- 16,20 ---- dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-globconf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-parser.h dhcp-sysconf.h dhcp-conf.h *************** *** 60,64 **** dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil -lefence dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ --- 60,65 ---- dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil dhcp_sniff_LDADD = -ldhcputil + libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client.c 24 Nov 2002 01:10:00 -0000 1.7 --- dhcp-client.c 15 Dec 2002 00:22:02 -0000 1.8 *************** *** 97,101 **** #endif /* HAVE_PROGNAME */ ! /* local vars for dhcpclient. */ static char *interface = NULL; /* the interface we're concerned with. */ static unsigned char want_background = 1; /* whether we should go into the background. */ --- 97,101 ---- #endif /* HAVE_PROGNAME */ ! /* local vars for dhcp-client. */ static char *interface = NULL; /* the interface we're concerned with. */ static unsigned char want_background = 1; /* whether we should go into the background. */ *************** *** 394,398 **** if(client_process_exists(interface)) { ! FATAL_MESSAGE("dhcpclient already exists on interface %s use -k to kill it", interface); } --- 394,398 ---- if(client_process_exists(interface)) { ! FATAL_MESSAGE("%s already exists on interface %s use -k to kill it", getprogname(), interface); } Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-libutil.h 24 Nov 2002 03:06:47 -0000 1.9 --- dhcp-libutil.h 15 Dec 2002 00:22:02 -0000 1.10 *************** *** 130,134 **** extern char *splice_many_strings(int num, char *s, ...); extern int string_matches(const char *s1, const char *s2); ! extern int hex_string_to_value(char *string, unsigned char *dst); extern int is_string(const char *string, int len); extern char *xstrdup(const char *string); --- 130,134 ---- extern char *splice_many_strings(int num, char *s, ...); extern int string_matches(const char *s1, const char *s2); ! extern int hex_string_to_value(const char *string, unsigned char *dst); extern int is_string(const char *string, int len); extern char *xstrdup(const char *string); *************** *** 142,145 **** --- 142,147 ---- extern const char *getprogname(void); extern int resolv(char *address, uint32_t *addr); + extern ip_addr_t *string_ip_to_ip_addr(const char *string_ip); + extern eth_addr_t *string_eth_addr_to_eth_addr(const char *eth_ip); extern int is_seven_bit_clean(const char *data, int len); Index: dhcp-parser.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-parser.c 24 Nov 2002 20:54:31 -0000 1.4 --- dhcp-parser.c 15 Dec 2002 00:22:02 -0000 1.5 *************** *** 31,35 **** /* these characters are special. we only allow them in a quoted string. */ ! static char special_characters[] = ";{}="; /* forward declaration of parsers. */ --- 31,35 ---- /* these characters are special. we only allow them in a quoted string. */ ! static char special_characters[] = ",;{}="; /* forward declaration of parsers. */ *************** *** 49,61 **** parser_input_t parsers[] = { ! { ';', parse_semicolon, }, ! { '\\', parse_gobble_line }, ! { '#' , parse_comment }, ! { '\"', parse_quoted_string }, ! { '\n', parse_newline }, ! { '=', parse_assignment }, ! { '{' , parse_block_open }, ! { '}', parse_block_close }, ! { ',', parse_comma }, }; --- 49,62 ---- parser_input_t parsers[] = { ! /* char val */ /* routine. */ /* peek val. */ ! { ';', parse_semicolon, PARSER_ATOM_SEMICOLON }, ! { '\\', parse_gobble_line, PARSER_ATOM_NEWLINE}, ! { '#' , parse_comment, PARSER_ATOM_NEWLINE }, ! { '\"', parse_quoted_string, PARSER_ATOM_STRING }, ! { '\n', parse_newline, PARSER_ATOM_NEWLINE }, ! { '=', parse_assignment, PARSER_ATOM_ASSIGNMENT }, ! { '{' , parse_block_open, PARSER_ATOM_BLOCK_OPEN }, ! { '}', parse_block_close, PARSER_ATOM_BLOCK_CLOSE }, ! { ',', parse_comma, PARSER_ATOM_COMMA, }, }; *************** *** 240,245 **** } ! /* get the next atom. */ ! atom_t get_next_atom(parser_t *input) { int c, c2; --- 241,245 ---- } ! static atom_t parser_get_next_atom_proc(parser_t *input, uint8_t peeking) { int c, c2; *************** *** 279,286 **** for(i = 0;i < NELMS(parsers); i++) { ! if(parsers[i].character == c) ! return parsers[i].do_parse(input); } /* if we have an alphanumeric it's a string. read it in. */ --- 279,301 ---- for(i = 0;i < NELMS(parsers); i++) { ! if(parsers[i].character == c) { ! ! if(peeking) { ! ! /* if we're just peeking ungetc before we return peek value. */ ! ungetc(c, input->fp); ! return parsers[i].peek_val; ! ! } ! ! return parsers[i].do_parse(input); ! } } + /* otherwise we default to trying a string. */ + + if(peeking) + return PARSER_ATOM_STRING; /* or at least we assume it's a string. */ + /* if we have an alphanumeric it's a string. read it in. */ *************** *** 294,298 **** return PARSER_ATOM_ERROR; } ! } } --- 309,333 ---- return PARSER_ATOM_ERROR; } ! } ! } ! ! /* get the next atom. */ ! atom_t get_next_atom(parser_t *input) ! { ! return(parser_get_next_atom_proc(input, 0)); ! } ! ! atom_t parser_peek_next_atom(parser_t *input) ! { ! return(parser_get_next_atom_proc(input, 1)); ! } ! ! atom_t get_next_atom_ignore_newlines(parser_t *input) ! { ! atom_t atom; ! ! while((atom = get_next_atom(input)) == PARSER_ATOM_NEWLINE); ! ! return atom; } Index: dhcp-parser.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-parser.h 24 Nov 2002 20:54:31 -0000 1.4 --- dhcp-parser.h 15 Dec 2002 00:22:02 -0000 1.5 *************** *** 36,46 **** char character; parse_input do_parse; } parser_input_t; - extern void destroy_parser(parser_t *parser); extern parser_t *create_parser(const char *filename); extern atom_t get_next_atom(parser_t *input); extern const char *parser_get_data(parser_t *input); extern int parser_get_line_no(parser_t *parser); /* parser return values. */ --- 36,52 ---- char character; parse_input do_parse; + atom_t peek_val; } parser_input_t; extern parser_t *create_parser(const char *filename); + extern void destroy_parser(parser_t *parser); + extern atom_t get_next_atom(parser_t *input); + extern atom_t get_next_atom_ignore_newlines(parser_t *input); + extern atom_t parser_peek_next_atom(parser_t *input); + extern const char *parser_get_data(parser_t *input); extern int parser_get_line_no(parser_t *parser); + /* parser return values. */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-util.c 16 Nov 2002 00:23:44 -0000 1.7 --- dhcp-util.c 15 Dec 2002 00:22:02 -0000 1.8 *************** *** 335,339 **** /* parse hex string (0x:0x...0x) to value. (not fun to write) */ ! int hex_string_to_value(char *string, unsigned char *dst) { char *sep, *ptr; --- 335,339 ---- /* parse hex string (0x:0x...0x) to value. (not fun to write) */ ! int hex_string_to_value(const char *string, unsigned char *dst) { char *sep, *ptr; *************** *** 492,494 **** --- 492,527 ---- interactive = interactive_arg; return; + } + + /* convert a string ip to ip_addr_t */ + ip_addr_t *string_ip_to_ip_addr(const char *string_ip) + { + ip_addr_t *ip; + + ip = xmalloc(sizeof(ip_addr_t)); + + /* FIXME: use inet_aton if available */ + *(ip) = inet_addr(string_ip); + + if(*(ip) == INADDR_NONE) { + xfree(ip); + return NULL; + } + + return ip; + } + + /* convert a string ip to ip_addr_t */ + eth_addr_t *string_eth_addr_to_eth_addr(const char *eth_addr) + { + eth_addr_t *eth; + + eth = xmalloc(sizeof(eth_addr_t)); + + if(hex_string_to_value(eth_addr, eth->data)) { + xfree(eth); + return NULL; + } + + return eth; } |
From: <act...@us...> - 2002-12-15 00:20:04
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv27646 Modified Files: README Log Message: correction on libdnet version Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README 30 Oct 2002 05:02:26 -0000 1.2 --- README 15 Dec 2002 00:20:00 -0000 1.3 *************** *** 38,42 **** http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (1.5 or above). http://libdnet.sourceforge.net/ --- 38,42 ---- http://www.tcpdump.org/ ! You will also need Dug Song's libdnet (1.5 or higher). http://libdnet.sourceforge.net/ |
From: <act...@us...> - 2002-11-24 20:54:37
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv23533 Modified Files: dhcp-parser.c dhcp-parser.h dhcp-varfile.c Log Message: revamp to parser Index: dhcp-parser.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-parser.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-parser.c 24 Nov 2002 20:54:31 -0000 1.4 *************** *** 30,33 **** --- 30,76 ---- #include "dhcp-parser.h" + /* these characters are special. we only allow them in a quoted string. */ + static char special_characters[] = ";{}="; + + /* forward declaration of parsers. */ + static token_t parse_comment(parser_t *input); + static token_t parse_gobble_line(parser_t *input); + static token_t parse_quoted_string(parser_t *input); + static token_t parse_string(parser_t *input); + static token_t parse_comment(parser_t *input); + static token_t parse_newline(parser_t *input); + static token_t parse_assignment(parser_t *input); + static token_t parse_block_open(parser_t *input); + static token_t parse_block_close(parser_t *input); + static token_t parse_comma(parser_t *input); + static token_t parse_semicolon(parser_t *input); + + /* parser dispatch table. */ + parser_input_t parsers[] = { + + { ';', parse_semicolon, }, + { '\\', parse_gobble_line }, + { '#' , parse_comment }, + { '\"', parse_quoted_string }, + { '\n', parse_newline }, + { '=', parse_assignment }, + { '{' , parse_block_open }, + { '}', parse_block_close }, + { ',', parse_comma }, + + }; + + static int is_special_char(int c) + { + int i; + + for(i = 0;i < NELMS(special_characters);i++) { + if(c == special_characters[i]) + return 1; + } + + return 0; + } + /* is a valid string character. */ static int is_valid_string_char(int c) *************** *** 36,40 **** return 0; ! if(ispunct(c) || isalnum(c)) return 1; else --- 79,83 ---- return 0; ! if(isalnum(c) || ispunct(c)) return 1; else *************** *** 46,52 **** { if(feof(input->fp)) ! return PARSER_TOKEN_EOF; else ! return PARSER_TOKEN_ERROR; } --- 89,95 ---- { if(feof(input->fp)) ! return PARSER_ATOM_EOF; else ! return PARSER_ATOM_ERROR; } *************** *** 66,70 **** case '\n': input->line_no++; ! return PARSER_TOKEN_NEWLINE; default: --- 109,113 ---- case '\n': input->line_no++; ! return PARSER_ATOM_NEWLINE; default: *************** *** 75,79 **** /* read a quoted string. */ ! static token_t parse_get_quoted_string(parser_t *input) { int c, c2; --- 118,122 ---- /* read a quoted string. */ ! static token_t parse_quoted_string(parser_t *input) { int c, c2; *************** *** 89,96 **** case '\"': ! return PARSER_TOKEN_QUOTED_STRING; case '\n': ! return PARSER_TOKEN_ERROR; /* error to have newline in string constant. */ case '\\': --- 132,139 ---- case '\"': ! return PARSER_ATOM_STRING; case '\n': ! return PARSER_ATOM_ERROR; /* error to have newline in string constant. */ case '\\': *************** *** 100,105 **** ungetc(c2, input->fp); ! if(parse_gobble_line(input) != PARSER_TOKEN_NEWLINE) ! return PARSER_TOKEN_ERROR; else break; --- 143,148 ---- ungetc(c2, input->fp); ! if(parse_gobble_line(input) != PARSER_ATOM_NEWLINE) ! return PARSER_ATOM_ERROR; else break; *************** *** 115,119 **** else { ungetc(c, input->fp); ! return PARSER_TOKEN_ERROR; } } --- 158,162 ---- else { ungetc(c, input->fp); ! return PARSER_ATOM_ERROR; } } *************** *** 122,126 **** /* read a string. */ ! static token_t parse_get_string(parser_t *input) { int c; --- 165,169 ---- /* read a string. */ ! static token_t parse_string(parser_t *input) { int c; *************** *** 137,157 **** case '\n': ungetc(c, input->fp); ! return PARSER_TOKEN_STRING; /* newline terminates string. */ case '\t': case ' ': ungetc(c, input->fp); ! return PARSER_TOKEN_STRING; /* newline terminates string. */ ! ! case '=': ! ungetc(c, input->fp); ! return PARSER_TOKEN_STRING; /* newline terminates string. */ default: ! if(is_valid_string_char(c)) stringbuffer_append_c(input->data_buff, (char)c); ! else { ungetc(c, input->fp); ! return PARSER_TOKEN_ERROR; /* anything else and we've been terminated. */ } } --- 180,202 ---- case '\n': ungetc(c, input->fp); ! return PARSER_ATOM_STRING; /* newline terminates string. */ case '\t': case ' ': ungetc(c, input->fp); ! return PARSER_ATOM_STRING; /* spaces or tabs terminate string */ default: ! ! if(is_special_char(c)) { ! ungetc(c, input->fp); ! return PARSER_ATOM_STRING; ! } ! ! if(is_valid_string_char(c)) { stringbuffer_append_c(input->data_buff, (char)c); ! } else { ungetc(c, input->fp); ! return PARSER_ATOM_ERROR; /* anything else and we've been terminated. */ } } *************** *** 159,172 **** } /* get the next atom. */ atom_t get_next_atom(parser_t *input) { int c, c2; ! token_t token; stringbuffer_clear(input->data_buff); while(1) { - c = fgetc(input->fp); --- 204,252 ---- } + static token_t parse_comment(parser_t *input) + { + return parse_gobble_line(input); + } + + static token_t parse_newline(parser_t *input) + { + input->line_no++; + return PARSER_ATOM_NEWLINE; + } + + static token_t parse_assignment(parser_t *input) + { + return PARSER_ATOM_ASSIGNMENT; + } + + static token_t parse_block_open(parser_t *input) + { + return PARSER_ATOM_BLOCK_OPEN; + } + + static token_t parse_block_close(parser_t *input) + { + return PARSER_ATOM_BLOCK_CLOSE; + } + + static token_t parse_comma(parser_t *input) + { + return PARSER_ATOM_COMMA; + } + + static token_t parse_semicolon(parser_t *input) + { + return PARSER_ATOM_SEMICOLON; + } + /* get the next atom. */ atom_t get_next_atom(parser_t *input) { int c, c2; ! int i; stringbuffer_clear(input->data_buff); while(1) { c = fgetc(input->fp); *************** *** 176,209 **** return PARSER_ATOM_EOF; - case '#': - - token = parse_gobble_line(input); - - if(token == PARSER_TOKEN_NEWLINE || token == PARSER_TOKEN_EOF) - return PARSER_ATOM_END_OF_STATEMENT; - - /* anything else is an error. */ - return PARSER_ATOM_ERROR; - - case '\n': - input->line_no++; - return PARSER_ATOM_END_OF_STATEMENT; - - case '=': - return PARSER_ATOM_ASSIGNMENT; - - case '\t': case ' ': ! break; ! ! case '\"': ! token = parse_get_quoted_string(input); ! ! if(token == PARSER_TOKEN_ERROR) ! return PARSER_ATOM_ERROR; ! ! return PARSER_ATOM_STRING; case '\\': c2 = getc(input->fp); if(c2 != '\\') { --- 256,265 ---- return PARSER_ATOM_EOF; case ' ': ! case '\t': ! continue; case '\\': + c2 = getc(input->fp); if(c2 != '\\') { *************** *** 211,215 **** ungetc(c2, input->fp); ! if(parse_gobble_line(input) != PARSER_TOKEN_NEWLINE) return PARSER_ATOM_ERROR; else --- 267,271 ---- ungetc(c2, input->fp); ! if(parse_gobble_line(input) != PARSER_ATOM_NEWLINE) return PARSER_ATOM_ERROR; else *************** *** 217,236 **** } else ungetc(c2, input->fp); ! /* fall through */ - default: /* if we have an alphanumeric it's a string. read it in. */ ! if(is_valid_string_char(c)) { ungetc(c, input->fp); ! token = parse_get_string(input); ! ! if(token == PARSER_TOKEN_ERROR) ! return PARSER_ATOM_ERROR; ! ! return PARSER_ATOM_STRING; } return PARSER_ATOM_ERROR; } --- 273,295 ---- } else ungetc(c2, input->fp); ! /* fall through */ default: + + for(i = 0;i < NELMS(parsers); i++) { + + if(parsers[i].character == c) + return parsers[i].do_parse(input); + } + /* if we have an alphanumeric it's a string. read it in. */ ! if(is_valid_string_char(c) || c == '\\') { ungetc(c, input->fp); ! return parse_string(input); } + + /* anything else is an error. */ return PARSER_ATOM_ERROR; } Index: dhcp-parser.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-parser.h 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-parser.h 24 Nov 2002 20:54:31 -0000 1.4 *************** *** 31,34 **** --- 31,41 ---- typedef uint8_t atom_t; + typedef token_t (*parse_input)(parser_t *input); + + typedef struct { + char character; + parse_input do_parse; + } parser_input_t; + extern void destroy_parser(parser_t *parser); extern parser_t *create_parser(const char *filename); *************** *** 38,57 **** /* parser return values. */ ! #define PARSER_TOKEN_ERROR 0 ! #define PARSER_TOKEN_NEWLINE 1 ! #define PARSER_TOKEN_EOF 2 ! #define PARSER_TOKEN_QUOTED_STRING 3 ! #define PARSER_TOKEN_STRING 4 ! #define PARSER_TOKEN_ASSIGNMENT 5 ! ! #define PARSER_ATOM_ERROR 0 ! #define PARSER_ATOM_STRING 1 ! #define PARSER_ATOM_ASSIGNMENT 2 ! #define PARSER_ATOM_END_OF_STATEMENT 3 ! #define PARSER_ATOM_EOF 4 ! ! /* Parse types. */ ! #define PARSE_SINGLE_STRING 1 ! #define PARSE_DOUBLE_STRINGS 2 #endif /* DHCP_PARSER_H */ --- 45,51 ---- /* parser return values. */ ! enum parser_atom { PARSER_ATOM_ERROR = 0, PARSER_ATOM_STRING, PARSER_ATOM_ASSIGNMENT, PARSER_ATOM_NEWLINE, ! PARSER_ATOM_EOF, PARSER_ATOM_BLOCK_OPEN, PARSER_ATOM_BLOCK_CLOSE, PARSER_ATOM_SEMICOLON, ! PARSER_ATOM_COMMA }; #endif /* DHCP_PARSER_H */ Index: dhcp-varfile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-varfile.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-varfile.c 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-varfile.c 24 Nov 2002 20:54:31 -0000 1.4 *************** *** 20,25 **** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * varfiles -- variable files. All the files which we read are varfiles. * */ --- 20,28 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * ! * varfiles -- variable files. Files with varname or varname = ! * varvalue for statements. * + * This files are meant to be human readable and be cross platform by writing + * the serialized form of all the values. */ *************** *** 84,88 **** atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_END_OF_STATEMENT) /* skip empty lines/comments. */ continue; --- 87,91 ---- atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_NEWLINE) /* skip empty lines/comments. */ continue; *************** *** 98,102 **** /* if we don't get an end of statement or eof here it's a parse error. */ ! if(atom != PARSER_ATOM_END_OF_STATEMENT && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; --- 101,105 ---- /* if we don't get an end of statement or eof here it's a parse error. */ ! if(atom != PARSER_ATOM_NEWLINE && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; *************** *** 114,118 **** atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_END_OF_STATEMENT) /* skip empty lines/comments. */ continue; --- 117,121 ---- atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_NEWLINE) /* skip empty lines/comments. */ continue; *************** *** 128,133 **** } - /* the rest should be ASSIGNMENT STRING END_OF_STATEMENT; */ - atom = get_next_atom(varfile->parser); --- 131,134 ---- *************** *** 147,151 **** atom = get_next_atom(varfile->parser); ! if(atom != PARSER_ATOM_END_OF_STATEMENT && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; --- 148,152 ---- atom = get_next_atom(varfile->parser); ! if(atom != PARSER_ATOM_NEWLINE && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; |
From: <act...@us...> - 2002-11-24 03:06:50
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv30737 Modified Files: dhcp-libutil.h Log Message: NELMS :-) Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-libutil.h 24 Nov 2002 01:10:00 -0000 1.8 --- dhcp-libutil.h 24 Nov 2002 03:06:47 -0000 1.9 *************** *** 255,258 **** --- 255,261 ---- /* macros. */ + /* NELMS straight out of "The Practice of Programming" Pike and Kernighan. */ + #define NELMS(x) (sizeof(x)/sizeof(x[0])) + /* log message macros. */ #define INFO_MESSAGE(...) { info_message(__VA_ARGS__); } |
From: <act...@us...> - 2002-11-24 01:12:15
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv25272/src Modified Files: dhcp-client-cache.c dhcp-client-states.c dhcp-sysconf.c dhcp-timer.c Log Message: fixed up indentation with indent Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-cache.c 22 Nov 2002 15:30:37 -0000 1.7 --- dhcp-client-cache.c 24 Nov 2002 01:12:12 -0000 1.8 *************** *** 178,182 **** case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(atoi(varfile_get_name(varfile)), varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; --- 178,182 ---- case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(atoi(varfile_get_name(varfile)), varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-states.c 24 Nov 2002 01:10:00 -0000 1.6 --- dhcp-client-states.c 24 Nov 2002 01:12:12 -0000 1.7 *************** *** 151,155 **** { /* just call renew_option_list since it's the same. */ ! return(client_build_renew_option_list(dc)); } --- 151,155 ---- { /* just call renew_option_list since it's the same. */ ! return (client_build_renew_option_list(dc)); } *************** *** 288,296 **** if(next_timer != 0) ! timeout = next_timer/2; ! else timeout = next_timer; ! } else { timeout = RECOMMENDED_MAX_SECS_WAIT; } --- 288,296 ---- if(next_timer != 0) ! timeout = next_timer / 2; ! else timeout = next_timer; ! } else { timeout = RECOMMENDED_MAX_SECS_WAIT; } *************** *** 625,629 **** retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, compensate_timeout_with_timer(dc)); switch (retval) { --- 625,630 ---- retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, ! compensate_timeout_with_timer(dc)); switch (retval) { *************** *** 669,673 **** retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_rebind, compensate_timeout_with_timer(dc)); switch (retval) { --- 670,675 ---- retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_rebind, ! compensate_timeout_with_timer(dc)); switch (retval) { *************** *** 684,689 **** default: ! FATAL_MESSAGE ! ("invalid return value from raw network handler -- this a bug report it."); } --- 686,690 ---- default: ! FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-sysconf.c 22 Nov 2002 15:30:38 -0000 1.7 --- dhcp-sysconf.c 24 Nov 2002 01:12:12 -0000 1.8 *************** *** 465,469 **** sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; WARN_MESSAGE("unable to setup option: %s", dhcp_option_string_get(ce->tag)); ! } else { --- 465,469 ---- sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; WARN_MESSAGE("unable to setup option: %s", dhcp_option_string_get(ce->tag)); ! } else { Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-timer.c 24 Nov 2002 01:10:00 -0000 1.5 --- dhcp-timer.c 24 Nov 2002 01:12:12 -0000 1.6 *************** *** 118,122 **** uint32_t time_now; ! begin: if(timer->triggers == NULL) --- 118,122 ---- uint32_t time_now; ! begin: if(timer->triggers == NULL) *************** *** 175,177 **** return trigger->seconds; } - --- 175,176 ---- |
From: <act...@us...> - 2002-11-24 01:10:43
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv24661/src Modified Files: Makefile.am Log Message: using AM_CFLAGS now Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.am 19 Nov 2002 19:44:43 -0000 1.8 --- Makefile.am 24 Nov 2002 01:10:35 -0000 1.9 *************** *** 3,7 **** # Main source Makefile.am ! CFLAGS = -Wall -Werror -g INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ --- 3,7 ---- # Main source Makefile.am ! AM_CFLAGS = -Wall -Werror -g INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv24303/src Modified Files: dhcp-client-conf.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-convert.c dhcp-libutil.h dhcp-timer.c Log Message: rebind/renew implemented Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-conf.c 22 Nov 2002 15:30:37 -0000 1.5 --- dhcp-client-conf.c 24 Nov 2002 01:10:00 -0000 1.6 *************** *** 37,42 **** #include "dhcp-options-strings.h" - #define DEFAULT_CONFIG_OPTIONS_LEN 8 - /* Basic network configuration. * Here we keep the options we want by default. */ --- 37,40 ---- *************** *** 97,101 **** return -1; ! for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { if(fprintf(fp, "\"%s\"\n", dhcp_option_string_get(i)) < 0) { --- 95,99 ---- return -1; ! for(i = 0; i < NELMS(default_config_options); i++) { if(fprintf(fp, "\"%s\"\n", dhcp_option_string_get(i)) < 0) { *************** *** 114,118 **** int i; ! for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { cc->options[default_config_options[i]] = 1; } --- 112,116 ---- int i; ! for(i = 0; i < NELMS(default_config_options); i++) { cc->options[default_config_options[i]] = 1; } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-states.c 19 Nov 2002 19:44:44 -0000 1.5 --- dhcp-client-states.c 24 Nov 2002 01:10:00 -0000 1.6 *************** *** 44,48 **** ***************************/ ! /* Create DHCP RELEASE option list. */ static list_t *client_build_release_option_list(dhcp_client_control_t *dc) { --- 44,48 ---- ***************************/ ! /* create DHCP RELEASE option list. */ static list_t *client_build_release_option_list(dhcp_client_control_t *dc) { *************** *** 62,74 **** } ! static dhcp_option_t *client_build_parameter_request_list(dhcp_client_control_t *dc) ! { ! dhcp_option_t *option; ! ! option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); ! return option; ! } ! ! /* This is used for both requests and discovery. */ static list_t *client_build_option_list(dhcp_client_control_t *dc) { --- 62,66 ---- } ! /* create DISCOVER and REQUEST option list. */ static list_t *client_build_option_list(dhcp_client_control_t *dc) { *************** *** 101,105 **** } ! /* Create DHCP DISCOVER option list. */ static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { --- 93,97 ---- } ! /* create DHCP DISCOVER option list. */ static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { *************** *** 108,112 **** dhcp_option_t *option; ! option = client_build_parameter_request_list(dc); options = add_to_list(options, option); --- 100,104 ---- dhcp_option_t *option; ! option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); options = add_to_list(options, option); *************** *** 121,125 **** } ! /* Create DHCP REQUEST option list. */ static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { --- 113,117 ---- } ! /* create DHCP REQUEST option list. */ static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { *************** *** 138,142 **** } ! /* Create DHCP REBIND option list. */ static list_t *client_build_renew_option_list(dhcp_client_control_t *dc) { --- 130,134 ---- } ! /* create DHCP RENEW option list. */ static list_t *client_build_renew_option_list(dhcp_client_control_t *dc) { *************** *** 155,164 **** } /****************** * Check Routines * ******************/ ! /* Check the requested options. ! * We use the globconf option. */ static int client_check_requested_options(dhcp_client_control_t *dc) --- 147,163 ---- } + /* create DHCP REBIND option list. */ + static list_t *client_build_rebind_option_list(dhcp_client_control_t *dc) + { + /* just call renew_option_list since it's the same. */ + return(client_build_renew_option_list(dc)); + } + /****************** * Check Routines * ******************/ ! /* check the requested options. ! * we use the globconf option. */ static int client_check_requested_options(dhcp_client_control_t *dc) *************** *** 182,186 **** } ! /* Basic DHCP test on incoming rawnet packet. */ static int client_check_dhcp(dhcp_client_control_t *dc) { --- 181,185 ---- } ! /* basic DHCP test on incoming rawnet packet. */ static int client_check_dhcp(dhcp_client_control_t *dc) { *************** *** 228,231 **** --- 227,231 ---- } + /* check for valid renew response. */ static int client_check_renew(void *arg) { *************** *** 235,240 **** } /************* ! * Utilities.* *************/ --- 235,248 ---- } + /* check for valid renew response. */ + static int client_check_rebind(void *arg) + { + /* we're expecting the same as request :-) */ + return (client_check_request(arg)); + + } + /************* ! * Utilities * *************/ *************** *** 267,272 **** } /************* ! * ARP/UNARP.* *************/ --- 275,304 ---- } + time_t compensate_timeout_with_timer(dhcp_client_control_t *dc) + { + uint32_t next_timer; + time_t timeout; + + /* we realize time_t may not be uint32_t, however we're only + * going to set the max timeout if it is lower so this is + * safe. we shouldn't overflow. */ + + next_timer = timer_peek_next_timer(dc->timer); + if(next_timer < RECOMMENDED_MAX_SECS_WAIT) { + + if(next_timer != 0) + timeout = next_timer/2; + else + timeout = next_timer; + + } else { + timeout = RECOMMENDED_MAX_SECS_WAIT; + } + + return timeout; + } + /************* ! * ARP/UNARP * *************/ *************** *** 323,326 **** --- 355,360 ---- int retval; + INFO_MESSAGE("attempting DHCP DISCOVER"); + options = client_build_discover_option_list(dc); *************** *** 385,389 **** } ! /* do client_request_ack transaction. */ int client_request_ack(dhcp_client_control_t *dc) { --- 419,423 ---- } ! /* do request/ack transaction. */ int client_request_ack(dhcp_client_control_t *dc) { *************** *** 391,394 **** --- 425,430 ---- int retval; + INFO_MESSAGE("attempting DHCP REQUEST"); + /* Build options along with the options in our cache. */ *************** *** 426,431 **** default: ! FATAL_MESSAGE ! ("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); } --- 462,466 ---- default: ! FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } *************** *** 446,454 **** } ! /* release lease. */ int client_release(dhcp_client_control_t *dc) { list_t *options; options = client_build_release_option_list(dc); --- 481,491 ---- } ! /* do release */ int client_release(dhcp_client_control_t *dc) { list_t *options; + INFO_MESSAGE("sending DHCP RELEASE"); + options = client_build_release_option_list(dc); *************** *** 478,486 **** } ! /* do setup (call do_sysconf) */ int client_setup(dhcp_client_control_t *dc) { list_t *options; options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { --- 515,525 ---- } ! /* do system setup */ int client_setup(dhcp_client_control_t *dc) { list_t *options; + INFO_MESSAGE("performing system configuration"); + options = client_cache_load_option_string_list(dc->cache, 0); if(options == NULL) { *************** *** 506,512 **** } ! /* wait for timers and other interrupts . */ int client_wait(dhcp_client_control_t *dc) { /* take our raw network connection down. */ rawnet_down(dc->rawnet); --- 545,553 ---- } ! /* wait for timers and other interrupts */ int client_wait(dhcp_client_control_t *dc) { + INFO_MESSAGE("entering wait stage"); + /* take our raw network connection down. */ rawnet_down(dc->rawnet); *************** *** 567,586 **** } ! /* do a rebind. */ int client_renew(dhcp_client_control_t *dc) { list_t *options; int retval; - options = client_build_renew_option_list(dc); build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->sip_addr, dc->shw_addr); retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, RECOMMENDED_MAX_SECS_WAIT); switch (retval) { case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP request."); ! return STATE_FATAL_ERROR; case RAWNET_OK: --- 608,634 ---- } ! /* do a renew: this is exactly like rebind only we're unicasting. */ int client_renew(dhcp_client_control_t *dc) { list_t *options; int retval; + + INFO_MESSAGE("attempting DHCP RENEW"); + + options = client_build_renew_option_list(dc); build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->sip_addr, dc->shw_addr); + /* find out how much time we have until the next timer. + * if we have no other timers it's an error, however + * it will be caught later now just do our best. */ + retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, compensate_timeout_with_timer(dc)); ! switch (retval) { case RAWNET_TIMEOUT: ! return STATE_WAIT; /* no response: we've timed out. */ case RAWNET_OK: *************** *** 604,607 **** --- 652,701 ---- * here we'll fall into rebind time at the next timer * trigger. */ + + return STATE_WAIT; + } + + + /* do a rebind. */ + int client_rebind(dhcp_client_control_t *dc) + { + list_t *options; + int retval; + + INFO_MESSAGE("Attempting DHCP REBIND"); + + options = client_build_rebind_option_list(dc); + build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); + + retval = + rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_rebind, compensate_timeout_with_timer(dc)); + + switch (retval) { + + case RAWNET_TIMEOUT: + return STATE_WAIT; /* no response. we've timed out. */ + + case RAWNET_OK: + break; + + case RAWNET_ERROR: + ERROR_MESSAGE("received error from raw network handler."); + return STATE_FATAL_ERROR; + + default: + FATAL_MESSAGE + ("invalid return value from raw network handler -- this a bug report it."); + } + + /* if we got a pack we need to setup our timers. */ + if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) { + + client_setup_timers(dc); + + /* since we did a rebind our server's ip address and mac address may be different. */ + dhcp_client_set_server_ip_address(dc, ip_get_source_addr(dc->rawnet->ip_p)); + dhcp_client_set_server_hw_address(dc, eth_get_src_address(dc->rawnet->ether_p)); + + } return STATE_WAIT; Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client.c 19 Nov 2002 19:44:44 -0000 1.6 --- dhcp-client.c 24 Nov 2002 01:10:00 -0000 1.7 *************** *** 84,87 **** --- 84,88 ---- client_release, client_renew, + client_rebind, client_fatal_error, client_do_shutdown, *************** *** 251,255 **** case TIMER_REBIND: ! state = STATE_REQUEST_ACK; break; --- 252,256 ---- case TIMER_REBIND: ! state = STATE_REBIND; break; Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client.h 19 Nov 2002 19:44:44 -0000 1.5 --- dhcp-client.h 24 Nov 2002 01:10:00 -0000 1.6 *************** *** 70,75 **** #define STATE_RELEASE 4 #define STATE_RENEW 5 ! #define STATE_FATAL_ERROR 6 ! #define STATE_DO_SHUTDOWN 7 --- 70,76 ---- #define STATE_RELEASE 4 #define STATE_RENEW 5 ! #define STATE_REBIND 6 ! #define STATE_FATAL_ERROR 7 ! #define STATE_DO_SHUTDOWN 8 *************** *** 86,89 **** --- 87,91 ---- extern int client_release(dhcp_client_control_t *dc); extern int client_renew(dhcp_client_control_t *dc); + extern int client_rebind(dhcp_client_control_t *dc); extern int client_setup(dhcp_client_control_t *dc); extern int client_fatal_error(dhcp_client_control_t *dc); Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-convert.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-convert.c 24 Nov 2002 01:10:00 -0000 1.4 *************** *** 565,569 **** char *network_int_to_string(const unsigned char *data, int data_len, size_t size, int si) { ! char *string; if(size > data_len) --- 565,569 ---- char *network_int_to_string(const unsigned char *data, int data_len, size_t size, int si) { ! char *string = NULL; if(size > data_len) *************** *** 739,743 **** uint16_t *val; int len = 0; ! char *ptr; const char *cp; --- 739,743 ---- uint16_t *val; int len = 0; ! char *ptr = NULL; const char *cp; Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-libutil.h 19 Nov 2002 19:44:44 -0000 1.7 --- dhcp-libutil.h 24 Nov 2002 01:10:00 -0000 1.8 *************** *** 59,62 **** --- 59,63 ---- /* trigger object. */ typedef struct { + uint32_t time_set; uint32_t seconds; uint32_t id; *************** *** 194,197 **** --- 195,199 ---- extern uint32_t timer_get_current_id(timer_keeper_t *timer); extern void reinitialize_timer(timer_keeper_t *timer); + extern uint32_t timer_peek_next_timer(timer_keeper_t *timer); /* var file. */ *************** *** 246,249 **** --- 248,255 ---- #define MILLISECOND_RAND_TIMEOUT 1000 #define RECOMMENDED_MAX_SECS_WAIT 64 + + /* constant time values. */ + + #define INFINITE_TIME 0xFFFFFFFF /* macros. */ Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-timer.c 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-timer.c 24 Nov 2002 01:10:00 -0000 1.5 *************** *** 58,61 **** --- 58,62 ---- trigger->seconds = trigger_time; trigger->id = id; + trigger->time_set = time(NULL); return trigger; *************** *** 105,122 **** timer_trigger_t *trigger = create_trigger(trigger_time, id); timer->triggers = add_to_list(timer->triggers, trigger); return; } ! /* timer setup next trigger. */ ! int timer_set_next(timer_keeper_t *timer) { timer_trigger_t *trigger; if(timer->triggers == NULL) ! return 1; - timer->triggers = sort_list(timer->triggers, compare_triggers_shortest); trigger = timer->triggers->data; set_alarm(trigger->seconds); --- 106,152 ---- timer_trigger_t *trigger = create_trigger(trigger_time, id); timer->triggers = add_to_list(timer->triggers, trigger); + timer->triggers = sort_list(timer->triggers, compare_triggers_shortest); return; } ! /* utility to grab next valid timer: this will delete ones which have passed since. */ ! static timer_trigger_t *get_next_timer(timer_keeper_t *timer) { + uint32_t time_left; timer_trigger_t *trigger; + uint32_t time_now; + + begin: if(timer->triggers == NULL) ! return NULL; trigger = timer->triggers->data; + time_now = time(NULL); + time_left = trigger->seconds - (time_now - trigger->time_set); + + if(time_left > trigger->seconds) { + /* overflow. get the next timer. */ + timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); + destroy_trigger(trigger); + + goto begin; + } + + trigger->seconds = time_left; + trigger->time_set = time_now; + return trigger; + } + + /* timer setup next trigger. */ + int timer_set_next(timer_keeper_t *timer) + { + + timer_trigger_t *trigger; + trigger = get_next_timer(timer); + + if(trigger == NULL) + return 1; set_alarm(trigger->seconds); *************** *** 133,134 **** --- 163,177 ---- return timer->current_id; } + + uint32_t timer_peek_next_timer(timer_keeper_t *timer) + { + timer_trigger_t *trigger; + + trigger = get_next_timer(timer); + + if(trigger == NULL) + return INFINITE_TIME; + + return trigger->seconds; + } + |
From: <act...@us...> - 2002-11-22 15:33:29
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv29457/src Modified Files: dhcp-client-cache.h Log Message: removed prototype for internal format loading -- no longer needed Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-cache.h 19 Nov 2002 19:44:44 -0000 1.3 --- dhcp-client-cache.h 22 Nov 2002 15:33:26 -0000 1.4 *************** *** 43,47 **** extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); - extern list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, --- 43,46 ---- |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv27725/src Modified Files: dhcp-cache-entry.c dhcp-cache-entry.h dhcp-client-cache.c dhcp-client-conf.c dhcp-options-strings.c dhcp-options-strings.h dhcp-sysconf.c Log Message: optimized cache handling in sysconf Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-cache-entry.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-cache-entry.c 22 Nov 2002 15:30:37 -0000 1.4 *************** *** 35,39 **** /* constructors. */ ! cache_entry_t *create_cache_entry(const char *name, const char *value) { cache_entry_t *cache; --- 35,39 ---- /* constructors. */ ! cache_entry_t *create_cache_entry(uint8_t tag, const char *name, const char *value) { cache_entry_t *cache; *************** *** 42,45 **** --- 42,46 ---- cache->name = xstrdup(name); cache->value = xstrdup(value); + cache->tag = tag; return cache; Index: dhcp-cache-entry.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-cache-entry.h 16 Nov 2002 00:23:42 -0000 1.2 --- dhcp-cache-entry.h 22 Nov 2002 15:30:37 -0000 1.3 *************** *** 27,35 **** typedef struct { char *name; char *value; } cache_entry_t; ! extern cache_entry_t *create_cache_entry(const char *name, const char *value); extern void destroy_cache_entry(cache_entry_t *cache); extern void cache_entry_purge_list(list_t *cache_list); --- 27,36 ---- typedef struct { + uint8_t tag; char *name; char *value; } cache_entry_t; ! extern cache_entry_t *create_cache_entry(uint8_t tag, const char *name, const char *value); extern void destroy_cache_entry(cache_entry_t *cache); extern void cache_entry_purge_list(list_t *cache_list); Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-client-cache.c 22 Nov 2002 01:17:34 -0000 1.6 --- dhcp-client-cache.c 22 Nov 2002 15:30:37 -0000 1.7 *************** *** 56,73 **** void client_cache_purge(client_cache_t *cc) { ! list_t *list_ptr, *tmp; ! cache_entry_t *ce; ! ! list_ptr = cc->vars; ! while(list_ptr) { ! ! tmp = list_ptr; ! list_ptr = list_ptr->next; ! ! ce = tmp->data; ! destroy_cache_entry(ce); ! xfree(tmp); ! } ! cc->vars = NULL; return; --- 56,60 ---- void client_cache_purge(client_cache_t *cc) { ! cache_entry_purge_list(cc->vars); cc->vars = NULL; return; *************** *** 191,195 **** case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; --- 178,183 ---- case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(atoi(varfile_get_name(varfile)), ! varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; *************** *** 246,255 **** * Conversion work horses: * * * * * * * * * * * * * * */ - - /* convert to internal datums. */ - static void *convert_to_internal(unsigned char tag, char *string) - { - return NULL; - } /* convert to network. */ --- 234,237 ---- *************** *** 267,271 **** if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_options_strings[tag]); return NULL; } --- 249,253 ---- if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_option_string_get(tag)); return NULL; } *************** *** 285,289 **** tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { ! ce = create_cache_entry(dhcp_options_strings[tag], string); return ce; } --- 267,271 ---- tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { ! ce = create_cache_entry(tag, dhcp_option_string_get(tag), string); return ce; } *************** *** 296,300 **** cache_entry_t *ce; ! ce = create_cache_entry(dhcp_options_strings[tag], string); return ce; } --- 278,282 ---- cache_entry_t *ce; ! ce = create_cache_entry(tag, dhcp_option_string_get(tag), string); return ce; } *************** *** 369,373 **** } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_options_strings[opt->tag]); xfree(val); } --- 351,355 ---- } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_option_string_get(opt->tag)); xfree(val); } *************** *** 403,412 **** { return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); - } - - /* load options and return internal datum list. */ - list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp) - { - return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_internal)); } --- 385,388 ---- Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-conf.c 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-client-conf.c 22 Nov 2002 15:30:37 -0000 1.5 *************** *** 99,103 **** for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { ! if(fprintf(fp, "\"%s\"\n", dhcp_options_strings[default_config_options[i]]) < 0) { WARN_MESSAGE("could not dump options to file. I'm going to continue anyway."); fclose(fp); --- 99,103 ---- for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { ! if(fprintf(fp, "\"%s\"\n", dhcp_option_string_get(i)) < 0) { WARN_MESSAGE("could not dump options to file. I'm going to continue anyway."); fclose(fp); *************** *** 149,153 **** * we can just do a file_get_var_name() safely. */ ! if(string_matches(dhcp_options_strings[i], varfile_get_name(varfile))) { cc->options[i] = 1; match = 1; --- 149,153 ---- * we can just do a file_get_var_name() safely. */ ! if(string_matches(dhcp_option_string_get(i), varfile_get_name(varfile))) { cc->options[i] = 1; match = 1; Index: dhcp-options-strings.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-options-strings.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-options-strings.c 22 Nov 2002 15:30:38 -0000 1.4 *************** *** 27,31 **** #define MODULE_NAME "dhcp-option-strings" ! char *dhcp_options_strings[] = { "Pad", /* 0 */ "Subnet Mask", /* 1 */ --- 27,31 ---- #define MODULE_NAME "dhcp-option-strings" ! static char *dhcp_options_strings[] = { "Pad", /* 0 */ "Subnet Mask", /* 1 */ *************** *** 91,92 **** --- 91,97 ---- "Client ID", /* 61 */ }; + + const char *dhcp_option_string_get(int index) + { + return dhcp_options_strings[index]; + } Index: dhcp-options-strings.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-options-strings.h 16 Nov 2002 00:23:43 -0000 1.2 --- dhcp-options-strings.h 22 Nov 2002 15:30:38 -0000 1.3 *************** *** 26,30 **** #define DHCP_OPTION_STRINGS_H ! extern char *dhcp_options_strings[]; #endif /* DHCP_OPTION_STRINGS_H */ --- 26,30 ---- #define DHCP_OPTION_STRINGS_H ! extern const char *dhcp_option_string_get(int index); #endif /* DHCP_OPTION_STRINGS_H */ Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-sysconf.c 22 Nov 2002 00:53:17 -0000 1.6 --- dhcp-sysconf.c 22 Nov 2002 15:30:38 -0000 1.7 *************** *** 364,368 **** ce = list_ptr->data; ! if(string_matches(dhcp_options_strings[TAG_DHCP_REQUESTED_IP_ADDRESS], ce->name)) { data = --- 364,368 ---- ce = list_ptr->data; ! if(string_matches(dhcp_option_string_get(TAG_DHCP_REQUESTED_IP_ADDRESS), ce->name)) { data = *************** *** 376,380 **** } ! if(string_matches(dhcp_options_strings[TAG_DHCP_SUBNET_MASK], ce->name)) { data = option_convert_handlers[TAG_DHCP_SUBNET_MASK].serialize_to_internal(ce->value); --- 376,380 ---- } ! if(string_matches(dhcp_option_string_get(TAG_DHCP_SUBNET_MASK), ce->name)) { data = option_convert_handlers[TAG_DHCP_SUBNET_MASK].serialize_to_internal(ce->value); *************** *** 386,390 **** } ! if(string_matches(dhcp_options_strings[TAG_DHCP_INTERFACE_MTU], ce->name)) { data = option_convert_handlers[TAG_DHCP_INTERFACE_MTU].serialize_to_internal(ce->value); --- 386,390 ---- } ! if(string_matches(dhcp_option_string_get(TAG_DHCP_INTERFACE_MTU), ce->name)) { data = option_convert_handlers[TAG_DHCP_INTERFACE_MTU].serialize_to_internal(ce->value); *************** *** 418,422 **** void *data; cache_entry_t *ce; - unsigned char i; /* Clean up any config files we have. */ --- 418,421 ---- *************** *** 437,486 **** ce = list_ptr->data; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! ! if(string_matches(dhcp_options_strings[i], ce->name)) { ! ! /* Make sure we know how to setup this option. */ ! ! if(sysconf_handlers[i].setup == NULL || ! option_convert_handlers[i].serialize_to_internal == NULL) ! break; ! data = option_convert_handlers[i].serialize_to_internal(ce->value); ! /* Cleanup first, if we're supposed to. */ ! if(sysconf_handlers[i].cleanup != NULL && ! (sysconf_handlers[i].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_options_strings[i]); ! if(sysconf_handlers[i].cleanup(data, dc)) ! WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_options_strings[i]); ! } ! /* Now we can try to setup the option, and flag it for ! * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_options_strings[i]); ! if(sysconf_handlers[i].setup(data, dc)) { ! sysconf_handlers[i].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_options_strings[i]); ! } else { ! sysconf_handlers[i].flag |= SYSCONF_DO_CLEANUP; ! } ! option_convert_handlers[i].free_internal(data); - } - } } /* we don't need to worry about race conditions. * /etc should NOT be world writable! */ --- 436,480 ---- ce = list_ptr->data; ! /* Make sure we know how to setup this option. */ ! if(sysconf_handlers[ce->tag].setup == NULL || ! option_convert_handlers[ce->tag].serialize_to_internal == NULL) ! continue; ! data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); ! /* Cleanup first, if we're supposed to. */ ! if(sysconf_handlers[ce->tag].cleanup != NULL && ! (sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_option_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].cleanup(data, dc)) ! WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_string_get(ce->tag)); ! } ! /* Now we can try to setup the option, and flag it for ! * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_option_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].setup(data, dc)) { ! sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_option_string_get(ce->tag)); ! ! } else { ! sysconf_handlers[ce->tag].flag |= SYSCONF_DO_CLEANUP; ! } ! option_convert_handlers[ce->tag].free_internal(data); } + /* we don't need to worry about race conditions. * /etc should NOT be world writable! */ *************** *** 498,502 **** void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc) { - int i; void *data; cache_entry_t *ce; --- 492,495 ---- *************** *** 510,537 **** ce = list_ptr->data; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! ! ! if(string_matches(dhcp_options_strings[i], ce->name)) { ! ! /* Perform cleanup only if we're supposed to, and if there's a ! * cleanup function for the option. */ ! ! if(sysconf_handlers[i].flag & SYSCONF_DO_CLEANUP && ! sysconf_handlers[i].cleanup != NULL) { ! ! ! data = option_convert_handlers[i].serialize_to_internal(ce->value); ! INFO_MESSAGE("cleanup option: %s", dhcp_options_strings[i]); ! if(sysconf_handlers[i].cleanup(data, dc)) ! WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_options_strings[i]); ! option_convert_handlers[i].free_internal(data); ! } ! } } } --- 503,518 ---- ce = list_ptr->data; + if(sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP && + sysconf_handlers[ce->tag].cleanup != NULL) { ! data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); ! INFO_MESSAGE("cleanup option: %s", dhcp_option_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].cleanup(data, dc)) ! WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_string_get(ce->tag)); ! option_convert_handlers[ce->tag].free_internal(data); } } |
From: <act...@us...> - 2002-11-22 01:17:37
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv32403/src Modified Files: dhcp-client-cache.c Log Message: corrective measure for temporarily new cache file format Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-cache.c 22 Nov 2002 00:53:17 -0000 1.5 --- dhcp-client-cache.c 22 Nov 2002 01:17:34 -0000 1.6 *************** *** 369,373 **** } ! fprintf(fp, "\"%d\"=%s\n", opt->tag, val); xfree(val); } --- 369,373 ---- } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_options_strings[opt->tag]); xfree(val); } |
From: <act...@us...> - 2002-11-22 00:53:20
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv27754/src Modified Files: dhcp-client-cache.c dhcp-sysconf.c Log Message: fix to client cache not correctly reporting if its empty bug Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-cache.c 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-client-cache.c 22 Nov 2002 00:53:17 -0000 1.5 *************** *** 160,166 **** fname = get_fname(cc); if(file_exists(fname)) - retval = 1; - else retval = 0; xfree(fname); --- 160,166 ---- fname = get_fname(cc); if(file_exists(fname)) retval = 0; + else + retval = 1; xfree(fname); *************** *** 224,228 **** } ! /* load cache (interface) */ static int client_cache_load(client_cache_t *cc, unsigned char use_tmp) { --- 224,228 ---- } ! /* load cache */ static int client_cache_load(client_cache_t *cc, unsigned char use_tmp) { *************** *** 246,251 **** * Conversion work horses: * * * * * * * * * * * * * * */ ! ! /* convert to internal datums. */ static void *convert_to_internal(unsigned char tag, char *string) { --- 246,251 ---- * Conversion work horses: * * * * * * * * * * * * * * */ ! ! /* convert to internal datums. */ static void *convert_to_internal(unsigned char tag, char *string) { *************** *** 292,295 **** --- 292,303 ---- } + static void *convert_to_cache_entry(unsigned char tag, char *string) + { + cache_entry_t *ce; + + ce = create_cache_entry(dhcp_options_strings[tag], string); + return ce; + } + /* * Convert options from cache serialized form to whatever form convert_func, returns. *************** *** 302,307 **** list_t *options = NULL; list_t *cache; ! cache_entry_t *ce, *copy; ! unsigned char i; void *data; --- 310,314 ---- list_t *options = NULL; list_t *cache; ! cache_entry_t *ce; void *data; *************** *** 309,331 **** ce = cache->data; ! ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! ! if(string_matches(dhcp_options_strings[i], ce->name)) { ! ! if(convert_func) { ! data = convert_func(i, ce->value); ! if(data == NULL) ! break; /* break out of for loop since we have a match and we're ! * done even if we couldn't get the data. */ ! options = add_to_list(options, data); ! break; ! } else { ! copy = create_cache_entry(ce->name, ce->value); ! options = add_to_list(options, copy); ! break; ! } ! } } } --- 316,324 ---- ce = cache->data; ! data = convert_func(atoi(ce->name), ce->value); ! if(data != NULL) { /* we need to silently ignore nulls here so that the timer only converter works. */ ! options = add_to_list(options, data); } + } *************** *** 337,340 **** --- 330,334 ---- * file. the list should contain pointers to dhcp_option_t datums * in network byte order. */ + int client_cache_dump_options(client_cache_t *cc, list_t *options) { *************** *** 362,366 **** continue; - name = dhcp_options_strings[opt->tag]; val = option_convert_handlers[opt->tag].serialize(opt->data, opt->len); --- 356,359 ---- *************** *** 376,380 **** } ! fprintf(fp, "\"%s\"=%s\n", name, val); xfree(val); } --- 369,373 ---- } ! fprintf(fp, "\"%d\"=%s\n", opt->tag, val); xfree(val); } *************** *** 421,425 **** list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); } --- 414,418 ---- list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_cache_entry)); } Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-sysconf.c 19 Nov 2002 19:44:44 -0000 1.5 --- dhcp-sysconf.c 22 Nov 2002 00:53:17 -0000 1.6 *************** *** 188,191 **** --- 188,195 ---- }; + /* * * * * * * * * * * * * * * * * * * * + * Sysconf functions. These do setup. * + * * * * * * * * * * * * * * * * * * * */ + static int client_setup_lease_time(void *value, dhcp_client_control_t *dc) { *************** *** 405,409 **** } ! /* XXX - handle return value elsewhere. */ void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface) { --- 409,416 ---- } ! /* * * * * * * * * * * * ! * Sysconf interface. * ! * * * * * * * * * * * */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface) { |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv17456/src Modified Files: Makefile.am dhcp-client-cache.c dhcp-client-cache.h dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-com.c dhcp-librawnet.h dhcp-libutil.h dhcp-sysconf.c dhcp-sysconf.h dhcp-timer.c Log Message: fixed timers; fixed up client-cache a bit Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 15 Nov 2002 21:06:47 -0000 1.7 --- Makefile.am 19 Nov 2002 19:44:43 -0000 1.8 *************** *** 60,64 **** dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ --- 60,64 ---- dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil -lefence dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-cache.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-client-cache.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 36,41 **** #include "dhcp-options-strings.h" /* constructor. */ ! client_cache_t *create_client_cache(const char *interface) { client_cache_t *cc; --- 36,45 ---- #include "dhcp-options-strings.h" + /* * * * * * * * * * * * * * * * * * + * Destroy/Create/Purge routines. * + * * * * * * * * * * * * * * * * * */ + /* constructor. */ ! client_cache_t *client_cache_create(const char *interface) { client_cache_t *cc; *************** *** 48,53 **** } /* purges list in cache object. */ ! void purge_cache(client_cache_t *cc) { list_t *list_ptr, *tmp; --- 52,58 ---- } + /* FIXME: make it use destroy_list. */ /* purges list in cache object. */ ! void client_cache_purge(client_cache_t *cc) { list_t *list_ptr, *tmp; *************** *** 73,77 **** { if(cc->vars) ! purge_cache(cc); xfree(cc); --- 78,82 ---- { if(cc->vars) ! client_cache_purge(cc); xfree(cc); *************** *** 79,82 **** --- 84,176 ---- } + /* * * * * * * * * * * * * * * + * Cache Filename Routines. * + * * * * * * * * * * * * * * */ + + static char *get_fname_proc(const client_cache_t *cc, const char *suffix) + { + char *fname; + stringbuffer *sb = create_stringbuffer(); + stringbuffer_aprintf(sb, "%s.%s", cc->interface, suffix); + + fname = xstrdup(stringbuffer_getstring(sb)); /* FIXME: use a stringbuffer associated creation routine. */ + destroy_stringbuffer(sb); + + return fname; + } + + static char *get_fname(const client_cache_t *cc) + { + return (get_fname_proc(cc, "cache")); + } + + static char *get_fname_tmp(client_cache_t *cc) + { + return (get_fname_proc(cc, "cache.tmp")); + } + + /* * * * * * * * * * * * + * Cache Manipulation * + * * * * * * * * * * * */ + + /* update cache: move temp cache over real cache. */ + void client_cache_update(client_cache_t *cc) + { + char *fname_tmp, *fname; + + fname_tmp = get_fname_tmp(cc); + fname = get_fname(cc); + + move_file(fname_tmp, fname); + + xfree(fname); + xfree(fname_tmp); + + return; + } + + /* delete old temporary cache. */ + void client_cache_delete_tmp_cache(client_cache_t *cc) + { + char *fname = get_fname_tmp(cc); + + delete_file(fname); + xfree(fname); + + return; + } + + /* delete cache. */ + void client_cache_delete_cache(client_cache_t *cc) + { + char *fname = get_fname(cc); + + delete_file(fname); + xfree(fname); + + return; + } + + /* check if cache is empty. */ + int client_cache_is_empty(client_cache_t *cc) + { + int retval; + char *fname; + + fname = get_fname(cc); + if(file_exists(fname)) + retval = 1; + else + retval = 0; + + xfree(fname); + + return retval; + } + + /* * * * * * * * * * * + * Cache load/dump * + * * * * * * * * * * */ + /* read next cache entry from file. */ static cache_entry_t *read_next_cache_var(varfile_t *varfile) *************** *** 108,113 **** } ! /* Load up cache from filename. */ ! static int load_client_cache_proc(client_cache_t *cc, char *filename) { varfile_t *varfile; --- 202,207 ---- } ! /* Load up cache from file named by filename. */ ! static int client_cache_load_proc(client_cache_t *cc, char *filename) { varfile_t *varfile; *************** *** 130,165 **** } - /* filename creation routines. */ - static char *get_fname(client_cache_t *cc) - { - char *fname; - stringbuffer *sb = create_stringbuffer(); - stringbuffer_aprintf(sb, "%s.%s", cc->interface, "cache"); - - fname = xstrdup(stringbuffer_getstring(sb)); - destroy_stringbuffer(sb); - - return fname; - } - - static char *get_fname_tmp(client_cache_t *cc) - { - char *fname; - stringbuffer *sb = create_stringbuffer(); - stringbuffer_aprintf(sb, "%s.%s", cc->interface, "cache.tmp"); - - fname = xstrdup(stringbuffer_getstring(sb)); - destroy_stringbuffer(sb); - - return fname; - } - /* load cache (interface) */ ! int load_client_cache(client_cache_t *cc, unsigned char use_tmp) { char *fname; int retval; ! purge_cache(cc); if(use_tmp) --- 224,234 ---- } /* load cache (interface) */ ! static int client_cache_load(client_cache_t *cc, unsigned char use_tmp) { char *fname; int retval; ! client_cache_purge(cc); if(use_tmp) *************** *** 168,172 **** fname = get_fname(cc); ! retval = load_client_cache_proc(cc, fname); xfree(fname); --- 237,241 ---- fname = get_fname(cc); ! retval = client_cache_load_proc(cc, fname); xfree(fname); *************** *** 174,199 **** } ! /* check to see if cache is empty: ! * as long as the cache file exists ! * we're always guaranteed a cache ! * except on filesystem corruption. ! * in that case we can't do much except ! * complain. using file_exists() is ! * as good as it gets. ! */ ! int client_cache_is_empty(client_cache_t *cc) ! { ! int retval = 0; ! char *fname; ! ! fname = get_fname(cc); ! if(file_exists(fname)) ! retval = 1; ! xfree(fname); ! return retval; } ! /* work horse routine to convert from serialized state to network datum. */ static void *convert_to_network(unsigned char tag, char *string) { --- 243,257 ---- } ! /* * * * * * * * * * * * * * ! * Conversion work horses: * ! * * * * * * * * * * * * * */ ! /* convert to internal datums. */ ! static void *convert_to_internal(unsigned char tag, char *string) ! { ! return NULL; } ! /* convert to network. */ static void *convert_to_network(unsigned char tag, char *string) { *************** *** 218,221 **** --- 276,295 ---- } + /* convert only timer options to serialized form. */ + static void *convert_timers_to_string(unsigned char tag, char *string) + { + cache_entry_t *ce; + + /* we have three timers we care about */ + if(tag == TAG_DHCP_IP_ADDRESS_LEASE_TIME || + tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { + + ce = create_cache_entry(dhcp_options_strings[tag], string); + return ce; + } + + return NULL; + } + /* * Convert options from cache serialized form to whatever form convert_func, returns. *************** *** 259,265 **** } ! /* dump options into file. here we take data in network form and dump them in serialized form. ! * we always do this to the temp file. ! */ int client_cache_dump_options(client_cache_t *cc, list_t *options) { --- 333,340 ---- } ! /* dump options into file. here we take data in network form and ! * dump them in serialized form. we always do this to the temp ! * file. the list should contain pointers to dhcp_option_t datums ! * in network byte order. */ int client_cache_dump_options(client_cache_t *cc, list_t *options) { *************** *** 309,313 **** } ! /* work horse load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void *(*convert_func) (unsigned char tag, --- 384,388 ---- } ! /* work horse load options and convert routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, void *(*convert_func) (unsigned char tag, *************** *** 317,329 **** list_t *options; ! if(load_client_cache(cc, use_tmp) < 0) return NULL; options = get_cache_options_list_proc(cc, convert_func); ! purge_cache(cc); return options; } /* load options and return network list. */ list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) --- 392,409 ---- list_t *options; ! if(client_cache_load(cc, use_tmp) < 0) return NULL; options = get_cache_options_list_proc(cc, convert_func); ! client_cache_purge(cc); return options; } + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Main conversion interface. These routines will load, convert, * + * and return the options in whichever format we want. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + /* load options and return network list. */ list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) *************** *** 332,376 **** } ! /* load options and return serialized list. */ ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) ! { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); ! } ! ! /* update cache: move temp cache over real cache. */ ! void client_cache_update(client_cache_t *cc) { ! char *fname_tmp, *fname; ! ! fname_tmp = get_fname_tmp(cc); ! fname = get_fname(cc); ! ! move_file(fname_tmp, fname); ! ! xfree(fname); ! xfree(fname_tmp); ! ! return; } ! /* delete old temporary cache. */ ! void client_cache_delete_tmp_cache(client_cache_t *cc) { ! char *fname = get_fname_tmp(cc); ! ! delete_file(fname); ! xfree(fname); ! ! return; } ! /* delete cache. */ ! void client_cache_delete_cache(client_cache_t *cc) { ! char *fname = get_fname(cc); ! ! delete_file(fname); ! xfree(fname); ! ! return; } --- 412,430 ---- } ! /* load options and return internal datum list. */ ! list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_internal)); } ! /* load options and return serialized list. */ ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); } ! /* load timer options and return them in internal list. */ ! list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_timers_to_string)); } Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-cache.h 16 Nov 2002 00:23:42 -0000 1.2 --- dhcp-client-cache.h 19 Nov 2002 19:44:44 -0000 1.3 *************** *** 34,48 **** /* prototypes. */ ! extern client_cache_t *create_client_cache(const char *interface); ! extern void purge_cache(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); ! extern int load_client_cache(client_cache_t *cc, unsigned char use_tmp); extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); ! extern void client_cache_update(client_cache_t *cc); ! extern void client_cache_delete_tmp_cache(client_cache_t *cc); ! extern void client_cache_delete_cache(client_cache_t *cc); #endif /* DHCP_CLIENT_CACHE_H */ --- 34,50 ---- /* prototypes. */ ! extern client_cache_t *client_cache_create(const char *interface); ! extern void client_cache_purge(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); ! extern void client_cache_update(client_cache_t *cc); ! extern void client_cache_delete_tmp_cache(client_cache_t *cc); ! extern void client_cache_delete_cache(client_cache_t *cc); extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); + extern list_t *client_cache_load_option_internal_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); ! extern list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, ! unsigned char use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-conf.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-client-conf.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 23,26 **** --- 23,28 ---- */ + /* THIS ENTIRE THING NEEDS TO BE REDONE. */ + #define MODULE_NAME "dhcp-client-conf" *************** *** 215,217 **** --- 217,225 ---- return (retval); + } + + /* return the bit array indexing the options we want. */ + uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) + { + return cc->options; } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-conf.h 16 Nov 2002 00:23:42 -0000 1.2 --- dhcp-client-conf.h 19 Nov 2002 19:44:44 -0000 1.3 *************** *** 40,43 **** --- 40,44 ---- extern void client_conf_destroy(client_conf_t *cc); extern int load_client_conf(client_conf_t *cc); + extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-control.c 16 Nov 2002 00:23:42 -0000 1.4 --- dhcp-client-control.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 140,154 **** dc->interface = xstrdup(interface); dc->conf = create_client_conf(dc->interface); ! dc->cache = create_client_cache(dc->interface); dc->timer = create_timer(); if(load_client_conf(dc->conf) < 0) { ERROR_MESSAGE("could not read client conf."); - destroy_dhcp_client_control(dc); - return NULL; - } - - if(load_client_cache(dc->cache, 0) < 0) { - ERROR_MESSAGE("could not read client cache."); destroy_dhcp_client_control(dc); return NULL; --- 140,148 ---- dc->interface = xstrdup(interface); dc->conf = create_client_conf(dc->interface); ! dc->cache = client_cache_create(dc->interface); dc->timer = create_timer(); if(load_client_conf(dc->conf) < 0) { ERROR_MESSAGE("could not read client conf."); destroy_dhcp_client_control(dc); return NULL; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-states.c 16 Nov 2002 00:23:42 -0000 1.4 --- dhcp-client-states.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 62,67 **** } /* This is used for both requests and discovery. */ ! static list_t *client_build_option_list(unsigned char *opts, dhcp_client_control_t *dc) { list_t *options = NULL; --- 62,75 ---- } + static dhcp_option_t *client_build_parameter_request_list(dhcp_client_control_t *dc) + { + dhcp_option_t *option; + + option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); + return option; + } + /* This is used for both requests and discovery. */ ! static list_t *client_build_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 69,78 **** char *hostname; - if(opts != NULL) { - /* parameter_request_list */ - option = dhcp_build_parameter_request_list_option(opts); - options = add_to_list(options, option); - } - /* dhcp max DHCP message size: * should go into globconf. */ --- 77,80 ---- *************** *** 100,104 **** /* Create DHCP DISCOVER option list. */ ! static list_t *client_build_discover_option_list(unsigned char *opts, dhcp_client_control_t *dc) { list_t *options = NULL; --- 102,106 ---- /* Create DHCP DISCOVER option list. */ ! static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 106,114 **** dhcp_option_t *option; /* dhcp message type. */ option = dhcp_build_message_type(DHCP_DISCOVER_TM); options = add_to_list(options, option); ! requested_options = client_build_option_list(opts, dc); options = join_lists(options, requested_options); --- 108,119 ---- dhcp_option_t *option; + option = client_build_parameter_request_list(dc); + options = add_to_list(options, option); + /* dhcp message type. */ option = dhcp_build_message_type(DHCP_DISCOVER_TM); options = add_to_list(options, option); ! requested_options = client_build_option_list(dc); options = join_lists(options, requested_options); *************** *** 117,121 **** /* Create DHCP REQUEST option list. */ ! static list_t *client_build_request_option_list(unsigned char *opts, dhcp_client_control_t *dc) { list_t *options = NULL; --- 122,126 ---- /* Create DHCP REQUEST option list. */ ! static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { list_t *options = NULL; *************** *** 127,131 **** options = add_to_list(options, option); ! requested_options = client_build_option_list(opts, dc); options = join_lists(options, requested_options); --- 132,136 ---- options = add_to_list(options, option); ! requested_options = client_build_option_list(dc); options = join_lists(options, requested_options); *************** *** 133,136 **** --- 138,162 ---- } + /* Create DHCP REBIND option list. */ + static list_t *client_build_renew_option_list(dhcp_client_control_t *dc) + { + list_t *options = NULL; + dhcp_option_t *option; + + /* dhcp message type. */ + option = dhcp_build_message_type(DHCP_REQUEST_TM); + options = add_to_list(options, option); + + /* client_id */ + option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); + options = add_to_list(options, option); + + return options; + } + + /****************** + * Check Routines * + ******************/ + /* Check the requested options. * We use the globconf option. */ *************** *** 156,163 **** } - /****************** - * Check Routines * - ******************/ - /* Basic DHCP test on incoming rawnet packet. */ static int client_check_dhcp(dhcp_client_control_t *dc) --- 182,185 ---- *************** *** 206,209 **** --- 228,238 ---- } + static int client_check_renew(void *arg) + { + /* we're expecting the same as request :-) */ + return (client_check_request(arg)); + + } + /************* * Utilities.* *************** *** 220,223 **** --- 249,270 ---- } + static void client_setup_timers(dhcp_client_control_t *dc) + { + list_t *timer_options; + + timer_options = client_cache_load_option_timer_string_list(dc->cache, 0); + + if(timer_options == NULL) { + FATAL_MESSAGE("no timers to setup. we should have least one: lease time"); + exit(1); + } + + reinitialize_timer(dc->timer); + do_sysconf(timer_options, dc, 0); + cache_entry_purge_list(timer_options); + + return; + } + /************* * ARP/UNARP.* *************** *** 276,280 **** int retval; ! options = client_build_discover_option_list(dc->conf->options, dc); /* when we begin transmitting discover_offer we setup our secs field. --- 323,327 ---- int retval; ! options = client_build_discover_option_list(dc); /* when we begin transmitting discover_offer we setup our secs field. *************** *** 346,350 **** /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(NULL, dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); --- 393,397 ---- /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); *************** *** 368,372 **** case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); return STATE_FATAL_ERROR; --- 415,419 ---- case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP request."); return STATE_FATAL_ERROR; *************** *** 449,453 **** */ ! do_sysconf(options, dc); cache_entry_purge_list(options); --- 496,500 ---- */ ! do_sysconf(options, dc, 1); cache_entry_purge_list(options); *************** *** 459,463 **** } ! /* wait for renewal time. */ int client_wait(dhcp_client_control_t *dc) { --- 506,510 ---- } ! /* wait for timers and other interrupts . */ int client_wait(dhcp_client_control_t *dc) { *************** *** 476,490 **** suspend_for_interrupts(); ! rawnet_up(dc->rawnet); ! ! /* Update our DHCP secs datum since we're renewing after this. */ ! dhcp_client_reset_secs(dc); ! dhcp_client_update_secs(dc); ! return STATE_REQUEST_ACK; /* if we didn't get an ALARM it's ! * probably a HUP or a TERM. in ! * either case we can return ! * STATE_REQUEST_ACK here. */ } --- 523,537 ---- suspend_for_interrupts(); ! /* bring the raw network devices back up. we'll probably ! * need them: FIXME, revamp into one network module that uses ! * raw or user level networking depending on our interface's ! * state */ ! rawnet_up(dc->rawnet); ! return STATE_FATAL_ERROR; /* it doesn't matter what we return here really. ! * since we're supposed to detect an interrupt ! * as soon as we get back. set as fatal error ! * to catch any bugs. */ } *************** *** 518,520 **** --- 565,608 ---- exit(0); + } + + /* do a rebind. */ + int client_renew(dhcp_client_control_t *dc) + { + list_t *options; + int retval; + options = client_build_renew_option_list(dc); + + build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->sip_addr, dc->shw_addr); + + retval = + rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_renew, RECOMMENDED_MAX_SECS_WAIT); + switch (retval) { + + case RAWNET_TIMEOUT: + ERROR_MESSAGE("timeout on DHCP request."); + return STATE_FATAL_ERROR; + + case RAWNET_OK: + break; + + case RAWNET_ERROR: + ERROR_MESSAGE("received error from raw network handler."); + return STATE_FATAL_ERROR; + + default: + FATAL_MESSAGE + ("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); + } + + /* if we got a pack we only need to setup our timers. */ + if(dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM)) { + client_setup_timers(dc); + } + + /* in the end we return to waiting. if we didn't get an ACK + * here we'll fall into rebind time at the next timer + * trigger. */ + + return STATE_WAIT; } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client.c 16 Nov 2002 00:23:42 -0000 1.5 --- dhcp-client.c 19 Nov 2002 19:44:44 -0000 1.6 *************** *** 83,91 **** client_wait, client_release, client_fatal_error, client_do_shutdown, }; - /* global vars affecting other code. */ int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ --- 83,91 ---- client_wait, client_release, + client_renew, client_fatal_error, client_do_shutdown, }; /* global vars affecting other code. */ int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ *************** *** 239,245 **** --- 239,249 ---- case INTERRUPT_ALARM: + switch (timer_get_current_id(dc->timer)) { case TIMER_RENEW: + state = STATE_RENEW; + break; + case TIMER_IP_LEASE: state = STATE_DISCOVER_OFFER; *************** *** 249,254 **** state = STATE_REQUEST_ACK; break; - } default: --- 253,261 ---- state = STATE_REQUEST_ACK; break; + default: + FATAL_MESSAGE("invalid timer type caught. this is a bug. report me."); + } + break; default: *************** *** 333,337 **** /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc->interface); /* now delete. */ --- 340,344 ---- /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = client_cache_create(dc->interface); /* now delete. */ Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client.h 16 Nov 2002 00:23:43 -0000 1.4 --- dhcp-client.h 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 69,74 **** #define STATE_WAIT 3 #define STATE_RELEASE 4 ! #define STATE_FATAL_ERROR 5 ! #define STATE_DO_SHUTDOWN 6 /* timer IDs. */ --- 69,76 ---- #define STATE_WAIT 3 #define STATE_RELEASE 4 ! #define STATE_RENEW 5 ! #define STATE_FATAL_ERROR 6 ! #define STATE_DO_SHUTDOWN 7 ! /* timer IDs. */ *************** *** 83,86 **** --- 85,89 ---- extern int client_wait(dhcp_client_control_t *dc); extern int client_release(dhcp_client_control_t *dc); + extern int client_renew(dhcp_client_control_t *dc); extern int client_setup(dhcp_client_control_t *dc); extern int client_fatal_error(dhcp_client_control_t *dc); Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-com.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-com.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 514,518 **** /* accept bit array telling us which options to build the request option. */ ! dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options) { unsigned char i, j; --- 514,518 ---- /* accept bit array telling us which options to build the request option. */ ! dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options) { unsigned char i, j; Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-librawnet.h 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-librawnet.h 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 435,439 **** extern uint32_t dhcp_gen_xid(void); ! extern dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options); extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); extern dhcp_option_t *dhcp_build_message_type(unsigned char type); --- 435,439 ---- extern uint32_t dhcp_gen_xid(void); ! extern dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options); extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); extern dhcp_option_t *dhcp_build_message_type(unsigned char type); *************** *** 443,446 **** --- 443,447 ---- extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); extern dhcp_option_t *dhcp_build_hostname(char *hostname); + /* Ether obj routines. */ Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-libutil.h 16 Nov 2002 00:23:43 -0000 1.6 --- dhcp-libutil.h 19 Nov 2002 19:44:44 -0000 1.7 *************** *** 193,196 **** --- 193,197 ---- extern int timer_purge(timer_keeper_t); extern uint32_t timer_get_current_id(timer_keeper_t *timer); + extern void reinitialize_timer(timer_keeper_t *timer); /* var file. */ Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sysconf.c 16 Nov 2002 00:23:44 -0000 1.4 --- dhcp-sysconf.c 19 Nov 2002 19:44:44 -0000 1.5 *************** *** 42,45 **** --- 42,54 ---- #include "dhcp-options-strings.h" + + static int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); + static int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); + static int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); + static int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); + static int client_setup_lease_time(void *value, dhcp_client_control_t *dc); + static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc); + static int client_setup_renew_time(void *value, dhcp_client_control_t *dc); + /* Only use handlers here which can be done in any order. * Some special handlers are done in a particular order *************** *** 155,167 **** {NULL, NULL, SYSCONF_UNSET,} , /* 50 Requested IP Address. */ ! {sysconf_setup_lease_time, ! NULL, SYSCONF_UNSET,} , /* 51 IP Address Lease Time. */ ! {sysconf_setup_renew_time, ! NULL, SYSCONF_UNSET,} ! , /* 52 Renewal Time (T1). */ ! {sysconf_setup_rebind_time, ! NULL, SYSCONF_UNSET,} ! , /* 53 Rebind Time. (T2). */ {NULL, NULL, SYSCONF_UNSET,} , /* 54 */ --- 164,173 ---- {NULL, NULL, SYSCONF_UNSET,} , /* 50 Requested IP Address. */ ! {client_setup_lease_time, NULL, SYSCONF_UNSET,} , /* 51 IP Address Lease Time. */ ! {NULL, SYSCONF_UNSET,} ! , /* 52 */ ! {NULL, SYSCONF_UNSET,} ! , /* 53 */ {NULL, NULL, SYSCONF_UNSET,} , /* 54 */ *************** *** 172,179 **** {NULL, NULL, SYSCONF_UNSET,} , /* 57 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 58 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 59 */ {NULL, NULL, SYSCONF_UNSET,} , /* 60 */ --- 178,185 ---- {NULL, NULL, SYSCONF_UNSET,} , /* 57 */ ! {client_setup_renew_time, NULL, SYSCONF_UNSET,} ! , /* 58 Renewal Time (T1). */ ! {client_setup_rebind_time, NULL, SYSCONF_UNSET,} ! , /* 59 Rebind Time (T2). */ {NULL, NULL, SYSCONF_UNSET,} , /* 60 */ *************** *** 182,212 **** }; ! static int sysconf_setup_u32_timer(uint32_t seconds, int id, dhcp_client_control_t *dc) ! { ! timer_add_trigger(dc->timer, seconds, id); ! return 0; ! } ! ! int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_IP_LEASE, dc); return 0; } ! int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_REBIND, dc); return 0; } ! int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc) { ! uint32_t seconds = *(uint32_t *)value; ! sysconf_setup_u32_timer(seconds, TIMER_RENEW, dc); return 0; } --- 188,212 ---- }; ! static int client_setup_lease_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_IP_LEASE); return 0; } ! static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_REBIND); return 0; } ! static int client_setup_renew_time(void *value, dhcp_client_control_t *dc) { ! uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_RENEW); return 0; } *************** *** 406,410 **** /* XXX - handle return value elsewhere. */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc) { list_t *list_ptr; --- 406,410 ---- /* XXX - handle return value elsewhere. */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface) { list_t *list_ptr; *************** *** 420,424 **** * is likely required for the others to work. */ ! sysconf_setup_interface(options, dc); /* Now walk through the other options, performing setup and --- 420,425 ---- * is likely required for the others to work. */ ! if(do_interface) ! sysconf_setup_interface(options, dc); /* Now walk through the other options, performing setup and Index: dhcp-sysconf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-sysconf.h 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-sysconf.h 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 40,51 **** /* System configuration routines. */ ! extern int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); --- 40,44 ---- /* System configuration routines. */ ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-timer.c 15 Nov 2002 21:06:47 -0000 1.3 --- dhcp-timer.c 19 Nov 2002 19:44:44 -0000 1.4 *************** *** 37,49 **** static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { ! uint32_t *trigger1, *trigger2; trigger1 = trigger1_p; trigger2 = trigger2_p; ! if(trigger1 > trigger2) return 1; ! if(trigger1 < trigger2) return -1; --- 37,49 ---- static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { ! timer_trigger_t *trigger1, *trigger2; trigger1 = trigger1_p; trigger2 = trigger2_p; ! if(trigger1->seconds > trigger2->seconds) return 1; ! if(trigger1->seconds < trigger2->seconds) return -1; *************** *** 51,54 **** --- 51,77 ---- } + /* create a new trigger. */ + static timer_trigger_t *create_trigger(uint32_t trigger_time, uint32_t id) + { + timer_trigger_t *trigger = xmalloc(sizeof(timer_trigger_t)); + + trigger->seconds = trigger_time; + trigger->id = id; + + return trigger; + } + + /* destroy a trigger. */ + static void destroy_trigger(timer_trigger_t *trigger) + { + xfree(trigger); + } + + /* destroy a trigger in a list. */ + static void destroy_trigger_l(void *trigger) + { + destroy_trigger(trigger); + } + /* create a new timer keeper. */ timer_keeper_t *create_timer(void) *************** *** 65,69 **** void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, NULL); xfree(timer); --- 88,92 ---- void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, destroy_trigger_l); xfree(timer); *************** *** 71,82 **** } /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time, uint32_t id) { ! timer_trigger_t *trigger = xmalloc(sizeof(timer_trigger_t)); ! ! trigger->seconds = trigger_time; ! trigger->id = id; ! timer->triggers = add_to_list(timer->triggers, trigger); --- 94,107 ---- } + void reinitialize_timer(timer_keeper_t *timer) + { + purge_list(timer->triggers, NULL); + timer->triggers = NULL; + } + /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time, uint32_t id) { ! timer_trigger_t *trigger = create_trigger(trigger_time, id); timer->triggers = add_to_list(timer->triggers, trigger); *************** *** 99,103 **** timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); ! xfree(trigger); return 0; --- 124,128 ---- timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); ! destroy_trigger(trigger); return 0; |
From: <act...@us...> - 2002-11-19 19:44:46
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv17456 Modified Files: TODO Log Message: fixed timers; fixed up client-cache a bit Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TODO 29 Oct 2002 17:11:02 -0000 1.1.1.1 --- TODO 19 Nov 2002 19:44:43 -0000 1.2 *************** *** 99,108 **** -- apply only to a specific interface. - -- existing tests will need to be linked in with autotest when it becomes - real in autoconf. right now use the current system of building - and running them as make test - -- change uint32_t to ip_addr_t for ipv4 addresses. -- make it so set/get methods in all packeting routines do network type conversions and not higher level functions --- 99,107 ---- -- apply only to a specific interface. -- change uint32_t to ip_addr_t for ipv4 addresses. -- make it so set/get methods in all packeting routines do network type conversions and not higher level functions + + -- conversion routines are taking too long to access. walks + through the table can be shortened by direct indexing. |
From: <act...@us...> - 2002-11-16 00:24:14
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv31010 Modified Files: .cvsignore Added Files: .indent.pro doindent.sh Log Message: now with automatic indentation --- NEW FILE: .indent.pro --- /* basically use K&R style */ -kr /* line continuation options */ -lp /* indenting options */ -i4 -nut /* blank lines */ -nsob /* spacing at for,while,if... */ -nsaf -nsai -nsaw /* other stuff */ -nbs -ncs -npcs -c1 -ts1 -l100 /* typedefs */ -T uint32_t -T uint16_t -T uint8_t -T int32_t -T int16_t -T int8_t -T list_t -T cache_entry_t -T client_cache_t -T client_conf_t -T ip_addr_t -T eth_addr_t -T dhcp_client_control_t -T glob_conf_t -T interface_control_t -T dhcp_option_t -T rawnet_t -T rtt_t -T timer_trigger_t -T timer_keeper_t -T parser_t -T varfile_t -T token_t -T atom_t --- NEW FILE: doindent.sh --- #!/bin/sh # # $Header: /cvsroot/dhcp-agent/dhcp-agent/doindent.sh,v 1.1 2002/11/16 00:23:41 actmodern Exp $ # Walk through subdirs and indent files. export INDENT_PROFILE=`pwd`/.indent.pro subdirs=src for dir in $subdirs; do cd $dir list=`ls | grep '\.[ch]$'` for i in $list; do indent $i; done; cd .. done; Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/.cvsignore,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** .cvsignore 30 Oct 2002 04:56:04 -0000 1.3 --- .cvsignore 16 Nov 2002 00:23:41 -0000 1.4 *************** *** 8,9 **** --- 8,10 ---- stamp-h1 config.guess config.sub ltmain.sh + .indent.pro doindent.sh |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv31010/src Modified Files: dhcp-align.c dhcp-align.h dhcp-arp-discovery.c dhcp-arp.c dhcp-cache-entry.c dhcp-cache-entry.h dhcp-client-cache.c dhcp-client-cache.h dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-com.c dhcp-convert.c dhcp-convert.h dhcp-daemon.c dhcp-daemon.h dhcp-eth.c dhcp-files.c dhcp-globconf.c dhcp-globconf.h dhcp-icmp-discovery.c dhcp-icmp.c dhcp-interface.c dhcp-interface.h dhcp-interrupt.c dhcp-ip.c dhcp-librawnet.h dhcp-libutil.h dhcp-limits.h dhcp-list.c dhcp-local.h dhcp-log.c dhcp-log.h dhcp-options-strings.c dhcp-options-strings.h dhcp-packet-build.c dhcp-parser.c dhcp-parser.h dhcp-print.c dhcp-print.h dhcp-rawnet.c dhcp-route.c dhcp-rtt.c dhcp-sniff.c dhcp-sniffer-ohandlers.c dhcp-snprintf.c dhcp-stringbuffer.c dhcp-sysconf.c dhcp-sysconf.h dhcp-udp.c dhcp-util.c dhcp-varfile.c Log Message: now with automatic indentation Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-align.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-align.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 40,44 **** { unsigned char vhl; ! vhl = *data; --- 40,44 ---- { unsigned char vhl; ! vhl = *data; *************** *** 104,109 **** } ! void align_dhcphdr(const unsigned char *data, ! dhcphdr *dhcp) { memcpy(&dhcp->op, data, sizeof(dhcp->op)); --- 104,108 ---- } ! void align_dhcphdr(const unsigned char *data, dhcphdr * dhcp) { memcpy(&dhcp->op, data, sizeof(dhcp->op)); *************** *** 155,164 **** memcpy(&header->eth_dst, data, ETH_ADDR_LEN); data += ETH_ADDR_LEN; ! memcpy(&header->eth_src, data, ETH_ADDR_LEN); data += ETH_ADDR_LEN; ! memcpy(&header->eth_type, data, ETH_TYPE_LEN); ! return; } --- 154,163 ---- memcpy(&header->eth_dst, data, ETH_ADDR_LEN); data += ETH_ADDR_LEN; ! memcpy(&header->eth_src, data, ETH_ADDR_LEN); data += ETH_ADDR_LEN; ! memcpy(&header->eth_type, data, ETH_TYPE_LEN); ! return; } Index: dhcp-align.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-align.h 10 Nov 2002 15:46:40 -0000 1.1 --- dhcp-align.h 16 Nov 2002 00:23:42 -0000 1.2 *************** *** 29,33 **** extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); extern void align_udp(const unsigned char *data, struct udp_hdr *udp); ! extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); extern void align_eth(const unsigned char *data, struct eth_hdr *header); extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); --- 29,33 ---- extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); extern void align_udp(const unsigned char *data, struct udp_hdr *udp); ! extern void align_dhcphdr(const unsigned char *data, dhcphdr * dhcp); extern void align_eth(const unsigned char *data, struct eth_hdr *header); extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); *************** *** 37,39 **** extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); ! #endif /* DHCP_ALIGN_H */ --- 37,39 ---- extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); ! #endif /* DHCP_ALIGN_H */ Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp-discovery.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-arp-discovery.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-arp-discovery.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 68,72 **** } ! int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr) { list_t *arg_list = NULL; --- 68,73 ---- } ! int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, ! eth_addr_t *mac_addr) { list_t *arg_list = NULL; *************** *** 80,123 **** * hardware address so we get a reply back. */ ! build_arp_request(net, net->cip_addr, address, net->chw_addr); while(retries--) { ! retval = rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply, RECOMMENDED_MAX_SECS_WAIT); ! switch(retval) { ! case RAWNET_TIMEOUT: ! /* we timed out. retry. */ ! break; ! case RAWNET_OK: ! ! /* Yummy! We got a valid reply! */ ! ! sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); ! /* just free up pair. FIXME: this isn't good because we're ! * breaking the list blackbox. we need a better way to do this. ! * the datums don't need to be freed since we keep them on the stack. */ ! xfree(arg_list->next); ! xfree(arg_list); ! return 0; ! case RAWNET_ERROR: ! /* wops error. this is bad. */ ! ERROR_MESSAGE("received error from raw network handler."); ! return 1; default: /* not good. */ FATAL_MESSAGE("invalid return from rawnet_transact. this a bug report it."); ! } } ! /* FIXME: ditto (see above) */ xfree(arg_list->next); --- 81,126 ---- * hardware address so we get a reply back. */ ! build_arp_request(net, net->cip_addr, address, net->chw_addr); while(retries--) { ! retval = ! rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply, ! RECOMMENDED_MAX_SECS_WAIT); ! switch (retval) { ! case RAWNET_TIMEOUT: ! /* we timed out. retry. */ ! break; ! case RAWNET_OK: ! /* Yummy! We got a valid reply! */ ! sender_addr = arp_get_sender_hardware_address(net->arp_p); ! memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); ! /* just free up pair. FIXME: this isn't good because we're ! * breaking the list blackbox. we need a better way to do this. ! * the datums don't need to be freed since we keep them on the stack. */ ! xfree(arg_list->next); ! xfree(arg_list); ! ! return 0; ! ! case RAWNET_ERROR: ! /* wops error. this is bad. */ ! ERROR_MESSAGE("received error from raw network handler."); ! return 1; default: /* not good. */ FATAL_MESSAGE("invalid return from rawnet_transact. this a bug report it."); ! } } ! /* FIXME: ditto (see above) */ xfree(arg_list->next); Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-arp.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-arp.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 35,46 **** { arp_obj *arp; ! arp = xmalloc(sizeof(arp_obj)); ! return arp; } /* destructor */ ! void arp_destroy(arp_obj *arp) { xfree(arp); --- 35,46 ---- { arp_obj *arp; ! arp = xmalloc(sizeof(arp_obj)); ! return arp; } /* destructor */ ! void arp_destroy(arp_obj * arp) { xfree(arp); *************** *** 49,53 **** /* set routines. */ ! void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr) { arp->header.ar_hrd = htons(hdr_addr); --- 49,53 ---- /* set routines. */ ! void arp_set_hardware_type(arp_obj * arp, uint16_t hdr_addr) { arp->header.ar_hrd = htons(hdr_addr); *************** *** 55,59 **** } ! void arp_set_protocol_type(arp_obj *arp, uint16_t pro) { arp->header.ar_pro = htons(pro); --- 55,59 ---- } ! void arp_set_protocol_type(arp_obj * arp, uint16_t pro) { arp->header.ar_pro = htons(pro); *************** *** 61,70 **** } ! void arp_set_hardware_len(arp_obj *arp, uint8_t len) { arp->header.ar_hln = len; return; } ! void arp_set_protocol_len(arp_obj *arp, uint8_t len) { arp->header.ar_pln = len; --- 61,70 ---- } ! void arp_set_hardware_len(arp_obj * arp, uint8_t len) { arp->header.ar_hln = len; return; } ! void arp_set_protocol_len(arp_obj * arp, uint8_t len) { arp->header.ar_pln = len; *************** *** 72,76 **** } ! void arp_set_op(arp_obj *arp, uint16_t op) { arp->header.ar_op = htons(op); --- 72,76 ---- } ! void arp_set_op(arp_obj * arp, uint16_t op) { arp->header.ar_op = htons(op); *************** *** 78,82 **** } ! void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr) { memcpy(&arp->arp_data.ar_sha, &addr.data, ETH_ADDR_LEN); --- 78,82 ---- } ! void arp_set_sender_hardware_address(arp_obj * arp, eth_addr_t addr) { memcpy(&arp->arp_data.ar_sha, &addr.data, ETH_ADDR_LEN); *************** *** 84,88 **** } ! void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr) { memcpy(&arp->arp_data.ar_spa, &addr, IP_ADDR_LEN); --- 84,88 ---- } ! void arp_set_sender_protocol_address(arp_obj * arp, uint32_t addr) { memcpy(&arp->arp_data.ar_spa, &addr, IP_ADDR_LEN); *************** *** 90,94 **** } ! void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr) { memcpy(&arp->arp_data.ar_tha, &addr.data, ETH_ADDR_LEN); --- 90,94 ---- } ! void arp_set_target_hardware_address(arp_obj * arp, eth_addr_t addr) { memcpy(&arp->arp_data.ar_tha, &addr.data, ETH_ADDR_LEN); *************** *** 96,100 **** } ! void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr) { memcpy(&arp->arp_data.ar_tpa, &addr, IP_ADDR_LEN); --- 96,100 ---- } ! void arp_set_target_protocol_address(arp_obj * arp, uint32_t addr) { memcpy(&arp->arp_data.ar_tpa, &addr, IP_ADDR_LEN); *************** *** 104,148 **** /* get routines. */ ! uint16_t arp_get_op(arp_obj *arp) { ! return(ntohs(arp->header.ar_op)); } ! uint16_t arp_get_hardware_type(arp_obj *arp) { ! return(ntohs(arp->header.ar_hrd)); } ! uint16_t arp_get_protocol_type(arp_obj *arp) { ! return(ntohs(arp->header.ar_pro)); } ! uint8_t arp_get_hardware_len(arp_obj *arp) { ! return(arp->header.ar_hln); } ! uint8_t arp_get_protocol_len(arp_obj *arp) { ! return(arp->header.ar_pln); } ! unsigned char *arp_get_sender_hardware_address(arp_obj *arp) { ! return(arp->arp_data.ar_sha); } ! unsigned char *arp_get_sender_protocol_address(arp_obj *arp) { ! return(arp->arp_data.ar_spa); } /* dump image to packet. */ ! void arp_write_packet_image(arp_obj *arp, unsigned char *packet) { memcpy(packet, &arp->header.ar_hrd, sizeof(arp->header.ar_hrd)); packet += sizeof(arp->header.ar_hrd); ! memcpy(packet, &arp->header.ar_pro, sizeof(arp->header.ar_pro)); packet += sizeof(arp->header.ar_pro); --- 104,148 ---- /* get routines. */ ! uint16_t arp_get_op(arp_obj * arp) { ! return (ntohs(arp->header.ar_op)); } ! uint16_t arp_get_hardware_type(arp_obj * arp) { ! return (ntohs(arp->header.ar_hrd)); } ! uint16_t arp_get_protocol_type(arp_obj * arp) { ! return (ntohs(arp->header.ar_pro)); } ! uint8_t arp_get_hardware_len(arp_obj * arp) { ! return (arp->header.ar_hln); } ! uint8_t arp_get_protocol_len(arp_obj * arp) { ! return (arp->header.ar_pln); } ! unsigned char *arp_get_sender_hardware_address(arp_obj * arp) { ! return (arp->arp_data.ar_sha); } ! unsigned char *arp_get_sender_protocol_address(arp_obj * arp) { ! return (arp->arp_data.ar_spa); } /* dump image to packet. */ ! void arp_write_packet_image(arp_obj * arp, unsigned char *packet) { memcpy(packet, &arp->header.ar_hrd, sizeof(arp->header.ar_hrd)); packet += sizeof(arp->header.ar_hrd); ! memcpy(packet, &arp->header.ar_pro, sizeof(arp->header.ar_pro)); packet += sizeof(arp->header.ar_pro); *************** *** 150,160 **** memcpy(packet, &arp->header.ar_hln, sizeof(arp->header.ar_hln)); packet += sizeof(arp->header.ar_hln); ! memcpy(packet, &arp->header.ar_pln, sizeof(arp->header.ar_pln)); packet += sizeof(arp->header.ar_pln); ! memcpy(packet, &arp->header.ar_op, sizeof(arp->header.ar_op)); packet += sizeof(arp->header.ar_op); ! memcpy(packet, &arp->arp_data.ar_sha, sizeof(arp->arp_data.ar_sha)); packet += sizeof(arp->arp_data.ar_sha); --- 150,160 ---- memcpy(packet, &arp->header.ar_hln, sizeof(arp->header.ar_hln)); packet += sizeof(arp->header.ar_hln); ! memcpy(packet, &arp->header.ar_pln, sizeof(arp->header.ar_pln)); packet += sizeof(arp->header.ar_pln); ! memcpy(packet, &arp->header.ar_op, sizeof(arp->header.ar_op)); packet += sizeof(arp->header.ar_op); ! memcpy(packet, &arp->arp_data.ar_sha, sizeof(arp->arp_data.ar_sha)); packet += sizeof(arp->arp_data.ar_sha); *************** *** 162,175 **** memcpy(packet, &arp->arp_data.ar_spa, sizeof(arp->arp_data.ar_spa)); packet += sizeof(arp->arp_data.ar_spa); ! memcpy(packet, &arp->arp_data.ar_tha, sizeof(arp->arp_data.ar_tha)); packet += sizeof(arp->arp_data.ar_tha); memcpy(packet, &arp->arp_data.ar_tpa, sizeof(arp->arp_data.ar_tpa)); ! return; } ! int arp_read_packet_image(arp_obj *arp, const unsigned char *packet, int len) { if(len < (ARP_HDR_LEN + ARP_ETHIP_LEN)) --- 162,175 ---- memcpy(packet, &arp->arp_data.ar_spa, sizeof(arp->arp_data.ar_spa)); packet += sizeof(arp->arp_data.ar_spa); ! memcpy(packet, &arp->arp_data.ar_tha, sizeof(arp->arp_data.ar_tha)); packet += sizeof(arp->arp_data.ar_tha); memcpy(packet, &arp->arp_data.ar_tpa, sizeof(arp->arp_data.ar_tpa)); ! return; } ! int arp_read_packet_image(arp_obj * arp, const unsigned char *packet, int len) { if(len < (ARP_HDR_LEN + ARP_ETHIP_LEN)) Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-cache-entry.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-cache-entry.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 38,46 **** { cache_entry_t *cache; ! cache = xmalloc(sizeof(cache_entry_t)); cache->name = xstrdup(name); cache->value = xstrdup(value); ! return cache; } --- 38,46 ---- { cache_entry_t *cache; ! cache = xmalloc(sizeof(cache_entry_t)); cache->name = xstrdup(name); cache->value = xstrdup(value); ! return cache; } *************** *** 51,55 **** xfree(cache->value); xfree(cache); ! return; } --- 51,55 ---- xfree(cache->value); xfree(cache); ! return; } Index: dhcp-cache-entry.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-cache-entry.h 10 Nov 2002 15:46:40 -0000 1.1 --- dhcp-cache-entry.h 16 Nov 2002 00:23:42 -0000 1.2 *************** *** 35,37 **** extern void cache_entry_purge_list(list_t *cache_list); ! #endif /* DHCP_CACHE_ENTRY_H */ --- 35,37 ---- extern void cache_entry_purge_list(list_t *cache_list); ! #endif /* DHCP_CACHE_ENTRY_H */ Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-cache.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client-cache.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 40,48 **** { client_cache_t *cc; ! cc = xmalloc(sizeof(client_cache_t)); cc->interface = interface; /* don't copy just point. */ cc->vars = NULL; ! return cc; } --- 40,48 ---- { client_cache_t *cc; ! cc = xmalloc(sizeof(client_cache_t)); cc->interface = interface; /* don't copy just point. */ cc->vars = NULL; ! return cc; } *************** *** 53,63 **** list_t *list_ptr, *tmp; cache_entry_t *ce; ! list_ptr = cc->vars; ! while(list_ptr) { ! tmp = list_ptr; list_ptr = list_ptr->next; ! ce = tmp->data; destroy_cache_entry(ce); --- 53,63 ---- list_t *list_ptr, *tmp; cache_entry_t *ce; ! list_ptr = cc->vars; ! while(list_ptr) { ! tmp = list_ptr; list_ptr = list_ptr->next; ! ce = tmp->data; destroy_cache_entry(ce); *************** *** 74,78 **** if(cc->vars) purge_cache(cc); ! xfree(cc); return; --- 74,78 ---- if(cc->vars) purge_cache(cc); ! xfree(cc); return; *************** *** 86,94 **** retval = varfile_get_next_var(varfile); ! switch(retval) { ! case VARFILE_PARSE_ERROR: ! ERROR_MESSAGE("parser error in cache: %s : %d", varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return NULL; case VARFILE_EOF: --- 86,95 ---- retval = varfile_get_next_var(varfile); ! switch (retval) { ! case VARFILE_PARSE_ERROR: ! ERROR_MESSAGE("parser error in cache: %s : %d", varfile_get_filename(varfile), ! varfile_get_lineno(varfile)); ! return NULL; case VARFILE_EOF: *************** *** 159,165 **** char *fname; int retval; ! purge_cache(cc); ! if(use_tmp) fname = get_fname_tmp(cc); --- 160,166 ---- char *fname; int retval; ! purge_cache(cc); ! if(use_tmp) fname = get_fname_tmp(cc); *************** *** 169,173 **** retval = load_client_cache_proc(cc, fname); xfree(fname); ! return retval; } --- 170,174 ---- retval = load_client_cache_proc(cc, fname); xfree(fname); ! return retval; } *************** *** 185,194 **** int retval = 0; char *fname; ! fname = get_fname(cc); if(file_exists(fname)) retval = 1; xfree(fname); ! return retval; } --- 186,195 ---- int retval = 0; char *fname; ! fname = get_fname(cc); if(file_exists(fname)) retval = 1; xfree(fname); ! return retval; } *************** *** 200,212 **** dhcp_option_t *opt; unsigned char len; ! if(option_convert_handlers[tag].serialize_to_network == NULL) return NULL; ! data = option_convert_handlers[tag].serialize_to_network(string, &len); ! if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_options_strings[tag]); return NULL; } --- 201,213 ---- dhcp_option_t *opt; unsigned char len; ! if(option_convert_handlers[tag].serialize_to_network == NULL) return NULL; ! data = option_convert_handlers[tag].serialize_to_network(string, &len); ! if(data == NULL) { WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", ! dhcp_options_strings[tag]); return NULL; } *************** *** 222,227 **** * */ ! static list_t *get_cache_options_list_proc(client_cache_t *cc, ! void* (*convert_func)(unsigned char tag, char *string)) { list_t *options = NULL; --- 223,228 ---- * */ ! static list_t *get_cache_options_list_proc(client_cache_t *cc, ! void *(*convert_func) (unsigned char tag, char *string)) { list_t *options = NULL; *************** *** 231,243 **** void *data; ! for(cache = cc->vars;cache;cache = cache->next) { ! ce = cache->data; - - for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! if(string_matches(dhcp_options_strings[i], ce->name)) { ! if(convert_func) { data = convert_func(i, ce->value); if(data == NULL) --- 232,244 ---- void *data; ! for(cache = cc->vars; cache; cache = cache->next) { ! ce = cache->data; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! if(string_matches(dhcp_options_strings[i], ce->name)) { ! ! if(convert_func) { data = convert_func(i, ce->value); if(data == NULL) *************** *** 254,258 **** } } ! return options; } --- 255,259 ---- } } ! return options; } *************** *** 261,266 **** * we always do this to the temp file. */ ! int client_cache_dump_options(client_cache_t *cc, ! list_t *options) { FILE *fp; --- 262,266 ---- * we always do this to the temp file. */ ! int client_cache_dump_options(client_cache_t *cc, list_t *options) { FILE *fp; *************** *** 277,285 **** return -1; ! for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { ! /* Run coversion routines to store internally in * serialized (string) state. */ ! opt = list_ptr->data; --- 277,285 ---- return -1; ! for(list_ptr = options; list_ptr; list_ptr = list_ptr->next) { ! /* Run coversion routines to store internally in * serialized (string) state. */ ! opt = list_ptr->data; *************** *** 296,300 **** */ ! if(val == NULL) { WARN_MESSAGE("option %s appear malformed. skipping.."); continue; --- 296,300 ---- */ ! if(val == NULL) { WARN_MESSAGE("option %s appear malformed. skipping.."); continue; *************** *** 311,317 **** /* work horse load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, ! void* (*convert_func)(unsigned char tag, char *string)) { ! list_t *options; --- 311,318 ---- /* work horse load options routine. */ static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, ! void *(*convert_func) (unsigned char tag, ! char *string)) { ! list_t *options; *************** *** 328,337 **** list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) { ! return(client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); } /* load options and return serialized list. */ list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return(client_cache_load_options_list_proc(cc, use_tmp, NULL)); } --- 329,339 ---- list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); } + /* load options and return serialized list. */ list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) { ! return (client_cache_load_options_list_proc(cc, use_tmp, NULL)); } *************** *** 340,347 **** { char *fname_tmp, *fname; ! fname_tmp = get_fname_tmp(cc); fname = get_fname(cc); ! move_file(fname_tmp, fname); --- 342,349 ---- { char *fname_tmp, *fname; ! fname_tmp = get_fname_tmp(cc); fname = get_fname(cc); ! move_file(fname_tmp, fname); *************** *** 359,363 **** delete_file(fname); xfree(fname); ! return; } --- 361,365 ---- delete_file(fname); xfree(fname); ! return; } *************** *** 370,374 **** delete_file(fname); xfree(fname); ! return; } --- 372,376 ---- delete_file(fname); xfree(fname); ! return; } Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-client-cache.h 10 Nov 2002 15:46:40 -0000 1.1 --- dhcp-client-cache.h 16 Nov 2002 00:23:42 -0000 1.2 *************** *** 28,32 **** /* data structures. */ typedef struct { ! const char *interface; /* points to dhcp_client_control->interface */ list_t *vars; } client_cache_t; --- 28,32 ---- /* data structures. */ typedef struct { ! const char *interface; /* points to dhcp_client_control->interface */ list_t *vars; } client_cache_t; *************** *** 46,48 **** extern void client_cache_delete_cache(client_cache_t *cc); ! #endif /* DHCP_CLIENT_CACHE_H */ --- 46,48 ---- extern void client_cache_delete_cache(client_cache_t *cc); ! #endif /* DHCP_CLIENT_CACHE_H */ Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-conf.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client-conf.c 16 Nov 2002 00:23:42 -0000 1.3 *************** *** 40,54 **** * Here we keep the options we want by default. */ ! static const int default_config_options[] = { ! TAG_DHCP_SUBNET_MASK, /* Subnet Mask */ ! TAG_DHCP_ROUTER, /* Routers. */ ! TAG_DHCP_INTERFACE_MTU, /* Interface MTU */ ! TAG_DHCP_DOMAIN_NAME_SERVER, /* Domain Name Servers. */ ! TAG_DHCP_DOMAIN_NAME, /* Domain Name. */ ! TAG_DHCP_REQUESTED_IP_ADDRESS, /* Requested IP Address. */ ! TAG_DHCP_IP_ADDRESS_LEASE_TIME, /* IP Address lease time. */ ! TAG_DHCP_RENEWAL_TIME, /* Renewal time. */ ! TAG_DHCP_REBINDING_TIME, /* Rebinding time. */ ! TAG_DHCP_SERVER_IDENTIFIER, /* Server Identifier. */ }; --- 40,54 ---- * Here we keep the options we want by default. */ ! static const int default_config_options[] = { ! TAG_DHCP_SUBNET_MASK, /* Subnet Mask */ ! TAG_DHCP_ROUTER, /* Routers. */ ! TAG_DHCP_INTERFACE_MTU, /* Interface MTU */ ! TAG_DHCP_DOMAIN_NAME_SERVER, /* Domain Name Servers. */ ! TAG_DHCP_DOMAIN_NAME, /* Domain Name. */ ! TAG_DHCP_REQUESTED_IP_ADDRESS, /* Requested IP Address. */ ! TAG_DHCP_IP_ADDRESS_LEASE_TIME, /* IP Address lease time. */ ! TAG_DHCP_RENEWAL_TIME, /* Renewal time. */ ! TAG_DHCP_REBINDING_TIME, /* Rebinding time. */ ! TAG_DHCP_SERVER_IDENTIFIER, /* Server Identifier. */ }; *************** *** 61,65 **** { client_conf_t *cc; ! cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); --- 61,65 ---- { client_conf_t *cc; ! cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); *************** *** 70,74 **** void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } --- 70,74 ---- void client_conf_destroy(client_conf_t *cc) { ! xfree(cc); } *************** *** 89,93 **** int i; FILE *fp; ! fp = file_open_or_create_safe(fname, "a+"); --- 89,93 ---- int i; FILE *fp; ! fp = file_open_or_create_safe(fname, "a+"); *************** *** 95,101 **** return -1; ! for(i = 0;i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { ! ! if(fprintf(fp, "\"%s\"\n",dhcp_options_strings[default_config_options[i]]) < 0) { WARN_MESSAGE("could not dump options to file. I'm going to continue anyway."); fclose(fp); --- 95,101 ---- return -1; ! for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { ! ! if(fprintf(fp, "\"%s\"\n", dhcp_options_strings[default_config_options[i]]) < 0) { WARN_MESSAGE("could not dump options to file. I'm going to continue anyway."); fclose(fp); *************** *** 103,107 **** } } ! fclose(fp); return 0; --- 103,107 ---- } } ! fclose(fp); return 0; *************** *** 112,119 **** int i; ! for(i = 0;i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { cc->options[default_config_options[i]] = 1; } ! return; } --- 112,119 ---- int i; ! for(i = 0; i < DEFAULT_CONFIG_OPTIONS_LEN; i++) { cc->options[default_config_options[i]] = 1; } ! return; } *************** *** 132,163 **** return -1; } ! while(1) { ! retval = varfile_get_next_var(varfile); ! switch(retval) { ! case VARFILE_SUCCESS: ! match = 0; ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! /* as long as no error was returned from file_parse_string ! * we can just do a file_get_var_name() safely. */ ! if(string_matches(dhcp_options_strings[i], ! varfile_get_name(varfile))) { ! cc->options[i] = 1; ! match = 1; ! break; ! } ! ! } ! if(match != 1) ! WARN_MESSAGE("encountered illegal DHCP option in %s: %s : %d", fname, varfile_get_name(varfile), ! varfile_get_lineno(varfile)); ! break; case VARFILE_EOF: --- 132,162 ---- return -1; } ! while(1) { ! retval = varfile_get_next_var(varfile); ! switch (retval) { ! case VARFILE_SUCCESS: ! match = 0; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { ! /* as long as no error was returned from file_parse_string ! * we can just do a file_get_var_name() safely. */ ! if(string_matches(dhcp_options_strings[i], varfile_get_name(varfile))) { ! cc->options[i] = 1; ! match = 1; ! break; ! } ! } ! ! if(match != 1) ! WARN_MESSAGE("encountered illegal DHCP option in %s: %s : %d", fname, ! varfile_get_name(varfile), varfile_get_lineno(varfile)); ! break; case VARFILE_EOF: *************** *** 166,172 **** case VARFILE_PARSE_ERROR: ! ERROR_MESSAGE("parse error in opts file: %s : %d", varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return -1; default: --- 165,171 ---- case VARFILE_PARSE_ERROR: ! ERROR_MESSAGE("parse error in opts file: %s : %d", varfile_get_filename(varfile), varfile_get_lineno(varfile)); ! return -1; default: *************** *** 179,190 **** also call dump_defaults if file does not exist */ ! static int load_client_conf_proc(char *fname, ! client_conf_t *cc, int (*load_conf)(client_conf_t *cc, char *fname), ! void (*use_defaults)(client_conf_t *cc), ! int (*dump_defaults)(client_conf_t *cc, char *fname)) { int retval; ! if(!file_exists(fname)) { /* it doesn't exist. strap default. */ use_defaults(cc); --- 178,190 ---- also call dump_defaults if file does not exist */ ! static int load_client_conf_proc(char *fname, ! client_conf_t *cc, int (*load_conf) (client_conf_t *cc, ! char *fname), ! void (*use_defaults) (client_conf_t *cc), ! int (*dump_defaults) (client_conf_t *cc, char *fname)) { int retval; ! if(!file_exists(fname)) { /* it doesn't exist. strap default. */ use_defaults(cc); *************** *** 201,205 **** int load_client_conf(client_conf_t *cc) { ! char *fname; int retval; --- 201,205 ---- int load_client_conf(client_conf_t *cc) { ! char *fname; int retval; *************** *** 210,217 **** /* check for options file. */ fname = get_conf_options_fname(cc); ! retval = load_client_conf_proc(fname, cc, client_conf_load_options, use_default_options, dump_config_options); xfree(fname); ! return(retval); } --- 210,217 ---- /* check for options file. */ fname = get_conf_options_fname(cc); ! retval = load_client_conf_proc(fname, cc, client_conf_load_options, use_default_options, dump_config_options); xfree(fname); ! return (retval); } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-client-conf.h 10 Nov 2002 15:46:40 -0000 1.1 --- dhcp-client-conf.h 16 Nov 2002 00:23:42 -0000 1.2 *************** *** 30,35 **** typedef struct { char *conf_file; ! const char *interface; /* points to dhcp_client_control->interface */ ! /* specific configurations */ --- 30,35 ---- typedef struct { char *conf_file; ! const char *interface; /* points to dhcp_client_control->interface */ ! /* specific configurations */ *************** *** 41,43 **** extern int load_client_conf(client_conf_t *cc); ! #endif /* DHCP_CLIENT_CONF_H */ --- 41,43 ---- extern int load_client_conf(client_conf_t *cc); ! #endif /* DHCP_CLIENT_CONF_H */ Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-control.c 15 Nov 2002 21:19:35 -0000 1.3 --- dhcp-client-control.c 16 Nov 2002 00:23:42 -0000 1.4 *************** *** 69,72 **** --- 69,73 ---- return 0; } + /* create client id from a string in the format of xx:xx:xx:xx:xx:xx */ static unsigned char *create_fake_client_id(unsigned char *mac_string) *************** *** 78,87 **** *s = DLT_EN10MB; s++; ! if(hex_string_to_value(mac_string, mac_add)) { ERROR_MESSAGE("malformed mac string %s", mac_string); return NULL; } ! memcpy(s, mac_add, ETH_ADDR_LEN); s--; --- 79,88 ---- *s = DLT_EN10MB; s++; ! if(hex_string_to_value(mac_string, mac_add)) { ERROR_MESSAGE("malformed mac string %s", mac_string); return NULL; } ! memcpy(s, mac_add, ETH_ADDR_LEN); s--; *************** *** 94,98 **** { unsigned char *s; ! s = xmalloc(1 + ETH_ADDR_LEN); *s = DLT_EN10MB; --- 95,99 ---- { unsigned char *s; ! s = xmalloc(1 + ETH_ADDR_LEN); *s = DLT_EN10MB; *************** *** 100,104 **** memcpy(s, interface_address.data, ETH_ADDR_LEN); s--; ! return s; } --- 101,105 ---- memcpy(s, interface_address.data, ETH_ADDR_LEN); s--; ! return s; } *************** *** 108,116 **** { dhcp_client_control_t *dc; ! dc = xmalloc(sizeof(dhcp_client_control_t)); memset(dc, 0, sizeof(dhcp_client_control_t)); dc->interface = xstrdup(interface); ! return dc; } --- 109,117 ---- { dhcp_client_control_t *dc; ! dc = xmalloc(sizeof(dhcp_client_control_t)); memset(dc, 0, sizeof(dhcp_client_control_t)); dc->interface = xstrdup(interface); ! return dc; } *************** *** 132,139 **** #ifdef HAVE_UNAME struct utsname utsname; ! #endif /* HAVE_UNAME */ dc = xcalloc(sizeof(dhcp_client_control_t)); ! dc->state = 0; dc->interface = xstrdup(interface); --- 133,140 ---- #ifdef HAVE_UNAME struct utsname utsname; ! #endif /* HAVE_UNAME */ dc = xcalloc(sizeof(dhcp_client_control_t)); ! dc->state = 0; dc->interface = xstrdup(interface); *************** *** 148,152 **** } ! if(load_client_cache(dc->cache, 0) < 0) { ERROR_MESSAGE("could not read client cache."); destroy_dhcp_client_control(dc); --- 149,153 ---- } ! if(load_client_cache(dc->cache, 0) < 0) { ERROR_MESSAGE("could not read client cache."); destroy_dhcp_client_control(dc); *************** *** 161,168 **** dport = ntohs(dport); sport = ntohs(sport); - - if(dport == -1 || sport == -1) { ! WARN_MESSAGE("could not lookup dhcp services in service db (%s) will use reasonable defaults."); sport = BOOTP_CLIENT; --- 162,170 ---- dport = ntohs(dport); sport = ntohs(sport); ! if(dport == -1 || sport == -1) { ! ! WARN_MESSAGE ! ("could not lookup dhcp services in service db (%s) will use reasonable defaults."); sport = BOOTP_CLIENT; *************** *** 176,180 **** dport, sport); ! if((dc->rawnet = rawnet_create(interface, stringbuffer_getstring(filter), sport, dport, promiscuous)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); destroy_dhcp_client_control(dc); --- 178,184 ---- dport, sport); ! if((dc->rawnet = ! rawnet_create(interface, stringbuffer_getstring(filter), sport, dport, ! promiscuous)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); destroy_dhcp_client_control(dc); *************** *** 185,192 **** /* Additional fields. */ ! /* xid setting */ dhcp_client_update_xid(dc); ! /* secs settings. */ dhcp_client_reset_secs(dc); --- 189,196 ---- /* Additional fields. */ ! /* xid setting */ dhcp_client_update_xid(dc); ! /* secs settings. */ dhcp_client_reset_secs(dc); *************** *** 198,207 **** #ifdef HAVE_UNAME uname(&utsname); ! dc->class_id = splice_many_strings(4, utsname.sysname, utsname.nodename, utsname.release, utsname.version, utsname.machine); ! #else /* HAVE_UNAME */ dc->class_id = xstrdup("Unknown"); ! #endif /* HAVE_UNAME */ ! if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) { ERROR_MESSAGE("could not acquire interface address."); return NULL; --- 202,213 ---- #ifdef HAVE_UNAME uname(&utsname); ! dc->class_id = ! splice_many_strings(4, utsname.sysname, utsname.nodename, utsname.release, utsname.version, ! utsname.machine); ! #else /* HAVE_UNAME */ dc->class_id = xstrdup("Unknown"); ! #endif /* HAVE_UNAME */ ! if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) { ERROR_MESSAGE("could not acquire interface address."); return NULL; *************** *** 218,226 **** { char *new_client_id = create_fake_client_id(fake_hw_addr); ! if(dc->client_id != NULL) ! xfree(dc->client_id); dc->client_id = new_client_id; ! rawnet_use_fake_hw_addr(dc->rawnet, fake_hw_addr); return; --- 224,232 ---- { char *new_client_id = create_fake_client_id(fake_hw_addr); ! if(dc->client_id != NULL) ! xfree(dc->client_id); dc->client_id = new_client_id; ! rawnet_use_fake_hw_addr(dc->rawnet, fake_hw_addr); return; *************** *** 235,240 **** if(dc->cache) client_cache_destroy(dc->cache); ! ! if(dc->conf) client_conf_destroy(dc->conf); --- 241,246 ---- if(dc->cache) client_cache_destroy(dc->cache); ! ! if(dc->conf) client_conf_destroy(dc->conf); *************** *** 247,251 **** if(dc->class_id) xfree(dc->class_id); ! if(dc->client_id) xfree(dc->client_id); --- 253,257 ---- if(dc->class_id) xfree(dc->class_id); ! if(dc->client_id) xfree(dc->client_id); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client-states.c 15 Nov 2002 21:06:47 -0000 1.3 --- dhcp-client-states.c 16 Nov 2002 00:23:42 -0000 1.4 *************** *** 53,57 **** option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); options = add_to_list(options, option); ! /* dhcp message type. */ option = dhcp_build_message_type(DHCP_RELEASE_TM); --- 53,57 ---- option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); options = add_to_list(options, option); ! /* dhcp message type. */ option = dhcp_build_message_type(DHCP_RELEASE_TM); *************** *** 69,83 **** char *hostname; ! if(opts != NULL) { /* parameter_request_list */ ! option = dhcp_build_parameter_request_list_option(opts); options = add_to_list(options, option); ! } ! /* dhcp max DHCP message size: * should go into globconf. */ option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE); options = add_to_list(options, option); ! /* client_id */ option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); --- 69,83 ---- char *hostname; ! if(opts != NULL) { /* parameter_request_list */ ! option = dhcp_build_parameter_request_list_option(opts); options = add_to_list(options, option); ! } ! /* dhcp max DHCP message size: * should go into globconf. */ option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE); options = add_to_list(options, option); ! /* client_id */ option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); *************** *** 90,94 **** /* hostname if available */ hostname = glob_conf_get_val(CLIENT_HOSTNAME); ! if(hostname != NULL) { /* if we have one set it. */ option = dhcp_build_hostname(hostname); --- 90,94 ---- /* hostname if available */ hostname = glob_conf_get_val(CLIENT_HOSTNAME); ! if(hostname != NULL) { /* if we have one set it. */ option = dhcp_build_hostname(hostname); *************** *** 145,154 **** 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)); } --- 145,155 ---- 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)); } *************** *** 167,172 **** if((!rawnet_is_valid(dc->rawnet)) || ! dc->rawnet->type != RAWNET_DHCP || ! (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) return 0; --- 168,172 ---- if((!rawnet_is_valid(dc->rawnet)) || ! dc->rawnet->type != RAWNET_DHCP || (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) return 0; *************** *** 184,194 **** if(client_check_dhcp(dc) && - /* check that the type is an offer. */ - dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) && - /* check if the requested options match what we want. */ - client_check_requested_options(dc)) return 1; --- 184,190 ---- *************** *** 281,285 **** options = client_build_discover_option_list(dc->conf->options, dc); ! /* when we begin transmitting discover_offer we setup our secs field. * this is because relay agents and dhcp servers use this to see how --- 277,281 ---- options = client_build_discover_option_list(dc->conf->options, dc); ! /* when we begin transmitting discover_offer we setup our secs field. * this is because relay agents and dhcp servers use this to see how *************** *** 289,293 **** dhcp_client_update_secs(dc); ! /* update new xid per start of discovery .*/ dhcp_client_update_xid(dc); --- 285,289 ---- dhcp_client_update_secs(dc); ! /* update new xid per start of discovery . */ dhcp_client_update_xid(dc); *************** *** 300,342 **** client_check_discover, RECOMMENDED_MAX_SECS_WAIT); ! switch(retval) { ! case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! case RAWNET_OK: ! break; ! case RAWNET_ERROR: ! ERROR_MESSAGE("received error from raw network handler."); ! return STATE_FATAL_ERROR; ! default: ! FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } /* Check for two options before inserting them ourselves. * The server may have decided to be nice to us. */ ! if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS)) ! dc->rawnet->dhcp_p->options = ! add_to_list(dc->rawnet->dhcp_p->options, ! dhcp_build_requested_ip_address(dhcp_get_yiaddr(dc->rawnet->dhcp_p))); ! if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER)) ! dc->rawnet->dhcp_p->options = ! add_to_list(dc->rawnet->dhcp_p->options, ! dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); /* dump cache file. */ ! if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { ERROR_MESSAGE("could not create temporary cache."); return STATE_FATAL_ERROR; } ! client_cache_update(dc->cache); ! return STATE_REQUEST_ACK; } --- 296,338 ---- client_check_discover, RECOMMENDED_MAX_SECS_WAIT); ! switch (retval) { ! case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! case RAWNET_OK: ! break; ! case RAWNET_ERROR: ! ERROR_MESSAGE("received error from raw network handler."); ! return STATE_FATAL_ERROR; ! default: ! FATAL_MESSAGE("invalid return value from raw network handler -- this a bug report it."); } /* Check for two options before inserting them ourselves. * The server may have decided to be nice to us. */ ! if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS)) ! dc->rawnet->dhcp_p->options = ! add_to_list(dc->rawnet->dhcp_p->options, ! dhcp_build_requested_ip_address(dhcp_get_yiaddr(dc->rawnet->dhcp_p))); ! if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER)) ! dc->rawnet->dhcp_p->options = ! add_to_list(dc->rawnet->dhcp_p->options, ! dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); /* dump cache file. */ ! if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { ERROR_MESSAGE("could not create temporary cache."); return STATE_FATAL_ERROR; } ! client_cache_update(dc->cache); ! return STATE_REQUEST_ACK; } *************** *** 349,385 **** /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(NULL, dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); ! if(cache_options == NULL) { ERROR_MESSAGE("could not load cache."); return STATE_FATAL_ERROR; } ! options = join_lists(options, cache_options); /* Our options cleared by build_* since they are passed * down and later purged. */ ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); ! retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request, RECOMMENDED_MAX_SECS_WAIT); ! switch(retval) { ! case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! case RAWNET_OK: ! break; ! case RAWNET_ERROR: ! ERROR_MESSAGE("received error from raw network handler."); ! return STATE_FATAL_ERROR; ! default: ! FATAL_MESSAGE("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); } --- 345,384 ---- /* Build options along with the options in our cache. */ ! options = client_build_request_option_list(NULL, dc); cache_options = client_cache_load_option_network_list(dc->cache, 0); ! if(cache_options == NULL) { ERROR_MESSAGE("could not load cache."); return STATE_FATAL_ERROR; } ! options = join_lists(options, cache_options); /* Our options cleared by build_* since they are passed * down and later purged. */ ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); ! retval = ! rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request, ! RECOMMENDED_MAX_SECS_WAIT); ! switch (retval) { ! case RAWNET_TIMEOUT: ! ERROR_MESSAGE("timeout on DHCP discover."); ! return STATE_FATAL_ERROR; ! case RAWNET_OK: ! break; ! case RAWNET_ERROR: ! ERROR_MESSAGE("received error from raw network handler."); ! return STATE_FATAL_ERROR; ! default: ! FATAL_MESSAGE ! ("dhcp-client-states: invalid return value from raw network handler -- this a bug report it."); } *************** *** 408,413 **** build_dhcp_release(dc->rawnet, dc->xid, options, dc->sip_addr, dc->shw_addr); ! ! if(rawnet_send_packet(dc->rawnet) < 0) { ERROR_MESSAGE("could not send release."); return STATE_FATAL_ERROR; --- 407,412 ---- build_dhcp_release(dc->rawnet, dc->xid, options, dc->sip_addr, dc->shw_addr); ! ! if(rawnet_send_packet(dc->rawnet) < 0) { ERROR_MESSAGE("could not send release."); return STATE_FATAL_ERROR; *************** *** 425,433 **** /* since we're releasing the lease we should down the interface */ dhcp_client_interface_down(dc); ! /* called from do_shutdown() so no real state returned. * however if we do take the return value into consideration * we should handle it as an error. */ ! return STATE_FATAL_ERROR; } --- 424,432 ---- /* since we're releasing the lease we should down the interface */ dhcp_client_interface_down(dc); ! /* called from do_shutdown() so no real state returned. * however if we do take the return value into consideration * we should handle it as an error. */ ! return STATE_FATAL_ERROR; } *************** *** 438,442 **** options = client_cache_load_option_string_list(dc->cache, 0); ! if(options == NULL) { ERROR_MESSAGE("received empty configuration cache! cannot configure host"); return STATE_FATAL_ERROR; --- 437,441 ---- options = client_cache_load_option_string_list(dc->cache, 0); ! if(options == NULL) { ERROR_MESSAGE("received empty configuration cache! cannot configure host"); return STATE_FATAL_ERROR; *************** *** 470,481 **** if(timer_set_next(dc->timer)) { ! FATAL_MESSAGE("no timers set. we should have at least one for lease expiry sent to us from the server."); } /* wait for any interrupts. */ suspend_for_interrupts(); ! rawnet_up(dc->rawnet); ! /* Update our DHCP secs datum since we're renewing after this. */ --- 469,481 ---- if(timer_set_next(dc->timer)) { ! FATAL_MESSAGE ! ("no timers set. we should have at least one for lease expiry sent to us from the server."); } /* wait for any interrupts. */ suspend_for_interrupts(); ! rawnet_up(dc->rawnet); ! /* Update our DHCP secs datum since we're renewing after this. */ *************** *** 506,510 **** /* load what we can from the cache. */ ! cached_options = client_cache_load_option_string_list(dc->cache, 0); if(cached_options != NULL) do_sysconf_cleanup(cached_options, dc); --- 506,510 ---- /* load what we can from the cache. */ ! cached_options = client_cache_load_option_string_list(dc->cache, 0); if(cached_options != NULL) do_sysconf_cleanup(cached_options, dc); Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client.c 15 Nov 2002 21:19:35 -0000 1.4 --- dhcp-client.c 16 Nov 2002 00:23:42 -0000 1.5 *************** *** 52,60 **** /* table of functions indexed by command codes. */ client_command commands[] = { ! do_version, /* print out version information. */ ! do_kill_client, /* kill client. */ ! do_wake_client, /* wake client. */ ! do_clear_cache, /* clear cache. */ ! do_client, /* initialize and run client. */ }; --- 52,60 ---- /* table of functions indexed by command codes. */ client_command commands[] = { ! do_version, /* print out version information. */ ! do_kill_client, /* kill client. */ ! do_wake_client, /* wake client. */ ! do_clear_cache, /* clear cache. */ ! do_client, /* initialize and run client. */ }; *************** *** 69,77 **** interface_lister get_interface[] = { ! NULL, /* version output needs nothing. */ ! interface_get_active, /* kill client. */ ! interface_get_active, /* wake client. */ ! interface_get_active, /* clear cache. */ ! interface_get_inactive, /* run client. */ }; --- 69,77 ---- interface_lister get_interface[] = { ! NULL, /* version output needs nothing. */ ! interface_get_active, /* kill client. */ ! interface_get_active, /* wake client. */ ! interface_get_active, /* clear cache. */ ! interface_get_inactive, /* run client. */ }; *************** *** 87,104 **** }; ! /* global vars affecting other code. */ ! int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ #if !defined(HAVE_PROGNAME) const char *__progname; ! #endif /* HAVE_PROGNAME */ /* local vars for dhcpclient. */ ! static char *interface = NULL; /* the interface we're concerned with. */ static unsigned char want_background = 1; /* whether we should go into the background. */ ! static char *fake_hw_addr = NULL; /* if using fake hardware address set here. */ ! static int promiscuous = 0; /* whether or not we're running in promiscious mode. */ /* Utility routines. */ --- 87,104 ---- }; ! /* global vars affecting other code. */ ! int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ #if !defined(HAVE_PROGNAME) const char *__progname; ! #endif /* HAVE_PROGNAME */ /* local vars for dhcpclient. */ ! static char *interface = NULL; /* the interface we're concerned with. */ static unsigned char want_background = 1; /* whether we should go into the background. */ ! static char *fake_hw_addr = NULL; /* if using fake hardware address set here. */ ! static int promiscuous = 0; /* whether or not we're running in promiscious mode. */ /* Utility routines. */ *************** *** 113,117 **** if(init_glob_conf(stringbuffer_getstring(sb))) { ! FATAL_MESSAGE("could not read nor create global configuration file: %s", stringbuffer_getstring(sb)); } --- 113,118 ---- if(init_glob_conf(stringbuffer_getstring(sb))) { ! FATAL_MESSAGE("could not read nor create global configuration file: %s", ! stringbuffer_getstring(sb)); } *************** *** 123,127 **** static int initialize_client_state(dhcp_client_control_t *dc) { ! if(client_cache_is_empty(dc->cache)) { return STATE_DISCOVER_OFFER; } else /* if not empty we assume we can request the options. */ --- 124,128 ---- static int initialize_client_state(dhcp_client_control_t *dc) { ! if(client_cache_is_empty(dc->cache)) { return STATE_DISCOVER_OFFER; } else /* if not empty we assume we can request the options. */ *************** *** 149,154 **** pid_t pid; ! if(!get_pid_file(interface, &pid)) ! return 0; /* no pid file -- therefore no process. */ #if !defined(KILL_SIGNAL_DETECT) --- 150,155 ---- pid_t pid; ! if(!get_pid_file(interface, &pid)) ! return 0; /* no pid file -- therefore no process. */ #if !defined(KILL_SIGNAL_DETECT) *************** *** 156,169 **** /* if we can't detect it assume it is up since the PID file exists :| * issue warning though. */ ! WARN_MESSAGE("%s PID file exists please delete and kill process.", getprogname()); ! return 0; #else ! if(!kill(pid, 0)) ! return 1; ! else { ! delete_pid_file(interface); ! return 0; ! } #endif --- 157,170 ---- /* if we can't detect it assume it is up since the PID file exists :| * issue warning though. */ ! WARN_MESSAGE("%s PID file exists please delete and kill process.", getprogname()); ! return... [truncated message content] |
From: <act...@us...> - 2002-11-15 21:20:11
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv4939 Modified Files: dhcp-client-control.c dhcp-client.c Log Message: fix to interrupt handling Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-control.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client-control.c 15 Nov 2002 21:19:35 -0000 1.3 *************** *** 140,143 **** --- 140,144 ---- dc->conf = create_client_conf(dc->interface); dc->cache = create_client_cache(dc->interface); + dc->timer = create_timer(); if(load_client_conf(dc->conf) < 0) { *************** *** 237,240 **** --- 238,244 ---- if(dc->conf) client_conf_destroy(dc->conf); + + if(dc->timer) + destroy_timer(dc->timer); if(dc->interface) Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client.c 15 Nov 2002 21:06:47 -0000 1.3 --- dhcp-client.c 15 Nov 2002 21:19:35 -0000 1.4 *************** *** 225,234 **** --- 225,239 ---- switch(got_interrupt_type()) { + case INTERRUPT_NONE: + break; + case INTERRUPT_TERM: state = STATE_DO_SHUTDOWN; + break; case INTERRUPT_HUP: /* for now shutdown. */ state = STATE_DO_SHUTDOWN; + break; case INTERRUPT_ALARM: *************** *** 238,246 **** case TIMER_IP_LEASE: state = STATE_DISCOVER_OFFER; case TIMER_REBIND: state = STATE_REQUEST_ACK; ! } } --- 243,256 ---- case TIMER_IP_LEASE: state = STATE_DISCOVER_OFFER; + break; case TIMER_REBIND: state = STATE_REQUEST_ACK; ! break; } + + + default: + FATAL_MESSAGE("invalid interrupt type caught. this is a bug. report me."); } |
From: <act...@us...> - 2002-11-15 21:07:26
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv32686/src Modified Files: Makefile.am dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-daemon.c dhcp-daemon.h dhcp-libutil.h dhcp-sysconf.c dhcp-sysconf.h dhcp-timer.c dhcp-util.c Added Files: dhcp-interrupt.c Log Message: redid interrupt handlers; almost got rebind/renew done --- NEW FILE: dhcp-interrupt.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interrupt.c,v 1.1 2002/11/15 21:06:47 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Utility routines. * */ #define MODULE_NAME "dhcp-interrupt" #include "dhcp-local.h" #include "dhcp-libutil.h" /* wrap for volatine integers, or proper sig_atomic_t types. */ #ifdef HAVE_SIG_ATOMIC_T static sig_atomic_t have_shutdown = 0; static sig_atomic_t have_hup = 0; static sig_atomic_t have_alarm = 0; #else static volatile int have_shutdown = 0; static volatile int have_hup = 0; static volatile int have_alarm = 0; #endif /* All handlers do is setup atomic variables. */ /* term handler. */ RETSIGTYPE handle_shutdown(int i) { have_shutdown = 1; return (RETSIGTYPE) 0; } /* hup handler. */ RETSIGTYPE handle_hup(int i) { have_hup = 1; return (RETSIGTYPE) 0; } /* alarm handler. */ static RETSIGTYPE handle_alarm(int i) { have_alarm = 1; return (RETSIGTYPE) 0; } /* check which variables ere setup and return. * clear before returning. */ int got_interrupt_type(void) { if(have_shutdown) { have_shutdown = 0; return INTERRUPT_TERM; } if(have_hup) { have_hup = 0; return INTERRUPT_HUP; } if(have_alarm) { have_alarm = 0; return INTERRUPT_ALARM; } return INTERRUPT_NONE; } /* will trigger alarm for one time only. */ void set_alarm(uint32_t alarm_time) { add_interrupt_handler(SIGALRM, handle_alarm); alarm(alarm_time); return; } /* remove alarm. */ void remove_alarm(void) { have_alarm = 0; alarm(0); /* reset alarm to fire off immediately. */ while(!alarm); /* should happen _very_ soon. */ have_alarm = 0; /* now remove: this also makes sure we don't have a pending * SIGARLM. */ remove_interrupt(SIGALRM); return; } /* add signal handler. */ void add_interrupt_handler(int sigtype, void (*sighandler)(int)) { struct sigaction sa; memset(&sa, 0, sizeof(struct sigaction)); sa.sa_handler = sighandler; sigfillset(&sa.sa_mask); if(sigaction(sigtype, &sa, NULL)) FATAL_MESSAGE("could not set signal handler for: %d", sigtype); return; } /* block all signals. */ void block_interrupts(void) { sigset_t signal_mask; sigfillset(&signal_mask); sigprocmask(SIG_SETMASK, &signal_mask, NULL); return; } /* unblock signals temporarily so we can receive pending signals. */ int check_for_interrupts(void) { /* Easiest way to do this is unblock all signals, * then block them again. */ sigset_t signal_mask, o_mask; sigemptyset(&signal_mask); sigprocmask(SIG_SETMASK, &signal_mask, &o_mask); /* here we get all the signals. */ sigprocmask(SIG_SETMASK, &o_mask, NULL); return 0; } /* suspend indefinetly for a signal (useful for alarm). */ void suspend_for_interrupts(void) { sigset_t signal_mask; sigemptyset(&signal_mask); sigsuspend(&signal_mask); } /* remove an interrupt. */ void remove_interrupt(int sig) { sigset_t signal_set; sigemptyset(&signal_set); sigaddset(&signal_set, sig); if(sigpending(&signal_set)) { add_interrupt_handler(sig, SIG_IGN); sigfillset(&signal_set); sigdelset(&signal_set, sig); sigsuspend(&signal_set); add_interrupt_handler(sig, SIG_DFL); } return; } Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.am 10 Nov 2002 16:14:38 -0000 1.6 --- Makefile.am 15 Nov 2002 21:06:47 -0000 1.7 *************** *** 41,45 **** dhcp-arp.c \ dhcp-icmp.c \ ! dhcp-route.c dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 41,46 ---- dhcp-arp.c \ dhcp-icmp.c \ ! dhcp-route.c \ ! dhcp-interrupt.c dhcp_sniff_SOURCES = dhcp-sniff.c \ Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client-states.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client-states.c 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 456,460 **** return STATE_FATAL_ERROR; } ! return STATE_WAIT; } --- 456,460 ---- return STATE_FATAL_ERROR; } ! return STATE_WAIT; } *************** *** 463,486 **** int client_wait(dhcp_client_control_t *dc) { ! struct timeval alarm_time; ! /* ! * setup signal based on renewal time ! * we actually don't care about lease ! * time since we purge our cache ! * when we exit and release our lease. ! * ! * FIXME: (check RFC compliance) ! */ ! rawnet_down(dc->rawnet); ! alarm_time.tv_sec = dc->renewal_time; ! alarm_time.tv_usec = 0; ! ! set_alarm(alarm_time); ! ! suspend_for_interrupts(); /* if we got a shutdown or HUP it will be caught later. */ rawnet_up(dc->rawnet); --- 463,479 ---- int client_wait(dhcp_client_control_t *dc) { ! /* take our raw network connection down. */ rawnet_down(dc->rawnet); + /* Ask our internal timer to setup our next alarm: this is + * for rebind, renewal, and expiry in that order. */ ! if(timer_set_next(dc->timer)) { ! FATAL_MESSAGE("no timers set. we should have at least one for lease expiry sent to us from the server."); ! } + /* wait for any interrupts. */ + suspend_for_interrupts(); + rawnet_up(dc->rawnet); *************** *** 490,496 **** dhcp_client_update_secs(dc); ! return STATE_REQUEST_ACK; /* if we didn't an ALARM get it it's probably a HUP ! * or a TERM. in either case we can ! * return STATE_REQUEST_ACK here. */ } --- 483,490 ---- dhcp_client_update_secs(dc); ! return STATE_REQUEST_ACK; /* if we didn't get an ALARM it's ! * probably a HUP or a TERM. in ! * either case we can return ! * STATE_REQUEST_ACK here. */ } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client.c 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 222,227 **** check_for_interrupts(); ! if(want_shutdown) ! client_states[STATE_DO_SHUTDOWN](dc); /* if we're only running to be setup, --- 222,247 ---- check_for_interrupts(); ! ! switch(got_interrupt_type()) { ! ! case INTERRUPT_TERM: ! state = STATE_DO_SHUTDOWN; ! ! case INTERRUPT_HUP: ! /* for now shutdown. */ ! state = STATE_DO_SHUTDOWN; ! ! case INTERRUPT_ALARM: ! switch(timer_get_current_id(dc->timer)) { ! ! case TIMER_RENEW: ! case TIMER_IP_LEASE: ! state = STATE_DISCOVER_OFFER; ! ! case TIMER_REBIND: ! state = STATE_REQUEST_ACK; ! ! } ! } /* if we're only running to be setup, Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-client.h 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-client.h 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 36,43 **** client_conf_t *conf; /* configuration. */ ! uint32_t xid; /* unique xid */ ! time_t started; /* the amount of milliseconds since we started. */ time_t secs; /* secs -- used to save secs value. */ ! uint32_t renewal_time; /* when to renew lease (secs). */ char *interface; /* interface name. */ --- 36,43 ---- client_conf_t *conf; /* configuration. */ ! uint32_t xid; /* unique xid */ ! time_t started; /* the amount of milliseconds since we started. */ time_t secs; /* secs -- used to save secs value. */ ! timer_keeper_t *timer; /* timer for rebind/renew. */ char *interface; /* interface name. */ *************** *** 71,74 **** --- 71,78 ---- #define STATE_FATAL_ERROR 5 #define STATE_DO_SHUTDOWN 6 + + /* timer IDs. */ + + enum client_timer_types { TIMER_IP_LEASE = 1, TIMER_REBIND, TIMER_RENEW }; /* prototypes. */ Index: dhcp-daemon.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-daemon.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-daemon.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-daemon.c 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 33,64 **** #include "dhcp-log.h" - /* wrap for volatine integers, or proper sig_atomic_t types. */ - - #ifdef HAVE_SIG_ATOMIC_T - - sig_atomic_t want_shutdown = 0; - sig_atomic_t want_hup = 0; - - #else /* HAVE_SIG_ATOMIC_T */ - - volatile int want_shutdown = 0; - volatile int want_hup = 0; - - #endif /* HAVE_SIG_ATOMIC_T */ - - /* All handlers do is setup atomic variables. */ - - static RETSIGTYPE handle_shutdown(int i) - { - want_shutdown = 1; - return (RETSIGTYPE) 0; - } - - static RETSIGTYPE handle_hup(int i) - { - want_hup = 1; - return (RETSIGTYPE) 0; - } - /* setup our interrupt handles. */ void setup_interrupt_handlers(void) --- 33,36 ---- Index: dhcp-daemon.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-daemon.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-daemon.h 10 Nov 2002 15:46:40 -0000 1.1 --- dhcp-daemon.h 15 Nov 2002 21:06:47 -0000 1.2 *************** *** 27,44 **** #define DHCP_DAEMON_H - /* global vars. */ - - #ifdef HAVE_SIG_ATOMIC_T - - extern sig_atomic_t want_shutdown; - extern sig_atomic_t want_hup; - - #else /* HAVE_SIG_ATOMIC_T */ - - extern volatile int want_shutdown; - extern volatile int want_hup; - - #endif /* HAVE_SIG_ATOMIC_T */ - /* prototypes. */ extern void go_background(char *dir); --- 27,30 ---- Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-libutil.h 10 Nov 2002 15:46:40 -0000 1.4 --- dhcp-libutil.h 15 Nov 2002 21:06:47 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- * * * * * * * * * * */ + /* native data structures. */ /* list object. */ typedef struct list { *************** *** 46,49 **** --- 47,52 ---- } stringbuffer; + /* utility data structures. */ + /* rtt object. */ typedef struct rtt { *************** *** 54,60 **** --- 57,70 ---- } rtt_t; + /* trigger object. */ + typedef struct { + uint32_t seconds; + uint32_t id; + } timer_trigger_t; + /* timer object. */ typedef struct { list_t *triggers; + uint32_t current_id; } timer_keeper_t; *************** *** 109,113 **** /* alarm handlers. */ extern int had_alarm(void); ! extern void set_alarm(struct timeval alarm_time); extern void remove_alarm(void); --- 119,123 ---- /* alarm handlers. */ extern int had_alarm(void); ! extern void set_alarm(uint32_t alarm_time); extern void remove_alarm(void); *************** *** 175,184 **** void set_interactive(uint8_t interactive_arg); ! /* Timer object. */ extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); ! extern void timer_set_next(timer_keeper_t *timer); ! extern void timer_add_trigger(timer_keeper_t *timer, uint32_t time); extern int timer_purge(timer_keeper_t); /* var file. */ --- 185,195 ---- void set_interactive(uint8_t interactive_arg); ! /* timer object. */ extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); ! extern int timer_set_next(timer_keeper_t *timer); ! extern void timer_add_trigger(timer_keeper_t *timer, uint32_t time, uint32_t id); extern int timer_purge(timer_keeper_t); + extern uint32_t timer_get_current_id(timer_keeper_t *timer); /* var file. */ *************** *** 208,211 **** --- 219,225 ---- extern void suspend_for_interrupts(void); extern void remove_interrupt(int sig); + extern RETSIGTYPE handle_hup(int i); + extern RETSIGTYPE handle_shutdown(int i); + extern int got_interrupt_type(void); /* constants. */ *************** *** 254,257 **** --- 268,275 ---- #define ERROR_LEVEL LOG_ERR /* Error level */ #define INFO_LEVEL LOG_INFO /* Normal level */ + + /* interrupt types. */ + + enum interrupt_types { INTERRUPT_NONE, INTERRUPT_ALARM, INTERRUPT_HUP, INTERRUPT_TERM }; #endif /* DHCP_LIBUTIL_H */ Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-sysconf.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-sysconf.c 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 103,110 **** { NULL, NULL, SYSCONF_UNSET, }, /* 48 X-Windows font servers. */ { NULL, NULL, SYSCONF_UNSET, }, /* 49 X-Windows system display manager. */ ! { NULL, NULL, SYSCONF_UNSET, }, /* 50 */ ! { NULL, NULL, SYSCONF_UNSET, }, /* 51 */ ! { NULL, NULL, SYSCONF_UNSET, }, /* 52 */ ! { NULL, NULL, SYSCONF_UNSET, }, /* 53 */ { NULL, NULL, SYSCONF_UNSET, }, /* 54 */ { NULL, NULL, SYSCONF_UNSET, }, /* 55 */ --- 103,113 ---- { NULL, NULL, SYSCONF_UNSET, }, /* 48 X-Windows font servers. */ { NULL, NULL, SYSCONF_UNSET, }, /* 49 X-Windows system display manager. */ ! { NULL, NULL, SYSCONF_UNSET, }, /* 50 Requested IP Address. */ ! { sysconf_setup_lease_time, ! NULL, SYSCONF_UNSET, }, /* 51 IP Address Lease Time. */ ! { sysconf_setup_renew_time, ! NULL, SYSCONF_UNSET, }, /* 52 Renewal Time (T1). */ ! { sysconf_setup_rebind_time, ! NULL, SYSCONF_UNSET, }, /* 53 Rebind Time. (T2). */ { NULL, NULL, SYSCONF_UNSET, }, /* 54 */ { NULL, NULL, SYSCONF_UNSET, }, /* 55 */ *************** *** 116,119 **** --- 119,152 ---- { NULL, NULL, SYSCONF_UNSET, }, /* 61 */ }; + + static int sysconf_setup_u32_timer(uint32_t seconds, int id, dhcp_client_control_t *dc) + { + timer_add_trigger(dc->timer, seconds, id); + return 0; + } + + int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc) + { + uint32_t seconds = *(uint32_t *)value; + + sysconf_setup_u32_timer(seconds, TIMER_IP_LEASE, dc); + return 0; + } + + int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc) + { + uint32_t seconds = *(uint32_t *)value; + + sysconf_setup_u32_timer(seconds, TIMER_REBIND, dc); + return 0; + } + + int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc) + { + uint32_t seconds = *(uint32_t *)value; + + sysconf_setup_u32_timer(seconds, TIMER_RENEW, dc); + return 0; + } int sysconf_setup_routers(void *value, dhcp_client_control_t *dc) Index: dhcp-sysconf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-sysconf.h 29 Oct 2002 17:11:34 -0000 1.1.1.1 --- dhcp-sysconf.h 15 Nov 2002 21:06:47 -0000 1.2 *************** *** 40,43 **** --- 40,46 ---- /* System configuration routines. */ + extern int sysconf_setup_lease_time(void *value, dhcp_client_control_t *dc); + extern int sysconf_setup_rebind_time(void *value, dhcp_client_control_t *dc); + extern int sysconf_setup_renew_time(void *value, dhcp_client_control_t *dc); extern int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); extern int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-timer.c 10 Nov 2002 15:46:40 -0000 1.2 --- dhcp-timer.c 15 Nov 2002 21:06:47 -0000 1.3 *************** *** 72,79 **** /* add a new trigger. */ ! void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time) { ! uint32_t *trigger = xmalloc(sizeof(uint32_t)); ! *trigger = trigger_time; timer->triggers = add_to_list(timer->triggers, trigger); --- 72,81 ---- /* add a new trigger. */ ! void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time, uint32_t id) { ! timer_trigger_t *trigger = xmalloc(sizeof(timer_trigger_t)); ! ! trigger->seconds = trigger_time; ! trigger->id = id; timer->triggers = add_to_list(timer->triggers, trigger); *************** *** 83,99 **** /* timer setup next trigger. */ ! void timer_set_next(timer_keeper_t *timer) { ! uint32_t *trigger; if(timer->triggers == NULL) ! return; timer->triggers = sort_list(timer->triggers, compare_triggers_shortest); trigger = timer->triggers->data; ! alarm(*trigger); timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); xfree(trigger); } --- 85,109 ---- /* timer setup next trigger. */ ! int timer_set_next(timer_keeper_t *timer) { ! timer_trigger_t *trigger; if(timer->triggers == NULL) ! return 1; timer->triggers = sort_list(timer->triggers, compare_triggers_shortest); trigger = timer->triggers->data; ! set_alarm(trigger->seconds); ! timer->current_id = trigger->id; timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); xfree(trigger); + + return 0; + } + + uint32_t timer_get_current_id(timer_keeper_t *timer) + { + return timer->current_id; } Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-util.c 9 Nov 2002 16:59:15 -0000 1.5 --- dhcp-util.c 15 Nov 2002 21:06:47 -0000 1.6 *************** *** 266,345 **** } - /* signal manipulation routines. */ - - /* add signal handler. */ - void add_interrupt_handler(int sigtype, void (*sighandler)(int)) - { - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - - sa.sa_handler = sighandler; - sigfillset(&sa.sa_mask); - - if(sigaction(sigtype, &sa, NULL)) - FATAL_MESSAGE("could not set signal handler for: %d", sigtype); - - return; - } - - /* block all signals. */ - void block_interrupts(void) - { - sigset_t signal_mask; - - sigfillset(&signal_mask); - - sigprocmask(SIG_SETMASK, &signal_mask, NULL); - - return; - } - - /* unblock signals temporarily so we can receive pending signals. */ - int check_for_interrupts(void) - { - /* Easiest way to do this is unblock all signals, - * then block them again. */ - - sigset_t signal_mask, o_mask; - - sigemptyset(&signal_mask); - - sigprocmask(SIG_SETMASK, &signal_mask, &o_mask); - /* here we get all the signals. */ - sigprocmask(SIG_SETMASK, &o_mask, NULL); - - return 0; - } - - /* suspend indefinetly for a signal (useful for alarm). */ - void suspend_for_interrupts(void) - { - sigset_t signal_mask; - - sigemptyset(&signal_mask); - sigsuspend(&signal_mask); - - } - - void remove_interrupt(int sig) - { - sigset_t signal_set; - - sigemptyset(&signal_set); - sigaddset(&signal_set, sig); - - if(sigpending(&signal_set)) { - add_interrupt_handler(sig, SIG_IGN); - sigfillset(&signal_set); - sigdelset(&signal_set, SIGALRM); - - sigsuspend(&signal_set); - add_interrupt_handler(sig, SIG_DFL); - } - - return; - } - /* String routines. */ --- 266,269 ---- *************** *** 521,585 **** #endif /* HAVE_GETPROGNAME */ - - /* alarm handling routine and variable. */ - - /* wrap for volatine integers, or proper sig_atomic_t types. */ - - #ifdef HAVE_SIG_ATOMIC_T - - static sig_atomic_t have_alarm = 0; - - #else /* HAVE_SIG_ATOMIC_T */ - - static volatile int have_alarm = 0; - - #endif - - static RETSIGTYPE handle_alarm(int i) - { - have_alarm = 1; - return (RETSIGTYPE) 0; - } - - static struct timeval disarm_timer = { 0, 0 }; - - /* will trigger alarm for one time only. */ - void set_alarm(struct timeval alarm_time) - { - struct itimerval timer; - - timer.it_interval = alarm_time; - timer.it_value = disarm_timer; - - have_alarm = 0; - add_interrupt_handler(SIGALRM, handle_alarm); - - /* that's it. after this the timer is ticking. */ - setitimer(ITIMER_REAL, &timer, NULL); - - return; - } - - /* tells us whether we received an alarm or not.*/ - int had_alarm(void) - { - return have_alarm; - } - - /* remove alarm. */ - void remove_alarm(void) - { - struct itimerval timer; - - timer.it_interval = disarm_timer; - timer.it_value = disarm_timer; - - setitimer(ITIMER_REAL, &timer, NULL); - - /* now make sure we don't have a pending SIGARLM. */ - remove_interrupt(SIGALRM); - - return; - } /* check for seven bit cleanliness. */ --- 445,448 ---- |
From: <act...@us...> - 2002-11-10 16:14:42
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv18917 Modified Files: Makefile.am Log Message: updated to specify all the right files Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 10 Nov 2002 15:46:40 -0000 1.5 --- Makefile.am 10 Nov 2002 16:14:38 -0000 1.6 *************** *** 12,15 **** --- 12,22 ---- lib_LTLIBRARIES = libdhcputil.la + + 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-convert.h dhcp-globconf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ + dhcp-parser.h dhcp-sysconf.h + + libdhcputil_la_SOURCES = dhcp-util.c \ dhcp-stringbuffer.c \ *************** *** 24,30 **** dhcp-rawnet.c \ dhcp-interface.c \ - dhcp-local.h \ - dhcp-libutil.h \ - dhcp-librawnet.h \ dhcp-align.c \ dhcp-packet-build.c \ --- 31,34 ---- *************** *** 55,62 **** dhcp-globconf.c - dhcp_client_LDADD = -ldhcputil dhcp_sniff_LDADD = -ldhcputil libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ - - noinst_HEADERS = dhcp-agent.h ../config.h --- 59,63 ---- |
From: <act...@us...> - 2002-11-10 15:51:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv1482 Removed Files: dhcp-rtt.h dhcp-timer.h Log Message: no longer need dhcp-timer/dhcp-rtt --- dhcp-rtt.h DELETED --- --- dhcp-timer.h DELETED --- |
From: <act...@us...> - 2002-11-10 15:48:26
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv31698 Removed Files: dhcp-agent.h Log Message: no longer need dhcp-agent.h --- dhcp-agent.h DELETED --- |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv30373 Modified Files: Makefile.am dhcp-agent.h dhcp-align.c dhcp-arp-discovery.c dhcp-arp.c dhcp-cache-entry.c dhcp-client-cache.c dhcp-client-conf.c dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-com.c dhcp-convert.c dhcp-daemon.c dhcp-eth.c dhcp-globconf.c dhcp-icmp-discovery.c dhcp-icmp.c dhcp-interface.c dhcp-ip.c dhcp-librawnet.h dhcp-libutil.h dhcp-local.h dhcp-options-strings.c dhcp-packet-build.c dhcp-print.c dhcp-print.h dhcp-rawnet.c dhcp-route.c dhcp-rtt.c dhcp-rtt.h dhcp-sniff.c dhcp-sniffer-ohandlers.c dhcp-sysconf.c dhcp-timer.c dhcp-timer.h dhcp-udp.c Added Files: dhcp-align.h dhcp-cache-entry.h dhcp-client-cache.h dhcp-client-conf.h dhcp-daemon.h dhcp-interface.h dhcp-limits.h dhcp-options-strings.h Removed Files: dhcp-files.h dhcp-net.h Log Message: completed code split --- NEW FILE: dhcp-align.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_ALIGN_H #define DHCP_ALIGN_H /* alignment routines. */ extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); extern void align_udp(const unsigned char *data, struct udp_hdr *udp); extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); extern void align_eth(const unsigned char *data, struct eth_hdr *header); extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); extern void align_arp_header(const unsigned char *data, struct arp_hdr *header); extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); #endif /* DHCP_ALIGN_H */ --- NEW FILE: dhcp-cache-entry.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_CACHE_ENTRY_H #define DHCP_CACHE_ENTRY_H typedef struct { char *name; char *value; } cache_entry_t; extern cache_entry_t *create_cache_entry(const char *name, const char *value); extern void destroy_cache_entry(cache_entry_t *cache); extern void cache_entry_purge_list(list_t *cache_list); #endif /* DHCP_CACHE_ENTRY_H */ --- NEW FILE: dhcp-client-cache.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_CLIENT_CACHE_H #define DHCP_CLIENT_CACHE_H /* data structures. */ typedef struct { const char *interface; /* points to dhcp_client_control->interface */ list_t *vars; } client_cache_t; /* prototypes. */ extern client_cache_t *create_client_cache(const char *interface); extern void purge_cache(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); extern int load_client_cache(client_cache_t *cc, unsigned char use_tmp); extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); extern void client_cache_update(client_cache_t *cc); extern void client_cache_delete_tmp_cache(client_cache_t *cc); extern void client_cache_delete_cache(client_cache_t *cc); #endif /* DHCP_CLIENT_CACHE_H */ --- NEW FILE: dhcp-client-conf.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_CLIENT_CONF_H #define DHCP_CLIENT_CONF_H /* data structures. */ 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. */ } client_conf_t; extern client_conf_t *create_client_conf(const char *interface); extern void client_conf_destroy(client_conf_t *cc); extern int load_client_conf(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ --- NEW FILE: dhcp-daemon.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-daemon.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_DAEMON_H #define DHCP_DAEMON_H /* global vars. */ #ifdef HAVE_SIG_ATOMIC_T extern sig_atomic_t want_shutdown; extern sig_atomic_t want_hup; #else /* HAVE_SIG_ATOMIC_T */ extern volatile int want_shutdown; extern volatile int want_hup; #endif /* HAVE_SIG_ATOMIC_T */ /* prototypes. */ extern void go_background(char *dir); extern void setup_interrupt_handlers(void); #endif /* DHCP_DAEMON_H */ --- NEW FILE: dhcp-interface.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_INTERFACE_H #define DHCP_INTERFACE_H extern interface_control_t *create_interface_control(char *name); extern void destroy_interface_control(interface_control_t *ic); extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); extern int interface_down(interface_control_t *ic); extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); extern list_t *interface_get_active_interfaces(void); extern list_t *interface_get_inactive_interfaces(void); extern int interface_is_up(interface_control_t *ic); #endif /* DHCP_INTERFACE_H */ --- NEW FILE: dhcp-limits.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-limits.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_LIMITS_H #define DHCP_LIMITS_H /* sensible default for max descriptors -- we use this if we can't find it through other means (sysconf/getrusage) */ #define SENSIBLE_DESCRIPTOR_MAX 128 /* Generic size for buffers we use. * XXX -- fix generic buffers into sensible sizes. */ #define GENERIC_BUFFSIZE 256 /* mtu -- this is a broken guessing game right now.*/ #define DEFAULT_MTU 1500 #define SNAPLEN DEFAULT_MTU /* XXX -- should be called DEFAULT_SNAPLEN. * rawnet makes an assumption on incoming * packets this is broken. fixme. * */ /* Max message size option default. */ #define MAX_MESSAGE_SIZE 576 /* max options handled. */ #define MAX_OPTIONS_HANDLED 62 #endif /* DHCP_LIMITS_H */ --- NEW FILE: dhcp-options-strings.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_OPTION_STRINGS_H #define DHCP_OPTION_STRINGS_H extern char *dhcp_options_strings[]; #endif /* DHCP_OPTION_STRINGS_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 9 Nov 2002 16:59:15 -0000 1.4 --- Makefile.am 10 Nov 2002 15:46:40 -0000 1.5 *************** *** 3,7 **** # Main source Makefile.am ! CFLAGS = -Wall -Werror INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ --- 3,7 ---- # Main source Makefile.am ! CFLAGS = -Wall -Werror -g INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ *************** *** 9,13 **** # Programs we are compiling. ! #bin_PROGRAMS = dhcp-sniff dhcp-client lib_LTLIBRARIES = libdhcputil.la --- 9,13 ---- # Programs we are compiling. ! bin_PROGRAMS = dhcp-sniff dhcp-client lib_LTLIBRARIES = libdhcputil.la *************** *** 21,67 **** dhcp-varfile.c \ dhcp-parser.c \ ! dhcp-files.c ! # dhcp-rawnet.c ! # dhcp-align.c ! # dhcp-com.c \ ! # dhcp-eth.c \ ! # dhcp-ip.c \ ! # dhcp-udp.c \ ! # dhcp-arp.c \ ! # dhcp-icmp.c \ ! # dhcp-interface.c \ dhcp-libutil.h \ ! # dhcp-librawnet.h \ ! # dhcp-packet-build.c \ ! # dhcp-icmp-discovery.c \ ! # dhcp-arp-discovery.c \ ! dhcp-local.h ! # dhcp_sniff_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-sniff.c \ ! # dhcp-print.c \ ! # dhcp-sniffer-ohandlers.c ! # dhcp_client_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-client.c \ ! # dhcp-daemon.c \ ! # dhcp-client-cache.c \ ! # dhcp-cache-entry.c \ ! # dhcp-client-control.c \ ! # dhcp-client-conf.c \ ! # dhcp-client-states.c \ ! # dhcp-options-strings.c \ ! # dhcp-convert.c \ ! # dhcp-sysconf.c \ ! # dhcp-route.c \ ! # dhcp-globconf.c ! # dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! # dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h --- 21,62 ---- dhcp-varfile.c \ dhcp-parser.c \ ! dhcp-files.c \ ! dhcp-rawnet.c \ ! dhcp-interface.c \ ! dhcp-local.h \ dhcp-libutil.h \ ! dhcp-librawnet.h \ ! dhcp-align.c \ ! dhcp-packet-build.c \ ! dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c \ ! dhcp-com.c \ ! dhcp-eth.c \ ! dhcp-ip.c \ ! dhcp-udp.c \ ! dhcp-arp.c \ ! dhcp-icmp.c \ ! dhcp-route.c ! dhcp_sniff_SOURCES = dhcp-sniff.c \ ! dhcp-print.c \ ! dhcp-sniffer-ohandlers.c ! dhcp_client_SOURCES = dhcp-client.c \ ! dhcp-daemon.c \ ! dhcp-client-cache.c \ ! dhcp-cache-entry.c \ ! dhcp-client-control.c \ ! dhcp-client-conf.c \ ! dhcp-client-states.c \ ! dhcp-options-strings.c \ ! dhcp-convert.c \ ! dhcp-sysconf.c \ ! dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil ! dhcp_sniff_LDADD = -ldhcputil ! libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-agent.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-agent.h 29 Oct 2002 17:11:33 -0000 1.1.1.1 --- dhcp-agent.h 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 61,89 **** extern const char *__progname; - #if defined(HAVE_GETOPT_H) - - # include <getopt.h> - - #endif /* HAVE_GETOPT_H */ - - #ifdef HAVE_PRIMACROS_H - - #include <primacros.h> - - #endif /* HAVE_PRIMACROS_H */ - - #if defined(HAVE_STDARG_H) - - # include <stdarg.h> - - # else - - # if defined(HAVE_SYS_VARARGS_H) - - # include <varargs.h> - - # endif /* HAVE_VARARGS_H */ - - #endif /* HAVE_STDARG_H */ # if defined(HAVE_SYS_UTSNAME_H) --- 61,64 ---- *************** *** 98,105 **** * * * * * * * * * * */ - /* Limit on size of strings we'd be willing to handle. */ - - # define MAX_STRING_LEN 256 - /* Generic size for buffers we use. * XXX -- fix generic buffers into sensible sizes. --- 73,76 ---- *************** *** 115,133 **** */ - # define DEFAULT_MTU 1500 - # define SNAPLEN DEFAULT_MTU /* XXX -- should be called DEFAULT_SNAPLEN. - * rawnet makes an assumption on incoming - * packets this is broken. fixme. - * - */ - - /* Max message size option default. */ - - # define MAX_MESSAGE_SIZE 576 - - /* max options handled. */ - - # define MAX_OPTIONS_HANDLED 62 - /* sensible default for max descriptors -- we use this if we can't find it through other means (sysconf/getrusage) */ --- 86,89 ---- *************** *** 135,163 **** #define SENSIBLE_DESCRIPTOR_MAX 128 - /* Reasonable defaults in case services db isn't up to date. */ - - #define BOOTP_CLIENT 68 - #define BOOTP_SERVER 67 - - /* Solaris doesn't have INADDR_NONE */ - - #ifndef INADDR_NONE - #define INADDR_NONE (uint32_t) -1 - #endif - - /* Verbosity levels. */ - - enum verbosity { QUIET_VERBOSITY_LEVEL = 0, ERROR_VERBOSITY_LEVEL, NORMAL_VERBOSITY_LEVEL, - WARNING_VERBOSITY_LEVEL, DEBUG_VERBOSITY_LEVEL, MAX_VERBOSITY_LEVEL }; - - /* Line length for messages before breaking into a new line. */ - - #define MESSAGE_LINE_LENGTH 60 - - /* as mentioned in rfc2131, 64 seconds is the recommended upper - * limit of waiting time for ethernet. */ - - #define RECOMMENDED_MAX_SECS_WAIT 10 - /* * * * * * * * * * * * Data structures. * --- 91,94 ---- *************** *** 172,830 **** } list_t; - /* DHCP fixed header -- before dhcp options. */ - - /* Size of header independant of any padding - * sizeof() the structure may return. */ - - #define DHCP_FIXEDHDR_LEN 236 - - typedef struct { - uint8_t op; - uint8_t htype; - uint8_t hlen; - uint8_t hops; - uint32_t xid; - uint16_t secs; - uint16_t flags; - uint32_t ciaddr; - uint32_t yiaddr; - uint32_t siaddr; - uint32_t giaddr; - - #define DHCP_CHADDR_SIZE 16 - unsigned char chaddr[DHCP_CHADDR_SIZE]; - #define DHCP_SNAME_SIZE 64 - unsigned char sname[DHCP_SNAME_SIZE]; - #define DHCP_FILE_SIZE 128 - unsigned char file[DHCP_FILE_SIZE]; - - /* options go here. */ - } dhcphdr; - - /* dhcp option structure for internal - * dhcp object representation. */ - - typedef struct { - unsigned char tag; - unsigned char len; - unsigned char *data; - } dhcp_option_t; - - /* DHCP object * - * for packet assembly/disassembly. */ - - typedef struct { - dhcphdr fixedheader; /* DHCP fixed header. */ - uint32_t magic_cookie; /* Magic cookie. */ - list_t *options; /* Option list. */ - list_t *options_seek; /* Seek pointer to option list. */ - } dhcp_obj; - - /* - * Other packet objects. - * - * We use these to create a single interface - * for creating custom packeting. - * - */ - - typedef struct { - struct eth_hdr header; - } eth_obj; - - typedef struct { - struct ip_hdr header; - } ip_obj; - - typedef struct { - struct arp_hdr header; - struct arp_ethip arp_data; - } arp_obj; - - typedef struct { - struct icmp_hdr icmp_header; - union icmp_msg icmp_msg; - } icmp_obj; - - typedef struct { - struct udp_hdr header; - } udp_obj; - - /* interface control object: - * we store dnet's interface handle, - * and interface_entry structure. - * We need the entry structure - */ - - typedef struct { - intf_t *interface_handle; - struct intf_entry *interface_entry; - } interface_control_t; - - /* - * DHCP raw network object. - * - * We do all our network transmission - * through this data structure. - * - */ - - typedef struct { - - /* we should not interface directly with any of these members - * above the rawnet layer: FIXME -- unfortunately we do. */ - - pcap_t *pcap; /* packet capturing device (pcap). */ - int pcap_fd; /* file descriptor we can select on for pcap. */ - eth_t *eth; /* ethernet device handler (libdnet). */ - - uint16_t src_port, dst_port; /* udp ports for writing packets. */ - char *device; /* device name. */ - - char *packet_data; /* packet data. */ - int packet_len; /* total length of packet. */ - - struct timeval tstamp; /* timestamp. */ - - eth_addr_t chw_addr; /* our hardware address. */ - ip_addr_t cip_addr; /* our ip address. */ - - eth_addr_t *fake_hw_addr; /* our fake hardware address. */ - - int promiscuous; /* run in promiscuous mode flag. */ - interface_control_t - *intf_handle; /* interface control handle. */ - - /* - * Data objects - * - * After reception of packets on the wire - * they're aligned and placed into these - * objects. - * - */ - - unsigned char type; /* Type of data: - * ARP, ICMP DHCP */ - char *pcap_filter; /* low level pcap filter. */ - - /* Packet data. */ - - eth_obj *ether_p; - ip_obj *ip_p; - arp_obj *arp_p; - icmp_obj *icmp_p; - udp_obj *udp_p; - dhcp_obj *dhcp_p; - - } rawnet_t; - - typedef struct { - char *conf_file; - char *interface; /* points to dhcp_client_control->interface */ - - /* specific configurations */ - - unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ - } client_conf_t; - - /* Cache data types. */ - - typedef struct { - char *name; - char *value; - } cache_entry_t; - - typedef struct { - char *interface; /* points to dhcp_client_control->interface */ - list_t *vars; - } client_cache_t; - - /* Client data object. */ - - typedef struct { - - rawnet_t *rawnet; /* raw network handle */ - - client_cache_t *cache; /* cache */ - client_conf_t *conf; /* configuration. */ - - uint32_t xid; /* unique xid */ - time_t started; /* the amount of milliseconds since we started. */ - time_t secs; /* secs -- used to save secs value. */ - uint32_t renewal_time; /* when to renew lease (secs). */ - - char *interface; /* interface name. */ - unsigned char *class_id, *client_id; /* client_id, class_id */ - int state; /* our current state. */ - int discover_offer_retries; /* counter for retries on discover_offer */ - - ip_addr_t sip_addr; /* server's ip address. */ - eth_addr_t shw_addr; /* server's hardware address. */ - - } dhcp_client_control_t; - - /* Option print handler structure. */ - - typedef struct { - char *prefix; - void (*handle_option)(const unsigned char *data, - int len, int print_val); - } option_handler; - /* * * * * * * * Constants * * * * * * * */ - /* Syslog options. */ - - #define LOG_OPT LOG_PID|LOG_NDELAY /* Options */ - #define LOG_FACILITY LOG_DAEMON /* Facility */ - #define ERROR_LEVEL LOG_ERR /* Error level */ - #define INFO_LEVEL LOG_INFO /* Normal level */ - - /* DHCP Type messages */ - - # define DHCP_DISCOVER_TM 1 - # define DHCP_OFFER_TM 2 - # define DHCP_REQUEST_TM 3 - # define DHCP_DECLINE_TM 4 - # define DHCP_DHCPACK_TM 5 - # define DHCP_DHCPNAK_TM 6 - # define DHCP_RELEASE_TM 7 - - /* BOOTP Types */ - - #define DHCP_BOOTP_REQUEST 1 - #define DHCP_BOOTP_REPLY 2 - - /* Flags */ - - #define DHCP_BROADCAST_FLAG 0x8000 - - /* Option tags. */ - - /* (this is me trying to make constant names out of long option - * names. let the comedy ensue!) - */ - - # define TAG_DHCP_PAD 0 - # define TAG_DHCP_SUBNET_MASK 1 - # define TAG_DHCP_TIME_OFFSET 2 - # define TAG_DHCP_ROUTER 3 - # define TAG_DHCP_TIME_SERVER 4 - # define TAG_DHCP_NAME_SERVER 5 - # define TAG_DHCP_DOMAIN_NAME_SERVER 6 - # define TAG_DHCP_LOG_SERVER 7 - # define TAG_DHCP_COOKIE_SERVER 8 - # define TAG_DHCP_LPR_SERVER 9 - # define TAG_DHCP_IMPRESS_SERVER 10 - # define TAG_DHCP_RESOURCE_LOCATION_SERVER 11 - # define TAG_DHCP_HOST_NAME 12 - # define TAG_DHCP_BOOT_FILE_SIZE 13 - # define TAG_DHCP_MERIT_DUMP_FILE 14 - # define TAG_DHCP_DOMAIN_NAME 15 - # define TAG_DHCP_SWAP_SERVER 16 - # define TAG_DHCP_ROOT_PATH 17 - # define TAG_DHCP_EXTENSIONS_PATH 18 - # define TAG_DHCP_IP_FORWARDING 19 - # define TAG_DHCP_NON_LOCAL_SOURCE_ROUTING 20 - # define TAG_DHCP_POLICY_FILTER 21 - # define TAG_DHCP_MAX_DGRAM_REASSUMBLY_SIZE 22 - # define TAG_DHCP_IP_TIME_TO_LIVE 23 - # define TAG_DHCP_MTU_AGING_TIMEOUT 24 - # define TAG_DHCP_MTU_PLATEAU_TABLE 25 - # define TAG_DHCP_INTERFACE_MTU 26 - # define TAG_DHCP_SUBNETS_ARE_LOCAL 27 - # define TAG_DHCP_BROADCAST_ADDRESS 28 - # define TAG_DHCP_MASK_DISCOVERY 29 - # define TAG_DHCP_MASK_SUPPLIER 30 - # define TAG_DHCP_ROUTER_DISCOVERY 31 - # define TAG_DHCP_ROUTER_SOLICITATION 32 - # define TAG_DHCP_STATIC_ROUTE 33 - # define TAG_DHCP_TRAILER_ENCAPSULATION 34 - # define TAG_DHCP_ARP_CACHE_TIMEOUT 35 - # define TAG_DHCP_ETHERNET_ENCAPSULATION 36 - # define TAG_DHCP_TCP_DEFAULT_TTL 37 - # define TAG_DHCP_TCP_KEEPALIVE_INTERVAL 38 - # define TAG_DHCP_TCP_KEEPALIVE_GARBAGE 39 - # define TAG_DHCP_NIS_DOMAIN_NAME 40 - # define TAG_DHCP_NIS_SERVERS 41 - # define TAG_DHCP_NTP_SERVERS 42 - # define TAG_DHCP_VENDOR_SPECIFIC 43 - # define TAG_DHCP_NETBIOSOTCP_NAME_SERVER 44 - # define TAG_DHCP_NETBIOSOTCP_DATAGRAM_SERVER 45 - # define TAG_DHCP_NETBIOSOTCP_NODE_TYPE 46 - # define TAG_DHCP_NETBIOSOTCP_SCOPE 47 - # define TAG_DHCP_XWIN_FONT_SERVER 48 - # define TAG_DHCP_XWIN_DISP_MANAGER_SERVER 49 - # define TAG_DHCP_REQUESTED_IP_ADDRESS 50 - # define TAG_DHCP_IP_ADDRESS_LEASE_TIME 51 - # define TAG_DHCP_OVERLOAD 52 - # define TAG_DHCP_MESSAGE_TYPE 53 - # define TAG_DHCP_SERVER_IDENTIFIER 54 - # define TAG_DHCP_PARAMETERS 55 - # define TAG_DHCP_MESSAGE 56 - # define TAG_DHCP_MAX_DHCP_SIZE 57 - # define TAG_DHCP_RENEWAL_TIME 58 - # define TAG_DHCP_REBINDING_TIME 59 - # define TAG_DHCP_VENDOR_CLASS_ID 60 - # define TAG_DHCP_CLIENT_ID 61 - # define TAG_DHCP_NISPLUS_DOMAIN 64 - # define TAG_DHCP_NISPLUS_SERVERS 65 - # define TAG_DHCP_TFTP_SERVER 66 - # define TAG_DHCP_BOOT_FILE_NAME 67 - # define TAG_DHCP_IP_HOME_AGENT 68 - # define TAG_DHCP_SMTP_SERVER 69 - # define TAG_DHCP_POP_SERVER 70 - # define TAG_DHCP_NNTP_SERVER 71 - # define TAG_DHCP_DEFAULT_WWW_SERVER 72 - # define TAG_DHCP_DEFAULT_FINGER_SERVER 73 - # define TAG_DHCP_DEFAULT_IRC_SERVER 74 - # define TAG_DHCP_DEFAULT_ST_SERVER 75 - # define TAG_DHCP_DEFAULT_STDA_SERVER 76 - # define TAG_DHCP_END 255 - - /* DHCP overload option values. */ - - #define DHCP_OVERLOAD_FILE 1 - #define DHCP_OVERLOAD_SNAME 2 - #define DHCP_OVERLOAD_BOTH 3 - - /* NetBIOS Scope Node Types */ - - # define NETBIOS_B_NODE 0x01 - # define NETBIOS_P_NODE 0x02 - # define NETBIOS_M_NODE 0x04 - # define NETBIOS_H_NODE 0x06 - - /* Parse types. */ - - #define PARSE_SINGLE_STRING 1 - #define PARSE_DOUBLE_STRINGS 2 - /* * * * * * * * * * * * * Function prototypes * * * * * * * * * * * * */ - /* cache manipulation. */ - - extern client_cache_t *create_client_cache(dhcp_client_control_t *dc); - extern void client_cache_destroy(client_cache_t *cc); - extern int load_client_cache(client_cache_t *dc, unsigned char use_tmp); - extern int client_cache_is_empty(client_cache_t *cc); - extern void purge_cache(client_cache_t *cc); - extern int client_cache_dump_options(client_cache_t *cc, list_t *options); - extern list_t *client_cache_load_option_network_list(client_cache_t *cc, - unsigned char use_temp); - extern list_t *client_cache_load_option_string_list(client_cache_t *cc, - unsigned char use_tmp); - - extern void client_cache_update(client_cache_t *cc); - extern void client_cache_delete_cache(client_cache_t *cc); - extern void client_cache_delete_tmp_cache(client_cache_t *cc); - - /* cache object manipulation. */ - - extern cache_entry_t *make_cache_entry(const char *name, const char *value); - extern void destroy_cache_entry(cache_entry_t *cache); - extern void cache_entry_purge_list(list_t *cache_list); - - /* packet building routines. */ - - /* dhcp packet routines. */ - extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); - extern void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, - ip_addr_t sip_addr, eth_addr_t shw_addr); - extern void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); - extern void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); - - /* arp packet routines. */ - extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, - eth_addr_t source_hw_addr); - - extern void build_arp_reply(rawnet_t *net, - uint32_t source_addr, - uint32_t dest_addr, - eth_addr_t source_hw_addr, - eth_addr_t dest_hw_addr); - - extern void build_arp_request(rawnet_t *net, - uint32_t source_addr, - uint32_t dest_addr, - eth_addr_t source_hw_addr); - - extern void build_unarp(rawnet_t *net, uint32_t source_addr, - eth_addr_t source_hw_addr); - - /* icmp packet routines. */ - extern void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); - extern void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); - extern void build_icmp_echo_request(rawnet_t *net, ip_addr_t source_addr, ip_addr_t dest_addr, - eth_addr_t source_mac, eth_addr_t dest_mac, uint16_t id, - uint16_t seq); - - /* ICMP discovery routines. */ - extern int icmp_subnet_mask_discovery(rawnet_t *net, int retries, uint32_t *subnet_mask); - extern list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses); - - /* ARP discovery routines. */ - extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr); - - /* routing table routines. */ - - extern int route_find(rawnet_t *net, ip_addr_t addr, eth_addr_t *dest_mac); - - /* Daemon routines. */ - - extern void go_background(char *dir); - extern void setup_interrupt_handlers(void); - - /* Replacement vsnprintf, snprintf that work the way we want them to. */ - - extern int snprintf (char *str, size_t count, const char *fmt, ...); - extern int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); - - /* DHCP obj routines. */ - - extern dhcp_obj *dhcp_create(void); - extern void dhcp_purge(dhcp_obj *dhcp); - extern void dhcp_purge_option_list(list_t *options); /* only use on network list. */ - extern void dhcp_destroy(dhcp_obj *dhcp); - extern int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len); - extern void dhcp_write_packet_image(dhcp_obj *dhcp, unsigned char *packet); - - extern unsigned char dhcp_get_op(dhcp_obj *dhcp); - extern unsigned char dhcp_get_hlen(dhcp_obj *dhcp); - extern unsigned char dhcp_get_htype(dhcp_obj *dhcp); - extern unsigned char dhcp_get_hops(dhcp_obj *dhcp); - extern uint32_t dhcp_get_xid(dhcp_obj *dhcp); - extern uint16_t dhcp_get_secs(dhcp_obj *dhcp); - extern uint16_t dhcp_get_flags(dhcp_obj *dhcp); - extern uint32_t dhcp_get_ciaddr(dhcp_obj *dhcp); - extern uint32_t dhcp_get_yiaddr(dhcp_obj *dhcp); - extern uint32_t dhcp_get_siaddr(dhcp_obj *dhcp); - extern uint32_t dhcp_get_giaddr(dhcp_obj *dhcp); - extern unsigned char *dhcp_get_chaddr(dhcp_obj *dhcp); - extern unsigned char *dhcp_get_sname(dhcp_obj *dhcp); - extern unsigned char *dhcp_get_filename(dhcp_obj *dhcp); - extern uint32_t dhcp_get_magic_cookie(dhcp_obj *dhcp); - - extern void dhcp_set_op(dhcp_obj *dhcp, unsigned char op); - extern void dhcp_set_htype(dhcp_obj *dhcp, unsigned char htype); - extern void dhcp_set_hlen(dhcp_obj *dhcp, unsigned char hlen); - extern void dhcp_set_hops(dhcp_obj *dhcp, unsigned char hops); - extern void dhcp_set_xid(dhcp_obj *dhcp, uint32_t xid); - extern void dhcp_set_secs(dhcp_obj *dhcp, uint16_t secs); - extern void dhcp_set_flag_broadcast(dhcp_obj *dhcp); - extern void dhcp_unset_flag_broadcast(dhcp_obj *dhcp); - extern void dhcp_set_ciaddr(dhcp_obj *dhcp, uint32_t ciaddr); - extern void dhcp_set_yiaddr(dhcp_obj *dhcp, uint32_t yiaddr); - extern void dhcp_set_siaddr(dhcp_obj *dhcp, uint32_t siaddr); - extern void dhcp_set_giaddr(dhcp_obj *dhcp, uint32_t giaddr); - extern void dhcp_set_sname(dhcp_obj *dhcp, unsigned char *sname); - extern void dhcp_set_filename(dhcp_obj *dhcp, unsigned char *file); - extern void dhcp_set_magic_cookie(dhcp_obj *dhcp); - extern void dhcp_set_options(dhcp_obj *dhcp, list_t *options); - extern void dhcp_set_chaddr(dhcp_obj *dhcp, unsigned char *chaddr, int len); - - extern void dhcp_clear_sname(dhcp_obj *dhcp); - extern void dhcp_clear_filename(dhcp_obj *dhcp); - extern void dhcp_clear_chaddr(dhcp_obj *dhcp); - - extern void dhcp_reset_option_seek(dhcp_obj *dhcp); - extern dhcp_option_t *dhcp_get_next_option(dhcp_obj *dhcp); - extern dhcp_option_t *create_dhcp_option(const unsigned char *opt_data, - unsigned char len, unsigned char tag); - extern void destroy_dhcp_option(dhcp_option_t *option); - extern uint16_t dhcp_get_options_len(list_t *options); - extern int dhcp_valid_magic_cookie(dhcp_obj *dhcp); - extern int dhcp_is_type(dhcp_obj *dhcp, unsigned char type); - extern int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len); - extern int dhcp_have_atleast_requested_options(dhcp_obj *dhcp, unsigned char *option); - extern int dhcp_have_exact_requested_options(dhcp_obj *dhcp, unsigned char *options); - extern int dhcp_have_option(dhcp_obj *dhcp, unsigned char tag); - extern int dhcp_is_file_overload(dhcp_obj *dhcp); - extern int dhcp_is_sname_overload(dhcp_obj *dhcp); - extern uint32_t dhcp_gen_xid(void); - - extern dhcp_option_t *dhcp_build_parameter_request_list_option(unsigned char *requested_options); - extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); - extern dhcp_option_t *dhcp_build_message_type(unsigned char type); - extern dhcp_option_t *dhcp_build_class_id(unsigned char *class_id); - extern dhcp_option_t *dhcp_build_client_id(unsigned char *client_id, unsigned char len); - extern dhcp_option_t *dhcp_build_requested_ip_address(uint32_t address); - extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); - extern dhcp_option_t *dhcp_build_hostname(char *hostname); - - - /* Ether obj routines. */ - - extern eth_obj *eth_create(void); - extern void eth_destroy(eth_obj *eth); - extern int eth_read_packet_image(eth_obj *eth, const unsigned char *packet, int len); - extern void eth_write_packet_image(eth_obj *eth, unsigned char *packet); - - extern eth_addr_t eth_get_src_address(eth_obj *eth); - extern eth_addr_t eth_get_dst_address(eth_obj *eth); - extern uint16_t eth_get_type(eth_obj *eth); - - extern void eth_set_src_address(eth_obj *eth, eth_addr_t addr); - extern void eth_set_dst_address(eth_obj *eth, eth_addr_t addr); - extern void eth_set_type(eth_obj *eth, uint16_t type); - - /* IP obj routines. */ - - extern ip_obj *ip_create(void); - extern void ip_destroy(ip_obj *ip); - extern int ip_read_packet_image(ip_obj *ip, const unsigned char *packet, int len); - extern void ip_write_packet_image(ip_obj *ip, unsigned char *packet); - - extern uint32_t ip_get_source_addr(ip_obj *ip); - extern uint32_t ip_get_dest_addr(ip_obj *ip); - extern unsigned char ip_get_hl(ip_obj *ip); - extern uint8_t ip_get_proto(ip_obj *ip); - - extern void ip_set_hl(ip_obj *ip, uint16_t header_len); - extern void ip_set_tos(ip_obj *ip, unsigned char ip_tos); - extern void ip_set_len(ip_obj *ip, uint16_t ip_len); - extern void ip_set_id(ip_obj *ip, uint16_t ip_id); - extern void ip_set_off(ip_obj *ip, uint16_t ip_off); - extern void ip_set_ttl(ip_obj *ip, uint8_t ip_ttl); - extern void ip_set_proto(ip_obj *ip, unsigned char ip_proto); - extern void ip_set_source_addr(ip_obj *ip, uint32_t ip_src); - extern void ip_set_dest_addr(ip_obj *ip, uint32_t ip_src); - - /* ARP obj routines. */ - - extern arp_obj *arp_create(void); - extern void arp_destroy(arp_obj *arp); - extern void arp_write_packet_image(arp_obj *arp, unsigned char *packet); - - extern void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr); - extern void arp_set_protocol_type(arp_obj *arp, uint16_t pro); - extern void arp_set_hardware_len(arp_obj *arp, uint8_t len); - extern void arp_set_protocol_len(arp_obj *arp, uint8_t len); - extern void arp_set_op(arp_obj *arp, uint16_t op); - extern void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr); - extern void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr); - extern void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr); - extern void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr); - - extern uint16_t arp_get_op(arp_obj *arp); - extern uint16_t arp_get_hardware_type(arp_obj *arp); - extern uint16_t arp_get_protocol_type(arp_obj *arp); - extern uint8_t arp_get_hardware_len(arp_obj *arp); - extern uint8_t arp_get_protocol_len(arp_obj *arp); - extern unsigned char *arp_get_sender_hardware_address(arp_obj *arp); - extern unsigned char *arp_get_sender_protocol_address(arp_obj *arp); - - extern int arp_read_packet_image(arp_obj *arp, const unsigned char *packet, int len); - - /* UDP obj routines. */ - - extern udp_obj *udp_create(void); - extern void udp_destroy(udp_obj *udp); - extern int udp_read_packet_image(udp_obj *udp, const unsigned char *packet, int len); - extern void udp_write_packet_image(udp_obj *udp, unsigned char *packet); - - extern uint16_t udp_get_src_port(udp_obj *udp); - extern uint16_t udp_get_dst_port(udp_obj *udp); - extern uint16_t udp_get_len(udp_obj *udp); - - extern void udp_set_src_port(udp_obj *udp, uint16_t src_port); - extern void udp_set_dst_port(udp_obj *udp, uint16_t dst_port); - extern void udp_set_len(udp_obj *udp, uint16_t len); - extern void udp_set_cksum(udp_obj *udp, uint16_t cksum); - - /* ICMP obj routines. */ - - extern icmp_obj *icmp_create(void); - extern void icmp_destroy(icmp_obj *icmp); - - extern void icmp_set_type(icmp_obj *icmp, uint8_t type); - extern void icmp_set_code(icmp_obj *icmp, uint8_t code); - extern void icmp_clear_cksum(icmp_obj *icmp); - extern void icmp_mask_set_id(icmp_obj *icmp, uint32_t id); - extern void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq); - extern void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask); - extern void icmp_echo_set_id(icmp_obj *icmp, uint16_t id); - extern void icmp_echo_set_seq(icmp_obj *icmp, uint16_t seq); - - extern uint8_t icmp_get_type(icmp_obj *icmp); - extern uint32_t icmp_mask_get_mask(icmp_obj *icmp_p); - extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); - extern int icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet, int len); - - /* Alignment functions. */ - - extern void align_eth(const unsigned char *data, struct eth_hdr *eth); - extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); - extern void align_udp(const unsigned char *data, struct udp_hdr *udp); - extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); - extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); - extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); - extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); - extern void align_arp_header(const unsigned char *data, struct arp_hdr *header); - extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); - - /* Linked List routines. */ - - extern list_t *add_to_list(list_t *head, void *datum); - extern list_t *add_to_end_of_list(list_t *head, void *datum); - extern list_t *remove_from_list(list_t *head, void *datum); - extern void purge_list(list_t *head, void (*purge_func)(void *d)); - extern void purge_list_internal(void *head); - extern list_t *join_lists(list_t *first_list, list_t *second_list); - extern list_t *list_find_datum_by(list_t *list, int (*find_func)(void *, void *), void *arg); - extern list_t *sort_list(list_t *list, int (*compare)(void *, void *)); - - /* Logging functions. */ - - extern void init_log(const char *s); - extern void close_log(void); - extern void error_log(const char *msg); - extern void info_log(const char *msg); - - /* dhcp client control */ - - extern dhcp_client_control_t *create_dhcp_client_control(char *interface, int promiscuous); - extern void destroy_dhcp_client_control(dhcp_client_control_t *dc); - extern void dhcp_client_update_secs(dhcp_client_control_t *dc); - extern void dhcp_client_reset_secs(dhcp_client_control_t *dc); - extern void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, - char *fake_hw_addr); - extern dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface); - extern void dhcp_client_interface_down(dhcp_client_control_t *dc); - extern void dhcp_client_update_xid(dhcp_client_control_t *dc); - - extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); - extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); - - /* dhcp client conf */ - - extern client_conf_t *create_client_conf(dhcp_client_control_t *dc); - extern void client_conf_destroy(client_conf_t *cc); - extern int load_client_conf(client_conf_t *cc); - - /* interface control */ - - extern interface_control_t *create_interface_control(char *name); - extern int interface_is_up(interface_control_t *ic); - extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); - extern int interface_down(interface_control_t *ic); - extern void destroy_interface_control(interface_control_t *ic); - extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); - extern list_t *interface_get_active_interfaces(void); - extern list_t *interface_get_inactive_interfaces(void); - - /* client states */ - - extern int client_discover_offer(dhcp_client_control_t *dc); - extern int client_request_ack(dhcp_client_control_t *dc); - extern int client_wait(dhcp_client_control_t *dc); - extern int client_release(dhcp_client_control_t *dc); - extern int client_setup(dhcp_client_control_t *dc); - /* Global vars. */ --- 103,114 ---- *************** *** 833,837 **** extern int want_shutdown, want_hup; extern char *dhcp_conf_options_strings[]; - extern option_handler option_handlers[]; extern char *dhcp_options_strings[]; --- 117,120 ---- Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-align.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-align.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 33,37 **** #define MODULE_NAME "dhcp-align" ! #include <dhcp-agent.h> void align_ip(const unsigned char *data, struct ip_hdr *iphdr) --- 33,39 ---- #define MODULE_NAME "dhcp-align" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" void align_ip(const unsigned char *data, struct ip_hdr *iphdr) Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp-discovery.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-arp-discovery.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-arp-discovery.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 23,29 **** */ ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-net.h> #define MODULE_NAME "dhcp-arp-discovery" --- 23,29 ---- */ ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" #define MODULE_NAME "dhcp-arp-discovery" Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-arp.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-arp.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,30 **** #define MODULE_NAME "dhcp-arp" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> /* constructor */ --- 25,33 ---- #define MODULE_NAME "dhcp-arp" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-align.h" /* constructor */ Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-cache-entry.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-cache-entry.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 29,37 **** #define MODULE_NAME "dhcp-cache-entry" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> /* constructors. */ ! cache_entry_t *make_cache_entry(const char *name, const char *value) { cache_entry_t *cache; --- 29,39 ---- #define MODULE_NAME "dhcp-cache-entry" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! ! #include "dhcp-cache-entry.h" /* constructors. */ ! cache_entry_t *create_cache_entry(const char *name, const char *value) { cache_entry_t *cache; Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-cache.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-cache.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 26,43 **** #define MODULE_NAME "dhcp-client-cache" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> ! #include <dhcp-varfile.h> ! #include <dhcp-convert.h> /* constructor. */ ! client_cache_t *create_client_cache(dhcp_client_control_t *dc) { client_cache_t *cc; cc = xmalloc(sizeof(client_cache_t)); ! cc->interface = dc->interface; /* don't copy just point. */ cc->vars = NULL; --- 26,46 ---- #define MODULE_NAME "dhcp-client-cache" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-cache-entry.h" ! #include "dhcp-client-cache.h" ! #include "dhcp-convert.h" ! #include "dhcp-options-strings.h" /* constructor. */ ! client_cache_t *create_client_cache(const char *interface) { client_cache_t *cc; cc = xmalloc(sizeof(client_cache_t)); ! cc->interface = interface; /* don't copy just point. */ cc->vars = NULL; *************** *** 93,97 **** case VARFILE_SUCCESS: ! cache_entry = make_cache_entry(varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; --- 96,100 ---- case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; *************** *** 244,248 **** break; } else { ! copy = make_cache_entry(ce->name, ce->value); options = add_to_list(options, copy); break; --- 247,251 ---- break; } else { ! copy = create_cache_entry(ce->name, ce->value); options = add_to_list(options, copy); break; Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-conf.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-conf.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,33 **** #define MODULE_NAME "dhcp-client-conf" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> ! #include <dhcp-varfile.h> #define DEFAULT_CONFIG_OPTIONS_LEN 8 --- 25,37 ---- #define MODULE_NAME "dhcp-client-conf" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-client-conf.h" ! #include "dhcp-cache-entry.h" ! #include "dhcp-client-cache.h" ! #include "dhcp-options-strings.h" #define DEFAULT_CONFIG_OPTIONS_LEN 8 *************** *** 54,58 **** } ! client_conf_t *create_client_conf(dhcp_client_control_t *dc) { client_conf_t *cc; --- 58,62 ---- } ! client_conf_t *create_client_conf(const char *interface) { client_conf_t *cc; *************** *** 60,64 **** cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); ! cc->interface = dc->interface; return cc; } --- 64,68 ---- cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); ! cc->interface = interface; return cc; } Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-control.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-control.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 24,31 **** #define MODULE_NAME "dhcp-client-control" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-globconf.h> ! #include <dhcp-net.h> /* Utility routines to update counters and time stamps. */ --- 24,38 ---- #define MODULE_NAME "dhcp-client-control" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-client-conf.h" ! #include "dhcp-cache-entry.h" ! #include "dhcp-client-cache.h" ! #include "dhcp-client.h" ! #include "dhcp-client-conf.h" ! #include "dhcp-globconf.h" /* Utility routines to update counters and time stamps. */ *************** *** 131,136 **** dc->state = 0; dc->interface = xstrdup(interface); ! dc->conf = create_client_conf(dc); ! dc->cache = create_client_cache(dc); if(load_client_conf(dc->conf) < 0) { --- 138,143 ---- dc->state = 0; dc->interface = xstrdup(interface); ! dc->conf = create_client_conf(dc->interface); ! dc->cache = create_client_cache(dc->interface); if(load_client_conf(dc->conf) < 0) { *************** *** 148,153 **** /* Get port numbers from services db. */ ! dport = port_for_service("bootps", "udp"); ! sport = port_for_service("bootpc", "udp"); dport = ntohs(dport); --- 155,160 ---- /* Get port numbers from services db. */ ! dport = rawnet_port_for_service("bootps", "udp"); ! sport = rawnet_port_for_service("bootpc", "udp"); dport = ntohs(dport); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-states.c 29 Oct 2002 17:11:20 -0000 1.1.1.1 --- dhcp-client-states.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 28,37 **** #define MODULE_NAME "dhcp-client-states" ! #include <dhcp-agent.h> ! #include <dhcp-client.h> ! #include <dhcp-util.h> ! #include <dhcp-sysconf.h> ! #include <dhcp-globconf.h> ! #include <dhcp-net.h> /*************************** --- 28,42 ---- #define MODULE_NAME "dhcp-client-states" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-client-conf.h" ! #include "dhcp-cache-entry.h" ! #include "dhcp-client-cache.h" ! #include "dhcp-client.h" ! #include "dhcp-globconf.h" ! #include "dhcp-sysconf.h" /*************************** *************** *** 421,425 **** dhcp_client_interface_down(dc); ! return 0; /* called from do_shutdown() so no real state returned */ } --- 426,433 ---- dhcp_client_interface_down(dc); ! /* called from do_shutdown() so no real state returned. ! * however if we do take the return value into consideration ! * we should handle it as an error. */ ! return STATE_FATAL_ERROR; } *************** *** 493,494 **** --- 501,526 ---- } + /* do a graceful shutdown. */ + int client_do_shutdown(dhcp_client_control_t *dc) + { + list_t *cached_options; + + INFO_MESSAGE("shutting down."); + + if(dc) { /* only do clean up if we can. */ + + /* load what we can from the cache. */ + + cached_options = client_cache_load_option_string_list(dc->cache, 0); + if(cached_options != NULL) + do_sysconf_cleanup(cached_options, dc); + + cache_entry_purge_list(cached_options); + + client_release(dc); + delete_pid_file(dc->interface); + destroy_dhcp_client_control(dc); + } + + exit(0); + } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client.c 29 Oct 2002 17:11:21 -0000 1.1.1.1 --- dhcp-client.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,34 **** #define MODULE_NAME "dhcp-client" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-sysconf.h> ! #include <dhcp-globconf.h> ! #include <dhcp-files.h> ! #include <dhcp-client.h> /* forward declarations of do_ routines. */ --- 25,39 ---- #define MODULE_NAME "dhcp-client" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-client-conf.h" ! #include "dhcp-cache-entry.h" ! #include "dhcp-client-cache.h" ! #include "dhcp-client.h" ! #include "dhcp-globconf.h" ! #include "dhcp-daemon.h" /* forward declarations of do_ routines. */ *************** *** 79,82 **** --- 84,88 ---- client_release, client_fatal_error, + client_do_shutdown, }; *************** *** 138,166 **** } - /* do a graceful shutdown. */ - static void do_shutdown(dhcp_client_control_t *dc) - { - list_t *cached_options; - - INFO_MESSAGE("shutting down."); - - if(dc) { /* only do clean up if we can. */ - - /* load what we can from the cache. */ - - cached_options = client_cache_load_option_string_list(dc->cache, 0); - if(cached_options != NULL) - do_sysconf_cleanup(cached_options, dc); - - cache_entry_purge_list(cached_options); - - client_release(dc); - delete_pid_file(dc->interface); - destroy_dhcp_client_control(dc); - } - - exit(0); - } - /* check for existing client. */ static int client_process_exists(char *interface) --- 144,147 ---- *************** *** 198,204 **** if(active) ! interface_list = interface_get_active_interfaces(); else ! interface_list = interface_get_inactive_interfaces(); if(interface_list == NULL) --- 179,185 ---- if(active) ! interface_list = rawnet_list_active_interfaces(); else ! interface_list = rawnet_list_inactive_interfaces(); if(interface_list == NULL) *************** *** 242,246 **** if(want_shutdown) ! do_shutdown(dc); /* if we're only running to be setup, --- 223,227 ---- if(want_shutdown) ! client_states[STATE_DO_SHUTDOWN](dc); /* if we're only running to be setup, *************** *** 322,326 **** /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc); /* now delete. */ --- 303,307 ---- /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc->interface); /* now delete. */ *************** *** 404,408 **** if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting."); ! do_shutdown(NULL); } --- 385,389 ---- if((dc = create_dhcp_client_control(interface, promiscuous)) == ... [truncated message content] |