QUIC PORT: Keep a list of all child channels
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)

ssl/quic/quic_channel.c
ssl/quic/quic_channel_local.h
ssl/quic/quic_port.c
ssl/quic/quic_port_local.h

index 02ef8454967f6dadc87c2532918942a63b2c5e87..1ea69584c5197ccf5fadc68b46cd1aaeb7d1bb78 100644 (file)
@@ -46,6 +46,8 @@
  */
 #define DEFAULT_MAX_ACK_DELAY   QUIC_DEFAULT_MAX_ACK_DELAY
 
+DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
+
 static void ch_save_err_state(QUIC_CHANNEL *ch);
 static void ch_rx_pre(QUIC_CHANNEL *ch);
 static int ch_rx(QUIC_CHANNEL *ch, int channel_only);
@@ -486,6 +488,8 @@ static int ch_init(QUIC_CHANNEL *ch)
     ch_update_idle(ch);
     ossl_quic_reactor_init(&ch->rtor, ch_tick, ch,
                            ch_determine_next_tick_deadline(ch));
+    ossl_list_ch_insert_tail(&ch->port->channel_list, ch);
+    ch->on_port_list = 1;
     return 1;
 
 err:
@@ -543,6 +547,10 @@ static void ch_cleanup(QUIC_CHANNEL *ch)
         OPENSSL_free(srte);
     }
     lh_QUIC_SRT_ELEM_free(ch->srt_hash_tok);
+    if (ch->on_port_list) {
+        ossl_list_ch_remove(&ch->port->channel_list, ch);
+        ch->on_port_list = 0;
+    }
 }
 
 QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args)
index af35a6326bcf689b431da9b0a5cd8e101e8b6204..37cf73c67a148ffa1b3f8b1bc9214d69bd69eb8c 100644 (file)
@@ -38,6 +38,12 @@ DEFINE_LIST_OF(stateless_reset_tokens, QUIC_SRT_ELEM);
 struct quic_channel_st {
     QUIC_PORT                       *port;
 
+    /*
+     * QUIC_PORT keeps the channels which belong to it on a list for bookkeeping
+     * purposes.
+     */
+    OSSL_LIST_MEMBER(ch, struct quic_channel_st);
+
     /*
      * 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
@@ -449,6 +455,9 @@ struct quic_channel_st {
     /* Are we using addressed mode? */
     unsigned int                    addressed_mode                      : 1;
 
+    /* Are we on the QUIC_PORT linked list of channels? */
+    unsigned int                    on_port_list                        : 1;
+
     /* Saved error stack in case permanent error was encountered */
     ERR_STATE                       *err_state;
 
index 0beb69835bbaecaeb7b14a128827cefe457bd5a0..8b727d2f128be7ff4c9899b897deabe75bd4b1ec 100644 (file)
@@ -23,6 +23,8 @@ static OSSL_TIME get_time(void *arg);
 static void port_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags);
 //static void port_default_packet_handler(QUIC_URXE *e, void *arg);
 
+DEFINE_LIST_OF_IMPL(ch, QUIC_CHANNEL);
+
 QUIC_PORT *ossl_quic_port_new(const QUIC_PORT_ARGS *args)
 {
     QUIC_PORT *port;
@@ -82,6 +84,7 @@ err:
 
 static void port_cleanup(QUIC_PORT *port)
 {
+    assert(ossl_list_ch_num(&port->channel_list) == 0);
     ossl_quic_demux_free(port->demux);
     port->demux = NULL;
 }
index 60216bb1b5b13df7243afad0753679f94e58bda3..7aaf4d6a425d8a46a9042f98b7f16936cfd29336 100644 (file)
@@ -3,6 +3,7 @@
 
 # include "internal/quic_port.h"
 # include "internal/quic_reactor.h"
+# include "internal/list.h"
 
 # ifndef OPENSSL_NO_QUIC
 
@@ -15,6 +16,8 @@
  *
  * Other components should not include this header.
  */
+DECLARE_LIST_OF(ch, QUIC_CHANNEL);
+
 struct quic_port_st {
     OSSL_LIB_CTX                    *libctx;
     const char                      *propq;
@@ -39,6 +42,9 @@ struct quic_port_st {
 
     /* RX demuxer. We register incoming DCIDs with this. */
     QUIC_DEMUX                      *demux;
+
+    /* List of all child channels. */
+    OSSL_LIST(ch)                   channel_list;
 };
 
 # endif