From 8370c93a0314f440ce98537144d6cd8d6776c40b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Mon, 8 Nov 2021 17:01:46 +0100 Subject: [PATCH] MINOR: quic: Possible wrong connection identification A client may send several Initial packets. This is the case for picoquic with -Q option. In this case we must identify the connection of incoming Initial packets thanks to the original destination connection ID. --- src/xprt_quic.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/xprt_quic.c b/src/xprt_quic.c index 2aaf9ba..f0a9ad1 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -3729,30 +3729,36 @@ static ssize_t qc_lstnr_pkt_rcv(unsigned char **buf, const unsigned char *end, goto err; } - pkt->qc = qc; - /* This is the DCID node sent in this packet by the client. */ - node = &qc->odcid_node; - /* Enqueue this packet. */ - MT_LIST_APPEND(&l->rx.pkts, &pkt->rx_list); - /* Try to accept a new connection. */ - listener_accept(l); - HA_RWLOCK_WRLOCK(QUIC_LOCK, &l->rx.cids_lock); /* Insert the DCID the QUIC client has chosen (only for listeners) */ - ebmb_insert(&l->rx.odcids, &qc->odcid_node, qc->odcid.len); - /* Insert our SCID, the connection ID for the QUIC client. */ - n = ebmb_insert(&l->rx.cids, &qc->scid_node, qc->scid.len); + n = ebmb_insert(&l->rx.odcids, &qc->odcid_node, qc->odcid.len); + if (n == &qc->odcid_node) { + /* Insert our SCID, the connection ID for the QUIC client. */ + ebmb_insert(&l->rx.cids, &qc->scid_node, qc->scid.len); + } HA_RWLOCK_WRUNLOCK(QUIC_LOCK, &l->rx.cids_lock); - if (n != &qc->scid_node) { + + pkt->qc = qc; + if (n == &qc->odcid_node) { + /* Enqueue this packet. */ + MT_LIST_APPEND(&l->rx.pkts, &pkt->rx_list); + /* Try to accept a new connection. */ + listener_accept(l); + } + else { quic_conn_free(qc); - qc = ebmb_entry(n, struct quic_conn, scid_node); + qc = ebmb_entry(n, struct quic_conn, odcid_node); } + + /* This is the DCID node sent in this packet by the client. */ + node = &qc->odcid_node; } else { if (pkt->type == QUIC_PACKET_TYPE_INITIAL && cids == &l->rx.odcids) qc = ebmb_entry(node, struct quic_conn, odcid_node); else qc = ebmb_entry(node, struct quic_conn, scid_node); + pkt->qc = qc; conn_ctx = qc->conn->xprt_ctx; } } @@ -3772,12 +3778,11 @@ static ssize_t qc_lstnr_pkt_rcv(unsigned char **buf, const unsigned char *end, qc = ebmb_entry(node, struct quic_conn, scid_node); conn_ctx = qc->conn->xprt_ctx; *buf += QUIC_CID_LEN; + pkt->qc = qc; /* A short packet is the last one of an UDP datagram. */ pkt->len = end - *buf; } - pkt->qc = qc; - /* Store the DCID used for this packet to check the packet which * come in this UDP datagram match with it. */ -- 1.7.10.4