You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dhcppkt.h 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef _IPXE_DHCPPKT_H
  2. #define _IPXE_DHCPPKT_H
  3. /** @file
  4. *
  5. * DHCP packets
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/dhcp.h>
  10. #include <ipxe/dhcpopts.h>
  11. #include <ipxe/refcnt.h>
  12. /**
  13. * A DHCP packet
  14. *
  15. */
  16. struct dhcp_packet {
  17. /** Reference counter */
  18. struct refcnt refcnt;
  19. /** The DHCP packet contents */
  20. struct dhcphdr *dhcphdr;
  21. /** DHCP options */
  22. struct dhcp_options options;
  23. /** Settings interface */
  24. struct settings settings;
  25. };
  26. /**
  27. * Increment reference count on DHCP packet
  28. *
  29. * @v dhcppkt DHCP packet
  30. * @ret dhcppkt DHCP packet
  31. */
  32. static inline __attribute__ (( always_inline )) struct dhcp_packet *
  33. dhcppkt_get ( struct dhcp_packet *dhcppkt ) {
  34. ref_get ( &dhcppkt->refcnt );
  35. return dhcppkt;
  36. }
  37. /**
  38. * Decrement reference count on DHCP packet
  39. *
  40. * @v dhcppkt DHCP packet
  41. */
  42. static inline __attribute__ (( always_inline )) void
  43. dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
  44. ref_put ( &dhcppkt->refcnt );
  45. }
  46. /**
  47. * Get used length of DHCP packet
  48. *
  49. * @v dhcppkt DHCP packet
  50. * @ret len Used length
  51. */
  52. static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
  53. return ( offsetof ( struct dhcphdr, options ) +
  54. dhcppkt->options.used_len );
  55. }
  56. extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
  57. const void *data, size_t len );
  58. extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
  59. void *data, size_t len );
  60. extern void dhcppkt_init ( struct dhcp_packet *dhcppkt,
  61. struct dhcphdr *data, size_t len );
  62. #endif /* _IPXE_DHCPPKT_H */