summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2023-02-21 10:18:59 +0000
committerHugo Landau <hlandau@openssl.org>2023-03-30 11:14:08 +0100
commitf2f7c4f15ab1d8dc36b668877253c0e497da8ca6 (patch)
tree4bb2b2cb17054c2c152de33fcfbbcd59a8d1c3a4
parent9f7acf071c363ed8cb5012e122e1e60447b45c78 (diff)
Front End for QUIC Thread Assisted Mode
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20348)
-rw-r--r--ssl/quic/quic_impl.c30
-rw-r--r--ssl/quic/quic_local.h9
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.