iPXE
dhcp.h
Go to the documentation of this file.
00001 #ifndef _IPXE_DHCP_H
00002 #define _IPXE_DHCP_H
00003 
00004 /** @file
00005  *
00006  * Dynamic Host Configuration Protocol
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <stdarg.h>
00014 #include <ipxe/in.h>
00015 #include <ipxe/list.h>
00016 #include <ipxe/refcnt.h>
00017 #include <ipxe/tables.h>
00018 #include <ipxe/uuid.h>
00019 #include <ipxe/netdevice.h>
00020 #include <ipxe/uaccess.h>
00021 
00022 struct interface;
00023 struct dhcp_options;
00024 struct dhcp_packet;
00025 
00026 /** BOOTP/DHCP server port */
00027 #define BOOTPS_PORT 67
00028 
00029 /** BOOTP/DHCP client port */
00030 #define BOOTPC_PORT 68
00031 
00032 /** PXE server port */
00033 #define PXE_PORT 4011
00034 
00035 /** Construct a tag value for an encapsulated option
00036  *
00037  * This tag value can be passed to Etherboot functions when searching
00038  * for DHCP options in order to search for a tag within an
00039  * encapsulated options block.
00040  */
00041 #define DHCP_ENCAP_OPT( encapsulator, encapsulated ) \
00042         ( ( (encapsulator) << 8 ) | (encapsulated) )
00043 /** Extract encapsulating option block tag from encapsulated tag value */
00044 #define DHCP_ENCAPSULATOR( encap_opt ) ( (encap_opt) >> 8 )
00045 /** Extract encapsulated option tag from encapsulated tag value */
00046 #define DHCP_ENCAPSULATED( encap_opt ) ( (encap_opt) & 0xff )
00047 /** Option is encapsulated */
00048 #define DHCP_IS_ENCAP_OPT( opt ) DHCP_ENCAPSULATOR( opt )
00049 
00050 /**
00051  * @defgroup dhcpopts DHCP option tags
00052  * @{
00053  */
00054 
00055 /** Padding
00056  *
00057  * This tag does not have a length field; it is always only a single
00058  * byte in length.
00059  */
00060 #define DHCP_PAD 0
00061 
00062 /** Minimum normal DHCP option */
00063 #define DHCP_MIN_OPTION 1
00064 
00065 /** Subnet mask */
00066 #define DHCP_SUBNET_MASK 1
00067 
00068 /** Routers */
00069 #define DHCP_ROUTERS 3
00070 
00071 /** DNS servers */
00072 #define DHCP_DNS_SERVERS 6
00073 
00074 /** Syslog servers */
00075 #define DHCP_LOG_SERVERS 7
00076 
00077 /** Host name */
00078 #define DHCP_HOST_NAME 12
00079 
00080 /** Domain name */
00081 #define DHCP_DOMAIN_NAME 15
00082 
00083 /** Root path */
00084 #define DHCP_ROOT_PATH 17
00085 
00086 /** Maximum transmission unit */
00087 #define DHCP_MTU 26
00088 
00089 /** Vendor encapsulated options */
00090 #define DHCP_VENDOR_ENCAP 43
00091 
00092 /** PXE boot server discovery control */
00093 #define DHCP_PXE_DISCOVERY_CONTROL DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 6 )
00094 
00095 /** PXE boot server discovery control bits */
00096 enum dhcp_pxe_discovery_control {
00097         /** Inhibit broadcast discovery */
00098         PXEBS_NO_BROADCAST = 1,
00099         /** Inhibit multicast discovery */
00100         PXEBS_NO_MULTICAST = 2,
00101         /** Accept only servers in DHCP_PXE_BOOT_SERVERS list */
00102         PXEBS_NO_UNKNOWN_SERVERS = 4,
00103         /** Skip discovery if filename present */
00104         PXEBS_SKIP = 8,
00105 };
00106 
00107 /** PXE boot server multicast address */
00108 #define DHCP_PXE_BOOT_SERVER_MCAST DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 7 )
00109 
00110 /** PXE boot servers */
00111 #define DHCP_PXE_BOOT_SERVERS DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 8 )
00112 
00113 /** PXE boot server */
00114 struct dhcp_pxe_boot_server {
00115         /** "Type" */
00116         uint16_t type;
00117         /** Number of IPv4 addresses */
00118         uint8_t num_ip;
00119         /** IPv4 addresses */
00120         struct in_addr ip[0];
00121 } __attribute__ (( packed ));
00122 
00123 /** PXE boot menu */
00124 #define DHCP_PXE_BOOT_MENU DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 9 )
00125 
00126 /** PXE boot menu */
00127 struct dhcp_pxe_boot_menu {
00128         /** "Type" */
00129         uint16_t type;
00130         /** Description length */
00131         uint8_t desc_len;
00132         /** Description */
00133         char desc[0];
00134 } __attribute__ (( packed ));
00135 
00136 /** PXE boot menu prompt */
00137 #define DHCP_PXE_BOOT_MENU_PROMPT DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 10 )
00138 
00139 /** PXE boot menu prompt */
00140 struct dhcp_pxe_boot_menu_prompt {
00141         /** Timeout
00142          *
00143          * A value of 0 means "time out immediately and select first
00144          * boot item, without displaying the prompt".  A value of 255
00145          * means "display menu immediately with no timeout".  Any
00146          * other value means "display prompt, wait this many seconds
00147          * for keypress, if key is F8, display menu, otherwise select
00148          * first boot item".
00149          */
00150         uint8_t timeout;
00151         /** Prompt to press F8 */
00152         char prompt[0];
00153 } __attribute__ (( packed ));
00154 
00155 /** PXE boot menu item */
00156 #define DHCP_PXE_BOOT_MENU_ITEM DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 71 )
00157 
00158 /** PXE boot menu item */
00159 struct dhcp_pxe_boot_menu_item {
00160         /** "Type"
00161          *
00162          * This field actually identifies the specific boot server (or
00163          * cluster of boot servers offering identical boot files).
00164          */
00165         uint16_t type;
00166         /** "Layer"
00167          *
00168          * Just don't ask.
00169          */
00170         uint16_t layer;
00171 } __attribute__ (( packed ));
00172 
00173 /** Requested IP address */
00174 #define DHCP_REQUESTED_ADDRESS 50
00175 
00176 /** Lease time */
00177 #define DHCP_LEASE_TIME 51
00178 
00179 /** Option overloading
00180  *
00181  * The value of this option is the bitwise-OR of zero or more
00182  * DHCP_OPTION_OVERLOAD_XXX constants.
00183  */
00184 #define DHCP_OPTION_OVERLOAD 52
00185 
00186 /** The "file" field is overloaded to contain extra DHCP options */
00187 #define DHCP_OPTION_OVERLOAD_FILE 1
00188 
00189 /** The "sname" field is overloaded to contain extra DHCP options */
00190 #define DHCP_OPTION_OVERLOAD_SNAME 2
00191 
00192 /** DHCP message type */
00193 #define DHCP_MESSAGE_TYPE 53
00194 #define DHCPNONE 0
00195 #define DHCPDISCOVER 1
00196 #define DHCPOFFER 2
00197 #define DHCPREQUEST 3
00198 #define DHCPDECLINE 4
00199 #define DHCPACK 5
00200 #define DHCPNAK 6
00201 #define DHCPRELEASE 7
00202 #define DHCPINFORM 8
00203 
00204 /** DHCP server identifier */
00205 #define DHCP_SERVER_IDENTIFIER 54
00206 
00207 /** Parameter request list */
00208 #define DHCP_PARAMETER_REQUEST_LIST 55
00209 
00210 /** Maximum DHCP message size */
00211 #define DHCP_MAX_MESSAGE_SIZE 57
00212 
00213 /** Vendor class identifier */
00214 #define DHCP_VENDOR_CLASS_ID 60
00215 
00216 /** Vendor class identifier for PXE clients */
00217 #define DHCP_VENDOR_PXECLIENT( arch, ndi )                              \
00218         'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':',               \
00219         'A', 'r', 'c', 'h', ':', DHCP_VENDOR_PXECLIENT_ARCH ( arch ),   \
00220         ':', 'U', 'N', 'D', 'I', ':', DHCP_VENDOR_PXECLIENT_UNDI ( ndi )
00221 
00222 /** Vendor class identifier architecture for PXE clients */
00223 #define DHCP_VENDOR_PXECLIENT_ARCH( arch )                              \
00224         ( '0' + ( ( (arch) / 10000 ) % 10 ) ),                          \
00225         ( '0' + ( ( (arch) /  1000 ) % 10 ) ),                          \
00226         ( '0' + ( ( (arch) /   100 ) % 10 ) ),                          \
00227         ( '0' + ( ( (arch) /    10 ) % 10 ) ),                          \
00228         ( '0' + ( ( (arch) /     1 ) % 10 ) )
00229 
00230 /** Vendor class identifier UNDI version for PXE clients */
00231 #define DHCP_VENDOR_PXECLIENT_UNDI( type, major, minor )                \
00232         DHCP_VENDOR_PXECLIENT_UNDI_VERSION ( major ),                   \
00233         DHCP_VENDOR_PXECLIENT_UNDI_VERSION ( minor )
00234 #define DHCP_VENDOR_PXECLIENT_UNDI_VERSION( version )                   \
00235         ( '0' + ( ( (version) /   100 ) % 10 ) ),                       \
00236         ( '0' + ( ( (version) /    10 ) % 10 ) ),                       \
00237         ( '0' + ( ( (version) /     1 ) % 10 ) )
00238 
00239 /** Client identifier */
00240 #define DHCP_CLIENT_ID 61
00241 
00242 /** Client identifier */
00243 struct dhcp_client_id {
00244         /** Link-layer protocol */
00245         uint8_t ll_proto;
00246         /** Link-layer address */
00247         uint8_t ll_addr[MAX_LL_ADDR_LEN];
00248 } __attribute__ (( packed ));
00249 
00250 /** TFTP server name
00251  *
00252  * This option replaces the fixed "sname" field, when that field is
00253  * used to contain overloaded options.
00254  */
00255 #define DHCP_TFTP_SERVER_NAME 66
00256 
00257 /** Bootfile name
00258  *
00259  * This option replaces the fixed "file" field, when that field is
00260  * used to contain overloaded options.
00261  */
00262 #define DHCP_BOOTFILE_NAME 67
00263 
00264 /** User class identifier */
00265 #define DHCP_USER_CLASS_ID 77
00266 
00267 /** Client system architecture */
00268 #define DHCP_CLIENT_ARCHITECTURE 93
00269 
00270 /** DHCP client architecture */
00271 struct dhcp_client_architecture {
00272         uint16_t arch;
00273 } __attribute__ (( packed ));
00274 
00275 /** DHCP client architecture values
00276  *
00277  * These are defined by the PXE specification and redefined by
00278  * RFC4578.
00279  */
00280 enum dhcp_client_architecture_values {
00281         /** Intel x86 PC */
00282         DHCP_CLIENT_ARCHITECTURE_X86 = 0x0000,
00283         /** NEC/PC98 */
00284         DHCP_CLIENT_ARCHITECTURE_PC98 = 0x0001,
00285         /** EFI Itanium */
00286         DHCP_CLIENT_ARCHITECTURE_IA64 = 0x0002,
00287         /** DEC Alpha */
00288         DHCP_CLIENT_ARCHITECTURE_ALPHA = 0x0003,
00289         /** Arc x86 */
00290         DHCP_CLIENT_ARCHITECTURE_ARCX86 = 0x0004,
00291         /** Intel Lean Client */
00292         DHCP_CLIENT_ARCHITECTURE_LC = 0x0005,
00293         /** EFI IA32 */
00294         DHCP_CLIENT_ARCHITECTURE_IA32 = 0x0006,
00295         /** EFI x86-64 */
00296         DHCP_CLIENT_ARCHITECTURE_X86_64 = 0x0007,
00297         /** EFI Xscale */
00298         DHCP_CLIENT_ARCHITECTURE_XSCALE = 0x0008,
00299         /** EFI BC */
00300         DHCP_CLIENT_ARCHITECTURE_EFI = 0x0009,
00301         /** EFI 32-bit ARM */
00302         DHCP_CLIENT_ARCHITECTURE_ARM32 = 0x000a,
00303         /** EFI 64-bit ARM */
00304         DHCP_CLIENT_ARCHITECTURE_ARM64 = 0x000b,
00305 };
00306 
00307 /** Client network device interface */
00308 #define DHCP_CLIENT_NDI 94
00309 
00310 /** UUID client identifier */
00311 #define DHCP_CLIENT_UUID 97
00312 
00313 /** UUID client identifier */
00314 struct dhcp_client_uuid {
00315         /** Identifier type */
00316         uint8_t type;
00317         /** UUID */
00318         union uuid uuid;
00319 } __attribute__ (( packed ));
00320 
00321 #define DHCP_CLIENT_UUID_TYPE 0
00322 
00323 /** DNS domain search list */
00324 #define DHCP_DOMAIN_SEARCH 119
00325 
00326 /** Etherboot-specific encapsulated options
00327  *
00328  * This encapsulated options field is used to contain all options
00329  * specific to Etherboot (i.e. not assigned by IANA or other standards
00330  * bodies).
00331  */
00332 #define DHCP_EB_ENCAP 175
00333 
00334 /** Priority of this options block
00335  *
00336  * This is a signed 8-bit integer field indicating the priority of
00337  * this block of options.  It can be used to specify the relative
00338  * priority of multiple option blocks (e.g. options from non-volatile
00339  * storage versus options from a DHCP server).
00340  */
00341 #define DHCP_EB_PRIORITY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x01 )
00342 
00343 /** "Your" IP address
00344  *
00345  * This option is used internally to contain the value of the "yiaddr"
00346  * field, in order to provide a consistent approach to storing and
00347  * processing options.  It should never be present in a DHCP packet.
00348  */
00349 #define DHCP_EB_YIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x02 )
00350 
00351 /** "Server" IP address
00352  *
00353  * This option is used internally to contain the value of the "siaddr"
00354  * field, in order to provide a consistent approach to storing and
00355  * processing options.  It should never be present in a DHCP packet.
00356  */
00357 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x03 )
00358 
00359 /** Keep SAN drive registered
00360  *
00361  * If set to a non-zero value, iPXE will not detach any SAN drive
00362  * after failing to boot from it.  (This option is required in order
00363  * to perform an installation direct to an iSCSI target.)
00364  */
00365 #define DHCP_EB_KEEP_SAN DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x08 )
00366 
00367 /** Skip booting from SAN drive
00368  *
00369  * If set to a non-zero value, iPXE will skip booting from any SAN
00370  * drive.  (This option is sometimes required in conjunction with @c
00371  * DHCP_EB_KEEP_SAN in order to perform an installation direct to an
00372  * iSCSI target.)
00373  */
00374 #define DHCP_EB_SKIP_SAN_BOOT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x09 )
00375 
00376 /*
00377  * Tags in the range 0x10-0x4f are reserved for feature markers
00378  *
00379  */
00380 
00381 /** Scriptlet
00382  *
00383  * If a scriptlet exists, it will be executed in place of the usual
00384  * call to autoboot()
00385  */
00386 #define DHCP_EB_SCRIPTLET DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x51 )
00387 
00388 /** Encrypted syslog server */
00389 #define DHCP_EB_SYSLOGS_SERVER DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x55 )
00390 
00391 /** Trusted root certficate fingerprints */
00392 #define DHCP_EB_TRUST DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5a )
00393 
00394 /** Client certficate */
00395 #define DHCP_EB_CERT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5b )
00396 
00397 /** Client private key */
00398 #define DHCP_EB_KEY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5c )
00399 
00400 /** Cross-signed certificate source */
00401 #define DHCP_EB_CROSS_CERT DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5d )
00402 
00403 /** Skip PXE DHCP protocol extensions such as ProxyDHCP
00404  *
00405  * If set to a non-zero value, iPXE will not wait for ProxyDHCP offers
00406  * and will ignore any PXE-specific DHCP options that it receives.
00407  */
00408 #define DHCP_EB_NO_PXEDHCP DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
00409 
00410 /** Network device descriptor
00411  *
00412  * Byte 0 is the bus type ID; remaining bytes depend on the bus type.
00413  *
00414  * PCI devices:
00415  * Byte 0 : 1 (PCI)
00416  * Byte 1 : PCI vendor ID MSB
00417  * Byte 2 : PCI vendor ID LSB
00418  * Byte 3 : PCI device ID MSB
00419  * Byte 4 : PCI device ID LSB
00420  */
00421 #define DHCP_EB_BUS_ID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
00422 
00423 /** Network device descriptor */
00424 struct dhcp_netdev_desc {
00425         /** Bus type ID */
00426         uint8_t type;
00427         /** Vendor ID */
00428         uint16_t vendor;
00429         /** Device ID */
00430         uint16_t device;
00431 } __attribute__ (( packed ));
00432 
00433 /** Use cached network settings (obsolete; do not reuse this value) */
00434 #define DHCP_EB_USE_CACHED DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb2 )
00435 
00436 /** SAN retry count
00437  *
00438  * This is the maximum number of times that SAN operations will be
00439  * retried.
00440  */
00441 #define DHCP_EB_SAN_RETRY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbb )
00442 
00443 /** SAN filename
00444  *
00445  * This is the path of the bootloader within the SAN device.
00446  */
00447 #define DHCP_EB_SAN_FILENAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbc )
00448 
00449 /** SAN drive number
00450  *
00451  * This is the drive number for a SAN-hooked drive.  For BIOS, 0x80 is
00452  * the first hard disk, 0x81 is the second hard disk, etc.
00453  */
00454 #define DHCP_EB_SAN_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
00455 
00456 /** Username
00457  *
00458  * This will be used as the username for any required authentication.
00459  * It is expected that this option's value will be held in
00460  * non-volatile storage, rather than transmitted as part of a DHCP
00461  * packet.
00462  */
00463 #define DHCP_EB_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
00464 
00465 /** Password
00466  *
00467  * This will be used as the password for any required authentication.
00468  * It is expected that this option's value will be held in
00469  * non-volatile storage, rather than transmitted as part of a DHCP
00470  * packet.
00471  */
00472 #define DHCP_EB_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
00473 
00474 /** Reverse username
00475  *
00476  * This will be used as the reverse username (i.e. the username
00477  * provided by the server) for any required authentication.  It is
00478  * expected that this option's value will be held in non-volatile
00479  * storage, rather than transmitted as part of a DHCP packet.
00480  */
00481 #define DHCP_EB_REVERSE_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc0 )
00482 
00483 /** Reverse password
00484  *
00485  * This will be used as the reverse password (i.e. the password
00486  * provided by the server) for any required authentication.  It is
00487  * expected that this option's value will be held in non-volatile
00488  * storage, rather than transmitted as part of a DHCP packet.
00489  */
00490 #define DHCP_EB_REVERSE_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )
00491 
00492 /** User ID
00493  *
00494  * This will be used as the user id for AUTH_SYS based authentication in NFS.
00495  */
00496 #define DHCP_EB_UID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc2 )
00497 
00498 /** Group ID
00499  *
00500  * This will be used as the group id for AUTH_SYS based authentication in NFS.
00501  */
00502 #define DHCP_EB_GID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc3 )
00503 
00504 /** iPXE version number */
00505 #define DHCP_EB_VERSION DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )
00506 
00507 /** iSCSI primary target IQN */
00508 #define DHCP_ISCSI_PRIMARY_TARGET_IQN 201
00509 
00510 /** iSCSI secondary target IQN */
00511 #define DHCP_ISCSI_SECONDARY_TARGET_IQN 202
00512 
00513 /** iSCSI initiator IQN */
00514 #define DHCP_ISCSI_INITIATOR_IQN 203
00515 
00516 /** Maximum normal DHCP option */
00517 #define DHCP_MAX_OPTION 254
00518 
00519 /** End of options
00520  *
00521  * This tag does not have a length field; it is always only a single
00522  * byte in length.
00523  */
00524 #define DHCP_END 255
00525 
00526 /** @} */
00527 
00528 /** Construct a DHCP option from a list of bytes */
00529 #define DHCP_OPTION( ... ) VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
00530 
00531 /** Construct a DHCP option from a list of characters */
00532 #define DHCP_STRING( ... ) DHCP_OPTION ( __VA_ARGS__ )
00533 
00534 /** Construct a byte-valued DHCP option */
00535 #define DHCP_BYTE( value ) DHCP_OPTION ( value )
00536 
00537 /** Construct a word-valued DHCP option */
00538 #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ),   \
00539                                          ( ( (value) >> 0 ) & 0xff ) )
00540 
00541 /** Construct a dword-valued DHCP option */
00542 #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
00543                                           ( ( (value) >> 16 ) & 0xff ), \
00544                                           ( ( (value) >> 8  ) & 0xff ), \
00545                                           ( ( (value) >> 0  ) & 0xff ) )
00546 
00547 /** Construct a DHCP encapsulated options field */
00548 #define DHCP_ENCAP( ... ) DHCP_OPTION ( __VA_ARGS__, DHCP_END )
00549 
00550 /**
00551  * A DHCP option
00552  *
00553  * DHCP options consist of a mandatory tag, a length field that is
00554  * mandatory for all options except @c DHCP_PAD and @c DHCP_END, and a
00555  * payload.  
00556  */
00557 struct dhcp_option {
00558         /** Tag
00559          *
00560          * Must be a @c DHCP_XXX value.
00561          */
00562         uint8_t tag;
00563         /** Length
00564          *
00565          * This is the length of the data field (i.e. excluding the
00566          * tag and length fields).  For the two tags @c DHCP_PAD and
00567          * @c DHCP_END, the length field is implicitly zero and is
00568          * also missing, i.e. these DHCP options are only a single
00569          * byte in length.
00570          */
00571         uint8_t len;
00572         /** Option data */
00573         uint8_t data[0];
00574 } __attribute__ (( packed ));
00575 
00576 /**
00577  * Length of a DHCP option header
00578  *
00579  * The header is the portion excluding the data, i.e. the tag and the
00580  * length.
00581  */
00582 #define DHCP_OPTION_HEADER_LEN ( offsetof ( struct dhcp_option, data ) )
00583 
00584 /** Maximum length for a single DHCP option */
00585 #define DHCP_MAX_LEN 0xff
00586 
00587 /**
00588  * A DHCP header
00589  *
00590  */
00591 struct dhcphdr {
00592         /** Operation
00593          *
00594          * This must be either @c BOOTP_REQUEST or @c BOOTP_REPLY.
00595          */
00596         uint8_t op;
00597         /** Hardware address type
00598          *
00599          * This is an ARPHRD_XXX constant.  Note that ARPHRD_XXX
00600          * constants are nominally 16 bits wide; this could be
00601          * considered to be a bug in the BOOTP/DHCP specification.
00602          */
00603         uint8_t htype;
00604         /** Hardware address length */
00605         uint8_t hlen;
00606         /** Number of hops from server */
00607         uint8_t hops;
00608         /** Transaction ID */
00609         uint32_t xid;
00610         /** Seconds since start of acquisition */
00611         uint16_t secs;
00612         /** Flags */
00613         uint16_t flags;
00614         /** "Client" IP address
00615          *
00616          * This is filled in if the client already has an IP address
00617          * assigned and can respond to ARP requests.
00618          */
00619         struct in_addr ciaddr;
00620         /** "Your" IP address
00621          *
00622          * This is the IP address assigned by the server to the client.
00623          */
00624         struct in_addr yiaddr;
00625         /** "Server" IP address
00626          *
00627          * This is the IP address of the next server to be used in the
00628          * boot process.
00629          */
00630         struct in_addr siaddr;
00631         /** "Gateway" IP address
00632          *
00633          * This is the IP address of the DHCP relay agent, if any.
00634          */
00635         struct in_addr giaddr;
00636         /** Client hardware address */
00637         uint8_t chaddr[16];
00638         /** Server host name (null terminated)
00639          *
00640          * This field may be overridden and contain DHCP options
00641          */
00642         char sname[64];
00643         /** Boot file name (null terminated)
00644          *
00645          * This field may be overridden and contain DHCP options
00646          */
00647         char file[128];
00648         /** DHCP magic cookie
00649          *
00650          * Must have the value @c DHCP_MAGIC_COOKIE.
00651          */
00652         uint32_t magic;
00653         /** DHCP options
00654          *
00655          * Variable length; extends to the end of the packet.  Minimum
00656          * length (for the sake of sanity) is 1, to allow for a single
00657          * @c DHCP_END tag.
00658          */
00659         uint8_t options[0];
00660 };
00661 
00662 /** Opcode for a request from client to server */
00663 #define BOOTP_REQUEST 1
00664 
00665 /** Opcode for a reply from server to client */
00666 #define BOOTP_REPLY 2
00667 
00668 /** BOOTP reply must be broadcast
00669  *
00670  * Clients that cannot accept unicast BOOTP replies must set this
00671  * flag.
00672  */
00673 #define BOOTP_FL_BROADCAST 0x8000
00674 
00675 /** DHCP magic cookie */
00676 #define DHCP_MAGIC_COOKIE 0x63825363UL
00677 
00678 /** DHCP minimum packet length
00679  *
00680  * This is the mandated minimum packet length that a DHCP participant
00681  * must be prepared to receive.
00682  */
00683 #define DHCP_MIN_LEN 552
00684 
00685 /** Settings block name used for DHCP responses */
00686 #define DHCP_SETTINGS_NAME "dhcp"
00687 
00688 /** Settings block name used for ProxyDHCP responses */
00689 #define PROXYDHCP_SETTINGS_NAME "proxydhcp"
00690 
00691 /** Setting block name used for BootServerDHCP responses */
00692 #define PXEBS_SETTINGS_NAME "pxebs"
00693 
00694 extern uint32_t dhcp_last_xid;
00695 extern int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
00696                                 struct net_device *netdev, uint8_t msgtype,
00697                                 uint32_t xid, const void *options,
00698                                 size_t options_len, void *data,
00699                                 size_t max_len );
00700 extern int dhcp_create_request ( struct dhcp_packet *dhcppkt,
00701                                  struct net_device *netdev,
00702                                  unsigned int msgtype, uint32_t xid,
00703                                  struct in_addr ciaddr,
00704                                  void *data, size_t max_len );
00705 extern int start_dhcp ( struct interface *job, struct net_device *netdev );
00706 extern int start_pxebs ( struct interface *job, struct net_device *netdev,
00707                          unsigned int pxe_type );
00708 
00709 #endif /* _IPXE_DHCP_H */