forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation.h
379 lines (330 loc) · 9.41 KB
/
operation.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
372
373
374
375
376
377
378
379
/*++
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
--*/
#ifdef QUIC_CLOG
#include "operation.h.clog.h"
#endif
typedef struct QUIC_SEND_REQUEST QUIC_SEND_REQUEST;
//
// For logging.
//
typedef enum QUIC_SCHEDULE_STATE {
QUIC_SCHEDULE_IDLE,
QUIC_SCHEDULE_QUEUED,
QUIC_SCHEDULE_PROCESSING
} QUIC_SCHEDULE_STATE;
typedef enum QUIC_OPERATION_TYPE {
QUIC_OPER_TYPE_API_CALL, // Process an API call from the app.
QUIC_OPER_TYPE_FLUSH_RECV, // Process queue of receive packets.
QUIC_OPER_TYPE_UNREACHABLE, // Process UDP unreachable event.
QUIC_OPER_TYPE_FLUSH_STREAM_RECV, // Indicate a stream data to the app.
QUIC_OPER_TYPE_FLUSH_SEND, // Frame packets and send them.
QUIC_OPER_TYPE_DEPRECATED, // No longer used.
QUIC_OPER_TYPE_TIMER_EXPIRED, // A timer expired.
QUIC_OPER_TYPE_TRACE_RUNDOWN, // A trace rundown was triggered.
QUIC_OPER_TYPE_ROUTE_COMPLETION, // Process route completion event.
//
// All stateless operations follow.
//
QUIC_OPER_TYPE_VERSION_NEGOTIATION, // A version negotiation needs to be sent.
QUIC_OPER_TYPE_STATELESS_RESET, // A stateless reset needs to be sent.
QUIC_OPER_TYPE_RETRY, // A retry needs to be sent.
} QUIC_OPERATION_TYPE;
typedef enum QUIC_API_TYPE {
QUIC_API_TYPE_CONN_CLOSE,
QUIC_API_TYPE_CONN_SHUTDOWN,
QUIC_API_TYPE_CONN_START,
QUIC_API_TYPE_CONN_SET_CONFIGURATION,
QUIC_API_TYPE_CONN_SEND_RESUMPTION_TICKET,
QUIC_API_TYPE_STRM_CLOSE,
QUIC_API_TYPE_STRM_SHUTDOWN,
QUIC_API_TYPE_STRM_START,
QUIC_API_TYPE_STRM_SEND,
QUIC_API_TYPE_STRM_RECV_COMPLETE,
QUIC_API_TYPE_STRM_RECV_SET_ENABLED,
QUIC_API_TYPE_SET_PARAM,
QUIC_API_TYPE_GET_PARAM,
QUIC_API_TYPE_DATAGRAM_SEND,
QUIC_API_TYPE_CONN_COMPLETE_RESUMPTION_TICKET_VALIDATION,
QUIC_API_TYPE_CONN_COMPLETE_CERTIFICATE_VALIDATION,
} QUIC_API_TYPE;
//
// Context for an API call. This is allocated separately from QUIC_OPERATION
// so that non-API-call operations will take less space.
//
typedef struct QUIC_API_CONTEXT {
QUIC_API_TYPE Type;
//
// A pointer to the return status for the operation. If this pointer is
// NULL, this the operation is performed asynchronously, with no
// completion event being set, nor the status being returned. If the
// pointer is set, then the operation is completed synchronously by setting
// the status and signaling the Completed event.
//
QUIC_STATUS* Status;
//
// Used for synchronous operations (see above).
//
CXPLAT_EVENT* Completed;
union {
struct {
void* Reserved; // Nothing.
} CONN_OPEN;
struct {
void* Reserved; // Nothing.
} CONN_CLOSED;
struct {
QUIC_CONNECTION_SHUTDOWN_FLAGS Flags;
BOOLEAN RegistrationShutdown : 1;
BOOLEAN TransportShutdown : 1;
QUIC_VAR_INT ErrorCode;
} CONN_SHUTDOWN;
struct {
QUIC_CONFIGURATION* Configuration;
_Null_terminated_
const char* ServerName;
uint16_t ServerPort;
QUIC_ADDRESS_FAMILY Family;
} CONN_START;
struct {
QUIC_CONFIGURATION* Configuration;
} CONN_SET_CONFIGURATION;
struct {
QUIC_SEND_RESUMPTION_FLAGS Flags;
uint8_t* ResumptionAppData;
uint16_t AppDataLength;
} CONN_SEND_RESUMPTION_TICKET;
struct {
BOOLEAN Result;
} CONN_COMPLETE_RESUMPTION_TICKET_VALIDATION;
struct {
QUIC_TLS_ALERT_CODES TlsAlert;
BOOLEAN Result;
} CONN_COMPLETE_CERTIFICATE_VALIDATION;
struct {
QUIC_STREAM_OPEN_FLAGS Flags;
QUIC_STREAM_CALLBACK_HANDLER Handler;
void* Context;
HQUIC* NewStream;
} STRM_OPEN;
struct {
QUIC_STREAM* Stream;
} STRM_CLOSE;
struct {
QUIC_STREAM* Stream;
QUIC_STREAM_START_FLAGS Flags;
} STRM_START;
struct {
QUIC_STREAM* Stream;
QUIC_STREAM_SHUTDOWN_FLAGS Flags;
QUIC_VAR_INT ErrorCode;
} STRM_SHUTDOWN;
struct {
QUIC_STREAM* Stream;
} STRM_SEND;
struct {
QUIC_STREAM* Stream;
} STRM_RECV_COMPLETE;
struct {
QUIC_STREAM* Stream;
BOOLEAN IsEnabled;
} STRM_RECV_SET_ENABLED;
struct {
HQUIC Handle;
uint32_t Param;
uint32_t BufferLength;
const void* Buffer;
} SET_PARAM;
struct {
HQUIC Handle;
uint32_t Param;
uint32_t* BufferLength;
void* Buffer;
} GET_PARAM;
};
} QUIC_API_CONTEXT;
typedef enum QUIC_CONN_TIMER_TYPE {
QUIC_CONN_TIMER_PACING,
QUIC_CONN_TIMER_ACK_DELAY,
QUIC_CONN_TIMER_LOSS_DETECTION,
QUIC_CONN_TIMER_KEEP_ALIVE,
QUIC_CONN_TIMER_IDLE,
QUIC_CONN_TIMER_SHUTDOWN,
QUIC_CONN_TIMER_COUNT
} QUIC_CONN_TIMER_TYPE;
typedef struct QUIC_STATELESS_CONTEXT {
QUIC_BINDING* Binding;
QUIC_WORKER* Worker;
QUIC_ADDR RemoteAddress;
CXPLAT_LIST_ENTRY ListEntry;
CXPLAT_HASHTABLE_ENTRY TableEntry;
QUIC_RX_PACKET* Packet;
uint32_t CreationTimeMs;
uint8_t HasBindingRef : 1;
uint8_t IsProcessed : 1;
uint8_t IsExpired : 1;
} QUIC_STATELESS_CONTEXT;
//
// A single unit of work for a connection.
//
typedef struct QUIC_OPERATION {
CXPLAT_LIST_ENTRY Link;
QUIC_OPERATION_TYPE Type;
//
// Some operations are allocated on the stack rather than via
// QuicOperationAlloc. This flag is used to differentiate
// between the two. Only operations allocated with
// QuicOperationAlloc should be freed with QuicOperationFree.
//
BOOLEAN FreeAfterProcess;
union {
struct {
void* Reserved; // Nothing.
} INITIALIZE;
struct {
QUIC_API_CONTEXT* Context;
} API_CALL;
struct {
void* Reserved; // Nothing.
} FLUSH_RECEIVE;
struct {
QUIC_ADDR RemoteAddress;
} UNREACHABLE;
struct {
QUIC_STREAM* Stream;
} FLUSH_STREAM_RECEIVE;
struct {
void* Reserved; // Nothing.
} FLUSH_SEND;
struct {
QUIC_CONN_TIMER_TYPE Type;
} TIMER_EXPIRED;
struct {
QUIC_STATELESS_CONTEXT* Context;
} STATELESS; // Stateless reset, retry and VN
struct {
uint8_t PhysicalAddress[6];
uint8_t PathId;
BOOLEAN Succeeded;
} ROUTE;
};
} QUIC_OPERATION;
inline
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicOperLog(
_In_ const void* Connection,
_In_ QUIC_OPERATION* Oper
)
{
UNREFERENCED_PARAMETER(Connection);
switch (Oper->Type) {
case QUIC_OPER_TYPE_API_CALL:
QuicTraceEvent(
ConnExecApiOper,
"[conn][%p] Execute: %u",
Connection,
Oper->API_CALL.Context->Type);
break;
case QUIC_OPER_TYPE_TIMER_EXPIRED:
QuicTraceEvent(
ConnExecTimerOper,
"[conn][%p] Execute: %u",
Connection,
Oper->TIMER_EXPIRED.Type);
break;
default:
QuicTraceEvent(
ConnExecOper,
"[conn][%p] Execute: %u",
Connection,
Oper->Type);
break;
}
}
//
// A queue of operations to be executed for a connection.
//
typedef struct QUIC_OPERATION_QUEUE {
//
// TRUE if the queue is being drained.
//
BOOLEAN ActivelyProcessing;
//
// Queue of pending operations.
//
CXPLAT_DISPATCH_LOCK Lock;
CXPLAT_LIST_ENTRY List;
} QUIC_OPERATION_QUEUE;
//
// Initializes an operation queue.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicOperationQueueInitialize(
_Inout_ QUIC_OPERATION_QUEUE* OperQ
);
//
// Uninitializes an operation queue.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicOperationQueueUninitialize(
_In_ QUIC_OPERATION_QUEUE* OperQ
);
//
// Allocates an operation.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_OPERATION*
QuicOperationAlloc(
_In_ QUIC_WORKER* Worker,
_In_ QUIC_OPERATION_TYPE Type
);
//
// Frees an operation.
//
_IRQL_requires_max_(PASSIVE_LEVEL)
void
QuicOperationFree(
_In_ QUIC_WORKER* Worker,
_In_ QUIC_OPERATION* Oper
);
//
// Enqueues an operation. Returns TRUE if the queue was previously empty and not
// already being processed.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
QuicOperationEnqueue(
_In_ QUIC_OPERATION_QUEUE* OperQ,
_In_ QUIC_OPERATION* Oper
);
//
// Enqueues an operation at the front of the queue. Returns TRUE if the queue
// was previously empty and not already being processed.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
BOOLEAN
QuicOperationEnqueueFront(
_In_ QUIC_OPERATION_QUEUE* OperQ,
_In_ QUIC_OPERATION* Oper
);
//
// Dequeues an operation. Returns NULL if the queue is empty.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_OPERATION*
QuicOperationDequeue(
_In_ QUIC_OPERATION_QUEUE* OperQ
);
//
// Dequeues and frees all operations.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
void
QuicOperationQueueClear(
_In_ QUIC_WORKER* Worker,
_In_ QUIC_OPERATION_QUEUE* OperQ
);