[dhcp-agent-commits] dhcp-agent/src dhcp-cache-entry.c,1.3,1.4 dhcp-cache-entry.h,1.2,1.3 dhcp-clien
Status: Alpha
Brought to you by:
actmodern
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); } } |