iPXE
|
DHCP options. More...
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | dhcp_options |
A DHCP options block. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
int | dhcpopt_applies (unsigned int tag) |
Check applicability of DHCP option setting. | |
int | dhcpopt_store (struct dhcp_options *options, unsigned int tag, const void *data, size_t len) |
Store value of DHCP option setting. | |
int | dhcpopt_fetch (struct dhcp_options *options, unsigned int tag, void *data, size_t len) |
Fetch value of DHCP option setting. | |
void | dhcpopt_init (struct dhcp_options *options, void *data, size_t alloc_len, int(*realloc)(struct dhcp_options *options, size_t len)) |
Initialise prepopulated block of DHCP options. | |
void | dhcpopt_update_used_len (struct dhcp_options *options) |
Recalculate length of DHCP options block. | |
int | dhcpopt_no_realloc (struct dhcp_options *options, size_t len) |
Refuse to reallocate DHCP option block. |
DHCP options.
Definition in file dhcpopts.h.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
int dhcpopt_applies | ( | unsigned int | tag | ) |
Check applicability of DHCP option setting.
tag | Setting tag number |
applies | Setting applies to this option block |
Definition at line 359 of file dhcpopts.c.
References DHCP_ENCAP_OPT, and DHCP_MAX_OPTION.
Referenced by dhcppkt_applies(), and nvo_applies().
{ return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION, DHCP_MAX_OPTION ) ) ); }
int dhcpopt_store | ( | struct dhcp_options * | options, |
unsigned int | tag, | ||
const void * | data, | ||
size_t | len | ||
) |
Store value of DHCP option setting.
options | DHCP option block |
tag | Setting tag number |
data | Setting data, or NULL to clear setting |
len | Length of setting data |
rc | Return status code |
Definition at line 374 of file dhcpopts.c.
References offset, and set_dhcp_option().
Referenced by dhcppkt_store(), and nvo_store().
int dhcpopt_fetch | ( | struct dhcp_options * | options, |
unsigned int | tag, | ||
void * | data, | ||
size_t | len | ||
) |
Fetch value of DHCP option setting.
options | DHCP option block |
tag | Setting tag number |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 393 of file dhcpopts.c.
References dhcp_option::data, dhcp_option(), find_dhcp_option_with_encap(), dhcp_option::len, memcpy(), NULL, and offset.
Referenced by dhcppkt_fetch(), and nvo_fetch().
{ int offset; struct dhcp_option *option; size_t option_len; offset = find_dhcp_option_with_encap ( options, tag, NULL ); if ( offset < 0 ) return offset; option = dhcp_option ( options, offset ); option_len = option->len; if ( len > option_len ) len = option_len; memcpy ( data, option->data, len ); return option_len; }
void dhcpopt_init | ( | struct dhcp_options * | options, |
void * | data, | ||
size_t | alloc_len, | ||
int(*)(struct dhcp_options *options, size_t len) | realloc | ||
) |
Initialise prepopulated block of DHCP options.
options | Uninitialised DHCP option block |
data | Memory for DHCP option data |
alloc_len | Length of memory for DHCP option data |
realloc | DHCP option block reallocator |
The memory content must already be filled with valid DHCP options. A zeroed block counts as a block of valid DHCP options.
Definition at line 451 of file dhcpopts.c.
References dhcp_options::alloc_len, dhcp_options::data, data, DBGC, dhcpopt_update_used_len(), dhcp_options::realloc, realloc(), and dhcp_options::used_len.
Referenced by dhcppkt_init(), and nvo_init().
void dhcpopt_update_used_len | ( | struct dhcp_options * | options | ) |
Recalculate length of DHCP options block.
options | Uninitialised DHCP option block |
The "used length" field will be updated based on scanning through the block to find the end of the options.
Definition at line 420 of file dhcpopts.c.
References dhcp_options::alloc_len, dhcp_option(), dhcp_option_len(), DHCP_PAD, offset, dhcp_option::tag, and dhcp_options::used_len.
Referenced by dhcpopt_init(), and nvo_load().
{ struct dhcp_option *option; int offset = 0; ssize_t remaining = options->alloc_len; unsigned int option_len; /* Find last non-pad option */ options->used_len = 0; while ( remaining ) { option = dhcp_option ( options, offset ); option_len = dhcp_option_len ( option ); remaining -= option_len; if ( remaining < 0 ) break; offset += option_len; if ( option->tag != DHCP_PAD ) options->used_len = offset; } }
int dhcpopt_no_realloc | ( | struct dhcp_options * | options, |
size_t | len | ||
) |
Refuse to reallocate DHCP option block.
options | DHCP option block |
len | New length |
rc | Return status code |
Definition at line 184 of file dhcpopts.c.
References ENOSPC.
Referenced by dhcppkt_init(), and nvo_realloc_dhcpopt().
{ return ( ( len <= options->alloc_len ) ? 0 : -ENOSPC ); }