iPXE
|
DHCP options. More...
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <ipxe/dhcp.h>
#include <ipxe/dhcpopts.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static char * | dhcp_tag_name (unsigned int tag) |
Obtain printable version of a DHCP option tag. More... | |
static struct dhcp_option * | dhcp_option (struct dhcp_options *options, unsigned int offset) |
Get pointer to DHCP option. More... | |
static int | dhcp_option_offset (struct dhcp_options *options, struct dhcp_option *option) |
Get offset of a DHCP option. More... | |
static unsigned int | dhcp_option_len (struct dhcp_option *option) |
Calculate length of any DHCP option. More... | |
static int | find_dhcp_option_with_encap (struct dhcp_options *options, unsigned int tag, int *encap_offset) |
Find DHCP option within DHCP options block, and its encapsulator (if any) More... | |
int | dhcpopt_no_realloc (struct dhcp_options *options, size_t len) |
Refuse to reallocate DHCP option block. More... | |
static int | resize_dhcp_option (struct dhcp_options *options, int offset, int encap_offset, size_t old_len, size_t new_len) |
Resize a DHCP option. More... | |
static int | set_dhcp_option (struct dhcp_options *options, unsigned int tag, const void *data, size_t len) |
Set value of DHCP option. More... | |
int | dhcpopt_applies (unsigned int tag) |
Check applicability of DHCP option setting. More... | |
int | dhcpopt_store (struct dhcp_options *options, unsigned int tag, const void *data, size_t len) |
Store value of DHCP option setting. More... | |
int | dhcpopt_fetch (struct dhcp_options *options, unsigned int tag, void *data, size_t len) |
Fetch value of DHCP option setting. More... | |
void | dhcpopt_update_used_len (struct dhcp_options *options) |
Recalculate length of DHCP options block. More... | |
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. More... | |
DHCP options.
Definition in file dhcpopts.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
inlinestatic |
Obtain printable version of a DHCP option tag.
tag | DHCP option tag |
name | String representation of the tag |
Definition at line 47 of file dhcpopts.c.
References DHCP_ENCAPSULATED, DHCP_ENCAPSULATOR, DHCP_IS_ENCAP_OPT, name, snprintf(), and tag.
Referenced by find_dhcp_option_with_encap(), and set_dhcp_option().
|
inlinestatic |
Get pointer to DHCP option.
options | DHCP options block |
offset | Offset within options block |
option | DHCP option |
Definition at line 68 of file dhcpopts.c.
References offset, and options.
Referenced by dhcpopt_fetch(), dhcpopt_update_used_len(), find_dhcp_option_with_encap(), resize_dhcp_option(), and set_dhcp_option().
|
inlinestatic |
Get offset of a DHCP option.
options | DHCP options block |
option | DHCP option |
offset | Offset within options block |
Definition at line 80 of file dhcpopts.c.
References options.
|
static |
Calculate length of any DHCP option.
option | DHCP option |
len | Length (including tag and length field) |
Definition at line 91 of file dhcpopts.c.
References DHCP_END, DHCP_OPTION_HEADER_LEN, and DHCP_PAD.
Referenced by dhcpopt_update_used_len(), find_dhcp_option_with_encap(), and set_dhcp_option().
|
static |
Find DHCP option within DHCP options block, and its encapsulator (if any)
options | DHCP options block |
tag | DHCP option tag to search for |
encap_offset | Offset of encapsulating DHCP option |
offset | Offset of DHCP option, or negative error |
Searches for the DHCP option matching the specified tag within the DHCP option block. Encapsulated options may be searched for by using DHCP_ENCAP_OPT() to construct the tag value.
If the option is encapsulated, and encap_offset
is non-NULL, it will be filled in with the offset of the encapsulating option.
This routine is designed to be paranoid. It does not assume that the option data is well-formatted, and so must guard against flaws such as options missing a DHCP_END
terminator, or options whose length would take them beyond the end of the data block.
Definition at line 119 of file dhcpopts.c.
References __attribute__, DBGC, DHCP_ENCAPSULATED, DHCP_ENCAPSULATOR, DHCP_END, DHCP_IS_ENCAP_OPT, dhcp_option(), DHCP_OPTION_HEADER_LEN, dhcp_option_len(), DHCP_PAD, dhcp_tag_name(), ENOENT, offset, options, tag, and unused.
Referenced by dhcpopt_fetch(), and set_dhcp_option().
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().
|
static |
Resize a DHCP option.
options | DHCP option block |
offset | Offset of option to resize |
encap_offset | Offset of encapsulating offset (or -ve for none) |
old_len | Old length (including header) |
new_len | New length (including header) |
rc | Return status code |
Definition at line 198 of file dhcpopts.c.
References DBGC, dest, DHCP_MAX_LEN, dhcp_option(), ENOSPC, dhcp_option::len, memmove(), memset(), offset, options, and rc.
Referenced by set_dhcp_option().
|
static |
Set value of DHCP option.
options | DHCP option block |
tag | DHCP option tag |
data | New value for DHCP option |
len | Length of value, in bytes |
offset | Offset of DHCP option, or negative error |
Sets the value of a DHCP option within the options block. The option may or may not already exist. Encapsulators will be created (and deleted) as necessary.
This call may fail due to insufficient space in the options block. If it does fail, and the option existed previously, the option will be left with its original value.
Definition at line 282 of file dhcpopts.c.
References data, DBGC, DHCP_ENCAPSULATOR, DHCP_END, dhcp_option(), DHCP_OPTION_HEADER_LEN, dhcp_option_len(), DHCP_PAD, dhcp_tag_name(), ENOTTY, find_dhcp_option_with_encap(), len, memcpy(), NULL, offset, options, rc, resize_dhcp_option(), and tag.
Referenced by dhcpopt_store().
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, DHCP_MAX_OPTION, and tag.
Referenced by dhcppkt_applies(), and nvo_applies().
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 data, len, offset, options, set_dhcp_option(), and tag.
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 data, dhcp_option(), find_dhcp_option_with_encap(), len, memcpy(), NULL, offset, options, and tag.
Referenced by dhcppkt_fetch(), and nvo_fetch().
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_option(), dhcp_option_len(), DHCP_PAD, offset, and options.
Referenced by dhcpopt_init(), and nvo_load().
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 data, DBGC, dhcpopt_update_used_len(), options, and realloc().
Referenced by dhcppkt_init(), and nvo_init().