From f2f7c4f15ab1d8dc36b668877253c0e497da8ca6 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Tue, 21 Feb 2023 10:18:59 +0000 Subject: Front End for QUIC Thread Assisted Mode Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/20348) --- ssl/quic/quic_impl.c | 30 ++++++++++++++++++++---------- ssl/quic/quic_local.h | 9 +++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 1ab6b8ba80..73071d4a73 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -161,6 +161,9 @@ SSL *ossl_quic_new(SSL_CTX *ctx) if ((qc->mutex = CRYPTO_THREAD_lock_new()) == NULL) goto err; + qc->is_thread_assisted + = (ssl_base->method == OSSL_QUIC_client_thread_method()); + /* Channel is not created yet. */ qc->ssl_mode = qc->ssl.ctx->mode; qc->last_error = SSL_ERROR_NONE; @@ -185,6 +188,10 @@ void ossl_quic_free(SSL *s) return; quic_lock(qc); /* best effort */ + + if (qc->is_thread_assisted && qc->started) + ossl_quic_thread_assist_wait_stopped(&qc->thread_assist); + ossl_quic_channel_free(qc->ch); BIO_free(qc->net_rbio); @@ -694,21 +701,24 @@ static int ensure_channel_and_start(QUIC_CONNECTION *qc) return 0; if (!configure_channel(qc) - || !ossl_quic_channel_start(qc->ch)) { - ossl_quic_channel_free(qc->ch); - qc->ch = NULL; - return 0; - } + || !ossl_quic_channel_start(qc->ch)) + goto err; qc->stream0 = ossl_quic_channel_get_stream_by_id(qc->ch, 0); - if (qc->stream0 == NULL) { - ossl_quic_channel_free(qc->ch); - qc->ch = NULL; - return 0; - } + if (qc->stream0 == NULL) + goto err; + + if (qc->is_thread_assisted) + if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch)) + goto err; qc->started = 1; return 1; + +err: + ossl_quic_channel_free(qc->ch); + qc->ch = NULL; + return 0; } QUIC_NEEDS_LOCK diff --git a/ssl/quic/quic_local.h b/ssl/quic/quic_local.h index 300332307c..d405052674 100644 --- a/ssl/quic/quic_local.h +++ b/ssl/quic/quic_local.h @@ -21,6 +21,7 @@ # include "internal/quic_stream.h" # include "internal/quic_channel.h" # include "internal/quic_reactor.h" +# include "internal/quic_thread_assist.h" # include "../ssl_local.h" # ifndef OPENSSL_NO_QUIC @@ -65,6 +66,11 @@ struct quic_conn_st { /* Initial peer L4 address. */ BIO_ADDR init_peer_addr; +#ifndef OPENSSL_NO_QUIC_THREAD_ASSIST + /* Manages thread for QUIC thread assisted mode. */ + QUIC_THREAD_ASSIST thread_assist; +#endif + /* Have we started? */ unsigned int started : 1; @@ -81,6 +87,9 @@ struct quic_conn_st { */ unsigned int as_server : 1; + /* Are we using thread assisted mode? Never changes after init. */ + unsigned int is_thread_assisted : 1; + /* * This state tracks SSL_write all-or-nothing (AON) write semantics * emulation. -- cgit v1.2.3