mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 02:50:25 +03:00
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.
This commit is contained in:
@@ -227,6 +227,27 @@ void unregister_dhcp_options ( struct dhcp_option_block *options ) {
|
||||
list_del ( &options->list );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user