iPXE
Data Structures | Functions
dhcppkt.h File Reference

DHCP packets. More...

#include <ipxe/dhcp.h>
#include <ipxe/dhcpopts.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Data Structures

struct  dhcp_packet
 A DHCP packet. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct dhcp_packetdhcppkt_get (struct dhcp_packet *dhcppkt)
 Increment reference count on DHCP packet. More...
 
static void dhcppkt_put (struct dhcp_packet *dhcppkt)
 Decrement reference count on DHCP packet. More...
 
static size_t dhcppkt_len (struct dhcp_packet *dhcppkt)
 Get used length of DHCP packet. More...
 
int dhcppkt_store (struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
 Store value of DHCP packet setting. More...
 
int dhcppkt_fetch (struct dhcp_packet *dhcppkt, unsigned int tag, void *data, size_t len)
 Fetch value of DHCP packet setting. More...
 
void dhcppkt_init (struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
 Initialise DHCP packet. More...
 

Detailed Description

DHCP packets.

Definition in file dhcppkt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dhcppkt_get()

static struct dhcp_packet* dhcppkt_get ( struct dhcp_packet dhcppkt)
inlinestatic

Increment reference count on DHCP packet.

Parameters
dhcppktDHCP packet
Return values
dhcppktDHCP packet

Definition at line 38 of file dhcppkt.h.

38  {
39  ref_get ( &dhcppkt->refcnt );
40  return dhcppkt;
41 }
struct refcnt refcnt
Reference counter.
Definition: dhcppkt.h:22
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and dhcp_packet::refcnt.

Referenced by dhcp_discovery_rx().

◆ dhcppkt_put()

static void dhcppkt_put ( struct dhcp_packet dhcppkt)
inlinestatic

Decrement reference count on DHCP packet.

Parameters
dhcppktDHCP packet

Definition at line 49 of file dhcppkt.h.

49  {
50  ref_put ( &dhcppkt->refcnt );
51 }
struct refcnt refcnt
Reference counter.
Definition: dhcppkt.h:22
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References ref_put, and dhcp_packet::refcnt.

Referenced by cachedhcp_free(), cachedhcp_record(), dhcp_deliver(), dhcp_discovery_rx(), and dhcp_free().

◆ dhcppkt_len()

static size_t dhcppkt_len ( struct dhcp_packet dhcppkt)
inlinestatic

Get used length of DHCP packet.

Parameters
dhcppktDHCP packet
Return values
lenUsed length

Definition at line 59 of file dhcppkt.h.

59  {
60  return ( offsetof ( struct dhcphdr, options ) +
61  dhcppkt->options.used_len );
62 }
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:26
static int options
Definition: 3c515.c:286
A DHCP header.
Definition: dhcp.h:613
size_t used_len
Option block used length.
Definition: dhcpopts.h:19

References offsetof, dhcp_packet::options, options, and dhcp_options::used_len.

Referenced by cachedhcp_record(), dhcp_tx(), and efi_pxe_fake().

◆ dhcppkt_store()

int dhcppkt_store ( struct dhcp_packet dhcppkt,
unsigned int  tag,
const void *  data,
size_t  len 
)

Store value of DHCP packet setting.

Parameters
dhcppktDHCP packet
tagSetting tag number
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 164 of file dhcppkt.c.

165  {
166  struct dhcp_packet_field *field;
167  void *field_data;
168 
169  /* If this is a special field, fill it in */
170  if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
171  if ( len > field->len )
172  return -ENOSPC;
173  field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
174  memset ( field_data, 0, field->len );
175  memcpy ( dhcp_packet_field ( dhcppkt->dhcphdr, field ),
176  data, len );
177  /* Erase any equivalent option from the options block */
178  dhcpopt_store ( &dhcppkt->options, tag, NULL, 0 );
179  return 0;
180  }
181 
182  /* Otherwise, use the generic options block */
183  return dhcpopt_store ( &dhcppkt->options, tag, data, len );
184 }
static struct dhcp_packet_field * find_dhcp_packet_field(unsigned int tag)
Find DHCP packet field corresponding to settings tag number.
Definition: dhcppkt.c:129
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:26
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void * dhcp_packet_field(struct dhcphdr *dhcphdr, struct dhcp_packet_field *field)
Get address of a DHCP packet field.
Definition: dhcppkt.c:117
#define ENOSPC
No space left on device.
Definition: errno.h:549
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int dhcpopt_store(struct dhcp_options *options, unsigned int tag, const void *data, size_t len)
Store value of DHCP option setting.
Definition: dhcpopts.c:374
A dedicated field within a DHCP packet.
Definition: dhcppkt.c:73
uint64_t tag
Identity tag.
Definition: edd.h:30
uint16_t len
Length of field.
Definition: dhcppkt.c:79
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

References data, dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_store(), ENOSPC, find_dhcp_packet_field(), len, dhcp_packet_field::len, memcpy(), memset(), NULL, dhcp_packet::options, and tag.

Referenced by copy_encap_settings(), dhcp_create_packet(), dhcp_create_request(), dhcp_proxy_tx(), dhcp_pxebs_tx(), dhcp_request_tx(), and dhcppkt_settings_store().

◆ dhcppkt_fetch()

int dhcppkt_fetch ( struct dhcp_packet dhcppkt,
unsigned int  tag,
void *  data,
size_t  len 
)

Fetch value of DHCP packet setting.

Parameters
dhcppktDHCP packet
tagSetting tag number
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 195 of file dhcppkt.c.

196  {
197  struct dhcp_packet_field *field;
198  void *field_data;
199  size_t field_len = 0;
200 
201  /* Identify special field, if any */
202  if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
203  field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
204  field_len = field->used_len ( field_data, field->len );
205  }
206 
207  /* Return special field, if it exists and is populated */
208  if ( field_len ) {
209  if ( len > field_len )
210  len = field_len;
211  memcpy ( data, field_data, len );
212  return field_len;
213  }
214 
215  /* Otherwise, use the generic options block */
216  return dhcpopt_fetch ( &dhcppkt->options, tag, data, len );
217 }
static struct dhcp_packet_field * find_dhcp_packet_field(unsigned int tag)
Find DHCP packet field corresponding to settings tag number.
Definition: dhcppkt.c:129
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:26
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void * dhcp_packet_field(struct dhcphdr *dhcphdr, struct dhcp_packet_field *field)
Get address of a DHCP packet field.
Definition: dhcppkt.c:117
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
size_t(* used_len)(const void *data, size_t len)
Calculate used length of field.
Definition: dhcppkt.c:86
int dhcpopt_fetch(struct dhcp_options *options, unsigned int tag, void *data, size_t len)
Fetch value of DHCP option setting.
Definition: dhcpopts.c:393
A dedicated field within a DHCP packet.
Definition: dhcppkt.c:73
uint64_t tag
Identity tag.
Definition: edd.h:30
uint16_t len
Length of field.
Definition: dhcppkt.c:79
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References data, dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_fetch(), find_dhcp_packet_field(), len, dhcp_packet_field::len, memcpy(), NULL, dhcp_packet::options, tag, and dhcp_packet_field::used_len.

