]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC ackm: use list.h
authorPauli <pauli@openssl.org>
Tue, 11 Oct 2022 09:20:12 +0000 (20:20 +1100)
committerPauli <pauli@openssl.org>
Wed, 16 Nov 2022 07:02:02 +0000 (18:02 +1100)
Instead of implementing a list internally.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/19377)

include/internal/quic_ackm.h
ssl/quic/quic_ackm.c
ssl/quic/quic_fifd.c

index 1188e30177b879dca54b1e7b401db20766794df3..492b0d8ca98ed1969384a2d7284ec3df0a3833f1 100644 (file)
@@ -14,6 +14,7 @@
 # include "internal/quic_types.h"
 # include "internal/quic_wire.h"
 # include "internal/time.h"
+# include "internal/list.h"
 
 typedef struct ossl_ackm_st OSSL_ACKM;
 
@@ -35,7 +36,8 @@ void ossl_ackm_set_ack_deadline_callback(OSSL_ACKM *ackm,
                                                     void *arg),
                                          void *arg);
 
-typedef struct ossl_ackm_tx_pkt_st {
+typedef struct ossl_ackm_tx_pkt_st OSSL_ACKM_TX_PKT;
+struct ossl_ackm_tx_pkt_st {
     /* The packet number of the transmitted packet. */
     QUIC_PN pkt_num;
 
@@ -89,15 +91,15 @@ typedef struct ossl_ackm_tx_pkt_st {
     /* 
      * (Internal use fields; must be zero-initialized.)
      *
-     * prev and next link us into the TX history list, anext is used to manifest
+     * Keep a TX history list, anext is used to manifest
      * a singly-linked list of newly-acknowledged packets, and lnext is used to
      * manifest a singly-linked list of newly lost packets.
      */
-    struct ossl_ackm_tx_pkt_st *prev;
-    struct ossl_ackm_tx_pkt_st *next;
+    OSSL_LIST_MEMBER(tx_history, OSSL_ACKM_TX_PKT);
+
     struct ossl_ackm_tx_pkt_st *anext;
     struct ossl_ackm_tx_pkt_st *lnext;
-} OSSL_ACKM_TX_PKT;
+};
 
 int ossl_ackm_on_tx_packet(OSSL_ACKM *ackm, OSSL_ACKM_TX_PKT *pkt);
 int ossl_ackm_on_rx_datagram(OSSL_ACKM *ackm, size_t num_bytes);
index 0f7166eaf39d4c605a68c57702af4d5a56d8219b..4378175f002216fbac523ee2987d7f597e96fcfc 100644 (file)
@@ -12,6 +12,8 @@
 #include "internal/common.h"
 #include <assert.h>
 
+DEFINE_LIST_OF(tx_history, OSSL_ACKM_TX_PKT);
+
 /*
  * TX Packet History
  * *****************
  */
 struct tx_pkt_history_st {
     /* A linked list of all our packets. */
-    OSSL_ACKM_TX_PKT *head, *tail;
-
-    /* Number of packets in the list. */
-    size_t num_packets;
+    OSSL_LIST(tx_history) packets;
 
     /*
      * Mapping from packet numbers (uint64_t) to (OSSL_ACKM_TX_PKT *)
@@ -78,8 +77,7 @@ static int tx_pkt_info_compare(const OSSL_ACKM_TX_PKT *a,
 static int
 tx_pkt_history_init(struct tx_pkt_history_st *h)
 {
-    h->head = h->tail = NULL;
-    h->num_packets  = 0;
+    ossl_list_tx_history_init(&h->packets);
     h->watermark    = 0;
     h->highest_sent = 0;
 
@@ -95,7 +93,7 @@ tx_pkt_history_destroy(struct tx_pkt_history_st *h)
 {
     lh_OSSL_ACKM_TX_PKT_free(h->map);
     h->map = NULL;
-    h->head = h->tail = NULL;
+    ossl_list_tx_history_init(&h->packets);
 }
 
 static int
@@ -113,20 +111,13 @@ tx_pkt_history_add_actual(struct tx_pkt_history_st *h,
         return 0;
 
     /* Should not already be in a list. */
-    if (!ossl_assert(pkt->next == NULL && pkt->prev == NULL))
+    if (!ossl_assert(ossl_list_tx_history_next(pkt) == NULL
+            && ossl_list_tx_history_prev(pkt) == NULL))
         return 0;
 
     lh_OSSL_ACKM_TX_PKT_insert(h->map, pkt);
 
-    pkt->next = NULL;
-    pkt->prev = h->tail;
-    if (h->tail != NULL)
-        h->tail->next = pkt;
-    h->tail = pkt;
-    if (h->head == NULL)
-        h->head = h->tail;
-
-    ++h->num_packets;
+    ossl_list_tx_history_insert_tail(&h->packets, pkt);
     return 1;
 }
 
@@ -168,19 +159,8 @@ tx_pkt_history_remove(struct tx_pkt_history_st *h, uint64_t pkt_num)
     if (pkt == NULL)
         return 0;
 
-    if (pkt->prev != NULL)
-        pkt->prev->next = pkt->next;
-    if (pkt->next != NULL)
-        pkt->next->prev = pkt->prev;
-    if (h->head == pkt)
-        h->head = pkt->next;
-    if (h->tail == pkt)
-        h->tail = pkt->prev;
-
-    pkt->prev = pkt->next = NULL;
-
+    ossl_list_tx_history_remove(&h->packets, pkt);
     lh_OSSL_ACKM_TX_PKT_delete(h->map, &key);
-    --h->num_packets;
     return 1;
 }
 
