qlog_event_helpers.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. #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. return 0;
  197. /*
  198. * If something goes wrong decoding a frame we cannot log it as that frame
  199. * as we need to know how to decode it in order to be able to do so, but in
  200. * that case we log it as an unknown frame to assist with diagnosis.
  201. */
  202. switch (frame_type) {
  203. case OSSL_QUIC_FRAME_TYPE_PADDING:
  204. QLOG_STR("frame_type", "padding");
  205. QLOG_U64("payload_length",
  206. ossl_quic_wire_decode_padding(pkt));
  207. break;
  208. case OSSL_QUIC_FRAME_TYPE_PING:
  209. if (!ossl_quic_wire_decode_frame_ping(pkt))
  210. goto unknown;
  211. QLOG_STR("frame_type", "ping");
  212. break;
  213. case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
  214. case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
  215. if (!ossl_quic_wire_peek_frame_ack_num_ranges(pkt, &num_ranges))
  216. goto unknown;
  217. ack.ack_ranges = ack_ranges;
  218. ack.num_ack_ranges = OSSL_NELEM(ack_ranges);
  219. if (!ossl_quic_wire_decode_frame_ack(pkt, 3, &ack, &total_ranges))
  220. goto unknown;
  221. QLOG_STR("frame_type", "ack");
  222. QLOG_U64("ack_delay", ossl_time2ms(ack.delay_time));
  223. if (ack.ecn_present) {
  224. QLOG_U64("ect1", ack.ect0);
  225. QLOG_U64("ect0", ack.ect1);
  226. QLOG_U64("ce", ack.ecnce);
  227. }
  228. QLOG_BEGIN_ARRAY("acked_ranges");
  229. for (i = 0; i < ack.num_ack_ranges; ++i) {
  230. QLOG_BEGIN_ARRAY(NULL)
  231. QLOG_U64(NULL, ack.ack_ranges[i].start);
  232. if (ack.ack_ranges[i].end != ack.ack_ranges[i].start)
  233. QLOG_U64(NULL, ack.ack_ranges[i].end);
  234. QLOG_END_ARRAY()
  235. }
  236. QLOG_END_ARRAY()
  237. break;
  238. case OSSL_QUIC_FRAME_TYPE_RESET_STREAM:
  239. {
  240. OSSL_QUIC_FRAME_RESET_STREAM f;
  241. if (!ossl_quic_wire_decode_frame_reset_stream(pkt, &f))
  242. goto unknown;
  243. QLOG_STR("frame_type", "reset_stream");
  244. QLOG_U64("stream_id", f.stream_id);
  245. QLOG_U64("error_code", f.app_error_code);
  246. QLOG_U64("final_size", f.final_size);
  247. }
  248. break;
  249. case OSSL_QUIC_FRAME_TYPE_STOP_SENDING:
  250. {
  251. OSSL_QUIC_FRAME_STOP_SENDING f;
  252. if (!ossl_quic_wire_decode_frame_stop_sending(pkt, &f))
  253. goto unknown;
  254. QLOG_STR("frame_type", "stop_sending");
  255. QLOG_U64("stream_id", f.stream_id);
  256. QLOG_U64("error_code", f.app_error_code);
  257. }
  258. break;
  259. case OSSL_QUIC_FRAME_TYPE_CRYPTO:
  260. {
  261. OSSL_QUIC_FRAME_CRYPTO f;
  262. if (!ossl_quic_wire_decode_frame_crypto(pkt, 1, &f))
  263. goto unknown;
  264. QLOG_STR("frame_type", "crypto");
  265. QLOG_U64("offset", f.offset);
  266. QLOG_U64("payload_length", f.len);
  267. *need_skip += (size_t)f.len;
  268. }
  269. break;
  270. case OSSL_QUIC_FRAME_TYPE_STREAM:
  271. case OSSL_QUIC_FRAME_TYPE_STREAM_FIN:
  272. case OSSL_QUIC_FRAME_TYPE_STREAM_LEN:
  273. case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN:
  274. case OSSL_QUIC_FRAME_TYPE_STREAM_OFF:
  275. case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN:
  276. case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN:
  277. case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN:
  278. {
  279. OSSL_QUIC_FRAME_STREAM f;
  280. if (!ossl_quic_wire_decode_frame_stream(pkt, 1, &f))
  281. goto unknown;
  282. QLOG_STR("frame_type", "stream");
  283. QLOG_U64("stream_id", f.stream_id);
  284. QLOG_U64("offset", f.offset);
  285. QLOG_U64("payload_length", f.len);
  286. QLOG_BOOL("explicit_length", f.has_explicit_len);
  287. if (f.is_fin)
  288. QLOG_BOOL("fin", 1);
  289. *need_skip = f.has_explicit_len
  290. ? *need_skip + (size_t)f.len : SIZE_MAX;
  291. }
  292. break;
  293. case OSSL_QUIC_FRAME_TYPE_MAX_DATA:
  294. {
  295. uint64_t x;
  296. if (!ossl_quic_wire_decode_frame_max_data(pkt, &x))
  297. goto unknown;
  298. QLOG_STR("frame_type", "max_data");
  299. QLOG_U64("maximum", x);
  300. }
  301. break;
  302. case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI:
  303. case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI:
  304. {
  305. uint64_t x;
  306. if (!ossl_quic_wire_decode_frame_max_streams(pkt, &x))
  307. goto unknown;
  308. QLOG_STR("frame_type", "max_streams");
  309. QLOG_STR("stream_type",
  310. frame_type == OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI
  311. ? "bidirectional" : "unidirectional");
  312. QLOG_U64("maximum", x);
  313. }
  314. break;
  315. case OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA:
  316. {
  317. uint64_t stream_id, max_data;
  318. if (!ossl_quic_wire_decode_frame_max_stream_data(pkt, &stream_id,
  319. &max_data))
  320. goto unknown;
  321. QLOG_STR("frame_type", "max_stream_data");
  322. QLOG_U64("stream_id", stream_id);
  323. QLOG_U64("maximum", max_data);
  324. }
  325. break;
  326. case OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE:
  327. {
  328. uint64_t challenge;
  329. if (!ossl_quic_wire_decode_frame_path_challenge(pkt, &challenge))
  330. goto unknown;
  331. QLOG_STR("frame_type", "path_challenge");
  332. }
  333. break;
  334. case OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE:
  335. {
  336. uint64_t challenge;
  337. if (!ossl_quic_wire_decode_frame_path_response(pkt, &challenge))
  338. goto unknown;
  339. QLOG_STR("frame_type", "path_response");
  340. }
  341. break;
  342. case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP:
  343. case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT:
  344. {
  345. OSSL_QUIC_FRAME_CONN_CLOSE f;
  346. if (!ossl_quic_wire_decode_frame_conn_close(pkt, &f))
  347. goto unknown;
  348. QLOG_STR("frame_type", "connection_close");
  349. QLOG_STR("error_space", f.is_app ? "application" : "transport");
  350. QLOG_U64("error_code_value", f.error_code);
  351. if (f.is_app)
  352. QLOG_U64("error_code", f.error_code);
  353. if (!f.is_app && f.frame_type != 0)
  354. QLOG_U64("trigger_frame_type", f.frame_type);
  355. QLOG_STR_LEN("reason", f.reason, f.reason_len);
  356. }
  357. break;
  358. case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE:
  359. {
  360. if (!ossl_quic_wire_decode_frame_handshake_done(pkt))
  361. goto unknown;
  362. QLOG_STR("frame_type", "handshake_done");
  363. }
  364. break;
  365. case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID:
  366. {
  367. OSSL_QUIC_FRAME_NEW_CONN_ID f;
  368. if (!ossl_quic_wire_decode_frame_new_conn_id(pkt, &f))
  369. goto unknown;
  370. QLOG_STR("frame_type", "new_connection_id");
  371. QLOG_U64("sequence_number", f.seq_num);
  372. QLOG_U64("retire_prior_to", f.retire_prior_to);
  373. QLOG_CID("connection_id", &f.conn_id);
  374. QLOG_BIN("stateless_reset_token",
  375. f.stateless_reset.token,
  376. sizeof(f.stateless_reset.token));
  377. }
  378. break;
  379. case OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID:
  380. {
  381. uint64_t seq_num;
  382. if (!ossl_quic_wire_decode_frame_retire_conn_id(pkt, &seq_num))
  383. goto unknown;
  384. QLOG_STR("frame_type", "retire_connection_id");
  385. QLOG_U64("sequence_number", seq_num);
  386. }
  387. break;
  388. case OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED:
  389. {
  390. uint64_t x;
  391. if (!ossl_quic_wire_decode_frame_data_blocked(pkt, &x))
  392. goto unknown;
  393. QLOG_STR("frame_type", "data_blocked");
  394. QLOG_U64("limit", x);
  395. }
  396. break;
  397. case OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED:
  398. {
  399. uint64_t stream_id, x;
  400. if (!ossl_quic_wire_decode_frame_stream_data_blocked(pkt,
  401. &stream_id,
  402. &x))
  403. goto unknown;
  404. QLOG_STR("frame_type", "stream_data_blocked");
  405. QLOG_U64("stream_id", stream_id);
  406. QLOG_U64("limit", x);
  407. }
  408. break;
  409. case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI:
  410. case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI:
  411. {
  412. uint64_t x;
  413. if (!ossl_quic_wire_decode_frame_streams_blocked(pkt, &x))
  414. goto unknown;
  415. QLOG_STR("frame_type", "streams_blocked");
  416. QLOG_STR("stream_type",
  417. frame_type == OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI
  418. ? "bidirectional" : "unidirectional");
  419. QLOG_U64("limit", x);
  420. }
  421. break;
  422. case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN:
  423. {
  424. const unsigned char *token;
  425. size_t token_len;
  426. if (!ossl_quic_wire_decode_frame_new_token(pkt, &token, &token_len))
  427. goto unknown;
  428. QLOG_STR("frame_type", "new_token");
  429. QLOG_BEGIN("token");
  430. QLOG_BEGIN("raw");
  431. QLOG_BIN("data", token, token_len);
  432. QLOG_END();
  433. QLOG_END();
  434. }
  435. break;
  436. default:
  437. unknown:
  438. QLOG_STR("frame_type", "unknown");
  439. QLOG_U64("frame_type_value", frame_type);
  440. /*
  441. * Can't continue scanning for frames in this case as the frame length
  442. * is unknown. We log the entire body of the rest of the packet payload
  443. * as the raw data of the frame.
  444. */
  445. QLOG_BEGIN("raw");
  446. QLOG_BIN("data", PACKET_data(&orig_pkt),
  447. PACKET_remaining(&orig_pkt));
  448. QLOG_END();
  449. ignore_res(PACKET_forward(pkt, PACKET_remaining(pkt)));
  450. break;
  451. }
  452. return 1;
  453. }
  454. static void log_frame(QLOG *qlog_instance, PACKET *pkt,
  455. size_t *need_skip)
  456. {
  457. size_t rem_before, rem_after;
  458. rem_before = PACKET_remaining(pkt);
  459. if (!log_frame_actual(qlog_instance, pkt, need_skip))
  460. return;
  461. rem_after = PACKET_remaining(pkt);
  462. QLOG_U64("length", rem_before - rem_after);
  463. }
  464. static int log_frames(QLOG *qlog_instance,
  465. const OSSL_QTX_IOVEC *iovec,
  466. size_t num_iovec)
  467. {
  468. size_t i;
  469. PACKET pkt;
  470. size_t need_skip = 0;
  471. for (i = 0; i < num_iovec; ++i) {
  472. if (!PACKET_buf_init(&pkt, iovec[i].buf, iovec[i].buf_len))
  473. return 0;
  474. while (PACKET_remaining(&pkt) > 0) {
  475. if (need_skip > 0) {
  476. size_t adv = need_skip;
  477. if (adv < PACKET_remaining(&pkt))
  478. adv = PACKET_remaining(&pkt);
  479. if (!PACKET_forward(&pkt, adv))
  480. return 0;
  481. need_skip -= adv;
  482. continue;
  483. }
  484. QLOG_BEGIN(NULL)
  485. {
  486. log_frame(qlog_instance, &pkt, &need_skip);
  487. }
  488. QLOG_END()
  489. }
  490. }
  491. return 1;
  492. }
  493. static void log_packet(QLOG *qlog_instance,
  494. const QUIC_PKT_HDR *hdr,
  495. QUIC_PN pn,
  496. const OSSL_QTX_IOVEC *iovec,
  497. size_t num_iovec,
  498. uint64_t datagram_id)
  499. {
  500. const char *type_s;
  501. QLOG_BEGIN("header")
  502. type_s = quic_pkt_type_to_qlog(hdr->type);
  503. if (type_s == NULL)
  504. type_s = "unknown";
  505. QLOG_STR("packet_type", type_s);
  506. if (ossl_quic_pkt_type_has_pn(hdr->type))
  507. QLOG_U64("packet_number", pn);
  508. QLOG_CID("dcid", &hdr->dst_conn_id);
  509. if (ossl_quic_pkt_type_has_scid(hdr->type))
  510. QLOG_CID("scid", &hdr->src_conn_id);
  511. if (hdr->token_len > 0) {
  512. QLOG_BEGIN("token")
  513. QLOG_BEGIN("raw")
  514. QLOG_BIN("data", hdr->token, hdr->token_len);
  515. QLOG_END()
  516. QLOG_END()
  517. }
  518. /* TODO(QLOG FUTURE): flags, length */
  519. QLOG_END()
  520. QLOG_U64("datagram_id", datagram_id);
  521. if (ossl_quic_pkt_type_is_encrypted(hdr->type)) {
  522. QLOG_BEGIN_ARRAY("frames")
  523. log_frames(qlog_instance, iovec, num_iovec);
  524. QLOG_END_ARRAY()
  525. }
  526. }
  527. #endif
  528. void ossl_qlog_event_transport_packet_sent(QLOG *qlog,
  529. const QUIC_PKT_HDR *hdr,
  530. QUIC_PN pn,
  531. const OSSL_QTX_IOVEC *iovec,
  532. size_t num_iovec,
  533. uint64_t datagram_id)
  534. {
  535. #ifndef OPENSSL_NO_QLOG
  536. QLOG_EVENT_BEGIN(qlog, transport, packet_sent)
  537. log_packet(qlog, hdr, pn, iovec, num_iovec, datagram_id);
  538. QLOG_EVENT_END()
  539. #endif
  540. }
  541. void ossl_qlog_event_transport_packet_received(QLOG *qlog,
  542. const QUIC_PKT_HDR *hdr,
  543. QUIC_PN pn,
  544. const OSSL_QTX_IOVEC *iovec,
  545. size_t num_iovec,
  546. uint64_t datagram_id)
  547. {
  548. #ifndef OPENSSL_NO_QLOG
  549. QLOG_EVENT_BEGIN(qlog, transport, packet_received)
  550. log_packet(qlog, hdr, pn, iovec, num_iovec, datagram_id);
  551. QLOG_EVENT_END()
  552. #endif
  553. }