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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
/*
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include "internal/qlog_event_helpers.h"
#include "internal/common.h"
#include "internal/packet.h"
#include "internal/quic_channel.h"
#include "internal/quic_error.h"
void ossl_qlog_event_connectivity_connection_started(QLOG *qlog,
const QUIC_CONN_ID *init_dcid)
{
#ifndef OPENSSL_NO_QLOG
QLOG_EVENT_BEGIN(qlog, connectivity, connection_started)
QLOG_STR("protocol", "quic");
QLOG_CID("dst_cid", init_dcid);
QLOG_EVENT_END()
#endif
}
#ifndef OPENSSL_NO_QLOG
static const char *map_state_to_qlog(uint32_t state,
int handshake_complete,
int handshake_confirmed)
{
switch (state) {
default:
case QUIC_CHANNEL_STATE_IDLE:
return NULL;
case QUIC_CHANNEL_STATE_ACTIVE:
if (handshake_confirmed)
return "handshake_confirmed";
else if (handshake_complete)
return "handshake_complete";
else
return "attempted";
case QUIC_CHANNEL_STATE_TERMINATING_CLOSING:
return "closing";
case QUIC_CHANNEL_STATE_TERMINATING_DRAINING:
return "draining";
case QUIC_CHANNEL_STATE_TERMINATED:
return "closed";
}
}
#endif
void ossl_qlog_event_connectivity_connection_state_updated(QLOG *qlog,
uint32_t old_state,
uint32_t new_state,
int handshake_complete,
int handshake_confirmed)
{
#ifndef OPENSSL_NO_QLOG
const char *state_s;
QLOG_EVENT_BEGIN(qlog, connectivity, connection_state_updated)
state_s = map_state_to_qlog(new_state,
handshake_complete,
handshake_confirmed);
if (state_s != NULL)
QLOG_STR("state", state_s);
QLOG_EVENT_END()
#endif
}
#ifndef OPENSSL_NO_QLOG
static const char *quic_err_to_qlog(uint64_t error_code)
{
switch (error_code) {
case QUIC_ERR_INTERNAL_ERROR:
return "internal_error";
case QUIC_ERR_CONNECTION_REFUSED:
return "connection_refused";
case QUIC_ERR_FLOW_CONTROL_ERROR:
return "flow_control_error";
case QUIC_ERR_STREAM_LIMIT_ERROR:
return "stream_limit_error";
case QUIC_ERR_STREAM_STATE_ERROR:
return "stream_state_error";
case QUIC_ERR_FINAL_SIZE_ERROR:
return "final_size_error";
case QUIC_ERR_FRAME_ENCODING_ERROR:
return "frame_encoding_error";
case QUIC_ERR_TRANSPORT_PARAMETER_ERROR:
return "transport_parameter_error";
case QUIC_ERR_CONNECTION_ID_LIMIT_ERROR:
return "connection_id_limit_error";
case QUIC_ERR_PROTOCOL_VIOLATION:
return "protocol_violation";
case QUIC_ERR_INVALID_TOKEN:
return "invalid_token";
case QUIC_ERR_APPLICATION_ERROR:
return "application_error";
case QUIC_ERR_CRYPTO_BUFFER_EXCEEDED:
return "crypto_buffer_exceeded";
case QUIC_ERR_KEY_UPDATE_ERROR:
return "key_update_error";
case QUIC_ERR_AEAD_LIMIT_REACHED:
return "aead_limit_reached";
case QUIC_ERR_NO_VIABLE_PATH:
return "no_viable_path";
default:
return NULL;
}
}
#endif
void ossl_qlog_event_connectivity_connection_closed(QLOG *qlog,
const QUIC_TERMINATE_CAUSE *tcause)
{
#ifndef OPENSSL_NO_QLOG
QLOG_EVENT_BEGIN(qlog, connectivity, connection_closed)
QLOG_STR("owner", tcause->remote ? "remote" : "local");
if (tcause->app) {
QLOG_U64("application_code", tcause->error_code);
} else {
const char *m = quic_err_to_qlog(tcause->error_code);
char ce[32];
if (tcause->error_code >= QUIC_ERR_CRYPTO_ERR_BEGIN
&& tcause->error_code <= QUIC_ERR_CRYPTO_ERR_END) {
BIO_snprintf(ce, sizeof(ce), "crypto_error_0x%03llx",
(unsigned long long)tcause->error_code);
m = ce;
}
/* TODO(QLOG FUTURE): Consider adding ERR information in the output. */
if (m != NULL)
QLOG_STR("connection_code", m);
else
QLOG_U64("connection_code", tcause->error_code);
}
QLOG_STR_LEN("reason", tcause->reason, tcause->reason_len);
QLOG_EVENT_END()
#endif
}
#ifndef OPENSSL_NO_QLOG
static const char *quic_pkt_type_to_qlog(uint32_t pkt_type)
{
switch (pkt_type) {
case QUIC_PKT_TYPE_INITIAL:
return "initial";
case QUIC_PKT_TYPE_HANDSHAKE:
return "handshake";
case QUIC_PKT_TYPE_0RTT:
return "0RTT";
case QUIC_PKT_TYPE_1RTT:
return "1RTT";
case QUIC_PKT_TYPE_VERSION_NEG:
return "version_negotiation";
case QUIC_PKT_TYPE_RETRY:
return "retry";
default:
return "unknown";
}
}
#endif
void ossl_qlog_event_recovery_packet_lost(QLOG *qlog,
const QUIC_TXPIM_PKT *tpkt)
{
#ifndef OPENSSL_NO_QLOG
QLOG_EVENT_BEGIN(qlog, recovery, packet_lost)
QLOG_BEGIN("header")
QLOG_STR("packet_type", quic_pkt_type_to_qlog(tpkt->pkt_type));
if (ossl_quic_pkt_type_has_pn(tpkt->pkt_type))
QLOG_U64("packet_number", tpkt->ackm_pkt.pkt_num);
QLOG_END()
QLOG_EVENT_END()
#endif
}
#ifndef OPENSSL_NO_QLOG
# define MAX_ACK_RANGES 32
static void ignore_res(int x) {}
/*
* For logging received packets, we need to parse all the frames in the packet
* to log them. We should do this separately to the RXDP code because we want to
* log the packet and its contents before we start to actually process it in
* case it causes an error. We also in general don't want to do other
* non-logging related work in the middle of an event logging transaction.
* Reparsing packet data allows us to meet these needs while avoiding the need
* to keep around bookkeeping data on what frames were in a packet, etc.
*
* For logging transmitted packets, we actually reuse the same code and reparse
* the outgoing packet's payload. This again has the advantage that we only log
* a packet when it is actually queued for transmission (and not if something
* goes wrong before then) while avoiding the need to keep around bookkeeping
* data on what frames it contained.
*/
static int log_frame_actual(QLOG *qlog_instance, PACKET *pkt,
size_t *need_skip)
{
uint64_t frame_type;
OSSL_QUIC_FRAME_ACK ack;
OSSL_QUIC_ACK_RANGE ack_ranges[MAX_ACK_RANGES];
uint64_t num_ranges, total_ranges;
size_t i;
PACKET orig_pkt = *pkt;
if (!ossl_quic_wire_peek_frame_header(pkt, &frame_type, NULL))
return 0;
/*
* If something goes wrong decoding a frame we cannot log it as that frame
* as we need to know how to decode it in order to be able to do so, but in
* that case we log it as an unknown frame to assist with diagnosis.
*/
switch (frame_type) {
case OSSL_QUIC_FRAME_TYPE_PADDING:
QLOG_STR("frame_type", "padding");
QLOG_U64("payload_length",
ossl_quic_wire_decode_padding(pkt));
break;
case OSSL_QUIC_FRAME_TYPE_PING:
if (!ossl_quic_wire_decode_frame_ping(pkt))
goto unknown;
QLOG_STR("frame_type", "ping");
break;
case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
if (!ossl_quic_wire_peek_frame_ack_num_ranges(pkt,
|