iPXE
dhcppkt.h
Go to the documentation of this file.
1 #ifndef _IPXE_DHCPPKT_H
2 #define _IPXE_DHCPPKT_H
3 
4 /** @file
5  *
6  * DHCP packets
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <ipxe/dhcp.h>
14 #include <ipxe/dhcpopts.h>
15 #include <ipxe/refcnt.h>
16 
17 /**
18  * A DHCP packet
19  *
20  */
21 struct dhcp_packet {
22  /** Reference counter */
23  struct refcnt refcnt;
24  /** The DHCP packet contents */
25  struct dhcphdr *dhcphdr;
26  /** DHCP options */
28  /** Settings interface */
30 };
31 
32 /**
33  * Increment reference count on DHCP packet
34  *
35  * @v dhcppkt DHCP packet
36  * @ret dhcppkt DHCP packet
37  */
38 static inline __attribute__ (( always_inline )) struct dhcp_packet *
39 dhcppkt_get ( struct dhcp_packet *dhcppkt ) {
40  ref_get ( &dhcppkt->refcnt );
41  return dhcppkt;
42 }
43 
44 /**
45  * Decrement reference count on DHCP packet
46  *
47  * @v dhcppkt DHCP packet
48  */
49 static inline __attribute__ (( always_inline )) void
50 dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
51  ref_put ( &dhcppkt->refcnt );
52 }
53 
54 /**
55  * Get used length of DHCP packet
56  *
57  * @v dhcppkt DHCP packet
58  * @ret len Used length
59  */
60 static inline size_t dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
61  return ( offsetof ( struct dhcphdr, options ) +
62  dhcppkt->options.used_len );
63 }
64 
65 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
66  const void *data, size_t len );
67 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
68  void *data, size_t len );
69 extern void dhcppkt_init ( struct dhcp_packet *dhcppkt,
70  struct dhcphdr *data, size_t len );
71 
72 #endif /* _IPXE_DHCPPKT_H */
FILE_SECBOOT(PERMITTED)
#define __attribute__(x)
Definition: compiler.h:10
A DHCP packet.
Definition: dhcppkt.h:21
Dynamic Host Configuration Protocol.
struct refcnt refcnt
Reference counter.
Definition: dhcppkt.h:23
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:25
int dhcppkt_store(struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
Store value of DHCP packet setting.
Definition: dhcppkt.c:165
A reference counter.
Definition: refcnt.h:27
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:27
void dhcppkt_init(struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
Initialise DHCP packet.
Definition: dhcppkt.c:301
static int options
Definition: 3c515.c:286
ring len
Length.
Definition: dwmac.h:231
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
A settings block.
Definition: settings.h:133
DHCP options.
A DHCP header.
Definition: dhcp.h:616
int dhcppkt_fetch(struct dhcp_packet *dhcppkt, unsigned int tag, void *data, size_t len)
Fetch value of DHCP packet setting.
Definition: dhcppkt.c:196
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:25
static void dhcppkt_put(struct dhcp_packet *dhcppkt)
Decrement reference count on DHCP packet.
Definition: dhcppkt.h:50
static size_t dhcppkt_len(struct dhcp_packet *dhcppkt)
Get used length of DHCP packet.
Definition: dhcppkt.h:60
Reference counting.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static struct dhcp_packet * dhcppkt_get(struct dhcp_packet *dhcppkt)
Increment reference count on DHCP packet.
Definition: dhcppkt.h:39
uint64_t tag
Identity tag.
Definition: edd.h:31
size_t used_len
Option block used length.
Definition: dhcpopts.h:20
A DHCP options block.
Definition: dhcpopts.h:16
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107