@@ -695,14 +675,14 @@ static OSSL_ACKM_TX_PKT *ackm_detect_and_remove_newly_acked_pkts(OSSL_ACKM *ackm
 
     pkt = tx_pkt_history_by_pkt_num(h, ack->ack_ranges[0].end);
     if (pkt == NULL)
-        pkt = h->tail;
+        pkt = ossl_list_tx_history_tail(&h->packets);
 
     for (; pkt != NULL; pkt = pprev) {
         /*
          * Save prev value as it will be zeroed if we remove the packet from the
          * history list below.
          */
-        pprev = pkt->prev;
+        pprev = ossl_list_tx_history_prev(pkt);
 
         for (;; ++ridx) {
             if (ridx >= ack->num_ack_ranges) {
@@ -774,7 +754,7 @@ static OSSL_ACKM_TX_PKT *ackm_detect_and_remove_lost_pkts(OSSL_ACKM *ackm,
     lost_send_time = ossl_time_subtract(now, loss_delay);
 
     h   = get_tx_history(ackm, pkt_space);
-    pkt = h->head;
+    pkt = ossl_list_tx_history_head(&h->packets);
 
     for (; pkt != NULL; pkt = pnext) {
         assert(pkt_space == pkt->pkt_space);
@@ -783,7 +763,7 @@ static OSSL_ACKM_TX_PKT *ackm_detect_and_remove_lost_pkts(OSSL_ACKM *ackm,
          * Save prev value as it will be zeroed if we remove the packet from the
          * history list below.
          */
-        pnext = pkt->next;
+        pnext = ossl_list_tx_history_next(pkt);
 
         if (pkt->pkt_num > ackm->largest_acked_pkt[pkt_space])
             continue;
@@ -1229,8 +1209,9 @@ int ossl_ackm_on_pkt_space_discarded(OSSL_ACKM *ackm, int pkt_space)
     if (pkt_space == QUIC_PN_SPACE_HANDSHAKE)
         ackm->peer_completed_addr_validation = 1;
 
-    for (pkt = get_tx_history(ackm, pkt_space)->head; pkt != NULL; pkt = pnext) {
-        pnext = pkt->next;
+    for (pkt = ossl_list_tx_history_head(&get_tx_history(ackm, pkt_space)->packets);
+            pkt != NULL; pkt = pnext) {
+        pnext = ossl_list_tx_history_next(pkt);
         if (pkt->is_inflight) {
             ackm->bytes_in_flight -= pkt->num_bytes;
             num_bytes_invalidated += pkt->num_bytes;
@@ -1339,10 +1320,12 @@ int ossl_ackm_get_probe_request(OSSL_ACKM *ackm, int clear,
 int ossl_ackm_get_largest_unacked(OSSL_ACKM *ackm, int pkt_space, QUIC_PN *pn)
 {
     struct tx_pkt_history_st *h;
+    OSSL_ACKM_TX_PKT *p;
 
     h = get_tx_history(ackm, pkt_space);
-    if (h->tail != NULL) {
-        *pn = h->tail->pkt_num;
+    p = ossl_list_tx_history_tail(&h->packets);
+    if (p != NULL) {
+        *pn = p->pkt_num;
         return 1;
     }
 
@@ -1416,7 +1399,7 @@ static int ackm_has_newly_missing(OSSL_ACKM *ackm, int pkt_space)
 
     h = get_rx_history(ackm, pkt_space);
 
-    if (ossl_list_uint_set_num(&h->set) == 0)
+    if (ossl_list_uint_set_is_empty(&h->set))
         return 0;
 
     /*
index 8f548520b1bc577b589424eaab554aa2598e39c8..f30e9d65531ea6c368d67b8d9d92c14a7c977642 100644 (file)
@@ -10,6 +10,8 @@
 #include "internal/quic_fifd.h"
 #include "internal/quic_wire.h"
 
+DEFINE_LIST_OF(tx_history, OSSL_ACKM_TX_PKT);
+
 int ossl_quic_fifd_init(QUIC_FIFD *fifd,
                         QUIC_CFQ *cfq,
                         OSSL_ACKM *ackm,
@@ -185,8 +187,8 @@ int ossl_quic_fifd_pkt_commit(QUIC_FIFD *fifd, QUIC_TXPIM_PKT *pkt)
     pkt->ackm_pkt.on_discarded  = on_discarded;
     pkt->ackm_pkt.cb_arg        = pkt;
 
-    pkt->ackm_pkt.prev = pkt->ackm_pkt.next
-        = pkt->ackm_pkt.anext = pkt->ackm_pkt.lnext = NULL;
+    ossl_list_tx_history_init_elem(&pkt->ackm_pkt);
+    pkt->ackm_pkt.anext = pkt->ackm_pkt.lnext = NULL;
 
     /*
      * Mark the CFQ items which have been added to this packet as having been