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.

625 lines
14 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. rawlog.h (Centralized Binary (Raw) Logging v1.0)
  5. Abstract:
  6. This module implements the centralized raw logging
  7. format. Internet Binary Logs (file format).
  8. Author:
  9. Ali E. Turkoglu (aliTu) 02-Oct-2001
  10. Revision History:
  11. ---
  12. --*/
  13. #ifndef _RAWLOG_H_
  14. #define _RAWLOG_H_
  15. //
  16. // Forwarders
  17. //
  18. typedef struct _UL_INTERNAL_REQUEST *PUL_INTERNAL_REQUEST;
  19. ///////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Global definitions
  22. //
  23. ///////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Version numbers for the original raw binary format.
  26. //
  27. #define MAJOR_RAW_LOG_FILE_VERSION (1)
  28. #define MINOR_RAW_LOG_FILE_VERSION (0)
  29. //
  30. // Normally computer name is defined as 256 wchars.
  31. //
  32. #define MAX_COMPUTER_NAME_LEN (256)
  33. //
  34. // The rawfile record types. Add to the end. Do not change
  35. // the existing values for types.
  36. //
  37. #define HTTP_RAW_RECORD_HEADER_TYPE (0)
  38. #define HTTP_RAW_RECORD_FOOTER_TYPE (1)
  39. #define HTTP_RAW_RECORD_INDEX_DATA_TYPE (2)
  40. #define HTTP_RAW_RECORD_HIT_LOG_DATA_TYPE (3)
  41. #define HTTP_RAW_RECORD_MISS_LOG_DATA_TYPE (4)
  42. #define HTTP_RAW_RECORD_CACHE_NOTIFICATION_DATA_TYPE (5)
  43. #define HTTP_RAW_RECORD_MAX_TYPE (6)
  44. //
  45. // Every record type should be PVOID aligned.
  46. //
  47. //
  48. // Header structure to identify the rawfile.
  49. // Header record allows validation check for the file, and
  50. // the movement of logs from one computer to another for post
  51. // processing w/o loosing the source of the logs.
  52. //
  53. typedef struct _HTTP_RAW_FILE_HEADER
  54. {
  55. //
  56. // Must be HTTP_RAW_RECORD_HEADER_TYPE.
  57. //
  58. USHORT RecordType;
  59. //
  60. // Identifies the version of the Internet Binary Log File.
  61. //
  62. union {
  63. struct {
  64. UCHAR MajorVersion; // MAJOR_RAW_LOG_FILE_VERSION
  65. UCHAR MinorVersion; // MINOR_RAW_LOG_FILE_VERSION
  66. };
  67. USHORT Version;
  68. };
  69. //
  70. // Shows the alignment padding size. sizeof(PVOID).
  71. //
  72. ULONG AlignmentSize;
  73. //
  74. // Timestamp for the raw file creation/opening.
  75. //
  76. LARGE_INTEGER DateTime;
  77. //
  78. // Name of the Server which created/opened the raw file.
  79. //
  80. WCHAR ComputerName[MAX_COMPUTER_NAME_LEN];
  81. } HTTP_RAW_FILE_HEADER, *PHTTP_RAW_FILE_HEADER;
  82. C_ASSERT( MAX_COMPUTER_NAME_LEN ==
  83. ALIGN_UP(MAX_COMPUTER_NAME_LEN,PVOID) );
  84. C_ASSERT( sizeof(HTTP_RAW_FILE_HEADER) ==
  85. ALIGN_UP(sizeof(HTTP_RAW_FILE_HEADER), PVOID));
  86. //
  87. // The file footer exists as an integrity check for the
  88. // post processing utilities.
  89. //
  90. typedef struct _HTTP_RAW_FILE_FOOTER
  91. {
  92. //
  93. // Must be HTTP_RAW_RECORD_FOOTER_TYPE.
  94. //
  95. USHORT RecordType;
  96. //
  97. // Reserved for alignment
  98. //
  99. USHORT Padding[3];
  100. //
  101. // Timestamp for the raw file close time.
  102. //
  103. LARGE_INTEGER DateTime;
  104. } HTTP_RAW_FILE_FOOTER, *PHTTP_RAW_FILE_FOOTER;
  105. C_ASSERT( sizeof(HTTP_RAW_FILE_FOOTER) ==
  106. ALIGN_UP(sizeof(HTTP_RAW_FILE_FOOTER), PVOID));
  107. //
  108. // Whenever Internal URI Cache is flushed we notify
  109. // binary log file parser to drop its own cache by
  110. // writing this record to the file.
  111. //
  112. typedef struct _HTTP_RAW_FILE_CACHE_NOTIFICATION
  113. {
  114. //
  115. // Must be HTTP_RAW_RECORD_CACHE_NOTIFICATION_DATA_TYPE.
  116. //
  117. USHORT RecordType;
  118. //
  119. // Reserved for alignment
  120. //
  121. USHORT Reserved[3];
  122. } HTTP_RAW_FILE_CACHE_NOTIFICATION,
  123. *PHTTP_RAW_FILE_CACHE_NOTIFICATION;
  124. C_ASSERT( sizeof(HTTP_RAW_FILE_CACHE_NOTIFICATION) ==
  125. ALIGN_UP(sizeof(HTTP_RAW_FILE_CACHE_NOTIFICATION), PVOID));
  126. //
  127. // Unique identifier for the url.
  128. //
  129. typedef struct _HTTP_RAWLOGID
  130. {
  131. //
  132. // The virtual address of the cache entry (from uri cache)
  133. //
  134. ULONG AddressLowPart;
  135. ULONG AddressHighPart;
  136. } HTTP_RAWLOGID, *PHTTP_RAWLOGID;
  137. //
  138. // It's IPv6 only if the corresponding flag is set in the
  139. // options.
  140. //
  141. typedef struct _HTTP_RAWLOG_IPV4_ADDRESSES {
  142. ULONG Client;
  143. ULONG Server;
  144. } HTTP_RAWLOG_IPV4_ADDRESSES, *PHTTP_RAWLOG_IPV4_ADDRESSES;
  145. C_ASSERT( sizeof(HTTP_RAWLOG_IPV4_ADDRESSES) ==
  146. ALIGN_UP(sizeof(HTTP_RAWLOG_IPV4_ADDRESSES), PVOID));
  147. typedef struct _HTTP_RAWLOG_IPV6_ADDRESSES {
  148. USHORT Client[8];
  149. USHORT Server[8];
  150. } HTTP_RAWLOG_IPV6_ADDRESSES, *PHTTP_RAWLOG_IPV6_ADDRESSES;
  151. C_ASSERT( sizeof(HTTP_RAWLOG_IPV6_ADDRESSES) ==
  152. ALIGN_UP(sizeof(HTTP_RAWLOG_IPV6_ADDRESSES), PVOID));
  153. //
  154. // Binary Log Protocol Version Field Values
  155. //
  156. #define BINARY_LOG_PROTOCOL_VERSION_UNKNWN (0)
  157. #define BINARY_LOG_PROTOCOL_VERSION_HTTP09 (1)
  158. #define BINARY_LOG_PROTOCOL_VERSION_HTTP10 (2)
  159. #define BINARY_LOG_PROTOCOL_VERSION_HTTP11 (3)
  160. //
  161. // Record type for the cache-hit case.
  162. //
  163. typedef struct _HTTP_RAW_FILE_HIT_LOG_DATA
  164. {
  165. //
  166. // Type must be HTTP_RAW_RECORD_HIT_LOG_DATA_TYPE.
  167. //
  168. USHORT RecordType;
  169. //
  170. // Optional flags.
  171. //
  172. union
  173. {
  174. struct
  175. {
  176. USHORT IPv6:1; // IPv6 or not
  177. USHORT ProtocolVersion:3; // HTTP1.0 or HTTP1.1
  178. USHORT Method:6; // HTTP_VERB
  179. USHORT Reserved:6;
  180. };
  181. USHORT Value;
  182. } Flags;
  183. //
  184. // Site ID. Represents which site owns this log record.
  185. //
  186. ULONG SiteID;
  187. //
  188. // Timestamp for the Log Hit.
  189. //
  190. LARGE_INTEGER DateTime;
  191. USHORT ServerPort;
  192. //
  193. // ProtocolStatus won't be bigger than 999.
  194. //
  195. USHORT ProtocolStatus;
  196. //
  197. // Other send completion results...
  198. //
  199. ULONG Win32Status;
  200. ULONGLONG TimeTaken;
  201. ULONGLONG BytesSent;
  202. ULONGLONG BytesReceived;
  203. //
  204. // For cache hits there will always be a UriStem Index record
  205. // written prior to this record.
  206. //
  207. HTTP_RAWLOGID UriStemId;
  208. //
  209. // Below variable Length Fields follows the structure.
  210. //
  211. // Client IP Address (v4 or v6) - 4 or 16 bytes
  212. // Server IP Address (v4 or v6) - 4 or 16 bytes
  213. } HTTP_RAW_FILE_HIT_LOG_DATA, *PHTTP_RAW_FILE_HIT_LOG_DATA;
  214. C_ASSERT( sizeof(HTTP_RAW_FILE_HIT_LOG_DATA) ==
  215. ALIGN_UP(sizeof(HTTP_RAW_FILE_HIT_LOG_DATA), PVOID));
  216. //
  217. // Record type for the cache-miss case.
  218. //
  219. typedef struct _HTTP_RAW_FILE_MISS_LOG_DATA
  220. {
  221. //
  222. // Type must be HTTP_RAW_RECORD_MISS_LOG_DATA_TYPE.
  223. //
  224. USHORT RecordType;
  225. //
  226. // Optional IPv6 flag and the version and the method
  227. // fields are compacted inside a ushort.
  228. //
  229. union
  230. {
  231. struct
  232. {
  233. USHORT IPv6:1; // IPv6 or not
  234. USHORT ProtocolVersion:3; // HTTP1.0 or HTTP1.1
  235. USHORT Method:6; // HTTP_VERB
  236. USHORT Reserved:6;
  237. };
  238. USHORT Value;
  239. } Flags;
  240. //
  241. // Site ID. Represents which site owns this log record.
  242. //
  243. ULONG SiteID;
  244. LARGE_INTEGER DateTime;
  245. USHORT ServerPort;
  246. //
  247. // ProtocolStatus won't be bigger than 999.
  248. //
  249. USHORT ProtocolStatus;
  250. //
  251. // Other send completion results...
  252. //
  253. ULONG Win32Status;
  254. ULONGLONG TimeTaken;
  255. ULONGLONG BytesSent;
  256. ULONGLONG BytesReceived;
  257. USHORT SubStatus;
  258. //
  259. // Variable length fields follows the structure.
  260. //
  261. USHORT UriStemSize;
  262. USHORT UriQuerySize;
  263. USHORT UserNameSize;
  264. // Client IP Address (v4 or v6) - 4 or 16 bytes
  265. // Server IP Address (v4 or v6) - 4 or 16 bytes
  266. // URI Stem - UriStemSize bytes
  267. // URI Query - UriQuerySize bytes
  268. // UserName - ALIGN_UP(UserNameSize,PVOID) bytes
  269. } HTTP_RAW_FILE_MISS_LOG_DATA, *PHTTP_RAW_FILE_MISS_LOG_DATA;
  270. C_ASSERT( sizeof(HTTP_RAW_FILE_MISS_LOG_DATA) ==
  271. ALIGN_UP(sizeof(HTTP_RAW_FILE_MISS_LOG_DATA), PVOID));
  272. //
  273. // For cache hits, the uri is logged as a variable string for the
  274. // first time. Later hits refers to this index's HTTP_RAWLOGID.
  275. //
  276. #define URI_BYTES_INLINED (4)
  277. #define URI_WCHARS_INLINED (URI_BYTES_INLINED/sizeof(WCHAR))
  278. typedef struct _HTTP_RAW_INDEX_FIELD_DATA
  279. {
  280. //
  281. // HTTP_RAW_RECORD_INDEX_DATA_TYPE.
  282. //
  283. USHORT RecordType;
  284. //
  285. // Size of the variable size string (in bytes).
  286. // When reading and writing need to align the DIFF(Size - 4)
  287. // up to PVOID.
  288. //
  289. USHORT Size;
  290. //
  291. // Unique Id for the uri.
  292. //
  293. HTTP_RAWLOGID Id;
  294. //
  295. // Variable size string follows immediately after the structure.
  296. // Array of 4 bytes is defined to be able to make it PVOID aligned
  297. // on ia64. Typically uris will be bigger than 4 byte.
  298. //
  299. WCHAR Str[URI_WCHARS_INLINED];
  300. } HTTP_RAW_INDEX_FIELD_DATA, *PHTTP_RAW_INDEX_FIELD_DATA;
  301. C_ASSERT( sizeof(HTTP_RAW_INDEX_FIELD_DATA) ==
  302. ALIGN_UP(sizeof(HTTP_RAW_INDEX_FIELD_DATA), PVOID));
  303. //
  304. // Macro to check the sanity of the raw file records.
  305. //
  306. #define IS_VALID_RAW_FILE_RECORD( pRecord ) \
  307. ( (pRecord) != NULL && \
  308. (pRecord)->RecordType >= 0 && \
  309. (pRecord)->RecordType <= HTTP_RAW_RECORD_MAX_TYPE \
  310. )
  311. //
  312. // One and only one binary log file entry manages the one centralized
  313. // binary log file for all sites. It is resident in the memory during
  314. // the lifetime of the driver.
  315. //
  316. typedef struct _UL_BINARY_LOG_FILE_ENTRY
  317. {
  318. //
  319. // Must be UL_BINARY_LOG_FILE_ENTRY_POOL_TAG.
  320. //
  321. ULONG Signature;
  322. //
  323. // This lock protects the shared writes and exclusive flushes.
  324. // It has to be push lock since the ZwWrite operation
  325. // cannot run at APC_LEVEL.
  326. //
  327. UL_PUSH_LOCK PushLock;
  328. //
  329. // The name of the file. Full path including the directory.
  330. //
  331. UNICODE_STRING FileName;
  332. PWSTR pShortName;
  333. //
  334. // Following will be NULL until a request comes in to the
  335. // site that this entry represents.
  336. //
  337. PUL_LOG_FILE_HANDLE pLogFile;
  338. //
  339. // Private config information.
  340. //
  341. HTTP_LOGGING_PERIOD Period;
  342. ULONG TruncateSize;
  343. //
  344. // The following fields are used to determine when/how to
  345. // recycle the log file.
  346. //
  347. ULONG TimeToExpire; // In Hours
  348. ULONG SequenceNumber; // When entry has MAX_SIZE or UNLIMITED period.
  349. ULARGE_INTEGER TotalWritten; // In Bytes
  350. //
  351. // File for the entry is automatically closed every 15
  352. // minutes. This is to track the idle time. This value
  353. // is in number of buffer flush periods, which's 1 minute
  354. // by default.
  355. //
  356. ULONG TimeToClose;
  357. //
  358. // For Log File ReCycling based on GMT time.
  359. // And periodic buffer flushing.
  360. //
  361. UL_LOG_TIMER BufferTimer;
  362. UL_LOG_TIMER Timer;
  363. UL_WORK_ITEM WorkItem; // For the pasive worker
  364. union
  365. {
  366. //
  367. // Flags to show the entry states mostly. Used by
  368. // recycling.
  369. //
  370. ULONG Value;
  371. struct
  372. {
  373. ULONG StaleSequenceNumber:1;
  374. ULONG StaleTimeToExpire:1;
  375. ULONG HeaderWritten:1;
  376. ULONG HeaderFlushPending:1;
  377. ULONG RecyclePending:1;
  378. ULONG Active:1;
  379. ULONG LocaltimeRollover:1;
  380. ULONG CreateFileFailureLogged:1;
  381. ULONG WriteFailureLogged:1;
  382. ULONG CacheFlushInProgress:1;
  383. };
  384. } Flags;
  385. ULONG ServedCacheHit;
  386. //
  387. // The default buffer size is g_AllocationGranularity.
  388. // The operating system's allocation granularity.
  389. //
  390. PUL_LOG_FILE_BUFFER LogBuffer;
  391. } UL_BINARY_LOG_FILE_ENTRY, *PUL_BINARY_LOG_FILE_ENTRY;
  392. #define IS_VALID_BINARY_LOG_FILE_ENTRY( pEntry ) \
  393. HAS_VALID_SIGNATURE(pEntry, UL_BINARY_LOG_FILE_ENTRY_POOL_TAG)
  394. //
  395. // Bitfields reserved for Method should be big enough to hold the max verb.
  396. //
  397. C_ASSERT(((USHORT)HttpVerbMaximum) < ((1 << 6) - 1));
  398. ///////////////////////////////////////////////////////////////////////////////
  399. //
  400. // Exported functions
  401. //
  402. ///////////////////////////////////////////////////////////////////////////////
  403. NTSTATUS
  404. UlInitializeBinaryLog(
  405. VOID
  406. );
  407. VOID
  408. UlTerminateBinaryLog(
  409. VOID
  410. );
  411. NTSTATUS
  412. UlCreateBinaryLogEntry(
  413. IN OUT PUL_CONTROL_CHANNEL pControlChannel,
  414. IN PHTTP_CONTROL_CHANNEL_BINARY_LOGGING pUserConfig
  415. );
  416. NTSTATUS
  417. UlCaptureRawLogData(
  418. IN PHTTP_LOG_FIELDS_DATA pUserData,
  419. IN PUL_INTERNAL_REQUEST pRequest,
  420. OUT PUL_LOG_DATA_BUFFER *ppLogData
  421. );
  422. NTSTATUS
  423. UlRawLogHttpHit(
  424. IN PUL_LOG_DATA_BUFFER pLogBuffer
  425. );
  426. NTSTATUS
  427. UlRawLogHttpCacheHit(
  428. IN PUL_FULL_TRACKER pTracker
  429. );
  430. VOID
  431. UlRemoveBinaryLogEntry(
  432. IN PUL_CONTROL_CHANNEL pControlChannel
  433. );
  434. NTSTATUS
  435. UlReConfigureBinaryLogEntry(
  436. IN OUT PUL_CONTROL_CHANNEL pControlChannel,
  437. IN PHTTP_CONTROL_CHANNEL_BINARY_LOGGING pCfgCurrent,
  438. IN PHTTP_CONTROL_CHANNEL_BINARY_LOGGING pCfgNew
  439. );
  440. VOID
  441. UlHandleCacheFlushedNotification(
  442. IN PUL_CONTROL_CHANNEL pControlChannel
  443. );
  444. VOID
  445. UlDisableIndexingForCacheHits(
  446. IN PUL_CONTROL_CHANNEL pControlChannel
  447. );
  448. #endif // _RAWLOG_H_