[dhcp-agent-commits] dhcp-agent/src dhcp-client-conf.c,1.8,1.9 dhcp-client-conf.h,1.5,1.6 dhcp-clien
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv22514 Modified Files: dhcp-client-conf.c dhcp-client-conf.h dhcp-client-control.c dhcp-client-states.c dhcp-ip.c dhcp-librawnet.h dhcp-libutil.h dhcp-util.c Log Message: more stuff Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client-conf.c 18 Dec 2002 05:40:38 -0000 1.8 --- dhcp-client-conf.c 19 Dec 2002 03:11:45 -0000 1.9 *************** *** 23,28 **** */ - /* THIS ENTIRE THING NEEDS TO BE REDONE. */ - #define MODULE_NAME "dhcp-client-conf" --- 23,26 ---- *************** *** 50,54 **** "dhcp-retries", "icmp-retries", ! "do-icmp-router-discovery", }; --- 48,52 ---- "dhcp-retries", "icmp-retries", ! "interface-mtu", }; *************** *** 66,70 **** CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, ! CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY, }; --- 64,68 ---- CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, ! CLIENT_VAR_INTERFACE_MTU, }; *************** *** 183,186 **** --- 181,190 ---- } + 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) { *************** *** 253,256 **** --- 257,265 ---- params->icmp_retries = atoi(var_value); + break; + + case CLIENT_VAR_INTERFACE_MTU: + + params->default_interface_mtu = atoi(var_value); break; Index: dhcp-client-conf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-conf.h 18 Dec 2002 05:40:38 -0000 1.5 --- dhcp-client-conf.h 19 Dec 2002 03:11:45 -0000 1.6 *************** *** 43,48 **** --- 43,51 ---- 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_icmp_router_discovery; /* perform router discovery via icmp. */ *************** *** 63,68 **** /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, ! CLIENT_VAR_DO_ICMP_ROUTER_DISCOVERY }; enum server_symbols { CLIENT_SERVER_IP = 0, CLIENT_SERVER_MAC }; --- 66,71 ---- /* symbols for variable substitution. */ ! enum var_symbols { CLIENT_VAR_HOSTNAME = 0, CLIENT_VAR_DHCP_RETRIES, CLIENT_VAR_ICMP_RETRIES, CLIENT_VAR_INTERFACE_MTU }; ! enum server_symbols { CLIENT_SERVER_IP = 0, CLIENT_SERVER_MAC }; *************** *** 75,78 **** --- 78,83 ---- 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); Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-client-control.c 16 Dec 2002 10:14:31 -0000 1.7 --- dhcp-client-control.c 19 Dec 2002 03:11:45 -0000 1.8 *************** *** 282,283 **** --- 282,295 ---- return; } + + /* get the server address. */ + + ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr) + { + return dc->sip_addr; + } + + eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr) + { + return dc->shw_addr; + } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-states.c 18 Dec 2002 05:40:38 -0000 1.10 --- dhcp-client-states.c 19 Dec 2002 03:11:45 -0000 1.11 *************** *** 33,36 **** --- 33,37 ---- #include "dhcp-librawnet.h" + #include "dhcp-options-strings.h" #include "dhcp-client-conf.h" #include "dhcp-cache-entry.h" *************** *** 40,44 **** /*************************** ! * Option List Generation. * ***************************/ --- 41,45 ---- /*************************** ! * option list generation * ***************************/ *************** *** 156,168 **** /****************** ! * Check Routines * ******************/ ! /* check the requested options. ! * we use the globconf option. */ ! static int client_check_requested_options(dhcp_client_control_t *dc) { ! /* FIXME: we default to at least. we need an actual policy in client_conf though. */ return 1; } --- 157,218 ---- /****************** ! * check routines * ******************/ ! /* check the requested options */ static int client_check_requested_options(dhcp_client_control_t *dc) { ! eth_addr_t eth_addr; ! ip_addr_t ip_addr; ! char *eth_addr_string; ! 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_source_addr(dc->rawnet->ip_p); ! eth_addr = eth_get_src_address(dc->rawnet->ether_p); ! ! eth_addr_string = eth_addr_to_string(eth_addr); ! ip_addr_string = ip_addr_to_string(ip_addr); ! ! /* build our received options array. */ ! ! memset(received_options, 0, sizeof(received_options)); ! dhcp_reset_option_seek(dc->rawnet->dhcp_p); ! ! while((dhcp_option = dhcp_get_next_option(dc->rawnet->dhcp_p)) != NULL) { ! ! /* if it's in our range fill it in or ignore it and give a warning. */ ! if(dhcp_option->tag > MAX_OPTIONS_HANDLED) { ! WARN_MESSAGE("ignoring received option tag which is out of our range: %d", dhcp_option->tag); ! continue; ! } ! ! 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. */ ! for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { ! ! if(required_options[i] && !received_options[i]) { ! WARN_MESSAGE("ignoring offer from server (%s : %s) : failed to supply required option: %s", ! ip_addr_string, eth_addr_string, dhcp_option_printable_string_get(i)); ! ! xfree(ip_addr_string); ! xfree(eth_addr_string); ! ! return 0; ! } ! } ! ! xfree(ip_addr_string); ! xfree(eth_addr_string); return 1; } *************** *** 192,202 **** if(client_check_dhcp(dc) && /* check that the type is an offer. */ dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) && /* check if the requested options match what we want. */ ! client_check_requested_options(dc)) return 1; ! else return 0; } --- 242,255 ---- if(client_check_dhcp(dc) && + /* check that the type is an offer. */ dhcp_is_type(dc->rawnet->dhcp_p, DHCP_OFFER_TM) && + /* check if the requested options match what we want. */ ! client_check_requested_options(dc)) { return 1; ! } else { return 0; + } } *************** *** 231,235 **** /************* ! * Utilities * *************/ --- 284,288 ---- /************* ! * utilities * *************/ *************** *** 333,337 **** /****************************** ! * DHCP client state routines.* ******************************/ --- 386,390 ---- /****************************** ! * DHCP client state routines * ******************************/ Index: dhcp-ip.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-ip.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-ip.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-ip.c 19 Dec 2002 03:11:45 -0000 1.4 *************** *** 48,57 **** } ! uint32_t ip_get_source_addr(ip_obj * ip) { return (ip->header.ip_src); } ! uint32_t ip_get_dest_addr(ip_obj * ip) { return (ip->header.ip_dst); --- 48,57 ---- } ! ip_addr_t ip_get_source_addr(ip_obj * ip) { return (ip->header.ip_src); } ! ip_addr_t ip_get_dest_addr(ip_obj * ip) { return (ip->header.ip_dst); Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-librawnet.h 16 Dec 2002 07:20:42 -0000 1.5 --- dhcp-librawnet.h 19 Dec 2002 03:11:45 -0000 1.6 *************** *** 465,470 **** extern void ip_write_packet_image(ip_obj * ip, unsigned char *packet); ! extern uint32_t ip_get_source_addr(ip_obj * ip); ! extern uint32_t ip_get_dest_addr(ip_obj * ip); extern unsigned char ip_get_hl(ip_obj * ip); extern uint8_t ip_get_proto(ip_obj * ip); --- 465,470 ---- extern void ip_write_packet_image(ip_obj * ip, unsigned char *packet); ! extern ip_addr_t ip_get_source_addr(ip_obj * ip); ! extern ip_addr_t ip_get_dest_addr(ip_obj * ip); extern unsigned char ip_get_hl(ip_obj * ip); extern uint8_t ip_get_proto(ip_obj * ip); Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-libutil.h 16 Dec 2002 07:20:42 -0000 1.11 --- dhcp-libutil.h 19 Dec 2002 03:11:45 -0000 1.12 *************** *** 179,182 **** --- 179,184 ---- extern ip_addr_t *string_ip_to_ip_addr(const char *string_ip); extern eth_addr_t *string_eth_addr_to_eth_addr(const char *eth_ip); + extern char *eth_addr_to_string(eth_addr_t eth_addr); + extern char *ip_addr_to_string(ip_addr_t ip_addr); extern int is_seven_bit_clean(const char *data, int len); *************** *** 222,226 **** /* interactive mode switch. */ ! void set_interactive(uint8_t interactive_arg); /* timer object. */ --- 224,228 ---- /* interactive mode switch. */ ! extern void set_interactive(uint8_t interactive_arg); /* timer object. */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-util.c 15 Dec 2002 00:22:02 -0000 1.8 --- dhcp-util.c 19 Dec 2002 03:11:45 -0000 1.9 *************** *** 526,527 **** --- 526,560 ---- return eth; } + + /* convert an ethernet address to a string and return a copy. */ + char *eth_addr_to_string(eth_addr_t eth_addr) + { + char *string; + stringbuffer *sb; + + sb = create_stringbuffer(); + stringbuffer_aprintf(sb, "%x:%x:%x:%x:%x:%x", eth_addr.data[0], eth_addr.data[1], + eth_addr.data[2], eth_addr.data[3], eth_addr.data[4], eth_addr.data[5]); + + string = xstrdup(stringbuffer_getstring(sb)); + + destroy_stringbuffer(sb); + return string; + + } + + /* convert an ip address to a string and return a copy. */ + char *ip_addr_to_string(ip_addr_t ip_addr) + { + char *string; + char *ip_string; + struct in_addr in_addr; + + in_addr.s_addr = ip_addr; + ip_string = inet_ntoa(in_addr); + string = xstrdup(ip_string); + + return string; + + } + |