Leaked source code of windows server 2003
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.

587 lines
17 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dhcp.h
  5. Abstract:
  6. This module defines the DHCP server service definitions and structures.
  7. Author:
  8. Manny Weiser (mannyw) 11-Aug-1992
  9. Revision History:
  10. Madan Appiah (madana) 10-Oct-1993
  11. --*/
  12. #ifndef _DHCP_
  13. #define _DHCP_
  14. #ifdef __cplusplus
  15. extern "C"{
  16. #endif
  17. #define WS_VERSION_REQUIRED MAKEWORD( 1, 1)
  18. //
  19. // update dhcpapi.h also if you modify the following three typedefs.
  20. //
  21. typedef DWORD DHCP_IP_ADDRESS, *PDHCP_IP_ADDRESS, *LPDHCP_IP_ADDRESS;
  22. typedef DWORD DHCP_OPTION_ID;
  23. typedef struct _DATE_TIME {
  24. DWORD dwLowDateTime;
  25. DWORD dwHighDateTime;
  26. } DATE_TIME, *PDATE_TIME, *LPDATE_TIME;
  27. #define DHCP_DATE_TIME_ZERO_HIGH 0
  28. #define DHCP_DATE_TIME_ZERO_LOW 0
  29. #define DHCP_DATE_TIME_INFINIT_HIGH 0x7FFFFFFF
  30. #define DHCP_DATE_TIME_INFINIT_LOW 0xFFFFFFFF
  31. #define DOT_IP_ADDR_SIZE 16 // XXX.XXX.XXX.XXX + '\0'
  32. #define NO_DHCP_IP_ADDRESS ((DHCP_IP_ADDRESS)-1)
  33. #define DHCP_IP_KEY_LEN 32 //arbitary size.
  34. #define INFINIT_TIME MAXINT_PTR // time_t is int_ptr
  35. #define INFINIT_LEASE 0xFFFFFFFF // in secs. (unsigned int.)
  36. // MDHCP server well known address. Relative "1" assignment in IPv4 local scope.
  37. /* FROM RFC 2365
  38. The high order /24 in every scoped region is reserved for relative
  39. assignments. A relative assignment is an integer offset from highest
  40. address in the scope and represents a 32-bit address (for IPv4). For
  41. example, in the Local Scope defined above, 239.255.255.0/24 is
  42. reserved for relative allocations. The de-facto relative assignment
  43. "0", (i.e., 239.255.255.255 in the Local Scope) currently exists for
  44. SAP [SAP]. The next relative assignment, "1", corresponds to the
  45. address 239.255.255.254 in the Local Scope. The rest of a scoped
  46. region below the reserved /24 is available for dynamic assignment
  47. (presumably by an address allocation protocol).
  48. */
  49. #define MADCAP_SERVER_IP_ADDRESS 0xfeffffef // 239.255.255.254
  50. //
  51. // hardware types.
  52. //
  53. #define HARDWARE_TYPE_NONE 0 // used for non-hardware type client id
  54. #define HARDWARE_TYPE_10MB_EITHERNET 1
  55. #define HARDWARE_TYPE_IEEE_802 6
  56. #define HARDWARE_ARCNET 7
  57. #define HARDWARE_PPP 8
  58. #define HARDWARE_1394 24
  59. //
  60. // Client-server protoocol reserved ports
  61. //
  62. #define DHCP_CLIENT_PORT 68
  63. #define DHCP_SERVR_PORT 67
  64. #define MADCAP_SERVER_PORT 2535
  65. //
  66. // DHCP BROADCAST flag.
  67. //
  68. #define DHCP_BROADCAST 0x8000
  69. #define DHCP_NO_BROADCAST 0x0000
  70. // MDHCP flag
  71. #define DHCP_MBIT 0x4000
  72. #define IS_MDHCP_MESSAGE( _msg ) ( ntohs((_msg)->Reserved) & DHCP_MBIT ? TRUE : FALSE )
  73. #define MDHCP_MESSAGE( _msg ) ( (_msg)->Reserved |= htons(DHCP_MBIT) )
  74. #define CLASSD_NET_ADDR(a) ((a & 0xf0) == 0xe0)
  75. #define CLASSD_HOST_ADDR(a) ((a & 0xf0000000) == 0xe0000000)
  76. #define CLASSE_HOST_ADDR(a) ((a & 0xf0000000) == 0xf0000000)
  77. #define CLASSE_NET_ADDR(a) ((a & 0xf0) == 0xf0)
  78. #define DHCP_MESSAGE_SIZE 576
  79. #define DHCP_RECV_MESSAGE_SIZE 4096
  80. #define DHCP_SEND_MESSAGE_SIZE 4096
  81. #define BOOTP_MESSAGE_SIZE 300 // the options field for bootp is 64 bytes.
  82. //
  83. // The amount of time to wait for a DHCP response after a request
  84. // has been sent.
  85. //
  86. #if !DBG
  87. #define WAIT_FOR_RESPONSE_TIME 5
  88. #else
  89. #define WAIT_FOR_RESPONSE_TIME 10
  90. #endif
  91. //
  92. // DHCP Operations
  93. //
  94. #define BOOT_REQUEST 1
  95. #define BOOT_REPLY 2
  96. //
  97. // DHCP Standard Options.
  98. //
  99. #define OPTION_PAD 0
  100. #define OPTION_SUBNET_MASK 1
  101. #define OPTION_TIME_OFFSET 2
  102. #define OPTION_ROUTER_ADDRESS 3
  103. #define OPTION_TIME_SERVERS 4
  104. #define OPTION_IEN116_NAME_SERVERS 5
  105. #define OPTION_DOMAIN_NAME_SERVERS 6
  106. #define OPTION_LOG_SERVERS 7
  107. #define OPTION_COOKIE_SERVERS 8
  108. #define OPTION_LPR_SERVERS 9
  109. #define OPTION_IMPRESS_SERVERS 10
  110. #define OPTION_RLP_SERVERS 11
  111. #define OPTION_HOST_NAME 12
  112. #define OPTION_BOOT_FILE_SIZE 13
  113. #define OPTION_MERIT_DUMP_FILE 14
  114. #define OPTION_DOMAIN_NAME 15
  115. #define OPTION_SWAP_SERVER 16
  116. #define OPTION_ROOT_DISK 17
  117. #define OPTION_EXTENSIONS_PATH 18
  118. //
  119. // IP layer parameters - per host
  120. //
  121. #define OPTION_BE_A_ROUTER 19
  122. #define OPTION_NON_LOCAL_SOURCE_ROUTING 20
  123. #define OPTION_POLICY_FILTER_FOR_NLSR 21
  124. #define OPTION_MAX_REASSEMBLY_SIZE 22
  125. #define OPTION_DEFAULT_TTL 23
  126. #define OPTION_PMTU_AGING_TIMEOUT 24
  127. #define OPTION_PMTU_PLATEAU_TABLE 25
  128. //
  129. // Link layer parameters - per interface.
  130. //
  131. #define OPTION_MTU 26
  132. #define OPTION_ALL_SUBNETS_MTU 27
  133. #define OPTION_BROADCAST_ADDRESS 28
  134. #define OPTION_PERFORM_MASK_DISCOVERY 29
  135. #define OPTION_BE_A_MASK_SUPPLIER 30
  136. #define OPTION_PERFORM_ROUTER_DISCOVERY 31
  137. #define OPTION_ROUTER_SOLICITATION_ADDR 32
  138. #define OPTION_STATIC_ROUTES 33
  139. #define OPTION_TRAILERS 34
  140. #define OPTION_ARP_CACHE_TIMEOUT 35
  141. #define OPTION_ETHERNET_ENCAPSULATION 36
  142. //
  143. // TCP Paramters - per host
  144. //
  145. #define OPTION_TTL 37
  146. #define OPTION_KEEP_ALIVE_INTERVAL 38
  147. #define OPTION_KEEP_ALIVE_DATA_SIZE 39
  148. //
  149. // Application Layer Parameters
  150. //
  151. #define OPTION_NETWORK_INFO_SERVICE_DOM 40
  152. #define OPTION_NETWORK_INFO_SERVERS 41
  153. #define OPTION_NETWORK_TIME_SERVERS 42
  154. //
  155. // Vender specific information option
  156. //
  157. #define OPTION_VENDOR_SPEC_INFO 43
  158. //
  159. // NetBIOS over TCP/IP Name server option
  160. //
  161. #define OPTION_NETBIOS_NAME_SERVER 44
  162. #define OPTION_NETBIOS_DATAGRAM_SERVER 45
  163. #define OPTION_NETBIOS_NODE_TYPE 46
  164. #define OPTION_NETBIOS_SCOPE_OPTION 47
  165. //
  166. // X Window System Options.
  167. //
  168. #define OPTION_XWINDOW_FONT_SERVER 48
  169. #define OPTION_XWINDOW_DISPLAY_MANAGER 49
  170. //
  171. // Other extensions
  172. //
  173. #define OPTION_REQUESTED_ADDRESS 50
  174. #define OPTION_LEASE_TIME 51
  175. #define OPTION_OK_TO_OVERLAY 52
  176. #define OPTION_MESSAGE_TYPE 53
  177. #define OPTION_SERVER_IDENTIFIER 54
  178. #define OPTION_PARAMETER_REQUEST_LIST 55
  179. #define OPTION_MESSAGE 56
  180. #define OPTION_MESSAGE_LENGTH 57
  181. #define OPTION_RENEWAL_TIME 58 // T1
  182. #define OPTION_REBIND_TIME 59 // T2
  183. #define OPTION_CLIENT_CLASS_INFO 60
  184. #define OPTION_CLIENT_ID 61
  185. #define OPTION_TFTP_SERVER_NAME 66
  186. #define OPTION_BOOTFILE_NAME 67
  187. //
  188. // user class id
  189. //
  190. #define OPTION_USER_CLASS 77
  191. //
  192. // Dynamic DNS Stuff. Tells if we should do both A+PTR updates?
  193. //
  194. #define OPTION_DYNDNS_BOTH 81
  195. //
  196. // used by binl
  197. //
  198. #define OPTION_NETWORK_INTERFACE_TYPE 91
  199. #define OPTION_SYSTEM_ARCHITECTURE 93
  200. #define OPTION_CLIENT_GUID 97
  201. // Multicast options.
  202. #define OPTION_MCAST_SCOPE_ID 101
  203. #define OPTION_MCAST_LEASE_START 102
  204. #define OPTION_MCAST_TTL 103
  205. #define OPTION_CLIENT_PORT 105
  206. #define OPTION_MCAST_SCOPE_LIST 107
  207. // disable autoconfiguration
  208. #define OPTION_IETF_AUTOCONF 116
  209. // special option to extend options
  210. #define OPTION_LARGE_OPTION 127
  211. #define OPTION_CLASSLESS_ROUTES 249
  212. #define OPTION_END 255
  213. // MADCAP OPTIONS
  214. #define MADCAP_OPTION_END 0
  215. #define MADCAP_OPTION_LEASE_TIME 1
  216. #define MADCAP_OPTION_SERVER_ID 2
  217. #define MADCAP_OPTION_LEASE_ID 3
  218. #define MADCAP_OPTION_MCAST_SCOPE 4
  219. #define MADCAP_OPTION_REQUEST_LIST 5
  220. #define MADCAP_OPTION_START_TIME 6
  221. #define MADCAP_OPTION_ADDR_COUNT 7
  222. #define MADCAP_OPTION_REQUESTED_LANG 8
  223. #define MADCAP_OPTION_MCAST_SCOPE_LIST 9
  224. #define MADCAP_OPTION_ADDR_LIST 10
  225. #define MADCAP_OPTION_TIME 11
  226. #define MADCAP_OPTION_FEATURE_LIST 12
  227. #define MADCAP_OPTION_RETRY_TIME 13
  228. #define MADCAP_OPTION_MIN_LEASE_TIME 14
  229. #define MADCAP_OPTION_MAX_START_TIME 15
  230. #define MADCAP_OPTION_ERROR 16
  231. // update the total whenever changes
  232. #define MADCAP_OPTION_TOTAL 17
  233. #define MADCAP_OPTION_NONE 0xffff
  234. // MADCAP error option codes
  235. #define MADCAP_NAK_REQ_NOT_COMPLETED 0
  236. #define MADCAP_NAK_INVALID_REQ 1
  237. #define MADCAP_NAK_CLOCK_SKEW 2
  238. #define MADCAP_NAK_INVALID_LEASE_ID 3
  239. #define MADCAP_NAK_UNSUPPORTED_FEATURE 4
  240. //
  241. // MADCAP Message types
  242. //
  243. #define MADCAP_DISCOVER_MESSAGE 1
  244. #define MADCAP_OFFER_MESSAGE 2
  245. #define MADCAP_REQUEST_MESSAGE 3
  246. #define MADCAP_RENEW_MESSAGE 4
  247. #define MADCAP_ACK_MESSAGE 5
  248. #define MADCAP_NACK_MESSAGE 6
  249. #define MADCAP_RELEASE_MESSAGE 7
  250. #define MADCAP_INFORM_MESSAGE 8
  251. // update the total when above changes
  252. #define MADCAP_TOTAL_MESSAGE 9
  253. // MADCAP version constants
  254. #define MADCAP_VERSION 0
  255. enum {
  256. MADCAP_ADDR_FAMILY_V4 = 1,
  257. MADCAP_ADDR_FAMILY_V6
  258. };
  259. // The following definations specify how the options are
  260. // formatted based on different versions and protocols
  261. enum {
  262. PROTO_DHCP,
  263. PROTO_MADCAP_V4,
  264. PROTO_MADCAP_V6
  265. };
  266. typedef struct _OPTION_VERSION {
  267. WORD Proto;
  268. WORD Version;
  269. } OPTION_VERSION, *POPTION_VERSION;
  270. #define OPT_VER_DHCP {PROTO_DHCP, 1 }
  271. #define OPT_VER_MADCAP_V4 {PROTO_MADCAP_V4, 0 }
  272. #define OPT_VER_MADCAP_V6 {PROTO_MADCAP_V6, 0 }
  273. // default mcast_ttl value.
  274. #define DEFAULT_MCAST_TTL 32
  275. //
  276. // Different option values for the DYNDNS_BOTH option ...
  277. //
  278. #define DYNDNS_S_BIT 0x01
  279. #define DYNDNS_O_BIT 0x02
  280. #define DYNDNS_E_BIT 0x04
  281. #define IS_CLIENT_DOING_A_AND_PTR(X) (((X)&DYNDNS_S_BIT)== 0)
  282. #define DYNDNS_REGISTER_AT_CLIENT 0 // Client will do both registrations
  283. #define DYNDNS_REGISTER_AT_SERVER 1 // Server will do registrations
  284. #define DYNDNS_DOWNLEVEL_CLIENT 0xFFFF// arbitraty # diff from above
  285. //
  286. // Microsoft-specific options
  287. //
  288. #define OPTION_MSFT_DSDOMAINNAME_REQ 94 // send me your DS Domain name
  289. #define OPTION_MSFT_DSDOMAINNAME_RESP 95 // sending my DS Domain name
  290. #define OPTION_MSFT_CONTINUED 250 // the previous option is being continued..
  291. #define OPTION_MSFT_AUTOCONF 251 // enable disable autoconf
  292. #define OPTION_MSFT_IE_PROXY 252 // IE5 proxy <string type>
  293. #define OPTION_MSFT_SERVER_APPL 253 // has a struct.
  294. #define OPTION_MSFT_VENDOR_NETBIOSLESS 1 // vendor option # 1
  295. #define OPTION_MSFT_VENDOR_FEATURELIST 2 // vendor option # 2
  296. #define BIT_RELEASE_ON_SHUTDOWN 0x01 // release on shutdown bit in feature list
  297. #define OPTION_MSFT_VENDOR_METRIC_BASE 3 // default gateway base metric.
  298. #define AUTOCONF_ENABLED 1
  299. #define AUTOCONF_DISABLED 0
  300. //
  301. // DHCP Message types
  302. //
  303. #define DHCP_DISCOVER_MESSAGE 1
  304. #define DHCP_OFFER_MESSAGE 2
  305. #define DHCP_REQUEST_MESSAGE 3
  306. #define DHCP_DECLINE_MESSAGE 4
  307. #define DHCP_ACK_MESSAGE 5
  308. #define DHCP_NACK_MESSAGE 6
  309. #define DHCP_RELEASE_MESSAGE 7
  310. #define DHCP_INFORM_MESSAGE 8
  311. #define DHCP_MAGIC_COOKIE_BYTE1 99
  312. #define DHCP_MAGIC_COOKIE_BYTE2 130
  313. #define DHCP_MAGIC_COOKIE_BYTE3 83
  314. #define DHCP_MAGIC_COOKIE_BYTE4 99
  315. #define BOOT_FILE_SIZE 128
  316. #define BOOT_SERVER_SIZE 64
  317. #define BOOT_FILE_SIZE_W ( BOOT_FILE_SIZE * sizeof( WCHAR ))
  318. #define BOOT_SERVER_SIZE_W ( BOOT_SERVER_SIZE * sizeof( WCHAR ))
  319. //
  320. // DHCP APP names - used to indentify to the eventlogger.
  321. //
  322. #define DHCP_EVENT_CLIENT TEXT("Dhcp")
  323. #define DHCP_EVENT_SERVER TEXT("DhcpServer")
  324. typedef struct _OPTION {
  325. BYTE OptionType;
  326. BYTE OptionLength;
  327. BYTE OptionValue[1];
  328. } OPTION, *POPTION, *LPOPTION;
  329. typedef struct _WIDE_OPTION {
  330. WORD OptionType;
  331. WORD OptionLength;
  332. BYTE OptionValue[1];
  333. } WIDE_OPTION, *PWIDE_OPTION, *LPWIDE_OPTION;
  334. //
  335. // A DHCP message buffer
  336. //
  337. #pragma pack(1) /* Assume byte packing */
  338. typedef struct _DHCP_MESSAGE {
  339. BYTE Operation;
  340. BYTE HardwareAddressType;
  341. BYTE HardwareAddressLength;
  342. BYTE HopCount;
  343. DWORD TransactionID;
  344. WORD SecondsSinceBoot;
  345. WORD Reserved;
  346. DHCP_IP_ADDRESS ClientIpAddress;
  347. DHCP_IP_ADDRESS YourIpAddress;
  348. DHCP_IP_ADDRESS BootstrapServerAddress;
  349. DHCP_IP_ADDRESS RelayAgentIpAddress;
  350. BYTE HardwareAddress[16];
  351. BYTE HostName[ BOOT_SERVER_SIZE ];
  352. BYTE BootFileName[BOOT_FILE_SIZE];
  353. OPTION Option;
  354. } DHCP_MESSAGE, *PDHCP_MESSAGE, *LPDHCP_MESSAGE;
  355. typedef struct _MADCAP_MESSAGE {
  356. BYTE Version;
  357. BYTE MessageType;
  358. WORD AddressFamily;
  359. DWORD TransactionID;
  360. // DHCP_IP_ADDRESS ClientIpAddress;
  361. // DHCP_IP_ADDRESS YourIpAddress;
  362. WIDE_OPTION Option;
  363. } MADCAP_MESSAGE, *PMADCAP_MESSAGE, *LPMADCAP_MESSAGE;
  364. #pragma pack()
  365. #define DHCP_MESSAGE_FIXED_PART_SIZE \
  366. (sizeof(DHCP_MESSAGE) - sizeof(OPTION))
  367. #define MADCAP_MESSAGE_FIXED_PART_SIZE \
  368. (sizeof(MADCAP_MESSAGE) - sizeof (WIDE_OPTION))
  369. #define DHCP_MIN_SEND_RECV_PK_SIZE \
  370. (DHCP_MESSAGE_FIXED_PART_SIZE + 64)
  371. //
  372. // Per message structure... Most of the structures here point within the
  373. // message.
  374. typedef struct _DHCP_SERVER_OPTIONS {
  375. BYTE *MessageType;
  376. DHCP_IP_ADDRESS UNALIGNED *SubnetMask;
  377. DHCP_IP_ADDRESS UNALIGNED *RequestedAddress;
  378. DWORD UNALIGNED *RequestLeaseTime;
  379. BYTE *OverlayFields;
  380. DHCP_IP_ADDRESS UNALIGNED *RouterAddress;
  381. DHCP_IP_ADDRESS UNALIGNED *Server;
  382. BYTE *ParameterRequestList;
  383. DWORD ParameterRequestListLength;
  384. CHAR *MachineName;
  385. DWORD MachineNameLength;
  386. BYTE ClientHardwareAddressType;
  387. BYTE ClientHardwareAddressLength;
  388. BYTE *ClientHardwareAddress;
  389. CHAR *ClassIdentifier;
  390. DWORD ClassIdentifierLength;
  391. BYTE *VendorClass;
  392. DWORD VendorClassLength;
  393. DWORD DNSFlags;
  394. DWORD DNSNameLength;
  395. LPBYTE DNSName;
  396. BOOLEAN DSDomainNameRequested;
  397. CHAR *DSDomainName;
  398. DWORD DSDomainNameLen;
  399. USHORT SystemArchitecture;
  400. DWORD SystemArchitectureLength;
  401. CHAR *NetworkInterfaceType;
  402. DWORD NetworkInterfaceTypeLength;
  403. CHAR *Guid;
  404. DWORD GuidLength;
  405. } DHCP_SERVER_OPTIONS, *LPDHCP_SERVER_OPTIONS;
  406. typedef struct _MADCAP_SERVER_OPTIONS {
  407. BYTE UNALIGNED *AddrRangeList;
  408. WORD AddrRangeListSize;
  409. DWORD UNALIGNED *RequestLeaseTime;
  410. DWORD UNALIGNED *LeaseStartTime;
  411. DHCP_IP_ADDRESS UNALIGNED *Server;
  412. BYTE *RequestList;
  413. WORD RequestListLength;
  414. DWORD UNALIGNED *ScopeId;
  415. CHAR *Guid;
  416. WORD GuidLength;
  417. WORD UNALIGNED *MinAddrCount;
  418. WORD UNALIGNED *AddrCount;
  419. BYTE *RequestLang;
  420. WORD RequestLangLength;
  421. DWORD UNALIGNED *Time;
  422. WORD UNALIGNED *Features[3];
  423. WORD FeatureCount[3];
  424. DWORD UNALIGNED *RetryTime;
  425. DWORD UNALIGNED *MinLeaseTime;
  426. DWORD UNALIGNED *MaxStartTime;
  427. BOOL OptPresent[MADCAP_OPTION_TOTAL];
  428. } MADCAP_SERVER_OPTIONS, *LPMADCAP_SERVER_OPTIONS;
  429. // the indices for Features array above
  430. enum {
  431. SUPPORTED_FEATURES, REQUESTED_FEATURES, REQUIRED_FEATURES
  432. };
  433. //
  434. // JET - DHCP database constants.
  435. //
  436. #define DB_TABLE_SIZE 10 // table size in 4K pages.
  437. #define DB_TABLE_DENSITY 80 // page density
  438. #define DB_LANGID 0x0409 // language id
  439. #define DB_CP 1252 // code page
  440. #if DBG
  441. //
  442. // debug functions.
  443. //
  444. #ifdef CHICAGO // No Tracing available on CHICAGO
  445. #define DhcpPrintTrace
  446. #endif
  447. #define IF_DEBUG(flag) if (DhcpGlobalDebugFlag & (DEBUG_ ## flag))
  448. #define DhcpPrint(_x_) DhcpPrintRoutine _x_
  449. #define Trace DhcpPrintTrace
  450. #ifndef CHICAGO
  451. VOID
  452. DhcpPrintTrace(
  453. IN LPSTR Format,
  454. ...
  455. );
  456. #endif
  457. VOID
  458. DhcpPrintRoutine(
  459. IN DWORD DebugFlag,
  460. IN LPSTR Format,
  461. ...
  462. );
  463. #else
  464. #define IF_DEBUG(flag) if (FALSE)
  465. #define DhcpPrint(_x_)
  466. #define Trace (void)
  467. #endif // DBG
  468. #define OpenDriver DhcpOpenDriver
  469. #ifdef __cplusplus
  470. }
  471. #endif
  472. #endif // _DHCP_