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)
 
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  )

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

359  {
360 
361  return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION,
362  DHCP_MAX_OPTION ) ) );
363 }
#define DHCP_MAX_OPTION
Maximum normal DHCP option.
Definition: dhcp.h:539
#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:30

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

375  {
376  int offset;
377 
379  if ( offset < 0 )
380  return offset;
381  return 0;
382 }
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:282
static int options
Definition: 3c515.c:286
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint64_t tag
Identity tag.
Definition: edd.h:30

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

394  {
395  int offset;
396  struct dhcp_option *option;
397  size_t option_len;
398 
400  if ( offset < 0 )
401  return offset;
402 
404  option_len = option->len;
405  if ( len > option_len )
406  len = option_len;
407  memcpy ( data, option->data, len );
408 
409  return option_len;
410 }
static struct dhcp_option * dhcp_option(struct dhcp_options *options, unsigned int offset)
Get pointer to DHCP option.
Definition: dhcpopts.c:68
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A long option, as used for getopt_long()
Definition: getopt.h:24
static int options
Definition: 3c515.c:286
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
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:119
A DHCP option.
Definition: dhcp.h:579
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

453  {
454 
455  /* Fill in fields */
456  options->data = data;
457  options->alloc_len = alloc_len;
458  options->realloc = realloc;
459 
460  /* Update length */
462 
463  DBGC ( options, "DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
464  options, options->data, options->used_len, options->alloc_len );
465 }
#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:420
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:521

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

420  {
421  struct dhcp_option *option;
422  int offset = 0;
423  ssize_t remaining = options->alloc_len;
424  unsigned int option_len;
425 
426  /* Find last non-pad option */
427  options->used_len = 0;
428  while ( remaining ) {
430  option_len = dhcp_option_len ( option );
431  remaining -= option_len;
432  if ( remaining < 0 )
433  break;
434  offset += option_len;
435  if ( option->tag != DHCP_PAD )
436  options->used_len = offset;
437  }
438 }
static struct dhcp_option * dhcp_option(struct dhcp_options *options, unsigned int offset)
Get pointer to DHCP option.
Definition: dhcpopts.c:68
#define DHCP_PAD
Padding.
Definition: dhcp.h:60
A long option, as used for getopt_long()
Definition: getopt.h:24
static int options
Definition: 3c515.c:286
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static unsigned int dhcp_option_len(struct dhcp_option *option)
Calculate length of any DHCP option.
Definition: dhcpopts.c:91
A DHCP option.
Definition: dhcp.h:579
signed long ssize_t
Definition: stdint.h:7

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

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

References ENOSPC.

Referenced by dhcppkt_init(), and nvo_realloc_dhcpopt().