MINOR: quic: remove address concatenation to ODCID

Previously, ODCID were concatenated with the client address. This was
done to prevent a collision between two endpoints which used the same
ODCID.

Thanks to the two previous patches, first connection generated CID is
now directly derived from the client ODCID using a hash function which
uses the client source address from the same purpose. Thus, it is now
unneeded to concatenate client address to <odcid> quic-conn member.

This change allows to simplify the quic_cid structure management and
reduce its size which is important as it is embedded several times in
various structures such as quic_conn and quic_rx_packet.

This should be backported up to 2.7.
This commit is contained in:
Amaury Denoyelle 2023-04-05 09:50:17 +02:00
parent 2c98209c1c
commit 15adc4cc4e
3 changed files with 5 additions and 51 deletions

View File

@ -282,9 +282,8 @@ extern const struct quic_version *preferred_version;
* <data> member must be the first one. * <data> member must be the first one.
*/ */
struct quic_cid { struct quic_cid {
unsigned char data[QUIC_CID_MAXLEN + sizeof(in_port_t) + sizeof(struct in6_addr)]; unsigned char data[QUIC_CID_MAXLEN];
unsigned char len; /* size of QUIC CID, excluding possible concatenated address */ unsigned char len; /* size of QUIC CID */
unsigned char addrlen; /* size of port + IP if present in data*/
}; };
/* QUIC connection id attached to a QUIC connection. /* QUIC connection id attached to a QUIC connection.
@ -651,12 +650,7 @@ struct quic_conn {
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;
/* struct quic_cid odcid; /* First DCID used by client on its Initial packet. */
* Original DCID used by clients on first Initial packets.
* <odcid> is concatenated with the socket src address.
*/
struct quic_cid odcid;
struct quic_cid dcid; /* DCID of our endpoint - not updated when a new DCID is used */ struct quic_cid dcid; /* DCID of our endpoint - not updated when a new DCID is used */
struct ebmb_node scid_node; /* used only for client side (backend) */ struct ebmb_node scid_node; /* used only for client side (backend) */
struct quic_cid scid; /* first SCID of our endpoint - not updated when a new SCID is used */ struct quic_cid scid; /* first SCID of our endpoint - not updated when a new SCID is used */

View File

@ -120,42 +120,6 @@ static inline size_t quic_saddr_cpy(unsigned char *buf,
return p - buf; return p - buf;
} }
/* Concatenate the port and address of <saddr> to <cid> QUIC connection ID. The
* <addrlen> field of <cid> will be updated with the size of the concatenated
* address.
*
* Returns the number of bytes concatenated to <cid>.
*/
static inline size_t quic_cid_saddr_cat(struct quic_cid *cid,
struct sockaddr_storage *saddr)
{
void *port, *addr;
size_t port_len, addr_len;
cid->addrlen = 0;
if (saddr->ss_family == AF_INET6) {
port = &((struct sockaddr_in6 *)saddr)->sin6_port;
addr = &((struct sockaddr_in6 *)saddr)->sin6_addr;
port_len = sizeof ((struct sockaddr_in6 *)saddr)->sin6_port;
addr_len = sizeof ((struct sockaddr_in6 *)saddr)->sin6_addr;
}
else {
port = &((struct sockaddr_in *)saddr)->sin_port;
addr = &((struct sockaddr_in *)saddr)->sin_addr;
port_len = sizeof ((struct sockaddr_in *)saddr)->sin_port;
addr_len = sizeof ((struct sockaddr_in *)saddr)->sin_addr;
}
memcpy(cid->data + cid->len, port, port_len);
cid->addrlen += port_len;
memcpy(cid->data + cid->len + port_len, addr, addr_len);
cid->addrlen += addr_len;
return port_len + addr_len;
}
/* Dump the QUIC connection ID value if present (non null length). Used only for /* Dump the QUIC connection ID value if present (non null length). Used only for
* debugging purposes. * debugging purposes.
* Always succeeds. * Always succeeds.

View File

@ -5421,10 +5421,9 @@ static struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4,
&quic_stats_module); &quic_stats_module);
qc->flags |= QUIC_FL_CONN_LISTENER; qc->flags |= QUIC_FL_CONN_LISTENER;
qc->state = QUIC_HS_ST_SERVER_INITIAL; qc->state = QUIC_HS_ST_SERVER_INITIAL;
/* Copy the initial DCID with the address. */ /* Copy the client original DCID. */
qc->odcid.len = dcid->len; qc->odcid.len = dcid->len;
qc->odcid.addrlen = dcid->addrlen; memcpy(qc->odcid.data, dcid->data, dcid->len);
memcpy(qc->odcid.data, dcid->data, dcid->len + dcid->addrlen);
/* copy the packet SCID to reuse it as DCID for sending */ /* copy the packet SCID to reuse it as DCID for sending */
if (scid->len) if (scid->len)
@ -8165,9 +8164,6 @@ int qc_check_dcid(struct quic_conn *qc, unsigned char *dcid, size_t dcid_len)
struct ebmb_node *node; struct ebmb_node *node;
struct quic_connection_id *id; struct quic_connection_id *id;
/* For ODCID, address is concatenated to it after qc.odcid.len so this
* comparison is safe.
*/
if ((qc->scid.len == dcid_len && if ((qc->scid.len == dcid_len &&
memcmp(qc->scid.data, dcid, dcid_len) == 0) || memcmp(qc->scid.data, dcid, dcid_len) == 0) ||
(qc->odcid.len == dcid_len && (qc->odcid.len == dcid_len &&