From: Frédéric Lécaille Date: Fri, 6 May 2022 12:18:53 +0000 (+0200) Subject: MINOR: quic: new_quic_cid() code moving X-Git-Tag: v2.6-dev10~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0226c521b0bdc53c6571dc37e2fc0aaf2edb18f2;p=thirdparty%2Fhaproxy.git MINOR: quic: new_quic_cid() code moving This function will have to call another one from quic_tls.[ch] soon. As we do not want to include quic_tls.h from xprt_quic.h because quic_tls.h already includes xprt_quic.h, let's moving it into xprt_quic.c. --- diff --git a/include/haproxy/xprt_quic.h b/include/haproxy/xprt_quic.h index 2c98ed6028..dc90f3d205 100644 --- a/include/haproxy/xprt_quic.h +++ b/include/haproxy/xprt_quic.h @@ -179,49 +179,6 @@ static inline void quic_pin_cid_to_tid(unsigned char *cid, int target_tid) cid[0] = cid[0] - (cid[0] % global.nbthread) + target_tid; } -/* Allocate a new CID with as sequence number and attach it to - * ebtree. - * - * The CID is randomly generated in part with the result altered to be - * associated with the current thread ID. This means this function must only - * be called by the quic_conn thread. - * - * Returns the new CID if succeeded, NULL if not. - */ -static inline struct quic_connection_id *new_quic_cid(struct eb_root *root, - struct quic_conn *qc, - int seq_num) -{ - struct quic_connection_id *cid; - - cid = pool_alloc(pool_head_quic_connection_id); - if (!cid) - return NULL; - - cid->cid.len = QUIC_HAP_CID_LEN; - if (RAND_bytes(cid->cid.data, cid->cid.len) != 1 || - RAND_bytes(cid->stateless_reset_token, - sizeof cid->stateless_reset_token) != 1) { - fprintf(stderr, "Could not generate %d random bytes\n", cid->cid.len); - goto err; - } - - quic_pin_cid_to_tid(cid->cid.data, tid); - - cid->qc = qc; - - cid->seq_num.key = seq_num; - cid->retire_prior_to = 0; - /* insert the allocated CID in the quic_conn tree */ - eb64_insert(root, &cid->seq_num); - - return cid; - - err: - pool_free(pool_head_quic_connection_id, cid); - return NULL; -} - /* The maximum size of a variable-length QUIC integer encoded with 1 byte */ #define QUIC_VARINT_1_BYTE_MAX ((1UL << 6) - 1) /* The maximum size of a variable-length QUIC integer encoded with 2 bytes */ diff --git a/src/xprt_quic.c b/src/xprt_quic.c index 66c3555a48..0d598ce463 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -3262,6 +3262,49 @@ int qc_send_ppkts(struct qring *qr, struct ssl_sock_ctx *ctx) return 1; } +/* Allocate a new CID with as sequence number and attach it to + * ebtree. + * + * The CID is randomly generated in part with the result altered to be + * associated with the current thread ID. This means this function must only + * be called by the quic_conn thread. + * + * Returns the new CID if succeeded, NULL if not. + */ +static struct quic_connection_id *new_quic_cid(struct eb_root *root, + struct quic_conn *qc, + int seq_num) +{ + struct quic_connection_id *cid; + + cid = pool_alloc(pool_head_quic_connection_id); + if (!cid) + return NULL; + + cid->cid.len = QUIC_HAP_CID_LEN; + if (RAND_bytes(cid->cid.data, cid->cid.len) != 1 || + RAND_bytes(cid->stateless_reset_token, + sizeof cid->stateless_reset_token) != 1) { + fprintf(stderr, "Could not generate %d random bytes\n", cid->cid.len); + goto err; + } + + quic_pin_cid_to_tid(cid->cid.data, tid); + + cid->qc = qc; + + cid->seq_num.key = seq_num; + cid->retire_prior_to = 0; + /* insert the allocated CID in the quic_conn tree */ + eb64_insert(root, &cid->seq_num); + + return cid; + + err: + pool_free(pool_head_quic_connection_id, cid); + return NULL; +} + /* Build all the frames which must be sent just after the handshake have succeeded. * This is essentially NEW_CONNECTION_ID frames. A QUIC server must also send * a HANDSHAKE_DONE frame.