From f7749968d6738a3d11225be08aa39b14a1b06ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Thu, 22 Jun 2023 15:02:38 +0200 Subject: [PATCH] CLEANUP: quic: Remove two useless pools a low QUIC connection level Both "quic_tx_ring" and "quic_rx_crypto_frm" pool are no more used. Should be backported as far as 2.6. --- include/haproxy/quic_conn-t.h | 1 - include/haproxy/quic_tls.h | 39 +++++++++++++++++++++++++++++++++++ src/quic_conn.c | 13 ++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/haproxy/quic_conn-t.h b/include/haproxy/quic_conn-t.h index eb05fd537..d05a7b96f 100644 --- a/include/haproxy/quic_conn-t.h +++ b/include/haproxy/quic_conn-t.h @@ -252,7 +252,6 @@ enum quic_pkt_type { #define QUIC_CONN_RX_BUFSZ (1UL << 16) extern struct trace_source trace_quic; -extern struct pool_head *pool_head_quic_tx_ring; extern struct pool_head *pool_head_quic_rx_packet; extern struct pool_head *pool_head_quic_tx_packet; extern struct pool_head *pool_head_quic_crypto_buf; diff --git a/include/haproxy/quic_tls.h b/include/haproxy/quic_tls.h index 0c6aff9be..9927044b4 100644 --- a/include/haproxy/quic_tls.h +++ b/include/haproxy/quic_tls.h @@ -184,6 +184,24 @@ static inline struct quic_pktns **ssl_to_quic_pktns(struct quic_conn *qc, } } +/* These following functions map TLS implementation encryption level to ours */ +static inline struct quic_pktns **qel_to_quic_pktns(struct quic_conn *qc, + enum quic_tls_enc_level level) +{ + switch (level) { + case QUIC_TLS_ENC_LEVEL_INITIAL: + return &qc->ipktns; + case QUIC_TLS_ENC_LEVEL_EARLY_DATA: + return &qc->apktns; + case QUIC_TLS_ENC_LEVEL_HANDSHAKE: + return &qc->hpktns; + case QUIC_TLS_ENC_LEVEL_APP: + return &qc->apktns; + default: + return NULL; + } +} + /* Map TLS stack encryption level to our internal QUIC TLS encryption level * if succeded, or -1 if failed. */ @@ -224,6 +242,27 @@ static inline struct quic_enc_level **ssl_to_qel_addr(struct quic_conn *qc, } } +/* Return the address of the QUIC TLS encryption level associated to internal + * encryption level and attached to QUIC connection if succeeded, or + * NULL if failed. + */ +static inline struct quic_enc_level **qel_to_qel_addr(struct quic_conn *qc, + enum quic_tls_enc_level level) +{ + switch (level) { + case QUIC_TLS_ENC_LEVEL_INITIAL: + return &qc->iel; + case QUIC_TLS_ENC_LEVEL_EARLY_DATA: + return &qc->eel; + case QUIC_TLS_ENC_LEVEL_HANDSHAKE: + return &qc->hel; + case QUIC_TLS_ENC_LEVEL_APP: + return &qc->ael; + default: + return NULL; + } +} + /* Return the QUIC TLS encryption level associated to internal encryption * level attached to QUIC connection if succeeded, or NULL if failed. */ diff --git a/src/quic_conn.c b/src/quic_conn.c index f44945af2..40454f112 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -211,7 +211,6 @@ INITCALL1(STG_REGISTER, trace_register_source, TRACE_SOURCE); static BIO_METHOD *ha_quic_meth; -DECLARE_POOL(pool_head_quic_tx_ring, "quic_tx_ring", QUIC_TX_RING_BUFSZ); DECLARE_POOL(pool_head_quic_conn_rxbuf, "quic_conn_rxbuf", QUIC_CONN_RX_BUFSZ); DECLARE_STATIC_POOL(pool_head_quic_conn_ctx, "quic_conn_ctx", sizeof(struct ssl_sock_ctx)); @@ -221,7 +220,6 @@ DECLARE_POOL(pool_head_quic_connection_id, DECLARE_POOL(pool_head_quic_dgram, "quic_dgram", sizeof(struct quic_dgram)); DECLARE_POOL(pool_head_quic_rx_packet, "quic_rx_packet", sizeof(struct quic_rx_packet)); DECLARE_POOL(pool_head_quic_tx_packet, "quic_tx_packet", sizeof(struct quic_tx_packet)); -DECLARE_STATIC_POOL(pool_head_quic_rx_crypto_frm, "quic_rx_crypto_frm", sizeof(struct quic_rx_crypto_frm)); 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)); DECLARE_POOL(pool_head_quic_frame, "quic_frame", sizeof(struct quic_frame)); @@ -6051,6 +6049,17 @@ static inline int qc_try_rm_hp(struct quic_conn *qc, tel = quic_packet_type_enc_level(pkt->type); qel = qc_quic_enc_level(qc, tel); + if (!qel) { + struct quic_enc_level **qc_qel = qel_to_qel_addr(qc, tel); + struct quic_pktns **qc_pktns = qel_to_quic_pktns(qc, tel); + + if (!qc_enc_level_alloc(qc, qc_pktns, qc_qel, quic_to_ssl_enc_level(tel))) { + TRACE_PROTO("Could not allocated an encryption level", QUIC_EV_CONN_ADDDATA, qc); + goto out; + } + + qel = *qc_qel; + } if (qc_qel_may_rm_hp(qc, qel)) { struct quic_tls_ctx *tls_ctx = qc_select_tls_ctx(qc, qel, pkt);