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.

772 lines
26 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. globals.h
  5. Abstract:
  6. This is the main header file for IPSEC. Contains all the globals.
  7. Author:
  8. Sanjay Anand (SanjayAn) 2-January-1997
  9. ChunYe
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #ifndef _GLOBALS_H
  15. #define _GLOBALS_H
  16. #include "NsIpsec.h"
  17. #define MAX_COUNT_STRING_LEN 32
  18. #define MAX_IP_OPTION_SIZE 40
  19. // 64 bytes
  20. #define MAX_KEYLEN_SHA 64
  21. #define MAX_KEYLEN_MD5 64
  22. // 8 bytes
  23. #define MAX_KEYLEN_DES 8
  24. #define MAX_IV_LEN DES_BLOCKLEN
  25. #define MAX_KEY_LEN MAX(MAX_KEYLEN_MD5, MAX_KEYLEN_DES)
  26. //
  27. // we set aside SPIs between 256 and 65536 (64K) for hardware offload
  28. //
  29. #define LOWER_BOUND_SPI 256
  30. #define UPPER_BOUND_SPI ((ULONG) -1) // MAX_ULONG
  31. #define INVALID_INDEX 0xffffffff
  32. #define RNG_KEY_SIZE 256 // 2048 bits
  33. #define RNG_REKEY_THRESHOLD 65536 // 64K raw bytes
  34. //
  35. // Constants related to filter lists
  36. //
  37. #define INBOUND_TRANSPORT_FILTER 0
  38. #define OUTBOUND_TRANSPORT_FILTER 1
  39. #define INBOUND_TUNNEL_FILTER 2
  40. #define OUTBOUND_TUNNEL_FILTER 3
  41. #define MIN_FILTER INBOUND_TRANSPORT_FILTER
  42. #define MAX_FILTER OUTBOUND_TUNNEL_FILTER
  43. #define MIN_TRANSPORT_FILTER INBOUND_TRANSPORT_FILTER
  44. #define MAX_TRANSPORT_FILTER OUTBOUND_TRANSPORT_FILTER
  45. #define MIN_TUNNEL_FILTER INBOUND_TUNNEL_FILTER
  46. #define MAX_TUNNEL_FILTER OUTBOUND_TUNNEL_FILTER
  47. #define INBOUND_OUTBOUND_INCREMENT 1
  48. #define TRANSPORT_TUNNEL_INCREMENT 2
  49. #define NUM_FILTERS (MAX_FILTER - MIN_FILTER + 1)
  50. //
  51. // Number of extra bytes when we pad - one for padlen and other for payloadtype
  52. //
  53. #define NUM_EXTRA 2
  54. #define ESP_SIZE (sizeof(ESP) + DES_BLOCKLEN * sizeof(UCHAR))
  55. #define TRUNCATED_HASH_LEN 12 // 96 bits
  56. #define REPLAY_WINDOW_SIZE 64
  57. #define MAX_PAD_LEN (DES_BLOCKLEN + NUM_EXTRA - 1)
  58. #define IPSEC_SMALL_BUFFER_SIZE 50
  59. #define IPSEC_LARGE_BUFFER_SIZE 200
  60. #define IPSEC_CACHE_LINE_SIZE 16
  61. #define IPSEC_LIST_DEPTH 5
  62. typedef ULONG tSPI;
  63. #define MAX_BLOCKLEN MAX(DES_BLOCKLEN, 0)
  64. #define IPSEC_TAG_INIT 'ISpI'
  65. #define IPSEC_TAG_AH 'TApI'
  66. #define IPSEC_TAG_AH_TU 'UApI'
  67. #define IPSEC_TAG_ESP 'TEpI'
  68. #define IPSEC_TAG_ESP_TU 'UEpI'
  69. #define IPSEC_TAG_HUGHES 'THpI'
  70. #define IPSEC_TAG_HUGHES_TU 'UHpI'
  71. #define IPSEC_TAG_ACQUIRE_CTX 'XApI'
  72. #define IPSEC_TAG_FILTER 'IFpI'
  73. #define IPSEC_TAG_SA 'ASpI'
  74. #define IPSEC_TAG_KEY 'EKpI'
  75. #define IPSEC_TAG_TIMER 'ITpI'
  76. #define IPSEC_TAG_STALL_QUEUE 'QSpI'
  77. #define IPSEC_TAG_LOOKASIDE_LISTS 'ALpI'
  78. #define IPSEC_TAG_BUFFER_POOL 'PBpI'
  79. #define IPSEC_TAG_SEND_COMPLETE 'CSpI'
  80. #define IPSEC_TAG_EVT_QUEUE 'QEpI'
  81. #define IPSEC_TAG_HW 'WHpI'
  82. #define IPSEC_TAG_HW_PKTINFO 'KPpI'
  83. #define IPSEC_TAG_HW_PKTEXT 'XEpI'
  84. #define IPSEC_TAG_HW_ADDSA 'SApI'
  85. #define IPSEC_TAG_HW_DELSA 'SDpI'
  86. #define IPSEC_TAG_HW_PLUMB 'LPpI'
  87. #define IPSEC_TAG_COMP 'OCpI'
  88. #define IPSEC_TAG_REINJECT 'ERpI'
  89. #define IPSEC_TAG_IOCTL 'OIpI'
  90. #define IPSEC_TAG_LOG 'OLpI'
  91. #define IPSEC_TAG_PARSER 'sPpI'
  92. #define IPSEC_TAG_ICMP 'cIpI'
  93. #define IPSEC_TAG_STATEFUL_ENTRY 'ESpI'
  94. #define IPSEC_TAG_STATEFUL_HT 'HSpI'
  95. #define IPSEC_TAG_HASH_POOL 'PHpI'
  96. #define IPSEC_LOG_PACKET_SIZE 128 //Size in bytes of stored packet in troubleshoot mode
  97. //
  98. // The IPSEC ESP payload
  99. //
  100. typedef struct _ESP {
  101. tSPI esp_spi;
  102. } ESP, *PESP;
  103. typedef struct _NATENCAP {
  104. ushort uh_src; // Source port.
  105. ushort uh_dest; // Destination port.
  106. ushort uh_length; // Length
  107. ushort uh_xsum; // Checksum.
  108. UCHAR Zero[8];
  109. } NATENCAP, *PNATENCAP;
  110. typedef struct _NATENCAP_OTHER {
  111. ushort uh_src; // Source port.
  112. ushort uh_dest; // Destination port.
  113. ushort uh_length; // Length
  114. ushort uh_xsum; // Checksum.
  115. } NATENCAP_OTHER, *PNATENCAP_OTHER;
  116. //
  117. // SA Flags - Not mutually exclusive
  118. //
  119. #define FLAGS_SA_INITIATOR 0x00000001 // use Initiator keys? might be deprecated soon
  120. #define FLAGS_SA_OUTBOUND 0x00000002 // outbound SA?
  121. #define FLAGS_SA_TUNNEL 0x00000004 // tunnel mode? sa_TunnelAddr is significant
  122. #define FLAGS_SA_REKEY 0x00000010 // is this rekeyed LarvalSA?
  123. #define FLAGS_SA_REKEY_ORI 0x00000020 // did this kick off a rekey?
  124. #define FLAGS_SA_MANUAL 0x00000040 // manual keyed?
  125. #define FLAGS_SA_MTU_BUMPED 0x00000080 // was MTU bumped down on this SA?
  126. #define FLAGS_SA_PENDING 0x00000100 // this is on the pending queue.
  127. #define FLAGS_SA_TIMER_STARTED 0x00000200 // timer started on this SA
  128. #define FLAGS_SA_HW_PLUMBED 0x00000400 // hw acceleration plumbed successfully
  129. #define FLAGS_SA_HW_PLUMB_FAILED 0x00000800 // hw acceleration plumbing failed
  130. #define FLAGS_SA_HW_DELETE_SA 0x00001000 // hw acceleration - this is the pending delete.
  131. #define FLAGS_SA_HW_CRYPTO_ONLY 0x00002000 // hw acceleration - this is a crypto-only provider.
  132. #define FLAGS_SA_HW_RESET 0x00004000 // hw acceleration - this offload SA has been reset
  133. #define FLAGS_SA_HW_DELETE_QUEUED 0x00008000 // hw acceleration - this SA delete is queued so make sure reset doesn't touch it
  134. #define FLAGS_SA_REFERENCED 0x00010000 // is this SA the next of another?
  135. #define FLAGS_SA_NOTIFY_PERFORMED 0x00020000 // For inbound only. Notification performed
  136. #define FLAGS_SA_ON_FILTER_LIST 0x00040000 // used on inbound SAs to indicate they are on filter lists
  137. #define FLAGS_SA_ON_SPI_HASH 0x00080000 // used on inbound SAs to indicate they are on spi hash lists
  138. #define FLAGS_SA_EXPIRED 0x00100000 // has this SA expired?
  139. #define FLAGS_SA_IDLED_OUT 0x00200000 // has this SA idled out?
  140. #define FLAGS_SA_HIBERNATED 0x00400000 // has this SA been hibernated?
  141. #define FLAGS_SA_DELETE_BY_IOCTL 0x00800000 // sa delete initiated by external source
  142. #define FLAGS_SA_OFFLOADABLE 0x01000000 // is this SA offloadable?
  143. #define FLAGS_SA_PASSTHRU_FILTER 0x02000000 // sa derived from a pass-thru filter
  144. #define FLAGS_SA_DISABLE_IDLE_OUT 0x04000000 // don't idle out
  145. #define FLAGS_SA_DISABLE_ANTI_REPLAY_CHECK 0x08000000 // don't check anti-replay
  146. #define FLAGS_SA_DISABLE_LIFETIME_CHECK 0x10000000 // don't check lifetimes
  147. #define FLAGS_SA_ENABLE_NLBS_IDLE_CHECK 0x20000000 // Idle out faster
  148. //
  149. // SA States - Mutually exclusive
  150. //
  151. typedef enum _SA_STATE {
  152. STATE_SA_CREATED = 1, // when created
  153. STATE_SA_LARVAL, // Key negotiation going on - outbound SAs only
  154. STATE_SA_ACTIVE, // outbound SA completely setup
  155. STATE_SA_LARVAL_ACTIVE, // inbound active SA without the associated outbound SA
  156. STATE_SA_ZOMBIE // SAs flushed, ready to be deleted
  157. } SA_STATE, *PSA_STATE;
  158. #define IPSEC_SA_SIGNATURE 0x4601
  159. #define IPSEC_FILTER_SIGNATURE 0x4602
  160. #if DBG
  161. #define IPSEC_SA_D_1 'SAD1'
  162. #define IPSEC_SA_D_2 'SAD2'
  163. #define IPSEC_SA_D_3 'SAD3'
  164. #define IPSEC_SA_D_4 'SAD4'
  165. #endif
  166. typedef struct _FILTER FILTER, *PFILTER;
  167. typedef struct _INTERNAL_ALGO_INFO {
  168. ULONG algoIdentifier;
  169. PUCHAR algoKey;
  170. ULONG algoKeylen;
  171. ULONG algoRounds;
  172. } INTERNAL_ALGO_INFO, *PINTERNAL_ALGO_INFO;
  173. typedef struct _INTERNAL_ALGO {
  174. INTERNAL_ALGO_INFO integrityAlgo;
  175. INTERNAL_ALGO_INFO confAlgo;
  176. INTERNAL_ALGO_INFO compAlgo;
  177. } INTERNAL_ALGO, *PINTERNAL_ALGO;
  178. typedef struct _IPSEC_ACQUIRE_CONTEXT IPSEC_ACQUIRE_CONTEXT, *PIPSEC_ACQUIRE_CONTEXT;
  179. typedef struct _FILTER_CACHE FILTER_CACHE, *PFILTER_CACHE;
  180. //
  181. // Security Association Table (SATable)
  182. //
  183. // Indexed by the following:
  184. //
  185. // Sender maps {Src Addr, Dest Addr, User Context} to the index
  186. //
  187. // Receiver maps {Dest Addr, SPI} to the index
  188. // SPI values are unique when generated manually, so can be used directly
  189. // to index into the SATable for
  190. //
  191. typedef struct _SATableEntry {
  192. LIST_ENTRY sa_SPILinkage; // linkage in SPI hash table list
  193. LIST_ENTRY sa_FilterLinkage; // linkage in Filter table list
  194. LIST_ENTRY sa_LarvalLinkage; // linkage in Larval SA list
  195. LIST_ENTRY sa_PendingLinkage; // linkage in pending SA list - waiting for Acquire Irp
  196. struct _SATableEntry *sa_AssociatedSA; // outbound -> inbound link
  197. struct _SATableEntry *sa_RekeyLarvalSA; // points to the Larval SA on a rekey
  198. struct _SATableEntry *sa_RekeyOriginalSA; // Rekey Larval SA points to the original SA that kicked off the rekey
  199. ULONG sa_Signature; // contains 4601
  200. ULONG sa_AcquireId; // cross-check with the Acquire Irp context
  201. PIPSEC_ACQUIRE_CONTEXT sa_AcquireCtx; // actual acquire context - used to invalidate the context.
  202. ULONG sa_Flags; // flags as defined above
  203. SA_STATE sa_State; // states as defined above
  204. ULONG sa_Reference; // ref count
  205. PFILTER sa_Filter; // assoc filter entry
  206. PFILTER_CACHE sa_FilterCache; // back pointer to cache entry so we can disable it when an SA goes away
  207. KSPIN_LOCK sa_Lock; // lock to protect the FilterCache ptr.
  208. #if DBG
  209. ULONG sa_d1;
  210. #endif
  211. ULARGE_INTEGER sa_uliSrcDstAddr;
  212. ULARGE_INTEGER sa_uliSrcDstMask;
  213. ULARGE_INTEGER sa_uliProtoSrcDstPort;
  214. IPAddr sa_TunnelAddr; // Tunnel dest end IP Addr
  215. IPAddr sa_SrcTunnelAddr; // Tunnel src end IP Addr
  216. // SPI - host order - if outbound, SPI for remote,
  217. // else inbound (our) SPI
  218. tSPI sa_SPI; // Inbound: in the multiple ops case, this is the SPI of the last operation.
  219. // Outbound: order is as specified in the update.
  220. LONG sa_NumOps; // the total number of operations to be done
  221. tSPI sa_OtherSPIs[MAX_OPS]; // the other alternate SPIs.
  222. OPERATION_E sa_Operation[MAX_OPS];
  223. INTERNAL_ALGO sa_Algorithm[MAX_OPS];
  224. ULONG sa_ReplayStartPoint; // corresponds to RP_Key_I/R
  225. ULONG sa_ReplayLastSeq[MAX_OPS]; // for replay detection - last seq recd
  226. ULONGLONG sa_ReplayBitmap[MAX_OPS]; // for replay detection - 64 packet window
  227. ULONG sa_ReplaySendSeq[MAX_OPS]; // for replay detection - next seq # to send
  228. ULONG sa_ReplayLen; // for replay detection - length of replay field - 32 bits
  229. #if DBG
  230. ULONG sa_d2;
  231. #endif
  232. UCHAR sa_iv[MAX_OPS][DES_BLOCKLEN]; // IV_Key_I/R
  233. ULONG sa_ivlen;
  234. ULONG sa_TruncatedLen; // length of final hash after truncation
  235. LARGE_INTEGER sa_KeyExpirationTime; // time till re-key
  236. LARGE_INTEGER sa_KeyExpirationBytes; // max # of KBytes xformed till re-key
  237. LARGE_INTEGER sa_TotalBytesTransformed; // running total
  238. LARGE_INTEGER sa_KeyExpirationTimeWithPad;
  239. LARGE_INTEGER sa_KeyExpirationBytesWithPad;
  240. LARGE_INTEGER sa_IdleTime; // total time this SA can sit idle
  241. LARGE_INTEGER sa_LastUsedTime; // time this SA was used last
  242. #if DBG
  243. ULONG sa_d3;
  244. #endif
  245. LIFETIME sa_Lifetime;
  246. ULONG sa_BlockedDataLen; // amount of pended data
  247. PNDIS_BUFFER sa_BlockedBuffer; // stall queue of 1 Mdl chain
  248. #if DBG
  249. ULONG sa_d4;
  250. #endif
  251. Interface *sa_IPIF;
  252. IPSEC_TIMER sa_Timer; // Timer struct for timer queue
  253. ULONG sa_ExpiryTime; // time until this SA expires
  254. NDIS_HANDLE sa_OffloadHandle;
  255. LONG sa_NumSends;
  256. WORK_QUEUE_ITEM sa_QueueItem;
  257. ULONG sa_IPSecOverhead;
  258. ULONG sa_NewMTU;
  259. DWORD sa_QMPFSGroup;
  260. IKE_COOKIE_PAIR sa_CookiePair;
  261. IPSEC_SA_STATS sa_Stats;
  262. UCHAR sa_DestType;
  263. IPSEC_SA_UDP_ENCAP_TYPE sa_EncapType;
  264. IPSEC_UDP_ENCAP_CONTEXT sa_EncapContext;
  265. IPAddr sa_PeerPrivateAddr;
  266. } SA_TABLE_ENTRY, *PSA_TABLE_ENTRY;
  267. //
  268. // Context used between Key manager and IPSEC. Points to the Larval SA basically.
  269. //
  270. typedef struct _IPSEC_ACQUIRE_CONTEXT {
  271. ULONG AcquireId; // unique ID to represent this transaction
  272. PSA_TABLE_ENTRY pSA; // larval SA should contain this ID
  273. } IPSEC_ACQUIRE_CONTEXT, *PIPSEC_ACQUIRE_CONTEXT;
  274. //
  275. // Packet Classification/Policy Setting is similar to that of the
  276. // Filter Driver. We dont have filters per interface, however.
  277. //
  278. typedef struct _FILTER {
  279. ULONG Signature; // contains 4602
  280. BOOLEAN TunnelFilter;
  281. BOOLEAN LinkedFilter; // true if on linked list
  282. USHORT Flags;
  283. PFILTER_CACHE FilterCache; // back pointer to cache entry so we can disable it when filter is deleted
  284. LIST_ENTRY MaskedLinkage;
  285. ULARGE_INTEGER uliSrcDstAddr;
  286. ULARGE_INTEGER uliSrcDstMask;
  287. ULARGE_INTEGER uliProtoSrcDstPort;
  288. ULARGE_INTEGER uliProtoSrcDstMask;
  289. IPAddr TunnelAddr;
  290. ULONG Reference; // ref count
  291. LONG SAChainSize; // number of entries for SA chain hash
  292. ULONG Index; // hinted index
  293. GUID PolicyId; // policy GUID
  294. GUID FilterId; // filter GUID
  295. #if GPC
  296. union {
  297. LIST_ENTRY GpcLinkage;
  298. struct _GPC_FILTER {
  299. GPC_HANDLE GpcCfInfoHandle;
  300. GPC_HANDLE GpcPatternHandle;
  301. } GpcFilter;
  302. };
  303. #endif
  304. LIST_ENTRY SAChain[1]; // chain of SAs associated with this Filter
  305. } FILTER, *PFILTER;
  306. //
  307. // a first level cache, contains IP headers cached for fast lookups
  308. //
  309. typedef struct _FILTER_CACHE {
  310. ULARGE_INTEGER uliSrcDstAddr;
  311. ULARGE_INTEGER uliProtoSrcDstPort;
  312. BOOLEAN FilterEntry; // if TRUE, the next one is a Filter
  313. union {
  314. PSA_TABLE_ENTRY pSAEntry; // points to the associated SAEntry
  315. PFILTER pFilter; // points to the (drop/PassThru filter)
  316. };
  317. PSA_TABLE_ENTRY pNextSAEntry; // points to the associated NextSAEntry
  318. #if DBG
  319. ULARGE_INTEGER CacheHitCount;
  320. #endif
  321. } FILTER_CACHE, *PFILTER_CACHE;
  322. //
  323. // Hash tables for specific SAs
  324. //
  325. typedef struct _SA_HASH {
  326. LIST_ENTRY SAList;
  327. } SA_HASH, *PSA_HASH;
  328. //
  329. // This structure is used to hold on to an Irp from the Key manager.
  330. // The Irp is completed to kick off an SA negotiation.
  331. //
  332. typedef struct _IPSEC_ACQUIRE_INFO {
  333. PIRP Irp; // irp passed down from Key manager
  334. LIST_ENTRY PendingAcquires; // linked list of pending acquire requests
  335. LIST_ENTRY PendingNotifies; // linked list of pending notifications
  336. KSPIN_LOCK Lock;
  337. BOOLEAN ResolvingNow; // irp is in user mode doing a resolve
  338. BOOLEAN InMe; // irp is in user mode doing a resolve
  339. } IPSEC_ACQUIRE_INFO, *PIPSEC_ACQUIRE_INFO;
  340. //
  341. // Buffer for lookaside list descriptors. Lookaside list descriptors
  342. // cannot be statically allocated, as they need to ALWAYS be nonpageable,
  343. // even when the entire driver is paged out.
  344. //
  345. typedef struct _IPSEC_LOOKASIDE_LISTS {
  346. NPAGED_LOOKASIDE_LIST SendCompleteCtxList;
  347. NPAGED_LOOKASIDE_LIST LargeBufferList;
  348. NPAGED_LOOKASIDE_LIST SmallBufferList;
  349. } IPSEC_LOOKASIDE_LISTS, *PIPSEC_LOOKASIDE_LISTS;
  350. //
  351. // Data is organized as an MDL followed by the actual buffer being described by
  352. // the mdl.
  353. //
  354. // !!NOTE: In the struct below, Data should be quadaligned since MDLs are always
  355. // quad-aligned.
  356. //
  357. typedef struct _IPSEC_LA_BUFFER {
  358. ULONG Tag; // the actual tag this was used for
  359. PVOID Buffer; // the actual buffer
  360. ULONG BufferLength; // length of the buffer pointed by MDL
  361. PMDL Mdl; // pointer to an MDL describing the buffer
  362. UCHAR Data[1]; // the real data starts here
  363. } IPSEC_LA_BUFFER, *PIPSEC_LA_BUFFER;
  364. #define IPSEC_STATEFUL_HASH_TABLE_SIZE 1000
  365. typedef struct _IPSEC_STATEFUL_HASH_TABLE{
  366. // Array of lists
  367. // Lists of IPSEC_STATEFUL_ENTRY
  368. LIST_ENTRY Entry[IPSEC_STATEFUL_HASH_TABLE_SIZE];
  369. }IPSEC_STATEFUL_HASH_TABLE, *PIPSEC_STATEFUL_HASH_TABLE;
  370. // Always stored outbound
  371. // Allocated from IPSEC_HASH_BUFFER_POOL
  372. // Stored in IPSEC_STATEFUL_HASH_TABLE
  373. typedef struct _IPSEC_STATEFUL_ENTRY {
  374. LIST_ENTRY CollisionLinkage;
  375. IPAddr SrcAddr;
  376. IPAddr DestAddr;
  377. BYTE Protocol;
  378. USHORT SrcPort;
  379. USHORT DestPort;
  380. } IPSEC_STATEFUL_ENTRY, *PIPSEC_STATEFUL_ENTRY;
  381. #define TOTAL_STATEFUL_ENTRY_COUNT 10000
  382. //Write access to SADBLock required for allocation
  383. //Cycle around when full.
  384. //Use list entries in the IPSEC_STATEFUL_ENTRY
  385. //to remove from hash table.
  386. typedef struct _IPSEC_HASH_BUFFER_POOL {
  387. ULONG ulEntriesUsed;
  388. ULONG ulCurrentPosition;
  389. IPSEC_STATEFUL_ENTRY PoolEntry[TOTAL_STATEFUL_ENTRY_COUNT];
  390. } IPSEC_HASH_BUFFER_POOL, * PIPSEC_HASH_BUFFER_POOL;
  391. typedef struct _IPSEC_GLOBAL {
  392. BOOLEAN DriverUnloading; // Is driver being unloaded?
  393. BOOLEAN BoundToIP; // Are we bound to IP yet?
  394. BOOLEAN SendBoundToIP; // Is IPSecHandler bound to IP?
  395. BOOLEAN InitCrypto; // Are crypto routines initialized?
  396. BOOLEAN InitRNG; // Is RNG initialized?
  397. BOOLEAN InitTcpip; // Is TCP/IP loaded?
  398. #if FIPS
  399. BOOLEAN InitFips; // Is Fips driver loaded and function table set?
  400. #endif
  401. #if GPC
  402. BOOLEAN InitGpc; // Is GPC driver loaded and function table set?
  403. #endif
  404. LONG NumSends; // counts the number of pending sends
  405. LONG NumThreads; // counts the number of threads in driver
  406. LONG NumWorkers; // counts the number of worker threads
  407. LONG NumTimers; // counts the number of active timers
  408. LONG NumIoctls; // counts the number of active IOCTLs
  409. LIST_ENTRY LarvalSAList;
  410. KSPIN_LOCK LarvalListLock; // protects the larval SA list
  411. MRSW_LOCK SADBLock; // protects the Filter/SA DB
  412. MRSW_LOCK SPIListLock; // protects the SPI list
  413. //
  414. // We partition the filters into tunnel/masked and inbound/outbound filters.
  415. //
  416. LIST_ENTRY FilterList[NUM_FILTERS];
  417. ULONG NumPolicies; // number of filters plumbed in the driver
  418. ULONG NumTunnelFilters;
  419. ULONG NumMaskedFilters;
  420. ULONG NumOutboundSAs;
  421. ULONG NumMulticastFilters;
  422. //
  423. // Inbound <SPI, dest> hash
  424. //
  425. PSA_HASH pSADb;
  426. LONG NumSA;
  427. LONG SAHashSize;
  428. PFILTER_CACHE *ppCache;
  429. ULONG CacheSize;
  430. ULONG CacheHalfSize;
  431. //
  432. // SA negotiate context
  433. //
  434. IPSEC_ACQUIRE_INFO AcquireInfo;
  435. //
  436. // timers
  437. //
  438. KSPIN_LOCK TimerLock;
  439. IPSEC_TIMER_LIST TimerList[IPSEC_CLASS_MAX];
  440. IPSEC_TIMER ReaperTimer; // reaper thread runs here.
  441. //
  442. // Global lookaside lists. These must always be in nonpaged pool,
  443. // even when the driver is paged out.
  444. //
  445. PIPSEC_LOOKASIDE_LISTS IPSecLookasideLists;
  446. ULONG IPSecLargeBufferSize;
  447. ULONG IPSecLargeBufferListDepth;
  448. ULONG IPSecSmallBufferSize;
  449. ULONG IPSecSmallBufferListDepth;
  450. ULONG IPSecSendCompleteCtxSize;
  451. ULONG IPSecSendCompleteCtxDepth;
  452. ULONG IPSecCacheLineSize;
  453. PDEVICE_OBJECT IPSecDevice;
  454. PDRIVER_OBJECT IPSecDriverObject;
  455. ProtInfo IPProtInfo;
  456. IPOptInfo OptInfo;
  457. //
  458. // stats
  459. //
  460. IPSEC_QUERY_STATS Statistics;
  461. DWORD dwPacketsOnWrongSA;
  462. ULONG EnableOffload;
  463. ULONG DefaultSAIdleTime;
  464. ULONG LogInterval;
  465. ULONG EventQueueSize;
  466. ULONG RekeyTime;
  467. ULONG NoDefaultExempt;
  468. KSPIN_LOCK EventLogLock; // lock to protect event queue
  469. IPSEC_TIMER EventLogTimer;
  470. ULONG IPSecBufferedEvents;
  471. PUCHAR IPSecLogMemory;
  472. PUCHAR IPSecLogMemoryLoc;
  473. PUCHAR IPSecLogMemoryEnd;
  474. LARGE_INTEGER SAIdleTime;
  475. #if DBG
  476. ULARGE_INTEGER CacheHitCount;
  477. #endif
  478. OPERATION_MODE OperationMode;
  479. IPSEC_FORWARDING_BEHAVIOR DefaultForwardingBehavior;
  480. ULONG DiagnosticMode;
  481. #if GPC
  482. GPC_EXPORTED_CALLS GpcEntries;
  483. GPC_HANDLE GpcClients[GPC_CF_MAX];
  484. ULONG GpcActive;
  485. ULONG GpcNumFilters[GPC_CF_MAX];
  486. LIST_ENTRY GpcFilterList[NUM_FILTERS];
  487. #if DBG
  488. LARGE_INTEGER GpcTotalPassedIn;
  489. LARGE_INTEGER GpcClassifyNeeded;
  490. LARGE_INTEGER GpcReClassified;
  491. #endif
  492. #endif
  493. #if FIPS
  494. PFILE_OBJECT FipsFileObject;
  495. FIPS_FUNCTION_TABLE FipsFunctionTable;
  496. #endif
  497. PIPSEC_EXEMPT_ENTRY BootExemptList;
  498. ULONG BootExemptListSize; //Entry count
  499. // Pointer to the Hash table
  500. // Initialized in DriverEntry
  501. PIPSEC_STATEFUL_HASH_TABLE BootStatefulHT;
  502. PIPSEC_HASH_BUFFER_POOL BootBufferPool;
  503. LARGE_INTEGER StartTimeDelta;
  504. IPSEC_NATSHIM_FUNCTIONS ShimFunctions;
  505. VOID (*TcpipFreeBuff)(struct IPRcvBuf *);
  506. INT (*TcpipAllocBuff)(struct IPRcvBuf *, UINT);
  507. UCHAR (*TcpipGetAddrType)(IPAddr);
  508. IP_STATUS (*TcpipGetInfo)(IPInfo *, INT);
  509. NDIS_STATUS (*TcpipNdisRequest)(PVOID, NDIS_REQUEST_TYPE, NDIS_OID, PVOID, UINT, PUINT);
  510. PVOID (*TcpipRegisterProtocol)(UCHAR, PVOID, PVOID, PVOID, PVOID, PVOID, PVOID);
  511. NTSTATUS (*TcpipSetIPSecStatus)(BOOLEAN);
  512. IP_STATUS (*TcpipIPTransmit)(PVOID, PVOID, PNDIS_BUFFER, UINT, IPAddr, IPAddr, IPOptInfo *, RouteCacheEntry *, UCHAR, PIRP);
  513. IP_STATUS (*TcpipSetIPSecPtr)(PIPSEC_FUNCTIONS);
  514. IP_STATUS (*TcpipUnSetIPSecPtr)(PIPSEC_FUNCTIONS);
  515. IP_STATUS (*TcpipUnSetIPSecSendPtr)(PIPSEC_FUNCTIONS);
  516. UINT (*TcpipTCPXsum)(UINT, PVOID, UINT);
  517. USHORT (*TcpipGenIpId)();
  518. PVOID (*TcpipDeRegisterProtocol)(UCHAR);
  519. IP_STATUS (*TcpipGetPInfo)(IPAddr, IPAddr, uint *, uint *, RouteCacheEntry *);
  520. IP_STATUS (*TcpipSendICMPErr)(IPAddr, IPHeader UNALIGNED *, uchar, uchar, ulong, uchar);
  521. } IPSEC_GLOBAL, *PIPSEC_GLOBAL;
  522. //
  523. // Contexts used to store eventlog contexts.
  524. //
  525. #define IPSEC_DROP_STATUS_CRYPTO_DONE 0x00000001
  526. #define IPSEC_DROP_STATUS_NEXT_CRYPTO_DONE 0x00000002
  527. #define IPSEC_DROP_STATUS_SA_DELETE_REQ 0x00000004
  528. #define IPSEC_DROP_STATUS_DONT_LOG 0x00000008
  529. typedef struct _IPSEC_DROP_STATUS {
  530. ULONG IPSecStatus;
  531. ULONG OffloadStatus;
  532. ULONG Flags;
  533. } IPSEC_DROP_STATUS, *PIPSEC_DROP_STATUS;
  534. typedef struct _IPSEC_EVENT_CTX {
  535. IPAddr Addr;
  536. ULONG EventCode;
  537. ULONG UniqueEventValue;
  538. ULONG EventCount;
  539. PUCHAR pPacket;
  540. ULONG PacketSize;
  541. IPSEC_DROP_STATUS DropStatus;
  542. } IPSEC_EVENT_CTX, *PIPSEC_EVENT_CTX;
  543. typedef struct _IPSEC_NOTIFY_EXPIRE {
  544. LIST_ENTRY notify_PendingLinkage; // linkage in pending SA list - waiting for Acquire Irp
  545. ULARGE_INTEGER sa_uliSrcDstAddr;
  546. ULARGE_INTEGER sa_uliSrcDstMask;
  547. ULARGE_INTEGER sa_uliProtoSrcDstPort;
  548. IPAddr sa_TunnelAddr; // Tunnel end IP Addr
  549. IPAddr sa_InboundTunnelAddr; // Tunnel end IP Addr
  550. tSPI InboundSpi; // Inbound: in the multiple ops case, this is the SPI of the last operation.
  551. tSPI OutboundSpi;
  552. IKE_COOKIE_PAIR sa_CookiePair;
  553. DWORD Flags;
  554. IPSEC_UDP_ENCAP_CONTEXT sa_EncapContext;
  555. IPAddr sa_PeerPrivateAddr;
  556. } IPSEC_NOTIFY_EXPIRE, *PIPSEC_NOTIFY_EXPIRE;
  557. typedef IPSEC_ADD_UPDATE_SA IPSEC_ADD_SA, *PIPSEC_ADD_SA;
  558. typedef IPSEC_ADD_UPDATE_SA IPSEC_UPDATE_SA, *PIPSEC_UPDATE_SA;
  559. #define IPSEC_ADD_SA_NO_KEY_SIZE FIELD_OFFSET(IPSEC_ADD_SA, SAInfo.KeyMat[0])
  560. #define IPSEC_UPDATE_SA_NO_KEY_SIZE FIELD_OFFSET(IPSEC_UPDATE_SA, SAInfo.KeyMat[0])
  561. typedef struct _PARSER_IFENTRY {
  562. struct _PARSER_IFENTRY * pNext;
  563. UDP_ENCAP_TYPE UdpEncapType;
  564. USHORT usDstEncapPort;
  565. HANDLE hInterface;
  566. HANDLE hParserIfOffload;
  567. ULONG uRefCnt;
  568. } PARSER_IFENTRY, * PPARSER_IFENTRY;
  569. //
  570. // Contexts used to store SA plumbing contexts.
  571. //
  572. typedef struct _IPSEC_PLUMB_SA {
  573. Interface *DestIF;
  574. PSA_TABLE_ENTRY pSA;
  575. PPARSER_IFENTRY pParserIfEntry;
  576. PUCHAR Buf;
  577. ULONG Len;
  578. WORK_QUEUE_ITEM PlumbQueueItem;
  579. } IPSEC_PLUMB_SA, *PIPSEC_PLUMB_SA;
  580. typedef struct _IPSEC_MTU_CONTEXT {
  581. IPAddr Src;
  582. IPAddr TransportDest;
  583. IPAddr TunnelDest;
  584. tSPI TransportSPI;
  585. tSPI TunnelSPI;
  586. } IPSEC_MTU_CONTEXT, *PIPSEC_MTU_CONTEXT;
  587. //
  588. // Contexts used to log events
  589. //
  590. typedef struct _IPSEC_LOG_EVENT {
  591. LONG LogSize;
  592. WORK_QUEUE_ITEM LogQueueItem;
  593. UCHAR pLog[1];
  594. } IPSEC_LOG_EVENT, *PIPSEC_LOG_EVENT;
  595. #define PROTOCOL_UDP 17
  596. #define TCP_HEADER_SIZE 20
  597. #define UDP_HEADER_SIZE 8
  598. #define MIN_ACQUIRE_ID 5
  599. #endif _GLOBALS_H