summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2022-10-11 20:20:12 +1100
committerPauli <pauli@openssl.org>2022-11-16 18:02:02 +1100
commitdead13551c6661d34af3e5ddf1bc53c9efdb5647 (patch)
tree9cbe22d5b77f27b5a58caeeec09b27fe9d280297
parente32fc5ad0ea1a2d69f12d9208f2de489f7ee9737 (diff)
QUIC ackm: use list.h
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)
-rw-r--r--include/internal/quic_ackm.h12
-rw-r--r--ssl/quic/quic_ackm.c59
-rw-r--r--ssl/quic/quic_fifd.c6
3 files changed, 32 insertions, 45 deletions
diff --git a/include/internal/quic_ackm.h b/include/internal/quic_ackm.h
index 1188e30177..492b0d8ca9 100644
--- a/include/internal/quic_ackm.h
+++ b/include/internal/quic_ackm.h
@@ -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);
diff --git a/ssl/quic/quic_ackm.c b/ssl/quic/quic_ackm.c
index 0f7166eaf3..4378175f00 100644
--- a/ssl/quic/quic_ackm.c
+++ b/ssl/quic/quic_ackm.c
@@ -12,6 +12,8 @@
#include "internal/common.h"
#include <assert.h>
+DEFINE_LIST_OF(tx_history, OSSL_ACKM_TX_PKT);
+
/*
* TX Packet History
* *****************
@@ -28,10 +30,7 @@
*/
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;
/*
diff --git a/ssl/quic/quic_fifd.c b/ssl/quic/quic_fifd.c
index 8f548520b1..f30e9d6553 100644
--- a/ssl/quic/quic_fifd.c
+++ b/ssl/quic/quic_fifd.c
@@ -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