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 * 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. 33 * 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. 38 * 39 * All QUIC_PORT instances are created by a QUIC_ENGINE. 40 */ 41 typedef struct quic_port_args_st { 42 /* The engine which the QUIC port is to be a child of. */ 43 QUIC_ENGINE *engine; 44 45 /* 46 * This SSL_CTX will be used when constructing the handshake layer object 47 * inside newly created channels. 48 */ 49 SSL_CTX *channel_ctx; 50 51 /* 52 * If 1, this port is to be used for multiple connections, so 53 * non-zero-length CIDs should be used. If 0, this port will only be used 54 * for a single connection, so a zero-length local CID can be used. 55 */ 56 int is_multi_conn; 57 } QUIC_PORT_ARGS; 58 59 /* Only QUIC_ENGINE should use this function. */ 60 QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args); 61 62 void ossl_quic_port_free(QUIC_PORT *port); 63 64 /* 65 * Operations 66 * ========== 67 */ 68 69 /* Create an outgoing channel using this port. */ 70 QUIC_CHANNEL *ossl_quic_port_create_outgoing(QUIC_PORT *port, SSL *tls); 71 72 /* 73 * Create an incoming channel using this port. 74 * 75 * TODO(QUIC SERVER): temporary TSERVER use only - will be removed. 76 */ 77 QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls); 78 79 /* 80 * Queries and Accessors 81 * ===================== 82 */ 83 84 /* Gets/sets the underlying network read and write BIO. */ 85 BIO *ossl_quic_port_get_net_rbio(QUIC_PORT *port); 86 BIO *ossl_quic_port_get_net_wbio(QUIC_PORT *port); 87 int ossl_quic_port_set_net_rbio(QUIC_PORT *port, BIO *net_rbio); 88 int ossl_quic_port_set_net_wbio(QUIC_PORT *port, BIO *net_wbio); 89 90 /* 91 * Re-poll the network BIOs already set to determine if their support 92 * for polling has changed. 93 */ 94 int ossl_quic_port_update_poll_descriptors(QUIC_PORT *port); 95 96 /* Gets the engine which this port is a child of. */ 97 QUIC_ENGINE *ossl_quic_port_get0_engine(QUIC_PORT *port); 98 99 /* Gets the reactor which can be used to tick/poll on the port. */ 100 QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port); 101 102 /* Gets the demuxer belonging to the port. */ 103 QUIC_DEMUX *ossl_quic_port_get0_demux(QUIC_PORT *port); 104 105 /* Gets the mutex used by the port. */ 106 CRYPTO_MUTEX *ossl_quic_port_get0_mutex(QUIC_PORT *port); 107 108 /* Gets the current time. */ 109 OSSL_TIME ossl_quic_port_get_time(QUIC_PORT *port); 110 111 int ossl_quic_port_get_rx_short_dcid_len(const QUIC_PORT *port); 112 int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port); 113 114 /* Returns 1 if the port is running/healthy, 0 if it has failed. */ 115 int ossl_quic_port_is_running(const QUIC_PORT *port); 116 117 /* 118 * Restores port-level error to the error stack. To be called only if 119 * the port is no longer running. 120 */ 121 void ossl_quic_port_restore_err_state(const QUIC_PORT *port); 122 123 /* For use by QUIC_ENGINE. You should not need to call this directly. */ 124 void ossl_quic_port_subtick(QUIC_PORT *port, QUIC_TICK_RESULT *r, 125 uint32_t flags); 126 127 /* 128 * Events 129 * ====== 130 */ 131 132 /* 133 * Called if a permanent network error occurs. Terminates all channels 134 * immediately. triggering_ch is an optional argument designating 135 * a channel which encountered the network error. 136 */ 137 void ossl_quic_port_raise_net_error(QUIC_PORT *port, 138 QUIC_CHANNEL *triggering_ch); 139 140 # endif 141 142 #endif 143