From a7348f6f85778f5242b1325c8682c4c90c78a184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Tue, 3 Aug 2021 16:50:14 +0200 Subject: [PATCH] MINOR: quic: Make qc_build_hdshk_pkt() atomically consume a packet number Atomically increase the "next packet variable" before building a new packet. Make the code bug on a packet building failure. This should never happen if we do not want to consume a packet number for nothing. There are remaining modifications to come to ensure this is the case. --- src/xprt_quic.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/xprt_quic.c b/src/xprt_quic.c index cb7092e7b..85c6a3a9e 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -3918,11 +3918,10 @@ static struct quic_tx_packet *qc_build_hdshk_pkt(unsigned char **pos, beg = *pos; pn_len = 0; buf_pn = NULL; - pn = qel->pktns->tx.next_pn + 1; - if (!qc_do_build_hdshk_pkt(*pos, buf_end, pkt, pkt_type, pn, &pn_len, &buf_pn, qel, qc)) { - *err = -1; - goto err; - } + /* Consume a packet number. */ + pn = HA_ATOMIC_ADD_FETCH(&qel->pktns->tx.next_pn, 1); + if (!qc_do_build_hdshk_pkt(*pos, buf_end, pkt, pkt_type, pn, &pn_len, &buf_pn, qel, qc)) + BUG_ON(0); end = beg + pkt->len; payload = buf_pn + pn_len; @@ -3946,10 +3945,8 @@ static struct quic_tx_packet *qc_build_hdshk_pkt(unsigned char **pos, /* Now that a correct packet is built, let us consume <*pos> buffer. */ *pos = end; - /* Consume a packet number. */ - ++qel->pktns->tx.next_pn; /* Attach the built packet to its tree. */ - pkt->pn_node.key = qel->pktns->tx.next_pn; + pkt->pn_node.key = pn; /* Set the packet in fligth length for in flight packet only. */ if (pkt->flags & QUIC_FL_TX_PACKET_IN_FLIGHT) { pkt->in_flight_len = pkt->len;