6 * Dynamic Host Configuration Protocol
12 #include <gpxe/list.h>
13 #include <gpxe/refcnt.h>
14 #include <gpxe/tables.h>
21 /** BOOTP/DHCP server port */
22 #define BOOTPS_PORT 67
24 /** BOOTP/DHCP client port */
25 #define BOOTPC_PORT 68
27 /** Construct a tag value for an encapsulated option
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.
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 )
43 * @defgroup dhcpopts DHCP option tags
49 * This tag does not have a length field; it is always only a single
54 /** Minimum normal DHCP option */
55 #define DHCP_MIN_OPTION 1
58 #define DHCP_SUBNET_MASK 1
61 #define DHCP_ROUTERS 3
64 #define DHCP_DNS_SERVERS 6
67 #define DHCP_LOG_SERVERS 7
70 #define DHCP_HOST_NAME 12
73 #define DHCP_DOMAIN_NAME 15
76 #define DHCP_ROOT_PATH 17
78 /** Vendor encapsulated options */
79 #define DHCP_VENDOR_ENCAP 43
81 /** Requested IP address */
82 #define DHCP_REQUESTED_ADDRESS 50
85 #define DHCP_LEASE_TIME 51
87 /** Option overloading
89 * The value of this option is the bitwise-OR of zero or more
90 * DHCP_OPTION_OVERLOAD_XXX constants.
92 #define DHCP_OPTION_OVERLOAD 52
94 /** The "file" field is overloaded to contain extra DHCP options */
95 #define DHCP_OPTION_OVERLOAD_FILE 1
97 /** The "sname" field is overloaded to contain extra DHCP options */
98 #define DHCP_OPTION_OVERLOAD_SNAME 2
100 /** DHCP message type */
101 #define DHCP_MESSAGE_TYPE 53
102 #define DHCPDISCOVER 1
104 #define DHCPREQUEST 3
105 #define DHCPDECLINE 4
108 #define DHCPRELEASE 7
111 /** DHCP server identifier */
112 #define DHCP_SERVER_IDENTIFIER 54
114 /** Parameter request list */
115 #define DHCP_PARAMETER_REQUEST_LIST 55
117 /** Maximum DHCP message size */
118 #define DHCP_MAX_MESSAGE_SIZE 57
120 /** Vendor class identifier */
121 #define DHCP_VENDOR_CLASS_ID 60
123 /** Client identifier */
124 #define DHCP_CLIENT_ID 61
128 * This option replaces the fixed "sname" field, when that field is
129 * used to contain overloaded options.
131 #define DHCP_TFTP_SERVER_NAME 66
135 * This option replaces the fixed "file" field, when that field is
136 * used to contain overloaded options.
138 #define DHCP_BOOTFILE_NAME 67
140 /** Client system architecture */
141 #define DHCP_CLIENT_ARCHITECTURE 93
143 /** Client network device interface */
144 #define DHCP_CLIENT_NDI 94
146 /** UUID client identifier */
147 #define DHCP_CLIENT_UUID 97
149 /** Etherboot-specific encapsulated options
151 * This encapsulated options field is used to contain all options
152 * specific to Etherboot (i.e. not assigned by IANA or other standards
155 #define DHCP_EB_ENCAP 175
157 /** Priority of this options block
159 * This is a signed 8-bit integer field indicating the priority of
160 * this block of options. It can be used to specify the relative
161 * priority of multiple option blocks (e.g. options from non-volatile
162 * storage versus options from a DHCP server).
164 #define DHCP_EB_PRIORITY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 1 )
166 /** "Your" IP address
168 * This option is used internally to contain the value of the "yiaddr"
169 * field, in order to provide a consistent approach to storing and
170 * processing options. It should never be present in a DHCP packet.
172 #define DHCP_EB_YIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 2 )
174 /** "Server" IP address
176 * This option is used internally to contain the value of the "siaddr"
177 * field, in order to provide a consistent approach to storing and
178 * processing options. It should never be present in a DHCP packet.
180 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 3 )
184 * This option is used internally to contain the network device
185 * hardware address, in order to provide a consistent approach to
186 * storing and processing options. It should never be present in a
189 #define DHCP_EB_MAC DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 4 )
192 * Tags in the range 0x10-0x7f are reserved for feature markers
198 * If set to a non-zero value, gPXE will not wait for ProxyDHCP offers
199 * and will ignore any ProxyDHCP offers that it receives.
201 #define DHCP_EB_NO_PROXYDHCP DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
203 /** Network device descriptor
205 * Byte 0 is the bus type ID; remaining bytes depend on the bus type.
209 * Byte 1 : PCI vendor ID MSB
210 * Byte 2 : PCI vendor ID LSB
211 * Byte 3 : PCI device ID MSB
212 * Byte 4 : PCI device ID LSB
214 #define DHCP_EB_BUS_ID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
216 /** BIOS drive number
218 * This is the drive number for a drive emulated via INT 13. 0x80 is
219 * the first hard disk, 0x81 is the second hard disk, etc.
221 #define DHCP_EB_BIOS_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
225 * This will be used as the username for any required authentication.
226 * It is expected that this option's value will be held in
227 * non-volatile storage, rather than transmitted as part of a DHCP
230 #define DHCP_EB_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
234 * This will be used as the password for any required authentication.
235 * It is expected that this option's value will be held in
236 * non-volatile storage, rather than transmitted as part of a DHCP
239 #define DHCP_EB_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
241 /** iSCSI primary target IQN */
242 #define DHCP_ISCSI_PRIMARY_TARGET_IQN 201
244 /** iSCSI secondary target IQN */
245 #define DHCP_ISCSI_SECONDARY_TARGET_IQN 202
247 /** iSCSI initiator IQN */
248 #define DHCP_ISCSI_INITIATOR_IQN 203
250 /** Maximum normal DHCP option */
251 #define DHCP_MAX_OPTION 254
255 * This tag does not have a length field; it is always only a single
263 * Count number of arguments to a variadic macro
265 * This rather neat, non-iterative solution is courtesy of Laurent
269 #define _VA_ARG_COUNT( _1, _2, _3, _4, _5, _6, _7, _8, \
270 _9, _10, _11, _12, _13, _14, _15, _16, \
271 _17, _18, _19, _20, _21, _22, _23, _24, \
272 _25, _26, _27, _28, _29, _30, _31, _32, \
273 _33, _34, _35, _36, _37, _38, _39, _40, \
274 _41, _42, _43, _44, _45, _46, _47, _48, \
275 _49, _50, _51, _52, _53, _54, _55, _56, \
276 _57, _58, _59, _60, _61, _62, _63, N, ... ) N
277 #define VA_ARG_COUNT( ... ) \
278 _VA_ARG_COUNT ( __VA_ARGS__, \
279 63, 62, 61, 60, 59, 58, 57, 56, \
280 55, 54, 53, 52, 51, 50, 49, 48, \
281 47, 46, 45, 44, 43, 42, 41, 40, \
282 39, 38, 37, 36, 35, 34, 33, 32, \
283 31, 30, 29, 28, 27, 26, 25, 24, \
284 23, 22, 21, 20, 19, 18, 17, 16, \
285 15, 14, 13, 12, 11, 10, 9, 8, \
286 7, 6, 5, 4, 3, 2, 1, 0 )
288 /** Construct a DHCP option from a list of bytes */
289 #define DHCP_OPTION( ... ) VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
291 /** Construct a DHCP option from a list of characters */
292 #define DHCP_STRING( ... ) DHCP_OPTION ( __VA_ARGS__ )
294 /** Construct a byte-valued DHCP option */
295 #define DHCP_BYTE( value ) DHCP_OPTION ( value )
297 /** Construct a word-valued DHCP option */
298 #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
299 ( ( (value) >> 0 ) & 0xff ) )
301 /** Construct a dword-valued DHCP option */
302 #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
303 ( ( (value) >> 16 ) & 0xff ), \
304 ( ( (value) >> 8 ) & 0xff ), \
305 ( ( (value) >> 0 ) & 0xff ) )
307 /** Construct a DHCP encapsulated options field */
308 #define DHCP_ENCAP( ... ) DHCP_OPTION ( __VA_ARGS__, DHCP_END )
313 * DHCP options consist of a mandatory tag, a length field that is
314 * mandatory for all options except @c DHCP_PAD and @c DHCP_END, and a
320 * Must be a @c DHCP_XXX value.
325 * This is the length of the data field (i.e. excluding the
326 * tag and length fields). For the two tags @c DHCP_PAD and
327 * @c DHCP_END, the length field is implicitly zero and is
328 * also missing, i.e. these DHCP options are only a single
334 } __attribute__ (( packed ));
337 * Length of a DHCP option header
339 * The header is the portion excluding the data, i.e. the tag and the
342 #define DHCP_OPTION_HEADER_LEN ( offsetof ( struct dhcp_option, data ) )
344 /** Maximum length for a single DHCP option */
345 #define DHCP_MAX_LEN 0xff
354 * This must be either @c BOOTP_REQUEST or @c BOOTP_REPLY.
357 /** Hardware address type
359 * This is an ARPHRD_XXX constant. Note that ARPHRD_XXX
360 * constants are nominally 16 bits wide; this could be
361 * considered to be a bug in the BOOTP/DHCP specification.
364 /** Hardware address length */
366 /** Number of hops from server */
368 /** Transaction ID */
370 /** Seconds since start of acquisition */
374 /** "Client" IP address
376 * This is filled in if the client already has an IP address
377 * assigned and can respond to ARP requests.
379 struct in_addr ciaddr;
380 /** "Your" IP address
382 * This is the IP address assigned by the server to the client.
384 struct in_addr yiaddr;
385 /** "Server" IP address
387 * This is the IP address of the next server to be used in the
390 struct in_addr siaddr;
391 /** "Gateway" IP address
393 * This is the IP address of the DHCP relay agent, if any.
395 struct in_addr giaddr;
396 /** Client hardware address */
398 /** Server host name (null terminated)
400 * This field may be overridden and contain DHCP options
403 /** Boot file name (null terminated)
405 * This field may be overridden and contain DHCP options
408 /** DHCP magic cookie
410 * Must have the value @c DHCP_MAGIC_COOKIE.
415 * Variable length; extends to the end of the packet. Minimum
416 * length (for the sake of sanity) is 1, to allow for a single
422 /** Opcode for a request from client to server */
423 #define BOOTP_REQUEST 1
425 /** Opcode for a reply from server to client */
426 #define BOOTP_REPLY 2
428 /** BOOTP reply must be broadcast
430 * Clients that cannot accept unicast BOOTP replies must set this
433 #define BOOTP_FL_BROADCAST 0x8000
435 /** DHCP magic cookie */
436 #define DHCP_MAGIC_COOKIE 0x63825363UL
438 /** DHCP minimum packet length
440 * This is the mandated minimum packet length that a DHCP participant
441 * must be prepared to receive.
443 #define DHCP_MIN_LEN 552
445 /** Maximum time that we will wait for ProxyDHCP offers */
446 #define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 )
448 extern int create_dhcpdiscover ( struct net_device *netdev,
449 void *data, size_t max_len );
450 extern int create_dhcpack ( struct net_device *netdev,
451 void *data, size_t max_len );
452 extern int create_proxydhcpack ( struct net_device *netdev,
453 void *data, size_t max_len );
454 extern int start_dhcp ( struct job_interface *job, struct net_device *netdev );
456 #endif /* _GPXE_DHCP_H */