QUIC TSERVER: Provide a TSERVER's QUIC_CHANNEL with a currently unused 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
ssl/quic/quic_tserver.c

index d4f3018cc476c73f592f24517f30e209aa152a31..f4bee6bf4685f9bcc009d679a1bbf7fdcb056bae 100644 (file)
 #  define QUIC_CHANNEL_STATE_TERMINATED                  4
 
 typedef struct quic_channel_args_st {
+    /*
+     * The QUIC_PORT which the channel is to belong to. The lifetime of the
+     * QUIC_PORT must exceed that of the created channel.
+     */
     QUIC_PORT       *port;
 
     OSSL_LIB_CTX    *libctx;
index 130733821cf3d9c37d655049a98c2d7be2052a3f..e5cc31ba82115c9f94489f5d8a0879a583e733b5 100644 (file)
@@ -10,6 +10,7 @@
 #include "internal/quic_tserver.h"
 #include "internal/quic_channel.h"
 #include "internal/quic_statm.h"
+#include "internal/quic_port.h"
 #include "internal/common.h"
 #include "internal/time.h"
 #include "quic_local.h"
@@ -25,8 +26,10 @@ struct quic_tserver_st {
     SSL *ssl;
 
     /*
-     * The QUIC channel providing the core QUIC connection implementation.
+     * The QUIC port and channel providing the core QUIC connection
+     * implementation.
      */
+    QUIC_PORT       *port;
     QUIC_CHANNEL    *ch;
 
     /* The mutex we give to the QUIC channel. */
@@ -75,6 +78,7 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
                                     const char *certfile, const char *keyfile)
 {
     QUIC_TSERVER *srv = NULL;
+    QUIC_PORT_ARGS port_args = {0};
     QUIC_CHANNEL_ARGS ch_args = {0};
     QUIC_CONNECTION *qc = NULL;
 
@@ -113,6 +117,16 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
     if (srv->tls == NULL)
         goto err;
 
+    port_args.libctx        = srv->args.libctx;
+    port_args.propq         = srv->args.propq;
+    port_args.mutex         = srv->mutex;
+    port_args.now_cb        = srv->args.now_cb;
+    port_args.now_cb_arg    = srv->args.now_cb_arg;
+
+    if ((srv->port = ossl_quic_port_new(&port_args)) == NULL)
+        goto err;
+
+    ch_args.port        = srv->port;
     ch_args.libctx      = srv->args.libctx;
     ch_args.propq       = srv->args.propq;
     ch_args.tls         = srv->tls;
@@ -143,6 +157,7 @@ err:
             SSL_CTX_free(srv->ctx);
         SSL_free(srv->tls);
         ossl_quic_channel_free(srv->ch);
+        ossl_quic_port_free(srv->port);
 #if defined(OPENSSL_THREADS)
         ossl_crypto_mutex_free(&srv->mutex);
 #endif
@@ -159,6 +174,7 @@ void ossl_quic_tserver_free(QUIC_TSERVER *srv)
         return;
 
     ossl_quic_channel_free(srv->ch);
+    ossl_quic_port_free(srv->port);
     BIO_free_all(srv->args.net_rbio);
     BIO_free_all(srv->args.net_wbio);
     OPENSSL_free(srv->ssl);