quic_cfq.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright 2022-2023 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_CFQ_H
  10. # define OSSL_QUIC_CFQ_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # include "internal/quic_predef.h"
  14. # ifndef OPENSSL_NO_QUIC
  15. /*
  16. * QUIC Control Frame Queue Item
  17. * =============================
  18. *
  19. * The CFQ item structure has a public and a private part. This structure
  20. * documents the public part.
  21. */
  22. typedef struct quic_cfq_item_st QUIC_CFQ_ITEM;
  23. struct quic_cfq_item_st {
  24. /*
  25. * These fields are not used by the CFQ, but are a convenience to assist the
  26. * TXPIM in keeping a list of GCR control frames which were sent in a
  27. * packet. They may be used for any purpose.
  28. */
  29. QUIC_CFQ_ITEM *pkt_prev, *pkt_next;
  30. /* All other fields are private; use ossl_quic_cfq_item_* accessors. */
  31. };
  32. # define QUIC_CFQ_STATE_NEW 0
  33. # define QUIC_CFQ_STATE_TX 1
  34. /* If set, do not retransmit on loss */
  35. #define QUIC_CFQ_ITEM_FLAG_UNRELIABLE (1U << 0)
  36. /* Returns the frame type of a CFQ item. */
  37. uint64_t ossl_quic_cfq_item_get_frame_type(const QUIC_CFQ_ITEM *item);
  38. /* Returns a pointer to the encoded buffer of a CFQ item. */
  39. const unsigned char *ossl_quic_cfq_item_get_encoded(const QUIC_CFQ_ITEM *item);
  40. /* Returns the length of the encoded buffer in bytes. */
  41. size_t ossl_quic_cfq_item_get_encoded_len(const QUIC_CFQ_ITEM *item);
  42. /* Returns the CFQ item state, a QUIC_CFQ_STATE_* value. */
  43. int ossl_quic_cfq_item_get_state(const QUIC_CFQ_ITEM *item);
  44. /* Returns the PN space for the CFQ item. */
  45. uint32_t ossl_quic_cfq_item_get_pn_space(const QUIC_CFQ_ITEM *item);
  46. /* Returns 1 if this is an unreliable frame. */
  47. int ossl_quic_cfq_item_is_unreliable(const QUIC_CFQ_ITEM *item);
  48. /*
  49. * QUIC Control Frame Queue
  50. * ========================
  51. */
  52. QUIC_CFQ *ossl_quic_cfq_new(void);
  53. void ossl_quic_cfq_free(QUIC_CFQ *cfq);
  54. /*
  55. * Input Side
  56. * ----------
  57. */
  58. /*
  59. * Enqueue a frame to the CFQ.
  60. *
  61. * encoded points to the opaque encoded frame.
  62. *
  63. * free_cb is called by the CFQ when the buffer is no longer needed;
  64. * free_cb_arg is an opaque value passed to free_cb.
  65. *
  66. * priority determines the relative ordering of control frames in a packet.
  67. * Lower numerical values for priority mean that a frame should come earlier in
  68. * a packet. pn_space is a QUIC_PN_SPACE_* value.
  69. *
  70. * On success, returns a QUIC_CFQ_ITEM pointer which acts as a handle to
  71. * the queued frame. On failure, returns NULL.
  72. *
  73. * The frame is initially in the TX state, so there is no need to call
  74. * ossl_quic_cfq_mark_tx() immediately after calling this function.
  75. *
  76. * The frame type is duplicated as the frame_type argument here, even though it
  77. * is also encoded into the buffer. This allows the caller to determine the
  78. * frame type if desired without having to decode the frame.
  79. *
  80. * flags is zero or more QUIC_CFQ_ITEM_FLAG values.
  81. */
  82. typedef void (cfq_free_cb)(unsigned char *buf, size_t buf_len, void *arg);
  83. QUIC_CFQ_ITEM *ossl_quic_cfq_add_frame(QUIC_CFQ *cfq,
  84. uint32_t priority,
  85. uint32_t pn_space,
  86. uint64_t frame_type,
  87. uint32_t flags,
  88. const unsigned char *encoded,
  89. size_t encoded_len,
  90. cfq_free_cb *free_cb,
  91. void *free_cb_arg);
  92. /*
  93. * Effects an immediate transition of the given CFQ item to the TX state.
  94. */
  95. void ossl_quic_cfq_mark_tx(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item);
  96. /*
  97. * Effects an immediate transition of the given CFQ item to the NEW state,
  98. * allowing the frame to be retransmitted. If priority is not UINT32_MAX,
  99. * the priority is changed to the given value.
  100. */
  101. void ossl_quic_cfq_mark_lost(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item,
  102. uint32_t priority);
  103. /*
  104. * Releases a CFQ item. The item may be in either state (NEW or TX) prior to the
  105. * call. The QUIC_CFQ_ITEM pointer must not be used following this call.
  106. */
  107. void ossl_quic_cfq_release(QUIC_CFQ *cfq, QUIC_CFQ_ITEM *item);
  108. /*
  109. * Output Side
  110. * -----------
  111. */
  112. /*
  113. * Gets the highest priority CFQ item in the given PN space awaiting
  114. * transmission. If there are none, returns NULL.
  115. */
  116. QUIC_CFQ_ITEM *ossl_quic_cfq_get_priority_head(const QUIC_CFQ *cfq,
  117. uint32_t pn_space);
  118. /*
  119. * Given a CFQ item, gets the next CFQ item awaiting transmission in priority
  120. * order in the given PN space. In other words, given the return value of
  121. * ossl_quic_cfq_get_priority_head(), returns the next-lower priority item.
  122. * Returns NULL if the given item is the last item in priority order.
  123. */
  124. QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(const QUIC_CFQ_ITEM *item,
  125. uint32_t pn_space);
  126. # endif
  127. #endif