6 * Dynamic Host Configuration Protocol
12 #include <gpxe/list.h>
13 #include <gpxe/refcnt.h>
14 #include <gpxe/tables.h>
20 struct dhcp_pxe_boot_menu_item;
22 /** BOOTP/DHCP server port */
23 #define BOOTPS_PORT 67
25 /** BOOTP/DHCP client port */
26 #define BOOTPC_PORT 68
28 /** PXE server port */
31 /** Construct a tag value for an encapsulated option
33 * This tag value can be passed to Etherboot functions when searching
34 * for DHCP options in order to search for a tag within an
35 * encapsulated options block.
37 #define DHCP_ENCAP_OPT( encapsulator, encapsulated ) \
38 ( ( (encapsulator) << 8 ) | (encapsulated) )
39 /** Extract encapsulating option block tag from encapsulated tag value */
40 #define DHCP_ENCAPSULATOR( encap_opt ) ( (encap_opt) >> 8 )
41 /** Extract encapsulated option tag from encapsulated tag value */
42 #define DHCP_ENCAPSULATED( encap_opt ) ( (encap_opt) & 0xff )
43 /** Option is encapsulated */
44 #define DHCP_IS_ENCAP_OPT( opt ) DHCP_ENCAPSULATOR( opt )
47 * @defgroup dhcpopts DHCP option tags
53 * This tag does not have a length field; it is always only a single
58 /** Minimum normal DHCP option */
59 #define DHCP_MIN_OPTION 1
62 #define DHCP_SUBNET_MASK 1
65 #define DHCP_ROUTERS 3
68 #define DHCP_DNS_SERVERS 6
71 #define DHCP_LOG_SERVERS 7
74 #define DHCP_HOST_NAME 12
77 #define DHCP_DOMAIN_NAME 15
80 #define DHCP_ROOT_PATH 17
82 /** Vendor encapsulated options */
83 #define DHCP_VENDOR_ENCAP 43
85 /** PXE boot server multicast address */
86 #define DHCP_PXE_BOOT_SERVER_MCAST DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 7 )
89 #define DHCP_PXE_BOOT_MENU DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 9 )
91 /** PXE boot menu item */
92 #define DHCP_PXE_BOOT_MENU_ITEM DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 71 )
94 /** Requested IP address */
95 #define DHCP_REQUESTED_ADDRESS 50
98 #define DHCP_LEASE_TIME 51
100 /** Option overloading
102 * The value of this option is the bitwise-OR of zero or more
103 * DHCP_OPTION_OVERLOAD_XXX constants.
105 #define DHCP_OPTION_OVERLOAD 52
107 /** The "file" field is overloaded to contain extra DHCP options */
108 #define DHCP_OPTION_OVERLOAD_FILE 1
110 /** The "sname" field is overloaded to contain extra DHCP options */
111 #define DHCP_OPTION_OVERLOAD_SNAME 2
113 /** DHCP message type */
114 #define DHCP_MESSAGE_TYPE 53
116 #define DHCPDISCOVER 1
118 #define DHCPREQUEST 3
119 #define DHCPDECLINE 4
122 #define DHCPRELEASE 7
125 /** DHCP server identifier */
126 #define DHCP_SERVER_IDENTIFIER 54
128 /** Parameter request list */
129 #define DHCP_PARAMETER_REQUEST_LIST 55
131 /** Maximum DHCP message size */
132 #define DHCP_MAX_MESSAGE_SIZE 57
134 /** Vendor class identifier */
135 #define DHCP_VENDOR_CLASS_ID 60
137 /** Client identifier */
138 #define DHCP_CLIENT_ID 61
142 * This option replaces the fixed "sname" field, when that field is
143 * used to contain overloaded options.
145 #define DHCP_TFTP_SERVER_NAME 66
149 * This option replaces the fixed "file" field, when that field is
150 * used to contain overloaded options.
152 #define DHCP_BOOTFILE_NAME 67
154 /** Client system architecture */
155 #define DHCP_CLIENT_ARCHITECTURE 93
157 /** Client network device interface */
158 #define DHCP_CLIENT_NDI 94
160 /** UUID client identifier */
161 #define DHCP_CLIENT_UUID 97
163 /** Etherboot-specific encapsulated options
165 * This encapsulated options field is used to contain all options
166 * specific to Etherboot (i.e. not assigned by IANA or other standards
169 #define DHCP_EB_ENCAP 175
171 /** Priority of this options block
173 * This is a signed 8-bit integer field indicating the priority of
174 * this block of options. It can be used to specify the relative
175 * priority of multiple option blocks (e.g. options from non-volatile
176 * storage versus options from a DHCP server).
178 #define DHCP_EB_PRIORITY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x01 )
180 /** "Your" IP address
182 * This option is used internally to contain the value of the "yiaddr"
183 * field, in order to provide a consistent approach to storing and
184 * processing options. It should never be present in a DHCP packet.
186 #define DHCP_EB_YIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x02 )
188 /** "Server" IP address
190 * This option is used internally to contain the value of the "siaddr"
191 * field, in order to provide a consistent approach to storing and
192 * processing options. It should never be present in a DHCP packet.
194 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x03 )
196 /** Keep SAN drive registered
198 * If set to a non-zero value, gPXE will not detach any SAN drive
199 * after failing to boot from it. (This option is required in order
200 * to perform a Windows Server 2008 installation direct to an iSCSI
203 #define DHCP_EB_KEEP_SAN DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x08 )
206 * Tags in the range 0x10-0x7f are reserved for feature markers
210 /** Skip PXE DHCP protocol extensions such as ProxyDHCP
212 * If set to a non-zero value, gPXE will not wait for ProxyDHCP offers
213 * and will ignore any PXE-specific DHCP offers that it receives.
215 #define DHCP_EB_NO_PXEDHCP DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
217 /** Network device descriptor
219 * Byte 0 is the bus type ID; remaining bytes depend on the bus type.
223 * Byte 1 : PCI vendor ID MSB
224 * Byte 2 : PCI vendor ID LSB
225 * Byte 3 : PCI device ID MSB
226 * Byte 4 : PCI device ID LSB
228 #define DHCP_EB_BUS_ID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
230 /** BIOS drive number
232 * This is the drive number for a drive emulated via INT 13. 0x80 is
233 * the first hard disk, 0x81 is the second hard disk, etc.
235 #define DHCP_EB_BIOS_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
239 * This will be used as the username for any required authentication.
240 * It is expected that this option's value will be held in
241 * non-volatile storage, rather than transmitted as part of a DHCP
244 #define DHCP_EB_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
248 * This will be used as the password for any required authentication.
249 * It is expected that this option's value will be held in
250 * non-volatile storage, rather than transmitted as part of a DHCP
253 #define DHCP_EB_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
257 * This will be used as the reverse username (i.e. the username
258 * provided by the server) for any required authentication. It is
259 * expected that this option's value will be held in non-volatile
260 * storage, rather than transmitted as part of a DHCP packet.
262 #define DHCP_EB_REVERSE_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc0 )
266 * This will be used as the reverse password (i.e. the password
267 * provided by the server) for any required authentication. It is
268 * expected that this option's value will be held in non-volatile
269 * storage, rather than transmitted as part of a DHCP packet.
271 #define DHCP_EB_REVERSE_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )
273 /** gPXE version number */
274 #define DHCP_EB_VERSION DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )
276 /** iSCSI primary target IQN */
277 #define DHCP_ISCSI_PRIMARY_TARGET_IQN 201
279 /** iSCSI secondary target IQN */
280 #define DHCP_ISCSI_SECONDARY_TARGET_IQN 202
282 /** iSCSI initiator IQN */
283 #define DHCP_ISCSI_INITIATOR_IQN 203
285 /** Maximum normal DHCP option */
286 #define DHCP_MAX_OPTION 254
290 * This tag does not have a length field; it is always only a single
298 * Count number of arguments to a variadic macro
300 * This rather neat, non-iterative solution is courtesy of Laurent
304 #define _VA_ARG_COUNT( _1, _2, _3, _4, _5, _6, _7, _8, \
305 _9, _10, _11, _12, _13, _14, _15, _16, \
306 _17, _18, _19, _20, _21, _22, _23, _24, \
307 _25, _26, _27, _28, _29, _30, _31, _32, \
308 _33, _34, _35, _36, _37, _38, _39, _40, \
309 _41, _42, _43, _44, _45, _46, _47, _48, \
310 _49, _50, _51, _52, _53, _54, _55, _56, \
311 _57, _58, _59, _60, _61, _62, _63, N, ... ) N
312 #define VA_ARG_COUNT( ... ) \
313 _VA_ARG_COUNT ( __VA_ARGS__, \
314 63, 62, 61, 60, 59, 58, 57, 56, \
315 55, 54, 53, 52, 51, 50, 49, 48, \
316 47, 46, 45, 44, 43, 42, 41, 40, \
317 39, 38, 37, 36, 35, 34, 33, 32, \
318 31, 30, 29, 28, 27, 26, 25, 24, \
319 23, 22, 21, 20, 19, 18, 17, 16, \
320 15, 14, 13, 12, 11, 10, 9, 8, \
321 7, 6, 5, 4, 3, 2, 1, 0 )
323 /** Construct a DHCP option from a list of bytes */
324 #define DHCP_OPTION( ... ) VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
326 /** Construct a DHCP option from a list of characters */
327 #define DHCP_STRING( ... ) DHCP_OPTION ( __VA_ARGS__ )
329 /** Construct a byte-valued DHCP option */
330 #define DHCP_BYTE( value ) DHCP_OPTION ( value )
332 /** Construct a word-valued DHCP option */
333 #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
334 ( ( (value) >> 0 ) & 0xff ) )
336 /** Construct a dword-valued DHCP option */
337 #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
338 ( ( (value) >> 16 ) & 0xff ), \
339 ( ( (value) >> 8 ) & 0xff ), \
340 ( ( (value) >> 0 ) & 0xff ) )
342 /** Construct a DHCP encapsulated options field */
343 #define DHCP_ENCAP( ... ) DHCP_OPTION ( __VA_ARGS__, DHCP_END )
348 * DHCP options consist of a mandatory tag, a length field that is
349 * mandatory for all options except @c DHCP_PAD and @c DHCP_END, and a
355 * Must be a @c DHCP_XXX value.
360 * This is the length of the data field (i.e. excluding the
361 * tag and length fields). For the two tags @c DHCP_PAD and
362 * @c DHCP_END, the length field is implicitly zero and is
363 * also missing, i.e. these DHCP options are only a single
369 } __attribute__ (( packed ));
372 * Length of a DHCP option header
374 * The header is the portion excluding the data, i.e. the tag and the
377 #define DHCP_OPTION_HEADER_LEN ( offsetof ( struct dhcp_option, data ) )
379 /** Maximum length for a single DHCP option */
380 #define DHCP_MAX_LEN 0xff
389 * This must be either @c BOOTP_REQUEST or @c BOOTP_REPLY.
392 /** Hardware address type
394 * This is an ARPHRD_XXX constant. Note that ARPHRD_XXX
395 * constants are nominally 16 bits wide; this could be
396 * considered to be a bug in the BOOTP/DHCP specification.
399 /** Hardware address length */
401 /** Number of hops from server */
403 /** Transaction ID */
405 /** Seconds since start of acquisition */
409 /** "Client" IP address
411 * This is filled in if the client already has an IP address
412 * assigned and can respond to ARP requests.
414 struct in_addr ciaddr;
415 /** "Your" IP address
417 * This is the IP address assigned by the server to the client.
419 struct in_addr yiaddr;
420 /** "Server" IP address
422 * This is the IP address of the next server to be used in the
425 struct in_addr siaddr;
426 /** "Gateway" IP address
428 * This is the IP address of the DHCP relay agent, if any.
430 struct in_addr giaddr;
431 /** Client hardware address */
433 /** Server host name (null terminated)
435 * This field may be overridden and contain DHCP options
438 /** Boot file name (null terminated)
440 * This field may be overridden and contain DHCP options
443 /** DHCP magic cookie
445 * Must have the value @c DHCP_MAGIC_COOKIE.
450 * Variable length; extends to the end of the packet. Minimum
451 * length (for the sake of sanity) is 1, to allow for a single
457 /** Opcode for a request from client to server */
458 #define BOOTP_REQUEST 1
460 /** Opcode for a reply from server to client */
461 #define BOOTP_REPLY 2
463 /** BOOTP reply must be broadcast
465 * Clients that cannot accept unicast BOOTP replies must set this
468 #define BOOTP_FL_BROADCAST 0x8000
470 /** DHCP magic cookie */
471 #define DHCP_MAGIC_COOKIE 0x63825363UL
473 /** DHCP minimum packet length
475 * This is the mandated minimum packet length that a DHCP participant
476 * must be prepared to receive.
478 #define DHCP_MIN_LEN 552
480 /** Maximum time that we will wait for ProxyDHCP responses */
481 #define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 )
483 /** Timeouts for sending DHCP packets */
484 #define DHCP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
485 #define DHCP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
487 /** Settings block name used for DHCP responses */
488 #define DHCP_SETTINGS_NAME "dhcp"
490 /** Settings block name used for ProxyDHCP responses */
491 #define PROXYDHCP_SETTINGS_NAME "proxydhcp"
493 /** Setting block name used for BootServerDHCP responses */
494 #define BSDHCP_SETTINGS_NAME "bs"
496 extern int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
497 struct net_device *netdev, uint8_t msgtype,
498 struct dhcp_options *options,
499 void *data, size_t max_len );
500 extern int dhcp_create_request ( struct dhcp_packet *dhcppkt,
501 struct net_device *netdev,
502 unsigned int msgtype, struct in_addr ciaddr,
503 struct in_addr server,
504 struct in_addr requested_ip,
505 struct dhcp_pxe_boot_menu_item *menu_item,
506 void *data, size_t max_len );
507 extern int start_dhcp ( struct job_interface *job, struct net_device *netdev );
509 #endif /* _GPXE_DHCP_H */