mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: quic: adjust quic CID derive API
ODCID are never stored in the CID tree. Instead, we store our generated CID which is directly derived from the CID using a hash function. This operation is done via quic_derive_cid(). Previously, generated CID was returned as a 64-bits integer. However, this is cumbersome to convert as an array of bytes which is the most common CID representation. Adjust this by modifying return type to a quic_cid struct. This should be backported up to 2.7.
This commit is contained in:
parent
1a5cc19cec
commit
c2a9264f34
@ -674,6 +674,8 @@ int quic_set_app_ops(struct quic_conn *qc, const unsigned char *alpn, size_t alp
|
|||||||
int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len);
|
int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len);
|
||||||
int quic_get_dgram_dcid(unsigned char *buf, const unsigned char *end,
|
int quic_get_dgram_dcid(unsigned char *buf, const unsigned char *end,
|
||||||
unsigned char **dcid, size_t *dcid_len);
|
unsigned char **dcid, size_t *dcid_len);
|
||||||
|
struct quic_cid quic_derive_cid(const struct quic_cid *orig,
|
||||||
|
const struct sockaddr_storage *addr);
|
||||||
int qc_send_mux(struct quic_conn *qc, struct list *frms);
|
int qc_send_mux(struct quic_conn *qc, struct list *frms);
|
||||||
|
|
||||||
void qc_notify_close(struct quic_conn *qc);
|
void qc_notify_close(struct quic_conn *qc);
|
||||||
|
@ -3910,16 +3910,18 @@ static int quic_stateless_reset_token_init(struct quic_connection_id *conn_id)
|
|||||||
/* Generate a CID directly derived from <orig> CID and <addr> address. The CID
|
/* Generate a CID directly derived from <orig> CID and <addr> address. The CID
|
||||||
* is then marked with the current thread ID.
|
* is then marked with the current thread ID.
|
||||||
*
|
*
|
||||||
* Returns a new 64-bits CID value.
|
* Returns the derived CID.
|
||||||
*/
|
*/
|
||||||
static uint64_t quic_derive_cid(const struct quic_cid *orig,
|
struct quic_cid quic_derive_cid(const struct quic_cid *orig,
|
||||||
const struct sockaddr_storage *addr)
|
const struct sockaddr_storage *addr)
|
||||||
{
|
{
|
||||||
|
struct quic_cid cid;
|
||||||
const struct sockaddr_in *in;
|
const struct sockaddr_in *in;
|
||||||
const struct sockaddr_in6 *in6;
|
const struct sockaddr_in6 *in6;
|
||||||
char *buf = trash.area;
|
char *buf = trash.area;
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
uint64_t hash;
|
uint64_t hash;
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Prepare buffer for hash using original CID first. */
|
/* Prepare buffer for hash using original CID first. */
|
||||||
memcpy(buf, orig->data, orig->len);
|
memcpy(buf, orig->data, orig->len);
|
||||||
@ -3948,7 +3950,6 @@ static uint64_t quic_derive_cid(const struct quic_cid *orig,
|
|||||||
default:
|
default:
|
||||||
/* TODO to implement */
|
/* TODO to implement */
|
||||||
ABORT_NOW();
|
ABORT_NOW();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Avoid similar values between multiple haproxy process. */
|
/* Avoid similar values between multiple haproxy process. */
|
||||||
@ -3958,10 +3959,14 @@ static uint64_t quic_derive_cid(const struct quic_cid *orig,
|
|||||||
/* Hash the final buffer content. */
|
/* Hash the final buffer content. */
|
||||||
hash = XXH64(buf, idx, 0);
|
hash = XXH64(buf, idx, 0);
|
||||||
|
|
||||||
/* Mark the current thread id in the CID. */
|
for (i = 0; i < sizeof(hash); ++i)
|
||||||
quic_pin_cid_to_tid((uchar *)&hash, tid);
|
cid.data[i] = hash >> ((sizeof(hash) * 7) - (8 * i));
|
||||||
|
cid.len = sizeof(hash);
|
||||||
|
|
||||||
return hash;
|
/* Mark the current thread id in the CID. */
|
||||||
|
quic_pin_cid_to_tid(cid.data, tid);
|
||||||
|
|
||||||
|
return cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a new CID and attach it to <root> ebtree.
|
/* Allocate a new CID and attach it to <root> ebtree.
|
||||||
@ -4002,8 +4007,7 @@ static struct quic_connection_id *new_quic_cid(struct eb_root *root,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Derive the new CID value from original CID. */
|
/* Derive the new CID value from original CID. */
|
||||||
const uint64_t hash = quic_derive_cid(orig, addr);
|
conn_id->cid = quic_derive_cid(orig, addr);
|
||||||
memcpy(conn_id->cid.data, &hash, sizeof(hash));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quic_stateless_reset_token_init(conn_id) != 1) {
|
if (quic_stateless_reset_token_init(conn_id) != 1) {
|
||||||
@ -6524,8 +6528,8 @@ static struct quic_conn *retrieve_qc_conn_from_cid(struct quic_rx_packet *pkt,
|
|||||||
*/
|
*/
|
||||||
if (!node && (pkt->type == QUIC_PACKET_TYPE_INITIAL ||
|
if (!node && (pkt->type == QUIC_PACKET_TYPE_INITIAL ||
|
||||||
pkt->type == QUIC_PACKET_TYPE_0RTT)) {
|
pkt->type == QUIC_PACKET_TYPE_0RTT)) {
|
||||||
uint64_t hash = quic_derive_cid(&pkt->dcid, saddr);
|
const struct quic_cid derive_cid = quic_derive_cid(&pkt->dcid, saddr);
|
||||||
node = ebmb_lookup(&quic_dghdlrs[tid].cids, &hash, sizeof(hash));
|
node = ebmb_lookup(&quic_dghdlrs[tid].cids, derive_cid.data, derive_cid.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
|
Loading…
Reference in New Issue
Block a user