00001 #ifndef _GPXE_DHCP_H
00002 #define _GPXE_DHCP_H
00003
00004
00005
00006
00007
00008
00009
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011
00012 #include <stdint.h>
00013 #include <gpxe/in.h>
00014 #include <gpxe/list.h>
00015 #include <gpxe/refcnt.h>
00016 #include <gpxe/tables.h>
00017 #include <gpxe/uuid.h>
00018 #include <gpxe/netdevice.h>
00019 #include <gpxe/uaccess.h>
00020
00021 struct job_interface;
00022 struct dhcp_options;
00023 struct dhcp_packet;
00024
00025
00026 #define BOOTPS_PORT 67
00027
00028
00029 #define BOOTPC_PORT 68
00030
00031
00032 #define PXE_PORT 4011
00033
00034
00035
00036
00037
00038
00039
00040 #define DHCP_ENCAP_OPT( encapsulator, encapsulated ) \
00041 ( ( (encapsulator) << 8 ) | (encapsulated) )
00042
00043 #define DHCP_ENCAPSULATOR( encap_opt ) ( (encap_opt) >> 8 )
00044
00045 #define DHCP_ENCAPSULATED( encap_opt ) ( (encap_opt) & 0xff )
00046
00047 #define DHCP_IS_ENCAP_OPT( opt ) DHCP_ENCAPSULATOR( opt )
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #define DHCP_PAD 0
00060
00061
00062 #define DHCP_MIN_OPTION 1
00063
00064
00065 #define DHCP_SUBNET_MASK 1
00066
00067
00068 #define DHCP_ROUTERS 3
00069
00070
00071 #define DHCP_DNS_SERVERS 6
00072
00073
00074 #define DHCP_LOG_SERVERS 7
00075
00076
00077 #define DHCP_HOST_NAME 12
00078
00079
00080 #define DHCP_DOMAIN_NAME 15
00081
00082
00083 #define DHCP_ROOT_PATH 17
00084
00085
00086 #define DHCP_VENDOR_ENCAP 43
00087
00088
00089 #define DHCP_PXE_DISCOVERY_CONTROL DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 6 )
00090
00091
00092 enum dhcp_pxe_discovery_control {
00093
00094 PXEBS_NO_BROADCAST = 1,
00095
00096 PXEBS_NO_MULTICAST = 2,
00097
00098 PXEBS_NO_UNKNOWN_SERVERS = 4,
00099
00100 PXEBS_SKIP = 8,
00101 };
00102
00103
00104 #define DHCP_PXE_BOOT_SERVER_MCAST DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 7 )
00105
00106
00107 #define DHCP_PXE_BOOT_SERVERS DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 8 )
00108
00109
00110 struct dhcp_pxe_boot_server {
00111
00112 uint16_t type;
00113
00114 uint8_t num_ip;
00115
00116 struct in_addr ip[0];
00117 } __attribute__ (( packed ));
00118
00119
00120 #define DHCP_PXE_BOOT_MENU DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 9 )
00121
00122
00123 struct dhcp_pxe_boot_menu {
00124
00125 uint16_t type;
00126
00127 uint8_t desc_len;
00128
00129 char desc[0];
00130 } __attribute__ (( packed ));
00131
00132
00133 #define DHCP_PXE_BOOT_MENU_PROMPT DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 10 )
00134
00135
00136 struct dhcp_pxe_boot_menu_prompt {
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 uint8_t timeout;
00147
00148 char prompt[0];
00149 } __attribute__ (( packed ));
00150
00151
00152 #define DHCP_PXE_BOOT_MENU_ITEM DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 71 )
00153
00154
00155 struct dhcp_pxe_boot_menu_item {
00156
00157
00158
00159
00160
00161 uint16_t type;
00162
00163
00164
00165
00166 uint16_t layer;
00167 } __attribute__ (( packed ));
00168
00169
00170 #define DHCP_REQUESTED_ADDRESS 50
00171
00172
00173 #define DHCP_LEASE_TIME 51
00174
00175
00176
00177
00178
00179
00180 #define DHCP_OPTION_OVERLOAD 52
00181
00182
00183 #define DHCP_OPTION_OVERLOAD_FILE 1
00184
00185
00186 #define DHCP_OPTION_OVERLOAD_SNAME 2
00187
00188
00189 #define DHCP_MESSAGE_TYPE 53
00190 #define DHCPNONE 0
00191 #define DHCPDISCOVER 1
00192 #define DHCPOFFER 2
00193 #define DHCPREQUEST 3
00194 #define DHCPDECLINE 4
00195 #define DHCPACK 5
00196 #define DHCPNAK 6
00197 #define DHCPRELEASE 7
00198 #define DHCPINFORM 8
00199
00200
00201 #define DHCP_SERVER_IDENTIFIER 54
00202
00203
00204 #define DHCP_PARAMETER_REQUEST_LIST 55
00205
00206
00207 #define DHCP_MAX_MESSAGE_SIZE 57
00208
00209
00210 #define DHCP_VENDOR_CLASS_ID 60
00211
00212
00213 #define DHCP_CLIENT_ID 61
00214
00215
00216 struct dhcp_client_id {
00217
00218 uint8_t ll_proto;
00219
00220 uint8_t ll_addr[MAX_LL_ADDR_LEN];
00221 } __attribute__ (( packed ));
00222
00223
00224
00225
00226
00227
00228 #define DHCP_TFTP_SERVER_NAME 66
00229
00230
00231
00232
00233
00234
00235 #define DHCP_BOOTFILE_NAME 67
00236
00237
00238 #define DHCP_USER_CLASS_ID 77
00239
00240
00241 #define DHCP_CLIENT_ARCHITECTURE 93
00242
00243
00244 #define DHCP_CLIENT_NDI 94
00245
00246
00247 #define DHCP_CLIENT_UUID 97
00248
00249
00250 struct dhcp_client_uuid {
00251
00252 uint8_t type;
00253
00254 union uuid uuid;
00255 } __attribute__ (( packed ));
00256
00257 #define DHCP_CLIENT_UUID_TYPE 0
00258
00259
00260
00261
00262
00263
00264
00265 #define DHCP_EB_ENCAP 175
00266
00267
00268
00269
00270
00271
00272
00273
00274 #define DHCP_EB_PRIORITY DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x01 )
00275
00276
00277
00278
00279
00280
00281
00282 #define DHCP_EB_YIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x02 )
00283
00284
00285
00286
00287
00288
00289
00290 #define DHCP_EB_SIADDR DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x03 )
00291
00292
00293
00294
00295
00296
00297
00298
00299 #define DHCP_EB_KEEP_SAN DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x08 )
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 #define DHCP_EB_NO_PXEDHCP DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 #define DHCP_EB_BUS_ID DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
00325
00326
00327 struct dhcp_netdev_desc {
00328
00329 uint8_t type;
00330
00331 uint16_t vendor;
00332
00333 uint16_t device;
00334 } __attribute__ (( packed ));
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 #define DHCP_EB_USE_CACHED DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb2 )
00345
00346
00347
00348
00349
00350
00351 #define DHCP_EB_BIOS_DRIVE DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
00352
00353
00354
00355
00356
00357
00358
00359
00360 #define DHCP_EB_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
00361
00362
00363
00364
00365
00366
00367
00368
00369 #define DHCP_EB_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
00370
00371
00372
00373
00374
00375
00376
00377
00378 #define DHCP_EB_REVERSE_USERNAME DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc0 )
00379
00380
00381
00382
00383
00384
00385
00386
00387 #define DHCP_EB_REVERSE_PASSWORD DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )
00388
00389
00390 #define DHCP_EB_VERSION DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )
00391
00392
00393 #define DHCP_ISCSI_PRIMARY_TARGET_IQN 201
00394
00395
00396 #define DHCP_ISCSI_SECONDARY_TARGET_IQN 202
00397
00398
00399 #define DHCP_ISCSI_INITIATOR_IQN 203
00400
00401
00402 #define DHCP_MAX_OPTION 254
00403
00404
00405
00406
00407
00408
00409 #define DHCP_END 255
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 #define _VA_ARG_COUNT( _1, _2, _3, _4, _5, _6, _7, _8, \
00421 _9, _10, _11, _12, _13, _14, _15, _16, \
00422 _17, _18, _19, _20, _21, _22, _23, _24, \
00423 _25, _26, _27, _28, _29, _30, _31, _32, \
00424 _33, _34, _35, _36, _37, _38, _39, _40, \
00425 _41, _42, _43, _44, _45, _46, _47, _48, \
00426 _49, _50, _51, _52, _53, _54, _55, _56, \
00427 _57, _58, _59, _60, _61, _62, _63, N, ... ) N
00428 #define VA_ARG_COUNT( ... ) \
00429 _VA_ARG_COUNT ( __VA_ARGS__, \
00430 63, 62, 61, 60, 59, 58, 57, 56, \
00431 55, 54, 53, 52, 51, 50, 49, 48, \
00432 47, 46, 45, 44, 43, 42, 41, 40, \
00433 39, 38, 37, 36, 35, 34, 33, 32, \
00434 31, 30, 29, 28, 27, 26, 25, 24, \
00435 23, 22, 21, 20, 19, 18, 17, 16, \
00436 15, 14, 13, 12, 11, 10, 9, 8, \
00437 7, 6, 5, 4, 3, 2, 1, 0 )
00438
00439
00440 #define DHCP_OPTION( ... ) VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
00441
00442
00443 #define DHCP_STRING( ... ) DHCP_OPTION ( __VA_ARGS__ )
00444
00445
00446 #define DHCP_BYTE( value ) DHCP_OPTION ( value )
00447
00448
00449 #define DHCP_WORD( value ) DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
00450 ( ( (value) >> 0 ) & 0xff ) )
00451
00452
00453 #define DHCP_DWORD( value ) DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
00454 ( ( (value) >> 16 ) & 0xff ), \
00455 ( ( (value) >> 8 ) & 0xff ), \
00456 ( ( (value) >> 0 ) & 0xff ) )
00457
00458
00459 #define DHCP_ENCAP( ... ) DHCP_OPTION ( __VA_ARGS__, DHCP_END )
00460
00461
00462
00463
00464
00465
00466
00467
00468 struct dhcp_option {
00469
00470
00471
00472
00473 uint8_t tag;
00474
00475
00476
00477
00478
00479
00480
00481
00482 uint8_t len;
00483
00484 uint8_t data[0];
00485 } __attribute__ (( packed ));
00486
00487
00488
00489
00490
00491
00492
00493 #define DHCP_OPTION_HEADER_LEN ( offsetof ( struct dhcp_option, data ) )
00494
00495
00496 #define DHCP_MAX_LEN 0xff
00497
00498
00499
00500
00501
00502 struct dhcphdr {
00503
00504
00505
00506
00507 uint8_t op;
00508
00509
00510
00511
00512
00513
00514 uint8_t htype;
00515
00516 uint8_t hlen;
00517
00518 uint8_t hops;
00519
00520 uint32_t xid;
00521
00522 uint16_t secs;
00523
00524 uint16_t flags;
00525
00526
00527
00528
00529
00530 struct in_addr ciaddr;
00531
00532
00533
00534
00535 struct in_addr yiaddr;
00536
00537
00538
00539
00540
00541 struct in_addr siaddr;
00542
00543
00544
00545
00546 struct in_addr giaddr;
00547
00548 uint8_t chaddr[16];
00549
00550
00551
00552
00553 char sname[64];
00554
00555
00556
00557
00558 char file[128];
00559
00560
00561
00562
00563 uint32_t magic;
00564
00565
00566
00567
00568
00569
00570 uint8_t options[0];
00571 };
00572
00573
00574 #define BOOTP_REQUEST 1
00575
00576
00577 #define BOOTP_REPLY 2
00578
00579
00580
00581
00582
00583
00584 #define BOOTP_FL_BROADCAST 0x8000
00585
00586
00587 #define DHCP_MAGIC_COOKIE 0x63825363UL
00588
00589
00590
00591
00592
00593
00594 #define DHCP_MIN_LEN 552
00595
00596
00597 #define DHCP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
00598 #define DHCP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
00599
00600
00601 #define PROXYDHCP_MAX_TIMEOUT ( 2 * TICKS_PER_SEC )
00602
00603
00604 #define PXEBS_MAX_TIMEOUT ( 3 * TICKS_PER_SEC )
00605
00606
00607 #define DHCP_SETTINGS_NAME "dhcp"
00608
00609
00610 #define PROXYDHCP_SETTINGS_NAME "proxydhcp"
00611
00612
00613 #define PXEBS_SETTINGS_NAME "pxebs"
00614
00615 extern void * dhcp_chaddr ( struct net_device *netdev, uint8_t *hlen,
00616 uint16_t *flags );
00617 extern int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
00618 struct net_device *netdev, uint8_t msgtype,
00619 const void *options, size_t options_len,
00620 void *data, size_t max_len );
00621 extern int dhcp_create_request ( struct dhcp_packet *dhcppkt,
00622 struct net_device *netdev,
00623 unsigned int msgtype, struct in_addr ciaddr,
00624 void *data, size_t max_len );
00625 extern int start_dhcp ( struct job_interface *job, struct net_device *netdev );
00626 extern int start_pxebs ( struct job_interface *job, struct net_device *netdev,
00627 unsigned int pxe_type );
00628
00629
00630
00631
00632
00633 __weak_decl ( void, get_cached_dhcpack, ( void ), (), );
00634
00635 extern void store_cached_dhcpack ( userptr_t data, size_t len );
00636
00637 #endif