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 */ 26 struct dhcp_options options; 27 /** Settings interface */ 28 struct settings settings; 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 * dhcppkt_get(struct dhcp_packet * dhcppkt)38dhcppkt_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 dhcppkt_put(struct dhcp_packet * dhcppkt)49dhcppkt_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 */ dhcppkt_len(struct dhcp_packet * dhcppkt)59static 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 */ 72