/src/openssl/ssl/quic/qlog_event_helpers.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include "internal/qlog_event_helpers.h" |
11 | | #include "internal/common.h" |
12 | | #include "internal/packet.h" |
13 | | #include "internal/quic_channel.h" |
14 | | #include "internal/quic_error.h" |
15 | | |
16 | | void ossl_qlog_event_connectivity_connection_started(QLOG *qlog, |
17 | | const QUIC_CONN_ID *init_dcid) |
18 | 0 | { |
19 | 0 | #ifndef OPENSSL_NO_QLOG |
20 | 0 | QLOG_EVENT_BEGIN(qlog, connectivity, connection_started) |
21 | 0 | QLOG_STR("protocol", "quic"); |
22 | 0 | QLOG_CID("dst_cid", init_dcid); |
23 | 0 | QLOG_EVENT_END() |
24 | 0 | #endif |
25 | 0 | } |
26 | | |
27 | | #ifndef OPENSSL_NO_QLOG |
28 | | static const char *map_state_to_qlog(uint32_t state, |
29 | | int handshake_complete, |
30 | | int handshake_confirmed) |
31 | 0 | { |
32 | 0 | switch (state) { |
33 | 0 | default: |
34 | 0 | case QUIC_CHANNEL_STATE_IDLE: |
35 | 0 | return NULL; |
36 | | |
37 | 0 | case QUIC_CHANNEL_STATE_ACTIVE: |
38 | 0 | if (handshake_confirmed) |
39 | 0 | return "handshake_confirmed"; |
40 | 0 | else if (handshake_complete) |
41 | 0 | return "handshake_complete"; |
42 | 0 | else |
43 | 0 | return "attempted"; |
44 | | |
45 | 0 | case QUIC_CHANNEL_STATE_TERMINATING_CLOSING: |
46 | 0 | return "closing"; |
47 | | |
48 | 0 | case QUIC_CHANNEL_STATE_TERMINATING_DRAINING: |
49 | 0 | return "draining"; |
50 | | |
51 | 0 | case QUIC_CHANNEL_STATE_TERMINATED: |
52 | 0 | return "closed"; |
53 | 0 | } |
54 | 0 | } |
55 | | #endif |
56 | | |
57 | | void ossl_qlog_event_connectivity_connection_state_updated(QLOG *qlog, |
58 | | uint32_t old_state, |
59 | | uint32_t new_state, |
60 | | int handshake_complete, |
61 | | int handshake_confirmed) |
62 | 0 | { |
63 | 0 | #ifndef OPENSSL_NO_QLOG |
64 | 0 | const char *state_s; |
65 | |
|
66 | 0 | QLOG_EVENT_BEGIN(qlog, connectivity, connection_state_updated) |
67 | 0 | state_s = map_state_to_qlog(new_state, |
68 | 0 | handshake_complete, |
69 | 0 | handshake_confirmed); |
70 | |
|
71 | 0 | if (state_s != NULL) |
72 | 0 | QLOG_STR("state", state_s); |
73 | 0 | QLOG_EVENT_END() |
74 | 0 | #endif |
75 | 0 | } |
76 | | |
77 | | #ifndef OPENSSL_NO_QLOG |
78 | | static const char *quic_err_to_qlog(uint64_t error_code) |
79 | 0 | { |
80 | 0 | switch (error_code) { |
81 | 0 | case OSSL_QUIC_ERR_INTERNAL_ERROR: |
82 | 0 | return "internal_error"; |
83 | 0 | case OSSL_QUIC_ERR_CONNECTION_REFUSED: |
84 | 0 | return "connection_refused"; |
85 | 0 | case OSSL_QUIC_ERR_FLOW_CONTROL_ERROR: |
86 | 0 | return "flow_control_error"; |
87 | 0 | case OSSL_QUIC_ERR_STREAM_LIMIT_ERROR: |
88 | 0 | return "stream_limit_error"; |
89 | 0 | case OSSL_QUIC_ERR_STREAM_STATE_ERROR: |
90 | 0 | return "stream_state_error"; |
91 | 0 | case OSSL_QUIC_ERR_FINAL_SIZE_ERROR: |
92 | 0 | return "final_size_error"; |
93 | 0 | case OSSL_QUIC_ERR_FRAME_ENCODING_ERROR: |
94 | 0 | return "frame_encoding_error"; |
95 | 0 | case OSSL_QUIC_ERR_TRANSPORT_PARAMETER_ERROR: |
96 | 0 | return "transport_parameter_error"; |
97 | 0 | case OSSL_QUIC_ERR_CONNECTION_ID_LIMIT_ERROR: |
98 | 0 | return "connection_id_limit_error"; |
99 | 0 | case OSSL_QUIC_ERR_PROTOCOL_VIOLATION: |
100 | 0 | return "protocol_violation"; |
101 | 0 | case OSSL_QUIC_ERR_INVALID_TOKEN: |
102 | 0 | return "invalid_token"; |
103 | 0 | case OSSL_QUIC_ERR_APPLICATION_ERROR: |
104 | 0 | return "application_error"; |
105 | 0 | case OSSL_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED: |
106 | 0 | return "crypto_buffer_exceeded"; |
107 | 0 | case OSSL_QUIC_ERR_KEY_UPDATE_ERROR: |
108 | 0 | return "key_update_error"; |
109 | 0 | case OSSL_QUIC_ERR_AEAD_LIMIT_REACHED: |
110 | 0 | return "aead_limit_reached"; |
111 | 0 | case OSSL_QUIC_ERR_NO_VIABLE_PATH: |
112 | 0 | return "no_viable_path"; |
113 | 0 | default: |
114 | 0 | return NULL; |
115 | 0 | } |
116 | 0 | } |
117 | | #endif |
118 | | |
119 | | void ossl_qlog_event_connectivity_connection_closed(QLOG *qlog, |
120 | | const QUIC_TERMINATE_CAUSE *tcause) |
121 | 0 | { |
122 | 0 | #ifndef OPENSSL_NO_QLOG |
123 | 0 | QLOG_EVENT_BEGIN(qlog, connectivity, connection_closed) |
124 | 0 | QLOG_STR("owner", tcause->remote ? "remote" : "local"); |
125 | 0 | if (tcause->app) { |
126 | 0 | QLOG_U64("application_code", tcause->error_code); |
127 | 0 | } else { |
128 | 0 | const char *m = quic_err_to_qlog(tcause->error_code); |
129 | 0 | char ce[32]; |
130 | |
|
131 | 0 | if (tcause->error_code >= OSSL_QUIC_ERR_CRYPTO_ERR_BEGIN |
132 | 0 | && tcause->error_code <= OSSL_QUIC_ERR_CRYPTO_ERR_END) { |
133 | 0 | BIO_snprintf(ce, sizeof(ce), "crypto_error_0x%03llx", |
134 | 0 | (unsigned long long)tcause->error_code); |
135 | 0 | m = ce; |
136 | 0 | } |
137 | | /* TODO(QLOG FUTURE): Consider adding ERR information in the output. */ |
138 | |
|
139 | 0 | if (m != NULL) |
140 | 0 | QLOG_STR("connection_code", m); |
141 | 0 | else |
142 | 0 | QLOG_U64("connection_code", tcause->error_code); |
143 | 0 | } |
144 | |
|
145 | 0 | QLOG_STR_LEN("reason", tcause->reason, tcause->reason_len); |
146 | 0 | QLOG_EVENT_END() |
147 | 0 | #endif |
148 | 0 | } |
149 | | |
150 | | #ifndef OPENSSL_NO_QLOG |
151 | | static const char *quic_pkt_type_to_qlog(uint32_t pkt_type) |
152 | 0 | { |
153 | 0 | switch (pkt_type) { |
154 | 0 | case QUIC_PKT_TYPE_INITIAL: |
155 | 0 | return "initial"; |
156 | 0 | case QUIC_PKT_TYPE_HANDSHAKE: |
157 | 0 | return "handshake"; |
158 | 0 | case QUIC_PKT_TYPE_0RTT: |
159 | 0 | return "0RTT"; |
160 | 0 | case QUIC_PKT_TYPE_1RTT: |
161 | 0 | return "1RTT"; |
162 | 0 | case QUIC_PKT_TYPE_VERSION_NEG: |
163 | 0 | return "version_negotiation"; |
164 | 0 | case QUIC_PKT_TYPE_RETRY: |
165 | 0 | return "retry"; |
166 | 0 | default: |
167 | 0 | return "unknown"; |
168 | 0 | } |
169 | 0 | } |
170 | | #endif |
171 | | |
172 | | void ossl_qlog_event_recovery_packet_lost(QLOG *qlog, |
173 | | const QUIC_TXPIM_PKT *tpkt) |
174 | 0 | { |
175 | 0 | #ifndef OPENSSL_NO_QLOG |
176 | 0 | QLOG_EVENT_BEGIN(qlog, recovery, packet_lost) |
177 | 0 | QLOG_BEGIN("header") |
178 | 0 | QLOG_STR("packet_type", quic_pkt_type_to_qlog(tpkt->pkt_type)); |
179 | 0 | if (ossl_quic_pkt_type_has_pn(tpkt->pkt_type)) |
180 | 0 | QLOG_U64("packet_number", tpkt->ackm_pkt.pkt_num); |
181 | 0 | QLOG_END() |
182 | 0 | QLOG_EVENT_END() |
183 | 0 | #endif |
184 | 0 | } |
185 | | |
186 | | #ifndef OPENSSL_NO_QLOG |
187 | | # define MAX_ACK_RANGES 32 |
188 | | |
189 | 0 | static void ignore_res(int x) {} |
190 | | |
191 | | /* |
192 | | * For logging received packets, we need to parse all the frames in the packet |
193 | | * to log them. We should do this separately to the RXDP code because we want to |
194 | | * log the packet and its contents before we start to actually process it in |
195 | | * case it causes an error. We also in general don't want to do other |
196 | | * non-logging related work in the middle of an event logging transaction. |
197 | | * Reparsing packet data allows us to meet these needs while avoiding the need |
198 | | * to keep around bookkeeping data on what frames were in a packet, etc. |
199 | | * |
200 | | * For logging transmitted packets, we actually reuse the same code and reparse |
201 | | * the outgoing packet's payload. This again has the advantage that we only log |
202 | | * a packet when it is actually queued for transmission (and not if something |
203 | | * goes wrong before then) while avoiding the need to keep around bookkeeping |
204 | | * data on what frames it contained. |
205 | | */ |
206 | | static int log_frame_actual(QLOG *qlog_instance, PACKET *pkt, |
207 | | size_t *need_skip) |
208 | 0 | { |
209 | 0 | uint64_t frame_type; |
210 | 0 | OSSL_QUIC_FRAME_ACK ack; |
211 | 0 | OSSL_QUIC_ACK_RANGE ack_ranges[MAX_ACK_RANGES]; |
212 | 0 | uint64_t num_ranges, total_ranges; |
213 | 0 | size_t i; |
214 | 0 | PACKET orig_pkt = *pkt; |
215 | |
|
216 | 0 | if (!ossl_quic_wire_peek_frame_header(pkt, &frame_type, NULL)) |
217 | 0 | return 0; |
218 | | |
219 | | /* |
220 | | * If something goes wrong decoding a frame we cannot log it as that frame |
221 | | * as we need to know how to decode it in order to be able to do so, but in |
222 | | * that case we log it as an unknown frame to assist with diagnosis. |
223 | | */ |
224 | 0 | switch (frame_type) { |
225 | 0 | case OSSL_QUIC_FRAME_TYPE_PADDING: |
226 | 0 | QLOG_STR("frame_type", "padding"); |
227 | 0 | QLOG_U64("payload_length", |
228 | 0 | ossl_quic_wire_decode_padding(pkt)); |
229 | 0 | break; |
230 | 0 | case OSSL_QUIC_FRAME_TYPE_PING: |
231 | 0 | if (!ossl_quic_wire_decode_frame_ping(pkt)) |
232 | 0 | goto unknown; |
233 | | |
234 | 0 | QLOG_STR("frame_type", "ping"); |
235 | 0 | break; |
236 | 0 | case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN: |
237 | 0 | case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN: |
238 | 0 | if (!ossl_quic_wire_peek_frame_ack_num_ranges(pkt, &num_ranges)) |
239 | 0 | goto unknown; |
240 | | |
241 | 0 | ack.ack_ranges = ack_ranges; |
242 | 0 | ack.num_ack_ranges = OSSL_NELEM(ack_ranges); |
243 | 0 | if (!ossl_quic_wire_decode_frame_ack(pkt, 3, &ack, &total_ranges)) |
244 | 0 | goto unknown; |
245 | | |
246 | 0 | QLOG_STR("frame_type", "ack"); |
247 | 0 | QLOG_U64("ack_delay", ossl_time2ms(ack.delay_time)); |
248 | 0 | if (ack.ecn_present) { |
249 | 0 | QLOG_U64("ect1", ack.ect0); |
250 | 0 | QLOG_U64("ect0", ack.ect1); |
251 | 0 | QLOG_U64("ce", ack.ecnce); |
252 | 0 | } |
253 | 0 | QLOG_BEGIN_ARRAY("acked_ranges"); |
254 | 0 | for (i = 0; i < ack.num_ack_ranges; ++i) { |
255 | 0 | QLOG_BEGIN_ARRAY(NULL) |
256 | 0 | QLOG_U64(NULL, ack.ack_ranges[i].start); |
257 | 0 | if (ack.ack_ranges[i].end != ack.ack_ranges[i].start) |
258 | 0 | QLOG_U64(NULL, ack.ack_ranges[i].end); |
259 | 0 | QLOG_END_ARRAY() |
260 | 0 | } |
261 | 0 | QLOG_END_ARRAY() |
262 | 0 | break; |
263 | 0 | case OSSL_QUIC_FRAME_TYPE_RESET_STREAM: |
264 | 0 | { |
265 | 0 | OSSL_QUIC_FRAME_RESET_STREAM f; |
266 | |
|
267 | 0 | if (!ossl_quic_wire_decode_frame_reset_stream(pkt, &f)) |
268 | 0 | goto unknown; |
269 | | |
270 | 0 | QLOG_STR("frame_type", "reset_stream"); |
271 | 0 | QLOG_U64("stream_id", f.stream_id); |
272 | 0 | QLOG_U64("error_code", f.app_error_code); |
273 | 0 | QLOG_U64("final_size", f.final_size); |
274 | 0 | } |
275 | 0 | break; |
276 | 0 | case OSSL_QUIC_FRAME_TYPE_STOP_SENDING: |
277 | 0 | { |
278 | 0 | OSSL_QUIC_FRAME_STOP_SENDING f; |
279 | |
|
280 | 0 | if (!ossl_quic_wire_decode_frame_stop_sending(pkt, &f)) |
281 | 0 | goto unknown; |
282 | | |
283 | 0 | QLOG_STR("frame_type", "stop_sending"); |
284 | 0 | QLOG_U64("stream_id", f.stream_id); |
285 | 0 | QLOG_U64("error_code", f.app_error_code); |
286 | 0 | } |
287 | 0 | break; |
288 | 0 | case OSSL_QUIC_FRAME_TYPE_CRYPTO: |
289 | 0 | { |
290 | 0 | OSSL_QUIC_FRAME_CRYPTO f; |
291 | |
|
292 | 0 | if (!ossl_quic_wire_decode_frame_crypto(pkt, 1, &f)) |
293 | 0 | goto unknown; |
294 | | |
295 | 0 | QLOG_STR("frame_type", "crypto"); |
296 | 0 | QLOG_U64("offset", f.offset); |
297 | 0 | QLOG_U64("payload_length", f.len); |
298 | 0 | *need_skip += (size_t)f.len; |
299 | 0 | } |
300 | 0 | break; |
301 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM: |
302 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_FIN: |
303 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_LEN: |
304 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN: |
305 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_OFF: |
306 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN: |
307 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN: |
308 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN: |
309 | 0 | { |
310 | 0 | OSSL_QUIC_FRAME_STREAM f; |
311 | |
|
312 | 0 | if (!ossl_quic_wire_decode_frame_stream(pkt, 1, &f)) |
313 | 0 | goto unknown; |
314 | | |
315 | 0 | QLOG_STR("frame_type", "stream"); |
316 | 0 | QLOG_U64("stream_id", f.stream_id); |
317 | 0 | QLOG_U64("offset", f.offset); |
318 | 0 | QLOG_U64("payload_length", f.len); |
319 | 0 | QLOG_BOOL("explicit_length", f.has_explicit_len); |
320 | 0 | if (f.is_fin) |
321 | 0 | QLOG_BOOL("fin", 1); |
322 | 0 | *need_skip = f.has_explicit_len |
323 | 0 | ? *need_skip + (size_t)f.len : SIZE_MAX; |
324 | 0 | } |
325 | 0 | break; |
326 | 0 | case OSSL_QUIC_FRAME_TYPE_MAX_DATA: |
327 | 0 | { |
328 | 0 | uint64_t x; |
329 | |
|
330 | 0 | if (!ossl_quic_wire_decode_frame_max_data(pkt, &x)) |
331 | 0 | goto unknown; |
332 | | |
333 | 0 | QLOG_STR("frame_type", "max_data"); |
334 | 0 | QLOG_U64("maximum", x); |
335 | 0 | } |
336 | 0 | break; |
337 | 0 | case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI: |
338 | 0 | case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI: |
339 | 0 | { |
340 | 0 | uint64_t x; |
341 | |
|
342 | 0 | if (!ossl_quic_wire_decode_frame_max_streams(pkt, &x)) |
343 | 0 | goto unknown; |
344 | | |
345 | 0 | QLOG_STR("frame_type", "max_streams"); |
346 | 0 | QLOG_STR("stream_type", |
347 | 0 | frame_type == OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI |
348 | 0 | ? "bidirectional" : "unidirectional"); |
349 | 0 | QLOG_U64("maximum", x); |
350 | 0 | } |
351 | 0 | break; |
352 | 0 | case OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA: |
353 | 0 | { |
354 | 0 | uint64_t stream_id, max_data; |
355 | |
|
356 | 0 | if (!ossl_quic_wire_decode_frame_max_stream_data(pkt, &stream_id, |
357 | 0 | &max_data)) |
358 | 0 | goto unknown; |
359 | | |
360 | 0 | QLOG_STR("frame_type", "max_stream_data"); |
361 | 0 | QLOG_U64("stream_id", stream_id); |
362 | 0 | QLOG_U64("maximum", max_data); |
363 | 0 | } |
364 | 0 | break; |
365 | 0 | case OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE: |
366 | 0 | { |
367 | 0 | uint64_t challenge; |
368 | |
|
369 | 0 | if (!ossl_quic_wire_decode_frame_path_challenge(pkt, &challenge)) |
370 | 0 | goto unknown; |
371 | | |
372 | 0 | QLOG_STR("frame_type", "path_challenge"); |
373 | 0 | } |
374 | 0 | break; |
375 | 0 | case OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE: |
376 | 0 | { |
377 | 0 | uint64_t challenge; |
378 | |
|
379 | 0 | if (!ossl_quic_wire_decode_frame_path_response(pkt, &challenge)) |
380 | 0 | goto unknown; |
381 | | |
382 | 0 | QLOG_STR("frame_type", "path_response"); |
383 | 0 | } |
384 | 0 | break; |
385 | 0 | case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP: |
386 | 0 | case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT: |
387 | 0 | { |
388 | 0 | OSSL_QUIC_FRAME_CONN_CLOSE f; |
389 | |
|
390 | 0 | if (!ossl_quic_wire_decode_frame_conn_close(pkt, &f)) |
391 | 0 | goto unknown; |
392 | | |
393 | 0 | QLOG_STR("frame_type", "connection_close"); |
394 | 0 | QLOG_STR("error_space", f.is_app ? "application" : "transport"); |
395 | 0 | QLOG_U64("error_code_value", f.error_code); |
396 | 0 | if (f.is_app) |
397 | 0 | QLOG_U64("error_code", f.error_code); |
398 | 0 | if (!f.is_app && f.frame_type != 0) |
399 | 0 | QLOG_U64("trigger_frame_type", f.frame_type); |
400 | 0 | QLOG_STR_LEN("reason", f.reason, f.reason_len); |
401 | 0 | } |
402 | 0 | break; |
403 | 0 | case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE: |
404 | 0 | { |
405 | 0 | if (!ossl_quic_wire_decode_frame_handshake_done(pkt)) |
406 | 0 | goto unknown; |
407 | | |
408 | 0 | QLOG_STR("frame_type", "handshake_done"); |
409 | 0 | } |
410 | 0 | break; |
411 | 0 | case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID: |
412 | 0 | { |
413 | 0 | OSSL_QUIC_FRAME_NEW_CONN_ID f; |
414 | |
|
415 | 0 | if (!ossl_quic_wire_decode_frame_new_conn_id(pkt, &f)) |
416 | 0 | goto unknown; |
417 | | |
418 | 0 | QLOG_STR("frame_type", "new_connection_id"); |
419 | 0 | QLOG_U64("sequence_number", f.seq_num); |
420 | 0 | QLOG_U64("retire_prior_to", f.retire_prior_to); |
421 | 0 | QLOG_CID("connection_id", &f.conn_id); |
422 | 0 | QLOG_BIN("stateless_reset_token", |
423 | 0 | f.stateless_reset.token, |
424 | 0 | sizeof(f.stateless_reset.token)); |
425 | 0 | } |
426 | 0 | break; |
427 | 0 | case OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID: |
428 | 0 | { |
429 | 0 | uint64_t seq_num; |
430 | |
|
431 | 0 | if (!ossl_quic_wire_decode_frame_retire_conn_id(pkt, &seq_num)) |
432 | 0 | goto unknown; |
433 | | |
434 | 0 | QLOG_STR("frame_type", "retire_connection_id"); |
435 | 0 | QLOG_U64("sequence_number", seq_num); |
436 | 0 | } |
437 | 0 | break; |
438 | 0 | case OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED: |
439 | 0 | { |
440 | 0 | uint64_t x; |
441 | |
|
442 | 0 | if (!ossl_quic_wire_decode_frame_data_blocked(pkt, &x)) |
443 | 0 | goto unknown; |
444 | | |
445 | 0 | QLOG_STR("frame_type", "data_blocked"); |
446 | 0 | QLOG_U64("limit", x); |
447 | 0 | } |
448 | 0 | break; |
449 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED: |
450 | 0 | { |
451 | 0 | uint64_t stream_id, x; |
452 | |
|
453 | 0 | if (!ossl_quic_wire_decode_frame_stream_data_blocked(pkt, |
454 | 0 | &stream_id, |
455 | 0 | &x)) |
456 | 0 | goto unknown; |
457 | | |
458 | 0 | QLOG_STR("frame_type", "stream_data_blocked"); |
459 | 0 | QLOG_U64("stream_id", stream_id); |
460 | 0 | QLOG_U64("limit", x); |
461 | 0 | } |
462 | 0 | break; |
463 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI: |
464 | 0 | case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI: |
465 | 0 | { |
466 | 0 | uint64_t x; |
467 | |
|
468 | 0 | if (!ossl_quic_wire_decode_frame_streams_blocked(pkt, &x)) |
469 | 0 | goto unknown; |
470 | | |
471 | 0 | QLOG_STR("frame_type", "streams_blocked"); |
472 | 0 | QLOG_STR("stream_type", |
473 | 0 | frame_type == OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI |
474 | 0 | ? "bidirectional" : "unidirectional"); |
475 | 0 | QLOG_U64("limit", x); |
476 | 0 | } |
477 | 0 | break; |
478 | 0 | case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN: |
479 | 0 | { |
480 | 0 | const unsigned char *token; |
481 | 0 | size_t token_len; |
482 | |
|
483 | 0 | if (!ossl_quic_wire_decode_frame_new_token(pkt, &token, &token_len)) |
484 | 0 | goto unknown; |
485 | | |
486 | 0 | QLOG_STR("frame_type", "new_token"); |
487 | 0 | QLOG_BEGIN("token"); |
488 | 0 | QLOG_BEGIN("raw"); |
489 | 0 | QLOG_BIN("data", token, token_len); |
490 | 0 | QLOG_END(); |
491 | 0 | QLOG_END(); |
492 | 0 | } |
493 | 0 | break; |
494 | 0 | default: |
495 | 0 | unknown: |
496 | 0 | QLOG_STR("frame_type", "unknown"); |
497 | 0 | QLOG_U64("frame_type_value", frame_type); |
498 | | |
499 | | /* |
500 | | * Can't continue scanning for frames in this case as the frame length |
501 | | * is unknown. We log the entire body of the rest of the packet payload |
502 | | * as the raw data of the frame. |
503 | | */ |
504 | 0 | QLOG_BEGIN("raw"); |
505 | 0 | QLOG_BIN("data", PACKET_data(&orig_pkt), |
506 | 0 | PACKET_remaining(&orig_pkt)); |
507 | 0 | QLOG_END(); |
508 | 0 | ignore_res(PACKET_forward(pkt, PACKET_remaining(pkt))); |
509 | 0 | break; |
510 | 0 | } |
511 | | |
512 | 0 | return 1; |
513 | 0 | } |
514 | | |
515 | | static void log_frame(QLOG *qlog_instance, PACKET *pkt, |
516 | | size_t *need_skip) |
517 | 0 | { |
518 | 0 | size_t rem_before, rem_after; |
519 | |
|
520 | 0 | rem_before = PACKET_remaining(pkt); |
521 | |
|
522 | 0 | if (!log_frame_actual(qlog_instance, pkt, need_skip)) |
523 | 0 | return; |
524 | | |
525 | 0 | rem_after = PACKET_remaining(pkt); |
526 | 0 | QLOG_U64("length", rem_before - rem_after); |
527 | 0 | } |
528 | | |
529 | | static int log_frames(QLOG *qlog_instance, |
530 | | const OSSL_QTX_IOVEC *iovec, |
531 | | size_t num_iovec) |
532 | 0 | { |
533 | 0 | size_t i; |
534 | 0 | PACKET pkt; |
535 | 0 | size_t need_skip = 0; |
536 | |
|
537 | 0 | for (i = 0; i < num_iovec; ++i) { |
538 | 0 | if (!PACKET_buf_init(&pkt, iovec[i].buf, iovec[i].buf_len)) |
539 | 0 | return 0; |
540 | | |
541 | 0 | while (PACKET_remaining(&pkt) > 0) { |
542 | 0 | if (need_skip > 0) { |
543 | 0 | size_t adv = need_skip; |
544 | |
|
545 | 0 | if (adv < PACKET_remaining(&pkt)) |
546 | 0 | adv = PACKET_remaining(&pkt); |
547 | |
|
548 | 0 | if (!PACKET_forward(&pkt, adv)) |
549 | 0 | return 0; |
550 | | |
551 | 0 | need_skip -= adv; |
552 | 0 | continue; |
553 | 0 | } |
554 | | |
555 | 0 | QLOG_BEGIN(NULL) |
556 | 0 | { |
557 | 0 | log_frame(qlog_instance, &pkt, &need_skip); |
558 | 0 | } |
559 | 0 | QLOG_END() |
560 | 0 | } |
561 | 0 | } |
562 | | |
563 | 0 | return 1; |
564 | 0 | } |
565 | | |
566 | | static void log_packet(QLOG *qlog_instance, |
567 | | const QUIC_PKT_HDR *hdr, |
568 | | QUIC_PN pn, |
569 | | const OSSL_QTX_IOVEC *iovec, |
570 | | size_t num_iovec, |
571 | | uint64_t datagram_id) |
572 | 0 | { |
573 | 0 | const char *type_s; |
574 | |
|
575 | 0 | QLOG_BEGIN("header") |
576 | 0 | type_s = quic_pkt_type_to_qlog(hdr->type); |
577 | 0 | if (type_s == NULL) |
578 | 0 | type_s = "unknown"; |
579 | |
|
580 | 0 | QLOG_STR("packet_type", type_s); |
581 | 0 | if (ossl_quic_pkt_type_has_pn(hdr->type)) |
582 | 0 | QLOG_U64("packet_number", pn); |
583 | |
|
584 | 0 | QLOG_CID("dcid", &hdr->dst_conn_id); |
585 | 0 | if (ossl_quic_pkt_type_has_scid(hdr->type)) |
586 | 0 | QLOG_CID("scid", &hdr->src_conn_id); |
587 | |
|
588 | 0 | if (hdr->token_len > 0) { |
589 | 0 | QLOG_BEGIN("token") |
590 | 0 | QLOG_BEGIN("raw") |
591 | 0 | QLOG_BIN("data", hdr->token, hdr->token_len); |
592 | 0 | QLOG_END() |
593 | 0 | QLOG_END() |
594 | 0 | } |
595 | | /* TODO(QLOG FUTURE): flags, length */ |
596 | 0 | QLOG_END() |
597 | 0 | QLOG_U64("datagram_id", datagram_id); |
598 | |
|
599 | 0 | if (ossl_quic_pkt_type_is_encrypted(hdr->type)) { |
600 | 0 | QLOG_BEGIN_ARRAY("frames") |
601 | 0 | log_frames(qlog_instance, iovec, num_iovec); |
602 | 0 | QLOG_END_ARRAY() |
603 | 0 | } |
604 | 0 | } |
605 | | |
606 | | #endif |
607 | | |
608 | | void ossl_qlog_event_transport_packet_sent(QLOG *qlog, |
609 | | const QUIC_PKT_HDR *hdr, |
610 | | QUIC_PN pn, |
611 | | const OSSL_QTX_IOVEC *iovec, |
612 | | size_t num_iovec, |
613 | | uint64_t datagram_id) |
614 | 0 | { |
615 | 0 | #ifndef OPENSSL_NO_QLOG |
616 | 0 | QLOG_EVENT_BEGIN(qlog, transport, packet_sent) |
617 | 0 | log_packet(qlog, hdr, pn, iovec, num_iovec, datagram_id); |
618 | 0 | QLOG_EVENT_END() |
619 | 0 | #endif |
620 | 0 | } |
621 | | |
622 | | void ossl_qlog_event_transport_packet_received(QLOG *qlog, |
623 | | const QUIC_PKT_HDR *hdr, |
624 | | QUIC_PN pn, |
625 | | const OSSL_QTX_IOVEC *iovec, |
626 | | size_t num_iovec, |
627 | | uint64_t datagram_id) |
628 | 0 | { |
629 | 0 | #ifndef OPENSSL_NO_QLOG |
630 | 0 | QLOG_EVENT_BEGIN(qlog, transport, packet_received) |
631 | 0 | log_packet(qlog, hdr, pn, iovec, num_iovec, datagram_id); |
632 | 0 | QLOG_EVENT_END() |
633 | 0 | #endif |
634 | 0 | } |