iPXE
Data Structures | Functions
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. 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_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...
 
void dhcpopt_update_used_len (struct dhcp_options *options)
 Recalculate length of DHCP options block. More...
 
int dhcpopt_no_realloc (struct dhcp_options *options, size_t len)
 Refuse to reallocate DHCP option block. More...
 

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)

Check applicability of DHCP option setting.

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

Definition at line 360 of file dhcpopts.c.

360  {
361 
362  return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION,
363  DHCP_MAX_OPTION ) ) );
364 }
#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
uint64_t tag
Identity tag.
Definition: edd.h:31

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 
)

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 375 of file dhcpopts.c.

376  {
377  int offset;
378 
380  if ( offset < 0 )
381  return offset;
382  return 0;
383 }
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:283
static int options
Definition: 3c515.c:286
ring len
Length.
Definition: dwmac.h:231
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint64_t tag
Identity tag.
Definition: edd.h:31

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 
)

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 394 of file dhcpopts.c.

395  {
396  int offset;
397  struct dhcp_option *option;
398  size_t option_len;
399 
401  if ( offset < 0 )
402  return offset;
403 
405  option_len = option->len;
406  if ( len > option_len )
407  len = option_len;
408  memcpy ( data, option->data, len );
409 
410  return option_len;
411 }
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 long option, as used for getopt_long()
Definition: getopt.h:25
static int options
Definition: 3c515.c:286
ring len
Length.
Definition: dwmac.h:231
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:120
A DHCP option.
Definition: dhcp.h:582
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint64_t tag
Identity tag.
Definition: edd.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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(*)(struct dhcp_options *options, size_t len realloc 
)

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 452 of file dhcpopts.c.

454  {
455 
456  /* Fill in fields */
457  options->data = data;
458  options->alloc_len = alloc_len;
459  options->realloc = realloc;
460 
461  /* Update length */
463 
464  DBGC ( options, "DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
465  options, options->data, options->used_len, options->alloc_len );
466 }
#define DBGC(...)
Definition: compiler.h:505
static int options
Definition: 3c515.c:286
void dhcpopt_update_used_len(struct dhcp_options *options)
Recalculate length of DHCP options block.
Definition: dhcpopts.c:421
uint8_t data[48]
Additional event data.
Definition: ena.h:22
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition: malloc.c:607

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

Referenced by dhcppkt_init(), and nvo_init().

◆ dhcpopt_update_used_len()

void dhcpopt_update_used_len ( struct dhcp_options options)

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 421 of file dhcpopts.c.

421  {
422  struct dhcp_option *option;
423  int offset = 0;
424  ssize_t remaining = options->alloc_len;
425  unsigned int option_len;
426 
427  /* Find last non-pad option */
428  options->used_len = 0;
429  while ( remaining ) {
431  option_len = dhcp_option_len ( option );
432  remaining -= option_len;
433  if ( remaining < 0 )
434  break;
435  offset += option_len;
436  if ( option->tag != DHCP_PAD )
437  options->used_len = offset;
438  }
439 }
static struct dhcp_option * dhcp_option(struct dhcp_options *options, unsigned int offset)
Get pointer to DHCP option.
Definition: dhcpopts.c:69
#define DHCP_PAD
Padding.
Definition: dhcp.h:60
A long option, as used for getopt_long()
Definition: getopt.h:25
static int options
Definition: 3c515.c:286
static unsigned int dhcp_option_len(struct dhcp_option *option)
Calculate length of any DHCP option.
Definition: dhcpopts.c:92
A DHCP option.
Definition: dhcp.h:582
signed long ssize_t
Definition: stdint.h:7
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

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 
)

Refuse to reallocate DHCP option block.

Parameters
optionsDHCP option block
lenNew length
Return values
rcReturn status code

Definition at line 185 of file dhcpopts.c.

185  {
186  return ( ( len <= options->alloc_len ) ? 0 : -ENOSPC );
187 }
#define ENOSPC
No space left on device.
Definition: errno.h:550

References ENOSPC.

Referenced by dhcppkt_init(), and nvo_realloc_dhcpopt().