Referenced by dhcp_deliver(), dhcp_discovery_rx(), dhcp_has_pxeopts(), dhcp_pxebs_rx(), and dhcppkt_settings_fetch().

◆ dhcppkt_init()

void dhcppkt_init ( struct dhcp_packet dhcppkt,
struct dhcphdr data,
size_t  len 
)

Initialise DHCP packet.

Parameters
dhcppktDHCP packet structure to fill in
dataDHCP packet raw data
max_lenLength of raw data buffer

Initialise a DHCP packet structure from a data buffer containing a DHCP packet.

Definition at line 300 of file dhcppkt.c.

301  {
302  ref_init ( &dhcppkt->refcnt, NULL );
303  dhcppkt->dhcphdr = data;
304  dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
305  ( len - offsetof ( struct dhcphdr, options ) ),
308  &dhcppkt->refcnt, NULL );
309 }
struct refcnt refcnt
Reference counter.
Definition: dhcppkt.h:22
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.
Definition: dhcpopts.c:451
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
uint8_t options[0]
DHCP options.
Definition: dhcp.h:681
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
static void settings_init(struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
Initialise a settings block.
Definition: settings.h:500
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:26
static int options
Definition: 3c515.c:286
struct settings settings
Settings interface.
Definition: dhcppkt.h:28
int dhcpopt_no_realloc(struct dhcp_options *options, size_t len)
Refuse to reallocate DHCP option block.
Definition: dhcpopts.c:184
A DHCP header.
Definition: dhcp.h:613
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
static struct settings_operations dhcppkt_settings_operations
DHCP settings operations.
Definition: dhcppkt.c:278
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References data, dhcp_packet::dhcphdr, dhcpopt_init(), dhcpopt_no_realloc(), dhcppkt_settings_operations, len, NULL, offsetof, dhcp_packet::options, options, dhcphdr::options, ref_init, dhcp_packet::refcnt, dhcp_packet::settings, and settings_init().

Referenced by cachedhcp_record(), dhcp_create_packet(), dhcp_deliver(), and efi_pxe_fake().