2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
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
9 #ifndef OSSL_QUIC_PORT_H
10 # define OSSL_QUIC_PORT_H
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"
19 # ifndef OPENSSL_NO_QUIC
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
30 * A QUIC port is responsible for managing a set of channels which all use the
31 * same UDP socket, and (in future) for automatically creating new channels when
32 * incoming connections are received.
34 * In order to retain compatibility with QUIC_TSERVER, it also supports a point
35 * of legacy compatibility where a caller can create an incoming (server role)
36 * channel and that channel will be automatically be bound to the next incoming
37 * connection. In the future this will go away once QUIC_TSERVER is removed.
39 typedef struct quic_port_args_st {
40 /* All channels in a QUIC event domain share the same (libctx, propq). */
45 * This must be a mutex the lifetime of which will exceed that of the port
46 * and all channels. The instantiator of the port is responsible for
47 * providing a mutex as this makes it easier to handle instantiation and
48 * teardown of channels in situations potentially requiring locking.
50 * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for
51 * compatibility with an OS's condition variable wait API, whereas RWLOCK
52 * may, depending on the build configuration, be implemented using an OS's
53 * mutex primitive or using its RW mutex primitive.
58 * Optional function pointer to use to retrieve the current time. If NULL,
59 * ossl_time_now() is used.
61 OSSL_TIME (*now_cb)(void *arg);
65 * This SSL_CTX will be used when constructing the handshake layer object
66 * inside newly created channels.
71 * If 1, this port is to be used for multiple connections, so
72 * non-zero-length CIDs should be used. If 0, this port will only be used
73 * for a single connection, so a zero-length local CID can be used.
78 typedef struct quic_port_st QUIC_PORT;
80 QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args);
82 void ossl_quic_port_free(QUIC_PORT *port);
89 /* Create an outgoing channel using this port. */
90 QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls);
93 * Create an incoming channel using this port. XXX for temporary TSERVER use
94 * only - will be removed.
96 QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls);
99 * Queries and Accessors
100 * =====================
103 /* Gets/sets the underlying network read and write BIO. */
104 BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port);
105 BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port);
106 int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio);
107 int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio);
110 * Re-poll the network BIOs already set to determine if their support
111 * for polling has changed.
113 int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port);
115 /* Gets the reactor which can be used to tick/poll on the port. */
116 QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port);
118 /* Gets the demuxer belonging to the port. */
119 QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port);
121 /* Gets the mutex used by the port. */
122 CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port);
124 /* Gets the current time. */
125 OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port);
127 int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port);
128 int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port);
130 /* For testing use. While enabled, ticking is not performed. */
131 void ossl_quic_port_set_inhibit_tick(QUIC_PORT *port, int inhibit);
139 * Called if a permanent network error occurs. Terminates all channels
142 void ossl_quic_port_raise_net_error(QUIC_PORT *port);