#define QUIC_FL_CONN_HPKTNS_DCD (1U << 16) /* Handshake packet number space discarded */
#define QUIC_FL_CONN_PEER_VALIDATED_ADDR (1U << 17) /* Peer address is considered as validated for this connection. */
#define QUIC_FL_CONN_NO_TOKEN_RCVD (1U << 18) /* Client dit not send any token */
-#define QUIC_FL_CONN_SCID_RECEIVED (1U << 19) /* (client only: first Initial received. */
+#define QUIC_FL_CONN_SCID_RECEIVED (1U << 19) /* (client only: first Initial accepted. */
#define QUIC_FL_CONN_XPRT_CLOSED (1U << 20) /* close callback of xprt layer already called */
/* gap here */
#define QUIC_FL_CONN_TO_KILL (1U << 24) /* Unusable connection, to be killed */
else {
struct quic_arng ar = { .first = pkt->pn, .last = pkt->pn };
+ if (pkt->type == QUIC_PACKET_TYPE_INITIAL && qc_is_back(qc) &&
+ !(qc->flags & QUIC_FL_CONN_SCID_RECEIVED)) {
+ /* Adopt the peer CID only after accepting its Initial. */
+ memcpy(qc->dcid.data, pkt->scid.data, pkt->scid.len);
+ qc->dcid.len = pkt->scid.len;
+ qc->flags |= QUIC_FL_CONN_SCID_RECEIVED;
+ }
+
/* RFC 9000 8.1. Address Validation during Connection Establishment
*
* Connection establishment implicitly provides address validation for
* ack-eliciting Initial packets to at least the smallest allowed maximum
* datagram size of 1200 bytes.
*/
- if (!(qc->flags & QUIC_FL_CONN_SCID_RECEIVED)) {
- qc->flags |= QUIC_FL_CONN_SCID_RECEIVED;
- memcpy(qc->dcid.data, pkt->scid.data, pkt->scid.len);
- qc->dcid.len = pkt->scid.len;
- }
-
if (qc_is_back(qc)) {
if (qc->flags & QUIC_FL_CONN_CLOSING) {
TRACE_PROTO("Packet dropped",