iPXE
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)
 FILE_SECBOOT (PERMITTED)
static struct dhcp_packetdhcppkt_get (struct dhcp_packet *dhcppkt)
 Increment reference count on DHCP packet.
static void dhcppkt_put (struct dhcp_packet *dhcppkt)
 Decrement reference count on DHCP packet.
static size_t dhcppkt_len (struct dhcp_packet *dhcppkt)
 Get used length of DHCP packet.
int dhcppkt_store (struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
 Store value of DHCP packet setting.
int dhcppkt_fetch (struct dhcp_packet *dhcppkt, unsigned int tag, void *data, size_t len)
 Fetch value of DHCP packet setting.
void dhcppkt_init (struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
 Initialise DHCP packet.

Detailed Description

DHCP packets.

Definition in file dhcppkt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ dhcppkt_get()

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 39 of file dhcppkt.h.

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

References ref_get, and dhcp_packet::refcnt.

Referenced by dhcp_discovery_rx().

◆ dhcppkt_put()

void dhcppkt_put ( struct dhcp_packet * dhcppkt)
inlinestatic

Decrement reference count on DHCP packet.

Parameters
dhcppktDHCP packet

Definition at line 50 of file dhcppkt.h.

50 {
51 ref_put ( &dhcppkt->refcnt );
52}
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107

References ref_put, and dhcp_packet::refcnt.

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

◆ dhcppkt_len()

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 60 of file dhcppkt.h.

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

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

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 165 of file dhcppkt.c.

166 {
167 struct dhcp_packet_field *field;
168 void *field_data;
169
170 /* If this is a special field, fill it in */
171 if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
172 if ( len > field->len )
173 return -ENOSPC;
174 field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
175 memset ( field_data, 0, field->len );
176 memcpy ( dhcp_packet_field ( dhcppkt->dhcphdr, field ),
177 data, len );
178 /* Erase any equivalent option from the options block */
179 dhcpopt_store ( &dhcppkt->options, tag, NULL, 0 );
180 return 0;
181 }
182
183 /* Otherwise, use the generic options block */
184 return dhcpopt_store ( &dhcppkt->options, tag, data, len );
185}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
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:375
static struct dhcp_packet_field * find_dhcp_packet_field(unsigned int tag)
Find DHCP packet field corresponding to settings tag number.
Definition dhcppkt.c:130
static void * dhcp_packet_field(struct dhcphdr *dhcphdr, struct dhcp_packet_field *field)
Get address of a DHCP packet field.
Definition dhcppkt.c:118
ring len
Length.
Definition dwmac.h:226
uint64_t tag
Identity tag.
Definition edd.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define ENOSPC
No space left on device.
Definition errno.h:550
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
A dedicated field within a DHCP packet.
Definition dhcppkt.c:74
uint16_t len
Length of field.
Definition dhcppkt.c:80
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition dhcppkt.h:25

References data, dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_store(), ENOSPC, find_dhcp_packet_field(), dhcp_packet_field::len, 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 )
extern

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 196 of file dhcppkt.c.

197 {
198 struct dhcp_packet_field *field;
199 void *field_data;
200 size_t field_len = 0;
201
202 /* Identify special field, if any */
203 if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
204 field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
205 field_len = field->used_len ( field_data, field->len );
206 }
207
208 /* Return special field, if it exists and is populated */
209 if ( field_len ) {
210 if ( len > field_len )
211 len = field_len;
212 memcpy ( data, field_data, len );
213 return field_len;
214 }
215
216 /* Otherwise, use the generic options block */
217 return dhcpopt_fetch ( &dhcppkt->options, tag, data, len );
218}
int dhcpopt_fetch(struct dhcp_options *options, unsigned int tag, void *data, size_t len)
Fetch value of DHCP option setting.
Definition dhcpopts.c:394
size_t(* used_len)(const void *data, size_t len)
Calculate used length of field.
Definition dhcppkt.c:87

References data, dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_fetch(), find_dhcp_packet_field(), dhcp_packet_field::len, 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 )
extern

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 301 of file dhcppkt.c.

302 {
303 ref_init ( &dhcppkt->refcnt, NULL );
304 dhcppkt->dhcphdr = data;
305 dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
306 ( len - offsetof ( struct dhcphdr, options ) ),
309 &dhcppkt->refcnt, NULL );
310}
int dhcpopt_no_realloc(struct dhcp_options *options, size_t len)
Refuse to reallocate DHCP option block.
Definition dhcpopts.c:185
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:452
static struct settings_operations dhcppkt_settings_operations
DHCP settings operations.
Definition dhcppkt.c:279
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:503
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
struct settings settings
Settings interface.
Definition dhcppkt.h:29
uint8_t options[0]
DHCP options.
Definition dhcp.h:684

References data, dhcp_packet::dhcphdr, dhcpopt_init(), dhcpopt_no_realloc(), dhcppkt_settings_operations, len, NULL, offsetof, dhcp_packet::options, dhcphdr::options, 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().