• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif /* HAVE_CONFIG_H */
31 
32 #include <ngtcp2/ngtcp2.h>
33 
34 typedef struct ngtcp2_pmtud {
35   const ngtcp2_mem *mem;
36   /* mtu_idx is the index of UDP payload size candidates to try
37      out. */
38   size_t mtu_idx;
39   /* num_pkts_sent is the number of mtu_idx sized UDP datagram payload
40      sent */
41   size_t num_pkts_sent;
42   /* expiry is the expired, if it is reached, send out the next UDP
43      datagram.  UINT64_MAX means no expiry, or expiration is canceled.
44      In either case, new probe packet should be sent unless we have
45      done all attempts. */
46   ngtcp2_tstamp expiry;
47   /* tx_pkt_num is the smallest outgoing packet number where the
48      current discovery is performed.  In other words, acknowledging
49      packet whose packet number lower than that does not indicate the
50      success of Path MTU Discovery. */
51   int64_t tx_pkt_num;
52   /* max_udp_payload_size is the maximum UDP payload size which is
53      known to work. */
54   size_t max_udp_payload_size;
55   /* hard_max_udp_payload_size is the maximum UDP payload size that is
56      going to be probed. */
57   size_t hard_max_udp_payload_size;
58   /* min_fail_udp_payload_size is the minimum UDP payload size that is
59      known to fail. */
60   size_t min_fail_udp_payload_size;
61 } ngtcp2_pmtud;
62 
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  * This function returns 0 if it succeeds, or one of the following
74  * negative error codes:
75  *
76  * NGTCP2_ERR_NOMEM
77  *     Out of memory.
78  */
79 int ngtcp2_pmtud_new(ngtcp2_pmtud **ppmtud, size_t max_udp_payload_size,
80                      size_t hard_max_udp_payload_size, int64_t tx_pkt_num,
81                      const ngtcp2_mem *mem);
82 
83 /*
84  * ngtcp2_pmtud_del deletes |pmtud|.
85  */
86 void ngtcp2_pmtud_del(ngtcp2_pmtud *pmtud);
87 
88 /*
89  * ngtcp2_pmtud_probelen returns the length of UDP payload size for a
90  * PMTUD probe packet.
91  */
92 size_t ngtcp2_pmtud_probelen(ngtcp2_pmtud *pmtud);
93 
94 /*
95  * ngtcp2_pmtud_probe_sent should be invoked when a PMTUD probe packet is
96  * sent.
97  */
98 void ngtcp2_pmtud_probe_sent(ngtcp2_pmtud *pmtud, ngtcp2_duration pto,
99                              ngtcp2_tstamp ts);
100 
101 /*
102  * ngtcp2_pmtud_require_probe returns nonzero if a PMTUD probe packet
103  * should be sent.
104  */
105 int ngtcp2_pmtud_require_probe(ngtcp2_pmtud *pmtud);
106 
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 /*
114  * ngtcp2_pmtud_handle_expiry handles expiry.
115  */
116 void ngtcp2_pmtud_handle_expiry(ngtcp2_pmtud *pmtud, ngtcp2_tstamp ts);
117 
118 /*
119  * ngtcp2_pmtud_finished returns nonzero if PMTUD has finished.
120  */
121 int ngtcp2_pmtud_finished(ngtcp2_pmtud *pmtud);
122 
123 #endif /* NGTCP2_PMTUD_H */
124