QUIC CHANNEL, TSERVER: Move to using libctx/propq/mutex/now_cb via QUIC_PORT
authorHugo Landau <hlandau@openssl.org>
Thu, 9 Nov 2023 10:27:13 +0000 (10:27 +0000)
committerHugo Landau <hlandau@openssl.org>
Thu, 21 Dec 2023 08:11:59 +0000 (08:11 +0000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22674)

include/internal/quic_channel.h
include/internal/quic_port.h
ssl/quic/quic_channel.c
ssl/quic/quic_channel_local.h
ssl/quic/quic_impl.c
ssl/quic/quic_port_local.h
ssl/quic/quic_tserver.c

index f4bee6bf4685f9bcc009d679a1bbf7fdcb056bae..9a434fbb7f97a0975321259edf7c4e8b50f983b2 100644 (file)
@@ -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;
index f8d774c1534886b198e313ef9251a317682c569e..a42d2138f5677905d298f15cd2df1106ab4868a2 100644 (file)
@@ -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;
index 8a7ddb9f3914ef4cb4feca0e09faa1049b6c7e46..e266a552e39298fbc551d70abe09a987dd662247 100644 (file)
@@ -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))
index 67e648b42f80dbef994acefa72742a387b3a79e1..af35a6326bcf689b431da9b0a5cd8e101e8b6204 100644 (file)
@@ -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
index adc954cafe80231943b3779820366e02e762c3a3..618b4f4ac40fe534435d8a19258f64658987b8ae 100644 (file)
@@ -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) {
index 0336cd7d049679fe5c8b7f6c9003aee371fcb9f9..60216bb1b5b13df7243afad0753679f94e58bda3 100644 (file)
@@ -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. */
index e5cc31ba82115c9f94489f5d8a0879a583e733b5..b5ba3eeb854ed6488e2434831a89a4ca8dc0f906 100644 (file)
@@ -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;