iPXE
dhcpopts.h File Reference

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)
 FILE_SECBOOT (PERMITTED)
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.

Detailed Description

DHCP options.

Definition in file dhcpopts.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ dhcpopt_applies()

int dhcpopt_applies ( unsigned int tag)
extern

Check applicability of DHCP option setting.

Parameters
tagSetting tag number
Return values
appliesSetting applies to this option block

Definition at line 365 of file dhcpopts.c.

365 {
366
367 return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION,
368 DHCP_MAX_OPTION ) ) );
369}
uint64_t tag
Identity tag.
Definition edd.h:1
#define DHCP_MAX_OPTION
Maximum normal DHCP option.
Definition dhcp.h:542
#define DHCP_ENCAP_OPT(encapsulator, encapsulated)
Construct a tag value for an encapsulated option.
Definition dhcp.h:41

References DHCP_ENCAP_OPT, DHCP_MAX_OPTION, and tag.

Referenced by dhcppkt_applies(), and nvo_applies().

◆ dhcpopt_store()

int dhcpopt_store ( struct dhcp_options * options,
unsigned int tag,
const void * data,
size_t len )
extern

Store value of DHCP option setting.

Parameters
optionsDHCP option block
tagSetting tag number
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 380 of file dhcpopts.c.

381 {
382 int offset;
383
385 if ( offset < 0 )
386 return offset;
387 return 0;
388}
static int options
Definition 3c515.c:286
uint16_t offset
Offset to command line.
Definition bzimage.h:3
static int set_dhcp_option(struct dhcp_options *options, unsigned int tag, const void *data, size_t len)
Set value of DHCP option.
Definition dhcpopts.c:287
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11

References data, len, offset, options, set_dhcp_option(), and tag.

Referenced by dhcppkt_store(), and nvo_store().

◆ dhcpopt_fetch()

int dhcpopt_fetch ( struct dhcp_options * options,
unsigned int tag,
void * data,
size_t len )
extern

Fetch value of DHCP option setting.

Parameters
optionsDHCP option block
tagSetting tag number
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 399 of file dhcpopts.c.

400 {
401 int offset;
402 struct dhcp_option *option;
403 size_t option_len;
404
406 if ( offset < 0 )
407 return offset;
408
410 option_len = option->len;
411 if ( len > option_len )
412 len = option_len;
413 memcpy ( data, option->data, len );
414
415 return option_len;
416}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
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).
Definition dhcpopts.c:123
static struct dhcp_option * dhcp_option(struct dhcp_options *options, unsigned int offset)
Get pointer to DHCP option.
Definition dhcpopts.c:69
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A DHCP option.
Definition dhcp.h:582
A long option, as used for getopt_long().
Definition getopt.h:25

References data, dhcp_option(), find_dhcp_option_with_encap(), len, memcpy(), NULL, offset, options, and tag.

Referenced by dhcppkt_fetch(), and nvo_fetch().

◆ dhcpopt_init()

void dhcpopt_init ( struct dhcp_options * options,
void * data,
size_t alloc_len,
int(* realloc )(struct dhcp_options *options, size_t len) )
extern

Initialise prepopulated block of DHCP options.

Parameters
optionsUninitialised DHCP option block
dataMemory for DHCP option data
alloc_lenLength of memory for DHCP option data
reallocDHCP 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 457 of file dhcpopts.c.

459 {
460
461 /* Fill in fields */
462 options->data = data;
463 options->alloc_len = alloc_len;
464 options->realloc = realloc;
465
466 /* Update length */
468
469 DBGC ( options, "DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
470 options, options->data, options->used_len, options->alloc_len );
471}
void dhcpopt_update_used_len(struct dhcp_options *options)
Recalculate length of DHCP options block.
Definition dhcpopts.c:426
#define DBGC(...)
Definition compiler.h:530
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition malloc.c:663

References data, DBGC, dhcpopt_update_used_len(), len, options, and realloc().

Referenced by dhcppkt_init(), and nvo_init().

◆ dhcpopt_update_used_len()

void dhcpopt_update_used_len ( struct dhcp_options * options)
extern

Recalculate length of DHCP options block.

Parameters
optionsUninitialised 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 426 of file dhcpopts.c.

426 {
427 struct dhcp_option *option;
428 int offset = 0;
429 ssize_t remaining = options->alloc_len;
430 unsigned int option_len;
431
432 /* Find last non-pad option */
433 options->used_len = 0;
434 while ( remaining ) {
436 option_len = dhcp_option_len ( option, remaining );
437 remaining -= option_len;
438 if ( remaining < 0 )
439 break;
440 offset += option_len;
441 if ( option->tag != DHCP_PAD )
442 options->used_len = offset;
443 }
444}
signed long ssize_t
Definition stdint.h:7
static unsigned int dhcp_option_len(struct dhcp_option *option, size_t remaining)
Calculate length of any DHCP option.
Definition dhcpopts.c:93
#define DHCP_PAD
Padding.
Definition dhcp.h:60

References dhcp_option(), dhcp_option_len(), DHCP_PAD, offset, and options.

Referenced by dhcpopt_init(), and nvo_load().

◆ dhcpopt_no_realloc()

int dhcpopt_no_realloc ( struct dhcp_options * options,
size_t len )
extern

Refuse to reallocate DHCP option block.

Parameters
optionsDHCP option block
lenNew length
Return values
rcReturn status code

Definition at line 189 of file dhcpopts.c.

189 {
190 return ( ( len <= options->alloc_len ) ? 0 : -ENOSPC );
191}
#define ENOSPC
No space left on device.
Definition errno.h:593

References ENOSPC, len, and options.

Referenced by dhcppkt_init(), and nvo_realloc_dhcpopt().