[Dhcp-agent-commits] CVS: dhcp-agent TODO,1.3,1.4 dhcp-agent.h,1.18,1.19 dhcp-com.c,1.3,1.4
Status: Alpha
Brought to you by:
actmodern
From: Thamer Al-H. <act...@us...> - 2002-02-08 18:15:56
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv30938 Modified Files: TODO dhcp-agent.h dhcp-com.c Log Message: dhcpclient now can read options if overloaded in sname of file bootp fields; Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TODO 30 Jan 2002 20:24:09 -0000 1.3 --- TODO 8 Feb 2002 18:15:52 -0000 1.4 *************** *** 10,15 **** extend over 255 octets) - -- deal with option overloads onto the bootp header. - major todos: --- 10,13 ---- Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-agent.h 7 Feb 2002 18:41:47 -0000 1.18 --- dhcp-agent.h 8 Feb 2002 18:15:52 -0000 1.19 *************** *** 408,411 **** --- 408,412 ---- # define TAG_DHCP_SUBNET_MASK 1 # define TAG_DHCP_REQUEST_IP_ADDRESS 50 + # define TAG_DHCP_OPTION_OVERLOAD 52 # define TAG_DHCP_MESSAGE_TYPE 53 # define TAG_DHCP_SERVER_IDENTIFIER 54 *************** *** 415,418 **** --- 416,425 ---- # define TAG_DHCP_CLIENT_ID 61 + /* DHCP overload option values. */ + + #define DHCP_OVERLOAD_FILE 1 + #define DHCP_OVERLOAD_SNAME 2 + #define DHCP_OVERLOAD_BOTH 3 + /* NetBIOS Scope Node Types */ *************** *** 620,623 **** --- 627,632 ---- extern int dhcp_have_atleast_requested_options(dhcp_obj *dhcp, unsigned char *option); extern int dhcp_have_option(dhcp_obj *dhcp, unsigned char tag); + extern int dhcp_is_file_overload(dhcp_obj *dhcp); + extern int dhcp_is_sname_overload(dhcp_obj *dhcp); extern dhcp_option *dhcp_build_parameter_request_list_option(unsigned char *requested_options); Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-com.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-com.c 3 Feb 2002 16:56:00 -0000 1.3 --- dhcp-com.c 8 Feb 2002 18:15:52 -0000 1.4 *************** *** 132,166 **** } ! /* read packet image. */ ! int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { unsigned char optlen; dhcp_option *option; - - /* Get the fixedheader or if not - * possible return an error. */ - - if(len < DHCP_FIXEDHDR_LEN) - return -1; - else - align_dhcphdr(dhcp_packet, &dhcp->fixedheader); ! len -= DHCP_FIXEDHDR_LEN; ! dhcp_packet += DHCP_FIXEDHDR_LEN; ! ! /* Copy out magic cookie. 4 octets. */ ! ! if(len >= 4) ! memcpy(&dhcp->magic_cookie, dhcp_packet, 4); ! else { ! memset(&dhcp->magic_cookie, 0, 4); /* set it to 0 so it doesn't pass test. */ ! return 0; ! } ! ! len -= 4; ! dhcp_packet += 4; ! ! /* ! * Now try and copy all the options. * We do no parsing at this point * since we may not require all --- 132,141 ---- } ! static void dhcp_read_options_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) { unsigned char optlen; dhcp_option *option; ! /* Try and copy all the options. * We do no parsing at this point * since we may not require all *************** *** 202,205 **** --- 177,223 ---- dhcp->options_seek = dhcp->options; + + return; + } + + /* read packet image. */ + int dhcp_read_packet_image(dhcp_obj *dhcp, const unsigned char *dhcp_packet, int len) + { + /* Get the fixedheader or if not + * possible return an error. */ + + if(len < DHCP_FIXEDHDR_LEN) + return -1; + else + align_dhcphdr(dhcp_packet, &dhcp->fixedheader); + + len -= DHCP_FIXEDHDR_LEN; + dhcp_packet += DHCP_FIXEDHDR_LEN; + + /* Copy out magic cookie. 4 octets. */ + + if(len >= 4) + memcpy(&dhcp->magic_cookie, dhcp_packet, 4); + else { + memset(&dhcp->magic_cookie, 0, 4); /* set it to 0 so it doesn't pass test. */ + return 0; + } + + len -= 4; + dhcp_packet += 4; + + /* read options placed after cookie. */ + dhcp_read_options_image(dhcp, dhcp_packet, len); + + /* We need to check file before sname to be compliant. */ + + /* Now check if we have options overload in file field + * and read options as necesssary. */ + if(dhcp_is_file_overload(dhcp)) + dhcp_read_options_image(dhcp, dhcp->fixedheader.file, DHCP_FILE_SIZE); + + /* Ditto on the sname field. */ + if(dhcp_is_sname_overload(dhcp)) + dhcp_read_options_image(dhcp, dhcp->fixedheader.sname, DHCP_SNAME_SIZE); return 0; *************** *** 388,391 **** --- 406,450 ---- } + /* get the overload which may be for file, sname, or both. */ + static unsigned char dhcp_get_overload_option(dhcp_obj *dhcp) + { + dhcp_option *option; + + dhcp_reset_option_seek(dhcp); + + while((option = dhcp_get_next_option(dhcp)) != NULL) { + if(option->tag == TAG_DHCP_OPTION_OVERLOAD) { + return *(option->data); + } + } + + return 0; + } + + /* options overloaded on file field? */ + int dhcp_is_file_overload(dhcp_obj *dhcp) + { + unsigned char overload_val = dhcp_get_overload_option(dhcp); + + if(overload_val == DHCP_OVERLOAD_FILE || + overload_val == DHCP_OVERLOAD_BOTH) + return 1; + else + return 0; + } + + /* options overloaded on sname field? */ + int dhcp_is_sname_overload(dhcp_obj *dhcp) + { + unsigned char overload_val = dhcp_get_overload_option(dhcp); + + if(overload_val == DHCP_OVERLOAD_SNAME || + overload_val == DHCP_OVERLOAD_BOTH) + return 1; + else + return 0; + } + + /* Check if we have at least the requested options: * count up the number of options we want, then |