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.

dhcpv6.h 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #ifndef _IPXE_DHCPV6_H
  2. #define _IPXE_DHCPV6_H
  3. /** @file
  4. *
  5. * Dynamic Host Configuration Protocol for IPv6
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/in.h>
  11. #include <ipxe/uuid.h>
  12. /** DHCPv6 server port */
  13. #define DHCPV6_SERVER_PORT 547
  14. /** DHCPv6 client port */
  15. #define DHCPV6_CLIENT_PORT 546
  16. /**
  17. * A DHCPv6 option
  18. *
  19. */
  20. struct dhcpv6_option {
  21. /** Code */
  22. uint16_t code;
  23. /** Length of the data field */
  24. uint16_t len;
  25. /** Data */
  26. uint8_t data[0];
  27. } __attribute__ (( packed ));
  28. /** DHCP unique identifier based on UUID (DUID-UUID) */
  29. struct dhcpv6_duid_uuid {
  30. /** Type */
  31. uint16_t type;
  32. /** UUID */
  33. union uuid uuid;
  34. } __attribute__ (( packed ));
  35. /** DHCP unique identifier based on UUID (DUID-UUID) */
  36. #define DHCPV6_DUID_UUID 4
  37. /** DHCPv6 client or server identifier option */
  38. struct dhcpv6_duid_option {
  39. /** Option header */
  40. struct dhcpv6_option header;
  41. /** DHCP unique identifier (DUID) */
  42. uint8_t duid[0];
  43. } __attribute__ (( packed ));
  44. /** DHCPv6 client identifier option */
  45. #define DHCPV6_CLIENT_ID 1
  46. /** DHCPv6 server identifier option */
  47. #define DHCPV6_SERVER_ID 2
  48. /** DHCPv6 identity association for non-temporary address (IA_NA) option */
  49. struct dhcpv6_ia_na_option {
  50. /** Option header */
  51. struct dhcpv6_option header;
  52. /** Identity association identifier (IAID) */
  53. uint32_t iaid;
  54. /** Renew time (in seconds) */
  55. uint32_t renew;
  56. /** Rebind time (in seconds) */
  57. uint32_t rebind;
  58. /** IA_NA options */
  59. struct dhcpv6_option options[0];
  60. } __attribute__ (( packed ));
  61. /** DHCPv6 identity association for non-temporary address (IA_NA) option */
  62. #define DHCPV6_IA_NA 3
  63. /** DHCPv6 identity association address (IAADDR) option */
  64. struct dhcpv6_iaaddr_option {
  65. /** Option header */
  66. struct dhcpv6_option header;
  67. /** IPv6 address */
  68. struct in6_addr address;
  69. /** Preferred lifetime (in seconds) */
  70. uint32_t preferred;
  71. /** Valid lifetime (in seconds) */
  72. uint32_t valid;
  73. /** IAADDR options */
  74. struct dhcpv6_option options[0];
  75. } __attribute__ (( packed ));
  76. /** DHCPv6 identity association address (IAADDR) option */
  77. #define DHCPV6_IAADDR 5
  78. /** DHCPv6 option request option */
  79. struct dhcpv6_option_request_option {
  80. /** Option header */
  81. struct dhcpv6_option header;
  82. /** Requested options */
  83. uint16_t requested[0];
  84. } __attribute__ (( packed ));
  85. /** DHCPv6 option request option */
  86. #define DHCPV6_OPTION_REQUEST 6
  87. /** DHCPv6 elapsed time option */
  88. struct dhcpv6_elapsed_time_option {
  89. /** Option header */
  90. struct dhcpv6_option header;
  91. /** Elapsed time, in centiseconds */
  92. uint16_t elapsed;
  93. } __attribute__ (( packed ));
  94. /** DHCPv6 elapsed time option */
  95. #define DHCPV6_ELAPSED_TIME 8
  96. /** DHCPv6 status code option */
  97. struct dhcpv6_status_code_option {
  98. /** Option header */
  99. struct dhcpv6_option header;
  100. /** Status code */
  101. uint16_t status;
  102. /** Status message */
  103. char message[0];
  104. } __attribute__ (( packed ));
  105. /** DHCPv6 status code option */
  106. #define DHCPV6_STATUS_CODE 13
  107. /** DHCPv6 user class */
  108. struct dhcpv6_user_class {
  109. /** Length */
  110. uint16_t len;
  111. /** User class string */
  112. char string[0];
  113. } __attribute__ (( packed ));
  114. /** DHCPv6 user class option */
  115. struct dhcpv6_user_class_option {
  116. /** Option header */
  117. struct dhcpv6_option header;
  118. /** User class */
  119. struct dhcpv6_user_class user_class[0];
  120. } __attribute__ (( packed ));
  121. /** DHCPv6 user class option */
  122. #define DHCPV6_USER_CLASS 15
  123. /** DHCPv6 vendor class option */
  124. #define DHCPV6_VENDOR_CLASS 16
  125. /** DHCPv6 PXE vendor class
  126. *
  127. * The DHCPv6 vendor class includes a field for an IANA enterprise
  128. * number. The EDK2 codebase uses the value 343, with the comment:
  129. *
  130. * TODO: IANA TBD: temporarily using Intel's
  131. *
  132. * Since this "temporarily" has applied since at least 2010, we assume
  133. * that it has become a de facto standard.
  134. */
  135. #define DHCPV6_VENDOR_CLASS_PXE 343
  136. /** DHCPv6 DNS recursive name server option */
  137. #define DHCPV6_DNS_SERVERS 23
  138. /** DHCPv6 domain search list option */
  139. #define DHCPV6_DOMAIN_LIST 24
  140. /** DHCPv6 bootfile URI option */
  141. #define DHCPV6_BOOTFILE_URL 59
  142. /** DHCPv6 bootfile parameters option */
  143. #define DHCPV6_BOOTFILE_PARAM 60
  144. /** DHCPv6 client system architecture option */
  145. #define DHCPV6_CLIENT_ARCHITECTURE 61
  146. /** DHCPv6 client network interface identifier option */
  147. #define DHCPV6_CLIENT_NDI 62
  148. /** DHCPv6 syslog server option
  149. *
  150. * This option code has not yet been assigned by IANA. Please update
  151. * this definition once an option code has been assigned.
  152. */
  153. #define DHCPV6_LOG_SERVERS 0xffffffffUL
  154. /** Construct a DHCPv6 byte value */
  155. #define DHCPV6_BYTE_VALUE( value ) ( (value) & 0xff )
  156. /** Construct a DHCPv6 word value */
  157. #define DHCPV6_WORD_VALUE( value ) \
  158. DHCPV6_BYTE_VALUE ( (value) >> 8 ), DHCPV6_BYTE_VALUE ( (value) >> 0 )
  159. /** Construct a DHCPv6 dword value */
  160. #define DHCPV6_DWORD_VALUE( value ) \
  161. DHCPV6_WORD_VALUE ( (value) >> 16 ), DHCPV6_WORD_VALUE ( (value) >> 0 )
  162. /** Construct a DHCPv6 option code */
  163. #define DHCPV6_CODE( code ) DHCPV6_WORD_VALUE ( code )
  164. /** Construct a DHCPv6 option length */
  165. #define DHCPV6_LEN( len ) DHCPV6_WORD_VALUE ( len )
  166. /** Construct a DHCPv6 option from a list of bytes */
  167. #define DHCPV6_OPTION( ... ) \
  168. DHCPV6_LEN ( VA_ARG_COUNT ( __VA_ARGS__ ) ), __VA_ARGS__
  169. /** Construct a DHCPv6 option from a list of characters */
  170. #define DHCPV6_STRING( ... ) DHCPV6_OPTION ( __VA_ARGS__ )
  171. /** Construct a byte-valued DHCPv6 option */
  172. #define DHCPV6_BYTE( value ) DHCPV6_OPTION ( DHCPV6_BYTE_VALUE ( value ) )
  173. /** Construct a word-valued DHCPv6 option */
  174. #define DHCPV6_WORD( value ) DHCPV6_OPTION ( DHCPV6_WORD_VALUE ( value ) )
  175. /** Construct a dword-valued DHCPv6 option */
  176. #define DHCPV6_DWORD( value ) DHCPV6_OPTION ( DHCPV6_DWORD_VALUE ( value ) )
  177. /**
  178. * Any DHCPv6 option
  179. *
  180. */
  181. union dhcpv6_any_option {
  182. struct dhcpv6_option header;
  183. struct dhcpv6_duid_option duid;
  184. struct dhcpv6_ia_na_option ia_na;
  185. struct dhcpv6_iaaddr_option iaaddr;
  186. struct dhcpv6_option_request_option option_request;
  187. struct dhcpv6_elapsed_time_option elapsed_time;
  188. struct dhcpv6_status_code_option status_code;
  189. struct dhcpv6_user_class_option user_class;
  190. };
  191. /**
  192. * A DHCPv6 header
  193. *
  194. */
  195. struct dhcpv6_header {
  196. /** Message type */
  197. uint8_t type;
  198. /** Transaction ID */
  199. uint8_t xid[3];
  200. /** Options */
  201. struct dhcpv6_option options[0];
  202. } __attribute__ (( packed ));
  203. /** DHCPv6 solicitation */
  204. #define DHCPV6_SOLICIT 1
  205. /** DHCPv6 advertisement */
  206. #define DHCPV6_ADVERTISE 2
  207. /** DHCPv6 request */
  208. #define DHCPV6_REQUEST 3
  209. /** DHCPv6 reply */
  210. #define DHCPV6_REPLY 7
  211. /** DHCPv6 information request */
  212. #define DHCPV6_INFORMATION_REQUEST 11
  213. /** DHCPv6 settings block name */
  214. #define DHCPV6_SETTINGS_NAME "dhcpv6"
  215. /**
  216. * Construct all-DHCP-relay-agents-and-servers multicast address
  217. *
  218. * @v addr Zeroed address to construct
  219. */
  220. static inline void ipv6_all_dhcp_relay_and_servers ( struct in6_addr *addr ) {
  221. addr->s6_addr16[0] = htons ( 0xff02 );
  222. addr->s6_addr[13] = 1;
  223. addr->s6_addr[15] = 2;
  224. }
  225. extern int start_dhcpv6 ( struct interface *job, struct net_device *netdev,
  226. int stateful );
  227. #endif /* _IPXE_DHCPV6_H */