iPXE
dhcppkt.h
Go to the documentation of this file.
00001 #ifndef _IPXE_DHCPPKT_H
00002 #define _IPXE_DHCPPKT_H
00003 
00004 /** @file
00005  *
00006  * DHCP packets
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/dhcp.h>
00013 #include <ipxe/dhcpopts.h>
00014 #include <ipxe/refcnt.h>
00015 
00016 /**
00017  * A DHCP packet
00018  *
00019  */
00020 struct dhcp_packet {
00021         /** Reference counter */
00022         struct refcnt refcnt;
00023         /** The DHCP packet contents */
00024         struct dhcphdr *dhcphdr;
00025         /** DHCP options */
00026         struct dhcp_options options;
00027         /** Settings interface */
00028         struct settings settings;
00029 };
00030 
00031 /**
00032  * Increment reference count on DHCP packet
00033  *
00034  * @v dhcppkt           DHCP packet
00035  * @ret dhcppkt         DHCP packet
00036  */
00037 static inline __attribute__ (( always_inline )) struct dhcp_packet *
00038 dhcppkt_get ( struct dhcp_packet *dhcppkt ) {
00039         ref_get ( &dhcppkt->refcnt );
00040         return dhcppkt;
00041 }
00042 
00043 /**
00044  * Decrement reference count on DHCP packet
00045  *
00046  * @v dhcppkt           DHCP packet
00047  */
00048 static inline __attribute__ (( always_inline )) void
00049 dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
00050         ref_put ( &dhcppkt->refcnt );
00051 }
00052 
00053 /**
00054  * Get used length of DHCP packet
00055  *
00056  * @v dhcppkt           DHCP packet
00057  * @ret len             Used length
00058  */
00059 static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
00060         return ( offsetof ( struct dhcphdr, options ) +
00061                  dhcppkt->options.used_len );
00062 }
00063 
00064 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
00065                            const void *data, size_t len );
00066 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
00067                            void *data, size_t len );
00068 extern void dhcppkt_init ( struct dhcp_packet *dhcppkt, 
00069                            struct dhcphdr *data, size_t len );
00070 
00071 #endif /* _IPXE_DHCPPKT_H */