[dhcp-agent-commits] dhcp-agent/src dhcp-client-conf.c,1.28,1.29 dhcp-client-conf.h,1.18,1.19 dhcp-o
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv7174/src Modified Files: dhcp-client-conf.c dhcp-client-conf.h dhcp-option-convert.c dhcp-option.c dhcp-option.h dhcp-sysconf.c Log Message: prepend, append, override now hooked into sysconf Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** dhcp-client-conf.c 23 Jun 2003 06:04:33 -0000 1.28 --- dhcp-client-conf.c 27 Jun 2003 03:16:27 -0000 1.29 *************** *** 734,737 **** --- 734,755 ---- * * * * * * */ + /* get options to override. */ + list_t *client_conf_get_override_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + return cc->params->override_options; + } + + /* get options to append. */ + list_t *client_conf_get_append_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + return cc->params->append_options; + } + + /* get options to prepend. */ + list_t *client_conf_get_prepend_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + return cc->params->prepend_options; + } + /* get parameters to request: this is always from the top level. */ uint8_t *client_conf_get_request_opt_bit_array(client_conf_t *cc) *************** *** 1013,1018 **** } ! static int directive_user_defined_option_handler_proc(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data, ! int var_type) { char *option_name; --- 1031,1037 ---- } ! static int directive_user_defined_option_handler_proc(client_conf_params_t *params, void *directive_data, ! directive_group_t group_type, void *group_data, ! int var_type) { char *option_name; Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-client-conf.h 23 Jun 2003 06:04:33 -0000 1.18 --- dhcp-client-conf.h 27 Jun 2003 03:16:27 -0000 1.19 *************** *** 96,99 **** --- 96,102 ---- extern int client_conf_reread(client_conf_t *cc); + extern list_t *client_conf_get_override_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); + extern list_t *client_conf_get_append_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); + extern list_t *client_conf_get_prepend_options(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t *client_conf_get_request_opt_bit_array(client_conf_t *cc); extern int client_conf_get_dhcp_discovery_retries(client_conf_t *cc); Index: dhcp-option-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-convert.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-option-convert.c 17 Jun 2003 07:34:16 -0000 1.5 --- dhcp-option-convert.c 27 Jun 2003 03:16:27 -0000 1.6 *************** *** 1685,1689 **** count = count_internal_string_atoms_and_mark(string_copy); ! opt->val = internal_string_list_ip_addr_to_internal(input, count); opt->num = count; --- 1685,1689 ---- count = count_internal_string_atoms_and_mark(string_copy); ! opt->val = internal_string_list_ip_addr_to_internal(string_copy, count); opt->num = count; Index: dhcp-option.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-option.c 17 Jun 2003 07:34:16 -0000 1.5 --- dhcp-option.c 27 Jun 2003 03:16:27 -0000 1.6 *************** *** 1440,1443 **** --- 1440,1444 ---- } + /* copy a dhcp option. */ dhcp_opt_t *dhcp_option_copy(dhcp_opt_t *option) { *************** *** 1447,1448 **** --- 1448,1498 ---- } + /* append to a dhcp list datum. */ + void dhcp_option_append(dhcp_opt_t *orig, dhcp_opt_t *data) + { + + uint8_t *new_data, *orig_data; + list_t *orig_list, *append_list; + dhcp_opt_len_t len; + + orig_list = dhcp_opt_get_host_data(orig); + append_list = dhcp_opt_get_host_data(data); + len = dhcp_opt_get_mem_len(orig); + + list_rewind(append_list); + while((orig_data = list_next(append_list)) != NULL) { + + new_data = xmalloc(len); + memcpy(new_data, orig_data, len); + + list_add_to_end(orig_list, new_data); + orig->num++; + } + + return; + } + + /* prepend to a dhcp list datum. */ + void dhcp_option_prepend(dhcp_opt_t *orig, dhcp_opt_t *data) + { + + uint8_t *new_data, *orig_data; + list_t *orig_list, *prepend_list; + dhcp_opt_len_t len; + + orig_list = dhcp_opt_get_host_data(orig); + prepend_list = dhcp_opt_get_host_data(data); + len = dhcp_opt_get_mem_len(orig); + + list_rewind(prepend_list); + while((orig_data = list_next(prepend_list)) != NULL) { + + new_data = xmalloc(len); + memcpy(new_data, orig_data, len); + + list_add(orig_list, new_data); + orig->num++; + } + + return; + } Index: dhcp-option.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-option.h 17 Jun 2003 07:34:16 -0000 1.5 --- dhcp-option.h 27 Jun 2003 03:16:27 -0000 1.6 *************** *** 49,52 **** --- 49,55 ---- extern dhcp_opt_t *dhcp_opt_create_parameter_request_list(uint8_t *requested_options); + extern void dhcp_option_append(dhcp_opt_t *orig, dhcp_opt_t *data); + extern void dhcp_option_prepend(dhcp_opt_t *orig, dhcp_opt_t *data); + /* constants. */ *************** *** 83,85 **** #endif /* DHCP_OPTION_H */ - --- 86,87 ---- Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-sysconf.c 25 Jun 2003 02:38:02 -0000 1.20 --- dhcp-sysconf.c 27 Jun 2003 03:16:27 -0000 1.21 *************** *** 41,44 **** --- 41,119 ---- #include "dhcp-client-guile.h" + /* override, prepend, and append to options. */ + + /* do overrides. */ + static void sysconf_override(list_t *options, list_t *overrides) + { + dhcp_opt_t *orig, *override; + + /* walk down list and override where necessary. since we're + * overriding the options list and will be rewriting it we + * need to loop on overrides in order to avoid looping + * indefinetly. unfortunately this gives us the worest case + * scenario in terms of cpu time. FIXME: write a + * list_replace_datum routine */ + + list_rewind(overrides); + while((override = list_next(overrides)) != NULL) { + + list_rewind(options); + while((orig = list_next(options)) != NULL) { + + if(DHCP_OPT_GET_TAG(override) == DHCP_OPT_GET_TAG(orig)) { + + list_remove_by_datum(options, orig); + DHCP_OPT_DESTROY(orig); + + list_add(options, dhcp_option_copy(override)); + break; + } + } + } + + return; + } + + static void sysconf_prepend_or_append_proc(list_t *options, list_t *add_options, + void (*add)(dhcp_opt_t *orig, dhcp_opt_t *add)) + { + dhcp_opt_t *orig, *add_opt; + + /* walk down list and do addition where necessary. */ + list_rewind(options); + while((orig = list_next(options)) != NULL) { + + list_rewind(add_options); + while((add_opt = list_next(add_options)) != NULL) { + + if(DHCP_OPT_GET_TAG(orig) == DHCP_OPT_GET_TAG(add_opt)) { + + /* we already know that the conf code guarantees + * we're only dealing with list types. no need to + * double check here. */ + + add(orig, add_opt); + break; + } + } + } + + return; + } + + /* do prepends. */ + static void sysconf_prepend(list_t *options, list_t *prepends) + { + sysconf_prepend_or_append_proc(options, prepends, dhcp_option_prepend); + return; + } + + /* do appends. */ + static void sysconf_append(list_t *options, list_t *appends) + { + sysconf_prepend_or_append_proc(options, appends, dhcp_option_append); + return; + } + /* * * * * * * * * * * * * Sysconf interface. * *************** *** 47,50 **** --- 122,144 ---- void do_sysconf(list_t *options, dhcp_client_control_t *dc, int state) { + list_t *overrides, *prepends, *appends; + + overrides = client_conf_get_override_options(dc->conf, + dhcp_client_get_server_ip_address(dc), + dhcp_client_get_server_hw_address(dc)); + + sysconf_override(options, overrides); + + prepends = client_conf_get_append_options(dc->conf, + dhcp_client_get_server_ip_address(dc), + dhcp_client_get_server_hw_address(dc)); + sysconf_prepend(options, prepends); + + appends = client_conf_get_prepend_options(dc->conf, + dhcp_client_get_server_ip_address(dc), + dhcp_client_get_server_hw_address(dc)); + sysconf_append(options, appends); + + return dhcp_sysconf_guile(dc, options, state); } |