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.
diff --git a/src/xprt_quic.c b/src/xprt_quic.c
index cb7092e..85c6a3a 100644
--- a/src/xprt_quic.c
+++ b/src/xprt_quic.c
@@ -3918,11 +3918,10 @@
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 @@
/* 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;