]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: remove address concatenation to ODCID
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 5 Apr 2023 07:50:17 +0000 (09:50 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 5 Apr 2023 09:09:57 +0000 (11:09 +0200)
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.

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

index f6a962984291d22b258f3cf43082684319813ac4..fdeb9dad371d68be700ac24163e0d0d39069595b 100644 (file)
@@ -282,9 +282,8 @@ extern const struct quic_version *preferred_version;
  * <data> member must be the first one.
  */
 struct quic_cid {
-       unsigned char data[QUIC_CID_MAXLEN + sizeof(in_port_t) + sizeof(struct in6_addr)];
-       unsigned char len; /* size of QUIC CID, excluding possible concatenated address */
-       unsigned char addrlen; /* size of port + IP if present in data*/
+       unsigned char data[QUIC_CID_MAXLEN];
+       unsigned char len; /* size of QUIC CID */
 };
 
 /* 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 */
        size_t enc_params_len;
 
-       /*
-        * Original DCID used by clients on first Initial packets.
-        * <odcid> is concatenated with the socket src address.
-        */
-       struct quic_cid odcid;
-
+       struct quic_cid odcid; /* First DCID used by client on its Initial packet. */
        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 quic_cid scid; /* first SCID of our endpoint - not updated when a new SCID is used */
index 8342c9bafdd1390cacdb4afae93accf291fdff23..568911052a5e0ee7d8cae0b7e1a699cb70424a48 100644 (file)
@@ -120,42 +120,6 @@ static inline size_t quic_saddr_cpy(unsigned char *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
  * debugging purposes.
  * Always succeeds.
index 268368f5b98e2525bec12b430b4d1cddf38fdb6e..06cbcdba732e9fe57d746fa173495ba9b868afba 100644 (file)
@@ -5421,10 +5421,9 @@ static struct quic_conn *qc_new_conn(const struct quic_version *qv, int ipv4,
                                                      &quic_stats_module);
                qc->flags |= QUIC_FL_CONN_LISTENER;
                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.addrlen = dcid->addrlen;
-               memcpy(qc->odcid.data, dcid->data, dcid->len + dcid->addrlen);
+               memcpy(qc->odcid.data, dcid->data, dcid->len);
 
                /* copy the packet SCID to reuse it as DCID for sending */
                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 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 &&
             memcmp(qc->scid.data, dcid, dcid_len) == 0) ||
            (qc->odcid.len == dcid_len &&