]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: quic: Make qc_build_hdshk_pkt() atomically consume a packet number
authorFrédéric Lécaille <flecaille@haproxy.com>
Tue, 3 Aug 2021 14:50:14 +0000 (16:50 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Sep 2021 13:27:25 +0000 (15:27 +0200)
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

index cb7092e7b5dee318771e16e59b75237c3065e957..85c6a3a9eaa00379ffee951590cee03e03db3b84 100644 (file)
@@ -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;