QUIC PORT, CHANNEL: Move DEMUX and default packet handling out of CHANNEL
[openssl.git] / include / internal / quic_port.h
1 /*
2  * Copyright 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_PORT_H
10 # define OSSL_QUIC_PORT_H
11
12 # include <openssl/ssl.h>
13 # include "internal/quic_types.h"
14 # include "internal/quic_reactor.h"
15 # include "internal/quic_demux.h"
16 # include "internal/quic_predef.h"
17 # include "internal/thread_arch.h"
18
19 # ifndef OPENSSL_NO_QUIC
20
21 /*
22  * QUIC Port
23  * =========
24  *
25  * A QUIC Port (QUIC_PORT) represents a single UDP network socket and contains
26  * zero or more subsidiary QUIC_CHANNEL instances, each of which represents a
27  * single QUIC connection. All QUIC_CHANNEL instances must belong to a
28  * QUIC_PORT.
29  */
30 typedef struct quic_port_args_st {
31     /* All channels in a QUIC event domain share the same (libctx, propq). */
32     OSSL_LIB_CTX    *libctx;
33     const char      *propq;
34
35     /*
36      * This must be a mutex the lifetime of which will exceed that of the port
37      * and all channels. The instantiator of the port is responsible for
38      * providing a mutex as this makes it easier to handle instantiation and
39      * teardown of channels in situations potentially requiring locking.
40      *
41      * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for
42      * compatibility with an OS's condition variable wait API, whereas RWLOCK
43      * may, depending on the build configuration, be implemented using an OS's
44      * mutex primitive or using its RW mutex primitive.
45      */
46     CRYPTO_MUTEX    *mutex;
47
48     /*
49      * Optional function pointer to use to retrieve the current time. If NULL,
50      * ossl_time_now() is used.
51      */
52     OSSL_TIME       (*now_cb)(void *arg);
53     void            *now_cb_arg;
54
55     /*
56      * This SSL_CTX will be used when constructing the handshake layer object
57      * inside newly created channels.
58      */
59     SSL_CTX         *channel_ctx;
60
61     /*
62      * If 1, this port is to be used for multiple connections, so
63      * non-zero-length CIDs should be used. If 0, this port will only be used
64      * for a single connection, so a zero-length local CID can be used.
65      */
66     int             is_multi_conn;
67 } QUIC_PORT_ARGS;
68
69 typedef struct quic_port_st QUIC_PORT;
70
71 QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args);
72
73 void ossl_quic_port_free(QUIC_PORT *port);
74
75 /*
76  * Operations
77  * ==========
78  */
79
80 /* Create an outgoing channel using this port. */
81 QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls);
82
83 /*
84  * Create an incoming channel using this port. XXX for temporary TSERVER use
85  * only - will be removed.
86  */
87 QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls);
88
89 /*
90  * Queries and Accessors
91  * =====================
92  */
93
94 /* Gets/sets the underlying network read and write BIO. */
95 BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port);
96 BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port);
97 int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio);
98 int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio);
99
100 int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port);
101
102 /* Gets the reactor which can be used to tick/poll on the port. */
103 QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port);
104
105 /* Gets the demuxer belonging to the port. */
106 QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port);
107
108 /* Gets the mutex used by the port. */
109 CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port);
110
111 /* Gets the current time. */
112 OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port);
113
114 int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port);
115 int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port);
116
117 # endif
118
119 #endif