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.
This commit is contained in:
Amaury Denoyelle 2022-01-26 09:51:28 +01:00
parent 8ae28077b9
commit 0b1f93127f
2 changed files with 21 additions and 5 deletions

View File

@ -614,6 +614,17 @@ struct rxbuf {
struct mt_list mt_list; 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). */ /* The number of buffers for outgoing packets (must be a power of two). */
#define QUIC_CONN_TX_BUFS_NB 8 #define QUIC_CONN_TX_BUFS_NB 8
#define QUIC_CONN_TX_BUF_SZ QUIC_PACKET_MAXLEN #define QUIC_CONN_TX_BUF_SZ QUIC_PACKET_MAXLEN
@ -647,6 +658,7 @@ struct quic_conn {
/* Thread ID this connection is attached to */ /* Thread ID this connection is attached to */
int tid; int tid;
int state; int state;
enum qc_mux_state mux_state; /* status of the connection/mux layer */
uint64_t err_code; uint64_t err_code;
unsigned char enc_params[QUIC_TP_MAX_ENCLEN]; /* encoded QUIC transport parameters */ unsigned char enc_params[QUIC_TP_MAX_ENCLEN]; /* encoded QUIC transport parameters */
size_t enc_params_len; size_t enc_params_len;

View File

@ -1058,6 +1058,9 @@ int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alp
if (app_ops->finalize) if (app_ops->finalize)
app_ops->finalize(qc->qcc->ctx); app_ops->finalize(qc->qcc->ctx);
/* mux-quic can now be considered ready. */
qc->mux_state = QC_MUX_READY;
return 1; 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)) if (!(qel->tls_ctx.rx.flags & QUIC_FL_TLS_SECRETS_SET))
return 0; return 0;
/* do not decrypt application level until handshake completion */ /* check if the connection layer is ready before using app level */
if (tel == QUIC_TLS_ENC_LEVEL_APP && if (tel == QUIC_TLS_ENC_LEVEL_APP && qc->mux_state != QC_MUX_READY)
HA_ATOMIC_LOAD(&qc->state) < QUIC_HS_ST_COMPLETE) {
return 0; return 0;
}
return 1; return 1;
} }
@ -3475,6 +3475,9 @@ void quic_close(struct connection *conn, void *xprt_ctx)
qc->timer_task = NULL; qc->timer_task = NULL;
} }
/* Next application data can be dropped. */
qc->mux_state = QC_MUX_RELEASED;
TRACE_LEAVE(QUIC_EV_CONN_CLOSE, qc); TRACE_LEAVE(QUIC_EV_CONN_CLOSE, qc);
/* TODO for now release the quic_conn on notification by the upper /* 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); memcpy(qc->dcid.data, dcid, dcid_len);
qc->dcid.len = dcid_len; qc->dcid.len = dcid_len;
} }
qc->mux_state = QC_MUX_NULL;
/* Initialize the output buffer */ /* Initialize the output buffer */
qc->obuf.pos = qc->obuf.data; qc->obuf.pos = qc->obuf.data;