-
Notifications
You must be signed in to change notification settings - Fork 536
/
quic_trace.h
371 lines (306 loc) · 13.5 KB
/
quic_trace.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
Abstract:
MsQuic defines two classes of tracing:
Events These are well-defined and have explicit formats. Each event is
defined with its own, unique function. These are generally used
for automated log processing (quicetw for instance).
Logs These use a printf style format for generally tracing more
detailed information than Events, and are purely for human
consumption.
Each class is individually configurable at compile time. Different platforms
or build configurations can have their own desired behavior. The following
configuration options are currently supported:
QUIC_EVENTS_STUB No-op all Events
QUIC_EVENTS_MANIFEST_ETW Write to Windows ETW framework
QUIC_EVENTS_STDOUT Write to stdout
QUIC_LOGS_STUB No-op all Logs
QUIC_LOGS_MANIFEST_ETW Write to Windows ETW framework
QUIC_LOGS_STDOUT Write to stdout
QUIC_CLOG Bypasses these mechanisms and uses CLOG to generate logging
--*/
#pragma once
#if !defined(QUIC_CLOG)
#if !defined(QUIC_EVENTS_STUB) && !defined(QUIC_EVENTS_MANIFEST_ETW) && !defined(QUIC_EVENTS_STDOUT)
#error "Must define one QUIC_EVENTS_*"
#endif
#if !defined(QUIC_LOGS_STUB) && !defined(QUIC_LOGS_MANIFEST_ETW) && !defined(QUIC_LOGS_STDOUT)
#error "Must define one QUIC_LOGS_*"
#endif
#endif
//
// Every data structure here has a matching ETW manifest definition. If you
// want to add something new, be sure to append it to the relevant enum block so
// as to preserve the existing values / order.
//
typedef enum QUIC_FLOW_BLOCK_REASON {
QUIC_FLOW_BLOCKED_SCHEDULING = 0x01,
QUIC_FLOW_BLOCKED_PACING = 0x02,
QUIC_FLOW_BLOCKED_AMPLIFICATION_PROT = 0x04,
QUIC_FLOW_BLOCKED_CONGESTION_CONTROL = 0x08,
QUIC_FLOW_BLOCKED_CONN_FLOW_CONTROL = 0x10,
QUIC_FLOW_BLOCKED_STREAM_ID_FLOW_CONTROL= 0x20,
QUIC_FLOW_BLOCKED_STREAM_FLOW_CONTROL = 0x40,
QUIC_FLOW_BLOCKED_APP = 0x80
} QUIC_FLOW_BLOCK_REASON;
typedef enum QUIC_TRACE_PACKET_TYPE {
QUIC_TRACE_PACKET_VN,
QUIC_TRACE_PACKET_INITIAL,
QUIC_TRACE_PACKET_ZERO_RTT,
QUIC_TRACE_PACKET_HANDSHAKE,
QUIC_TRACE_PACKET_RETRY,
QUIC_TRACE_PACKET_ONE_RTT
} QUIC_TRACE_PACKET_TYPE;
typedef enum QUIC_TRACE_PACKET_LOSS_REASON {
QUIC_TRACE_PACKET_LOSS_RACK,
QUIC_TRACE_PACKET_LOSS_FACK,
QUIC_TRACE_PACKET_LOSS_PROBE
} QUIC_TRACE_PACKET_LOSS_REASON;
typedef enum QUIC_TRACE_API_TYPE {
QUIC_TRACE_API_SET_PARAM,
QUIC_TRACE_API_GET_PARAM,
QUIC_TRACE_API_REGISTRATION_OPEN,
QUIC_TRACE_API_REGISTRATION_CLOSE,
QUIC_TRACE_API_REGISTRATION_SHUTDOWN,
QUIC_TRACE_API_CONFIGURATION_OPEN,
QUIC_TRACE_API_CONFIGURATION_CLOSE,
QUIC_TRACE_API_CONFIGURATION_LOAD_CREDENTIAL,
QUIC_TRACE_API_LISTENER_OPEN,
QUIC_TRACE_API_LISTENER_CLOSE,
QUIC_TRACE_API_LISTENER_START,
QUIC_TRACE_API_LISTENER_STOP,
QUIC_TRACE_API_CONNECTION_OPEN,
QUIC_TRACE_API_CONNECTION_CLOSE,
QUIC_TRACE_API_CONNECTION_SHUTDOWN,
QUIC_TRACE_API_CONNECTION_START,
QUIC_TRACE_API_CONNECTION_SET_CONFIGURATION,
QUIC_TRACE_API_CONNECTION_SEND_RESUMPTION_TICKET,
QUIC_TRACE_API_STREAM_OPEN,
QUIC_TRACE_API_STREAM_CLOSE,
QUIC_TRACE_API_STREAM_START,
QUIC_TRACE_API_STREAM_SHUTDOWN,
QUIC_TRACE_API_STREAM_SEND,
QUIC_TRACE_API_STREAM_RECEIVE_COMPLETE,
QUIC_TRACE_API_STREAM_RECEIVE_SET_ENABLED,
QUIC_TRACE_API_DATAGRAM_SEND,
QUIC_TRACE_API_CONNECTION_COMPLETE_RESUMPTION_TICKET_VALIDATION,
QUIC_TRACE_API_CONNECTION_COMPLETE_CERTIFICATE_VALIDATION,
QUIC_TRACE_API_COUNT // Must be last
} QUIC_TRACE_API_TYPE;
//
// Called from the platform code to trigger a tracing rundown for all objects
// in the current process (or kernel mode).
//
#ifdef __cplusplus
extern "C"
#endif
typedef
_Function_class_(QUIC_TRACE_RUNDOWN_CALLBACK)
_IRQL_requires_max_(PASSIVE_LEVEL)
void
(QUIC_TRACE_RUNDOWN_CALLBACK)(
void
);
extern QUIC_TRACE_RUNDOWN_CALLBACK* QuicTraceRundownCallback;
#ifdef QUIC_CLOG
#if DEBUG
#define QuicTraceLogStreamVerboseEnabled() TRUE
#define QuicTraceLogErrorEnabled() TRUE
#define QuicTraceLogWarningEnabled() TRUE
#define QuicTraceLogInfoEnabled() TRUE
#define QuicTraceLogVerboseEnabled() TRUE
#define QuicTraceEventEnabled(x) TRUE
#else
#define QuicTraceLogStreamVerboseEnabled() FALSE
#define QuicTraceLogErrorEnabled() FALSE
#define QuicTraceLogWarningEnabled() FALSE
#define QuicTraceLogInfoEnabled() FALSE
#define QuicTraceLogVerboseEnabled() FALSE
#define QuicTraceEventEnabled(x) FALSE
#endif
#define CASTED_CLOG_BYTEARRAY(Len, Data) CLOG_BYTEARRAY((unsigned char)(Len), (const unsigned char*)(Data))
#define CASTED_CLOG_BYTEARRAY16(Len, Data) CLOG_BYTEARRAY((unsigned short)(Len), (const unsigned char*)(Data))
#else
#if defined(QUIC_EVENTS_STDOUT) || defined(QUIC_LOGS_STDOUT) || \
defined(QUIC_EVENTS_STUB) || defined(QUIC_LOGS_STUB)
struct clog_param {
char * str;
struct clog_param * next;
};
#if defined(QUIC_EVENTS_STDOUT) || defined(QUIC_LOGS_STDOUT)
extern
#ifdef __cplusplus
"C"
#endif
void //__attribute__((no_instrument_function, format(printf, 2, 3)))
clog_stdout(struct clog_param * head, const char * format, ...);
#else
inline void //__attribute__((no_instrument_function, format(printf, 2, 3)))
clog_stdout(struct clog_param * head, const char * format, ...)
{
UNREFERENCED_PARAMETER(head);
UNREFERENCED_PARAMETER(format);
}
#endif
#define clog(Fmt, ...) \
do { \
struct clog_param * __head = 0; \
clog_stdout(__head, (Fmt), ##__VA_ARGS__); \
} while (0)
#endif
#if defined(QUIC_EVENTS_STDOUT) || defined(QUIC_LOGS_STUB)
#define QuicTraceEventEnabled(Name) TRUE
#define QuicTrace(Name, Fmt, ...) \
clog((Fmt " [" #Name ":%s:%d]\n"), ##__VA_ARGS__, __FILE__, __LINE__)
#define QuicTraceEvent(Name, Fmt, ...) QuicTrace(Name, Fmt, ##__VA_ARGS__)
#if defined(QUIC_EVENTS_STDOUT)
extern
#ifdef __cplusplus
"C"
#endif
char *
#ifndef _WIN32
__attribute__((no_instrument_function))
#endif
casted_clog_bytearray(const uint8_t * const data,
const size_t len,
struct clog_param ** head);
#else
inline char *
#ifndef _WIN32
__attribute__((no_instrument_function))
#endif
casted_clog_bytearray(const uint8_t * const data,
const size_t len,
struct clog_param ** head)
{
UNREFERENCED_PARAMETER(data);
UNREFERENCED_PARAMETER(len);
UNREFERENCED_PARAMETER(head);
return 0;
}
#endif
#define CASTED_CLOG_BYTEARRAY(Len, Data) \
casted_clog_bytearray((const uint8_t *)(Data), (Len), &__head)
#define CASTED_CLOG_BYTEARRAY16(Len, Data) \
casted_clog_bytearray((const uint8_t *)(Data), (Len), &__head)
#endif
#ifdef QUIC_EVENTS_MANIFEST_ETW
#include <evntprov.h>
#ifdef __cplusplus
extern "C"
#endif
_IRQL_requires_max_(PASSIVE_LEVEL)
_IRQL_requires_same_
void
NTAPI
QuicEtwCallback(
_In_ LPCGUID SourceId,
_In_ ULONG ControlCode,
_In_ UCHAR Level,
_In_ ULONGLONG MatchAnyKeyword,
_In_ ULONGLONG MatchAllKeyword,
_In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData,
_Inout_opt_ PVOID CallbackContext
);
//
// Defining MCGEN_PRIVATE_ENABLE_CALLBACK_V2, makes McGenControlCallbackV2
// call our user-defined callback routine. See MsQuicEvents.h.
//
#define MCGEN_PRIVATE_ENABLE_CALLBACK_V2 QuicEtwCallback
#pragma warning(push) // Don't care about warnings from generated files
#pragma warning(disable:6001)
#pragma warning(disable:26451)
#include "MsQuicEtw.h"
#pragma warning(pop)
#define QuicTraceEventEnabled(Name) EventEnabledQuic##Name()
#if defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL
#define _QuicTraceEvent(Name, Args) EventWriteQuic##Name##Args
#define QuicTraceEvent(Name, Fmt, ...) _QuicTraceEvent(Name, (__VA_ARGS__))
#else
#define QuicTraceEvent(Name, Fmt, ...) EventWriteQuic##Name (__VA_ARGS__)
#endif
#define CLOG_BYTEARRAY(Len, Data) (uint8_t)(Len), (uint8_t*)(Data)
#define CASTED_CLOG_BYTEARRAY(Len, Data) CLOG_BYTEARRAY((unsigned char)(Len), (const unsigned char*)(Data))
#define CLOG_BYTEARRAY16(Len, Data) (uint16_t)(Len), (uint8_t*)(Data)
#define CASTED_CLOG_BYTEARRAY16(Len, Data) CLOG_BYTEARRAY16((unsigned short)(Len), (const unsigned char*)(Data))
#endif // QUIC_EVENTS_MANIFEST_ETW
#if defined(QUIC_LOGS_STDOUT) || defined(QUIC_LOGS_STUB)
#define QuicTraceLogErrorEnabled() TRUE
#define QuicTraceLogWarningEnabled() TRUE
#define QuicTraceLogInfoEnabled() TRUE
#define QuicTraceLogVerboseEnabled() TRUE
#define QuicTraceLogError(Name, Fmt, ...) QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogWarning(Name, Fmt, ...) QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogInfo(Name, Fmt, ...) QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogVerbose(Name, Fmt, ...) QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogConnError(Name, X, Fmt, ...) \
do { \
UNREFERENCED_PARAMETER(X); \
QuicTrace(Name, Fmt, ##__VA_ARGS__); \
} while (0)
#define QuicTraceLogConnWarning(Name, X, Fmt, ...) \
do { \
UNREFERENCED_PARAMETER(X); \
QuicTrace(Name, Fmt, ##__VA_ARGS__); \
} while (0)
#define QuicTraceLogConnInfo(Name, X, Fmt, ...) \
do { \
UNREFERENCED_PARAMETER(X); \
QuicTrace(Name, Fmt, ##__VA_ARGS__); \
} while (0)
#define QuicTraceLogConnVerbose(Name, X, Fmt, ...) \
do { \
UNREFERENCED_PARAMETER(X); \
QuicTrace(Name, Fmt, ##__VA_ARGS__); \
} while (0)
#define QuicTraceLogStreamVerboseEnabled() TRUE
#define QuicTraceLogStreamError(Name, X, Fmt, ...) \
QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamWarning(Name, X, Fmt, ...) \
QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamInfo(Name, X, Fmt, ...) \
QuicTrace(Name, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamVerbose(Name, X, Fmt, ...) \
QuicTrace(Name, Fmt, ##__VA_ARGS__)
#endif
#ifdef QUIC_LOGS_MANIFEST_ETW
#pragma warning(push) // Don't care about warnings from generated files
#pragma warning(disable:6001)
#pragma warning(disable:26451)
#include "MsQuicEtw.h"
#pragma warning(pop)
#include <stdio.h>
#define QuicTraceLogErrorEnabled() EventEnabledQuicLogError()
#define QuicTraceLogWarningEnabled() EventEnabledQuicLogWarning()
#define QuicTraceLogInfoEnabled() EventEnabledQuicLogInfo()
#define QuicTraceLogVerboseEnabled() EventEnabledQuicLogVerbose()
#define QUIC_ETW_BUFFER_LENGTH 128
#define LogEtw(EventName, Fmt, ...) \
if (EventEnabledQuicLog##EventName()) { \
char EtwBuffer[QUIC_ETW_BUFFER_LENGTH]; \
_snprintf_s(EtwBuffer, sizeof(EtwBuffer), _TRUNCATE, Fmt, ##__VA_ARGS__); \
EventWriteQuicLog##EventName##_AssumeEnabled(EtwBuffer); \
}
#define LogEtwType(Type, EventName, Ptr, Fmt, ...) \
if (EventEnabledQuic##Type##Log##EventName()) { \
char EtwBuffer[QUIC_ETW_BUFFER_LENGTH]; \
_snprintf_s(EtwBuffer, sizeof(EtwBuffer), _TRUNCATE, Fmt, ##__VA_ARGS__); \
EventWriteQuic##Type##Log##EventName##_AssumeEnabled(Ptr, EtwBuffer); \
}
#define QuicTraceLogError(Name, Fmt, ...) LogEtw(Error, Fmt, ##__VA_ARGS__)
#define QuicTraceLogWarning(Name, Fmt, ...) LogEtw(Warning, Fmt, ##__VA_ARGS__)
#define QuicTraceLogInfo(Name, Fmt, ...) LogEtw(Info, Fmt, ##__VA_ARGS__)
#define QuicTraceLogVerbose(Name, Fmt, ...) LogEtw(Verbose, Fmt, ##__VA_ARGS__)
#define QuicTraceLogConnError(Name, Ptr, Fmt, ...) LogEtwType(Conn, Error, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogConnWarning(Name, Ptr, Fmt, ...) LogEtwType(Conn, Warning, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogConnInfo(Name, Ptr, Fmt, ...) LogEtwType(Conn, Info, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogConnVerbose(Name, Ptr, Fmt, ...) LogEtwType(Conn, Verbose, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamVerboseEnabled() EventEnabledQuicStreamLogVerbose()
#define QuicTraceLogStreamError(Name, Ptr, Fmt, ...) LogEtwType(Stream, Error, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamWarning(Name, Ptr, Fmt, ...) LogEtwType(Stream, Warning, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamInfo(Name, Ptr, Fmt, ...) LogEtwType(Stream, Info, Ptr, Fmt, ##__VA_ARGS__)
#define QuicTraceLogStreamVerbose(Name, Ptr, Fmt, ...) LogEtwType(Stream, Verbose, Ptr, Fmt, ##__VA_ARGS__)
#endif // QUIC_LOGS_MANIFEST_ETW
#endif // QUIC_CLOG