From: Frederic Lecaille Date: Tue, 5 Aug 2025 12:15:46 +0000 (+0200) Subject: MINOR: quic-be: Parse the NEW_TOKEN frame X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a209723fdd57bf2af3e3508a5b21638e05a30ab;p=thirdparty%2Fhaproxy.git MINOR: quic-be: Parse the NEW_TOKEN frame Rename ->data qf_new_token struct field to ->w_data to distinguish it from ->r_data new field used to parse the NEW_TOKEN frame. Indeed to build the NEW_TOKEN we need to write it to a static buffer into the frame struct. To parse it we only need to store the address of the token field into the RX buffer. --- diff --git a/include/haproxy/quic_frame-t.h b/include/haproxy/quic_frame-t.h index aff0161d5..c71bc7411 100644 --- a/include/haproxy/quic_frame-t.h +++ b/include/haproxy/quic_frame-t.h @@ -161,7 +161,10 @@ struct qf_crypto { struct qf_new_token { uint64_t len; - unsigned char data[QUIC_TOKEN_LEN]; + /* Used only to send data */ + unsigned char w_data[QUIC_TOKEN_LEN]; + /* Used only to receive data */ + const unsigned char *r_data; }; struct qf_stream { diff --git a/src/quic_conn.c b/src/quic_conn.c index 54b40881d..a689561e1 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -519,14 +519,14 @@ int quic_build_post_handshake_frames(struct quic_conn *qc, } new_token_frm_len = - quic_generate_token(frm->new_token.data, - sizeof(frm->new_token.data), &qc->peer_addr); + quic_generate_token(frm->new_token.w_data, + sizeof(frm->new_token.w_data), &qc->peer_addr); if (!new_token_frm_len) { TRACE_ERROR("token generation failed", QUIC_EV_CONN_IO_CB, qc); goto err; } - BUG_ON(new_token_frm_len != sizeof(frm->new_token.data)); + BUG_ON(new_token_frm_len != sizeof(frm->new_token.w_data)); frm->new_token.len = new_token_frm_len; LIST_APPEND(&frm_list, &frm->list); } diff --git a/src/quic_frame.c b/src/quic_frame.c index 3d1f12838..0e9c3cc3d 100644 --- a/src/quic_frame.c +++ b/src/quic_frame.c @@ -485,7 +485,7 @@ static int quic_build_new_token_frame(unsigned char **pos, const unsigned char * if (!quic_enc_int(pos, end, new_token_frm->len) || end - *pos < new_token_frm->len) return 0; - memcpy(*pos, new_token_frm->data, new_token_frm->len); + memcpy(*pos, new_token_frm->w_data, new_token_frm->len); *pos += new_token_frm->len; return 1; @@ -503,16 +503,7 @@ static int quic_parse_new_token_frame(struct quic_frame *frm, struct quic_conn * if (!quic_dec_int(&new_token_frm->len, pos, end) || end - *pos < new_token_frm->len) return 0; - /* TODO token length is unknown as it is dependent from the peer. Hence - * dynamic allocation should be implemented for token storage, albeit - * with constraint to ensure memory usage remains reasonable. - */ -#if 0 - if (sizeof(new_token_frm->data) < new_token_frm->len) - return 0; - memcpy(new_token_frm->data, *pos, new_token_frm->len); -#endif - + new_token_frm->r_data = *pos; *pos += new_token_frm->len; return 1;