dhcp-agent-commits Mailing List for dhcp-agent (Page 21)
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
|
From: <act...@us...> - 2003-03-30 04:34:04
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv4280 Modified Files: TODO Log Message: more stuff todo Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TODO 3 Jan 2003 21:28:56 -0000 1.7 --- TODO 30 Mar 2003 04:34:00 -0000 1.8 *************** *** 68,72 **** -- check for race condition -- even if it is tiny -- in client_wait ! -- make a distinction between SELECT and INIT-REBOOT. right now we have a single client_request_ack routine -- complete client-conf code. define the prototype for a hook and --- 68,73 ---- -- check for race condition -- even if it is tiny -- in client_wait ! -- make a distinction between SELECT and INIT-REBOOT. right now we have a ! single client_request_ack routine -- complete client-conf code. define the prototype for a hook and *************** *** 74,75 **** --- 75,103 ---- -- write dhcp-sysconf to allow configuration via a small minimalistic interpreter + + -- check if we handle 0xffffffff timers right. + + -- in dhcp-tokenizer use mmap() to implement nicer peeking. + + -- check types used in client conf code. fix problem assignments + where necessary. + + -- find out why dnet is acting a little silly with aliased interfaces. + + -- we're using bit (really byte) arrays to hold an option list in + many places in the code where this is useful. it may be + prudent to capsulate this as an object in its own right. + + -- client-conf limitiation. append/prepend options may not + contain semicolons in lists. append/prepend/override can't + tell the difference between a single value and a list. this + causes problem because we cannot cleanly link this into the + soon-to-be-written guile recipes. need a way to represent + options better. + + -- subnet mask must be first option if router option is set. + + -- need a whole new way to look at dhcp option. a dhcp_option + object which does a lot more and is abstracted from a lot of + the other code. + |
From: <act...@us...> - 2003-03-27 01:39:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv13664 Modified Files: dhcp-client-conf.c dhcp-client-conf.h Log Message: added override Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-client-conf.c 26 Mar 2003 05:23:02 -0000 1.21 --- dhcp-client-conf.c 27 Mar 2003 01:39:16 -0000 1.22 *************** *** 124,127 **** --- 124,131 ---- static const arg_symbol_t *prepend_arg_symbols[] = { NULL, NULL, NULL }; + static const arg_type_t override_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST }; + static const char **override_arg_strings[] = { NULL, NULL, NULL }; + static const arg_symbol_t *override_arg_symbols[] = { NULL, NULL, NULL }; + static const arg_type_t server_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_GROUP }; static const char **server_arg_strings[] = { server_strings, NULL, NULL }; *************** *** 200,204 **** }; - /* prepend command. */ static const command_t command_prepend = { --- 204,207 ---- *************** *** 211,214 **** --- 214,227 ---- }; + /* prepend command. */ + static const command_t command_override = { + DIRECTIVE_OVERRIDE, + "override", + 3, + override_arg_strings, + override_arg_types, + override_arg_symbols, + }; + static const command_t *commands[] = { &command_set_boolean, *************** *** 220,223 **** --- 233,237 ---- &command_append, &command_prepend, + &command_override, NULL, }; *************** *** 234,237 **** --- 248,252 ---- static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); + static int directive_override_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 245,248 **** --- 260,264 ---- directive_append_handler, directive_prepend_handler, + directive_override_handler, }; *************** *** 622,625 **** --- 638,642 ---- params->append_options = list_create(); params->prepend_options = list_create(); + params->override_options = list_create(); return params; *************** *** 634,637 **** --- 651,655 ---- list_destroy(params->append_options, cache_entry_destroy_l); list_destroy(params->prepend_options, cache_entry_destroy_l); + list_destroy(params->override_options, cache_entry_destroy_l); xfree(params); *************** *** 890,893 **** --- 908,915 ---- break; + case CLIENT_VAR_OVERRIDE_OPTIONS: + list_add(params->override_options, ce); + break; + default: FATAL_MESSAGE("i have encountered a bug. i shouldn't be here."); *************** *** 905,908 **** --- 927,935 ---- { return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_PREPEND_OPTIONS); + } + + static int directive_override_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) + { + return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_OVERRIDE_OPTIONS); } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-conf.h 26 Mar 2003 05:23:02 -0000 1.13 --- dhcp-client-conf.h 27 Mar 2003 01:39:16 -0000 1.14 *************** *** 55,58 **** --- 55,59 ---- list_t *append_options; /* options append values to. */ list_t *prepend_options; /* options prepend values to. */ + list_t *override_options; /* options override values. */ } client_conf_params_t; *************** *** 74,78 **** /* directive types. */ enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, ! DIRECTIVE_CONFIGURE, DIRECTIVE_APPEND, DIRECTIVE_PREPEND }; /* symbols for variable substitution. */ --- 75,79 ---- /* directive types. */ enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, ! DIRECTIVE_CONFIGURE, DIRECTIVE_APPEND, DIRECTIVE_PREPEND, DIRECTIVE_OVERRIDE }; /* symbols for variable substitution. */ *************** *** 80,84 **** CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS, CLIENT_VAR_APPEND_OPTIONS, ! CLIENT_VAR_PREPEND_OPTIONS }; /* server symbol substitution. */ --- 81,85 ---- CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS, CLIENT_VAR_APPEND_OPTIONS, ! CLIENT_VAR_PREPEND_OPTIONS, CLIENT_VAR_OVERRIDE_OPTIONS }; /* server symbol substitution. */ |
From: <act...@us...> - 2003-03-26 05:23:05
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv26563 Modified Files: dhcp-client-conf.c dhcp-client-conf.h Log Message: added prepend/append to client-conf Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-client-conf.c 25 Mar 2003 20:26:47 -0000 1.20 --- dhcp-client-conf.c 26 Mar 2003 05:23:02 -0000 1.21 *************** *** 620,623 **** --- 620,625 ---- params->variables = list_create(); params->lower_params = list_create(); + params->append_options = list_create(); + params->prepend_options = list_create(); return params; *************** *** 630,633 **** --- 632,637 ---- list_destroy(params->variables, dhcp_conf_var_destroy_l); list_destroy(params->lower_params, params_destroy_l); + list_destroy(params->append_options, cache_entry_destroy_l); + list_destroy(params->prepend_options, cache_entry_destroy_l); xfree(params); *************** *** 809,820 **** } ! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { return 0; } static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return 0; } --- 813,908 ---- } ! static int directive_static_cache_entry_handler_proc(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data, ! int var_type) { + char *option_name; + list_t *option_data_list; + char *data; + stringbuffer_t *sb; + cache_entry_t *ce = NULL; + directive_t *directive = directive_data; + uint8_t i; + + const char **option_strings = dhcp_option_conf_string_get_array(); + + option_name = list_first(directive->arguments); + option_data_list = list_get_by_index(directive->arguments, 2); + + + for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { + + if(!strcmp(option_strings[i], option_name)) { + + /* found a match. create cache entry and break out.*/ + + /* FIXME: a ";" will wreck havoc on conversion list routines by causing them to split a datum. + * this a limitation because dhcp-convert.c was never written to take in string form. it was always + * assumed that this data came in from the network in network form. */ + + /* more hackery. there are two versions of + * options. those with lists and those without. we + * actually can't tell the difference from here + * (FIXME: we should) so we check the list length. if + * it's more than one we append with a semicolon, and + * loop. otherwise we just pass. */ + + if(list_get_len(option_data_list) == 1) { + + /* just pass data . */ + data = list_first(option_data_list); + ce = create_cache_entry(i, dhcp_option_printable_string_get(i), data); + break; /* done. */ + + } else { + + /* create a list out of it just dhcp-convert would. + * this is too much hackery and needs to go soon. */ + + sb = stringbuffer_create(); + + while((data = list_next(option_data_list)) != NULL) { + stringbuffer_aprintf(sb, "%s;", data); + } + + ce = create_cache_entry(i, dhcp_option_printable_string_get(i), xstrdup(stringbuffer_getstring(sb))); + stringbuffer_destroy(sb); + + break; /* done. */ + } + } + } + + if(ce == NULL) { + ERROR_MESSAGE("unknown option %s to append/prepend", option_name); + return 1; + } + + /* check to make sure option name is valid. */ + + switch(var_type) { + + case CLIENT_VAR_APPEND_OPTIONS: + list_add(params->append_options, ce); + break; + + case CLIENT_VAR_PREPEND_OPTIONS: + list_add(params->prepend_options, ce); + break; + + default: + FATAL_MESSAGE("i have encountered a bug. i shouldn't be here."); + } + return 0; } + static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) + { + return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_APPEND_OPTIONS); + } + static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_PREPEND_OPTIONS); } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-conf.h 25 Mar 2003 20:26:50 -0000 1.12 --- dhcp-client-conf.h 26 Mar 2003 05:23:02 -0000 1.13 *************** *** 53,57 **** list_t *variables; /* variables of type var_t. */ list_t *lower_params; /* linked list to child parameters. */ ! } client_conf_params_t; --- 53,59 ---- list_t *variables; /* variables of type var_t. */ list_t *lower_params; /* linked list to child parameters. */ ! list_t *append_options; /* options append values to. */ ! list_t *prepend_options; /* options prepend values to. */ ! } client_conf_params_t; *************** *** 77,81 **** enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, ! CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS }; /* server symbol substitution. */ --- 79,84 ---- enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, ! CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS, CLIENT_VAR_APPEND_OPTIONS, ! CLIENT_VAR_PREPEND_OPTIONS }; /* server symbol substitution. */ |
From: <act...@us...> - 2003-03-26 03:45:41
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv2293 Modified Files: dhcp-convert.c Log Message: typo fix Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-convert.c 2 Jan 2003 04:23:01 -0000 1.8 --- dhcp-convert.c 26 Mar 2003 03:45:35 -0000 1.9 *************** *** 400,404 **** uint32_t *addr; list_t *addr_list = NULL; ! char *cp, *tmp_string, *orig_string;; addr_list = list_create(); --- 400,404 ---- uint32_t *addr; list_t *addr_list = NULL; ! char *cp, *tmp_string, *orig_string; addr_list = list_create(); |
From: <act...@us...> - 2003-03-25 20:29:24
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10086 Modified Files: dhcp-client-states.c Log Message: brought in line with recent conf changes; client_check_requested_options now checks required configuration or falls back on requested configuration Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** dhcp-client-states.c 25 Mar 2003 03:06:42 -0000 1.25 --- dhcp-client-states.c 25 Mar 2003 20:29:16 -0000 1.26 *************** *** 176,190 **** char *ip_addr_string; uint8_t *required_options; ! uint8_t received_options[MAX_OPTIONS_HANDLED + 1]; dhcp_option_t *dhcp_option; int i; /* get the mac address, and ip address from the packet. */ - ip_addr = ip_get_src_addr(dc->rawnet->ip_p); eth_addr = eth_get_src_addr(dc->rawnet->ether_p); ! /* build our received options array. */ memset(received_options, 0, sizeof(received_options)); dhcp_reset_option_seek(dc->rawnet->dhcp_p); --- 176,198 ---- char *ip_addr_string; uint8_t *required_options; ! uint8_t received_options[MAX_OPTIONS_HANDLED_NUM]; dhcp_option_t *dhcp_option; int i; /* get the mac address, and ip address from the packet. */ ip_addr = ip_get_src_addr(dc->rawnet->ip_p); eth_addr = eth_get_src_addr(dc->rawnet->ether_p); ! /* find out if we have a list of required options. */ ! required_options = client_conf_get_opt_required_bit_array(dc->conf, ip_addr, eth_addr); + if(required_options == NULL) { + /* if not we ask for our requested options and pick from there. */ + /* FIXME: it should be configurable that we accept any response. */ + WARN_MESSAGE("requiring all requested options since no required options have been configured explicity."); + required_options = client_conf_get_request_opt_bit_array(dc->conf); + } + + /* build our received options array. */ memset(received_options, 0, sizeof(received_options)); dhcp_reset_option_seek(dc->rawnet->dhcp_p); *************** *** 200,206 **** received_options[dhcp_option->tag] = 1; } - - /* now ask client-conf if we have the required options. */ - required_options = client_conf_get_opt_required_bit_array(dc->conf, ip_addr, eth_addr); /* make sure everything in our required option list is in our requested option list. */ --- 208,211 ---- |
From: <act...@us...> - 2003-03-25 20:28:10
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9109 Modified Files: dhcp-com.c dhcp-limits.h Log Message: MAX_OPTIONS_HANDLED now has a NUM counterpat. this fixes off by one errors in the past Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-com.c 2 Jan 2003 04:23:01 -0000 1.8 --- dhcp-com.c 25 Mar 2003 20:27:46 -0000 1.9 *************** *** 456,460 **** /* Grab length so we can just malloc all at once. */ ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) len++; --- 456,460 ---- /* Grab length so we can just malloc all at once. */ ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) len++; *************** *** 472,476 **** j = 0; ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { option->data[j] = i; --- 472,476 ---- j = 0; ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { option->data[j] = i; Index: dhcp-limits.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-limits.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-limits.h 3 Jan 2003 21:29:22 -0000 1.4 --- dhcp-limits.h 25 Mar 2003 20:27:47 -0000 1.5 *************** *** 44,46 **** --- 44,48 ---- #define MAX_OPTIONS_HANDLED 74 /* including 0 for PAD which we never care about. */ + #define MAX_OPTIONS_HANDLED_NUM (74 +1) /* MAX_OPTIONS_HANDLED + 1 options total since we include PAD (0). */ + #endif /* DHCP_LIMITS_H */ |
From: <act...@us...> - 2003-03-25 20:27:02
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv8458 Modified Files: dhcp-client-conf.c dhcp-client-conf.h Log Message: now using defaults for requested options; also several other fixes Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-client-conf.c 25 Mar 2003 03:06:18 -0000 1.19 --- dhcp-client-conf.c 25 Mar 2003 20:26:47 -0000 1.20 *************** *** 223,241 **** }; - /* 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. */ --- 223,226 ---- *************** *** 262,274 **** }; /* * * * * * * * * * * * utility routines * * * * * * * * * * * */ /* search through a list of conf variables and return if the type * is found. this is useful for overwriting variables: this is * slow however we assume we're not doing configuration variables * in excess of twenty or so in most situations. */ - static conf_var_t *find_conf_var(var_type_t var_type, list_t *var_list) { --- 247,304 ---- }; + /* 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. */ + }; + /* * * * * * * * * * * * utility routines * * * * * * * * * * * */ + static void configure_default_request_options(client_conf_t *cc) + { + conf_var_t *var; + uint8_t *default_request_options; + int i; + + default_request_options = xcalloc(MAX_OPTIONS_HANDLED_NUM * sizeof(uint8_t)); + + for(i = 0; i < NELMS(default_config_options); i++) { + default_request_options[default_config_options[i]] = 1; + } + + var = dhcp_conf_var_create(CLIENT_VAR_REQUEST_OPTIONS, default_request_options); + list_add(cc->params->variables, var); + + return; + } + + /* merge two bit arrays into dest. */ + static void merge_bit_arrays(uint8_t *dest, uint8_t *src, int len) + { + int i; + + for(i = 0; i < len; i++) { + if(src[i]) + dest[i] = 1; + } + + return; + } + /* search through a list of conf variables and return if the type * is found. this is useful for overwriting variables: this is * slow however we assume we're not doing configuration variables * in excess of twenty or so in most situations. */ static conf_var_t *find_conf_var(var_type_t var_type, list_t *var_list) { *************** *** 285,288 **** --- 315,319 ---- } + /* add variable or replace existing one. */ static void add_or_replace_var(list_t *variables, conf_var_t *var) { *************** *** 306,309 **** --- 337,366 ---- } + /* add or overwrite the bit array option. */ + static void add_or_overwrite_bit_array_var(list_t *variables, uint8_t *new_array, var_type_t var_type) + { + conf_var_t *cur_var; + uint8_t *old_array; + + /* see if this is already set.*/ + cur_var = find_conf_var(var_type, variables); + + /* if not add. */ + if(cur_var == NULL) { + + cur_var = dhcp_conf_var_create(var_type, new_array); + list_add(variables, cur_var); + + } else { + + old_array = dhcp_conf_var_get_val(cur_var); + merge_bit_arrays(old_array, new_array, MAX_OPTIONS_HANDLED_NUM); + xfree(new_array); /* free up since we're not replacing with it. */ + + } + + return; + } + /* search through lower params and return the first match. */ static client_conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr) *************** *** 348,358 **** { char *option_string; - const char **option_strings = dhcp_option_conf_string_get_array(); int i; list_rewind(strings); while((option_string = list_next(strings)) != NULL) { ! for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { if(!strcmp(option_strings[i], option_string)) { --- 405,415 ---- { char *option_string; int i; + const char **option_strings = dhcp_option_conf_string_get_array(); list_rewind(strings); while((option_string = list_next(strings)) != NULL) { ! for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(!strcmp(option_strings[i], option_string)) { *************** *** 406,412 **** case CLIENT_VAR_INTERFACE_MTU: uint16_val = string_to_uint16(var_value); ! var = dhcp_conf_var_create(var_symbol, uint16_val); ! break; default: --- 463,472 ---- case CLIENT_VAR_INTERFACE_MTU: uint16_val = string_to_uint16(var_value); ! if(uint16_val != NULL) { ! var = dhcp_conf_var_create(var_symbol, uint16_val); ! break; ! } + /* fall through. */ default: *************** *** 419,422 **** --- 479,483 ---- } + /* setup a boolean variable. */ static int client_conf_set_variable_boolean(client_conf_params_t *params, arg_symbol_t var_symbol, uint8_t bool_val) { *************** *** 709,713 **** list_t *string_list; uint8_t *options; - conf_var_t *var; /* the first argument is the string list we want. */ --- 770,773 ---- *************** *** 716,720 **** /* create bit array. */ ! options = xmalloc(sizeof(uint8_t) * MAX_OPTIONS_HANDLED); if(client_conf_fill_option_bit_array_from_string_list(string_list, options)) { --- 776,780 ---- /* create bit array. */ ! options = xcalloc(MAX_OPTIONS_HANDLED_NUM * sizeof(uint8_t)); if(client_conf_fill_option_bit_array_from_string_list(string_list, options)) { *************** *** 723,728 **** } ! var = dhcp_conf_var_create(type, options); ! add_or_replace_var(params->variables, var); return 0; --- 783,787 ---- } ! add_or_overwrite_bit_array_var(params->variables, options, type); return 0; *************** *** 738,742 **** static int directive_require_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { - return directive_option_array_handler_proc(params, directive_data, group_type, group_data, --- 797,800 ---- *************** *** 837,840 **** --- 895,901 ---- cc->params = params_create(); /* set top level to catchall group. */ cc->params->group_type = DIRECTIVE_GROUP_NULL; + + /* setup defaults request options: these we always request */ + configure_default_request_options(cc); if(client_conf_load_options(cc)) { Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client-conf.h 25 Mar 2003 03:06:19 -0000 1.11 --- dhcp-client-conf.h 25 Mar 2003 20:26:50 -0000 1.12 *************** *** 75,81 **** /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, ! CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, ! CLIENT_VAR_CONFIGURE_OPTIONS }; /* server symbol substitution. */ --- 75,81 ---- /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, ! CLIENT_VAR_INTERFACE_MTU, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, ! CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, CLIENT_VAR_CONFIGURE_OPTIONS }; /* server symbol substitution. */ |
From: <act...@us...> - 2003-03-25 03:07:30
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12854 Modified Files: Makefile.am Log Message: updated Makefile for new sources Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Makefile.am 3 Jan 2003 21:29:22 -0000 1.14 --- Makefile.am 25 Mar 2003 03:07:28 -0000 1.15 *************** *** 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-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.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-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.h dhcp-conf-var.h *************** *** 43,47 **** dhcp-route.c \ dhcp-interrupt.c \ ! dhcp-conf.c dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 43,48 ---- dhcp-route.c \ dhcp-interrupt.c \ ! dhcp-conf.c \ ! dhcp-conf-var.c dhcp_sniff_SOURCES = dhcp-sniff.c \ |
From: <act...@us...> - 2003-03-25 03:06:44
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12551 Modified Files: dhcp-client-states.c dhcp-sysconf.c Log Message: brought inline with new conf code Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** dhcp-client-states.c 2 Jan 2003 04:23:01 -0000 1.24 --- dhcp-client-states.c 25 Mar 2003 03:06:42 -0000 1.25 *************** *** 104,108 **** options = list_create(); ! option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); if(option == NULL) { WARN_MESSAGE("sending with empty parameter request list"); --- 104,108 ---- options = list_create(); ! option = dhcp_build_parameter_request_list_option(client_conf_get_request_opt_bit_array(dc->conf)); if(option == NULL) { WARN_MESSAGE("sending with empty parameter request list"); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-sysconf.c 3 Jan 2003 22:05:08 -0000 1.14 --- dhcp-sysconf.c 25 Mar 2003 03:06:42 -0000 1.15 *************** *** 478,483 **** * if so get the bit array. */ ! if(client_conf_get_opt_configure_set(dc->conf, dhcp_client_get_server_ip_address(dc), ! dhcp_client_get_server_hw_address(dc))) { configure_opts = client_conf_get_opt_configure_bit_array(dc->conf, --- 478,483 ---- * if so get the bit array. */ ! if(client_conf_get_opt_configure_bit_array(dc->conf, dhcp_client_get_server_ip_address(dc), ! dhcp_client_get_server_hw_address(dc))) { configure_opts = client_conf_get_opt_configure_bit_array(dc->conf, |
From: <act...@us...> - 2003-03-25 03:06:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12432 Modified Files: dhcp-client-conf.c dhcp-client-conf.h Log Message: client-conf code redo Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-client-conf.c 3 Jan 2003 22:09:44 -0000 1.18 --- dhcp-client-conf.c 25 Mar 2003 03:06:18 -0000 1.19 *************** *** 31,47 **** #include "dhcp-conf.h" #include "dhcp-client-conf.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" #include "dhcp-options-strings.h" #include "dhcp-client-defaults.h" - /* FIXME: check for destroy params mem leak. */ - /* * * * * * * * * * * * * * * * * * * * configuration grammar structures. * * * * * * * * * * * * * * * * * * * */ /* string arrays for commands. */ --- 31,58 ---- #include "dhcp-conf.h" + #include "dhcp-conf-var.h" #include "dhcp-client-conf.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" #include "dhcp-options-strings.h" + #include "dhcp-convert.h" #include "dhcp-client-defaults.h" /* * * * * * * * * * * * * * * * * * * * configuration grammar structures. * * * * * * * * * * * * * * * * * * * */ + /* + * We construct the tree for client-conf code to handle the + * grammar for us. + * + * The one limitation we have now is that the tree has branches + * from the top, the command name itself, and everything else is + * linear. This is fine for what we want to do now but it may + * need to support a more proper grammer tree for more complex + * parsing in the future. */ + + /* string arrays for commands. */ *************** *** 105,108 **** --- 116,127 ---- static const arg_symbol_t *configure_arg_symbols[] = { NULL }; + static const arg_type_t append_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST }; + static const char **append_arg_strings[] = { NULL, NULL, NULL }; + static const arg_symbol_t *append_arg_symbols[] = { NULL, NULL, NULL }; + + static const arg_type_t prepend_arg_types[] = { CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST }; + static const char **prepend_arg_strings[] = { NULL, NULL, NULL }; + static const arg_symbol_t *prepend_arg_symbols[] = { NULL, NULL, NULL }; + static const arg_type_t server_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_GROUP }; static const char **server_arg_strings[] = { server_strings, NULL, NULL }; *************** *** 151,155 **** }; ! /* request command. */ static const command_t command_configure = { DIRECTIVE_CONFIGURE, --- 170,174 ---- }; ! /* configure command. */ static const command_t command_configure = { DIRECTIVE_CONFIGURE, *************** *** 171,174 **** --- 190,214 ---- }; + /* append command. */ + static const command_t command_append = { + DIRECTIVE_APPEND, + "append", + 3, + append_arg_strings, + append_arg_types, + append_arg_symbols, + }; + + + /* prepend command. */ + static const command_t command_prepend = { + DIRECTIVE_PREPEND, + "prepend", + 3, + prepend_arg_strings, + prepend_arg_types, + prepend_arg_symbols, + }; + static const command_t *commands[] = { &command_set_boolean, *************** *** 178,181 **** --- 218,223 ---- &command_server, &command_configure, + &command_append, + &command_prepend, NULL, }; *************** *** 198,208 **** /* forward declaration of directive handlers. */ ! static int directive_group_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_set_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_set_boolean_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_request_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_require_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_server_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ --- 240,252 ---- /* forward declaration of directive handlers. */ ! static int directive_group_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_set_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_set_boolean_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_request_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_require_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_server_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_configure_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); ! static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 214,217 **** --- 258,263 ---- directive_server_handler, directive_configure_handler, + directive_append_handler, + directive_prepend_handler, }; *************** *** 220,224 **** * * * * * * * * * * */ ! static int fill_option_bit_array_from_string_list(list_t *strings, uint8_t *option_bit_array) { char *option_string; --- 266,349 ---- * * * * * * * * * * */ ! /* search through a list of conf variables and return if the type ! * is found. this is useful for overwriting variables: this is ! * slow however we assume we're not doing configuration variables ! * in excess of twenty or so in most situations. */ ! ! static conf_var_t *find_conf_var(var_type_t var_type, list_t *var_list) ! { ! conf_var_t *var; ! ! list_rewind(var_list); ! while((var = list_next(var_list)) != NULL) { ! ! if(var->type == var_type) ! return var; ! } ! ! return NULL; ! } ! ! static void add_or_replace_var(list_t *variables, conf_var_t *var) ! { ! conf_var_t *cur_var; ! ! /* see if this is already set.*/ ! cur_var = find_conf_var(var->type, variables); ! ! /* if not add. */ ! if(cur_var == NULL) { ! ! list_add(variables, var); ! ! } else { ! ! /* otherwise overwrite. */ ! dhcp_conf_var_overwrite(cur_var, var->type, var->val); ! dhcp_conf_var_destroy_no_val_free(var); /* we need to keep the value so don't free val. */ ! ! } ! } ! ! /* search through lower params and return the first match. */ ! static client_conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr) ! { ! client_conf_params_t *params = NULL; ! ! list_rewind(lower_params); ! while((params = list_next(lower_params)) != NULL) { ! ! if((memcmp(&ip, ¶ms->server_ip, sizeof(ip_addr_t)) == 0) ! || (memcmp(ð_addr, ¶ms->server_hw_addr, sizeof(eth_addr_t)) == 0)) { ! /* if a match is found break out. */ ! break; ! } else { ! /* check lower parameters too. */ ! if((params = get_params_for(params->lower_params, ip, eth_addr)) != NULL) ! break; ! } ! ! /* otherwise we keep looping. */ ! ! } ! ! return params; ! } ! ! /* utility routine to call on client_conf to find the best ! * param. this calls get_params_for on all lower parameters which is in of itself recursive. */ ! static client_conf_params_t *find_best_params_for(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) ! { ! client_conf_params_t *params; ! ! params = get_params_for(cc->params->lower_params, ip_addr, eth_addr); ! if(params == NULL) ! params = cc->params; ! ! return params; ! } ! ! /* given a list of strings identifying options we fill a bit array that references the option by the index. */ ! static int client_conf_fill_option_bit_array_from_string_list(list_t *strings, uint8_t *option_bit_array) { char *option_string; *************** *** 227,231 **** list_rewind(strings); ! for(option_string = list_next(strings); option_string; option_string = list_next(strings)) { for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { --- 352,356 ---- list_rewind(strings); ! while((option_string = list_next(strings)) != NULL) { for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { *************** *** 246,304 **** } ! static int client_conf_set_variable(conf_params_t *params, arg_symbol_t var_symbol, const char *var_value) { - /* FIXME: insert sanity checks on data. */ switch(var_symbol) { ! case CLIENT_VAR_HOSTNAME: ! ! if(params->client_hostname != NULL) { ! xfree(params->client_hostname); ! params->client_hostname = NULL; ! } ! params->client_hostname = xstrdup(var_value); break; - ! case CLIENT_VAR_DHCP_DISCOVERY_RETRIES: ! ! params->dhcp_discovery_retries = atoi(var_value); ! break; case CLIENT_VAR_ICMP_RETRIES: ! params->icmp_retries = atoi(var_value); ! params->icmp_retries_set = 1; break; case CLIENT_VAR_INTERFACE_MTU: ! ! params->default_interface_mtu = atoi(var_value); break; default: return 1; } return 0; } ! static int client_conf_set_variable_boolean(conf_params_t *params, arg_symbol_t var_symbol, uint8_t bool_val) { ! switch(var_symbol) { ! ! case CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP: ! ! params->do_measure_router_latency_icmp = bool_val; ! params->do_measure_router_latency_icmp_set = 1; ! break; ! ! default: ! return 1; ! } return 0; --- 371,432 ---- } ! /* setup a variable in params_t. */ ! static int client_conf_set_variable(client_conf_params_t *params, arg_symbol_t var_symbol, const char *var_value) { + conf_var_t *var = NULL; + int *int_val; + uint16_t *uint16_val; switch(var_symbol) { ! /* string types can be created with no checking. ! * just attempt a copy (will exit on failure). */ ! case CLIENT_VAR_HOSTNAME: ! var = dhcp_conf_var_create(var_symbol, xstrdup(var_value)); break; ! /* integer values greater than zero. use unsigned check ! * to prevent negative values. */ + case CLIENT_VAR_DHCP_DISCOVERY_RETRIES: case CLIENT_VAR_ICMP_RETRIES: ! if(!is_signed_numeric(var_value)) { ! ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value); ! return 1; ! } ! ! int_val = xmalloc(sizeof(int)); ! *int_val = atoi(var_value); ! ! var = dhcp_conf_var_create(var_symbol, int_val); break; case CLIENT_VAR_INTERFACE_MTU: ! uint16_val = string_to_uint16(var_value); ! var = dhcp_conf_var_create(var_symbol, uint16_val); break; default: + + ERROR_MESSAGE("unable to understand assignment value of : %s\n", var_value); return 1; } + add_or_replace_var(params->variables, var); return 0; } ! static int client_conf_set_variable_boolean(client_conf_params_t *params, arg_symbol_t var_symbol, uint8_t bool_val) { + conf_var_t *var = NULL; + uint8_t *val; ! val = xmalloc(sizeof(uint8_t)); ! *val = bool_val; ! var = dhcp_conf_var_create(var_symbol, val); ! add_or_replace_var(params->variables, var); return 0; *************** *** 319,322 **** --- 447,524 ---- } + static uint8_t *get_conf_bit_array_var(client_conf_params_t *params, var_type_t var_type) + { + conf_var_t *var; + uint8_t *bit_array = NULL; + + var = find_conf_var(var_type, params->variables); + + if(var != NULL) + bit_array = dhcp_conf_var_get_val(var); + + return bit_array; + } + + static int get_conf_int_var(client_conf_params_t *params, var_type_t var_type, int default_val) + { + conf_var_t *var; + int *retries = NULL; + + var = find_conf_var(var_type, params->variables); + + if(var != NULL) + retries = dhcp_conf_var_get_val(var); + + if(retries) + return *retries; + else + return default_val; + } + + static uint8_t get_conf_bool_val(client_conf_params_t *params, var_type_t var_type, uint8_t default_val) + { + conf_var_t *var; + uint8_t *bool_val = NULL; + + var = find_conf_var(var_type, params->variables); + + if(var != NULL) + bool_val = dhcp_conf_var_get_val(var); + + if(bool_val) + return *bool_val; + else + return default_val; + } + + static uint16_t get_conf_uint16_val(client_conf_params_t *params, var_type_t var_type, uint16_t default_val) + { + conf_var_t *var; + uint16_t *uint16_val = NULL; + + var = find_conf_var(var_type, params->variables); + + if(var != NULL) + uint16_val = dhcp_conf_var_get_val(var); + + if(uint16_val) + return *uint16_val; + else + return default_val; + } + + static const char *get_conf_string_val(client_conf_params_t *params, var_type_t var_type) + { + conf_var_t *var; + const char *string_val = NULL; + + var = find_conf_var(var_type, params->variables); + + if(var != NULL) + string_val = dhcp_conf_var_get_val(var); + + return string_val; + } + static int client_conf_load_options(client_conf_t *cc) { *************** *** 336,340 **** /* read compiled directives. */ ! if(directive_group_handler(&cc->parameters, conf->directives, DIRECTIVE_GROUP_NULL, NULL)) { conf_destroy(conf); return 1; --- 538,542 ---- /* read compiled directives. */ ! if(directive_group_handler(cc->params, conf->directives, DIRECTIVE_GROUP_NULL, NULL)) { conf_destroy(conf); return 1; *************** *** 345,373 **** } ! /* search through lower params and return best match. */ ! static conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr) { ! /* FIXME: this is broken -- needs to be fixed up. */ ! conf_params_t *params; ! list_rewind(lower_params); ! while((params = list_next(lower_params)) != NULL) { ! if(params->group_type == DIRECTIVE_GROUP_IP_ADDRESS && ! (ip == params->server_ip)) { ! return params; ! } ! if(params->group_type == DIRECTIVE_GROUP_MAC_ADDRESS && ! (!memcmp(eth_addr.data, params->server_hw_addr.data, ETH_ADDR_LEN))) { ! return params; ! } ! /* recursively check lower parameters too. */ ! if((params = get_params_for(params->lower_params, ip, eth_addr)) != NULL) ! return params; ! } ! return NULL; } --- 547,582 ---- } ! /* * * * * * * * * * * * * * * * * * * ! * params constructors/destructors * ! * * * * * * * * * * * * * * * * * * */ ! ! static client_conf_params_t *params_create(void) { ! client_conf_params_t *params; ! params = xmalloc(sizeof(client_conf_params_t)); ! params->group_type = DIRECTIVE_GROUP_NULL; ! params->variables = list_create(); ! params->lower_params = list_create(); ! return params; ! } ! static void params_destroy_l(void *data) ! { ! client_conf_params_t *params = data; ! list_destroy(params->variables, dhcp_conf_var_destroy_l); ! list_destroy(params->lower_params, params_destroy_l); ! xfree(params); ! } ! ! ! static void params_destroy(client_conf_params_t *params) ! { ! /* call recursive function to destroy it and everything under it. */ ! params_destroy_l(params); ! return; } *************** *** 376,389 **** * * * * * * */ ! /* get parameters to request: ip and eth addr silently ignored. */ ! uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) { ! return cc->parameters.request_options; } ! /* get number of retries for dhcp: ip and eth addr silently ignored. */ int client_conf_get_dhcp_discovery_retries(client_conf_t *cc) { ! return cc->parameters.dhcp_discovery_retries; } --- 585,598 ---- * * * * * * */ ! /* get parameters to request: this is always from the top level. */ ! uint8_t *client_conf_get_request_opt_bit_array(client_conf_t *cc) { ! return get_conf_bit_array_var(cc->params, CLIENT_VAR_REQUEST_OPTIONS); } ! /* get number of retries for dhcp: this is always from the top level. */ int client_conf_get_dhcp_discovery_retries(client_conf_t *cc) { ! return get_conf_int_var(cc->params, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_DEFAULT_DHCP_DISCOVERY_RETRIES); } *************** *** 391,414 **** uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! conf_params_t *params; ! ! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); ! ! if(params != NULL && params->required_set) ! return params->required_options; ! else ! return cc->parameters.required_options; ! } ! ! uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) ! { ! conf_params_t *params; ! ! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); ! ! if(params != NULL && params->configure_set) ! return 1; ! else ! return cc->parameters.configure_set; } --- 600,605 ---- uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr); ! return get_conf_bit_array_var(params, CLIENT_VAR_REQUIRE_OPTIONS); } *************** *** 416,427 **** uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! conf_params_t *params; ! ! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); ! ! if(params != NULL && params->configure_set) ! return params->configure_options; ! else ! return cc->parameters.configure_options; } --- 607,612 ---- uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr); ! return get_conf_bit_array_var(params, CLIENT_VAR_CONFIGURE_OPTIONS); } *************** *** 429,459 **** int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! conf_params_t *params; ! ! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); ! ! if(params != NULL && params->icmp_retries_set) ! return params->icmp_retries; ! else ! return cc->parameters.icmp_retries; } ! /* get the hostname option the client should set. */ const char *client_conf_get_hostname(client_conf_t *cc) { ! return cc->parameters.client_hostname; } ! /* get the hostname option the client should set. */ uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! conf_params_t *params; ! ! params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); ! ! if(params != NULL && params->do_measure_router_latency_icmp_set) ! return params->do_measure_router_latency_icmp; ! else ! return cc->parameters.do_measure_router_latency_icmp; } --- 614,632 ---- int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr); ! return get_conf_int_var(params, CLIENT_VAR_ICMP_RETRIES, CLIENT_DEFAULT_ICMP_RETRIES); } ! /* get the hostname option the client should set: always from the top level */ const char *client_conf_get_hostname(client_conf_t *cc) { ! return get_conf_string_val(cc->params, CLIENT_VAR_HOSTNAME); } ! /* find out whether or not we should attempt to measure router latency. */ uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) { ! client_conf_params_t *params = find_best_params_for(cc, ip_addr, eth_addr); ! return get_conf_bool_val(params, CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP); } *************** *** 461,465 **** int client_conf_get_default_mtu(client_conf_t *cc) { ! return cc->parameters.default_interface_mtu; } --- 634,638 ---- int client_conf_get_default_mtu(client_conf_t *cc) { ! return get_conf_uint16_val(cc->params, CLIENT_VAR_INTERFACE_MTU, CLIENT_DEFAULT_MTU); } *************** *** 468,472 **** * * * * * * * * * * * */ ! static int directive_group_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { list_t *directive_list; --- 641,645 ---- * * * * * * * * * * * */ ! static int directive_group_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { list_t *directive_list; *************** *** 507,511 **** } ! static int directive_set_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { directive_t *directive = directive_data; --- 680,684 ---- } ! static int directive_set_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { directive_t *directive = directive_data; *************** *** 527,562 **** } ! static int directive_request_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { directive_t *directive = directive_data; list_t *args; list_t *string_list; args = directive->arguments; string_list = list_first(args); ! if(fill_option_bit_array_from_string_list(string_list, params->request_options)) return 1; return 0; } ! static int directive_require_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! directive_t *directive = directive_data; ! list_t *args; ! list_t *string_list; ! args = directive->arguments; ! string_list = list_first(args); ! if(fill_option_bit_array_from_string_list(string_list, params->required_options)) ! return 1; ! params->required_set = 1; return 0; } ! static int directive_server_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { list_t *args; --- 700,765 ---- } ! /* procified routine for request/require/configure etc: these all deal with bit arrays. */ ! static int directive_option_array_handler_proc(client_conf_params_t *params, void *directive_data, ! directive_group_t group_type, void *group_data, ! var_type_t type) { directive_t *directive = directive_data; list_t *args; list_t *string_list; + uint8_t *options; + conf_var_t *var; + /* the first argument is the string list we want. */ args = directive->arguments; string_list = list_first(args); ! /* create bit array. */ ! options = xmalloc(sizeof(uint8_t) * MAX_OPTIONS_HANDLED); ! ! if(client_conf_fill_option_bit_array_from_string_list(string_list, options)) { ! xfree(options); return 1; + } + var = dhcp_conf_var_create(type, options); + add_or_replace_var(params->variables, var); return 0; + } ! static int directive_request_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_option_array_handler_proc(params, directive_data, ! group_type, group_data, ! CLIENT_VAR_REQUEST_OPTIONS); ! } ! static int directive_require_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) ! { ! return directive_option_array_handler_proc(params, directive_data, ! group_type, group_data, ! CLIENT_VAR_REQUIRE_OPTIONS); ! } ! static int directive_configure_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) ! { ! return directive_option_array_handler_proc(params, directive_data, ! group_type, group_data, ! CLIENT_VAR_CONFIGURE_OPTIONS); ! } ! ! static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) ! { return 0; } ! static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) ! { ! return 0; ! } ! ! static int directive_server_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { list_t *args; *************** *** 564,568 **** void *address_data; void *directives; ! conf_params_t *new_params; directive_group_t new_group_type; directive_t *directive; --- 767,771 ---- void *address_data; void *directives; ! client_conf_params_t *new_params; directive_group_t new_group_type; directive_t *directive; *************** *** 594,605 **** address_data = list_get_by_index(args, 1); directives = list_get_by_index(args, 2); - new_params = xcalloc(sizeof(conf_params_t)); if(directive_group_handler(new_params, directives, new_group_type, address_data) < 0) return 1; - if(params->lower_params == NULL) - params->lower_params = list_create(); - list_add_to_end(params->lower_params, new_params); --- 797,805 ---- address_data = list_get_by_index(args, 1); directives = list_get_by_index(args, 2); + new_params = params_create(); if(directive_group_handler(new_params, directives, new_group_type, address_data) < 0) return 1; list_add_to_end(params->lower_params, new_params); *************** *** 607,611 **** } ! static int directive_set_boolean_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { directive_t *directive = directive_data; --- 807,812 ---- } ! static int directive_set_boolean_handler(client_conf_params_t *params, void *directive_data, ! directive_group_t group_type, void *group_data) { directive_t *directive = directive_data; *************** *** 627,656 **** } - static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) - { - directive_t *directive = directive_data; - list_t *args; - list_t *string_list; - - args = directive->arguments; - string_list = list_first(args); - - if(fill_option_bit_array_from_string_list(string_list, params->configure_options)) - return 1; - - /* always default with the timers. these must be set irregardless of what the user sets. */ - params->configure_options[TAG_DHCP_IP_ADDRESS_LEASE_TIME] = 1; - params->configure_options[TAG_DHCP_REBINDING_TIME] = 1; - params->configure_options[TAG_DHCP_RENEWAL_TIME] = 1; - - params->configure_set = 1; - return 0; - - } - - /* * * * * * * * * * * * * * * - * constructors/destructors * - * * * * * * * * * * * * * * */ - client_conf_t *create_client_conf(const char *interface) { --- 828,831 ---- *************** *** 660,675 **** cc->interface = interface; cc->conf_file = get_conf_options_fname(cc); ! cc->parameters.lower_params = list_create(); ! ! cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */ ! ! /* setup the defaults in the top level param datum. ! * these are all set in dhcp-client-defaults.h */ ! ! cc->parameters.client_hostname = CLIENT_DEFAULT_HOSTNAME; ! cc->parameters.dhcp_discovery_retries = CLIENT_DEFAULT_DHCP_DISCOVERY_OFFER_RETRIES; ! cc->parameters.icmp_retries = CLIENT_DEFAULT_ICMP_RETRIES; ! cc->parameters.default_interface_mtu = CLIENT_DEFAULT_MTU; ! cc->parameters.do_measure_router_latency_icmp = CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP; if(client_conf_load_options(cc)) { --- 835,840 ---- cc->interface = interface; cc->conf_file = get_conf_options_fname(cc); ! cc->params = params_create(); /* set top level to catchall group. */ ! cc->params->group_type = DIRECTIVE_GROUP_NULL; if(client_conf_load_options(cc)) { *************** *** 681,711 **** } - static void params_destroy(conf_params_t *params, uint8_t topflag) - { - list_t *params_list; - conf_params_t *lower_params; - - params_list = params->lower_params; - list_rewind(params_list); - for(lower_params = list_next(params_list); lower_params; - lower_params = list_next(params_list)) { - params_destroy(lower_params, 0); - } - - if(params->client_hostname) - xfree(params->client_hostname); - - list_destroy(params->lower_params, NULL); - params->lower_params = NULL; - - if(!topflag) - xfree(params); - } - void client_conf_destroy(client_conf_t *cc) { ! /* recursively kill all the parameters we've collected. */ ! params_destroy(&cc->parameters, 1); /* free up the client conf structure. */ --- 846,854 ---- } void client_conf_destroy(client_conf_t *cc) { ! /* destroy loaded parameters. */ ! params_destroy(cc->params); /* free up the client conf structure. */ Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-conf.h 3 Jan 2003 22:05:07 -0000 1.10 --- dhcp-client-conf.h 25 Mar 2003 03:06:19 -0000 1.11 *************** *** 41,90 **** typedef struct { ! directive_group_t group_type; ! ! ip_addr_t server_ip; ! eth_addr_t server_hw_addr; ! ! /* these are never used in lower params so no _set variable. */ ! ! uint8_t request_options[MAX_OPTIONS_HANDLED + 1]; /* which options we request. */ ! int dhcp_discovery_retries; /* amount of times we should retry dhcp operations. */ ! int default_interface_mtu; /* our default interface mtu. */ ! char *client_hostname; /* setting for the hostname option. */ ! ! uint8_t required_set; ! uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */ ! ! uint8_t configure_set; ! uint8_t configure_options[MAX_OPTIONS_HANDLED + 1]; /* which options we actually handle. */ ! uint8_t icmp_retries_set; /* whether the icmp retries is explicitly set. */ ! int icmp_retries; /* amount of times we should retry icmp operations. */ ! uint8_t do_measure_router_latency_icmp_set; /* whether the router latency is explicitly set. */ ! uint8_t do_measure_router_latency_icmp; /* perform router latency discovery via icmp. */ ! list_t *lower_params; /* linked list to child parameters. */ ! } conf_params_t; typedef struct { ! char *conf_file; const char *interface; /* points to dhcp_client_control->interface */ ! conf_params_t parameters; } client_conf_t; /* typedef of directive handler. */ ! typedef int (*directive_handler_t)(conf_params_t *param, void *directive_data, directive_group_t group_type, void *group_data); /* directive types. */ ! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, DIRECTIVE_CONFIGURE }; /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU }; ! ! /* symbols for boolean variable substitution */ ! enum var_boolean_symbols { CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP = 0 }; /* server symbol substitution. */ --- 41,81 ---- typedef struct { ! /* server specific options. may be set to hardware address or ! * IP address matching. */ ! directive_group_t group_type; ! /* depending on what kind of grouping these two addresses may be used. */ ! ip_addr_t server_ip; /* server ip address. */ ! eth_addr_t server_hw_addr; /* server hw address. */ ! list_t *variables; /* variables of type var_t. */ ! list_t *lower_params; /* linked list to child parameters. */ ! ! } client_conf_params_t; typedef struct { ! ! char *conf_file; /* name of conf file. */ const char *interface; /* points to dhcp_client_control->interface */ ! /* the top level conf_params_t -- top level is for any server. ! * we have lower level ones pointed from the top level. */ ! client_conf_params_t *params; ! } client_conf_t; /* typedef of directive handler. */ ! typedef int (*directive_handler_t)(client_conf_params_t *param, void *directive_data, directive_group_t group_type, void *group_data); /* directive types. */ ! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, ! DIRECTIVE_CONFIGURE, DIRECTIVE_APPEND, DIRECTIVE_PREPEND }; /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, ! CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP, CLIENT_VAR_REQUEST_OPTIONS, CLIENT_VAR_REQUIRE_OPTIONS, ! CLIENT_VAR_CONFIGURE_OPTIONS }; /* server symbol substitution. */ *************** *** 99,113 **** extern int client_conf_reread(client_conf_t *cc); ! extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); extern int client_conf_get_dhcp_discovery_retries(client_conf_t *cc); - extern int client_conf_get_default_mtu(client_conf_t *cc); extern const char *client_conf_get_hostname(client_conf_t *cc); extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); - extern uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); ! #endif /* DHCP_CLIENT_CONF_H */ --- 90,103 ---- extern int client_conf_reread(client_conf_t *cc); ! 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); extern const char *client_conf_get_hostname(client_conf_t *cc); + extern int client_conf_get_default_mtu(client_conf_t *cc); extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); ! extern int client_conf_get_default_mtu(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ |
From: <act...@us...> - 2003-03-25 03:05:55
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12268 Added Files: dhcp-conf-var.c dhcp-conf-var.h Log Message: added lightweight conf var type --- NEW FILE: dhcp-conf-var.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf-var.c,v 1.1 2003/03/25 03:05:52 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. * */ #define MODULE_NAME "dhcp-conf-var" #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-conf-var.h" /* * * * * * * * * * * * * * * * * * * * * * * * * * conf_var_t is a super light variable holder. * * We just want to hold a name and a pointer to * * data. * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* create/destroy */ conf_var_t *dhcp_conf_var_create(var_type_t var_type, void *val) { conf_var_t *var; var = xmalloc(sizeof(conf_var_t)); var->type = var_type; var->val = val; return var; } void dhcp_conf_var_destroy(conf_var_t *var) { xfree(var->val); xfree(var); } /* utility destroy. we call this when we don't want to free the * value because we've called something like * dhcp_conf_var_overwrite() with it. */ void dhcp_conf_var_destroy_no_val_free(conf_var_t *var) { xfree(var); } void dhcp_conf_var_destroy_l(void *data) { conf_var_t *var = data; dhcp_conf_var_destroy(var); return; } /* accessors. */ void *dhcp_conf_var_get_val(conf_var_t *var) { return var->val; } var_type_t dhcp_conf_var_get_type(conf_var_t *var) { return var->type; } /* free up and overwrite old value. */ void dhcp_conf_var_overwrite(conf_var_t *var, var_type_t var_type, void *val) { xfree(var->val); var->type = var_type; var->val = val; return; } --- NEW FILE: dhcp-conf-var.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf-var.h,v 1.1 2003/03/25 03:05:52 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_CONF_VAR_H #define DHCP_CONF_VAR_H typedef uint32_t var_type_t; typedef struct { var_type_t type; void *val; } conf_var_t; extern conf_var_t *dhcp_conf_var_create(var_type_t var_type, void *val); extern void dhcp_conf_var_destroy(conf_var_t *var); extern void dhcp_conf_var_destroy_l(void *var); extern void dhcp_conf_var_destroy_no_val_free(conf_var_t *var); extern void *dhcp_conf_var_get_val(conf_var_t *var); extern var_type_t dhcp_conf_var_get_type(conf_var_t *var); extern void dhcp_conf_var_overwrite(conf_var_t *var, var_type_t var_type, void *val); #endif /* DHCP_CONF_VAR_H */ |
From: <act...@us...> - 2003-03-25 03:05:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12030 Modified Files: dhcp-tokenizer.c Log Message: small typo fixed Index: dhcp-tokenizer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-tokenizer.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-tokenizer.c 30 Dec 2002 03:41:52 -0000 1.3 --- dhcp-tokenizer.c 25 Mar 2003 03:05:06 -0000 1.4 *************** *** 23,26 **** --- 23,31 ---- */ + /* TODO: + * It may be profitable to mmap() in order to implement peeking nicer. + * Config files won't be so big anyway. + */ + #define MODULE_NAME "dhcp-tokenizer" *************** *** 157,161 **** } ! /* anything else means insert c2 without handling it specially*/ stringbuffer_append_c(tokenizer->data_buff, (char)c2); --- 162,166 ---- } ! /* anything else means insert c2 without handling it specially. */ stringbuffer_append_c(tokenizer->data_buff, (char)c2); |
From: <act...@us...> - 2003-03-25 03:04:03
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11681 Modified Files: dhcp-libutil.h dhcp-util.c Log Message: added signed/unsigned numeric check util routine Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dhcp-libutil.h 2 Jan 2003 04:23:01 -0000 1.23 --- dhcp-libutil.h 25 Mar 2003 03:03:56 -0000 1.24 *************** *** 194,198 **** --- 194,202 ---- extern char *eth_addr_to_string(eth_addr_t eth_addr); extern char *ip_addr_to_string(ip_addr_t ip_addr); + + /* type check routines */ extern int is_seven_bit_clean(const char *data, int len); + extern int is_signed_numeric(const char *string); + extern int is_unsigned_numeric(const char *string); /* Replacement vsnprintf, snprintf that work the way we want them to. */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-util.c 29 Dec 2002 05:31:36 -0000 1.12 --- dhcp-util.c 25 Mar 2003 03:03:58 -0000 1.13 *************** *** 35,38 **** --- 35,42 ---- static int verbosity_level = DEBUG_VERBOSITY_LEVEL; + /* * * * * * * * * * * + * message routines * + * * * * * * * * * * */ + /* set the verbosity level. */ int set_verbosity_level(int verbosity_level_to_set) *************** *** 194,204 **** } ! /* ! * Malloc and free wrapper functions in case ! * we want to do some accounting or debugging here. ! * It also calls fatal_error aborting us if ! * we ever run out of memory. ! * ! */ void *xmalloc(size_t size) --- 198,211 ---- } ! void set_interactive(uint8_t interactive_arg) ! { ! /* set to 1 or 0. */ ! interactive = interactive_arg; ! return; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * dynamic memory allocation wrappers. * ! * * * * * * * * * * * * * * * * * * * */ void *xmalloc(size_t size) *************** *** 244,247 **** --- 251,260 ---- } + /* * * * * * * * * * * + * string routines. * + * most of these * + * need to die. * + * * * * * * * * * * */ + #ifndef HAVE_STRDUP *************** *** 380,395 **** } ! /* check if two strings match. */ ! int string_matches(const char *s1, const char *s2) { ! if(!strcmp(s1, s2)) ! return 1; ! else ! return 0; } ! /* Random number generation. * ! * We're interfacing into dnet's code * ! * here. */ static rand_t *ran_gen = NULL; --- 393,458 ---- } ! /* * * * * * * * * * * * * * * * * ! * simple check routines. * ! * use these for types checking * ! * and other similar checks. * ! * * * * * * * * * * * * * * * * */ ! ! /* check for seven bit cleanliness. */ ! int is_seven_bit_clean(const char *data, int len) { ! int i; ! const unsigned char *ptr = data; ! ! for(i = 0; i < len; i++) { ! if(ptr[i] >= 128) ! return 0; ! } ! ! return 1; } ! /* is numeric */ ! int is_unsigned_numeric(const char *string) ! { ! const char *ptr; ! ! for(ptr = string; *ptr; ptr++) { ! if(!isdigit(*ptr)) ! return 0; ! } ! ! return 1; ! } ! ! /* is numeric */ ! int is_signed_numeric(const char *string) ! { ! const char *ptr; ! ! /* check for a prefix '-' character */ ! ! for(ptr = string; *ptr; ptr++) { ! if(*ptr == '-') ! break; ! else if(isdigit(*ptr)) ! break; ! else ! return 0; ! } ! ! for(; *ptr; ptr++) { ! if(!isdigit(*ptr)) ! return 0; ! } ! ! return 1; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * Random number generation. * ! * We're interfacing into dnet's code * ! * here. * ! * * * * * * * * * * * * * * * * * * * */ static rand_t *ran_gen = NULL; *************** *** 454,478 **** #endif /* HAVE_GETPROGNAME */ - /* check for seven bit cleanliness. */ - int is_seven_bit_clean(const char *data, int len) - { - int i; - const unsigned char *ptr = data; - - for(i = 0; i < len; i++) { - if(ptr[i] >= 128) - return 0; - } - - return 1; - } - - void set_interactive(uint8_t interactive_arg) - { - /* set to 1 or 0. */ - interactive = interactive_arg; - return; - } - /* convert a string ip to ip_addr_t */ ip_addr_t *string_ip_to_ip_addr(const char *string_ip) --- 517,520 ---- *************** *** 539,541 **** } - --- 581,582 ---- |
From: <act...@us...> - 2003-03-25 03:02:56
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11435 Modified Files: dhcp-interrupt.c Log Message: small typo fix Index: dhcp-interrupt.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interrupt.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-interrupt.c 19 Dec 2002 17:20:36 -0000 1.3 --- dhcp-interrupt.c 25 Mar 2003 03:02:53 -0000 1.4 *************** *** 30,34 **** #include "dhcp-libutil.h" ! /* wrap for volatine integers, or proper sig_atomic_t types. */ #ifdef HAVE_SIG_ATOMIC_T --- 30,34 ---- #include "dhcp-libutil.h" ! /* wrap for volatile integers, or proper sig_atomic_t types. */ #ifdef HAVE_SIG_ATOMIC_T |
From: <act...@us...> - 2003-03-25 03:01:57
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11097 Modified Files: dhcp-client-defaults.h Log Message: renamed dhcp_discovery constant Index: dhcp-client-defaults.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-defaults.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-client-defaults.h 3 Jan 2003 21:29:22 -0000 1.1 --- dhcp-client-defaults.h 25 Mar 2003 03:01:53 -0000 1.2 *************** *** 51,55 **** * giving up. */ ! #define CLIENT_DEFAULT_DHCP_DISCOVERY_OFFER_RETRIES 3 /* Retries per ICMP operation. This defines how many times ICMP --- 51,55 ---- * giving up. */ ! #define CLIENT_DEFAULT_DHCP_DISCOVERY_RETRIES 3 /* Retries per ICMP operation. This defines how many times ICMP |
From: <act...@us...> - 2003-03-25 03:01:20
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10878 Modified Files: dhcp-cache-entry.c dhcp-cache-entry.h Log Message: cache_entry_destroy_l externed Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-cache-entry.c 2 Jan 2003 04:23:01 -0000 1.6 --- dhcp-cache-entry.c 25 Mar 2003 03:01:04 -0000 1.7 *************** *** 59,64 **** } ! /* use alongside purge_list or similar routines. */ ! static void cache_entry_destroy_l(void *data) { cache_entry_destroy(data); --- 59,64 ---- } ! /* list purge compatible option. */ ! void cache_entry_destroy_l(void *data) { cache_entry_destroy(data); Index: dhcp-cache-entry.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-cache-entry.h 16 Dec 2002 10:04:33 -0000 1.4 --- dhcp-cache-entry.h 25 Mar 2003 03:01:05 -0000 1.5 *************** *** 35,38 **** --- 35,39 ---- extern void cache_entry_destroy(cache_entry_t *cache); extern void cache_entry_purge_list(list_t *cache_list); + extern void cache_entry_destroy_l(void *data); #endif /* DHCP_CACHE_ENTRY_H */ |
From: <act...@us...> - 2003-01-05 00:28:47
|
Update of /cvsroot/dhcp-agent/dhcp-agent/conf In directory sc8-pr-cvs1:/tmp/cvs-serv29842 Added Files: networking-basic.sysconf Log Message: tentative sysconf recipe file --- NEW FILE: networking-basic.sysconf --- # $Header: /cvsroot/dhcp-agent/dhcp-agent/conf/networking-basic.sysconf,v 1.1 2003/01/05 00:28:44 actmodern Exp $ # # dhcp-sysconf recipe file. # # We describe recipes to setup our system based # on input from a dhcp server. # # The following options can never be handled here. They're # handled internally by the client: # # ip-address, subnet mask, lease time, renewal time, rebinding time, # interface mtu # # Setup a default route by icmp pinging first # routers { setup { # # Uncomment below if you don't want to ICMP ping to find the router # with the lowest latency. You can also set "do-measure-icmp-latency" to "no" # so as to disable it globaly from doing anything # ${sort_by_latency_icmp($0)}; add-route ${list_first($0)} default; }; inform-setup "Added default route to " $list_first($0); cleanup { remove-route default; }; inform-cleanup "Removed default route."; }; # setup domain-name and domain-name-servers # # This recipe makes use of a file stub which calls expand_list_newlines() # an operation that expands the variable o domain-name, domain-name-servers { setup { # insert into file "/etc/resolv.conf" # Everything in the file-insert grouping describes # a file stub which is expanded and dumped in place of # that file verbatim except for the variable substitutions # and operations performed on variable substitutions file-truncate /etc/resolv.conf; file-insert /etc/resolv.conf { nameserver ${expand_list_newlines(1)} $0 }; }; inform-setup "Updated /etc/resolv.conf"; cleanup { file-truncate /etc/resolv.conf; # Alternative uncomment this to delete the file. # # file-remove /etc/resolv.conf }; inform-cleanup "Emptied /etc/resolv.conf"; }; ip-forwarding { setup { # For Linux insert the character "1" in # /proc/sys/net/ipv4/ip_forward file-truncate /proc/sys/net/ipv4/ip_forward; file-insert /proc/sys/net/ipv4/ip_forward { 1 }; }; cleanup { file-truncate /proc/sys/net/ipv4/ip_forward; file-insert /proc/sys/net/ipv4/ip_forward { 0 }; }; }; hostname { setup { # Just add the hostname to /etc/HOSTNAME # # file-truncate /etc/HOSTNAME; file-insert /etc/HOSTNAME { $0 }; # Alternatively uncomment below to execute "hostname" with the # hostname as the argument. # # exec "/bin/hostname" $0; }; inform-setup "Setup hostname to $0"; # No cleanup for this unless you want to use the silly one below. # Uncomment it if you do. # cleanup { # file-remove /etc/HOSTNAME; # exec "/bin/hostname" "unknown"; }; }; |
From: <act...@us...> - 2003-01-03 22:09:49
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv13202 Modified Files: dhcp-client-conf.c Log Message: always set the timers irregardless of directives Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-client-conf.c 3 Jan 2003 22:05:06 -0000 1.17 --- dhcp-client-conf.c 3 Jan 2003 22:09:44 -0000 1.18 *************** *** 639,642 **** --- 639,647 ---- return 1; + /* always default with the timers. these must be set irregardless of what the user sets. */ + params->configure_options[TAG_DHCP_IP_ADDRESS_LEASE_TIME] = 1; + params->configure_options[TAG_DHCP_REBINDING_TIME] = 1; + params->configure_options[TAG_DHCP_RENEWAL_TIME] = 1; + params->configure_set = 1; return 0; |
From: <act...@us...> - 2003-01-03 22:05:13
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11631 Modified Files: dhcp-client-conf.c dhcp-client-conf.h dhcp-sysconf.c Log Message: added \'configure\' keyword Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client-conf.c 3 Jan 2003 21:29:22 -0000 1.16 --- dhcp-client-conf.c 3 Jan 2003 22:05:06 -0000 1.17 *************** *** 101,104 **** --- 101,108 ---- static const arg_symbol_t *require_arg_symbols[] = { NULL }; + static const arg_type_t configure_arg_types[] = { CONF_STRING_LIST }; + static const char **configure_arg_strings[] = { NULL }; + static const arg_symbol_t *configure_arg_symbols[] = { NULL }; + static const arg_type_t server_arg_types[] = { CONF_IDENTIFIER, CONF_ADDRESS, CONF_GROUP }; static const char **server_arg_strings[] = { server_strings, NULL, NULL }; *************** *** 147,150 **** --- 151,164 ---- }; + /* request command. */ + static const command_t command_configure = { + DIRECTIVE_CONFIGURE, + "configure", + 1, + configure_arg_strings, + configure_arg_types, + configure_arg_symbols, + }; + /* server command. */ static const command_t command_server = { *************** *** 163,166 **** --- 177,181 ---- &command_require, &command_server, + &command_configure, NULL, }; *************** *** 189,192 **** --- 204,208 ---- static int directive_require_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); static int directive_server_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); + static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data); /* indexed by directive types in dhcp-client-conf.h . */ *************** *** 197,200 **** --- 213,217 ---- directive_require_handler, directive_server_handler, + directive_configure_handler, }; *************** *** 229,233 **** } - static int client_conf_set_variable(conf_params_t *params, arg_symbol_t var_symbol, const char *var_value) { --- 246,249 ---- *************** *** 385,388 **** --- 401,429 ---- } + uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + conf_params_t *params; + + params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); + + if(params != NULL && params->configure_set) + return 1; + else + return cc->parameters.configure_set; + } + + /* get required options */ + uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + conf_params_t *params; + + params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); + + if(params != NULL && params->configure_set) + return params->configure_options; + else + return cc->parameters.configure_options; + } + /* get number of times to attempt icmp operations where applicable */ int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) *************** *** 584,587 **** --- 625,645 ---- return 0; + } + + static int directive_configure_handler(conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) + { + directive_t *directive = directive_data; + list_t *args; + list_t *string_list; + + args = directive->arguments; + string_list = list_first(args); + + if(fill_option_bit_array_from_string_list(string_list, params->configure_options)) + return 1; + + params->configure_set = 1; + return 0; + } Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-conf.h 3 Jan 2003 21:29:22 -0000 1.9 --- dhcp-client-conf.h 3 Jan 2003 22:05:07 -0000 1.10 *************** *** 56,59 **** --- 56,62 ---- uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */ + uint8_t configure_set; + uint8_t configure_options[MAX_OPTIONS_HANDLED + 1]; /* which options we actually handle. */ + uint8_t icmp_retries_set; /* whether the icmp retries is explicitly set. */ int icmp_retries; /* amount of times we should retry icmp operations. */ *************** *** 77,81 **** /* directive types. */ ! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP }; /* symbols for variable substitution. */ --- 80,84 ---- /* directive types. */ ! enum directive_types { DIRECTIVE_SET_BOOLEAN = 0, DIRECTIVE_SET, DIRECTIVE_REQUEST, DIRECTIVE_REQUIRE, DIRECTIVE_SERVER_GROUP, DIRECTIVE_CONFIGURE }; /* symbols for variable substitution. */ *************** *** 102,107 **** --- 105,113 ---- extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); + extern uint8_t client_conf_get_opt_configure_set(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); + extern uint8_t *client_conf_get_opt_configure_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); + #endif /* DHCP_CLIENT_CONF_H */ Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-sysconf.c 3 Jan 2003 21:29:22 -0000 1.13 --- dhcp-sysconf.c 3 Jan 2003 22:05:08 -0000 1.14 *************** *** 463,466 **** --- 463,467 ---- void *data; cache_entry_t *ce; + uint8_t *configure_opts = NULL; /* Clean up any config files we have. */ *************** *** 474,477 **** --- 475,489 ---- sysconf_setup_interface(options, dc); + /* ask client conf if we're supposed to configure certain options. + * if so get the bit array. */ + + if(client_conf_get_opt_configure_set(dc->conf, dhcp_client_get_server_ip_address(dc), + dhcp_client_get_server_hw_address(dc))) { + + configure_opts = client_conf_get_opt_configure_bit_array(dc->conf, + dhcp_client_get_server_ip_address(dc), + dhcp_client_get_server_hw_address(dc)); + } + /* Now walk through the other options, performing setup and * cleanup operations as necessary. */ *************** *** 480,488 **** while((ce = list_next(options)) != NULL) { ! /* 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); --- 492,512 ---- while((ce = list_next(options)) != NULL) { ! /* Make sure we know how to setup this option, and we're ! * supposed to. */ ! if(configure_opts) { ! ! if(sysconf_handlers[ce->tag].setup == NULL || ! option_convert_handlers[ce->tag].serialize_to_internal == NULL || ! configure_opts[ce->tag] == 0) ! continue; ! ! } else { ! ! 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); |
From: <act...@us...> - 2003-01-03 21:29:46
|
Update of /cvsroot/dhcp-agent/dhcp-agent/conf In directory sc8-pr-cvs1:/tmp/cvs-serv31688/conf Modified Files: networking-basic.conf Log Message: modified config directives a bit Index: networking-basic.conf =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/conf/networking-basic.conf,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** networking-basic.conf 21 Dec 2002 18:13:59 -0000 1.2 --- networking-basic.conf 3 Jan 2003 21:29:44 -0000 1.3 *************** *** 4,8 **** # We only ask for network setup parameters. # ! # # This will setup dhcp to accept the following configuration # parameters from any dhcp server: --- 4,9 ---- # We only ask for network setup parameters. # ! # Thamer Alharbash <tm...@wh...> ! # This will setup dhcp to accept the following configuration # parameters from any dhcp server: *************** *** 12,16 **** # # It will require all of the above. Otherwise uncomment below to be ! # more flexible # --- 13,17 ---- # # It will require all of the above. Otherwise uncomment below to be ! # more flexible # *************** *** 39,49 **** # give us one. ! set interface-mtu = 1500; # ! # DHCP -- try up to three times before giving up. # ! set dhcp-retries = 3; # --- 40,50 ---- # give us one. ! set default-interface-mtu = 1500; # ! # DHCP -- try to discover/request three times before giving up. # ! set dhcp-discovery-retries = 3; # *************** *** 57,59 **** # ! enable do-find-best-router-icmp = yes; --- 58,60 ---- # ! enable do-measure-router-latency = no; |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv31513 Modified Files: Makefile.am dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client.h dhcp-conf.c dhcp-interface.c dhcp-librawnet.h dhcp-limits.h dhcp-packet-build.c dhcp-rawnet.c dhcp-sniff.c dhcp-sysconf.c Added Files: dhcp-client-defaults.h dhcp-sniff-defaults.h Log Message: fixed up config code to work with new lists and hooked them into the client --- NEW FILE: dhcp-client-defaults.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-defaults.h,v 1.1 2003/01/03 21:29:22 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_DEFAULTS_H #define DHCP_CLIENT_DEFAULTS_H /* default MTU to use on interface during initialization * and if none is provided and used from the server. */ #define CLIENT_DEFAULT_MTU 1500 /* Default snaplen. This should be set to the default mtu. * only change this if you know what you're doing. */ #define CLIENT_DEFAULT_SNAPLEN DEFAULT_MTU /* Default hostname: defaults to none (NULL) */ #define CLIENT_DEFAULT_HOSTNAME NULL /* Default DHCP timeout per operation. */ #define CLIENT_DEFAULT_DHCP_TIMEOUT 64 /* recommended by RFC2131 */ /* Number of times a DHCP operation should retry: this does not * affect the timeout on a per operation basis. The client will * still wait as long as CLIENT_DEFAULT_DHCP_TIMEOUT for each * individual operation (e.g. DISCOVER). The setting below will * affect how many times discover/offer will be attempted before * giving up. */ #define CLIENT_DEFAULT_DHCP_DISCOVERY_OFFER_RETRIES 3 /* Retries per ICMP operation. This defines how many times ICMP * should be retried if failure occurs. For averaging it also * defines how many times an ICMP operation should be performed * altogether. */ #define CLIENT_DEFAULT_ICMP_RETRIES 3 /* Whether or not to use ICMP to measure latency to specified * routers. The client will attempt to send an ICMP Echo Request * to any routers it receives to measure latency. The client will * then make use of the router with the least latency. Non-zero * value enables this. */ #define CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP 1 #endif /* DHCP_CLIENT_DEFAULTS_H */ --- NEW FILE: dhcp-sniff-defaults.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff-defaults.h,v 1.1 2003/01/03 21:29:22 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_SNIFF_DEFAULTS_H #define DHCP_SNIFF_DEFAULTS_H #define DEFAULT_SNIFF_SNAPLEN 1500 #endif /* DHCP_SNIFF_DEFAULTS_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.am 30 Dec 2002 00:45:03 -0000 1.13 --- Makefile.am 3 Jan 2003 21:29:22 -0000 1.14 *************** *** 3,7 **** # Main source Makefile.am ! AM_CFLAGS = -Wall -Werror -g INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ --- 3,7 ---- # Main source Makefile.am ! AM_CFLAGS = -Wall -Werror INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client-conf.c 2 Jan 2003 04:23:01 -0000 1.15 --- dhcp-client-conf.c 3 Jan 2003 21:29:22 -0000 1.16 *************** *** 36,39 **** --- 36,41 ---- #include "dhcp-options-strings.h" + #include "dhcp-client-defaults.h" + /* FIXME: check for destroy params mem leak. */ *************** *** 47,57 **** static const char *var_strings[] = { "hostname", ! "dhcp-retries", "icmp-retries", ! "interface-mtu", }; static const char *var_boolean_strings[] = { ! "do-find-best-router-icmp", }; --- 49,59 ---- static const char *var_strings[] = { "hostname", ! "dhcp-discovery-retries", "icmp-retries", ! "default-interface-mtu", }; static const char *var_boolean_strings[] = { ! "do-measure-router-latency", }; *************** *** 67,71 **** static const arg_symbol_t var_symbols[] = { CLIENT_VAR_HOSTNAME, ! CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, --- 69,73 ---- static const arg_symbol_t var_symbols[] = { CLIENT_VAR_HOSTNAME, ! CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU, *************** *** 197,230 **** }; - /* * * * * * * - * accessors * - * * * * * * */ - - uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) - { - return cc->parameters.request_options; - } - - uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) - { - /* FIXME: search lower groups too. */ - return cc->parameters.required_options; - } - - int client_conf_get_dhcp_retries(client_conf_t *cc) - { - return cc->parameters.dhcp_retries; - } - - int client_conf_get_icmp_retries(client_conf_t *cc) - { - return cc->parameters.icmp_retries; - } - - const char *client_conf_get_hostname(client_conf_t *cc) - { - return cc->parameters.client_hostname; - } - /* * * * * * * * * * * * utility routines * --- 199,202 ---- *************** *** 275,281 **** ! case CLIENT_VAR_DHCP_RETRIES: ! params->dhcp_retries = atoi(var_value); break; --- 247,253 ---- ! case CLIENT_VAR_DHCP_DISCOVERY_RETRIES: ! params->dhcp_discovery_retries = atoi(var_value); break; *************** *** 283,286 **** --- 255,259 ---- params->icmp_retries = atoi(var_value); + params->icmp_retries_set = 1; break; *************** *** 303,307 **** --- 276,282 ---- case CLIENT_VAR_DO_MEASURE_ROUTER_LATENCY_ICMP: + params->do_measure_router_latency_icmp = bool_val; + params->do_measure_router_latency_icmp_set = 1; break; *************** *** 354,357 **** --- 329,426 ---- } + /* search through lower params and return best match. */ + static conf_params_t *get_params_for(list_t *lower_params, ip_addr_t ip, eth_addr_t eth_addr) + { + /* FIXME: this is broken -- needs to be fixed up. */ + conf_params_t *params; + + list_rewind(lower_params); + while((params = list_next(lower_params)) != NULL) { + + if(params->group_type == DIRECTIVE_GROUP_IP_ADDRESS && + (ip == params->server_ip)) { + return params; + } + + if(params->group_type == DIRECTIVE_GROUP_MAC_ADDRESS && + (!memcmp(eth_addr.data, params->server_hw_addr.data, ETH_ADDR_LEN))) { + return params; + } + + /* recursively check lower parameters too. */ + if((params = get_params_for(params->lower_params, ip, eth_addr)) != NULL) + return params; + } + + return NULL; + } + + /* * * * * * * + * accessors * + * * * * * * */ + + /* get parameters to request: ip and eth addr silently ignored. */ + uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc) + { + return cc->parameters.request_options; + } + + /* get number of retries for dhcp: ip and eth addr silently ignored. */ + int client_conf_get_dhcp_discovery_retries(client_conf_t *cc) + { + return cc->parameters.dhcp_discovery_retries; + } + + /* get required options */ + uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + conf_params_t *params; + + params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); + + if(params != NULL && params->required_set) + return params->required_options; + else + return cc->parameters.required_options; + } + + /* get number of times to attempt icmp operations where applicable */ + int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + conf_params_t *params; + + params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); + + if(params != NULL && params->icmp_retries_set) + return params->icmp_retries; + else + return cc->parameters.icmp_retries; + } + + /* get the hostname option the client should set. */ + const char *client_conf_get_hostname(client_conf_t *cc) + { + return cc->parameters.client_hostname; + } + + /* get the hostname option the client should set. */ + uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr) + { + conf_params_t *params; + + params = get_params_for(cc->parameters.lower_params, ip_addr, eth_addr); + + if(params != NULL && params->do_measure_router_latency_icmp_set) + return params->do_measure_router_latency_icmp; + else + return cc->parameters.do_measure_router_latency_icmp; + } + + /* get mtu setting. */ + int client_conf_get_default_mtu(client_conf_t *cc) + { + return cc->parameters.default_interface_mtu; + } + /* * * * * * * * * * * * * directive handlers. * *************** *** 407,411 **** var_symbol = list_get_by_index(args, 0); ! var_value = list_get_by_index(args, 3); if(client_conf_set_variable(params, *var_symbol, var_value)) { --- 476,480 ---- var_symbol = list_get_by_index(args, 0); ! var_value = list_get_by_index(args, 2); if(client_conf_set_variable(params, *var_symbol, var_value)) { *************** *** 444,447 **** --- 513,517 ---- return 1; + params->required_set = 1; return 0; } *************** *** 491,495 **** params->lower_params = list_create(); ! list_add(params->lower_params, new_params); return 0; --- 561,565 ---- params->lower_params = list_create(); ! list_add_to_end(params->lower_params, new_params); return 0; *************** *** 530,533 **** --- 600,612 ---- cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */ + + /* setup the defaults in the top level param datum. + * these are all set in dhcp-client-defaults.h */ + + cc->parameters.client_hostname = CLIENT_DEFAULT_HOSTNAME; + cc->parameters.dhcp_discovery_retries = CLIENT_DEFAULT_DHCP_DISCOVERY_OFFER_RETRIES; + cc->parameters.icmp_retries = CLIENT_DEFAULT_ICMP_RETRIES; + cc->parameters.default_interface_mtu = CLIENT_DEFAULT_MTU; + cc->parameters.do_measure_router_latency_icmp = CLIENT_DEFAULT_DO_MEASURE_LATENCY_ICMP; if(client_conf_load_options(cc)) { Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client-conf.h 21 Dec 2002 18:13:10 -0000 1.8 --- dhcp-client-conf.h 3 Jan 2003 21:29:22 -0000 1.9 *************** *** 32,35 **** --- 32,42 ---- /* data structures. */ + /* note on conf_params_t: all members have an associated _set + * member which tells us easily if they've been set. this is + * only useful for lower_params where specific groups are + * specified and the settings override the global ones. the top + * level param is initialized to defaults and no checking is made + * there. */ + typedef struct { *************** *** 39,54 **** eth_addr_t server_hw_addr; ! uint8_t request_options[MAX_OPTIONS_HANDLED + 1]; /* which options we request. */ ! uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */ ! 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. */ ! int default_interface_mtu; /* our default interface mtu. */ ! uint8_t do_measure_router_latency_icmp; /* perform router latency discovery via icmp. */ ! list_t *lower_params; /* linked list to child parameters. */ } conf_params_t; --- 46,66 ---- eth_addr_t server_hw_addr; ! /* these are never used in lower params so no _set variable. */ ! uint8_t request_options[MAX_OPTIONS_HANDLED + 1]; /* which options we request. */ ! int dhcp_discovery_retries; /* amount of times we should retry dhcp operations. */ ! int default_interface_mtu; /* our default interface mtu. */ ! char *client_hostname; /* setting for the hostname option. */ ! uint8_t required_set; ! uint8_t required_options[MAX_OPTIONS_HANDLED + 1]; /* which options we require. */ ! uint8_t icmp_retries_set; /* whether the icmp retries is explicitly set. */ ! int icmp_retries; /* amount of times we should retry icmp operations. */ ! uint8_t do_measure_router_latency_icmp_set; /* whether the router latency is explicitly set. */ ! uint8_t do_measure_router_latency_icmp; /* perform router latency discovery via icmp. */ ! ! list_t *lower_params; /* linked list to child parameters. */ } conf_params_t; *************** *** 68,72 **** /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU }; /* symbols for boolean variable substitution */ --- 80,84 ---- /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_DISCOVERY_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU }; /* symbols for boolean variable substitution */ *************** *** 82,94 **** 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 uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); ! ! 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); ! extern int client_conf_reread(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ --- 94,107 ---- extern client_conf_t *create_client_conf(const char *interface); extern void client_conf_destroy(client_conf_t *cc); + extern int client_conf_reread(client_conf_t *cc); extern uint8_t *client_conf_get_opt_bit_array(client_conf_t *cc); ! extern int client_conf_get_dhcp_discovery_retries(client_conf_t *cc); ! extern int client_conf_get_default_mtu(client_conf_t *cc); extern const char *client_conf_get_hostname(client_conf_t *cc); ! extern uint8_t *client_conf_get_opt_required_bit_array(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); ! extern int client_conf_get_icmp_retries(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); ! extern uint8_t client_conf_get_do_measure_router_latency_icmp(client_conf_t *cc, ip_addr_t ip_addr, eth_addr_t eth_addr); #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.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-control.c 29 Dec 2002 05:09:55 -0000 1.13 --- dhcp-client-control.c 3 Jan 2003 21:29:22 -0000 1.14 *************** *** 60,64 **** 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++; --- 60,64 ---- int dhcp_client_discover_offer_can_retry(dhcp_client_control_t *dc) { ! uint32_t discover_offer_retries = client_conf_get_dhcp_discovery_retries(dc->conf); dc->discover_offer_retries++; *************** *** 171,175 **** if((dc->rawnet = ! rawnet_create(interface, stringbuffer_getstring(filter), sport, dport, promiscuous, clear_interface)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); --- 171,175 ---- if((dc->rawnet = ! rawnet_create(interface, stringbuffer_getstring(filter), client_conf_get_default_mtu(dc->conf), sport, dport, promiscuous, clear_interface)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client.h 29 Dec 2002 05:09:55 -0000 1.11 --- dhcp-client.h 3 Jan 2003 21:29:22 -0000 1.12 *************** *** 26,29 **** --- 26,31 ---- #define DHCP_CLIENT_H + #include "dhcp-client-defaults.h" /* include defaults. */ + /* data structures. */ Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-conf.c 2 Jan 2003 04:23:01 -0000 1.9 --- dhcp-conf.c 3 Jan 2003 21:29:22 -0000 1.10 *************** *** 87,90 **** --- 87,92 ---- directive = xcalloc(sizeof(directive_t)); + directive->argument_types = list_create(); + directive->arguments = list_create(); return directive; } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-interface.c 2 Jan 2003 04:23:01 -0000 1.6 --- dhcp-interface.c 3 Jan 2003 21:29:22 -0000 1.7 *************** *** 50,54 **** { if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! ERROR_MESSAGE("could apply settings to interface %s : %s", ic->interface_entry->intf_name, strerror(errno)); return -1; --- 50,54 ---- { if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! ERROR_MESSAGE("could not apply settings to interface %s : %s", ic->interface_entry->intf_name, strerror(errno)); return -1; *************** *** 114,124 **** } ! /* Set mtu to default if not passed. */ ! ! if(mtu != -1) ! ic->interface_entry->intf_mtu = mtu; ! else ! ic->interface_entry->intf_mtu = DEFAULT_MTU; ! ic->interface_entry->intf_flags |= INTF_FLAG_UP; --- 114,118 ---- } ! ic->interface_entry->intf_mtu = 1500; ic->interface_entry->intf_flags |= INTF_FLAG_UP; *************** *** 128,132 **** * fails. so we'll ignore the error for now. FIXME: * update when dnet is fixed. (the address is set to 0 ! * but dnet doesn't get further than netmask settings. */ /* ERROR_MESSAGE("could not bring up interface %s : %s", --- 122,127 ---- * fails. so we'll ignore the error for now. FIXME: * update when dnet is fixed. (the address is set to 0 ! * but dnet doesn't get further than netmask settings). ! */ /* ERROR_MESSAGE("could not bring up interface %s : %s", Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-librawnet.h 2 Jan 2003 04:23:01 -0000 1.9 --- dhcp-librawnet.h 3 Jan 2003 21:29:22 -0000 1.10 *************** *** 145,148 **** --- 145,149 ---- int promiscuous; /* run in promiscuous mode flag. */ + int mtu; /* mtu setting. */ interface_control_t *intf_handle; /* interface control handle. */ *************** *** 313,318 **** /* rawnet routines. */ ! extern rawnet_t *rawnet_create(const char *device, const char *filter, int sport, int dport, ! int promiscuous, int clear_address); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net, struct timeval *tm); --- 314,319 ---- /* rawnet routines. */ ! extern rawnet_t *rawnet_create(const char *device, const char *filter, int mtu, int sport, ! int dport, int promiscuous, int clear_address); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net, struct timeval *tm); *************** *** 440,444 **** extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); extern dhcp_option_t *dhcp_build_hostname(const char *hostname); - /* Ether obj routines. */ --- 441,444 ---- Index: dhcp-limits.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-limits.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-limits.h 16 Dec 2002 07:20:42 -0000 1.3 --- dhcp-limits.h 3 Jan 2003 21:29:22 -0000 1.4 *************** *** 38,49 **** #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 --- 38,41 ---- Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-packet-build.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-packet-build.c 27 Dec 2002 02:53:21 -0000 1.4 --- dhcp-packet-build.c 3 Jan 2003 21:29:22 -0000 1.5 *************** *** 50,54 **** packet_ptr = net->packet_data; ! memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); --- 50,54 ---- packet_ptr = net->packet_data; ! memset(packet_ptr, 0, net->mtu); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); *************** *** 77,81 **** packet_ptr = net->packet_data; ! memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); --- 77,81 ---- packet_ptr = net->packet_data; ! memset(packet_ptr, 0, net->mtu); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); *************** *** 94,98 **** packet_ptr = net->packet_data; ! memset(packet_ptr, 0, DEFAULT_MTU); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); --- 94,98 ---- packet_ptr = net->packet_data; ! memset(packet_ptr, 0, net->mtu); /* fixme: fix the default mtu issue! */ eth_write_packet_image(net->ether_p, packet_ptr); *************** *** 374,378 **** */ ! if(total_len > DEFAULT_MTU) FATAL_MESSAGE ("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); --- 374,378 ---- */ ! if(total_len > net->mtu) FATAL_MESSAGE ("Outgoing DHCP packet too large. I'm currently not implementing this properly so I'll have to exit!"); Index: dhcp-rawnet.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-rawnet.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-rawnet.c 29 Dec 2002 05:09:55 -0000 1.5 --- dhcp-rawnet.c 3 Jan 2003 21:29:22 -0000 1.6 *************** *** 105,108 **** --- 105,112 ---- /* now set our address, whether we set it earlier or not. */ rawnet_get_ip_addr(net, &net->cip_addr); + + xfree(net->packet_data); + net->packet_data = xmalloc(mtu); + return 0; } *************** *** 136,140 **** */ ! static pcap_t *initialize_pcap_device(char *interface_name, char *filter_string, int promiscuous) { pcap_t *pcap; --- 140,145 ---- */ ! static pcap_t *initialize_pcap_device(char *interface_name, int snaplen, ! char *filter_string, int promiscuous) { pcap_t *pcap; *************** *** 150,154 **** /* Open packet capturing device. */ ! pcap = pcap_open_live(interface_name, SNAPLEN, promiscuous, 0, errbuf); if(pcap == NULL) { ERROR_MESSAGE("could not open pcap device: %s", pcap_geterr(pcap)); --- 155,159 ---- /* Open packet capturing device. */ ! pcap = pcap_open_live(interface_name, snaplen, promiscuous, 0, errbuf); if(pcap == NULL) { ERROR_MESSAGE("could not open pcap device: %s", pcap_geterr(pcap)); *************** *** 191,195 **** /* Create the workhorse raw network module. */ ! rawnet_t *rawnet_create(const char *device, const char *filter, int dhcp_src_port, int dhcp_dst_port, int promiscuous, int clear_address) { --- 196,200 ---- /* Create the workhorse raw network module. */ ! rawnet_t *rawnet_create(const char *device, const char *filter, int mtu, int dhcp_src_port, int dhcp_dst_port, int promiscuous, int clear_address) { *************** *** 202,207 **** net->device = xstrdup(device); net->pcap_filter = xstrdup(filter); ! net->packet_data = xcalloc(DEFAULT_MTU); /* XXX -- fixme make mtu configurable. */ net->promiscuous = promiscuous; /* get the interface handle for bringing it up or down and querying it. */ --- 207,213 ---- net->device = xstrdup(device); net->pcap_filter = xstrdup(filter); ! net->packet_data = xcalloc(mtu); net->promiscuous = promiscuous; + net->mtu = mtu; /* get the interface handle for bringing it up or down and querying it. */ *************** *** 226,230 **** /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0, -1, clear_address)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); --- 232,236 ---- /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0, net->mtu, clear_address)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); *************** *** 236,240 **** * so our caller wants us to initialize it either way. */ ! if(rawnet_interface_up(net, 0, 0, -1, clear_address)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); --- 242,246 ---- * so our caller wants us to initialize it either way. */ ! if(rawnet_interface_up(net, 0, 0, net->mtu, clear_address)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); *************** *** 256,260 **** /* get pcap handler */ ! net->pcap = initialize_pcap_device(net->device, net->pcap_filter, promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap device for: %s", device); --- 262,266 ---- /* get pcap handler */ ! net->pcap = initialize_pcap_device(net->device, net->mtu, net->pcap_filter, promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap device for: %s", device); *************** *** 381,385 **** int rawnet_up(rawnet_t *net) { ! net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap on device: %s", net->device); --- 387,391 ---- int rawnet_up(rawnet_t *net) { ! net->pcap = initialize_pcap_device(net->device, net->mtu, net->pcap_filter, net->promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap on device: %s", net->device); Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-sniff.c 2 Jan 2003 04:23:01 -0000 1.6 --- dhcp-sniff.c 3 Jan 2003 21:29:22 -0000 1.7 *************** *** 32,35 **** --- 32,36 ---- #include "dhcp-print.h" + #include "dhcp-sniff-defaults.h" int interactive = 1; *************** *** 118,122 **** /* It's ok not to set ports since we're not writing any packets. */ ! net = rawnet_create(interface_name, stringbuffer_getstring(filter), 0, 0, 1, 0); if(net == NULL) { FATAL_MESSAGE("unable to access raw network"); --- 119,123 ---- /* It's ok not to set ports since we're not writing any packets. */ ! net = rawnet_create(interface_name, stringbuffer_getstring(filter), DEFAULT_SNIFF_SNAPLEN, 0, 0, 1, 0); if(net == NULL) { FATAL_MESSAGE("unable to access raw network"); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-sysconf.c 2 Jan 2003 04:23:01 -0000 1.12 --- dhcp-sysconf.c 3 Jan 2003 21:29:22 -0000 1.13 *************** *** 255,290 **** memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); - sends = client_conf_get_icmp_retries(dc->conf); - - /* we're guaranteed at least one router and one returned from icmp_rtt_discovery */ routers = value; - average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends); ! /* Even if all routers fail to respond to the ICMP echo query, ! * we still want to use one of them. ! * (See RFC 1812, section 4.3.3.6.) */ ! list_rewind(average_latencies); ! addr_val = list_next(average_latencies); ! lowest_latency = list_next(average_latencies); ! while(((tmp_addr_val = list_next(average_latencies)) != NULL) ! && ((latency = list_next(average_latencies)) != NULL)) { ! if(*latency != -1 && *latency < *lowest_latency) { ! *lowest_latency = *latency; ! addr_val = tmp_addr_val; } - } ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! list_destroy(average_latencies, xfree); rt = route_open(); --- 255,302 ---- memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); routers = value; ! if(client_conf_get_do_measure_router_latency_icmp(dc->conf, ! dhcp_client_get_server_ip_address(dc), dhcp_client_get_server_hw_address(dc))) { ! /* check router latency with icmp. this is probably broken. */ ! sends = client_conf_get_icmp_retries(dc->conf, dhcp_client_get_server_ip_address(dc), dhcp_client_get_server_hw_address(dc)); ! /* we're guaranteed at least one router and one returned from icmp_rtt_discovery */ ! average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends); ! ! /* Even if all routers fail to respond to the ICMP echo query, ! * we still want to use one of them. ! * (See RFC 1812, section 4.3.3.6.) */ ! ! list_rewind(average_latencies); ! addr_val = list_next(average_latencies); ! lowest_latency = list_next(average_latencies); ! ! while(((tmp_addr_val = list_next(average_latencies)) != NULL) ! && ((latency = list_next(average_latencies)) != NULL)) { ! ! if(*latency != -1 && *latency < *lowest_latency) { ! *lowest_latency = *latency; ! addr_val = tmp_addr_val; ! } } ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! list_destroy(average_latencies, xfree); ! ! } else { ! ! /* just get the first value. */ ! addr_val = list_first(routers); ! } rt = route_open(); *************** *** 382,388 **** uint8_t have_addr = 0; uint8_t have_netmask = 0; ! uint16_t mtu = DEFAULT_MTU; cache_entry_t *ce; void *data; INFO_MESSAGE("configuring interface: %s", dc->interface); --- 394,401 ---- uint8_t have_addr = 0; uint8_t have_netmask = 0; ! uint16_t mtu_val = 0; cache_entry_t *ce; void *data; + int mtu; INFO_MESSAGE("configuring interface: %s", dc->interface); *************** *** 428,432 **** } ! if(rawnet_interface_up(dc->rawnet, addr, netmask, (int)mtu, 1)) { ERROR_MESSAGE("could not bring interface up: %s", rawnet_get_device_name(dc->rawnet)); return -1; --- 441,451 ---- } ! if(mtu_val != 0) ! mtu = mtu_val; /* we're promoting so it is safe. */ ! else ! mtu = client_conf_get_default_mtu(dc->conf); ! ! ! if(rawnet_interface_up(dc->rawnet, addr, netmask, mtu, 1)) { ERROR_MESSAGE("could not bring interface up: %s", rawnet_get_device_name(dc->rawnet)); return -1; |
From: <act...@us...> - 2003-01-03 21:29:01
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv31371 Modified Files: TODO Log Message: more TODO Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TODO 2 Jan 2003 04:21:16 -0000 1.6 --- TODO 3 Jan 2003 21:28:56 -0000 1.7 *************** *** 62,66 **** think this is done now) ! -- purge_list only accepts one destructor. we need a way of destroying a list with differnet data types. (this looks too complicated to do and not enough code needs it) --- 62,66 ---- think this is done now) ! -- list_destroy only accepts one destructor. we need a way of destroying a list with differnet data types. (this looks too complicated to do and not enough code needs it) *************** *** 74,76 **** -- write dhcp-sysconf to allow configuration via a small minimalistic interpreter - --- 74,75 ---- |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv25981/src Modified Files: dhcp-arp-discovery.c dhcp-cache-entry.c dhcp-client-cache.c dhcp-client-conf.c dhcp-client-states.c dhcp-client.c dhcp-com.c dhcp-conf.c dhcp-convert.c dhcp-icmp-discovery.c dhcp-interface.c dhcp-librawnet.h dhcp-libutil.h dhcp-list.c dhcp-sniff.c dhcp-sysconf.c dhcp-timer.c Log Message: redid list object Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp-discovery.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-arp-discovery.c 16 Nov 2002 00:23:42 -0000 1.3 --- dhcp-arp-discovery.c 2 Jan 2003 04:23:01 -0000 1.4 *************** *** 41,49 **** list_t *argument_list = data; ! net = argument_list->data; ! if(argument_list->next) ! addr = argument_list->next->data; ! else { ! WARN_MESSAGE("check arp reply: no address passed to function -- skipping"); return 0; } --- 41,49 ---- list_t *argument_list = data; ! net = list_first(argument_list); ! addr = list_second(argument_list); ! ! if(addr == NULL) { ! WARN_MESSAGE("no address passed to function -- skipping"); return 0; } *************** *** 71,80 **** eth_addr_t *mac_addr) { ! list_t *arg_list = NULL; unsigned char *sender_addr; int retval; ! arg_list = add_to_list(arg_list, &address); ! arg_list = add_to_list(arg_list, net); /* 0 for source ip, address to discover for dest, our --- 71,81 ---- eth_addr_t *mac_addr) { ! list_t *arg_list; unsigned char *sender_addr; int retval; ! arg_list = list_create(); ! list_add(arg_list, &address); ! list_add(arg_list, net); /* 0 for source ip, address to discover for dest, our *************** *** 102,111 **** 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; --- 103,107 ---- memcpy(mac_addr->data, sender_addr, ETH_ADDR_LEN); ! list_destroy(arg_list, NULL); return 0; *************** *** 114,117 **** --- 110,114 ---- /* wops error. this is bad. */ ERROR_MESSAGE("received error from raw network handler."); + list_destroy(arg_list, NULL); return 1; *************** *** 123,129 **** } ! /* FIXME: ditto (see above) */ ! xfree(arg_list->next); ! xfree(arg_list); WARN_MESSAGE("timeout on discovery."); --- 120,124 ---- } ! list_destroy(arg_list, NULL); WARN_MESSAGE("timeout on discovery."); Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-cache-entry.c 16 Dec 2002 10:04:32 -0000 1.5 --- dhcp-cache-entry.c 2 Jan 2003 04:23:01 -0000 1.6 *************** *** 68,72 **** void cache_entry_purge_list(list_t *cache_list) { ! purge_list(cache_list, cache_entry_destroy_l); return; } --- 68,72 ---- void cache_entry_purge_list(list_t *cache_list) { ! list_destroy(cache_list, cache_entry_destroy_l); return; } Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-cache.c 30 Dec 2002 03:41:51 -0000 1.12 --- dhcp-client-cache.c 2 Jan 2003 04:23:01 -0000 1.13 *************** *** 47,51 **** cc = xmalloc(sizeof(client_cache_t)); cc->interface = interface; /* don't copy just point. */ ! cc->vars = NULL; return cc; --- 47,51 ---- cc = xmalloc(sizeof(client_cache_t)); cc->interface = interface; /* don't copy just point. */ ! cc->vars = list_create(); return cc; *************** *** 57,61 **** { cache_entry_purge_list(cc->vars); ! cc->vars = NULL; return; } --- 57,61 ---- { cache_entry_purge_list(cc->vars); ! cc->vars = list_create(); return; } *************** *** 207,211 **** while((cache_entry = read_next_cache_var(varfile)) != NULL) ! cc->vars = add_to_list(cc->vars, cache_entry); destroy_varfile(varfile); --- 207,211 ---- while((cache_entry = read_next_cache_var(varfile)) != NULL) ! list_add(cc->vars, cache_entry); destroy_varfile(varfile); *************** *** 292,306 **** void *(*convert_func) (unsigned char tag, char *string)) { ! list_t *options = NULL; ! list_t *cache; cache_entry_t *ce; void *data; ! for(cache = cc->vars; cache; cache = cache->next) { - 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); } --- 292,307 ---- void *(*convert_func) (unsigned char tag, char *string)) { ! list_t *options; cache_entry_t *ce; void *data; ! options = list_create(); ! ! list_rewind(cc->vars); ! while((ce = list_next(cc->vars)) != NULL) { 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. */ ! list_add(options, data); } *************** *** 318,322 **** { FILE *fp; - list_t *list_ptr; char *name; char *val; --- 319,322 ---- *************** *** 332,342 **** 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; - if(option_convert_handlers[opt->tag].serialize == NULL) continue; --- 332,341 ---- return -1; ! list_rewind(options); ! while((opt = list_next(options)) != NULL) { /* Run coversion routines to store internally in * serialized (string) state. */ if(option_convert_handlers[opt->tag].serialize == NULL) continue; *************** *** 374,378 **** char *string)) { - list_t *options; --- 373,376 ---- Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-conf.c 23 Dec 2002 00:51:24 -0000 1.14 --- dhcp-client-conf.c 2 Jan 2003 04:23:01 -0000 1.15 *************** *** 36,39 **** --- 36,40 ---- #include "dhcp-options-strings.h" + /* FIXME: check for destroy params mem leak. */ /* * * * * * * * * * * * * * * * * * * *************** *** 236,242 **** int i; ! for(;strings; strings = strings->next) { ! ! option_string = strings->data; for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { --- 237,242 ---- int i; ! list_rewind(strings); ! for(option_string = list_next(strings); option_string; option_string = list_next(strings)) { for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { *************** *** 386,393 **** /* now process group. */ ! for(directive_list = directive_data; ! directive_list;directive_list = directive_list->next) { - directive = directive_list->data; if(directive_handlers[directive->command_code](params, directive, group_type, group_data)) return 1; --- 386,393 ---- /* now process group. */ ! directive_list = directive_data; ! list_rewind(directive_list); ! while((directive = list_next(directive_list)) != NULL) { if(directive_handlers[directive->command_code](params, directive, group_type, group_data)) return 1; *************** *** 406,411 **** args = directive->arguments; ! var_symbol = args->data; ! var_value = args->next->next->data; if(client_conf_set_variable(params, *var_symbol, var_value)) { --- 406,411 ---- args = directive->arguments; ! var_symbol = list_get_by_index(args, 0); ! var_value = list_get_by_index(args, 3); if(client_conf_set_variable(params, *var_symbol, var_value)) { *************** *** 424,428 **** args = directive->arguments; ! string_list = args->data; if(fill_option_bit_array_from_string_list(string_list, params->request_options)) --- 424,428 ---- args = directive->arguments; ! string_list = list_first(args); if(fill_option_bit_array_from_string_list(string_list, params->request_options)) *************** *** 439,443 **** args = directive->arguments; ! string_list = args->data; if(fill_option_bit_array_from_string_list(string_list, params->required_options)) --- 439,443 ---- args = directive->arguments; ! string_list = list_first(args); if(fill_option_bit_array_from_string_list(string_list, params->required_options)) *************** *** 455,465 **** conf_params_t *new_params; directive_group_t new_group_type; ! /* FIXME: check for the same group specified twice. ! * this gives us a bit of compression in the unlikely ! * case of a broken config file. */ ! ! args = directive_data; ! server_symbol = args->data; switch(*server_symbol) { --- 455,463 ---- conf_params_t *new_params; directive_group_t new_group_type; + directive_t *directive; ! directive = directive_data; ! args = directive->arguments; ! server_symbol = list_first(args); switch(*server_symbol) { *************** *** 483,488 **** } ! address_data = args->next->data; ! directives = args->next->next->data; new_params = xcalloc(sizeof(conf_params_t)); --- 481,486 ---- } ! address_data = list_get_by_index(args, 1); ! directives = list_get_by_index(args, 2); new_params = xcalloc(sizeof(conf_params_t)); *************** *** 490,494 **** return 1; ! params->lower_params = add_to_list(params->lower_params, new_params); return 0; --- 488,495 ---- return 1; ! if(params->lower_params == NULL) ! params->lower_params = list_create(); ! ! list_add(params->lower_params, new_params); return 0; *************** *** 504,509 **** args = directive->arguments; ! var_symbol = args->data; ! var_value = args->next->next->data; if(client_conf_set_variable_boolean(params, *var_symbol, *var_value)) { --- 505,510 ---- args = directive->arguments; ! var_symbol = list_get_by_index(args, 0); ! var_value = list_get_by_index(args, 2); if(client_conf_set_variable_boolean(params, *var_symbol, *var_value)) { *************** *** 526,529 **** --- 527,531 ---- cc->interface = interface; cc->conf_file = get_conf_options_fname(cc); + cc->parameters.lower_params = list_create(); cc->parameters.group_type = DIRECTIVE_GROUP_NULL; /* set top level to catchall group. */ *************** *** 542,555 **** conf_params_t *lower_params; ! for(params_list = params->lower_params; ! params_list; params_list = params_list->next) { ! ! lower_params = params_list->data; params_destroy(lower_params, 0); - } if(params->client_hostname) xfree(params->client_hostname); if(!topflag) --- 544,559 ---- conf_params_t *lower_params; ! params_list = params->lower_params; ! list_rewind(params_list); ! for(lower_params = list_next(params_list); lower_params; ! lower_params = list_next(params_list)) { params_destroy(lower_params, 0); } if(params->client_hostname) xfree(params->client_hostname); + + list_destroy(params->lower_params, NULL); + params->lower_params = NULL; if(!topflag) Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dhcp-client-states.c 30 Dec 2002 21:54:37 -0000 1.23 --- dhcp-client-states.c 2 Jan 2003 04:23:01 -0000 1.24 *************** *** 47,60 **** static list_t *client_build_release_option_list(dhcp_client_control_t *dc) { ! list_t *options = NULL; dhcp_option_t *option; /* client_id: RFC2131 says we MAY */ 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); ! options = add_to_list(options, option); return options; --- 47,62 ---- static list_t *client_build_release_option_list(dhcp_client_control_t *dc) { ! list_t *options; dhcp_option_t *option; + options = list_create(); + /* client_id: RFC2131 says we MAY */ option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); ! list_add(options, option); /* dhcp message type. */ option = dhcp_build_message_type(DHCP_RELEASE_TM); ! list_add(options, option); return options; *************** *** 65,84 **** static list_t *client_build_option_list(dhcp_client_control_t *dc) { ! list_t *options = NULL; dhcp_option_t *option; const char *hostname; /* 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)); ! options = add_to_list(options, option); /* class_id */ option = dhcp_build_class_id(dc->class_id); ! options = add_to_list(options, option); /* hostname if available */ --- 67,87 ---- static list_t *client_build_option_list(dhcp_client_control_t *dc) { ! list_t *options; dhcp_option_t *option; const char *hostname; + options = list_create(); /* dhcp max DHCP message size: * should go into globconf. */ option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE); ! list_add(options, option); /* client_id */ option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); ! list_add(options, option); /* class_id */ option = dhcp_build_class_id(dc->class_id); ! list_add(options, option); /* hostname if available */ *************** *** 87,91 **** /* if we have one set it. */ option = dhcp_build_hostname(hostname); ! options = add_to_list(options, option); } --- 90,94 ---- /* if we have one set it. */ option = dhcp_build_hostname(hostname); ! list_add(options, option); } *************** *** 96,116 **** static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { ! list_t *options = NULL; ! list_t *requested_options = NULL; dhcp_option_t *option; option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); if(option == NULL) { WARN_MESSAGE("sending with empty parameter request list"); } else { ! 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); return options; --- 99,120 ---- static list_t *client_build_discover_option_list(dhcp_client_control_t *dc) { ! list_t *options; ! list_t *requested_options; dhcp_option_t *option; + options = list_create(); option = dhcp_build_parameter_request_list_option(client_conf_get_opt_bit_array(dc->conf)); if(option == NULL) { WARN_MESSAGE("sending with empty parameter request list"); } else { ! list_add(options, option); } /* dhcp message type. */ option = dhcp_build_message_type(DHCP_DISCOVER_TM); ! list_add(options, option); requested_options = client_build_option_list(dc); ! list_join(options, requested_options); /* this destroys requested_options */ return options; *************** *** 120,133 **** static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { ! list_t *options = NULL; ! list_t *requested_options = NULL; dhcp_option_t *option; /* dhcp message type. */ option = dhcp_build_message_type(DHCP_REQUEST_TM); ! options = add_to_list(options, option); requested_options = client_build_option_list(dc); ! options = join_lists(options, requested_options); return options; --- 124,138 ---- static list_t *client_build_request_option_list(dhcp_client_control_t *dc) { ! list_t *options; ! list_t *requested_options; dhcp_option_t *option; + options = list_create(); /* dhcp message type. */ option = dhcp_build_message_type(DHCP_REQUEST_TM); ! list_add(options, option); requested_options = client_build_option_list(dc); ! list_join(options, requested_options); /* this destroys requested_options */ return options; *************** *** 137,150 **** 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; --- 142,156 ---- static list_t *client_build_renew_option_list(dhcp_client_control_t *dc) { ! list_t *options; dhcp_option_t *option; + options = list_create(); /* dhcp message type. */ option = dhcp_build_message_type(DHCP_REQUEST_TM); ! list_add(options, option); /* client_id */ option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); ! list_add(options, option); return options; *************** *** 229,233 **** /* is rawnet happy with the packet? */ ! if(((!rawnet_is_valid(dc->rawnet)) "&& /* is it a DHCP packet? */ --- 235,239 ---- /* is rawnet happy with the packet? */ ! if(((!rawnet_is_valid(dc->rawnet)) && /* is it a DHCP packet? */ *************** *** 305,309 **** dhcp_client_update_secs(dc); ! rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs); return; } --- 311,315 ---- dhcp_client_update_secs(dc); ! rawnet_dhcp_update(dc->rawnet, (uint16_t)dc->secs); /* FIXME: this may be an integer overflow. */ return; } *************** *** 316,320 **** 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); --- 322,326 ---- timer_options = client_cache_load_option_timer_string_list(dc->cache, 0); ! if(list_get_len(timer_options) == 0) { FATAL_MESSAGE("no timers to setup. we should have least one: lease time"); exit(1); *************** *** 405,409 **** int client_discover_offer(dhcp_client_control_t *dc) { ! list_t *options = NULL; int retval; --- 411,415 ---- int client_discover_offer(dhcp_client_control_t *dc) { ! list_t *options; int retval; *************** *** 460,471 **** 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. */ --- 466,475 ---- if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS)) ! list_add(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)) ! list_add(dc->rawnet->dhcp_p->options, ! dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); /* dump cache file. */ *************** *** 493,502 **** 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 --- 497,507 ---- cache_options = client_cache_load_option_network_list(dc->cache, 0); ! if(list_get_len(cache_options) == 0) { ! ERROR_MESSAGE("could not load cache."); return STATE_FATAL_ERROR; } ! list_join(options, cache_options); /* destroys cache_options. */ /* Our options cleared by build_* since they are passed *************** *** 584,588 **** 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; --- 589,593 ---- options = client_cache_load_option_string_list(dc->cache, 0); ! if(list_get_len(options) == 0) { ERROR_MESSAGE("received empty configuration cache! cannot configure host"); return STATE_FATAL_ERROR; *************** *** 672,676 **** * 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); --- 677,681 ---- * 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); *************** *** 697,702 **** 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); --- 702,706 ---- cached_options = client_cache_load_option_string_list(dc->cache, 0); ! do_sysconf_cleanup(cached_options, dc); cache_entry_purge_list(cached_options); *************** *** 715,719 **** list_t *options; int retval; - INFO_MESSAGE("attempting DHCP RENEW"); --- 719,722 ---- Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-client.c 31 Dec 2002 10:30:59 -0000 1.20 --- dhcp-client.c 2 Jan 2003 04:23:01 -0000 1.21 *************** *** 166,174 **** interface_list = rawnet_list_inactive_interfaces(); ! if(interface_list == NULL) return NULL; ! first_interface = xstrdup(interface_list->data); ! purge_list(interface_list, NULL); return first_interface; } --- 166,176 ---- interface_list = rawnet_list_inactive_interfaces(); ! if(list_get_len(interface_list) == 0) { ! list_destroy(interface_list, xfree); return NULL; + } ! first_interface = xstrdup(list_first(interface_list)); ! list_destroy(interface_list, xfree); return first_interface; } Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-com.c 27 Dec 2002 02:52:30 -0000 1.7 --- dhcp-com.c 2 Jan 2003 04:23:01 -0000 1.8 *************** *** 42,47 **** dhcp = xmalloc(sizeof(dhcp_obj)); ! dhcp->options = NULL; ! dhcp->options_seek = NULL; return dhcp; --- 42,46 ---- dhcp = xmalloc(sizeof(dhcp_obj)); ! dhcp->options = list_create(); return dhcp; *************** *** 52,77 **** void dhcp_purge_option_list(list_t *options) { - list_t *list_ptr, *tmp; - dhcp_option_t *option; - /* Free up options. */ ! if(options) { ! ! list_ptr = options; ! ! while(list_ptr) { ! ! tmp = list_ptr->next; ! option = list_ptr->data; ! ! xfree(option->data); ! xfree(option); ! xfree(list_ptr); ! ! list_ptr = tmp; ! } ! } ! return; } --- 51,57 ---- void dhcp_purge_option_list(list_t *options) { /* Free up options. */ ! list_destroy(options, xfree); return; } *************** *** 82,87 **** { dhcp_purge_option_list(dhcp->options); ! dhcp->options = NULL; ! dhcp->options_seek = NULL; return; --- 62,66 ---- { dhcp_purge_option_list(dhcp->options); ! dhcp->options = list_create(); return; *************** *** 177,181 **** break; ! dhcp->options = add_to_end_of_list(dhcp->options, option); len -= (optlen + 2); --- 156,160 ---- break; ! list_add_to_end(dhcp->options, option); len -= (optlen + 2); *************** *** 184,189 **** } - dhcp->options_seek = dhcp->options; - return; } --- 163,166 ---- *************** *** 336,340 **** void dhcp_reset_option_seek(dhcp_obj * dhcp) { ! dhcp->options_seek = dhcp->options; } --- 313,317 ---- void dhcp_reset_option_seek(dhcp_obj * dhcp) { ! list_rewind(dhcp->options); } *************** *** 343,356 **** dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp) { ! dhcp_option_t *rval; ! ! if(dhcp->options_seek == NULL) ! return NULL; ! ! rval = dhcp->options_seek->data; ! ! dhcp->options_seek = dhcp->options_seek->next; ! ! return rval; } --- 320,324 ---- dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp) { ! return(list_next(dhcp->options)); } *************** *** 462,471 **** { uint16_t len = 0; - list_t *opts; dhcp_option_t *opt; int padding; ! for(opts = options; opts; opts = opts->next) { ! opt = opts->data; len += 2; /* for tag and len bytes. */ --- 430,438 ---- { uint16_t len = 0; dhcp_option_t *opt; int padding; ! list_rewind(options); ! while((opt = list_next(options)) != NULL) { len += 2; /* for tag and len bytes. */ *************** *** 691,695 **** { dhcp->options = options; - dhcp->options_seek = options; return; } --- 658,661 ---- Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-conf.c 22 Dec 2002 08:31:29 -0000 1.8 --- dhcp-conf.c 2 Jan 2003 04:23:01 -0000 1.9 *************** *** 106,112 **** 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; --- 106,113 ---- static void directive_destroy(directive_t *directive) { ! list_t *arg_ptr; ! list_t *type_ptr; ! arg_type_t *arg_type; ! void *arg_data; arg_ptr = directive->arguments; *************** *** 116,139 **** * 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; } --- 117,143 ---- * and call the destroy routine per argument. */ ! list_rewind(type_ptr); ! list_rewind(arg_ptr); ! while((arg_type = list_next(type_ptr)) != NULL) { ! /* each arg_type tells us which destructor to call on the ! * argument data. */ ! arg_data = list_next(arg_ptr); ! /* we're automatically rewound after any removal. */ ! /* this won't free up the datums themselves. */ ! list_remove_by_datum(type_ptr, arg_type); ! list_remove_by_datum(arg_ptr, arg_data); ! ! /* now destroy ourselves. */ ! argument_destroyers[*arg_type](arg_data); ! arg_type_destroy((arg_type_t *)arg_type); } + list_destroy(type_ptr, NULL); + list_destroy(arg_ptr, NULL); + return; } *************** *** 159,163 **** conf->filename = xstrdup(filename); conf->commands = commands; ! conf->directives = NULL; return conf; --- 163,167 ---- conf->filename = xstrdup(filename); conf->commands = commands; ! conf->directives = list_create(); return conf; *************** *** 168,172 **** xfree(conf->filename); tokenizer_destroy(conf->tokenizer); ! purge_list(conf->directives, directive_destroy_l); xfree(conf); --- 172,176 ---- xfree(conf->filename); tokenizer_destroy(conf->tokenizer); ! list_destroy(conf->directives, directive_destroy_l); xfree(conf); *************** *** 319,326 **** 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; token_t token; /* ask compile_arg_string_list to do the work for us. * we peek for commas but that's about it. */ --- 323,331 ---- static void *compile_arg_string_list(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { ! list_t *string_list; char *string; token_t token; + string_list = list_create(); /* ask compile_arg_string_list to do the work for us. * we peek for commas but that's about it. */ *************** *** 334,342 **** ERROR_MESSAGE("no string list found at %d\n", conf_get_line_no(conf)); ! 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. */ --- 339,347 ---- ERROR_MESSAGE("no string list found at %d\n", conf_get_line_no(conf)); ! list_destroy(string_list, xfree); return NULL; } ! list_add_to_end(string_list, string); /* now peek for a comma, if available keep going. */ *************** *** 383,389 **** 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); } --- 388,393 ---- arg_type = arg_type_create(command->argument_types[i]); ! list_add_to_end(directive->argument_types, arg_type); ! list_add_to_end(directive->arguments, args); } *************** *** 437,441 **** token_t token; 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 --- 441,447 ---- token_t token; directive_t *directive; ! list_t *directive_list; ! ! directive_list = list_create(); /* if we have a brace, go ahead and read in a command list. by compiling each command under it *************** *** 465,474 **** goto error; ! directive_list = add_to_end_of_list(directive_list, directive); } error: ! purge_list(directive_list, directive_destroy_l); return NULL; } --- 471,480 ---- goto error; ! list_add_to_end(directive_list, directive); } error: ! list_destroy(directive_list, directive_destroy_l); return NULL; } *************** *** 485,489 **** list_t *list = data; ! purge_list(list, NULL); /* just free up a list of strings. */ } --- 491,495 ---- list_t *list = data; ! list_destroy(list, xfree); /* just free up a list of strings. */ } *************** *** 492,496 **** list_t *list = data; ! purge_list(list, directive_destroy_l); /* free up a list of directives. */ return; --- 498,502 ---- list_t *list = data; ! list_destroy(list, directive_destroy_l); /* free up a list of directives. */ return; *************** *** 520,524 **** return CONF_ERROR; /* if we got a string it should match or error. */ ! conf->directives = add_to_end_of_list(conf->directives, directive); } --- 526,530 ---- return CONF_ERROR; /* if we got a string it should match or error. */ ! list_add_to_end(conf->directives, directive); } Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-convert.c 23 Dec 2002 00:51:24 -0000 1.7 --- dhcp-convert.c 2 Jan 2003 04:23:01 -0000 1.8 *************** *** 59,62 **** --- 59,65 ---- */ + /* forward declaration of utility routines. */ + static void purge_list_internal(void *list); + option_convert_handler option_convert_handlers[] = { {NULL, NULL, NULL, NULL} *************** *** 268,271 **** --- 271,280 ---- }; + /* utility routine to destroy list. */ + static void purge_list_internal(void *list) + { + list_destroy(list, xfree); + } + /* Byte conversions useful for flags, and 1/0 values. */ *************** *** 393,396 **** --- 402,407 ---- char *cp, *tmp_string, *orig_string;; + addr_list = list_create(); + sb = stringbuffer_create(); stringbuffer_append(sb, string); *************** *** 407,411 **** *cp = 0; addr = string_to_addr(tmp_string); ! addr_list = add_to_end_of_list(addr_list, addr); cp++; --- 418,422 ---- *cp = 0; addr = string_to_addr(tmp_string); ! list_add_to_end(addr_list, addr); cp++; *************** *** 417,421 **** xfree(orig_string); ! return addr_list; } --- 428,438 ---- xfree(orig_string); ! ! if(list_get_len(addr_list) == 0) { ! list_destroy(addr_list, NULL); ! return NULL; ! } else { ! return addr_list; ! } } *************** *** 432,452 **** void *string_addr_list_to_network(const char *string, unsigned char *len_ret) { - list_t *ptr; list_t *addr_list = string_to_addr_list(string); int count = 0; uint32_t *data, *cp; ! for(ptr = addr_list; ptr; ptr = ptr->next) ! count++; ! data = xmalloc(count * IP_ADDR_LEN); cp = data; ! for(ptr = addr_list; ptr; ptr = ptr->next) { ! memcpy(cp, ptr->data, IP_ADDR_LEN); cp++; } ! purge_list(addr_list, NULL); *len_ret = (count * 4); --- 449,470 ---- void *string_addr_list_to_network(const char *string, unsigned char *len_ret) { list_t *addr_list = string_to_addr_list(string); int count = 0; uint32_t *data, *cp; + uint32_t *addr; ! if(addr_list == NULL) ! return NULL; ! data = xmalloc(count * list_get_len(addr_list)); cp = data; ! list_rewind(addr_list); ! while((addr = list_next(addr_list)) != NULL) { ! memcpy(cp, addr, IP_ADDR_LEN); cp++; } ! list_destroy(addr_list, xfree); *len_ret = (count * 4); *************** *** 737,745 **** void *string_to_uint16_list(const char *s) { ! list_t *list_ptr = NULL; void *val; const char *cp; char *ptr; cp = s; while((ptr = strchr(cp, ';')) != NULL) { --- 755,765 ---- void *string_to_uint16_list(const char *s) { ! list_t *list_ptr; void *val; const char *cp; char *ptr; + list_ptr = list_create(); + cp = s; while((ptr = strchr(cp, ';')) != NULL) { *************** *** 749,753 **** break; ! list_ptr = add_to_list(list_ptr, val); ptr++; --- 769,773 ---- break; ! list_add(list_ptr, val); ptr++; *************** *** 755,758 **** --- 775,783 ---- break; cp = ptr; + } + + if(list_get_len(list_ptr) == 0) { + list_destroy(list_ptr, NULL); + return NULL; } Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-icmp-discovery.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-icmp-discovery.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-icmp-discovery.c 2 Jan 2003 04:23:01 -0000 1.4 *************** *** 152,156 **** list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses, int sends) { ! list_t *rtts = NULL; int *latency, *average_latency; int send_count, unreachable_count, highest_latency; --- 152,156 ---- list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses, int sends) { ! list_t *rtts; int *latency, *average_latency; int send_count, unreachable_count, highest_latency; *************** *** 158,161 **** --- 158,163 ---- eth_addr_t dest_mac; + rtts = list_create(); + /* Our algorithm works as such: send out an ICMP echo request * and wait for a reply. We count the total number of *************** *** 166,173 **** * address. */ ! /* loop per address. */ ! for(; addresses; addresses = addresses->next) { ! ! host_addr = addresses->data; /* We need to arp for MAC address first. Call --- 168,173 ---- * address. */ ! list_rewind(addresses); ! while((host_addr = list_next(addresses)) != NULL) { /* We need to arp for MAC address first. Call *************** *** 241,245 **** xfree(latency); /* free our latency array. */ ! rtts = add_to_list(rtts, average_latency); /* we need to copy the host address so --- 241,245 ---- xfree(latency); /* free our latency array. */ ! list_add(rtts, average_latency); /* we need to copy the host address so *************** *** 249,255 **** memcpy(host_addr_copy, host_addr, sizeof(ip_addr_t)); ! rtts = add_to_list(rtts, host_addr_copy); } ! return rtts; } --- 249,259 ---- memcpy(host_addr_copy, host_addr, sizeof(ip_addr_t)); ! list_add(rtts, host_addr_copy); } ! if(list_get_len(rtts) == 0) { ! list_destroy(rtts, NULL); ! return NULL; ! } else ! return rtts; } Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-interface.c 29 Dec 2002 05:09:55 -0000 1.5 --- dhcp-interface.c 2 Jan 2003 04:23:01 -0000 1.6 *************** *** 209,213 **** interfaces = arg; ! check = interfaces->data; /* first is always the routine to check routine. */ --- 209,213 ---- interfaces = arg; ! check = list_first(interfaces); /* first is always the routine to check routine. */ *************** *** 219,223 **** if(check(entry)) { intf_name = xstrdup(entry->intf_name); ! interfaces = add_to_end_of_list(interfaces, intf_name); } --- 219,223 ---- if(check(entry)) { intf_name = xstrdup(entry->intf_name); ! list_add_to_end(interfaces, intf_name); } *************** *** 228,243 **** { intf_t *interfaces; ! list_t *interface_list = NULL; ! list_t *returned_list; /* add check as first datum. */ ! interface_list = add_to_end_of_list(interface_list, check); interfaces = intf_open(); if(interfaces == NULL) { ! xfree(interface_list); /* fixme: this isn't really ! * good. we should have a way to destroy a list but not its ! * datums if we want to. */ intf_close(interfaces); ERROR_MESSAGE("could not obtain interface handle: %s", strerror(errno)); return NULL; --- 228,243 ---- { intf_t *interfaces; ! list_t *interface_list; + interface_list = list_create(); /* add check as first datum. */ ! list_add(interface_list, check); interfaces = intf_open(); if(interfaces == NULL) { ! ! list_destroy(interface_list, NULL); intf_close(interfaces); + ERROR_MESSAGE("could not obtain interface handle: %s", strerror(errno)); return NULL; *************** *** 248,255 **** intf_close(interfaces); ! returned_list = interface_list->next; ! xfree(interface_list); ! ! return returned_list; } --- 248,253 ---- intf_close(interfaces); ! list_remove_by_datum(interface_list, check); /* remove our check routine. */ ! return interface_list; } Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-librawnet.h 29 Dec 2002 05:09:55 -0000 1.8 --- dhcp-librawnet.h 2 Jan 2003 04:23:01 -0000 1.9 *************** *** 82,86 **** uint32_t magic_cookie; /* Magic cookie. */ list_t *options; /* Option list. */ - list_t *options_seek; /* Seek pointer to option list. */ } dhcp_obj; --- 82,85 ---- Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** dhcp-libutil.h 30 Dec 2002 00:45:03 -0000 1.22 --- dhcp-libutil.h 2 Jan 2003 04:23:01 -0000 1.23 *************** *** 46,53 **** /* native data structures. */ ! /* list object. */ ! typedef struct list { ! struct list *next; void *data; } list_t; --- 46,59 ---- /* native data structures. */ ! typedef struct node { ! struct node *next; void *data; + } node_t; + + typedef struct { + node_t *head; + node_t *tail; + node_t *seek; + int len; } list_t; *************** *** 195,206 **** /* 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 *)); /* stringbuffer. */ --- 201,217 ---- /* Linked List routines. */ ! extern list_t *list_create(void); ! extern void list_add(list_t *list, void *data); ! extern void list_add_to_end(list_t *list, void *data); ! extern int list_remove_by_datum(list_t *list, void *data); ! extern void list_destroy(list_t *list, void (*purge_func) (void *d)); ! extern void list_join(list_t *first_list, list_t *second_list); ! extern list_t *list_sort(list_t *list, int (*compare) (void *, void *)); ! extern void *list_get_by_index(list_t *list, int index); ! extern void *list_first(list_t *list); ! extern void *list_second(list_t *list); ! extern void list_rewind(list_t *list); ! extern void *list_next(list_t *list); ! extern int list_get_len(list_t *list); /* stringbuffer. */ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-list.c 16 Nov 2002 00:23:43 -0000 1.4 --- dhcp-list.c 2 Jan 2003 04:23:01 -0000 1.5 *************** *** 27,169 **** #include "dhcp-libutil.h" ! list_t *add_to_list(list_t *head, void *datum) { ! list_t *tmp; ! tmp = xmalloc(sizeof(list_t)); ! tmp->data = datum; ! tmp->next = head; ! return tmp; } ! list_t *add_to_end_of_list(list_t *head, void *datum) { ! list_t *tmp, *tmp2; ! tmp = xmalloc(sizeof(list_t)); ! tmp->data = datum; ! tmp->next = NULL; ! if(head == NULL) { ! return tmp; ! } else { ! for(tmp2 = head; tmp2->next; tmp2 = tmp2->next); ! tmp2->next = tmp; ! if(head == NULL) ! return tmp; ! else ! return head; } } ! list_t *remove_from_list(list_t *head, void *datum) { ! list_t *tmp, *tmp2; ! if(head->data == datum) { ! tmp = head->next; ! xfree(head); ! return tmp; ! } else { ! for(tmp = head; tmp->next; tmp = tmp->next) { ! if(tmp->next->data == datum) { ! tmp2 = tmp->next; ! tmp->next = tmp->next->next; ! xfree(tmp2); ! return head; ! } ! } } ! return NULL; /* this should never happen. */ ! } ! /* for convert array. */ ! void purge_list_internal(void *head) ! { ! purge_list((list_t *)head, NULL); } ! void purge_list(list_t *head, void (*purge_func) (void *d)) { ! list_t *tmp; ! while(head != NULL) { ! tmp = head; ! head = head->next; if(purge_func) ! purge_func(tmp->data); ! else ! xfree(tmp->data); ! xfree(tmp); } return; } ! list_t *join_lists(list_t *first_list, list_t *second_list) { - list_t *ptr; ! if(first_list == NULL) ! return second_list; ! if(second_list == NULL) ! return first_list; ! for(ptr = first_list; ptr->next; ptr = ptr->next); ! ptr->next = second_list; ! return first_list; ! } ! list_t *list_find_datum_by(list_t *list, int (*find_func) (void *, void *), void *arg) ! { ! list_t *ptr; ! for(ptr = list; ptr; ptr = ptr->next) { ! if(find_func(ptr, arg)) ! return ptr; } - return NULL; } ! /* we use a fairly dumb sorting algorithm. optimize later. the ! * real problem is we're using a list which sucks for these kinds ! * of things :-) */ ! list_t *sort_list(list_t *list, int (*compare) (void *, void *)) { ! list_t *new_list = NULL; ! list_t *highest, *ptr; while(1) { - /* keep looping until list is NULL. */ - highest = list; ! if(list == NULL) break; ! /* otherwise move down list and compare values. */ ! for(ptr = list->next; ptr; ptr = ptr->next) { ! if(compare(highest->data, ptr->data) == -1) { ! highest = ptr; } } ! new_list = add_to_list(new_list, highest->data); ! list = remove_from_list(list, highest->data); ! } return new_list; } --- 27,305 ---- #include "dhcp-libutil.h" ! /* create a new list. */ ! list_t *list_create(void) { ! list_t *list; ! list = xcalloc(sizeof(list_t)); ! return list; } ! /* add an item to the list. */ ! void list_add(list_t *list, void *data) { ! node_t *node; ! node = xcalloc(sizeof(node_t)); ! node->next = list->head; ! node->data = data; ! /* if there are no other datums the tail should be the node ! * too */ ! if(list->len == 0) ! list->tail = node; ! ! list->head = node; /* make the head the new node. */ ! list->len++; /* increment count. */ ! ! /* automatic rewind here. */ ! list_rewind(list); ! return; ! } ! ! /* add an item to the end of the list. */ ! void list_add_to_end(list_t *list, void *data) ! { ! node_t *node; ! ! /* if it's the only item in the list just add it normally. */ ! if(list->len == 0) { ! list_add(list, data); ! return; } + + node = xcalloc(sizeof(node_t)); + node->data = data; + + list->tail->next = node; + list->tail = node; + + list->len++; + + /* automatic rewind here. */ + list_rewind(list); + return; } ! /* remove a list pointer by the datum. this does not free the ! * datum itself. */ ! int list_remove_by_datum(list_t *list, void *data) { ! node_t *node, *node_prev; ! if(list->len == 0) /* nothing to remove. */ ! return 1; ! /* check if the datum is the head of the list. */ ! if(list->head->data == data) { ! ! /* just remove head. */ ! node = list->head; ! list->head = list->head->next; ! xfree(node); ! ! if(list->len == 1) /* then we should clear tail as well. */ ! list->tail = list->head; ! ! list->len--; ! ! /* automatic rewind here. */ ! list_rewind(list); ! return 0; } ! /* anything else means it's not the head and it's something further down. */ ! if(list->len == 1) ! return 1; /* can't be anything else then */ ! node_prev = list->head; ! for(node = list->head->next; node; node = node->next) { ! if(node->data == data) { ! node_prev->next = node->next; ! ! /* if we're pruning the last item then set previous to the tail. */ ! if(list->tail == node) ! list->tail = node_prev; ! ! xfree(node); ! list->len--; ! ! /* automatic rewind here. */ ! list_rewind(list); ! return 0; ! } ! ! node_prev = node; ! } ! ! /* we did not find it. */ ! return 1; } ! /* destroy a list. use purge_func to freeing the datum if it is set. */ ! void list_destroy(list_t *list, void (*purge_func) (void *d)) { ! node_t *node, *node_next; ! if(list->len == 0) { ! /* nada, just destroy the list. */ ! xfree(list); ! return; ! } ! ! node = list->head; ! while(1) { ! node_next = node->next; if(purge_func) ! purge_func(node->data); ! xfree(node); ! ! node = node_next; ! if(node == NULL) ! break; } + xfree(list); + return; } ! /* concatenate second list to first list. second_list's data is ! * preserved but the list pointer itself is destroyed. */ ! void list_join(list_t *first_list, list_t *second_list) { ! if(second_list->len == 0) { ! xfree(second_list); ! /* automatic rewind here. */ ! list_rewind(first_list); ! return; ! } if(first_list->len == 0) { ! first_list->len = second_list->len; ! first_list->head = second_list->head; ! first_list->tail = second_list->tail; ! xfree(second_list); ! /* automatic rewind here. */ ! list_rewind(first_list); ! return; ! } else { ! ! first_list->len += second_list->len; ! first_list->tail->next = second_list->head; ! first_list->tail = second_list->tail; ! ! xfree(second_list); ! ! /* automatic rewind here. */ ! list_rewind(first_list); ! return; } } ! /* we use a fairly dumb sorting algorithm. we recreate a list ! * and add the datums into it. once done just free up the old list ! * without freeing the datums and return the new sorted list. */ ! list_t *list_sort(list_t *list, int (*compare) (void *, void *)) { ! node_t *node_walk, *node_highest; ! list_t *new_list; ! ! if(list->len <= 1) /* one or less means we cannot sort. */ ! return list; ! ! new_list = list_create(); while(1) { ! if(list->len == 1) { ! list_add_to_end(new_list, list->head->data); ! list_remove_by_datum(list, list->head->data); break; + } ! node_highest = list->head; ! for(node_walk = list->head->next; node_walk; node_walk = node_walk->next) { ! if(compare(node_highest->data, node_walk->data) == 1) { ! node_highest = node_walk; } } ! list_add_to_end(new_list, node_highest->data); ! list_remove_by_datum(list, node_highest->data); } + list_destroy(list, NULL); return new_list; + } + + void *list_get_by_index(list_t *list, int index) + { + int i; + node_t *node; + + if(list->len == 0) + return NULL; + + if((list->len -1) < index) + return NULL; + + i = 0; + for(node = list->head; node && i < index; node = node->next) { + i++; + } + + if(node == NULL) + return NULL; + + return node->data; + } + + /* useful routines for pairs. */ + void *list_first(list_t *list) + { + return list_get_by_index(list, 0); + } + + void *list_second(list_t *list) + { + return list_get_by_index(list, 1); + } + + /* useful for walking a list. */ + void list_rewind(list_t *list) + { + list->seek = list->head; + return; + } + + void *list_next(list_t *list) + { + void *data; + + if(list->seek == NULL) + return NULL; + + data = list->seek->data; + list->seek = list->seek->next; + + return data; + } + + int list_get_len(list_t *list) + { + return list->len; } Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-sniff.c 29 Dec 2002 05:09:55 -0000 1.5 --- dhcp-sniff.c 2 Jan 2003 04:23:01 -0000 1.6 *************** *** 90,95 **** if(available_interfaces != NULL) { ! interface_name = xstrdup(available_interfaces->data); ! purge_list(available_interfaces, NULL); } else { --- 90,95 ---- if(available_interfaces != NULL) { ! interface_name = xstrdup(list_first(available_interfaces)); ! list_destroy(available_interfaces, xfree); } else { Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-sysconf.c 29 Dec 2002 05:09:55 -0000 1.11 --- dhcp-sysconf.c 2 Jan 2003 04:23:01 -0000 1.12 *************** *** 244,252 **** { struct route_entry r_entry; ! uint32_t *addr_val = NULL; route_t *rt; list_t *routers; ! list_t *average_latencies, *list_ptr; ! int lowest_latency; int *latency; int sends; --- 244,252 ---- { struct route_entry r_entry; ! uint32_t *tmp_addr_val, *addr_val = NULL; route_t *rt; list_t *routers; ! list_t *average_latencies; ! int *lowest_latency; int *latency; int sends; *************** *** 257,260 **** --- 257,261 ---- sends = client_conf_get_icmp_retries(dc->conf); + /* we're guaranteed at least one router and one returned from icmp_rtt_discovery */ routers = value; average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends); *************** *** 263,276 **** * we still want to use one of them. * (See RFC 1812, section 4.3.3.6.) */ - addr_val = average_latencies->data; - lowest_latency = *(int *)average_latencies->next->data; ! /* Now pick best router and use it as default. */ ! for(list_ptr = average_latencies; list_ptr != NULL; list_ptr = list_ptr->next->next) { ! latency = list_ptr->next->data; ! if(*latency != -1 && *latency < lowest_latency) { ! lowest_latency = *latency; ! addr_val = list_ptr->next->data; } } --- 264,278 ---- * we still want to use one of them. * (See RFC 1812, section 4.3.3.6.) */ ! list_rewind(average_latencies); ! addr_val = list_next(average_latencies); ! lowest_latency = list_next(average_latencies); ! while(((tmp_addr_val = list_next(average_latencies)) != NULL) ! && ((latency = list_next(average_latencies)) != NULL)) { ! ! if(*latency != -1 && *latency < *lowest_latency) { ! *lowest_latency = *latency; ! addr_val = tmp_addr_val; } } *************** *** 284,288 **** memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! purge_list(average_latencies, NULL); rt = route_open(); --- 286,290 ---- memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! list_destroy(average_latencies, xfree); rt = route_open(); *************** *** 332,337 **** { FILE *fp; ! list_t *servers; struct in_addr addr; fp = file_open_or_create_safe("resolv.conf", "a"); --- 334,340 ---- { FILE *fp; ! list_t *servers = value; struct in_addr addr; + void *data; fp = file_open_or_create_safe("resolv.conf", "a"); *************** *** 339,344 **** return -1; ! for(servers = value; servers; servers = servers->next) { ! memcpy(&addr.s_addr, servers->data, IP_ADDR_LEN); fprintf(fp, "nameserver %s\n", inet_ntoa(addr)); } --- 342,348 ---- return -1; ! list_rewind(servers); ! while((data = list_next(servers)) != NULL) { ! memcpy(&addr.s_addr, data, IP_ADDR_LEN); fprintf(fp, "nameserver %s\n", inet_ntoa(addr)); } *************** *** 375,379 **** static int sysconf_setup_interface(list_t *options, dhcp_client_control_t *dc) { - list_t *list_ptr; uint32_t addr, netmask; uint8_t have_addr = 0; --- 379,382 ---- *************** *** 385,391 **** INFO_MESSAGE("configuring interface: %s", dc->interface); ! for(list_ptr = options; list_ptr; list_ptr = list_ptr->next) { ! ! ce = list_ptr->data; if(TAG_DHCP_REQUESTED_IP_ADDRESS == ce->tag) { --- 388,393 ---- INFO_MESSAGE("configuring interface: %s", dc->interface)... [truncated message content] |
From: <act...@us...> - 2003-01-02 04:23:04
|
Update of /cvsroot/dhcp-agent/dhcp-agent/tests In directory sc8-pr-cvs1:/tmp/cvs-serv25981/tests Modified Files: Makefile.am Added Files: tests-list.c Log Message: redid list object --- NEW FILE: tests-list.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/tests-list.c,v 1.1 2003/01/02 04:23: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. * * list test code * */ /* this code is very redundant but since it's test code it * doesn't really matter. */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "tests.h" int foo[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int bar[] = { 11, 12, 13, 14, 15 }; int foo_rand[] = { 9, 2, 1, 7, 13, 5 }; int foo_sorted[] = { 13, 9, 7, 5, 2, 1 }; /* array of test routines. */ static int test_create_destroy(const char *name) { list_t *list; list = list_create(); list_destroy(list, NULL); return 0; } static int test_add_get_len(const char *name) { list_t *list; int i, len; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add(list, &foo[i]); } if(len != list_get_len(list)) { TEST_ERROR(name, "length do not match after list_add"); list_destroy(list, NULL); return 1; } list_destroy(list, NULL); return 0; } static int test_add_get_by_index(const char *name) { list_t *list; int i, j, len; int *ptr; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add(list, &foo[i]); } j = 0; /* list should come back backward. */ for(i = (len - 1);i >= 0; i--) { ptr = list_get_by_index(list, j); j++; if(*ptr != foo[i]) { TEST_ERROR(name, "values do not match after list_add"); list_destroy(list, NULL); return 1; } } list_destroy(list, NULL); return 0; } static int test_add_to_end_get_len(const char *name) { list_t *list; int i, len; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add_to_end(list, &foo[i]); } if(len != list_get_len(list)) { TEST_ERROR(name, "length do not match after list_add"); list_destroy(list, NULL); return 1; } list_destroy(list, NULL); return 0; } static int test_add_to_end_get_by_index(const char *name) { list_t *list; int i, len; int *ptr; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add_to_end(list, &foo[i]); } /* list should come back backward. */ for(i = 0;i < len; i++) { ptr = list_get_by_index(list, i); if(*ptr != foo[i]) { TEST_ERROR(name, "values do not match after list_add_to_end"); list_destroy(list, NULL); return 1; } } list_destroy(list, NULL); return 0; } static int test_add_remove_get_len(const char *name) { list_t *list; int i, len; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add(list, &foo[i]); } if(list_get_len(list) != len) { TEST_ERROR(name, "len do not match after list_add"); list_destroy(list, NULL); return 1; } for(i = 0;i < len; i++) { list_remove_by_datum(list, &foo[i]); if(list_get_len(list) != (len - (i + 1))) { TEST_ERROR(name, "len do not match after list_remove"); list_destroy(list, NULL); return 1; } } list_destroy(list, NULL); return 0; } static int test_add_to_end_remove_get_len(const char *name) { list_t *list; int i, len; list = list_create(); len = TEST_NELMS(foo); for(i = 0; i < len; i++) { list_add_to_end(list, &foo[i]); } if(list_get_len(list) != len) { TEST_ERROR(name, "len do not match after list_add"); list_destroy(list, NULL); return 1; } for(i = 0;i < len; i++) { list_remove_by_datum(list, &foo[i]); if(list_get_len(list) != (len - (i + 1))) { TEST_ERROR(name, "len do not match after list_remove"); list_destroy(list, NULL); return 1; } } list_destroy(list, NULL); return 0; } static int test_join(const char *name) { list_t *list_foo, *list_bar; int foo_len, bar_len, i; foo_len = TEST_NELMS(foo); bar_len = TEST_NELMS(bar); /* * * * * * * * * * * * * * * * * * * test with two populated lists * * * * * * * * * * * * * * * * * * */ list_foo = list_create(); list_bar = list_create(); for(i = 0; i < foo_len; i++) { list_add_to_end(list_foo, &foo[i]); } for(i = 0; i < bar_len; i++) { list_add_to_end(list_bar, &bar[i]); } /* now join the lists and check length * as well as individual datums. */ list_join(list_foo, list_bar); if((foo_len + bar_len) != list_get_len(list_foo)) { TEST_ERROR(name, "len do not match after list_join"); list_destroy(list_foo, NULL); return 1; } list_destroy(list_foo, NULL); /* * * * * * * * * * * * * * * * * * * test with first list populated * * * * * * * * * * * * * * * * * * */ list_foo = list_create(); list_bar = list_create(); for(i = 0; i < foo_len; i++) { list_add_to_end(list_foo, &foo[i]); } list_join(list_foo, list_bar); if(foo_len != list_get_len(list_foo)) { TEST_ERROR(name, "len do not match after list_join"); list_destroy(list_foo, NULL); return 1; } list_destroy(list_foo, NULL); /* * * * * * * * * * * * * * * * * * * * test with second list populated * * * * * * * * * * * * * * * * * * * */ list_foo = list_create(); list_bar = list_create(); for(i = 0; i < bar_len; i++) { list_add_to_end(list_bar, &foo[i]); } list_join(list_foo, list_bar); if(bar_len != list_get_len(list_foo)) { TEST_ERROR(name, "len do not match after list_join"); list_destroy(list_foo, NULL); list_destroy(list_bar, NULL); return 1; } list_destroy(list_foo, NULL); return 0; } static int compare(void *data1, void *data2) { int *i, *j; i = data1; j = data2; if(*i < *j) return 1; if(*j < *i) return -1; return 0; } static int test_sort(const char *name) { list_t *list_foo; int foo_len, i; int *j; foo_len = TEST_NELMS(foo_rand); list_foo = list_create(); for(i = 0; i < foo_len; i++) { list_add(list_foo, &foo_rand[i]); } list_foo = list_sort(list_foo, compare); i = 0; list_rewind(list_foo); while((j = list_next(list_foo)) != NULL) { if(foo_sorted[i] != *j) { TEST_ERROR(name, "data not sorted properly by list_sort"); list_destroy(list_foo, NULL); return 1; } i++; } list_destroy(list_foo, NULL); return 0; } static test_table tests[] = { { "create/destroy", test_create_destroy }, { "add/get_len", test_add_get_len }, { "add/get_by_index", test_add_get_by_index }, { "add_to_end/get_len", test_add_to_end_get_len }, { "add_to_end/get_by_index", test_add_to_end_get_by_index }, { "add/remove/get_len", test_add_remove_get_len }, { "add_to_end/remove/get_len", test_add_to_end_remove_get_len }, { "join", test_join }, { "sort", test_sort } }; /* main: loops. */ int main(int argc, char *argv[]) { DO_TESTS(tests); exit(TESTS_EXIT_SUCCESS); } Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/tests/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 30 Dec 2002 00:47:52 -0000 1.1 --- Makefile.am 2 Jan 2003 04:23:02 -0000 1.2 *************** *** 5,13 **** AUTOMAKE_OPTIONS = foreign AM_CFLAGS = -Wall -Werror ! check_PROGRAMS = stringbuffertest INCLUDES = -I../src ! stringbuffertest_SOURCES = tests-stringbuffer.c tests.h LDADD = ../src/libdhcputil.la ! TESTS = stringbuffertest --- 5,15 ---- AUTOMAKE_OPTIONS = foreign AM_CFLAGS = -Wall -Werror ! check_PROGRAMS = stringbuffertest listtest INCLUDES = -I../src ! noinst_HEADERS = tests.h ! listtest_SOURCES = tests-list.c ! stringbuffertest_SOURCES = tests-stringbuffer.c LDADD = ../src/libdhcputil.la ! TESTS = stringbuffertest listtest |
From: <act...@us...> - 2003-01-02 04:21:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv25574 Modified Files: TODO Log Message: updated TODO Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TODO 29 Dec 2002 05:33:01 -0000 1.5 --- TODO 2 Jan 2003 04:21:16 -0000 1.6 *************** *** 24,49 **** other todo: - -- check for duplicates in configure.in and compress them (for - example -I and -L flags should not be repeated.) - - -- add cleanup handlers to down routes, interfaces, etc. - dhcp-sysconf needs to be redone to allow the following: - - * configure an option for the system. - * register a routine to be run after the initial - configuration is done -- - useful for copying files around or delaying - a certain setting till an earlier one is complete. - * clean up the option for the system. - useful for deleting or removing settings - which are persistant (config files no longer valid) - - * add ability to run external program with option string - passed to it via exec() - - * add special minimalist shell which has few and well defined - metacharacters called dhcpsysconf. and allow system configuration - to be done through it. - -- rawnet_is_valid needs more checks. --- 24,27 ---- *************** *** 54,65 **** defined. - -- client_discover_offer() should update its timeout when receiving - unwanted packets. - - the rawnet_transact() routine should be replaced with something - that is more flexible in timing out while not even considering - invalid packets. Mayhaps reading the next packet could be done - with a high level filter. - -- implement decline, and inform in the client. --- 32,35 ---- *************** *** 69,81 **** all over the code. ! -- the rawnet routines should be a shared library due to too many ! dependencies. the sniffer for example, only needs the packet ! parsing routines. ! ! -- get stringbuffer used in places where strings are being manipulated ! heavily. ! ! -- fix stringbuffer trimwhitespace to use last_occurance routine, and ! add first occurance for finding initial whitespace too. -- we may need to change the dhcp_build_* routines to use the --- 39,43 ---- all over the code. ! -- stringbuffer used in almost _all_ string operations except really simple ones. -- we may need to change the dhcp_build_* routines to use the *************** *** 93,117 **** the messaging routines or create a new one. ! -- dhcpclient startup needs a more clever way of detecting interfaces: ! ! -- detect which interfaces already have clients on them ! -- accept a list from globconf ! -- 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. -- purge_list only accepts one destructor. we need a way of destroying a list ! with differnet data types. ! ! -- cache code needs to escape what it saves to '"' or the '\' ! since both are interpreted by our lower level parser. -- check for race condition -- even if it is tiny -- in client_wait -- make a distinction between SELECT and INIT-REBOOT. right now we have a single client_request_ack routine --- 55,76 ---- the messaging routines or create a new one. ! -- change uint32_t to ip_addr_t for ipv4 addresses. (this looks ! almost done) -- make it so set/get methods in all packeting routines do ! network type conversions and not higher level functions (i ! think this is done now) -- purge_list only accepts one destructor. we need a way of destroying a list ! with differnet data types. (this looks too complicated to do ! and not enough code needs it) -- check for race condition -- even if it is tiny -- in client_wait -- make a distinction between SELECT and INIT-REBOOT. right now we have a single client_request_ack routine + + -- complete client-conf code. define the prototype for a hook and + put it in all the right places. + + -- write dhcp-sysconf to allow configuration via a small minimalistic interpreter + |