2
0

quic_txpim.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2022-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. #ifndef OSSL_QUIC_TXPIM_H
  10. # define OSSL_QUIC_TXPIM_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # include "internal/quic_predef.h"
  14. # include "internal/quic_cfq.h"
  15. # include "internal/quic_ackm.h"
  16. # ifndef OPENSSL_NO_QUIC
  17. /*
  18. * QUIC Transmitted Packet Information Manager
  19. * ===========================================
  20. */
  21. typedef struct quic_txpim_pkt_st {
  22. /* ACKM-specific data. Caller should fill this. */
  23. OSSL_ACKM_TX_PKT ackm_pkt;
  24. /* Linked list of CFQ items in this packet. */
  25. QUIC_CFQ_ITEM *retx_head;
  26. /* Reserved for FIFD use. */
  27. QUIC_FIFD *fifd;
  28. /* QUIC_PKT_TYPE value. For diagnostic use only. */
  29. unsigned char pkt_type;
  30. /* Regenerate-strategy frames. */
  31. unsigned int had_handshake_done_frame : 1;
  32. unsigned int had_max_data_frame : 1;
  33. unsigned int had_max_streams_bidi_frame : 1;
  34. unsigned int had_max_streams_uni_frame : 1;
  35. unsigned int had_ack_frame : 1;
  36. unsigned int had_conn_close : 1;
  37. /* Private data follows. */
  38. } QUIC_TXPIM_PKT;
  39. /* Represents a range of bytes in an application or CRYPTO stream. */
  40. typedef struct quic_txpim_chunk_st {
  41. /* The stream ID, or UINT64_MAX for the CRYPTO stream. */
  42. uint64_t stream_id;
  43. /*
  44. * The inclusive range of bytes in the stream. Exceptionally, if end <
  45. * start, designates a frame of zero length (used for FIN-only frames). In
  46. * this case end is the number of the final byte (i.e., one less than the
  47. * final size of the stream).
  48. */
  49. uint64_t start, end;
  50. /*
  51. * Whether a FIN was sent for this stream in the packet. Not valid for
  52. * CRYPTO stream.
  53. */
  54. unsigned int has_fin : 1;
  55. /*
  56. * If set, a STOP_SENDING frame was sent for this stream ID. (If no data was
  57. * sent for the stream, set end < start.)
  58. */
  59. unsigned int has_stop_sending : 1;
  60. /*
  61. * If set, a RESET_STREAM frame was sent for this stream ID. (If no data was
  62. * sent for the stream, set end < start.)
  63. */
  64. unsigned int has_reset_stream : 1;
  65. } QUIC_TXPIM_CHUNK;
  66. QUIC_TXPIM *ossl_quic_txpim_new(void);
  67. /*
  68. * Frees the TXPIM. All QUIC_TXPIM_PKTs which have been handed out by the TXPIM
  69. * must be released via a call to ossl_quic_txpim_pkt_release() before calling
  70. * this function.
  71. */
  72. void ossl_quic_txpim_free(QUIC_TXPIM *txpim);
  73. /*
  74. * Allocates a new QUIC_TXPIM_PKT structure from the pool. Returns NULL on
  75. * failure. The returned structure is cleared of all data and is in a fresh
  76. * initial state.
  77. */
  78. QUIC_TXPIM_PKT *ossl_quic_txpim_pkt_alloc(QUIC_TXPIM *txpim);
  79. /*
  80. * Releases the TXPIM packet, returning it to the pool.
  81. */
  82. void ossl_quic_txpim_pkt_release(QUIC_TXPIM *txpim, QUIC_TXPIM_PKT *fpkt);
  83. /* Clears the chunk list of the packet, removing all entries. */
  84. void ossl_quic_txpim_pkt_clear_chunks(QUIC_TXPIM_PKT *fpkt);
  85. /* Appends a chunk to the packet. The structure is copied. */
  86. int ossl_quic_txpim_pkt_append_chunk(QUIC_TXPIM_PKT *fpkt,
  87. const QUIC_TXPIM_CHUNK *chunk);
  88. /* Adds a CFQ item to the packet by prepending it to the retx_head list. */
  89. void ossl_quic_txpim_pkt_add_cfq_item(QUIC_TXPIM_PKT *fpkt,
  90. QUIC_CFQ_ITEM *item);
  91. /*
  92. * Returns a pointer to an array of stream chunk information structures for the
  93. * given packet. The caller must call ossl_quic_txpim_pkt_get_num_chunks() to
  94. * determine the length of this array. The returned pointer is invalidated
  95. * if the chunk list is mutated, for example via a call to
  96. * ossl_quic_txpim_pkt_append_chunk() or ossl_quic_txpim_pkt_clear_chunks().
  97. *
  98. * The chunks are sorted by (stream_id, start) in ascending order.
  99. */
  100. const QUIC_TXPIM_CHUNK *ossl_quic_txpim_pkt_get_chunks(const QUIC_TXPIM_PKT *fpkt);
  101. /*
  102. * Returns the number of entries in the array returned by
  103. * ossl_quic_txpim_pkt_get_chunks().
  104. */
  105. size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt);
  106. /*
  107. * Returns the number of QUIC_TXPIM_PKTs allocated by the given TXPIM that have
  108. * yet to be returned to the TXPIM.
  109. */
  110. size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim);
  111. # endif
  112. #endif