1 1.1 christos /* 2 1.1 christos * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos #ifndef OSSL_QUIC_PORT_H 10 1.1.1.2 christos #define OSSL_QUIC_PORT_H 11 1.1 christos 12 1.1.1.2 christos #include <openssl/ssl.h> 13 1.1.1.2 christos #include "internal/quic_types.h" 14 1.1.1.2 christos #include "internal/quic_reactor.h" 15 1.1.1.2 christos #include "internal/quic_demux.h" 16 1.1.1.2 christos #include "internal/quic_predef.h" 17 1.1.1.2 christos #include "internal/thread_arch.h" 18 1.1 christos 19 1.1.1.2 christos #ifndef OPENSSL_NO_QUIC 20 1.1 christos 21 1.1 christos /* 22 1.1 christos * QUIC Port 23 1.1 christos * ========= 24 1.1 christos * 25 1.1 christos * A QUIC Port (QUIC_PORT) represents a single UDP network socket and contains 26 1.1 christos * zero or more subsidiary QUIC_CHANNEL instances, each of which represents a 27 1.1 christos * single QUIC connection. All QUIC_CHANNEL instances must belong to a 28 1.1 christos * QUIC_PORT. 29 1.1 christos * 30 1.1 christos * A QUIC port is responsible for managing a set of channels which all use the 31 1.1 christos * same UDP socket, and (in future) for automatically creating new channels when 32 1.1 christos * incoming connections are received. 33 1.1 christos * 34 1.1 christos * In order to retain compatibility with QUIC_TSERVER, it also supports a point 35 1.1 christos * of legacy compatibility where a caller can create an incoming (server role) 36 1.1 christos * channel and that channel will be automatically be bound to the next incoming 37 1.1 christos * connection. In the future this will go away once QUIC_TSERVER is removed. 38 1.1 christos * 39 1.1 christos * All QUIC_PORT instances are created by a QUIC_ENGINE. 40 1.1 christos */ 41 1.1 christos typedef struct quic_port_args_st { 42 1.1 christos /* The engine which the QUIC port is to be a child of. */ 43 1.1.1.2 christos QUIC_ENGINE *engine; 44 1.1 christos 45 1.1 christos /* 46 1.1 christos * This callback allows port_new_handshake_layer to pre-create a quic 47 1.1 christos * connection object for the incoming channel 48 1.1 christos * user_ssl_arg is expected to point to a quic listener object 49 1.1 christos */ 50 1.1 christos SSL *(*get_conn_user_ssl)(QUIC_CHANNEL *ch, void *arg); 51 1.1 christos void *user_ssl_arg; 52 1.1 christos 53 1.1 christos /* 54 1.1 christos * This SSL_CTX will be used when constructing the handshake layer object 55 1.1 christos * inside newly created channels. 56 1.1 christos */ 57 1.1.1.2 christos SSL_CTX *channel_ctx; 58 1.1 christos 59 1.1 christos /* 60 1.1 christos * If 1, this port is to be used for multiple connections, so 61 1.1 christos * non-zero-length CIDs should be used. If 0, this port will only be used 62 1.1 christos * for a single connection, so a zero-length local CID can be used. 63 1.1 christos */ 64 1.1.1.2 christos int is_multi_conn; 65 1.1 christos 66 1.1 christos /* 67 1.1 christos * if 1, this port should do server address validation 68 1.1 christos */ 69 1.1.1.2 christos int do_addr_validation; 70 1.1 christos } QUIC_PORT_ARGS; 71 1.1 christos 72 1.1 christos /* Only QUIC_ENGINE should use this function. */ 73 1.1 christos QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args); 74 1.1 christos 75 1.1 christos void ossl_quic_port_free(QUIC_PORT *port); 76 1.1 christos 77 1.1 christos /* 78 1.1 christos * Operations 79 1.1 christos * ========== 80 1.1 christos */ 81 1.1 christos 82 1.1 christos /* Create an outgoing channel using this port. */ 83 1.1 christos QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls); 84 1.1 christos 85 1.1 christos /* 86 1.1 christos * Create an incoming channel using this port. 87 1.1 christos * 88 1.1 christos * TODO(QUIC FUTURE): temporary TSERVER use only - will be removed. 89 1.1 christos */ 90 1.1 christos QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls); 91 1.1 christos 92 1.1 christos /* 93 1.1 christos * Pop an incoming channel from the incoming channel queue. Returns NULL if 94 1.1 christos * there are no pending incoming channels. 95 1.1 christos */ 96 1.1 christos QUIC_CHANNEL *ossl_quic_port_pop_incoming(QUIC_PORT *port); 97 1.1 christos 98 1.1 christos /* Returns 1 if there is at least one connection incoming. */ 99 1.1 christos int ossl_quic_port_have_incoming(QUIC_PORT *port); 100 1.1 christos 101 1.1 christos /* 102 1.1 christos * Delete any channels which are pending acceptance. 103 1.1 christos */ 104 1.1 christos void ossl_quic_port_drop_incoming(QUIC_PORT *port); 105 1.1 christos 106 1.1 christos /* 107 1.1 christos * Queries and Accessors 108 1.1 christos * ===================== 109 1.1 christos */ 110 1.1 christos 111 1.1 christos /* Gets/sets the underlying network read and write BIO. */ 112 1.1 christos BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port); 113 1.1 christos BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port); 114 1.1 christos int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio); 115 1.1 christos int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio); 116 1.1 christos SSL_CTX *ossl_quic_port_get_channel_ctx(QUIC_PORT *port); 117 1.1 christos 118 1.1 christos /* 119 1.1 christos * Re-poll the network BIOs already set to determine if their support for 120 1.1 christos * polling has changed. If force is 0, only check again if the BIOs have been 121 1.1 christos * changed. 122 1.1 christos */ 123 1.1 christos int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port, int force); 124 1.1 christos 125 1.1 christos /* Gets the engine which this port is a child of. */ 126 1.1 christos QUIC_ENGINE *ossl_quic_port_get0_engine(QUIC_PORT *port); 127 1.1 christos 128 1.1 christos /* Gets the reactor which can be used to tick/poll on the port. */ 129 1.1 christos QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port); 130 1.1 christos 131 1.1 christos /* Gets the demuxer belonging to the port. */ 132 1.1 christos QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port); 133 1.1 christos 134 1.1 christos /* Gets the mutex used by the port. */ 135 1.1 christos CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port); 136 1.1 christos 137 1.1 christos /* Gets the current time. */ 138 1.1 christos OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port); 139 1.1 christos 140 1.1 christos int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port); 141 1.1 christos int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port); 142 1.1 christos 143 1.1 christos /* Returns 1 if the port is running/healthy, 0 if it has failed. */ 144 1.1 christos int ossl_quic_port_is_running(const QUIC_PORT *port); 145 1.1 christos 146 1.1 christos /* 147 1.1 christos * Restores port-level error to the error stack. To be called only if 148 1.1 christos * the port is no longer running. 149 1.1 christos */ 150 1.1 christos void ossl_quic_port_restore_err_state(const QUIC_PORT *port); 151 1.1 christos 152 1.1 christos /* For use by QUIC_ENGINE. You should not need to call this directly. */ 153 1.1 christos void ossl_quic_port_subtick(QUIC_PORT *port, QUIC_TICK_RESULT *r, 154 1.1.1.2 christos uint32_t flags); 155 1.1 christos 156 1.1 christos /* Returns the number of queued incoming channels. */ 157 1.1 christos size_t ossl_quic_port_get_num_incoming_channels(const QUIC_PORT *port); 158 1.1 christos 159 1.1 christos /* Sets if incoming connections should currently be allowed. */ 160 1.1 christos void ossl_quic_port_set_allow_incoming(QUIC_PORT *port, int allow_incoming); 161 1.1 christos 162 1.1 christos /* Returns 1 if we are using addressed mode on the read side. */ 163 1.1 christos int ossl_quic_port_is_addressed_r(const QUIC_PORT *port); 164 1.1 christos 165 1.1 christos /* Returns 1 if we are using addressed mode on the write side. */ 166 1.1 christos int ossl_quic_port_is_addressed_w(const QUIC_PORT *port); 167 1.1 christos 168 1.1 christos /* Returns 1 if we are using addressed mode. */ 169 1.1 christos int ossl_quic_port_is_addressed(const QUIC_PORT *port); 170 1.1 christos 171 1.1 christos /* 172 1.1 christos * Returns the current network BIO epoch. This increments whenever the network 173 1.1 christos * BIO configuration changes. 174 1.1 christos */ 175 1.1 christos uint64_t ossl_quic_port_get_net_bio_epoch(const QUIC_PORT *port); 176 1.1 christos 177 1.1 christos /* 178 1.1 christos * Events 179 1.1 christos * ====== 180 1.1 christos */ 181 1.1 christos 182 1.1 christos /* 183 1.1 christos * Called if a permanent network error occurs. Terminates all channels 184 1.1 christos * immediately. triggering_ch is an optional argument designating 185 1.1 christos * a channel which encountered the network error. 186 1.1 christos */ 187 1.1 christos void ossl_quic_port_raise_net_error(QUIC_PORT *port, 188 1.1.1.2 christos QUIC_CHANNEL *triggering_ch); 189 1.1 christos 190 1.1.1.2 christos #endif 191 1.1 christos 192 1.1 christos #endif 193