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 
12 #include <ipxe/dhcp.h>
13 #include <ipxe/dhcpopts.h>
14 #include <ipxe/refcnt.h>
15 
16 /**
17  * A DHCP packet
18  *
19  */
20 struct dhcp_packet {
21  /** Reference counter */
22  struct refcnt refcnt;
23  /** The DHCP packet contents */
24  struct dhcphdr *dhcphdr;
25  /** DHCP options */
27  /** Settings interface */
29 };
30 
31 /**
32  * Increment reference count on DHCP packet
33  *
34  * @v dhcppkt DHCP packet
35  * @ret dhcppkt DHCP packet
36  */
37 static inline __attribute__ (( always_inline )) struct dhcp_packet *
38 dhcppkt_get ( struct dhcp_packet *dhcppkt ) {
39  ref_get ( &dhcppkt->refcnt );
40  return dhcppkt;
41 }
42 
43 /**
44  * Decrement reference count on DHCP packet
45  *
46  * @v dhcppkt DHCP packet
47  */
48 static inline __attribute__ (( always_inline )) void
49 dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
50  ref_put ( &dhcppkt->refcnt );
51 }
52 
53 /**
54  * Get used length of DHCP packet
55  *
56  * @v dhcppkt DHCP packet
57  * @ret len Used length
58  */
59 static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
60  return ( offsetof ( struct dhcphdr, options ) +
61  dhcppkt->options.used_len );
62 }
63 
64 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
65  const void *data, size_t len );
66 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
67  void *data, size_t len );
68 extern void dhcppkt_init ( struct dhcp_packet *dhcppkt,
69  struct dhcphdr *data, size_t len );
70 
71 #endif /* _IPXE_DHCPPKT_H */
#define __attribute__(x)
Definition: compiler.h:10
A DHCP packet.
Definition: dhcppkt.h:20
Dynamic Host Configuration Protocol.
struct refcnt refcnt
Reference counter.
Definition: dhcppkt.h:22
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
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:164
A reference counter.
Definition: refcnt.h:26
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct dhcp_options options
DHCP options.
Definition: dhcppkt.h:26
void dhcppkt_init(struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
Initialise DHCP packet.
Definition: dhcppkt.c:300
static int options
Definition: 3c515.c:286
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
A settings block.
Definition: settings.h:132
DHCP options.
A DHCP header.
Definition: dhcp.h:591
int dhcppkt_fetch(struct dhcp_packet *dhcppkt, unsigned int tag, void *data, size_t len)
Fetch value of DHCP packet setting.
Definition: dhcppkt.c:195
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
uint32_t len
Length.
Definition: ena.h:14
static void dhcppkt_put(struct dhcp_packet *dhcppkt)
Decrement reference count on DHCP packet.
Definition: dhcppkt.h:49
Reference counting.
static struct dhcp_packet * dhcppkt_get(struct dhcp_packet *dhcppkt)
Increment reference count on DHCP packet.
Definition: dhcppkt.h:38
static int dhcppkt_len(struct dhcp_packet *dhcppkt)
Get used length of DHCP packet.
Definition: dhcppkt.h:59
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t tag
Identity tag.
Definition: edd.h:30
size_t used_len
Option block used length.
Definition: dhcpopts.h:19
A DHCP options block.
Definition: dhcpopts.h:15
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106