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 18KB

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