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.

494 lines
16 KiB

  1. /*++
  2. Copyright (C) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. dhcpssdk.h
  5. Abstract:
  6. Header for writing a DHCP Callout DLL.
  7. --*/
  8. #ifndef _CALLOUT_H_
  9. #define _CALLOUT_H_
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. // This structure could change any day. This will be accurate only for version 0 -- which
  17. // has to be checked for by any CalloutDLL that is hooking onto the DhcpHandleOptionsHook.
  18. typedef DWORD DHCP_IP_ADDRESS;
  19. typedef struct _DHCP_SERVER_OPTIONS {
  20. BYTE *MessageType;
  21. DHCP_IP_ADDRESS UNALIGNED *SubnetMask;
  22. DHCP_IP_ADDRESS UNALIGNED *RequestedAddress;
  23. DWORD UNALIGNED *RequestLeaseTime;
  24. BYTE *OverlayFields;
  25. DHCP_IP_ADDRESS UNALIGNED *RouterAddress;
  26. DHCP_IP_ADDRESS UNALIGNED *Server;
  27. BYTE *ParameterRequestList;
  28. DWORD ParameterRequestListLength;
  29. CHAR *MachineName;
  30. DWORD MachineNameLength;
  31. BYTE ClientHardwareAddressType;
  32. BYTE ClientHardwareAddressLength;
  33. BYTE *ClientHardwareAddress;
  34. CHAR *ClassIdentifier;
  35. DWORD ClassIdentifierLength;
  36. BYTE *VendorClass;
  37. DWORD VendorClassLength;
  38. DWORD DNSFlags;
  39. DWORD DNSNameLength;
  40. LPBYTE DNSName;
  41. BOOLEAN DSDomainNameRequested;
  42. CHAR *DSDomainName;
  43. DWORD DSDomainNameLen;
  44. DWORD UNALIGNED *ScopeId;
  45. } DHCP_SERVER_OPTIONS, *LPDHCP_SERVER_OPTIONS;
  46. //
  47. // The location in registry where the REG_MULTI_SZ list of callout DLLs
  48. // that the DHCP Server will try to load.
  49. //
  50. #define DHCP_CALLOUT_LIST_KEY L"System\\CurrentControlSet\\Services\\DHCPServer\\Parameters"
  51. #define DHCP_CALLOUT_LIST_VALUE L"CalloutDlls"
  52. #define DHCP_CALLOUT_LIST_TYPE REG_MULTI_SZ
  53. #define DHCP_CALLOUT_ENTRY_POINT "DhcpServerCalloutEntry"
  54. //
  55. // Control CODES used by DHCP Server to notify server state change.
  56. //
  57. #define DHCP_CONTROL_START 0x00000001
  58. #define DHCP_CONTROL_STOP 0x00000002
  59. #define DHCP_CONTROL_PAUSE 0x00000003
  60. #define DHCP_CONTROL_CONTINUE 0x00000004
  61. //
  62. // Other ControlCodes used by various Callout HOOKS.
  63. //
  64. #define DHCP_DROP_DUPLICATE 0x00000001 // duplicate of pkt being processed
  65. #define DHCP_DROP_NOMEM 0x00000002 // not enough server mem in queues
  66. #define DHCP_DROP_INTERNAL_ERROR 0x00000003 // ooops?
  67. #define DHCP_DROP_TIMEOUT 0x00000004 // too late, pkt is too old
  68. #define DHCP_DROP_UNAUTH 0x00000005 // server is not authorized to run
  69. #define DHCP_DROP_PAUSED 0x00000006 // service is paused
  70. #define DHCP_DROP_NO_SUBNETS 0x00000007 // no subnets configured on server
  71. #define DHCP_DROP_INVALID 0x00000008 // invalid packet or client
  72. #define DHCP_DROP_WRONG_SERVER 0x00000009 // client in different DS enterprise
  73. #define DHCP_DROP_NOADDRESS 0x0000000A // no address available to offer
  74. #define DHCP_DROP_PROCESSED 0x0000000B // packet has been processed
  75. #define DHCP_DROP_GEN_FAILURE 0x00000100 // catch-all error
  76. #define DHCP_SEND_PACKET 0x10000000 // send the packet on wire
  77. #define DHCP_PROB_CONFLICT 0x20000001 // address conflicted..
  78. #define DHCP_PROB_DECLINE 0x20000002 // an addr got declined
  79. #define DHCP_PROB_RELEASE 0x20000003 // an addr got released
  80. #define DHCP_PROB_NACKED 0x20000004 // a client is being nacked.
  81. #define DHCP_GIVE_ADDRESS_NEW 0x30000001 // give client a "new" address
  82. #define DHCP_GIVE_ADDRESS_OLD 0x30000002 // renew client's "old" address
  83. #define DHCP_CLIENT_BOOTP 0x30000003 // client is a BOOTP client
  84. #define DHCP_CLIENT_DHCP 0x30000004 // client is a DHCP client
  85. typedef
  86. DWORD
  87. (APIENTRY *LPDHCP_CONTROL)(
  88. IN DWORD dwControlCode,
  89. IN LPVOID lpReserved
  90. )
  91. /*++
  92. Routine Description:
  93. This routine is called whenever the DHCP Server service is
  94. started, stopped, paused or continued as defined by the values of
  95. the dwControlCode parameter. The lpReserved parameter is reserved
  96. for future use and it should not be interpreted in any way. This
  97. routine should not block.
  98. Arguments:
  99. dwControlCode - one of the DHCP_CONTROL_* values
  100. lpReserved - reserved for future use.
  101. --*/
  102. ;
  103. typedef
  104. DWORD
  105. (APIENTRY *LPDHCP_NEWPKT)(
  106. IN OUT LPBYTE *Packet,
  107. IN OUT DWORD *PacketSize,
  108. IN DWORD IpAddress,
  109. IN LPVOID Reserved,
  110. IN OUT LPVOID *PktContext,
  111. OUT LPBOOL ProcessIt
  112. )
  113. /*++
  114. Routine Description:
  115. This routine is called soon after the DHCP Server receives a
  116. packet that it attempts to process. This routine is in the
  117. critical path of server execution and should return very fast, as
  118. otherwise server performance will be impacted. The Callout DLL
  119. can modify the buffer or return a new buffer via the Packet,
  120. PacketSize arguments. Also, if the callout DLL has internal
  121. structures to keep track of the packet and its progress, it can
  122. then return a context to this packet in the PktContext parameter.
  123. This context will be passed to almost all other hooks to indicate
  124. the packet being referred to. Also, if the Callout DLL is
  125. planning on processing the packet or for some other reason the
  126. DHCP server is not expected to process this packet, then it can
  127. set the ProcessIt flag to FALSE to indicate that the packet is to
  128. be dropped.
  129. Arguments:
  130. Packet - This parameter points to a character buffer that holds
  131. the actual packet received by the DHCP Server.
  132. PacketSize - This parameter points to a variable that holds the
  133. size of the above buffer.
  134. IpAddress - This parameter points to an IPV4 host order IP address
  135. of the socket that this packet was received on.
  136. Reserved -Reserved for future use.
  137. PktContect - This is an opaque pointer used by the DHCP Server for
  138. future references to this packet. It is expected that the callout
  139. DLL will provide this pointer if it is interested in keeping track
  140. of the packet. (See the descriptions for the hooks below for
  141. other usage of this Context).
  142. ProcessIt - This is a BOOL flag that the CalloutDll can set to
  143. TRUE or reset to indicate if the DHCP Server should continue
  144. processing this packet or not, respectively.
  145. --*/
  146. ;
  147. typedef
  148. DWORD
  149. (APIENTRY *LPDHCP_DROP_SEND)(
  150. IN OUT LPBYTE *Packet,
  151. IN OUT DWORD *PacketSize,
  152. IN DWORD ControlCode,
  153. IN DWORD IpAddress,
  154. IN LPVOID Reserved,
  155. IN LPVOID PktContext
  156. )
  157. /*++
  158. Routine Description:
  159. This hook is called if a packet is (DropPktHook) dropped for some
  160. reason or if the packet is completely processed. (If a packet is
  161. dropped, the hook is called twice as it is called once again to
  162. note that the packet has been completely processed). The callout
  163. DLL should be prepared to handle this hook multiple times for a
  164. packet. This routine should not block. The ControlCode parameter
  165. defines the reasons for the packet being dropped:
  166. * DHCP_DROP_DUPLICATE - This packet is a duplicate of another
  167. received by the server.
  168. * DHCP_DROP_NOMEM - Not enough memory to process the packet.
  169. * DHCP_DROP_INTERNAL_ERROR - Unexpected nternal error occurred.
  170. * DHCP_DROP_TIMEOUT - The packet is too old to process.
  171. * DHCP_DROP_UNAUTH - The server is not authorized.
  172. * DHCP_DROP_PAUSED - The server is paused.
  173. * DHCP_DROP_NO_SUBNETS - There are no subnets configured.
  174. * DHCP_DROP_INVALID - The packet is invalid or it came on an
  175. invalid socket ..
  176. * DHCP_DROP_WRONG_SERVER - The packet was sent to the wrong DHCP Server.
  177. * DHCP_DROP_NOADDRESS - There is no address to offer.
  178. * DHCP_DROP_PROCESSED - The packet has been processed.
  179. * DHCP_DROP_GEN_FAILURE - An unknown error occurred.
  180. This routine is also called right before a response is sent down
  181. the wire (SendPktHook) and in this case the ControlCode has a
  182. value of DHCP_SEND_PACKET.
  183. Arguments:
  184. Packet - This parameter points to a character buffer that holds
  185. the packet being processed by the DHCP Server.
  186. PacketSize - This parameter points to a variable that holds the
  187. size of the above buffer.
  188. ControlCode - See description for various control codes.
  189. IpAddress - This parameter points to an IPV4 host order IP address
  190. of the socket that this packet was received on.
  191. Reserved - Reserved for future use.
  192. PktContext - This parameter is the packet context that the Callout
  193. DLL NewPkt Hook returned for this packet. This can be used to
  194. track a packet.
  195. --*/
  196. ;
  197. typedef
  198. DWORD
  199. (APIENTRY *LPDHCP_PROB)(
  200. IN LPBYTE Packet,
  201. IN DWORD PacketSize,
  202. IN DWORD ControlCode,
  203. IN DWORD IpAddress,
  204. IN DWORD AltAddress,
  205. IN LPVOID Reserved,
  206. IN LPVOID PktContext
  207. )
  208. /*++
  209. Routine Description:
  210. This routine is called whenever special events occur that cause
  211. the packet to be dropped etc. The possible ControlCodes and their
  212. meanings are as follows:
  213. * DHCP_PROB_CONFLICT - The address attempted to be offered
  214. (AltAddress) is in use in the network already.
  215. * DHCP_PROB_DECLINE - The packet was a DECLINE message for the
  216. address specified in AltAddress.
  217. * DHCP_PROB_RELEASE - The packet was a RELEASE message for the
  218. address specified in AltAddress.
  219. * DHCP_PROB_NACKED - The packet was a REQUEST message for address
  220. specified in AltAddress and it was NACKed by the server.
  221. This routine should not block.
  222. Arguments:
  223. Packet - This parameter is the buffer of the packet being
  224. processed.
  225. PacketSize - This is the size of the above buffer.
  226. ControlCode - Specifies the event. See description below for
  227. control codes and meanings.
  228. IpAddress - IpV4 address of socket this packet was received on.
  229. AltAddress - Request IpV4 Address or Ip address that is in
  230. conflict.
  231. Reserved - Reserve for future use.
  232. PktContext - This is the context returned by the NewPkt hook for
  233. this packet.
  234. --*/
  235. ;
  236. typedef
  237. DWORD
  238. (APIENTRY *LPDHCP_GIVE_ADDRESS)(
  239. IN LPBYTE Packet,
  240. IN DWORD PacketSize,
  241. IN DWORD ControlCode,
  242. IN DWORD IpAddress,
  243. IN DWORD AltAddress,
  244. IN DWORD AddrType,
  245. IN DWORD LeaseTime,
  246. IN LPVOID Reserved,
  247. IN LPVOID PktContext
  248. )
  249. /*++
  250. Routine Description:
  251. This routine is called when the server is about to send an ACK to
  252. a REQUEST message. The ControlCode specifies if the address is a
  253. totally new address or if it an renewal of an old address (with
  254. values DHCP_GIVE_ADDRESS_NEW and DHCP_GIVE_ADDRESS_OLD
  255. respectively). The address being offered is passed as the
  256. AltAddress parameter and the AddrType parameter can be one of
  257. DHCP_CLIENT_BOOTP or DHCP_CLIENT_DHCP indicating whether the
  258. client is using BOOTP or DHCP respectively. This call should not
  259. block.
  260. Arguments:
  261. Packet - This parameter is the buffer of the packet being
  262. processed.
  263. PacketSize - This is the size of the above buffer.
  264. ControlCode - See description above for control codes and
  265. meanings.
  266. IpAddress - IpV4 address of socket this packet was received on.
  267. AltAddress - IpV4 address being ACKed to the client.
  268. AddrType - Is this a DHCP or BOOTP address?
  269. LeaseTime - Lease duration being passed.
  270. Reserved - Reserve for future use.
  271. PktContext - This is the context returned by the NewPkt hook for
  272. this packet.
  273. --*/
  274. ;
  275. typedef
  276. DWORD
  277. (APIENTRY *LPDHCP_HANDLE_OPTIONS)(
  278. IN LPBYTE Packet,
  279. IN DWORD PacketSize,
  280. IN LPVOID Reserved,
  281. IN LPVOID PktContext,
  282. IN OUT LPDHCP_SERVER_OPTIONS ServerOptions
  283. )
  284. /*++
  285. Routine Description:
  286. This routine can be utilized by the CalloutDLL to avoid parsing
  287. the whole packet. The packet is parsed by the server and some
  288. commonly used options are returned in the parsed pointers
  289. structure (see header for definition of DHCP_SERVER_OPTIONS). The
  290. hook is expected to make a copy of the structure pointed to by
  291. ServerOptions if it needs it beyond this function call. This
  292. routine may be called several times for a single packet. This
  293. routine should not block.
  294. Arguments:
  295. Packet - This parameter is the buffer of the packet being
  296. processed.
  297. PacketSize - This is the size of the above buffer.
  298. Reserved - Reserve for future use.
  299. PktContext - This is the context returned by the NewPkt hook for
  300. this packet.
  301. ServerOptions - This parameter is the structure that contains a
  302. bunch of pointers that represent corresponding options.
  303. --*/
  304. ;
  305. typedef
  306. DWORD
  307. (APIENTRY *LPDHCP_DELETE_CLIENT)(
  308. IN DWORD IpAddress,
  309. IN LPBYTE HwAddress,
  310. IN ULONG HwAddressLength,
  311. IN DWORD Reserved,
  312. IN DWORD ClientType
  313. )
  314. /*++
  315. Routine Description:
  316. This routine is called before a client lease is deleted off the
  317. active leases database. The ClientType field is currently not
  318. provided and this should not be used. This routine should not
  319. block.
  320. Arguments:
  321. IpAddress - IpV4 address of the client lease being deleted.
  322. HwAddress - Buffer holding the Hardware address of the client (MAC).
  323. HwAddressLength - This specifies the length of the above buffer.
  324. Reserved - Reserved for future use.
  325. ClientType - Reserved for future use.
  326. --*/
  327. ;
  328. typedef
  329. struct _DHCP_CALLOUT_TABLE {
  330. LPDHCP_CONTROL DhcpControlHook;
  331. LPDHCP_NEWPKT DhcpNewPktHook;
  332. LPDHCP_DROP_SEND DhcpPktDropHook;
  333. LPDHCP_DROP_SEND DhcpPktSendHook;
  334. LPDHCP_PROB DhcpAddressDelHook;
  335. LPDHCP_GIVE_ADDRESS DhcpAddressOfferHook;
  336. LPDHCP_HANDLE_OPTIONS DhcpHandleOptionsHook;
  337. LPDHCP_DELETE_CLIENT DhcpDeleteClientHook;
  338. LPVOID DhcpExtensionHook;
  339. LPVOID DhcpReservedHook;
  340. } DHCP_CALLOUT_TABLE, *LPDHCP_CALLOUT_TABLE;
  341. typedef
  342. DWORD
  343. (APIENTRY *LPDHCP_ENTRY_POINT_FUNC) (
  344. IN LPWSTR ChainDlls,
  345. IN DWORD CalloutVersion,
  346. IN OUT LPDHCP_CALLOUT_TABLE CalloutTbl
  347. )
  348. /*++
  349. Routine Description:
  350. This is the routine that is called by the DHCP Server when it
  351. successfully loads a DLL. If the routine succeeds, then the
  352. DHCP Server does not attempt to load any of the DLLs specified in
  353. the ChainDlls list of DLLs. If this function fails for some
  354. reason, then the DHCP Server proceeds to the next DLL in the
  355. ChainDlls structure.
  356. Note that for version negotiation, the server may call this
  357. routine several times until a compatible version is found.
  358. It is expected that the entrypoint routine would walk through the
  359. names of the dlls and attempt to load each of them and when it
  360. succeeds in retrieving the entry point, it attempts to get the
  361. cumulative set of hooks by repeating the above procedure (as done
  362. by the DHCP Server).
  363. Arguments:
  364. ChainDlls - This is a set of DLL names in REG_MULTI_SZ format (as
  365. returned by Registry function calls). This does not contain the
  366. name of the current DLL itself, but only the names of all DLLs
  367. that follow the current DLL.
  368. CalloutVersion - This is the version that the Callout DLL is
  369. expected to support. The current version number is 0.
  370. CalloutTbl - This is the cumulative set of Hooks that is needed by
  371. the current DLLs as well as all the DLLs in ChainDlls. It is the
  372. responsibility of the current DLL to retrive the cumulative set of
  373. Hooks and merge that with its own set of hooks and return that in
  374. this table structure. The table structure is defined above.
  375. --*/
  376. ;
  377. #ifdef __cplusplus
  378. }
  379. #endif
  380. #endif _CALLOUT_H_
  381. //========================================================================
  382. // end of file
  383. //========================================================================