]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic-be: Parse the NEW_TOKEN frame
authorFrederic Lecaille <flecaille@haproxy.com>
Tue, 5 Aug 2025 12:15:46 +0000 (14:15 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 11 Sep 2025 16:26:21 +0000 (18:26 +0200)
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.

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

index aff0161d5d6dbb9d1840314820e2c141902549cc..c71bc741177fc14736dbd5637454aa6611280000 100644 (file)
@@ -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 {
index 54b40881d5f5b16ac4c8eb9f1f19f559e94ccbec..a689561e193ba6a6a5ba38b10cc03d70762cdbf1 100644 (file)
@@ -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);
        }
index 3d1f128388a2730cd004f7f559dc3e8ba0a46615..0e9c3cc3d2265d998dd8b073d6bcfe749940bc49 100644 (file)
@@ -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;