Source code of Windows XP (NT5)
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.

480 lines
14 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. ipsec.h
  5. Abstract:
  6. Generic include file used by components to access the IPSEC driver.
  7. Contains the SAAPI IOCTLs and the structures relevant to them.
  8. Author:
  9. Sanjay Anand (SanjayAn) 2-January-1997
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #ifndef _IPSEC_H
  15. #define _IPSEC_H
  16. #include <windef.h>
  17. #include <winipsec.h>
  18. //
  19. // NOTE: all addresses are expected in Network byte order
  20. //
  21. typedef unsigned long IPAddr;
  22. typedef unsigned long IPMask;
  23. //
  24. // This should go into a global header
  25. //
  26. #define DD_IPSEC_DEVICE_NAME L"\\Device\\IPSEC"
  27. #define DD_IPSEC_SYM_NAME L"\\DosDevices\\IPSECDev"
  28. #define DD_IPSEC_DOS_NAME L"\\\\.\\IPSECDev"
  29. //
  30. // This is the name of the event that will be signaled after any policy changes have been applied.
  31. //
  32. #define IPSEC_POLICY_CHANGE_NOTIFY L"IPSEC_POLICY_CHANGE_NOTIFY"
  33. // //
  34. // IOCTL code definitions and related structures //
  35. // All the IOCTLs are synchronous and need administrator privilege //
  36. // //
  37. #define FSCTL_IPSEC_BASE FILE_DEVICE_NETWORK
  38. #define _IPSEC_CTL_CODE(function, method, access) \
  39. CTL_CODE(FSCTL_IPSEC_BASE, function, method, access)
  40. //
  41. // Security Association/Policy APIs implemented as Ioctls
  42. //
  43. #define IOCTL_IPSEC_ADD_FILTER \
  44. _IPSEC_CTL_CODE(0, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  45. #define IOCTL_IPSEC_DELETE_FILTER \
  46. _IPSEC_CTL_CODE(1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  47. #define IOCTL_IPSEC_POST_FOR_ACQUIRE_SA \
  48. _IPSEC_CTL_CODE(2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  49. #define IOCTL_IPSEC_GET_SPI \
  50. _IPSEC_CTL_CODE(3, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  51. #define IOCTL_IPSEC_UPDATE_SA \
  52. _IPSEC_CTL_CODE(4, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  53. #define IOCTL_IPSEC_ADD_SA \
  54. _IPSEC_CTL_CODE(5, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  55. #define IOCTL_IPSEC_DELETE_SA \
  56. _IPSEC_CTL_CODE(6, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  57. #define IOCTL_IPSEC_EXPIRE_SA \
  58. _IPSEC_CTL_CODE(7, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  59. #define IOCTL_IPSEC_ENUM_SAS \
  60. _IPSEC_CTL_CODE(8, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
  61. #define IOCTL_IPSEC_ENUM_FILTERS \
  62. _IPSEC_CTL_CODE(9, METHOD_OUT_DIRECT, FILE_WRITE_ACCESS)
  63. #define IOCTL_IPSEC_QUERY_EXPORT \
  64. _IPSEC_CTL_CODE(10, METHOD_BUFFERED, FILE_ANY_ACCESS)
  65. #define IOCTL_IPSEC_QUERY_STATS \
  66. _IPSEC_CTL_CODE(11, METHOD_BUFFERED, FILE_ANY_ACCESS)
  67. #define IOCTL_IPSEC_QUERY_SPI \
  68. _IPSEC_CTL_CODE(12, METHOD_BUFFERED, FILE_ANY_ACCESS)
  69. #define IOCTL_IPSEC_SET_OPERATION_MODE \
  70. _IPSEC_CTL_CODE(13, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  71. #define IOCTL_IPSEC_SET_TCPIP_STATUS \
  72. _IPSEC_CTL_CODE(14, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  73. #define IOCTL_IPSEC_REGISTER_PROTOCOL \
  74. _IPSEC_CTL_CODE(15, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  75. //
  76. // Structures to go with the ioctls above
  77. //
  78. #define FILTER_FLAGS_PASS_THRU 0x0001
  79. #define FILTER_FLAGS_DROP 0x0002
  80. #define FILTER_FLAGS_INBOUND 0x0004
  81. #define FILTER_FLAGS_OUTBOUND 0x0008
  82. #define FILTER_FLAGS_MANUAL 0x0010
  83. // Flags for DestType in acquire
  84. #define IPSEC_BCAST 0x1
  85. #define IPSEC_MCAST 0x2
  86. //
  87. // for IOCTL_IPSEC_ADD_FILTER
  88. //
  89. typedef struct _IPSEC_FILTER {
  90. IPAddr SrcAddr;
  91. IPMask SrcMask;
  92. IPAddr DestAddr;
  93. IPMask DestMask;
  94. IPAddr TunnelAddr;
  95. DWORD Protocol;
  96. WORD SrcPort;
  97. WORD DestPort;
  98. BOOLEAN TunnelFilter;
  99. UCHAR Pad[1];
  100. WORD Flags;
  101. } IPSEC_FILTER, *PIPSEC_FILTER;
  102. typedef struct _IPSEC_FILTER_INFO {
  103. GUID FilterId; // unique identifier to identify a filter
  104. GUID PolicyId; // unique identifier to identify a policy entry
  105. ULONG Index; // hint on where this entry fits in the ordered list of filters
  106. IPSEC_FILTER AssociatedFilter;
  107. } IPSEC_FILTER_INFO, *PIPSEC_FILTER_INFO;
  108. typedef struct _IPSEC_ADD_FILTER {
  109. DWORD NumEntries;
  110. IPSEC_FILTER_INFO pInfo[1];
  111. } IPSEC_ADD_FILTER, *PIPSEC_ADD_FILTER;
  112. //
  113. // for IOCTL_IPSEC_DELETE_FILTER
  114. //
  115. typedef IPSEC_ADD_FILTER IPSEC_DELETE_FILTER, *PIPSEC_DELETE_FILTER;
  116. //
  117. // for IOCTL_IPSEC_ENUM_FILTERS
  118. //
  119. typedef struct _IPSEC_ENUM_FILTERS {
  120. DWORD NumEntries; // num entries for which there is space
  121. DWORD NumEntriesPresent; // num entries actually present in the driver
  122. IPSEC_FILTER_INFO pInfo[1];
  123. } IPSEC_ENUM_FILTERS, *PIPSEC_ENUM_FILTERS;
  124. //
  125. // for IOCTL_IPSEC_QUERY_STATS
  126. //
  127. typedef IPSEC_STATISTICS IPSEC_QUERY_STATS, *PIPSEC_QUERY_STATS;
  128. //
  129. // for IOCTL_IPSEC_SET_OPERATION_MODE
  130. //
  131. typedef enum _OPERATION_MODE {
  132. IPSEC_BYPASS_MODE = 0,
  133. IPSEC_BLOCK_MODE,
  134. IPSEC_SECURE_MODE,
  135. IPSEC_OPERATION_MODE_MAX
  136. } OPERATION_MODE;
  137. typedef struct _IPSEC_SET_OPERATION_MODE {
  138. OPERATION_MODE OperationMode;
  139. } IPSEC_SET_OPERATION_MODE, *PIPSEC_SET_OPERATION_MODE;
  140. //
  141. // For IOCTL_IPSEC_REGISTER_PROTOCOL.
  142. //
  143. typedef enum _REGISTER_PROTOCOL {
  144. IPSEC_REGISTER_PROTOCOLS = 0,
  145. IPSEC_DEREGISTER_PROTOCOLS,
  146. REGISTER_PROTOCOL_MAX
  147. } REGISTER_PROTOCOL, * PREGISTER_PROTOCOL;
  148. typedef struct _IPSEC_REGISTER_PROTOCOL {
  149. REGISTER_PROTOCOL RegisterProtocol;
  150. } IPSEC_REGISTER_PROTOCOL, * PIPSEC_REGISTER_PROTOCOL;
  151. //
  152. // for IOCTL_IPSEC_SET_TCPIP_STATUS
  153. //
  154. typedef struct _IPSEC_SET_TCPIP_STATUS {
  155. BOOLEAN TcpipStatus;
  156. PVOID TcpipFreeBuff;
  157. PVOID TcpipAllocBuff;
  158. PVOID TcpipGetInfo;
  159. PVOID TcpipNdisRequest;
  160. PVOID TcpipSetIPSecStatus;
  161. PVOID TcpipSetIPSecPtr;
  162. PVOID TcpipUnSetIPSecPtr;
  163. PVOID TcpipUnSetIPSecSendPtr;
  164. PVOID TcpipTCPXsum;
  165. } IPSEC_SET_TCPIP_STATUS, *PIPSEC_SET_TCPIP_STATUS;
  166. //
  167. // The base Security Association structure for IOCTL_IPSEC_*_SA
  168. //
  169. typedef ULONG SPI_TYPE;
  170. typedef enum _Operation {
  171. None = 0,
  172. Auth, // AH
  173. Encrypt, // ESP
  174. Compress
  175. } OPERATION_E;
  176. //
  177. // IPSEC DOI ESP algorithms
  178. //
  179. typedef enum _ESP_ALGO {
  180. IPSEC_ESP_NONE = 0,
  181. IPSEC_ESP_DES,
  182. IPSEC_ESP_DES_40,
  183. IPSEC_ESP_3_DES,
  184. IPSEC_ESP_MAX
  185. } ESP_ALGO;
  186. //
  187. // IPSEC DOI AH algorithms
  188. //
  189. typedef enum _AH_ALGO {
  190. IPSEC_AH_NONE = 0,
  191. IPSEC_AH_MD5,
  192. IPSEC_AH_SHA,
  193. IPSEC_AH_MAX
  194. } AH_ALGO;
  195. //
  196. // Lifetime structure - 0 => not significant
  197. //
  198. typedef struct _LIFETIME {
  199. ULONG KeyExpirationTime; // lifetime of key - in seconds
  200. ULONG KeyExpirationBytes; // max # of KBytes xformed till re-key
  201. } LIFETIME, *PLIFETIME;
  202. //
  203. // describes generic algorithm properties
  204. //
  205. typedef struct _ALGO_INFO {
  206. ULONG algoIdentifier; // ESP_ALGO or AH_ALGO
  207. ULONG algoKeylen; // len in bytes
  208. ULONG algoRounds; // # of algo rounds
  209. } ALGO_INFO, *PALGO_INFO;
  210. //
  211. // Security Association
  212. //
  213. //
  214. // Flags - not mutually exclusive
  215. //
  216. typedef ULONG SA_FLAGS;
  217. #define IPSEC_SA_INTERNAL_IOCTL_DELETE 0x00000008
  218. #define MAX_SAS 3 // COMP, ESP, AH
  219. #define MAX_OPS MAX_SAS
  220. typedef struct _SECURITY_ASSOCIATION {
  221. OPERATION_E Operation; // ordered set of operations
  222. SPI_TYPE SPI; // SPI in order of operations in OperationArray
  223. ALGO_INFO IntegrityAlgo; // AH
  224. ALGO_INFO ConfAlgo; // ESP
  225. PVOID CompAlgo; // compression algo info
  226. } SECURITY_ASSOCIATION, *PSECURITY_ASSOCIATION;
  227. typedef struct _SA_STRUCT {
  228. HANDLE Context; // context of the original ACQUIRE request
  229. ULONG NumSAs; // number of SAs following
  230. SA_FLAGS Flags;
  231. IPAddr TunnelAddr; // Tunnel end IP Addr
  232. LIFETIME Lifetime;
  233. IPSEC_FILTER InstantiatedFilter; // the actual addresses for which this SA was setup
  234. SECURITY_ASSOCIATION SecAssoc[MAX_SAS];
  235. DWORD dwQMPFSGroup;
  236. IKE_COOKIE_PAIR CookiePair;
  237. ULONG KeyLen; // key len in # of chars
  238. UCHAR KeyMat[1];
  239. } SA_STRUCT, *PSA_STRUCT;
  240. typedef struct _IPSEC_ADD_UPDATE_SA {
  241. SA_STRUCT SAInfo;
  242. } IPSEC_ADD_UPDATE_SA, *PIPSEC_ADD_UPDATE_SA;
  243. //
  244. // Outbound SAs are typically deleted
  245. //
  246. typedef struct _IPSEC_DELETE_SA {
  247. IPSEC_QM_SA SATemplate; // template used for SA match
  248. } IPSEC_DELETE_SA, *PIPSEC_DELETE_SA;
  249. //
  250. // Inbound SAs are typically expired
  251. //
  252. typedef struct _IPSEC_DELETE_INFO {
  253. IPAddr DestAddr;
  254. IPAddr SrcAddr;
  255. SPI_TYPE SPI;
  256. } IPSEC_DELETE_INFO, *PIPSEC_DELETE_INFO;
  257. typedef struct _IPSEC_EXPIRE_SA {
  258. IPSEC_DELETE_INFO DelInfo;
  259. } IPSEC_EXPIRE_SA, *PIPSEC_EXPIRE_SA;
  260. typedef struct _IPSEC_GET_SPI {
  261. HANDLE Context; // context to represent this SA negotiation
  262. IPSEC_FILTER InstantiatedFilter; // the actual addresses for which this SA was setup
  263. SPI_TYPE SPI; // filled out on return
  264. } IPSEC_GET_SPI, *PIPSEC_GET_SPI;
  265. typedef IPSEC_GET_SPI IPSEC_SET_SPI, *PIPSEC_SET_SPI;
  266. typedef struct _IPSEC_SA_ALGO_INFO {
  267. ALGO_INFO IntegrityAlgo;
  268. ALGO_INFO ConfAlgo;
  269. ALGO_INFO CompAlgo;
  270. } IPSEC_SA_ALGO_INFO, *PIPSEC_SA_ALGO_INFO;
  271. typedef ULONG SA_ENUM_FLAGS;
  272. #define SA_ENUM_FLAGS_INITIATOR 0x00000001
  273. #define SA_ENUM_FLAGS_MTU_BUMPED 0x00000002
  274. #define SA_ENUM_FLAGS_OFFLOADED 0x00000004
  275. #define SA_ENUM_FLAGS_OFFLOAD_FAILED 0x00000008
  276. #define SA_ENUM_FLAGS_OFFLOADABLE 0x00000010
  277. #define SA_ENUM_FLAGS_IN_REKEY 0x00000020
  278. typedef struct _IPSEC_SA_STATS {
  279. ULARGE_INTEGER ConfidentialBytesSent;
  280. ULARGE_INTEGER ConfidentialBytesReceived;
  281. ULARGE_INTEGER AuthenticatedBytesSent;
  282. ULARGE_INTEGER AuthenticatedBytesReceived;
  283. ULARGE_INTEGER TotalBytesSent;
  284. ULARGE_INTEGER TotalBytesReceived;
  285. ULARGE_INTEGER OffloadedBytesSent;
  286. ULARGE_INTEGER OffloadedBytesReceived;
  287. } IPSEC_SA_STATS, *PIPSEC_SA_STATS;
  288. typedef struct _IPSEC_SA_INFO {
  289. GUID PolicyId; // unique identifier to identify a policy entry
  290. GUID FilterId;
  291. LIFETIME Lifetime;
  292. IPAddr InboundTunnelAddr;
  293. ULONG NumOps;
  294. SPI_TYPE InboundSPI[MAX_OPS];
  295. SPI_TYPE OutboundSPI[MAX_OPS];
  296. OPERATION_E Operation[MAX_OPS];
  297. IPSEC_SA_ALGO_INFO AlgoInfo[MAX_OPS];
  298. IPSEC_FILTER AssociatedFilter;
  299. DWORD dwQMPFSGroup;
  300. IKE_COOKIE_PAIR CookiePair;
  301. SA_ENUM_FLAGS EnumFlags;
  302. IPSEC_SA_STATS Stats;
  303. } IPSEC_SA_INFO, *PIPSEC_SA_INFO;
  304. typedef struct _SECURITY_ASSOCIATION_OUT {
  305. DWORD Operation; // ordered set of operations
  306. SPI_TYPE SPI; // SPI in order of operations in OperationArray
  307. ALGO_INFO IntegrityAlgo; // AH
  308. ALGO_INFO ConfAlgo; // ESP
  309. ALGO_INFO CompAlgo; // compression algo info
  310. } SECURITY_ASSOCIATION_OUT, *PSECURITY_ASSOCIATION_OUT;
  311. typedef struct _IPSEC_SA_QUERY_INFO {
  312. GUID PolicyId; // unique identifier to identify a policy entry
  313. LIFETIME Lifetime;
  314. ULONG NumSAs;
  315. SECURITY_ASSOCIATION_OUT SecAssoc[MAX_SAS];
  316. IPSEC_FILTER AssociatedFilter;
  317. DWORD Flags;
  318. IKE_COOKIE_PAIR AssociatedMainMode;
  319. } IPSEC_SA_QUERY_INFO, *PIPSEC_SA_QUERY_INFO;
  320. typedef struct _IPSEC_ENUM_SAS {
  321. DWORD NumEntries; // num entries for which there is space
  322. DWORD NumEntriesPresent; // num entries actually present in the driver
  323. DWORD Index; // num entries to skip
  324. IPSEC_QM_SA SATemplate; // template used for SA match
  325. IPSEC_SA_INFO pInfo[1];
  326. } IPSEC_ENUM_SAS, *PIPSEC_ENUM_SAS;
  327. typedef struct _IPSEC_POST_FOR_ACQUIRE_SA {
  328. HANDLE IdentityInfo; // identity of Principal
  329. HANDLE Context; // context to represent this SA negotiation
  330. GUID PolicyId; // GUID for QM policy
  331. IPAddr SrcAddr;
  332. IPMask SrcMask;
  333. IPAddr DestAddr;
  334. IPMask DestMask;
  335. IPAddr TunnelAddr;
  336. IPAddr InboundTunnelAddr;
  337. DWORD Protocol;
  338. IKE_COOKIE_PAIR CookiePair; // only used for notify
  339. WORD SrcPort;
  340. WORD DestPort;
  341. BOOLEAN TunnelFilter; // TRUE => this is a tunnel filter
  342. UCHAR DestType;
  343. UCHAR Pad[2];
  344. } IPSEC_POST_FOR_ACQUIRE_SA, *PIPSEC_POST_FOR_ACQUIRE_SA;
  345. //NB. This must be <= size as the IPSEC_POST_FOR_ACQUIRE_SA
  346. typedef struct _IPSEC_POST_EXPIRE_NOTIFY {
  347. HANDLE IdentityInfo; // identity of Principal
  348. HANDLE Context; // context to represent this SA negotiation
  349. SPI_TYPE InboundSpi;
  350. SPI_TYPE OutboundSpi;
  351. DWORD Flags;
  352. IPAddr SrcAddr;
  353. IPMask SrcMask;
  354. IPAddr DestAddr;
  355. IPMask DestMask;
  356. IPAddr TunnelAddr;
  357. IPAddr InboundTunnelAddr;
  358. DWORD Protocol;
  359. IKE_COOKIE_PAIR CookiePair;
  360. WORD SrcPort;
  361. WORD DestPort;
  362. BOOLEAN TunnelFilter; // TRUE => this is a tunnel filter
  363. UCHAR Pad[3];
  364. } IPSEC_POST_EXPIRE_NOTIFY, *PIPSEC_POST_EXPIRE_NOTIFY;
  365. typedef struct _IPSEC_QUERY_EXPORT {
  366. BOOLEAN Export;
  367. } IPSEC_QUERY_EXPORT, *PIPSEC_QUERY_EXPORT;
  368. typedef struct _IPSEC_FILTER_SPI {
  369. IPSEC_FILTER Filter;
  370. SPI_TYPE Spi;
  371. DWORD Operation;
  372. DWORD Flags;
  373. struct _IPSEC_FILTER_SPI *Next;
  374. } IPSEC_FILTER_SPI, *PIPSEC_FILTER_SPI;
  375. typedef struct _QOS_FILTER_SPI {
  376. IPAddr SrcAddr;
  377. IPAddr DestAddr;
  378. DWORD Protocol;
  379. WORD SrcPort;
  380. WORD DestPort;
  381. DWORD Operation;
  382. DWORD Flags;
  383. SPI_TYPE Spi;
  384. } QOS_FILTER_SPI, *PQOS_FILTER_SPI;
  385. typedef struct _IPSEC_QUERY_SPI {
  386. IPSEC_FILTER Filter;
  387. SPI_TYPE Spi; // inbound spi
  388. SPI_TYPE OtherSpi; // outbound spi
  389. DWORD Operation;
  390. } IPSEC_QUERY_SPI, *PIPSEC_QUERY_SPI;
  391. #define IPSEC_NOTIFY_EXPIRE_CONTEXT 0x00000000
  392. #define IPSEC_RPC_CONTEXT 0x00000001
  393. #endif _IPSEC_H