diff options
author | Michael Brown | 2006-07-17 14:47:22 +0200 |
---|---|---|
committer | Michael Brown | 2006-07-17 14:47:22 +0200 |
commit | b24947f0c0f73978f274a604c224279de6daefd5 (patch) | |
tree | 3e590c70427b22229f9a3627910a78d6da8a5616 /src/net/dhcpopts.c | |
parent | Add (untested) code for parsing a received DHCP packet and constructing a (diff) | |
download | ipxe-b24947f0c0f73978f274a604c224279de6daefd5.tar.gz ipxe-b24947f0c0f73978f274a604c224279de6daefd5.tar.xz ipxe-b24947f0c0f73978f274a604c224279de6daefd5.zip |
Add sketch code to reassemble a DHCP packet from our internal "everything
is a DHCP option" data structures.
We need this code in order to be able to return a DHCP packet to a PXE NBP
which reflects options from our multiple sources (e.g. NVS and DHCP
server). This is expensive, but necessary. Having paid this cost, we may
as well try to use the same code to generate our DHCP request packets,
since the process is similar.
Diffstat (limited to 'src/net/dhcpopts.c')
-rw-r--r-- | src/net/dhcpopts.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c index 6b06b9a2..70196346 100644 --- a/src/net/dhcpopts.c +++ b/src/net/dhcpopts.c @@ -228,6 +228,27 @@ void unregister_dhcp_options ( struct dhcp_option_block *options ) { } /** + * Initialise empty block of DHCP options + * + * @v options Uninitialised DHCP option block + * @v data Memory for DHCP option data + * @v max_len Length of memory for DHCP option data + * + * Populates the DHCP option data with a single @c DHCP_END option and + * fills in the fields of the @c dhcp_option_block structure. + */ +void init_dhcp_options ( struct dhcp_option_block *options, + void *data, size_t max_len ) { + struct dhcp_option *option; + + options->data = data; + options->max_len = max_len; + option = options->data; + option->tag = DHCP_END; + options->len = 1; +} + +/** * Allocate space for a block of DHCP options * * @v max_len Maximum length of option block @@ -238,17 +259,12 @@ void unregister_dhcp_options ( struct dhcp_option_block *options ) { */ struct dhcp_option_block * alloc_dhcp_options ( size_t max_len ) { struct dhcp_option_block *options; - struct dhcp_option *option; options = malloc ( sizeof ( *options ) + max_len ); if ( options ) { - options->data = ( ( void * ) options + sizeof ( *options ) ); - options->max_len = max_len; - if ( max_len ) { - option = options->data; - option->tag = DHCP_END; - options->len = 1; - } + init_dhcp_options ( options, + ( (void *) options + sizeof ( *options ) ), + max_len ); } return options; } |