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.

dhcp.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. #ifndef _IPXE_DHCP_H
  2. #define _IPXE_DHCP_H
  3. /** @file
  4. *
  5. * Dynamic Host Configuration Protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <stdarg.h>
  11. #include <ipxe/in.h>
  12. #include <ipxe/list.h>
  13. #include <ipxe/refcnt.h>
  14. #include <ipxe/tables.h>
  15. #include <ipxe/uuid.h>
  16. #include <ipxe/netdevice.h>
  17. #include <ipxe/uaccess.h>
  18. struct interface;
  19. struct dhcp_options;
  20. struct dhcp_packet;
  21. /** BOOTP/DHCP server port */
  22. #define BOOTPS_PORT 67
  23. /** BOOTP/DHCP client port */
  24. #define BOOTPC_PORT 68
  25. /** PXE server port */
  26. #define PXE_PORT 4011
  27. /** Construct a tag value for an encapsulated option
  28. *
  29. * This tag value can be passed to Etherboot functions when searching
  30. * for DHCP options in order to search for a tag within an
  31. * encapsulated options block.
  32. */
  33. #define DHCP_ENCAP_OPT( encapsulator, encapsulated ) \
  34. ( ( (encapsulator) << 8 ) | (encapsulated) )
  35. /** Extract encapsulating option block tag from encapsulated tag value */
  36. #define DHCP_ENCAPSULATOR( encap_opt ) ( (encap_opt) >> 8 )
  37. /** Extract encapsulated option tag from encapsulated tag value */
  38. #define DHCP_ENCAPSULATED( encap_opt ) ( (encap_opt) & 0xff )
  39. /** Option is encapsulated */
  40. #define DHCP_IS_ENCAP_OPT( opt ) DHCP_ENCAPSULATOR( opt )
  41. /**
  42. * @defgroup dhcpopts DHCP option tags
  43. * @{
  44. */
  45. /** Padding
  46. *
  47. * This tag does not have a length field; it is always only a single
  48. * byte in length.
  49. */
  50. #define DHCP_PAD 0
  51. /** Minimum normal DHCP option */
  52. #define DHCP_MIN_OPTION 1
  53. /** Subnet mask */
  54. #define DHCP_SUBNET_MASK 1
  55. /** Routers */
  56. #define DHCP_ROUTERS 3
  57. /** DNS servers */
  58. #define DHCP_DNS_SERVERS 6
  59. /** Syslog servers */
  60. #define DHCP_LOG_SERVERS 7
  61. /** Host name */
  62. #define DHCP_HOST_NAME 12
  63. /** Domain name */
  64. #define DHCP_DOMAIN_NAME 15
  65. /** Root path */
  66. #define DHCP_ROOT_PATH 17
  67. /** Maximum transmission unit */
  68. #define DHCP_MTU 26
  69. /** Vendor encapsulated options */
  70. #define DHCP_VENDOR_ENCAP 43
  71. /** PXE boot server discovery control */
  72. #define DHCP_PXE_DISCOVERY_CONTROL DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 6 )
  73. /** PXE boot server discovery control bits */
  74. enum dhcp_pxe_discovery_control {
  75. /** Inhibit broadcast discovery */
  76. PXEBS_NO_BROADCAST = 1,
  77. /** Inhibit multicast discovery */
  78. PXEBS_NO_MULTICAST = 2,
  79. /** Accept only servers in DHCP_PXE_BOOT_SERVERS list */
  80. PXEBS_NO_UNKNOWN_SERVERS = 4,
  81. /** Skip discovery if filename present */
  82. PXEBS_SKIP = 8,
  83. };
  84. /** PXE boot server multicast address */
  85. #define DHCP_PXE_BOOT_SERVER_MCAST DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 7 )
  86. /** PXE boot servers */
  87. #define DHCP_PXE_BOOT_SERVERS DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 8 )
  88. /** PXE boot server */
  89. struct dhcp_pxe_boot_server {
  90. /** "Type" */
  91. uint16_t type;
  92. /** Number of IPv4 addresses */
  93. uint8_t num_ip;
  94. /** IPv4 addresses */
  95. struct in_addr ip[0];
  96. } __attribute__ (( packed ));
  97. /** PXE boot menu */
  98. #define DHCP_PXE_BOOT_MENU DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 9 )
  99. /** PXE boot menu */
  100. struct dhcp_pxe_boot_menu {
  101. /** "Type" */
  102. uint16_t type;
  103. /** Description length */
  104. uint8_t desc_len;
  105. /** Description */
  106. char desc[0];
  107. } __attribute__ (( packed ));
  108. /** PXE boot menu prompt */
  109. #define DHCP_PXE_BOOT_MENU_PROMPT DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 10 )
  110. /** PXE boot menu prompt */
  111. struct dhcp_pxe_boot_menu_prompt {
  112. /** Timeout
  113. *
  114. * A value of 0 means "time out immediately and select first
  115. * boot item, without displaying the prompt". A value of 255
  116. * means "display menu immediately with no timeout". Any
  117. * other value means "display prompt, wait this many seconds
  118. * for keypress, if key is F8, display menu, otherwise select
  119. * first boot item".
  120. */
  121. uint8_t timeout;
  122. /** Prompt to press F8 */
  123. char prompt[0];
  124. } __attribute__ (( packed ));
  125. /** PXE boot menu item */
  126. #define DHCP_PXE_BOOT_MENU_ITEM DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 71 )
  127. /** PXE boot menu item */
  128. struct dhcp_pxe_boot_menu_item {
  129. /** "Type"
  130. *
  131. * This field actually identifies the specific boot server (or
  132. * cluster of boot servers offering identical boot files).
  133. */
  134. uint16_t type;
  135. /** "Layer"
  136. *
  137. * Just don't ask.
  138. */
  139. uint16_t layer;
  140. } __attribute__ (( packed ));
  141. /** Requested IP address */
  142. #define DHCP_REQUESTED_ADDRESS 50
  143. /** Lease time */
  144. #define DHCP_LEASE_TIME 51
  145. /** Option overloading
  146. *
  147. * The value of this option is the bitwise-OR of zero or more
  148. * DHCP_OPTION_OVERLOAD_XXX constants.
  149. */
  150. #define DHCP_OPTION_OVERLOAD 52
  151. /** The "file" field is overloaded to contain extra DHCP options */
  152. #define DHCP_OPTION_OVERLOAD_FILE 1
  153. /** The "sname" field is overloaded to contain extra DHCP options */
  154. #define DHCP_OPTION_OVERLOAD_SNAME 2
  155. /** DHCP message type */
  156. #define DHCP_MESSAGE_TYPE 53
  157. #define DHCPNONE 0
  158. #define DHCPDISCOVER 1
  159. #define DHCPOFFER 2
  160. #define DHCPREQUEST 3
  161. #define DHCPDECLINE 4
  162. #define DHCPACK 5
  163. #define DHCPNAK 6
  164. #define DHCPRELEASE 7
  165. #define DHCPINFORM 8
  166. /** DHCP server identifier */
  167. #define DHCP_SERVER_IDENTIFIER 54
  168. /** Parameter request list */
  169. #define DHCP_PARAMETER_REQUEST_LIST 55
  170. /** Maximum DHCP message size */
  171. #define DHCP_MAX_MESSAGE_SIZE 57
  172. /** Vendor class identifier */
  173. #define DHCP_VENDOR_CLASS_ID 60
  174. /** Vendor class identifier for PXE clients */
  175. #define DHCP_VENDOR_PXECLIENT( arch, ndi ) \
  176. 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':', \
  177. 'A', 'r', 'c', 'h', ':', DHCP_VENDOR_PXECLIENT_ARCH ( arch ), \
  178. ':', 'U', 'N', 'D', 'I', ':', DHCP_VENDOR_PXECLIENT_UNDI ( ndi )
  179. /** Vendor class identifier architecture for PXE clients */
  180. #define DHCP_VENDOR_PXECLIENT_ARCH( arch ) \
  181. ( '0' + ( ( (arch) / 10000 ) % 10 ) ), \
  182. ( '0' + ( ( (arch) / 1000 ) % 10 ) ), \
  183. ( '0' + ( ( (arch) / 100 ) % 10 ) ), \
  184. ( '0' + ( ( (arch) / 10 ) % 10 ) ), \
  185. ( '0' + ( ( (arch) / 1 ) % 10 ) )
  186. /** Vendor class identifier UNDI version for PXE clients */
  187. #define DHCP_VENDOR_PXECLIENT_UNDI( type, major, minor ) \
  188. DHCP_VENDOR_PXECLIENT_UNDI_VERSION ( major ), \
  189. DHCP_VENDOR_PXECLIENT_UNDI_VERSION ( minor )
  190. #define DHCP_VENDOR_PXECLIENT_UNDI_VERSION( version ) \
  191. ( '0' + ( ( (version) / 100 ) % 10 ) ), \
  192. ( '0' + ( ( (version) / 10 ) % 10 ) ), \
  193. ( '0' + ( ( (version) / 1 ) % 10 ) )
  194. /** Client identifier */
  195. #define DHCP_CLIENT_ID 61
  196. /** Client identifier */
  197. struct dhcp_client_id {
  198. /** Link-layer protocol */
  199. uint8_t ll_proto;
  200. /** Link-layer address */
  201. uint8_t ll_addr[MAX_LL_ADDR_LEN];
  202. } __attribute__ (( packed ));
  203. /** TFTP server name
  204. *
  205. * This option replaces the fixed "sname" field, when that field is
  206. * used to contain overloaded options.
  207. */
  208. #define DHCP_TFTP_SERVER_NAME 66
  209. /** Bootfile name
  210. *
  211. * This option replaces the fixed "file" field, when that field is
  212. * used to contain overloaded options.
  213. */
  214. #define DHCP_BOOTFILE_NAME 67
  215. /** User class identifier */
  216. #define DHCP_USER_CLASS_ID 77
  217. /** Client system architecture */
  218. #define DHCP_CLIENT_ARCHITECTURE 93
  219. /** DHCP client architecture */
  220. struct dhcp_client_architecture {
  221. uint16_t arch;
  222. } __attribute__ (( packed ));
  223. /** DHCP client architecture values
  224. *
  225. * These are defined by the PXE specification and redefined by
  226. * RFC4578.
  227. */
  228. enum dhcp_client_architecture_values {
  229. /** Intel x86 PC */
  230. DHCP_CLIENT_ARCHITECTURE_X86 = 0x0000,
  231. /** NEC/PC98 */
  232. DHCP_CLIENT_ARCHITECTURE_PC98 = 0x0001,
  233. /** EFI Itanium */
  234. DHCP_CLIENT_ARCHITECTURE_IA64 = 0x0002,
  235. /** DEC Alpha */
  236. DHCP_CLIENT_ARCHITECTURE_ALPHA = 0x0003,
  237. /** Arc x86 */
  238. DHCP_CLIENT_ARCHITECTURE_ARCX86 = 0x0004,
  239. /** Intel Lean Client */
  240. DHCP_CLIENT_ARCHITECTURE_LC = 0x0005,
  241. /** EFI IA32 */
  242. DHCP_CLIENT_ARCHITECTURE_IA32 = 0x0006,
  243. /** EFI x86-64 */
  244. DHCP_CLIENT_ARCHITECTURE_X86_64 = 0x0007,
  245. /** EFI Xscale */
  246. DHCP_CLIENT_ARCHITECTURE_XSCALE = 0x0008,
  247. /** EFI BC */
  248. DHCP_CLIENT_ARCHITECTURE_EFI = 0x0009,
  249. /** EFI 32-bit ARM */
  250. DHCP_CLIENT_ARCHITECTURE_ARM32 = 0x000a,
  251. /** EFI 64-bit ARM */
  252. DHCP_CLIENT_ARCHITECTURE_ARM64 = 0x000b,
  253. };
  254. /** Client network device interface */
  255. #define DHCP_CLIENT_NDI 94
  256. /** UUID client identifier */
  257. #define DHCP_CLIENT_UUID 97
  258. /** UUID client identifier */
  259. struct dhcp_client_uuid {
  260. /** Identifier type */
  261. uint8_t type;
  262. /** UUID */
  263. union uuid uuid;
  264. } __attribute__ (( packed ));
  265. #define DHCP_CLIENT_UUID_TYPE 0
  266. /** DNS domain search list */
  267. #define DHCP_DOMAIN_SEARCH 119
  268. /** Etherboot-specific encapsulated options
  269. *
  270. * This encapsulated options field is used to contain all options
  271. * specific to Etherboot (i.e. not assigned by IANA or other standards
  272. * bodies).
  273. */
  274. #define DHCP_EB_ENCAP 175
  275. /** Priority of this options block
  276. *
  277. * This is a signed 8-bit integer field indicating the priority of
  278. * this block of options. It can be used to specify the relative
  279. * priority of multiple option blocks (e.g. options from non-volatile
  280. * storage versus options from a DHCP server).
  281. */
  282. #define DHCP_EB_PRIORITY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x01 )
  283. /** "Your" IP address
  284. *
  285. * This option is used internally to contain the value of the "yiaddr"
  286. * field, in order to provide a consistent approach to storing and
  287. * processing options. It should never be present in a DHCP packet.
  288. */
  289. #define DHCP_EB_YIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x02 )
  290. /** "Server" IP address
  291. *
  292. * This option is used internally to contain the value of the "siaddr"
  293. * field, in order to provide a consistent approach to storing and
  294. * processing options. It should never be present in a DHCP packet.
  295. */
  296. #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x03 )
  297. /** Keep SAN drive registered
  298. *
  299. * If set to a non-zero value, iPXE will not detach any SAN drive
  300. * after failing to boot from it. (This option is required in order
  301. * to perform an installation direct to an iSCSI target.)
  302. */
  303. #define DHCP_EB_KEEP_SAN DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x08 )
  304. /** Skip booting from SAN drive
  305. *
  306. * If set to a non-zero value, iPXE will skip booting from any SAN
  307. * drive. (This option is sometimes required in conjunction with @c
  308. * DHCP_EB_KEEP_SAN in order to perform an installation direct to an
  309. * iSCSI target.)
  310. */
  311. #define DHCP_EB_SKIP_SAN_BOOT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x09 )
  312. /*
  313. * Tags in the range 0x10-0x4f are reserved for feature markers
  314. *
  315. */
  316. /** Scriptlet
  317. *
  318. * If a scriptlet exists, it will be executed in place of the usual
  319. * call to autoboot()
  320. */
  321. #define DHCP_EB_SCRIPTLET DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x51 )
  322. /** Encrypted syslog server */
  323. #define DHCP_EB_SYSLOGS_SERVER DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x55 )
  324. /** Trusted root certficate fingerprints */
  325. #define DHCP_EB_TRUST DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5a )
  326. /** Client certficate */
  327. #define DHCP_EB_CERT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5b )
  328. /** Client private key */
  329. #define DHCP_EB_KEY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5c )
  330. /** Cross-signed certificate source */
  331. #define DHCP_EB_CROSS_CERT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5d )
  332. /** Skip PXE DHCP protocol extensions such as ProxyDHCP
  333. *
  334. * If set to a non-zero value, iPXE will not wait for ProxyDHCP offers
  335. * and will ignore any PXE-specific DHCP options that it receives.
  336. */
  337. #define DHCP_EB_NO_PXEDHCP DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
  338. /** Network device descriptor
  339. *
  340. * Byte 0 is the bus type ID; remaining bytes depend on the bus type.
  341. *
  342. * PCI devices:
  343. * Byte 0 : 1 (PCI)
  344. * Byte 1 : PCI vendor ID MSB
  345. * Byte 2 : PCI vendor ID LSB
  346. * Byte 3 : PCI device ID MSB
  347. * Byte 4 : PCI device ID LSB
  348. */
  349. #define DHCP_EB_BUS_ID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
  350. /** Network device descriptor */
  351. struct dhcp_netdev_desc {
  352. /** Bus type ID */
  353. uint8_t type;
  354. /** Vendor ID */
  355. uint16_t vendor;
  356. /** Device ID */
  357. uint16_t device;
  358. } __attribute__ (( packed ));
  359. /** Use cached network settings (obsolete; do not reuse this value) */
  360. #define DHCP_EB_USE_CACHED DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb2 )
  361. /** SAN retry count
  362. *
  363. * This is the maximum number of times that SAN operations will be
  364. * retried.
  365. */
  366. #define DHCP_EB_SAN_RETRY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbb )
  367. /** SAN filename
  368. *
  369. * This is the path of the bootloader within the SAN device.
  370. */
  371. #define DHCP_EB_SAN_FILENAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbc )
  372. /** SAN drive number
  373. *
  374. * This is the drive number for a SAN-hooked drive. For BIOS, 0x80 is
  375. * the first hard disk, 0x81 is the second hard disk, etc.
  376. */
  377. #define DHCP_EB_SAN_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
  378. /** Username
  379. *
  380. * This will be used as the username for any required authentication.
  381. * It is expected that this option's value will be held in
  382. * non-volatile storage, rather than transmitted as part of a DHCP
  383. * packet.
  384. */
  385. #define DHCP_EB_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
  386. /** Password
  387. *
  388. * This will be used as the password for any required authentication.
  389. * It is expected that this option's value will be held in
  390. * non-volatile storage, rather than transmitted as part of a DHCP
  391. * packet.
  392. */
  393. #define DHCP_EB_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
  394. /** Reverse username
  395. *
  396. * This will be used as the reverse username (i.e. the username
  397. * provided by the server) for any required authentication. It is
  398. * expected that this option's value will be held in non-volatile
  399. * storage, rather than transmitted as part of a DHCP packet.
  400. */
  401. #define DHCP_EB_REVERSE_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc0 )
  402. /** Reverse password
  403. *
  404. * This will be used as the reverse password (i.e. the password
  405. * provided by the server) for any required authentication. It is
  406. * expected that this option's value will be held in non-volatile
  407. * storage, rather than transmitted as part of a DHCP packet.
  408. */
  409. #define DHCP_EB_REVERSE_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )
  410. /** User ID
  411. *
  412. * This will be used as the user id for AUTH_SYS based authentication in NFS.
  413. */
  414. #define DHCP_EB_UID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc2 )
  415. /** Group ID
  416. *
  417. * This will be used as the group id for AUTH_SYS based authentication in NFS.
  418. */
  419. #define DHCP_EB_GID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc3 )
  420. /** iPXE version number */
  421. #define DHCP_EB_VERSION DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )
  422. /** iSCSI primary target IQN */
  423. #define DHCP_ISCSI_PRIMARY_TARGET_IQN 201
  424. /** iSCSI secondary target IQN */
  425. #define DHCP_ISCSI_SECONDARY_TARGET_IQN 202
  426. /** iSCSI initiator IQN */
  427. #define DHCP_ISCSI_INITIATOR_IQN 203
  428. /** Maximum normal DHCP option */
  429. #define DHCP_MAX_OPTION 254
  430. /** End of options
  431. *
  432. * This tag does not have a length field; it is always only a single
  433. * byte in length.
  434. */
  435. #define DHCP_END 255
  436. /** @} */
  437. /** Construct a DHCP option from a list of bytes */
  438. #define DHCP_OPTION( ... ) VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
  439. /** Construct a DHCP option from a list of characters */
  440. #define DHCP_STRING( ... ) DHCP_OPTION ( __VA_ARGS__ )
  441. /** Construct a byte-valued DHCP option */
  442. #define DHCP_BYTE( value ) DHCP_OPTION ( value )
  443. /** Construct a word-valued DHCP option */
  444. #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
  445. ( ( (value) >> 0 ) & 0xff ) )
  446. /** Construct a dword-valued DHCP option */
  447. #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
  448. ( ( (value) >> 16 ) & 0xff ), \
  449. ( ( (value) >> 8 ) & 0xff ), \
  450. ( ( (value) >> 0 ) & 0xff ) )
  451. /** Construct a DHCP encapsulated options field */
  452. #define DHCP_ENCAP( ... ) DHCP_OPTION ( __VA_ARGS__, DHCP_END )
  453. /**
  454. * A DHCP option
  455. *
  456. * DHCP options consist of a mandatory tag, a length field that is
  457. * mandatory for all options except @c DHCP_PAD and @c DHCP_END, and a
  458. * payload.
  459. */
  460. struct dhcp_option {
  461. /** Tag
  462. *
  463. * Must be a @c DHCP_XXX value.
  464. */
  465. uint8_t tag;
  466. /** Length
  467. *
  468. * This is the length of the data field (i.e. excluding the
  469. * tag and length fields). For the two tags @c DHCP_PAD and
  470. * @c DHCP_END, the length field is implicitly zero and is
  471. * also missing, i.e. these DHCP options are only a single
  472. * byte in length.
  473. */
  474. uint8_t len;
  475. /** Option data */
  476. uint8_t data[0];
  477. } __attribute__ (( packed ));
  478. /**
  479. * Length of a DHCP option header
  480. *
  481. * The header is the portion excluding the data, i.e. the tag and the
  482. * length.
  483. */
  484. #define DHCP_OPTION_HEADER_LEN ( offsetof ( struct dhcp_option, data ) )
  485. /** Maximum length for a single DHCP option */
  486. #define DHCP_MAX_LEN 0xff
  487. /**
  488. * A DHCP header
  489. *
  490. */
  491. struct dhcphdr {
  492. /** Operation
  493. *
  494. * This must be either @c BOOTP_REQUEST or @c BOOTP_REPLY.
  495. */
  496. uint8_t op;
  497. /** Hardware address type
  498. *
  499. * This is an ARPHRD_XXX constant. Note that ARPHRD_XXX
  500. * constants are nominally 16 bits wide; this could be
  501. * considered to be a bug in the BOOTP/DHCP specification.
  502. */
  503. uint8_t htype;
  504. /** Hardware address length */
  505. uint8_t hlen;
  506. /** Number of hops from server */
  507. uint8_t hops;
  508. /** Transaction ID */
  509. uint32_t xid;
  510. /** Seconds since start of acquisition */
  511. uint16_t secs;
  512. /** Flags */
  513. uint16_t flags;
  514. /** "Client" IP address
  515. *
  516. * This is filled in if the client already has an IP address
  517. * assigned and can respond to ARP requests.
  518. */
  519. struct in_addr ciaddr;
  520. /** "Your" IP address
  521. *
  522. * This is the IP address assigned by the server to the client.
  523. */
  524. struct in_addr yiaddr;
  525. /** "Server" IP address
  526. *
  527. * This is the IP address of the next server to be used in the
  528. * boot process.
  529. */
  530. struct in_addr siaddr;
  531. /** "Gateway" IP address
  532. *
  533. * This is the IP address of the DHCP relay agent, if any.
  534. */
  535. struct in_addr giaddr;
  536. /** Client hardware address */
  537. uint8_t chaddr[16];
  538. /** Server host name (null terminated)
  539. *
  540. * This field may be overridden and contain DHCP options
  541. */
  542. char sname[64];
  543. /** Boot file name (null terminated)
  544. *
  545. * This field may be overridden and contain DHCP options
  546. */
  547. char file[128];
  548. /** DHCP magic cookie
  549. *
  550. * Must have the value @c DHCP_MAGIC_COOKIE.
  551. */
  552. uint32_t magic;
  553. /** DHCP options
  554. *
  555. * Variable length; extends to the end of the packet. Minimum
  556. * length (for the sake of sanity) is 1, to allow for a single
  557. * @c DHCP_END tag.
  558. */
  559. uint8_t options[0];
  560. };
  561. /** Opcode for a request from client to server */
  562. #define BOOTP_REQUEST 1
  563. /** Opcode for a reply from server to client */
  564. #define BOOTP_REPLY 2
  565. /** BOOTP reply must be broadcast
  566. *
  567. * Clients that cannot accept unicast BOOTP replies must set this
  568. * flag.
  569. */
  570. #define BOOTP_FL_BROADCAST 0x8000
  571. /** DHCP magic cookie */
  572. #define DHCP_MAGIC_COOKIE 0x63825363UL
  573. /** DHCP minimum packet length
  574. *
  575. * This is the mandated minimum packet length that a DHCP participant
  576. * must be prepared to receive.
  577. */
  578. #define DHCP_MIN_LEN 552
  579. /** Settings block name used for DHCP responses */
  580. #define DHCP_SETTINGS_NAME "dhcp"
  581. /** Settings block name used for ProxyDHCP responses */
  582. #define PROXYDHCP_SETTINGS_NAME "proxydhcp"
  583. /** Setting block name used for BootServerDHCP responses */
  584. #define PXEBS_SETTINGS_NAME "pxebs"
  585. extern uint32_t dhcp_last_xid;
  586. extern int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
  587. struct net_device *netdev, uint8_t msgtype,
  588. uint32_t xid, const void *options,
  589. size_t options_len, void *data,
  590. size_t max_len );
  591. extern int dhcp_create_request ( struct dhcp_packet *dhcppkt,
  592. struct net_device *netdev,
  593. unsigned int msgtype, uint32_t xid,
  594. struct in_addr ciaddr,
  595. void *data, size_t max_len );
  596. extern int start_dhcp ( struct interface *job, struct net_device *netdev );
  597. extern int start_pxebs ( struct interface *job, struct net_device *netdev,
  598. unsigned int pxe_type );
  599. #endif /* _IPXE_DHCP_H */