qlog_event_helpers.c 20 KB

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