From: Amaury Denoyelle Date: Wed, 26 Jan 2022 08:51:28 +0000 (+0100) Subject: MINOR: quic: handle app data according to mux/connection layer status X-Git-Tag: v2.6-dev1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b1f93127f858b8455b1bb9cd93b29e9e3365dae;p=thirdparty%2Fhaproxy.git MINOR: quic: handle app data according to mux/connection layer status Define a new enum to represent the status of the mux/connection layer above a quic_conn. This is important to know if it's possible to handle application data, or if it should be buffered or dropped. --- diff --git a/include/haproxy/xprt_quic-t.h b/include/haproxy/xprt_quic-t.h index bb75cee1f7..562d22cab2 100644 --- a/include/haproxy/xprt_quic-t.h +++ b/include/haproxy/xprt_quic-t.h @@ -614,6 +614,17 @@ struct rxbuf { struct mt_list mt_list; }; +/* Status of the connection/mux layer. This defines how to handle app data. + * + * During a standard quic_conn lifetime it transitions like this : + * QC_MUX_NULL -> QC_MUX_READY -> QC_MUX_RELEASED + */ +enum qc_mux_state { + QC_MUX_NULL, /* not allocated, data should be buffered */ + QC_MUX_READY, /* allocated, ready to handle data */ + QC_MUX_RELEASED, /* released, data can be dropped */ +}; + /* The number of buffers for outgoing packets (must be a power of two). */ #define QUIC_CONN_TX_BUFS_NB 8 #define QUIC_CONN_TX_BUF_SZ QUIC_PACKET_MAXLEN @@ -647,6 +658,7 @@ struct quic_conn { /* Thread ID this connection is attached to */ int tid; int state; + enum qc_mux_state mux_state; /* status of the connection/mux layer */ uint64_t err_code; unsigned char enc_params[QUIC_TP_MAX_ENCLEN]; /* encoded QUIC transport parameters */ size_t enc_params_len; diff --git a/src/xprt_quic.c b/src/xprt_quic.c index ec09170b17..3683350a5c 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -1058,6 +1058,9 @@ int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alp if (app_ops->finalize) app_ops->finalize(qc->qcc->ctx); + /* mux-quic can now be considered ready. */ + qc->mux_state = QC_MUX_READY; + return 1; } @@ -3203,12 +3206,9 @@ static int qc_qel_may_rm_hp(struct quic_conn *qc, struct quic_enc_level *qel) if (!(qel->tls_ctx.rx.flags & QUIC_FL_TLS_SECRETS_SET)) return 0; - /* do not decrypt application level until handshake completion */ - if (tel == QUIC_TLS_ENC_LEVEL_APP && - HA_ATOMIC_LOAD(&qc->state) < QUIC_HS_ST_COMPLETE) { + /* check if the connection layer is ready before using app level */ + if (tel == QUIC_TLS_ENC_LEVEL_APP && qc->mux_state != QC_MUX_READY) return 0; - } - return 1; } @@ -3475,6 +3475,9 @@ void quic_close(struct connection *conn, void *xprt_ctx) qc->timer_task = NULL; } + /* Next application data can be dropped. */ + qc->mux_state = QC_MUX_RELEASED; + TRACE_LEAVE(QUIC_EV_CONN_CLOSE, qc); /* TODO for now release the quic_conn on notification by the upper @@ -3608,6 +3611,7 @@ static struct quic_conn *qc_new_conn(unsigned int version, int ipv4, memcpy(qc->dcid.data, dcid, dcid_len); qc->dcid.len = dcid_len; } + qc->mux_state = QC_MUX_NULL; /* Initialize the output buffer */ qc->obuf.pos = qc->obuf.data;