]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: quic: Move QUIC CRYPTO stream definitions/declarations to QUIC TLS
authorFrédéric Lécaille <flecaille@haproxy.com>
Mon, 27 Nov 2023 09:30:41 +0000 (10:30 +0100)
committerFrédéric Lécaille <flecaille@haproxy.com>
Tue, 28 Nov 2023 14:37:22 +0000 (15:37 +0100)
Move quic_cstream struct definition from quic_conn-t.h to quic_tls-t.h.
Its pool is also moved from quic_conn module to quic_tls. Same thing for
quic_cstream_new() and quic_cstream_free().

include/haproxy/quic_conn-t.h
include/haproxy/quic_tls-t.h
src/quic_conn.c
src/quic_tls.c

index b7eb7d44c80eaa91d295cb760e73b4fc4d011932..087dfd693089b705f6769a1444f30e55cb56bab2 100644 (file)
@@ -235,21 +235,6 @@ extern const struct quic_version *preferred_version;
 /* The maximum number of bytes of CRYPTO data in flight during handshakes. */
 #define QUIC_CRYPTO_IN_FLIGHT_MAX 4096
 
-/* Crypto data stream (one by encryption level) */
-struct quic_cstream {
-       struct {
-               uint64_t offset;       /* absolute current base offset of ncbuf */
-               struct ncbuf ncbuf;    /* receive buffer - can handle out-of-order offset frames */
-       } rx;
-       struct {
-               uint64_t offset;      /* last offset of data ready to be sent */
-               uint64_t sent_offset; /* last offset sent by transport layer */
-               struct buffer buf;    /* transmit buffer before sending via xprt */
-       } tx;
-
-       struct qc_stream_desc *desc;
-};
-
 struct quic_path {
        /* Control congestion. */
        struct quic_cc cc;
index edbbeeff5b1b8f5a37e0e79c368c2f575e4aa766..e74e5a95592573e4bf6ef30e00a6e79de87995b2 100644 (file)
@@ -219,6 +219,21 @@ struct quic_crypto_buf {
        size_t sz;
 };
 
+/* Crypto data stream (one by encryption level) */
+struct quic_cstream {
+       struct {
+               uint64_t offset;       /* absolute current base offset of ncbuf */
+               struct ncbuf ncbuf;    /* receive buffer - can handle out-of-order offset frames */
+       } rx;
+       struct {
+               uint64_t offset;      /* last offset of data ready to be sent */
+               uint64_t sent_offset; /* last offset sent by transport layer */
+               struct buffer buf;    /* transmit buffer before sending via xprt */
+       } tx;
+
+       struct qc_stream_desc *desc;
+};
+
 struct quic_enc_level {
        struct list list;
        /* Attach point to enqueue this encryption level during retransmissions */
index 334f7dccaec1f69d078415bf9b5056876b4ecdec..35c3c6fb7cd821063204b4faa72b582fe8d4164b 100644 (file)
@@ -137,7 +137,6 @@ DECLARE_STATIC_POOL(pool_head_quic_cc_conn, "quic_cc_conn", sizeof(struct quic_c
 DECLARE_STATIC_POOL(pool_head_quic_cids, "quic_cids", sizeof(struct eb_root));
 DECLARE_POOL(pool_head_quic_connection_id,
              "quic_connection_id", sizeof(struct quic_connection_id));
-DECLARE_STATIC_POOL(pool_head_quic_cstream, "quic_cstream", sizeof(struct quic_cstream));
 
 struct task *quic_conn_app_io_cb(struct task *t, void *context, unsigned int state);
 static int quic_conn_init_timer(struct quic_conn *qc);
@@ -791,57 +790,6 @@ struct task *quic_conn_io_cb(struct task *t, void *context, unsigned int state)
        return t;
 }
 
-/* Release the memory allocated for <cs> CRYPTO stream */
-void quic_cstream_free(struct quic_cstream *cs)
-{
-       if (!cs) {
-               /* This is the case for ORTT encryption level */
-               return;
-       }
-
-       quic_free_ncbuf(&cs->rx.ncbuf);
-
-       qc_stream_desc_release(cs->desc);
-       pool_free(pool_head_quic_cstream, cs);
-}
-
-/* Allocate a new QUIC stream for <qc>.
- * Return it if succeeded, NULL if not.
- */
-struct quic_cstream *quic_cstream_new(struct quic_conn *qc)
-{
-       struct quic_cstream *cs, *ret_cs = NULL;
-
-       TRACE_ENTER(QUIC_EV_CONN_LPKT, qc);
-       cs = pool_alloc(pool_head_quic_cstream);
-       if (!cs) {
-               TRACE_ERROR("crypto stream allocation failed", QUIC_EV_CONN_INIT, qc);
-               goto leave;
-       }
-
-       cs->rx.offset = 0;
-       cs->rx.ncbuf = NCBUF_NULL;
-       cs->rx.offset = 0;
-
-       cs->tx.offset = 0;
-       cs->tx.sent_offset = 0;
-       cs->tx.buf = BUF_NULL;
-       cs->desc = qc_stream_desc_new((uint64_t)-1, -1, cs, qc);
-       if (!cs->desc) {
-               TRACE_ERROR("crypto stream allocation failed", QUIC_EV_CONN_INIT, qc);
-               goto err;
-       }
-
-       ret_cs = cs;
- leave:
-       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
-       return ret_cs;
-
- err:
-       pool_free(pool_head_quic_cstream, cs);
-       goto leave;
-}
-
 /* Callback called upon loss detection and PTO timer expirations. */
 struct task *qc_process_timer(struct task *task, void *ctx, unsigned int state)
 {
index a75f012153ba8b642d3c5be71d4b2948e2ad84fc..7e18a39264f2244450786f5cd3db70ed478c26c2 100644 (file)
@@ -11,6 +11,8 @@
 #include <haproxy/pool.h>
 #include <haproxy/quic_ack.h>
 #include <haproxy/quic_conn.h>
+#include <haproxy/quic_rx.h>
+#include <haproxy/quic_stream.h>
 
 
 DECLARE_POOL(pool_head_quic_enc_level,  "quic_enc_level",  sizeof(struct quic_enc_level));
@@ -21,6 +23,7 @@ DECLARE_POOL(pool_head_quic_tls_iv,     "quic_tls_iv",     QUIC_TLS_IV_LEN);
 DECLARE_POOL(pool_head_quic_tls_key,    "quic_tls_key",    QUIC_TLS_KEY_LEN);
 
 DECLARE_POOL(pool_head_quic_crypto_buf, "quic_crypto_buf", sizeof(struct quic_crypto_buf));
+DECLARE_STATIC_POOL(pool_head_quic_cstream, "quic_cstream", sizeof(struct quic_cstream));
 
 /* Initial salt depending on QUIC version to derive client/server initial secrets.
  * This one is for draft-29 QUIC version.
@@ -112,6 +115,57 @@ void quic_tls_secret_hexdump(struct buffer *buf,
                chunk_appendf(buf, "%02x", secret[i]);
 }
 
+/* Release the memory allocated for <cs> CRYPTO stream */
+void quic_cstream_free(struct quic_cstream *cs)
+{
+       if (!cs) {
+               /* This is the case for ORTT encryption level */
+               return;
+       }
+
+       quic_free_ncbuf(&cs->rx.ncbuf);
+
+       qc_stream_desc_release(cs->desc);
+       pool_free(pool_head_quic_cstream, cs);
+}
+
+/* Allocate a new QUIC stream for <qc>.
+ * Return it if succeeded, NULL if not.
+ */
+struct quic_cstream *quic_cstream_new(struct quic_conn *qc)
+{
+       struct quic_cstream *cs, *ret_cs = NULL;
+
+       TRACE_ENTER(QUIC_EV_CONN_LPKT, qc);
+       cs = pool_alloc(pool_head_quic_cstream);
+       if (!cs) {
+               TRACE_ERROR("crypto stream allocation failed", QUIC_EV_CONN_INIT, qc);
+               goto leave;
+       }
+
+       cs->rx.offset = 0;
+       cs->rx.ncbuf = NCBUF_NULL;
+       cs->rx.offset = 0;
+
+       cs->tx.offset = 0;
+       cs->tx.sent_offset = 0;
+       cs->tx.buf = BUF_NULL;
+       cs->desc = qc_stream_desc_new((uint64_t)-1, -1, cs, qc);
+       if (!cs->desc) {
+               TRACE_ERROR("crypto stream allocation failed", QUIC_EV_CONN_INIT, qc);
+               goto err;
+       }
+
+       ret_cs = cs;
+ leave:
+       TRACE_LEAVE(QUIC_EV_CONN_LPKT, qc);
+       return ret_cs;
+
+ err:
+       pool_free(pool_head_quic_cstream, cs);
+       goto leave;
+}
+
 /* Uninitialize <qel> QUIC encryption level. Never fails. */
 void quic_conn_enc_level_uninit(struct quic_conn *qc, struct quic_enc_level *qel)
 {