ngtcp2_pmtud.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2022 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_PMTUD_H
  26. #define NGTCP2_PMTUD_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. typedef struct ngtcp2_pmtud {
  32. const ngtcp2_mem *mem;
  33. /* mtu_idx is the index of UDP payload size candidates to try
  34. out. */
  35. size_t mtu_idx;
  36. /* num_pkts_sent is the number of mtu_idx sized UDP datagram payload
  37. sent */
  38. size_t num_pkts_sent;
  39. /* expiry is the expired, if it is reached, send out the next UDP
  40. datagram. UINT64_MAX means no expiry, or expiration is canceled.
  41. In either case, new probe packet should be sent unless we have
  42. done all attempts. */
  43. ngtcp2_tstamp expiry;
  44. /* tx_pkt_num is the smallest outgoing packet number where the
  45. current discovery is performed. In other words, acknowledging
  46. packet whose packet number lower than that does not indicate the
  47. success of Path MTU Discovery. */
  48. int64_t tx_pkt_num;
  49. /* max_udp_payload_size is the maximum UDP payload size which is
  50. known to work. */
  51. size_t max_udp_payload_size;
  52. /* hard_max_udp_payload_size is the maximum UDP payload size that is
  53. going to be probed. */
  54. size_t hard_max_udp_payload_size;
  55. /* min_fail_udp_payload_size is the minimum UDP payload size that is
  56. known to fail. */
  57. size_t min_fail_udp_payload_size;
  58. /* probes is the array of UDP datagram payload size to probe. */
  59. const uint16_t *probes;
  60. /* probeslen is the number of probes pointed by probes. */
  61. size_t probeslen;
  62. } ngtcp2_pmtud;
  63. /*
  64. * ngtcp2_pmtud_new creates new ngtcp2_pmtud object, and assigns its
  65. * pointer to |*ppmtud|. |max_udp_payload_size| is the maximum UDP
  66. * payload size that is known to work for the current path.
  67. * |tx_pkt_num| should be the next packet number to send, which is
  68. * used to differentiate the PMTUD probe packet sent by the previous
  69. * PMTUD. PMTUD might finish immediately if |max_udp_payload_size| is
  70. * larger than or equal to all UDP payload probe candidates.
  71. * Therefore, call ngtcp2_pmtud_finished to check this situation.
  72. *
  73. * The array pointed by |pmtud_probes| of length |pmtud_probeslen|
  74. * specifies UDP datagram payload size to probe. If |pmtud_probeslen|
  75. * is zero, the default probes are used.
  76. *
  77. * This function returns 0 if it succeeds, or one of the following
  78. * negative error codes:
  79. *
  80. * NGTCP2_ERR_NOMEM
  81. * Out of memory.
  82. */
  83. int ngtcp2_pmtud_new(ngtcp2_pmtud **ppmtud, size_t max_udp_payload_size,
  84. size_t hard_max_udp_payload_size, int64_t tx_pkt_num,
  85. const uint16_t *pmtud_probes, size_t pmtud_probeslen,
  86. const ngtcp2_mem *mem);
  87. /*
  88. * ngtcp2_pmtud_del deletes |pmtud|.
  89. */
  90. void ngtcp2_pmtud_del(ngtcp2_pmtud *pmtud);
  91. /*
  92. * ngtcp2_pmtud_probelen returns the length of UDP payload size for a
  93. * PMTUD probe packet.
  94. */
  95. size_t ngtcp2_pmtud_probelen(ngtcp2_pmtud *pmtud);
  96. /*
  97. * ngtcp2_pmtud_probe_sent should be invoked when a PMTUD probe packet is
  98. * sent.
  99. */
  100. void ngtcp2_pmtud_probe_sent(ngtcp2_pmtud *pmtud, ngtcp2_duration pto,
  101. ngtcp2_tstamp ts);
  102. /*
  103. * ngtcp2_pmtud_require_probe returns nonzero if a PMTUD probe packet
  104. * should be sent.
  105. */
  106. int ngtcp2_pmtud_require_probe(ngtcp2_pmtud *pmtud);
  107. /*
  108. * ngtcp2_pmtud_probe_success should be invoked when a PMTUD probe
  109. * UDP datagram sized |payloadlen| is acknowledged.
  110. */
  111. void ngtcp2_pmtud_probe_success(ngtcp2_pmtud *pmtud, size_t payloadlen);
  112. /*
  113. * ngtcp2_pmtud_handle_expiry handles expiry.
  114. */
  115. void ngtcp2_pmtud_handle_expiry(ngtcp2_pmtud *pmtud, ngtcp2_tstamp ts);
  116. /*
  117. * ngtcp2_pmtud_finished returns nonzero if PMTUD has finished.
  118. */
  119. int ngtcp2_pmtud_finished(ngtcp2_pmtud *pmtud);
  120. #endif /* !defined(NGTCP2_PMTUD_H) */