xref: /freebsd/crypto/openssl/include/internal/quic_channel.h (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery  *
4*e7be843bSPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery  * in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery  * https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery  */
9*e7be843bSPierre Pronchery 
10*e7be843bSPierre Pronchery #ifndef OSSL_QUIC_CHANNEL_H
11*e7be843bSPierre Pronchery # define OSSL_QUIC_CHANNEL_H
12*e7be843bSPierre Pronchery 
13*e7be843bSPierre Pronchery # include <openssl/ssl.h>
14*e7be843bSPierre Pronchery # include "internal/quic_types.h"
15*e7be843bSPierre Pronchery # include "internal/quic_record_tx.h"
16*e7be843bSPierre Pronchery # include "internal/quic_wire.h"
17*e7be843bSPierre Pronchery # include "internal/quic_predef.h"
18*e7be843bSPierre Pronchery # include "internal/qlog.h"
19*e7be843bSPierre Pronchery # include "internal/time.h"
20*e7be843bSPierre Pronchery # include "internal/thread.h"
21*e7be843bSPierre Pronchery 
22*e7be843bSPierre Pronchery # ifndef OPENSSL_NO_QUIC
23*e7be843bSPierre Pronchery 
24*e7be843bSPierre Pronchery /*
25*e7be843bSPierre Pronchery  * QUIC Channel
26*e7be843bSPierre Pronchery  * ============
27*e7be843bSPierre Pronchery  *
28*e7be843bSPierre Pronchery  * A QUIC channel (QUIC_CHANNEL) is an object which binds together all of the
29*e7be843bSPierre Pronchery  * various pieces of QUIC into a single top-level object, and handles connection
30*e7be843bSPierre Pronchery  * state which is not specific to the client or server roles. In particular, it
31*e7be843bSPierre Pronchery  * is strictly separated from the libssl front end I/O API personality layer,
32*e7be843bSPierre Pronchery  * and is not an SSL object.
33*e7be843bSPierre Pronchery  *
34*e7be843bSPierre Pronchery  * The name QUIC_CHANNEL is chosen because QUIC_CONNECTION is already in use,
35*e7be843bSPierre Pronchery  * but functionally these relate to the same thing (a QUIC connection). The use
36*e7be843bSPierre Pronchery  * of two separate objects ensures clean separation between the API personality
37*e7be843bSPierre Pronchery  * layer and common code for handling connections, and between the functionality
38*e7be843bSPierre Pronchery  * which is specific to clients and which is specific to servers, and the
39*e7be843bSPierre Pronchery  * functionality which is common to both.
40*e7be843bSPierre Pronchery  *
41*e7be843bSPierre Pronchery  * The API personality layer provides SSL objects (e.g. a QUIC_CONNECTION) which
42*e7be843bSPierre Pronchery  * consume a QUIC channel and implement a specific public API. Things which are
43*e7be843bSPierre Pronchery  * handled by the API personality layer include emulation of blocking semantics,
44*e7be843bSPierre Pronchery  * handling of SSL object mode flags like non-partial write mode, etc.
45*e7be843bSPierre Pronchery  *
46*e7be843bSPierre Pronchery  * Where the QUIC_CHANNEL is used in a server role, there is one QUIC_CHANNEL
47*e7be843bSPierre Pronchery  * per connection. In the future a QUIC Channel Manager will probably be defined
48*e7be843bSPierre Pronchery  * to handle ownership of resources which are shared between connections (e.g.
49*e7be843bSPierre Pronchery  * demuxers). Since we only use server-side functionality for dummy test servers
50*e7be843bSPierre Pronchery  * for now, which only need to handle one connection at a time, this is not
51*e7be843bSPierre Pronchery  * currently modelled.
52*e7be843bSPierre Pronchery  *
53*e7be843bSPierre Pronchery  * Synchronisation
54*e7be843bSPierre Pronchery  * ---------------
55*e7be843bSPierre Pronchery  *
56*e7be843bSPierre Pronchery  * To support thread assisted mode, QUIC_CHANNEL can be used by multiple
57*e7be843bSPierre Pronchery  * threads. **It is the caller's responsibility to ensure that the QUIC_CHANNEL
58*e7be843bSPierre Pronchery  * is only accessed (whether via its methods or via direct access to its state)
59*e7be843bSPierre Pronchery  * while the channel mutex is held**, except for methods explicitly marked as
60*e7be843bSPierre Pronchery  * not requiring prior locking. This is an unchecked precondition.
61*e7be843bSPierre Pronchery  *
62*e7be843bSPierre Pronchery  * The instantiator of the channel is responsible for providing a suitable
63*e7be843bSPierre Pronchery  * mutex which then serves as the channel mutex; see QUIC_CHANNEL_ARGS.
64*e7be843bSPierre Pronchery  */
65*e7be843bSPierre Pronchery 
66*e7be843bSPierre Pronchery /*
67*e7be843bSPierre Pronchery  * The function does not acquire the channel mutex and assumes it is already
68*e7be843bSPierre Pronchery  * held by the calling thread.
69*e7be843bSPierre Pronchery  *
70*e7be843bSPierre Pronchery  * Any function tagged with this has the following precondition:
71*e7be843bSPierre Pronchery  *
72*e7be843bSPierre Pronchery  *   Precondition: must hold channel mutex (unchecked)
73*e7be843bSPierre Pronchery  */
74*e7be843bSPierre Pronchery #  define QUIC_NEEDS_LOCK
75*e7be843bSPierre Pronchery 
76*e7be843bSPierre Pronchery /*
77*e7be843bSPierre Pronchery  * The function acquires the channel mutex and releases it before returning in
78*e7be843bSPierre Pronchery  * all circumstances.
79*e7be843bSPierre Pronchery  *
80*e7be843bSPierre Pronchery  * Any function tagged with this has the following precondition and
81*e7be843bSPierre Pronchery  * postcondition:
82*e7be843bSPierre Pronchery  *
83*e7be843bSPierre Pronchery  *   Precondition: must not hold channel mutex (unchecked)
84*e7be843bSPierre Pronchery  *   Postcondition: channel mutex is not held (by calling thread)
85*e7be843bSPierre Pronchery  */
86*e7be843bSPierre Pronchery #  define QUIC_TAKES_LOCK
87*e7be843bSPierre Pronchery 
88*e7be843bSPierre Pronchery /*
89*e7be843bSPierre Pronchery  * The function acquires the channel mutex and leaves it acquired
90*e7be843bSPierre Pronchery  * when returning success.
91*e7be843bSPierre Pronchery  *
92*e7be843bSPierre Pronchery  * Any function tagged with this has the following precondition and
93*e7be843bSPierre Pronchery  * postcondition:
94*e7be843bSPierre Pronchery  *
95*e7be843bSPierre Pronchery  *   Precondition: must not hold channel mutex (unchecked)
96*e7be843bSPierre Pronchery  *   Postcondition: channel mutex is held by calling thread
97*e7be843bSPierre Pronchery  *      or function returned failure
98*e7be843bSPierre Pronchery  */
99*e7be843bSPierre Pronchery #  define QUIC_ACQUIRES_LOCK
100*e7be843bSPierre Pronchery 
101*e7be843bSPierre Pronchery #  define QUIC_TODO_LOCK
102*e7be843bSPierre Pronchery 
103*e7be843bSPierre Pronchery #  define QUIC_CHANNEL_STATE_IDLE                        0
104*e7be843bSPierre Pronchery #  define QUIC_CHANNEL_STATE_ACTIVE                      1
105*e7be843bSPierre Pronchery #  define QUIC_CHANNEL_STATE_TERMINATING_CLOSING         2
106*e7be843bSPierre Pronchery #  define QUIC_CHANNEL_STATE_TERMINATING_DRAINING        3
107*e7be843bSPierre Pronchery #  define QUIC_CHANNEL_STATE_TERMINATED                  4
108*e7be843bSPierre Pronchery 
109*e7be843bSPierre Pronchery typedef struct quic_channel_args_st {
110*e7be843bSPierre Pronchery     /*
111*e7be843bSPierre Pronchery      * The QUIC_PORT which the channel is to belong to. The lifetime of the
112*e7be843bSPierre Pronchery      * QUIC_PORT must exceed that of the created channel.
113*e7be843bSPierre Pronchery      */
114*e7be843bSPierre Pronchery     QUIC_PORT       *port;
115*e7be843bSPierre Pronchery     /* LCIDM to register LCIDs with. */
116*e7be843bSPierre Pronchery     QUIC_LCIDM      *lcidm;
117*e7be843bSPierre Pronchery     /* SRTM to register SRTs with. */
118*e7be843bSPierre Pronchery     QUIC_SRTM       *srtm;
119*e7be843bSPierre Pronchery     OSSL_QRX        *qrx;
120*e7be843bSPierre Pronchery 
121*e7be843bSPierre Pronchery     int             is_server;
122*e7be843bSPierre Pronchery     SSL             *tls;
123*e7be843bSPierre Pronchery 
124*e7be843bSPierre Pronchery     /* Whether to use qlog. */
125*e7be843bSPierre Pronchery     int             use_qlog;
126*e7be843bSPierre Pronchery 
127*e7be843bSPierre Pronchery     int             is_tserver_ch;
128*e7be843bSPierre Pronchery 
129*e7be843bSPierre Pronchery     /* Title to use for the qlog session, or NULL. */
130*e7be843bSPierre Pronchery     const char      *qlog_title;
131*e7be843bSPierre Pronchery } QUIC_CHANNEL_ARGS;
132*e7be843bSPierre Pronchery 
133*e7be843bSPierre Pronchery /* Represents the cause for a connection's termination. */
134*e7be843bSPierre Pronchery typedef struct quic_terminate_cause_st {
135*e7be843bSPierre Pronchery     /*
136*e7be843bSPierre Pronchery      * If we are in a TERMINATING or TERMINATED state, this is the error code
137*e7be843bSPierre Pronchery      * associated with the error. This field is valid iff we are in the
138*e7be843bSPierre Pronchery      * TERMINATING or TERMINATED states.
139*e7be843bSPierre Pronchery      */
140*e7be843bSPierre Pronchery     uint64_t                        error_code;
141*e7be843bSPierre Pronchery 
142*e7be843bSPierre Pronchery     /*
143*e7be843bSPierre Pronchery      * If terminate_app is set and this is nonzero, this is the frame type which
144*e7be843bSPierre Pronchery      * caused the connection to be terminated.
145*e7be843bSPierre Pronchery      */
146*e7be843bSPierre Pronchery     uint64_t                        frame_type;
147*e7be843bSPierre Pronchery 
148*e7be843bSPierre Pronchery     /*
149*e7be843bSPierre Pronchery      * Optional reason string. When calling ossl_quic_channel_local_close, if a
150*e7be843bSPierre Pronchery      * reason string pointer is passed, it is copied and stored inside
151*e7be843bSPierre Pronchery      * QUIC_CHANNEL for the remainder of the lifetime of the channel object.
152*e7be843bSPierre Pronchery      * Thus the string pointed to by this value, if non-NULL, is valid for the
153*e7be843bSPierre Pronchery      * lifetime of the QUIC_CHANNEL object.
154*e7be843bSPierre Pronchery      */
155*e7be843bSPierre Pronchery     const char                      *reason;
156*e7be843bSPierre Pronchery 
157*e7be843bSPierre Pronchery     /*
158*e7be843bSPierre Pronchery      * Length of reason in bytes. The reason is supposed to contain a UTF-8
159*e7be843bSPierre Pronchery      * string but may be arbitrary data if the reason came from the network.
160*e7be843bSPierre Pronchery      */
161*e7be843bSPierre Pronchery     size_t                          reason_len;
162*e7be843bSPierre Pronchery 
163*e7be843bSPierre Pronchery     /* Is this error code in the transport (0) or application (1) space? */
164*e7be843bSPierre Pronchery     unsigned int                    app : 1;
165*e7be843bSPierre Pronchery 
166*e7be843bSPierre Pronchery     /*
167*e7be843bSPierre Pronchery      * If set, the cause of the termination is a received CONNECTION_CLOSE
168*e7be843bSPierre Pronchery      * frame. Otherwise, we decided to terminate ourselves and sent a
169*e7be843bSPierre Pronchery      * CONNECTION_CLOSE frame (regardless of whether the peer later also sends
170*e7be843bSPierre Pronchery      * one).
171*e7be843bSPierre Pronchery      */
172*e7be843bSPierre Pronchery     unsigned int                    remote : 1;
173*e7be843bSPierre Pronchery } QUIC_TERMINATE_CAUSE;
174*e7be843bSPierre Pronchery 
175*e7be843bSPierre Pronchery /*
176*e7be843bSPierre Pronchery  * Create a new QUIC channel using the given arguments. The argument structure
177*e7be843bSPierre Pronchery  * does not need to remain allocated. Returns NULL on failure.
178*e7be843bSPierre Pronchery  *
179*e7be843bSPierre Pronchery  * Only QUIC_PORT should use this function.
180*e7be843bSPierre Pronchery  */
181*e7be843bSPierre Pronchery QUIC_CHANNEL *ossl_quic_channel_alloc(const QUIC_CHANNEL_ARGS *args);
182*e7be843bSPierre Pronchery int ossl_quic_channel_init(QUIC_CHANNEL *ch);
183*e7be843bSPierre Pronchery void ossl_quic_channel_bind_qrx(QUIC_CHANNEL *tserver_ch, OSSL_QRX *qrx);
184*e7be843bSPierre Pronchery 
185*e7be843bSPierre Pronchery 
186*e7be843bSPierre Pronchery /* No-op if ch is NULL. */
187*e7be843bSPierre Pronchery void ossl_quic_channel_free(QUIC_CHANNEL *ch);
188*e7be843bSPierre Pronchery 
189*e7be843bSPierre Pronchery /* Set mutator callbacks for test framework support */
190*e7be843bSPierre Pronchery int ossl_quic_channel_set_mutator(QUIC_CHANNEL *ch,
191*e7be843bSPierre Pronchery                                   ossl_mutate_packet_cb mutatecb,
192*e7be843bSPierre Pronchery                                   ossl_finish_mutate_cb finishmutatecb,
193*e7be843bSPierre Pronchery                                   void *mutatearg);
194*e7be843bSPierre Pronchery 
195*e7be843bSPierre Pronchery /*
196*e7be843bSPierre Pronchery  * Connection Lifecycle Events
197*e7be843bSPierre Pronchery  * ===========================
198*e7be843bSPierre Pronchery  *
199*e7be843bSPierre Pronchery  * Various events that can be raised on the channel by other parts of the QUIC
200*e7be843bSPierre Pronchery  * implementation. Some of these are suitable for general use by any part of the
201*e7be843bSPierre Pronchery  * code (e.g. ossl_quic_channel_raise_protocol_error), others are for very
202*e7be843bSPierre Pronchery  * specific use by particular components only (e.g.
203*e7be843bSPierre Pronchery  * ossl_quic_channel_on_handshake_confirmed).
204*e7be843bSPierre Pronchery  */
205*e7be843bSPierre Pronchery 
206*e7be843bSPierre Pronchery /*
207*e7be843bSPierre Pronchery  * To be used by a QUIC connection. Starts the channel. For a client-mode
208*e7be843bSPierre Pronchery  * channel, this starts sending the first handshake layer message, etc. Can only
209*e7be843bSPierre Pronchery  * be called in the idle state; successive calls are ignored.
210*e7be843bSPierre Pronchery  */
211*e7be843bSPierre Pronchery int ossl_quic_channel_start(QUIC_CHANNEL *ch);
212*e7be843bSPierre Pronchery 
213*e7be843bSPierre Pronchery /* Start a locally initiated connection shutdown. */
214*e7be843bSPierre Pronchery void ossl_quic_channel_local_close(QUIC_CHANNEL *ch, uint64_t app_error_code,
215*e7be843bSPierre Pronchery                                    const char *app_reason);
216*e7be843bSPierre Pronchery 
217*e7be843bSPierre Pronchery /**
218*e7be843bSPierre Pronchery  * @brief schedules a NEW_TOKEN frame for sending on the channel
219*e7be843bSPierre Pronchery  */
220*e7be843bSPierre Pronchery int ossl_quic_channel_schedule_new_token(QUIC_CHANNEL *ch,
221*e7be843bSPierre Pronchery                                          const unsigned char *token,
222*e7be843bSPierre Pronchery                                          size_t token_len);
223*e7be843bSPierre Pronchery 
224*e7be843bSPierre Pronchery /*
225*e7be843bSPierre Pronchery  * Called when the handshake is confirmed.
226*e7be843bSPierre Pronchery  */
227*e7be843bSPierre Pronchery int ossl_quic_channel_on_handshake_confirmed(QUIC_CHANNEL *ch);
228*e7be843bSPierre Pronchery 
229*e7be843bSPierre Pronchery /*
230*e7be843bSPierre Pronchery  * Raises a protocol error. This is intended to be the universal call suitable
231*e7be843bSPierre Pronchery  * for handling of all peer-triggered protocol violations or errors detected by
232*e7be843bSPierre Pronchery  * us. We specify a QUIC transport-scope error code and optional frame type
233*e7be843bSPierre Pronchery  * which was responsible. If a frame type is not applicable, specify zero. The
234*e7be843bSPierre Pronchery  * reason string is not currently handled, but should be a string of static
235*e7be843bSPierre Pronchery  * storage duration. If the connection has already terminated due to a previous
236*e7be843bSPierre Pronchery  * protocol error, this is a no-op; first error wins.
237*e7be843bSPierre Pronchery  *
238*e7be843bSPierre Pronchery  * Usually the ossl_quic_channel_raise_protocol_error() function should be used.
239*e7be843bSPierre Pronchery  * The ossl_quic_channel_raise_protocol_error_loc() function can be used
240*e7be843bSPierre Pronchery  * directly for passing through existing call site information from an existing
241*e7be843bSPierre Pronchery  * error.
242*e7be843bSPierre Pronchery  */
243*e7be843bSPierre Pronchery void ossl_quic_channel_raise_protocol_error_loc(QUIC_CHANNEL *ch,
244*e7be843bSPierre Pronchery                                                 uint64_t error_code,
245*e7be843bSPierre Pronchery                                                 uint64_t frame_type,
246*e7be843bSPierre Pronchery                                                 const char *reason,
247*e7be843bSPierre Pronchery                                                 ERR_STATE *err_state,
248*e7be843bSPierre Pronchery                                                 const char *src_file,
249*e7be843bSPierre Pronchery                                                 int src_line,
250*e7be843bSPierre Pronchery                                                 const char *src_func);
251*e7be843bSPierre Pronchery 
252*e7be843bSPierre Pronchery #define ossl_quic_channel_raise_protocol_error(ch, error_code, frame_type, reason) \
253*e7be843bSPierre Pronchery     ossl_quic_channel_raise_protocol_error_loc((ch), (error_code),  \
254*e7be843bSPierre Pronchery                                                (frame_type),        \
255*e7be843bSPierre Pronchery                                                (reason),            \
256*e7be843bSPierre Pronchery                                                NULL,                \
257*e7be843bSPierre Pronchery                                                OPENSSL_FILE,        \
258*e7be843bSPierre Pronchery                                                OPENSSL_LINE,        \
259*e7be843bSPierre Pronchery                                                OPENSSL_FUNC)
260*e7be843bSPierre Pronchery 
261*e7be843bSPierre Pronchery #define ossl_quic_channel_raise_protocol_error_state(ch, error_code, frame_type, reason, state) \
262*e7be843bSPierre Pronchery     ossl_quic_channel_raise_protocol_error_loc((ch), (error_code),  \
263*e7be843bSPierre Pronchery                                                (frame_type),        \
264*e7be843bSPierre Pronchery                                                (reason),            \
265*e7be843bSPierre Pronchery                                                (state),             \
266*e7be843bSPierre Pronchery                                                OPENSSL_FILE,        \
267*e7be843bSPierre Pronchery                                                OPENSSL_LINE,        \
268*e7be843bSPierre Pronchery                                                OPENSSL_FUNC)
269*e7be843bSPierre Pronchery 
270*e7be843bSPierre Pronchery 
271*e7be843bSPierre Pronchery /*
272*e7be843bSPierre Pronchery  * Returns 1 if permanent net error was detected on the QUIC_CHANNEL,
273*e7be843bSPierre Pronchery  * 0 otherwise.
274*e7be843bSPierre Pronchery  */
275*e7be843bSPierre Pronchery int ossl_quic_channel_net_error(QUIC_CHANNEL *ch);
276*e7be843bSPierre Pronchery 
277*e7be843bSPierre Pronchery /* Restore saved error state (best effort) */
278*e7be843bSPierre Pronchery void ossl_quic_channel_restore_err_state(QUIC_CHANNEL *ch);
279*e7be843bSPierre Pronchery 
280*e7be843bSPierre Pronchery /* For RXDP use. */
281*e7be843bSPierre Pronchery void ossl_quic_channel_on_remote_conn_close(QUIC_CHANNEL *ch,
282*e7be843bSPierre Pronchery                                             OSSL_QUIC_FRAME_CONN_CLOSE *f);
283*e7be843bSPierre Pronchery void ossl_quic_channel_on_new_conn_id(QUIC_CHANNEL *ch,
284*e7be843bSPierre Pronchery                                       OSSL_QUIC_FRAME_NEW_CONN_ID *f);
285*e7be843bSPierre Pronchery 
286*e7be843bSPierre Pronchery /* Temporarily exposed during QUIC_PORT transition. */
287*e7be843bSPierre Pronchery int ossl_quic_channel_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer,
288*e7be843bSPierre Pronchery                                   const QUIC_CONN_ID *peer_scid,
289*e7be843bSPierre Pronchery                                   const QUIC_CONN_ID *peer_dcid);
290*e7be843bSPierre Pronchery 
291*e7be843bSPierre Pronchery /* For use by QUIC_PORT. You should not need to call this directly. */
292*e7be843bSPierre Pronchery void ossl_quic_channel_subtick(QUIC_CHANNEL *ch, QUIC_TICK_RESULT *r,
293*e7be843bSPierre Pronchery                                uint32_t flags);
294*e7be843bSPierre Pronchery 
295*e7be843bSPierre Pronchery /* For use by QUIC_PORT only. */
296*e7be843bSPierre Pronchery void ossl_quic_channel_raise_net_error(QUIC_CHANNEL *ch);
297*e7be843bSPierre Pronchery 
298*e7be843bSPierre Pronchery /* For use by QUIC_PORT only. */
299*e7be843bSPierre Pronchery void ossl_quic_channel_on_stateless_reset(QUIC_CHANNEL *ch);
300*e7be843bSPierre Pronchery 
301*e7be843bSPierre Pronchery void ossl_quic_channel_inject(QUIC_CHANNEL *ch, QUIC_URXE *e);
302*e7be843bSPierre Pronchery 
303*e7be843bSPierre Pronchery void ossl_quic_channel_inject_pkt(QUIC_CHANNEL *ch, OSSL_QRX_PKT *qpkt);
304*e7be843bSPierre Pronchery 
305*e7be843bSPierre Pronchery /*
306*e7be843bSPierre Pronchery  * Queries and Accessors
307*e7be843bSPierre Pronchery  * =====================
308*e7be843bSPierre Pronchery  */
309*e7be843bSPierre Pronchery 
310*e7be843bSPierre Pronchery /* Gets the reactor which can be used to tick/poll on the channel. */
311*e7be843bSPierre Pronchery QUIC_REACTOR *ossl_quic_channel_get_reactor(QUIC_CHANNEL *ch);
312*e7be843bSPierre Pronchery 
313*e7be843bSPierre Pronchery /* Gets the QSM used with the channel. */
314*e7be843bSPierre Pronchery QUIC_STREAM_MAP *ossl_quic_channel_get_qsm(QUIC_CHANNEL *ch);
315*e7be843bSPierre Pronchery 
316*e7be843bSPierre Pronchery /* Gets the statistics manager used with the channel. */
317*e7be843bSPierre Pronchery OSSL_STATM *ossl_quic_channel_get_statm(QUIC_CHANNEL *ch);
318*e7be843bSPierre Pronchery 
319*e7be843bSPierre Pronchery /* Gets the TLS handshake layer used with the channel. */
320*e7be843bSPierre Pronchery SSL *ossl_quic_channel_get0_tls(QUIC_CHANNEL *ch);
321*e7be843bSPierre Pronchery 
322*e7be843bSPierre Pronchery /* Gets the channels short header connection id length */
323*e7be843bSPierre Pronchery size_t ossl_quic_channel_get_short_header_conn_id_len(QUIC_CHANNEL *ch);
324*e7be843bSPierre Pronchery 
325*e7be843bSPierre Pronchery /*
326*e7be843bSPierre Pronchery  * Gets/sets the current peer address. Generally this should be used before
327*e7be843bSPierre Pronchery  * starting a channel in client mode.
328*e7be843bSPierre Pronchery  */
329*e7be843bSPierre Pronchery int ossl_quic_channel_get_peer_addr(QUIC_CHANNEL *ch, BIO_ADDR *peer_addr);
330*e7be843bSPierre Pronchery int ossl_quic_channel_set_peer_addr(QUIC_CHANNEL *ch, const BIO_ADDR *peer_addr);
331*e7be843bSPierre Pronchery 
332*e7be843bSPierre Pronchery /*
333*e7be843bSPierre Pronchery  * Returns an existing stream by stream ID. Returns NULL if the stream does not
334*e7be843bSPierre Pronchery  * exist.
335*e7be843bSPierre Pronchery  */
336*e7be843bSPierre Pronchery QUIC_STREAM *ossl_quic_channel_get_stream_by_id(QUIC_CHANNEL *ch,
337*e7be843bSPierre Pronchery                                                 uint64_t stream_id);
338*e7be843bSPierre Pronchery 
339*e7be843bSPierre Pronchery /* Returns 1 if channel is terminating or terminated. */
340*e7be843bSPierre Pronchery int ossl_quic_channel_is_term_any(const QUIC_CHANNEL *ch);
341*e7be843bSPierre Pronchery const QUIC_TERMINATE_CAUSE *
342*e7be843bSPierre Pronchery ossl_quic_channel_get_terminate_cause(const QUIC_CHANNEL *ch);
343*e7be843bSPierre Pronchery int ossl_quic_channel_is_closing(const QUIC_CHANNEL *ch);
344*e7be843bSPierre Pronchery int ossl_quic_channel_is_terminated(const QUIC_CHANNEL *ch);
345*e7be843bSPierre Pronchery int ossl_quic_channel_is_active(const QUIC_CHANNEL *ch);
346*e7be843bSPierre Pronchery int ossl_quic_channel_is_handshake_complete(const QUIC_CHANNEL *ch);
347*e7be843bSPierre Pronchery int ossl_quic_channel_is_handshake_confirmed(const QUIC_CHANNEL *ch);
348*e7be843bSPierre Pronchery 
349*e7be843bSPierre Pronchery QUIC_PORT *ossl_quic_channel_get0_port(QUIC_CHANNEL *ch);
350*e7be843bSPierre Pronchery QUIC_ENGINE *ossl_quic_channel_get0_engine(QUIC_CHANNEL *ch);
351*e7be843bSPierre Pronchery QUIC_DEMUX *ossl_quic_channel_get0_demux(QUIC_CHANNEL *ch);
352*e7be843bSPierre Pronchery 
353*e7be843bSPierre Pronchery SSL *ossl_quic_channel_get0_ssl(QUIC_CHANNEL *ch);
354*e7be843bSPierre Pronchery 
355*e7be843bSPierre Pronchery /*
356*e7be843bSPierre Pronchery  * Retrieves a pointer to the channel mutex which was provided at the time the
357*e7be843bSPierre Pronchery  * channel was instantiated. In order to allow locks to be acquired and released
358*e7be843bSPierre Pronchery  * with the correct granularity, it is the caller's responsibility to ensure
359*e7be843bSPierre Pronchery  * this lock is held for write while calling any QUIC_CHANNEL method, except for
360*e7be843bSPierre Pronchery  * methods explicitly designed otherwise.
361*e7be843bSPierre Pronchery  *
362*e7be843bSPierre Pronchery  * This method is thread safe and does not require prior locking. It can also be
363*e7be843bSPierre Pronchery  * called while the lock is already held. Note that this is simply a convenience
364*e7be843bSPierre Pronchery  * function to access the mutex which was passed to the channel at instantiation
365*e7be843bSPierre Pronchery  * time; it does not belong to the channel but rather is presumed to belong to
366*e7be843bSPierre Pronchery  * the owner of the channel.
367*e7be843bSPierre Pronchery  */
368*e7be843bSPierre Pronchery CRYPTO_MUTEX *ossl_quic_channel_get_mutex(QUIC_CHANNEL *ch);
369*e7be843bSPierre Pronchery 
370*e7be843bSPierre Pronchery /*
371*e7be843bSPierre Pronchery  * Creates a new locally-initiated stream in the stream mapper, choosing an
372*e7be843bSPierre Pronchery  * appropriate stream ID. If is_uni is 1, creates a unidirectional stream, else
373*e7be843bSPierre Pronchery  * creates a bidirectional stream. Returns NULL on failure.
374*e7be843bSPierre Pronchery  */
375*e7be843bSPierre Pronchery QUIC_STREAM *ossl_quic_channel_new_stream_local(QUIC_CHANNEL *ch, int is_uni);
376*e7be843bSPierre Pronchery 
377*e7be843bSPierre Pronchery /*
378*e7be843bSPierre Pronchery  * Creates a new remotely-initiated stream in the stream mapper. The stream ID
379*e7be843bSPierre Pronchery  * is used to confirm the initiator and determine the stream type. The stream is
380*e7be843bSPierre Pronchery  * automatically added to the QSM's accept queue. A pointer to the stream is
381*e7be843bSPierre Pronchery  * also returned. Returns NULL on failure.
382*e7be843bSPierre Pronchery  */
383*e7be843bSPierre Pronchery QUIC_STREAM *ossl_quic_channel_new_stream_remote(QUIC_CHANNEL *ch,
384*e7be843bSPierre Pronchery                                                  uint64_t stream_id);
385*e7be843bSPierre Pronchery 
386*e7be843bSPierre Pronchery /*
387*e7be843bSPierre Pronchery  * Configures incoming stream auto-reject. If enabled, incoming streams have
388*e7be843bSPierre Pronchery  * both their sending and receiving parts automatically rejected using
389*e7be843bSPierre Pronchery  * STOP_SENDING and STREAM_RESET frames. aec is the application error
390*e7be843bSPierre Pronchery  * code to be used for those frames.
391*e7be843bSPierre Pronchery  */
392*e7be843bSPierre Pronchery void ossl_quic_channel_set_incoming_stream_auto_reject(QUIC_CHANNEL *ch,
393*e7be843bSPierre Pronchery                                                        int enable,
394*e7be843bSPierre Pronchery                                                        uint64_t aec);
395*e7be843bSPierre Pronchery 
396*e7be843bSPierre Pronchery /*
397*e7be843bSPierre Pronchery  * Causes the channel to reject the sending and receiving parts of a stream,
398*e7be843bSPierre Pronchery  * as though autorejected. Can be used if a stream has already been
399*e7be843bSPierre Pronchery  * accepted.
400*e7be843bSPierre Pronchery  */
401*e7be843bSPierre Pronchery void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs);
402*e7be843bSPierre Pronchery 
403*e7be843bSPierre Pronchery /* Replace local connection ID in TXP and DEMUX for testing purposes. */
404*e7be843bSPierre Pronchery int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch,
405*e7be843bSPierre Pronchery                                         const QUIC_CONN_ID *conn_id);
406*e7be843bSPierre Pronchery 
407*e7be843bSPierre Pronchery /* Setters for the msg_callback and msg_callback_arg */
408*e7be843bSPierre Pronchery void ossl_quic_channel_set_msg_callback(QUIC_CHANNEL *ch,
409*e7be843bSPierre Pronchery                                         ossl_msg_cb msg_callback,
410*e7be843bSPierre Pronchery                                         SSL *msg_callback_ssl);
411*e7be843bSPierre Pronchery void ossl_quic_channel_set_msg_callback_arg(QUIC_CHANNEL *ch,
412*e7be843bSPierre Pronchery                                             void *msg_callback_arg);
413*e7be843bSPierre Pronchery 
414*e7be843bSPierre Pronchery /* Testing use only - sets a TXKU threshold packet count override value. */
415*e7be843bSPierre Pronchery void ossl_quic_channel_set_txku_threshold_override(QUIC_CHANNEL *ch,
416*e7be843bSPierre Pronchery                                                    uint64_t tx_pkt_threshold);
417*e7be843bSPierre Pronchery 
418*e7be843bSPierre Pronchery /* Testing use only - gets current 1-RTT key epochs for QTX and QRX. */
419*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_tx_key_epoch(QUIC_CHANNEL *ch);
420*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_rx_key_epoch(QUIC_CHANNEL *ch);
421*e7be843bSPierre Pronchery 
422*e7be843bSPierre Pronchery /* Artificially trigger a spontaneous TXKU if possible. */
423*e7be843bSPierre Pronchery int ossl_quic_channel_trigger_txku(QUIC_CHANNEL *ch);
424*e7be843bSPierre Pronchery int ossl_quic_channel_has_pending(const QUIC_CHANNEL *ch);
425*e7be843bSPierre Pronchery 
426*e7be843bSPierre Pronchery /* Force transmission of an ACK-eliciting packet. */
427*e7be843bSPierre Pronchery int ossl_quic_channel_ping(QUIC_CHANNEL *ch);
428*e7be843bSPierre Pronchery 
429*e7be843bSPierre Pronchery /*
430*e7be843bSPierre Pronchery  * These queries exist for diagnostic purposes only. They may roll over.
431*e7be843bSPierre Pronchery  * Do not rely on them for non-testing purposes.
432*e7be843bSPierre Pronchery  */
433*e7be843bSPierre Pronchery uint16_t ossl_quic_channel_get_diag_num_rx_ack(QUIC_CHANNEL *ch);
434*e7be843bSPierre Pronchery 
435*e7be843bSPierre Pronchery /*
436*e7be843bSPierre Pronchery  * Diagnostic use only. Gets the current local CID.
437*e7be843bSPierre Pronchery  */
438*e7be843bSPierre Pronchery void ossl_quic_channel_get_diag_local_cid(QUIC_CHANNEL *ch, QUIC_CONN_ID *cid);
439*e7be843bSPierre Pronchery 
440*e7be843bSPierre Pronchery /*
441*e7be843bSPierre Pronchery  * Returns 1 if stream count flow control allows us to create a new
442*e7be843bSPierre Pronchery  * locally-initiated stream.
443*e7be843bSPierre Pronchery  */
444*e7be843bSPierre Pronchery int ossl_quic_channel_is_new_local_stream_admissible(QUIC_CHANNEL *ch, int is_uni);
445*e7be843bSPierre Pronchery 
446*e7be843bSPierre Pronchery /*
447*e7be843bSPierre Pronchery  * Returns the number of additional streams that can currently be created based
448*e7be843bSPierre Pronchery  * on flow control.
449*e7be843bSPierre Pronchery  */
450*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_local_stream_count_avail(const QUIC_CHANNEL *ch,
451*e7be843bSPierre Pronchery                                                         int is_uni);
452*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_remote_stream_count_avail(const QUIC_CHANNEL *ch,
453*e7be843bSPierre Pronchery                                                          int is_uni);
454*e7be843bSPierre Pronchery 
455*e7be843bSPierre Pronchery /*
456*e7be843bSPierre Pronchery  * Returns 1 if we have generated our local transport parameters yet.
457*e7be843bSPierre Pronchery  */
458*e7be843bSPierre Pronchery int ossl_quic_channel_have_generated_transport_params(const QUIC_CHANNEL *ch);
459*e7be843bSPierre Pronchery 
460*e7be843bSPierre Pronchery /* Configures the idle timeout to request from peer (milliseconds, 0=no timeout). */
461*e7be843bSPierre Pronchery void ossl_quic_channel_set_max_idle_timeout_request(QUIC_CHANNEL *ch, uint64_t ms);
462*e7be843bSPierre Pronchery /* Get the configured idle timeout to request from peer. */
463*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_max_idle_timeout_request(const QUIC_CHANNEL *ch);
464*e7be843bSPierre Pronchery /* Get the idle timeout requested by the peer. */
465*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_max_idle_timeout_peer_request(const QUIC_CHANNEL *ch);
466*e7be843bSPierre Pronchery /* Get the idle timeout actually negotiated. */
467*e7be843bSPierre Pronchery uint64_t ossl_quic_channel_get_max_idle_timeout_actual(const QUIC_CHANNEL *ch);
468*e7be843bSPierre Pronchery 
469*e7be843bSPierre Pronchery int ossl_quic_bind_channel(QUIC_CHANNEL *ch, const BIO_ADDR *peer,
470*e7be843bSPierre Pronchery                            const QUIC_CONN_ID *scid, const QUIC_CONN_ID *dcid,
471*e7be843bSPierre Pronchery                            const QUIC_CONN_ID *odcid);
472*e7be843bSPierre Pronchery 
473*e7be843bSPierre Pronchery # endif
474*e7be843bSPierre Pronchery 
475*e7be843bSPierre Pronchery #endif
476