From: Hugo Landau Date: Thu, 9 Nov 2023 10:27:13 +0000 (+0000) Subject: QUIC CHANNEL, TSERVER: Move to using libctx/propq/mutex/now_cb via QUIC_PORT X-Git-Tag: openssl-3.3.0-alpha1~439 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34fa182e1d8fa2f1d4016e13e7b6500fd117f781;p=thirdparty%2Fopenssl.git QUIC CHANNEL, TSERVER: Move to using libctx/propq/mutex/now_cb via QUIC_PORT Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/22674) --- diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h index f4bee6bf468..9a434fbb7f9 100644 --- a/include/internal/quic_channel.h +++ b/include/internal/quic_channel.h @@ -112,30 +112,8 @@ typedef struct quic_channel_args_st { */ QUIC_PORT *port; - OSSL_LIB_CTX *libctx; - const char *propq; int is_server; SSL *tls; - - /* - * This must be a mutex the lifetime of which will exceed that of the - * channel. The instantiator of the channel is responsible for providing a - * mutex as this makes it easier to handle instantiation and teardown of - * channels in situations potentially requiring locking. - * - * Note that this is a MUTEX not a RWLOCK as it needs to be an OS mutex for - * compatibility with an OS's condition variable wait API, whereas RWLOCK - * may, depending on the build configuration, be implemented using an OS's - * mutex primitive or using its RW mutex primitive. - */ - CRYPTO_MUTEX *mutex; - - /* - * Optional function pointer to use to retrieve the current time. If NULL, - * ossl_time_now() is used. - */ - OSSL_TIME (*now_cb)(void *arg); - void *now_cb_arg; } QUIC_CHANNEL_ARGS; typedef struct quic_channel_st QUIC_CHANNEL; diff --git a/include/internal/quic_port.h b/include/internal/quic_port.h index f8d774c1534..a42d2138f56 100644 --- a/include/internal/quic_port.h +++ b/include/internal/quic_port.h @@ -44,6 +44,10 @@ typedef struct quic_port_args_st { */ CRYPTO_MUTEX *mutex; + /* + * Optional function pointer to use to retrieve the current time. If NULL, + * ossl_time_now() is used. + */ OSSL_TIME (*now_cb)(void *arg); void *now_cb_arg; } QUIC_PORT_ARGS; diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index 8a7ddb9f391..e266a552e39 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -14,6 +14,7 @@ #include "internal/quic_rx_depack.h" #include "../ssl_local.h" #include "quic_channel_local.h" +#include "quic_port_local.h" /* * NOTE: While this channel implementation currently has basic server support, @@ -285,11 +286,11 @@ static int ch_init(QUIC_CHANNEL *ch) /* For clients, generate our initial DCID. */ if (!ch->is_server - && !gen_rand_conn_id(ch->libctx, INIT_DCID_LEN, &ch->init_dcid)) + && !gen_rand_conn_id(ch->port->libctx, INIT_DCID_LEN, &ch->init_dcid)) goto err; /* We plug in a network write BIO to the QTX later when we get one. */ - qtx_args.libctx = ch->libctx; + qtx_args.libctx = ch->port->libctx; qtx_args.mdpl = QUIC_MIN_INITIAL_DGRAM_LEN; ch->rx_max_udp_payload_size = qtx_args.mdpl; @@ -414,7 +415,7 @@ static int ch_init(QUIC_CHANNEL *ch) ch_default_packet_handler, ch); - qrx_args.libctx = ch->libctx; + qrx_args.libctx = ch->port->libctx; qrx_args.demux = ch->demux; qrx_args.short_conn_id_len = rx_short_cid_len; qrx_args.max_deferred = 32; @@ -552,13 +553,8 @@ QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args) return NULL; ch->port = args->port; - ch->libctx = args->libctx; - ch->propq = args->propq; ch->is_server = args->is_server; ch->tls = args->tls; - ch->mutex = args->mutex; - ch->now_cb = args->now_cb; - ch->now_cb_arg = args->now_cb_arg; if (!ch_init(ch)) { OPENSSL_free(ch); @@ -696,7 +692,7 @@ QUIC_PORT *ossl_quic_channel_get0_port(QUIC_CHANNEL *ch) CRYPTO_MUTEX *ossl_quic_channel_get_mutex(QUIC_CHANNEL *ch) { - return ch->mutex; + return ch->port->mutex; } int ossl_quic_channel_has_pending(const QUIC_CHANNEL *ch) @@ -715,10 +711,10 @@ static OSSL_TIME get_time(void *arg) { QUIC_CHANNEL *ch = arg; - if (ch->now_cb == NULL) + if (ch->port->now_cb == NULL) return ossl_time_now(); - return ch->now_cb(ch->now_cb_arg); + return ch->port->now_cb(ch->port->now_cb_arg); } /* Used by QSM. */ @@ -2279,8 +2275,8 @@ static void ch_rx_handle_packet(QUIC_CHANNEL *ch, int channel_only) * than allow the QRX to emit a potentially malformed packet to the * upper layers. However, special casing this will do for now. */ - if (!ossl_quic_validate_retry_integrity_tag(ch->libctx, - ch->propq, + if (!ossl_quic_validate_retry_integrity_tag(ch->port->libctx, + ch->port->propq, ch->qrx_pkt->hdr, &ch->init_dcid)) /* Malformed retry packet, ignore. */ @@ -2780,8 +2776,8 @@ int ossl_quic_channel_start(QUIC_CHANNEL *ch) return 0; /* Plug in secrets for the Initial EL. */ - if (!ossl_quic_provide_initial_secret(ch->libctx, - ch->propq, + if (!ossl_quic_provide_initial_secret(ch->port->libctx, + ch->port->propq, &ch->init_dcid, ch->is_server, ch->qrx, ch->qtx)) @@ -2880,8 +2876,8 @@ static int ch_retry(QUIC_CHANNEL *ch, * Plug in new secrets for the Initial EL. This is the only time we change * the secrets for an EL after we already provisioned it. */ - if (!ossl_quic_provide_initial_secret(ch->libctx, - ch->propq, + if (!ossl_quic_provide_initial_secret(ch->port->libctx, + ch->port->propq, &ch->retry_scid, /*is_server=*/0, ch->qrx, ch->qtx)) @@ -3504,7 +3500,7 @@ static int ch_server_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer, return 0; /* Generate a SCID we will use for the connection. */ - if (!gen_rand_conn_id(ch->libctx, INIT_DCID_LEN, + if (!gen_rand_conn_id(ch->port->libctx, INIT_DCID_LEN, &ch->cur_local_cid)) return 0; @@ -3525,8 +3521,8 @@ static int ch_server_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer, return 0; /* Plug in secrets for the Initial EL. */ - if (!ossl_quic_provide_initial_secret(ch->libctx, - ch->propq, + if (!ossl_quic_provide_initial_secret(ch->port->libctx, + ch->port->propq, &ch->init_dcid, /*is_server=*/1, ch->qrx, ch->qtx)) diff --git a/ssl/quic/quic_channel_local.h b/ssl/quic/quic_channel_local.h index 67e648b42f8..af35a6326bc 100644 --- a/ssl/quic/quic_channel_local.h +++ b/ssl/quic/quic_channel_local.h @@ -38,23 +38,6 @@ DEFINE_LIST_OF(stateless_reset_tokens, QUIC_SRT_ELEM); struct quic_channel_st { QUIC_PORT *port; - OSSL_LIB_CTX *libctx; - const char *propq; - - /* - * Master synchronisation mutex used for thread assisted mode - * synchronisation. We don't own this; the instantiator of the channel - * passes it to us and is responsible for freeing it after channel - * destruction. - */ - CRYPTO_MUTEX *mutex; - - /* - * Callback used to get the current time. - */ - OSSL_TIME (*now_cb)(void *arg); - void *now_cb_arg; - /* * The associated TLS 1.3 connection data. Used to provide the handshake * layer; its 'network' side is plugged into the crypto stream for each EL diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index adc954cafe8..618b4f4ac40 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -1505,13 +1505,8 @@ static int create_channel(QUIC_CONNECTION *qc) } ch_args.port = qc->port; - ch_args.libctx = qc->ssl.ctx->libctx; - ch_args.propq = qc->ssl.ctx->propq; ch_args.is_server = qc->as_server; ch_args.tls = qc->tls; - ch_args.mutex = qc->mutex; - ch_args.now_cb = get_time_cb; - ch_args.now_cb_arg = qc; qc->ch = ossl_quic_channel_new(&ch_args); if (qc->ch == NULL) { diff --git a/ssl/quic/quic_port_local.h b/ssl/quic/quic_port_local.h index 0336cd7d049..60216bb1b5b 100644 --- a/ssl/quic/quic_port_local.h +++ b/ssl/quic/quic_port_local.h @@ -19,7 +19,12 @@ struct quic_port_st { OSSL_LIB_CTX *libctx; const char *propq; - /* Mutex for the entire QUIC event domain. */ + /* + * Master synchronisation mutex for the entire QUIC event domain. Used for + * thread assisted mode synchronisation. We don't own this; the instantiator + * of the port passes it to us and is responsible for freeing it after port + * destruction. + */ CRYPTO_MUTEX *mutex; /* Callback used to get the current time. */ diff --git a/ssl/quic/quic_tserver.c b/ssl/quic/quic_tserver.c index e5cc31ba821..b5ba3eeb854 100644 --- a/ssl/quic/quic_tserver.c +++ b/ssl/quic/quic_tserver.c @@ -127,13 +127,8 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args, goto err; ch_args.port = srv->port; - ch_args.libctx = srv->args.libctx; - ch_args.propq = srv->args.propq; ch_args.tls = srv->tls; - ch_args.mutex = srv->mutex; ch_args.is_server = 1; - ch_args.now_cb = srv->args.now_cb; - ch_args.now_cb_arg = srv->args.now_cb_arg; if ((srv->ch = ossl_quic_channel_new(&ch_args)) == NULL) goto err;