Lines Matching +full:stop +full:- +full:ack
2 * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
22 * sent for which we later expect to receive an ACK. It is essentially a simple
46 * list non-monotonically, so packet numbers must be greater than or equal
64 return (unsigned long)pkt->pkt_num; in tx_pkt_info_hash()
70 if (a->pkt_num < b->pkt_num) in tx_pkt_info_compare()
71 return -1; in tx_pkt_info_compare()
72 if (a->pkt_num > b->pkt_num) in tx_pkt_info_compare()
80 ossl_list_tx_history_init(&h->packets); in tx_pkt_history_init()
81 h->watermark = 0; in tx_pkt_history_init()
82 h->highest_sent = 0; in tx_pkt_history_init()
84 h->map = lh_OSSL_ACKM_TX_PKT_new(tx_pkt_info_hash, tx_pkt_info_compare); in tx_pkt_history_init()
85 if (h->map == NULL) in tx_pkt_history_init()
94 lh_OSSL_ACKM_TX_PKT_free(h->map); in tx_pkt_history_destroy()
95 h->map = NULL; in tx_pkt_history_destroy()
96 ossl_list_tx_history_init(&h->packets); in tx_pkt_history_destroy()
109 existing = lh_OSSL_ACKM_TX_PKT_retrieve(h->map, pkt); in tx_pkt_history_add_actual()
118 lh_OSSL_ACKM_TX_PKT_insert(h->map, pkt); in tx_pkt_history_add_actual()
120 ossl_list_tx_history_insert_tail(&h->packets, pkt); in tx_pkt_history_add_actual()
129 if (!ossl_assert(pkt->pkt_num >= h->watermark)) in tx_pkt_history_add()
135 h->watermark = pkt->pkt_num + 1; in tx_pkt_history_add()
136 h->highest_sent = pkt->pkt_num; in tx_pkt_history_add()
148 return lh_OSSL_ACKM_TX_PKT_retrieve(h->map, &key); in tx_pkt_history_by_pkt_num()
162 ossl_list_tx_history_remove(&h->packets, pkt); in tx_pkt_history_remove()
163 lh_OSSL_ACKM_TX_PKT_delete(h->map, &key); in tx_pkt_history_remove()
171 * **Background.** The RX side of the ACK manager must track packets we have
172 * received for which we have to generate ACK frames. Broadly, this means we
178 * 1. We receive a packet but have not sent an ACK yet, so the transmitter
181 * 2. We receive a packet and send an ACK which is lost. We do not
182 * immediately know that the ACK was lost and the transmitter does not know
185 * 3. We receive a packet and send an ACK which is received by the
186 * transmitter. The transmitter does not immediately respond with an ACK,
187 * or responds with an ACK which is lost. The transmitter knows that we
189 * because the ACK we sent could have been lost.
191 * 4. We receive a packet and send an ACK which is received by the
192 * transmitter. The transmitter subsequently sends us an ACK which confirms
193 * its receipt of the ACK we sent, and we successfully receive that ACK, so
200 * will never again need to generate an ACK containing the PN in question, but
219 * - We have never processed this PN before
222 * - We have processed this PN but it has not yet been provably ACKed
223 * (and should therefore be in any future ACK frame generated;
226 * - We have processed this PN and it has been provably ACKed
243 * "A receiver MUST retain an ACK Range unless it can ensure that it will not
264 * - (A) The PN is above the watermark but we have not yet received it.
269 * - (B) The PN is above the watermark and we have received it.
271 * The PN should be included in any future ACK frame we generate.
274 * - (C) The PN is below the watermark.
284 * for the PNs in this state is because the provably ACKed and never-received
293 * keep reporting it in future ACK frames).
298 * "When a packet containing an ACK frame is sent, the Largest Acknowledged
299 * field in that frame can be saved. When a packet containing an ACK frame is
300 * acknowledged, the receiver can stop acknowledging packets less than or
301 * equal to the Largest Acknowledged field in the sent ACK frame."
304 * ACK frame is itself ACK'd, PNs referenced in that ACK frame become provably
308 * and previous ACK frames. Thus, some unreceived PNs may be moved below the
313 * purposes of duplicate detection) when a higher-numbered PN becomes provably
319 * subsequently generated ACK frame is sent in a future TX packet, and then we
327 * **Data structure.** Our state for the RX handling side of the ACK manager, as
335 * been provably ACKed, and thus will later need to generate an ACK frame for.
347 * - State (A) can transition to state (B) or (C)
348 * - State (B) can transition to state (C) only
349 * - State (C) is the terminal state
352 * but which have not been provably ACKed when we want to generate ACK frames.
353 * Since ACK frames can be lost and/or we might not know that the peer has
354 * successfully received them, we might generate multiple ACK frames covering a
376 * provably ACKed. This occurs when an ACK frame is received by the TX side of
377 * the ACK manager; thus, there is necessary interaction between the TX and RX
378 * sides of the ACK manager.
381 * side of the ACK manager, it may optionally have a Largest Acked value set on
382 * it. The user of the ACK manager should do this if the packet being
383 * transmitted contains an ACK frame, by setting the field to the Largest Acked
386 * used to update the state of the RX side of the ACK manager by bumping the
404 ossl_uint_set_init(&h->set); in rx_pkt_history_init()
405 h->watermark = 0; in rx_pkt_history_init()
410 ossl_uint_set_destroy(&h->set); in rx_pkt_history_destroy()
414 * Limit the number of ACK ranges we store to prevent resource consumption DoS
423 while (ossl_list_uint_set_num(&h->set) > MAX_RX_ACK_RANGES) { in rx_pkt_history_trim_range_count()
424 UINT_RANGE r = ossl_list_uint_set_head(&h->set)->range; in rx_pkt_history_trim_range_count()
429 ossl_uint_set_remove(&h->set, &r); in rx_pkt_history_trim_range_count()
448 if (pn < h->watermark) in rx_pkt_history_add_pn()
451 if (ossl_uint_set_insert(&h->set, &r) != 1) in rx_pkt_history_add_pn()
463 if (watermark <= h->watermark) in rx_pkt_history_bump_watermark()
468 r.end = watermark - 1; in rx_pkt_history_bump_watermark()
469 if (ossl_uint_set_remove(&h->set, &r) != 1) in rx_pkt_history_bump_watermark()
472 h->watermark = watermark; in rx_pkt_history_bump_watermark()
477 * ACK Manager Implementation
479 * Implementation of the ACK manager proper.
482 /* Constants used by the ACK manager; see RFC 9002. */
491 /* Default maximum amount of time to leave an ACK-eliciting packet un-ACK'd. */
523 * and removed again once ack'd/lost/discarded.
529 * ack-eliciting, and removed again once ack'd/lost/discarded.
533 /* Count of ECN-CE events. */
548 /* Set to 1 when we think an ACK frame should be generated. */
551 /* Set to 1 if an ACK frame has ever been generated. */
557 /* Generated ACK frames for each PN space. */
558 OSSL_QUIC_FRAME_ACK ack[QUIC_PN_SPACE_NUM]; member
577 * Number of ACK-eliciting packets since last ACK. We use this to defer
578 * emitting ACK frames until a threshold number of ACK-eliciting packets
584 * The ACK frame coalescing deadline at which we should flush any unsent ACK
590 * The RX maximum ACK delay (the maximum amount of time our peer might
591 * wait to send us an ACK after receiving an ACK-eliciting packet).
596 * The TX maximum ACK delay (the maximum amount of time we allow ourselves
597 * to wait before generating an ACK after receiving an ACK-eliciting
621 assert(!ackm->discarded[pkt_space]); in get_tx_history()
623 return &ackm->tx_history[pkt_space]; in get_tx_history()
632 assert(!ackm->discarded[pkt_space]); in get_rx_history()
634 return &ackm->rx_history[pkt_space]; in get_rx_history()
637 /* Does the newly-acknowledged list contain any ack-eliciting packet? */
640 for (; pkt != NULL; pkt = pkt->anext) in ack_includes_ack_eliciting()
641 if (pkt->is_ack_eliciting) in ack_includes_ack_eliciting()
647 /* Return number of ACK-eliciting bytes in flight across all PN spaces. */
654 total += ackm->ack_eliciting_bytes_in_flight[i]; in ackm_ack_eliciting_bytes_in_flight()
662 return pn >= range->start && pn <= range->end; in range_contains()
666 * Given a logical representation of an ACK frame 'ack', create a singly-linked
667 * list of the newly ACK'd frames; that is, of frames which are matched by the
668 * list of PN ranges contained in the ACK frame. The packet structures in the
673 const OSSL_QUIC_FRAME_ACK *ack, in ackm_detect_and_remove_newly_acked_pkts() argument
680 assert(ack->num_ack_ranges > 0); in ackm_detect_and_remove_newly_acked_pkts()
686 * ack->ack_ranges is a list of packet number ranges in descending order. in ackm_detect_and_remove_newly_acked_pkts()
689 * membership in the specified ack ranges. As an optimization, we use our in ackm_detect_and_remove_newly_acked_pkts()
691 * the ACK ranges given include nonexistent packets. in ackm_detect_and_remove_newly_acked_pkts()
695 pkt = tx_pkt_history_by_pkt_num(h, ack->ack_ranges[0].end); in ackm_detect_and_remove_newly_acked_pkts()
697 pkt = ossl_list_tx_history_tail(&h->packets); in ackm_detect_and_remove_newly_acked_pkts()
707 if (ridx >= ack->num_ack_ranges) { in ackm_detect_and_remove_newly_acked_pkts()
709 * We have exhausted all ranges so stop here, even if there are in ackm_detect_and_remove_newly_acked_pkts()
712 goto stop; in ackm_detect_and_remove_newly_acked_pkts()
715 if (range_contains(&ack->ack_ranges[ridx], pkt->pkt_num)) { in ackm_detect_and_remove_newly_acked_pkts()
717 tx_pkt_history_remove(h, pkt->pkt_num); in ackm_detect_and_remove_newly_acked_pkts()
720 fixup = &pkt->anext; in ackm_detect_and_remove_newly_acked_pkts()
723 } else if (pkt->pkt_num > ack->ack_ranges[ridx].end) { in ackm_detect_and_remove_newly_acked_pkts()
734 assert(pkt->pkt_num < ack->ack_ranges[ridx].start); in ackm_detect_and_remove_newly_acked_pkts()
739 stop: in ackm_detect_and_remove_newly_acked_pkts()
745 * Create a singly-linked list of newly detected-lost packets in the given
757 assert(ackm->largest_acked_pkt[pkt_space] != QUIC_PN_INVALID); in ackm_detect_and_remove_lost_pkts()
759 ossl_statm_get_rtt_info(ackm->statm, &rtt); in ackm_detect_and_remove_lost_pkts()
761 ackm->loss_time[pkt_space] = ossl_time_zero(); in ackm_detect_and_remove_lost_pkts()
772 now = ackm->now(ackm->now_arg); in ackm_detect_and_remove_lost_pkts()
776 pkt = ossl_list_tx_history_head(&h->packets); in ackm_detect_and_remove_lost_pkts()
779 assert(pkt_space == pkt->pkt_space); in ackm_detect_and_remove_lost_pkts()
787 if (pkt->pkt_num > ackm->largest_acked_pkt[pkt_space]) in ackm_detect_and_remove_lost_pkts()
793 if (ossl_time_compare(pkt->time, lost_send_time) <= 0 in ackm_detect_and_remove_lost_pkts()
794 || ackm->largest_acked_pkt[pkt_space] in ackm_detect_and_remove_lost_pkts()
795 >= pkt->pkt_num + K_PKT_THRESHOLD) { in ackm_detect_and_remove_lost_pkts()
796 tx_pkt_history_remove(h, pkt->pkt_num); in ackm_detect_and_remove_lost_pkts()
799 fixup = &pkt->lnext; in ackm_detect_and_remove_lost_pkts()
802 if (ossl_time_is_zero(ackm->loss_time[pkt_space])) in ackm_detect_and_remove_lost_pkts()
803 ackm->loss_time[pkt_space] = in ackm_detect_and_remove_lost_pkts()
804 ossl_time_add(pkt->time, loss_delay); in ackm_detect_and_remove_lost_pkts()
806 ackm->loss_time[pkt_space] = in ackm_detect_and_remove_lost_pkts()
807 ossl_time_min(ackm->loss_time[pkt_space], in ackm_detect_and_remove_lost_pkts()
808 ossl_time_add(pkt->time, loss_delay)); in ackm_detect_and_remove_lost_pkts()
817 OSSL_TIME time = ackm->loss_time[QUIC_PN_SPACE_INITIAL]; in ackm_get_loss_time_and_space()
822 || ossl_time_compare(ackm->loss_time[i], time) == -1) { in ackm_get_loss_time_and_space()
823 time = ackm->loss_time[i]; in ackm_get_loss_time_and_space()
838 ossl_statm_get_rtt_info(ackm->statm, &rtt); in ackm_get_pto_time_and_space()
847 (uint64_t)1 << min_u32(ackm->pto_count, in ackm_get_pto_time_and_space()
850 /* Anti-deadlock PTO starts from the current time. */ in ackm_get_pto_time_and_space()
852 assert(!ackm->peer_completed_addr_validation); in ackm_get_pto_time_and_space()
854 *space = ackm->discarded[QUIC_PN_SPACE_INITIAL] in ackm_get_pto_time_and_space()
857 return ossl_time_add(ackm->now(ackm->now_arg), duration); in ackm_get_pto_time_and_space()
866 if (ackm->ack_eliciting_bytes_in_flight[i] == 0 && in ackm_get_pto_time_and_space()
867 (ackm->handshake_confirmed == 1 || ackm->is_server == 1)) in ackm_get_pto_time_and_space()
872 if (!ackm->handshake_confirmed) in ackm_get_pto_time_and_space()
876 if (!ossl_time_is_infinite(ackm->rx_max_ack_delay)) { in ackm_get_pto_time_and_space()
878 = (uint64_t)1 << min_u32(ackm->pto_count, MAX_PTO_COUNT); in ackm_get_pto_time_and_space()
882 ossl_time_multiply(ackm->rx_max_ack_delay, in ackm_get_pto_time_and_space()
888 * Only re-arm timer if stack has sent at least one ACK eliciting frame. in ackm_get_pto_time_and_space()
889 * If stack has sent no ACK eliciting frame at given encryption level then in ackm_get_pto_time_and_space()
893 if (!ossl_time_is_zero(ackm->time_of_last_ack_eliciting_pkt[i])) { in ackm_get_pto_time_and_space()
894 t = ossl_time_add(ackm->time_of_last_ack_eliciting_pkt[i], duration); in ackm_get_pto_time_and_space()
909 ackm->loss_detection_deadline = deadline; in ackm_set_loss_detection_timer_actual()
911 if (ackm->loss_detection_deadline_cb != NULL) in ackm_set_loss_detection_timer_actual()
912 ackm->loss_detection_deadline_cb(deadline, in ackm_set_loss_detection_timer_actual()
913 ackm->loss_detection_deadline_cb_arg); in ackm_set_loss_detection_timer_actual()
929 && ackm->peer_completed_addr_validation) { in ackm_set_loss_detection_timer()
933 * anti-amplification limit. in ackm_set_loss_detection_timer()
961 pnext = p->lnext; in ackm_on_pkts_lost()
963 if (p->is_inflight) { in ackm_on_pkts_lost()
964 ackm->bytes_in_flight -= p->num_bytes; in ackm_on_pkts_lost()
965 if (p->is_ack_eliciting) in ackm_on_pkts_lost()
966 ackm->ack_eliciting_bytes_in_flight[p->pkt_space] in ackm_on_pkts_lost()
967 -= p->num_bytes; in ackm_on_pkts_lost()
969 if (p->pkt_num > largest_pn_lost) in ackm_on_pkts_lost()
970 largest_pn_lost = p->pkt_num; in ackm_on_pkts_lost()
974 * If this is pseudo-loss (e.g. during connection retry) we do not in ackm_on_pkts_lost()
978 loss_info.tx_time = p->time; in ackm_on_pkts_lost()
979 loss_info.tx_size = p->num_bytes; in ackm_on_pkts_lost()
981 ackm->cc_method->on_data_lost(ackm->cc_data, &loss_info); in ackm_on_pkts_lost()
985 p->on_lost(p->cb_arg); in ackm_on_pkts_lost()
992 ossl_statm_get_rtt_info(ackm->statm, &rtt); in ackm_on_pkts_lost()
993 if (!ossl_time_is_zero(ackm->first_rtt_sample) in ackm_on_pkts_lost()
997 ackm->cc_method->on_data_lost_finished(ackm->cc_data, flags); in ackm_on_pkts_lost()
1007 if (apkt->is_inflight) { in ackm_on_pkts_acked()
1008 ackm->bytes_in_flight -= apkt->num_bytes; in ackm_on_pkts_acked()
1009 if (apkt->is_ack_eliciting) in ackm_on_pkts_acked()
1010 ackm->ack_eliciting_bytes_in_flight[apkt->pkt_space] in ackm_on_pkts_acked()
1011 -= apkt->num_bytes; in ackm_on_pkts_acked()
1013 if (apkt->pkt_num > last_pn_acked) in ackm_on_pkts_acked()
1014 last_pn_acked = apkt->pkt_num; in ackm_on_pkts_acked()
1016 if (apkt->largest_acked != QUIC_PN_INVALID) in ackm_on_pkts_acked()
1022 apkt->pkt_space), in ackm_on_pkts_acked()
1023 apkt->largest_acked + 1); in ackm_on_pkts_acked()
1026 ainfo.tx_time = apkt->time; in ackm_on_pkts_acked()
1027 ainfo.tx_size = apkt->num_bytes; in ackm_on_pkts_acked()
1029 anext = apkt->anext; in ackm_on_pkts_acked()
1030 apkt->on_acked(apkt->cb_arg); /* may free apkt */ in ackm_on_pkts_acked()
1032 if (apkt->is_inflight) in ackm_on_pkts_acked()
1033 ackm->cc_method->on_data_acked(ackm->cc_data, &ainfo); in ackm_on_pkts_acked()
1051 for (i = 0; i < (int)OSSL_NELEM(ackm->tx_history); ++i) { in ossl_ackm_new()
1052 ackm->largest_acked_pkt[i] = QUIC_PN_INVALID; in ossl_ackm_new()
1053 ackm->rx_ack_flush_deadline[i] = ossl_time_infinite(); in ossl_ackm_new()
1054 if (tx_pkt_history_init(&ackm->tx_history[i]) < 1) in ossl_ackm_new()
1058 for (i = 0; i < (int)OSSL_NELEM(ackm->rx_history); ++i) in ossl_ackm_new()
1059 rx_pkt_history_init(&ackm->rx_history[i]); in ossl_ackm_new()
1061 ackm->now = now; in ossl_ackm_new()
1062 ackm->now_arg = now_arg; in ossl_ackm_new()
1063 ackm->statm = statm; in ossl_ackm_new()
1064 ackm->cc_method = cc_method; in ossl_ackm_new()
1065 ackm->cc_data = cc_data; in ossl_ackm_new()
1066 ackm->is_server = (char)is_server; in ossl_ackm_new()
1068 ackm->rx_max_ack_delay = ossl_ms2time(QUIC_DEFAULT_MAX_ACK_DELAY); in ossl_ackm_new()
1069 ackm->tx_max_ack_delay = DEFAULT_TX_MAX_ACK_DELAY; in ossl_ackm_new()
1074 while (--i >= 0) in ossl_ackm_new()
1075 tx_pkt_history_destroy(&ackm->tx_history[i]); in ossl_ackm_new()
1088 for (i = 0; i < OSSL_NELEM(ackm->tx_history); ++i) in ossl_ackm_free()
1089 if (!ackm->discarded[i]) { in ossl_ackm_free()
1090 tx_pkt_history_destroy(&ackm->tx_history[i]); in ossl_ackm_free()
1091 rx_pkt_history_destroy(&ackm->rx_history[i]); in ossl_ackm_free()
1099 struct tx_pkt_history_st *h = get_tx_history(ackm, pkt->pkt_space); in ossl_ackm_on_tx_packet()
1102 if (ossl_time_is_zero(pkt->time) in ossl_ackm_on_tx_packet()
1103 || ossl_time_compare(ackm->time_of_last_ack_eliciting_pkt[pkt->pkt_space], in ossl_ackm_on_tx_packet()
1104 pkt->time) > 0) in ossl_ackm_on_tx_packet()
1107 /* Must have non-zero number of bytes. */ in ossl_ackm_on_tx_packet()
1108 if (pkt->num_bytes == 0) in ossl_ackm_on_tx_packet()
1111 /* Does not make any sense for a non-in-flight packet to be ACK-eliciting. */ in ossl_ackm_on_tx_packet()
1112 if (!pkt->is_inflight && pkt->is_ack_eliciting) in ossl_ackm_on_tx_packet()
1118 if (pkt->is_inflight) { in ossl_ackm_on_tx_packet()
1119 if (pkt->is_ack_eliciting) { in ossl_ackm_on_tx_packet()
1120 ackm->time_of_last_ack_eliciting_pkt[pkt->pkt_space] = pkt->time; in ossl_ackm_on_tx_packet()
1121 ackm->ack_eliciting_bytes_in_flight[pkt->pkt_space] in ossl_ackm_on_tx_packet()
1122 += pkt->num_bytes; in ossl_ackm_on_tx_packet()
1125 ackm->bytes_in_flight += pkt->num_bytes; in ossl_ackm_on_tx_packet()
1128 ackm->cc_method->on_data_sent(ackm->cc_data, pkt->num_bytes); in ossl_ackm_on_tx_packet()
1136 /* No-op on the client. */ in ossl_ackm_on_rx_datagram()
1140 static void ackm_process_ecn(OSSL_ACKM *ackm, const OSSL_QUIC_FRAME_ACK *ack, in ackm_process_ecn() argument
1148 * If the ECN-CE counter reported by the peer has increased, this could in ackm_process_ecn()
1151 if (ack->ecnce > ackm->peer_ecnce[pkt_space]) { in ackm_process_ecn()
1152 ackm->peer_ecnce[pkt_space] = ack->ecnce; in ackm_process_ecn()
1155 pkt = tx_pkt_history_by_pkt_num(h, ack->ack_ranges[0].end); in ackm_process_ecn()
1159 ecn_info.largest_acked_time = pkt->time; in ackm_process_ecn()
1160 ackm->cc_method->on_ecn(ackm->cc_data, &ecn_info); in ackm_process_ecn()
1164 int ossl_ackm_on_rx_ack_frame(OSSL_ACKM *ackm, const OSSL_QUIC_FRAME_ACK *ack, in ossl_ackm_on_rx_ack_frame() argument
1170 if (ackm->largest_acked_pkt[pkt_space] == QUIC_PN_INVALID) in ossl_ackm_on_rx_ack_frame()
1171 ackm->largest_acked_pkt[pkt_space] = ack->ack_ranges[0].end; in ossl_ackm_on_rx_ack_frame()
1173 ackm->largest_acked_pkt[pkt_space] in ossl_ackm_on_rx_ack_frame()
1174 = ossl_quic_pn_max(ackm->largest_acked_pkt[pkt_space], in ossl_ackm_on_rx_ack_frame()
1175 ack->ack_ranges[0].end); in ossl_ackm_on_rx_ack_frame()
1178 * If we get an ACK in the handshake space, address validation is completed. in ossl_ackm_on_rx_ack_frame()
1179 * Make sure we update the timer, even if no packets were ACK'd. in ossl_ackm_on_rx_ack_frame()
1181 if (!ackm->peer_completed_addr_validation in ossl_ackm_on_rx_ack_frame()
1183 ackm->peer_completed_addr_validation = 1; in ossl_ackm_on_rx_ack_frame()
1190 na_pkts = ackm_detect_and_remove_newly_acked_pkts(ackm, ack, pkt_space); in ossl_ackm_on_rx_ack_frame()
1200 * one ACK-eliciting packet was newly acked. in ossl_ackm_on_rx_ack_frame()
1204 if (na_pkts->pkt_num == ack->ack_ranges[0].end && in ossl_ackm_on_rx_ack_frame()
1206 OSSL_TIME now = ackm->now(ackm->now_arg), ack_delay; in ossl_ackm_on_rx_ack_frame()
1207 if (ossl_time_is_zero(ackm->first_rtt_sample)) in ossl_ackm_on_rx_ack_frame()
1208 ackm->first_rtt_sample = now; in ossl_ackm_on_rx_ack_frame()
1210 /* Enforce maximum ACK delay. */ in ossl_ackm_on_rx_ack_frame()
1211 ack_delay = ack->delay_time; in ossl_ackm_on_rx_ack_frame()
1212 if (ackm->handshake_confirmed) in ossl_ackm_on_rx_ack_frame()
1213 ack_delay = ossl_time_min(ack_delay, ackm->rx_max_ack_delay); in ossl_ackm_on_rx_ack_frame()
1215 ossl_statm_update_rtt(ackm->statm, ack_delay, in ossl_ackm_on_rx_ack_frame()
1216 ossl_time_subtract(now, na_pkts->time)); in ossl_ackm_on_rx_ack_frame()
1226 if (ack->ecn_present) in ossl_ackm_on_rx_ack_frame()
1227 ackm_process_ecn(ackm, ack, pkt_space); in ossl_ackm_on_rx_ack_frame()
1240 if (ackm->peer_completed_addr_validation) in ossl_ackm_on_rx_ack_frame()
1241 ackm->pto_count = 0; in ossl_ackm_on_rx_ack_frame()
1252 if (ackm->discarded[pkt_space]) in ossl_ackm_on_pkt_space_discarded()
1256 ackm->peer_completed_addr_validation = 1; in ossl_ackm_on_pkt_space_discarded()
1258 for (pkt = ossl_list_tx_history_head(&get_tx_history(ackm, pkt_space)->packets); in ossl_ackm_on_pkt_space_discarded()
1261 if (pkt->is_inflight) { in ossl_ackm_on_pkt_space_discarded()
1262 ackm->bytes_in_flight -= pkt->num_bytes; in ossl_ackm_on_pkt_space_discarded()
1263 num_bytes_invalidated += pkt->num_bytes; in ossl_ackm_on_pkt_space_discarded()
1266 pkt->on_discarded(pkt->cb_arg); /* may free pkt */ in ossl_ackm_on_pkt_space_discarded()
1269 tx_pkt_history_destroy(&ackm->tx_history[pkt_space]); in ossl_ackm_on_pkt_space_discarded()
1270 rx_pkt_history_destroy(&ackm->rx_history[pkt_space]); in ossl_ackm_on_pkt_space_discarded()
1273 ackm->cc_method->on_data_invalidated(ackm->cc_data, in ossl_ackm_on_pkt_space_discarded()
1276 ackm->time_of_last_ack_eliciting_pkt[pkt_space] = ossl_time_zero(); in ossl_ackm_on_pkt_space_discarded()
1277 ackm->loss_time[pkt_space] = ossl_time_zero(); in ossl_ackm_on_pkt_space_discarded()
1278 ackm->pto_count = 0; in ossl_ackm_on_pkt_space_discarded()
1279 ackm->discarded[pkt_space] = 1; in ossl_ackm_on_pkt_space_discarded()
1280 ackm->ack_eliciting_bytes_in_flight[pkt_space] = 0; in ossl_ackm_on_pkt_space_discarded()
1287 ackm->handshake_confirmed = 1; in ossl_ackm_on_handshake_confirmed()
1288 ackm->peer_completed_addr_validation = 1; in ossl_ackm_on_handshake_confirmed()
1295 ++ackm->pending_probe.anti_deadlock_handshake; in ackm_queue_probe_anti_deadlock_handshake()
1300 ++ackm->pending_probe.anti_deadlock_initial; in ackm_queue_probe_anti_deadlock_initial()
1310 ++ackm->pending_probe.pto[pkt_space]; in ackm_queue_probe()
1330 assert(!ackm->peer_completed_addr_validation); in ossl_ackm_on_timeout()
1332 * Client sends an anti-deadlock packet: Initial is padded to earn more in ossl_ackm_on_timeout()
1333 * anti-amplification credit. A handshake packet proves address in ossl_ackm_on_timeout()
1336 if (ackm->discarded[QUIC_PN_SPACE_INITIAL]) in ossl_ackm_on_timeout()
1350 ++ackm->pto_count; in ossl_ackm_on_timeout()
1357 return ackm->loss_detection_deadline; in ossl_ackm_get_loss_detection_deadline()
1362 return &ackm->pending_probe; in ossl_ackm_get0_probe_request()
1371 p = ossl_list_tx_history_tail(&h->packets); in ossl_ackm_get_largest_unacked()
1373 *pn = p->pkt_num; in ossl_ackm_get_largest_unacked()
1380 /* Number of ACK-eliciting packets RX'd before we always emit an ACK. */
1384 * Return 1 if emission of an ACK frame is currently desired.
1388 * - We have flagged that we want to send an ACK frame
1391 * - We have exceeded the ACK flush deadline, meaning that
1392 * we have received at least one ACK-eliciting packet, but held off on
1393 * sending an ACK frame immediately in the hope that more ACK-eliciting
1395 * transmission of an ACK frame anyway.
1400 return ackm->rx_ack_desired[pkt_space] in ossl_ackm_is_ack_desired()
1401 || (!ossl_time_is_infinite(ackm->rx_ack_flush_deadline[pkt_space]) in ossl_ackm_is_ack_desired()
1402 && ossl_time_compare(ackm->now(ackm->now_arg), in ossl_ackm_is_ack_desired()
1403 ackm->rx_ack_flush_deadline[pkt_space]) >= 0); in ossl_ackm_is_ack_desired()
1407 * Returns 1 if an ACK frame matches a given packet number.
1409 static int ack_contains(const OSSL_QUIC_FRAME_ACK *ack, QUIC_PN pkt_num) in ack_contains() argument
1413 for (i = 0; i < ack->num_ack_ranges; ++i) in ack_contains()
1414 if (range_contains(&ack->ack_ranges[i], pkt_num)) in ack_contains()
1422 * implied missing (by us, in an ACK frame we previously generated).
1428 * generated ACK frame, but is not matched by the frame. in ackm_is_missing()
1430 return ackm->ack[pkt_space].num_ack_ranges > 0 in ackm_is_missing()
1431 && pkt_num <= ackm->ack[pkt_space].ack_ranges[0].end in ackm_is_missing()
1432 && !ack_contains(&ackm->ack[pkt_space], pkt_num); in ackm_is_missing()
1445 if (ossl_list_uint_set_is_empty(&h->set)) in ackm_has_newly_missing()
1457 * reported in any ACK frame. Thus there is a gap of at least one PN between in ackm_has_newly_missing()
1458 * the PNs we have ACK'd previously and the PN we have just received. in ackm_has_newly_missing()
1460 return ackm->ack[pkt_space].num_ack_ranges > 0 in ackm_has_newly_missing()
1461 && ossl_list_uint_set_tail(&h->set)->range.start in ackm_has_newly_missing()
1462 == ossl_list_uint_set_tail(&h->set)->range.end in ackm_has_newly_missing()
1463 && ossl_list_uint_set_tail(&h->set)->range.start in ackm_has_newly_missing()
1464 > ackm->ack[pkt_space].ack_ranges[0].end + 1; in ackm_has_newly_missing()
1470 ackm->rx_ack_flush_deadline[pkt_space] = deadline; in ackm_set_flush_deadline()
1472 if (ackm->ack_deadline_cb != NULL) in ackm_set_flush_deadline()
1473 ackm->ack_deadline_cb(ossl_ackm_get_ack_deadline(ackm, pkt_space), in ackm_set_flush_deadline()
1474 pkt_space, ackm->ack_deadline_cb_arg); in ackm_set_flush_deadline()
1477 /* Explicitly flags that we want to generate an ACK frame. */
1480 ackm->rx_ack_desired[pkt_space] = 1; in ackm_queue_ack()
1492 if (ackm->rx_ack_desired[pkt_space]) in ackm_on_rx_ack_eliciting()
1493 /* ACK generation already requested so nothing to do. */ in ackm_on_rx_ack_eliciting()
1496 ++ackm->rx_ack_eliciting_pkts_since_last_ack[pkt_space]; in ackm_on_rx_ack_eliciting()
1498 if (!ackm->rx_ack_generated[pkt_space] in ackm_on_rx_ack_eliciting()
1500 || ackm->rx_ack_eliciting_pkts_since_last_ack[pkt_space] in ackm_on_rx_ack_eliciting()
1506 * - We have never yet generated an ACK frame, meaning that this in ackm_on_rx_ack_eliciting()
1510 * - We previously reported the PN that we have just received as in ackm_on_rx_ack_eliciting()
1511 * missing in a previous ACK frame (meaning that we should report in ackm_on_rx_ack_eliciting()
1514 * - We have exceeded the ACK-eliciting packet threshold count in ackm_on_rx_ack_eliciting()
1515 * for the purposes of ACK coalescing, so request transmission in ackm_on_rx_ack_eliciting()
1516 * of an ACK frame, or in ackm_on_rx_ack_eliciting()
1518 * - The PN we just received and added to our PN RX history in ackm_on_rx_ack_eliciting()
1520 * inform the peer by sending an ACK frame immediately. in ackm_on_rx_ack_eliciting()
1522 * We do not test the ACK flush deadline here because it is tested in ackm_on_rx_ack_eliciting()
1530 * Not emitting an ACK yet. in ackm_on_rx_ack_eliciting()
1532 * Update the ACK flush deadline. in ackm_on_rx_ack_eliciting()
1534 * RFC 9000 s. 13.2.1: "An endpoint MUST acknowledge all ack-eliciting in ackm_on_rx_ack_eliciting()
1535 * Initial and Handshake packets immediately"; don't delay ACK generation if in ackm_on_rx_ack_eliciting()
1538 tx_max_ack_delay = ackm->tx_max_ack_delay; in ackm_on_rx_ack_eliciting()
1543 if (ossl_time_is_infinite(ackm->rx_ack_flush_deadline[pkt_space])) in ackm_on_rx_ack_eliciting()
1548 ossl_time_min(ackm->rx_ack_flush_deadline[pkt_space], in ackm_on_rx_ack_eliciting()
1555 struct rx_pkt_history_st *h = get_rx_history(ackm, pkt->pkt_space); in ossl_ackm_on_rx_packet()
1558 if (ossl_ackm_is_rx_pn_processable(ackm, pkt->pkt_num, pkt->pkt_space) != 1) in ossl_ackm_on_rx_packet()
1559 /* PN has already been processed or written off, no-op. */ in ossl_ackm_on_rx_packet()
1564 * We use this to calculate the ACK delay field of ACK frames. in ossl_ackm_on_rx_packet()
1566 if (pkt->pkt_num > ackm->rx_largest_pn[pkt->pkt_space]) { in ossl_ackm_on_rx_packet()
1567 ackm->rx_largest_pn[pkt->pkt_space] = pkt->pkt_num; in ossl_ackm_on_rx_packet()
1568 ackm->rx_largest_time[pkt->pkt_space] = pkt->time; in ossl_ackm_on_rx_packet()
1573 * being omitted from a previous ACK frame generated, we skip any packet in ossl_ackm_on_rx_packet()
1574 * count thresholds or coalescing delays and emit a new ACK frame in ossl_ackm_on_rx_packet()
1577 was_missing = ackm_is_missing(ackm, pkt->pkt_space, pkt->pkt_num); in ossl_ackm_on_rx_packet()
1583 if (rx_pkt_history_add_pn(h, pkt->pkt_num) != 1) in ossl_ackm_on_rx_packet()
1587 * Receiving this packet may or may not cause us to emit an ACK frame. in ossl_ackm_on_rx_packet()
1588 * We may not emit an ACK frame yet if we have not yet received a threshold in ossl_ackm_on_rx_packet()
1591 if (pkt->is_ack_eliciting) in ossl_ackm_on_rx_packet()
1592 ackm_on_rx_ack_eliciting(ackm, pkt->time, pkt->pkt_space, was_missing); in ossl_ackm_on_rx_packet()
1595 switch (pkt->ecn) { in ossl_ackm_on_rx_packet()
1597 ++ackm->rx_ect0[pkt->pkt_space]; in ossl_ackm_on_rx_packet()
1600 ++ackm->rx_ect1[pkt->pkt_space]; in ossl_ackm_on_rx_packet()
1603 ++ackm->rx_ecnce[pkt->pkt_space]; in ossl_ackm_on_rx_packet()
1613 OSSL_QUIC_FRAME_ACK *ack) in ackm_fill_rx_ack_ranges() argument
1623 for (x = ossl_list_uint_set_tail(&h->set); in ackm_fill_rx_ack_ranges()
1624 x != NULL && i < OSSL_NELEM(ackm->ack_ranges); in ackm_fill_rx_ack_ranges()
1626 ackm->ack_ranges[pkt_space][i].start = x->range.start; in ackm_fill_rx_ack_ranges()
1627 ackm->ack_ranges[pkt_space][i].end = x->range.end; in ackm_fill_rx_ack_ranges()
1630 ack->ack_ranges = ackm->ack_ranges[pkt_space]; in ackm_fill_rx_ack_ranges()
1631 ack->num_ack_ranges = i; in ackm_fill_rx_ack_ranges()
1637 OSSL_QUIC_FRAME_ACK *ack = &ackm->ack[pkt_space]; in ossl_ackm_get_ack_frame() local
1638 OSSL_TIME now = ackm->now(ackm->now_arg); in ossl_ackm_get_ack_frame()
1640 ackm_fill_rx_ack_ranges(ackm, pkt_space, ack); in ossl_ackm_get_ack_frame()
1642 if (!ossl_time_is_zero(ackm->rx_largest_time[pkt_space]) in ossl_ackm_get_ack_frame()
1643 && ossl_time_compare(now, ackm->rx_largest_time[pkt_space]) > 0 in ossl_ackm_get_ack_frame()
1645 ack->delay_time = in ossl_ackm_get_ack_frame()
1646 ossl_time_subtract(now, ackm->rx_largest_time[pkt_space]); in ossl_ackm_get_ack_frame()
1648 ack->delay_time = ossl_time_zero(); in ossl_ackm_get_ack_frame()
1650 ack->ect0 = ackm->rx_ect0[pkt_space]; in ossl_ackm_get_ack_frame()
1651 ack->ect1 = ackm->rx_ect1[pkt_space]; in ossl_ackm_get_ack_frame()
1652 ack->ecnce = ackm->rx_ecnce[pkt_space]; in ossl_ackm_get_ack_frame()
1653 ack->ecn_present = 1; in ossl_ackm_get_ack_frame()
1655 ackm->rx_ack_eliciting_pkts_since_last_ack[pkt_space] = 0; in ossl_ackm_get_ack_frame()
1657 ackm->rx_ack_generated[pkt_space] = 1; in ossl_ackm_get_ack_frame()
1658 ackm->rx_ack_desired[pkt_space] = 0; in ossl_ackm_get_ack_frame()
1660 return ack; in ossl_ackm_get_ack_frame()
1666 if (ackm->rx_ack_desired[pkt_space]) in ossl_ackm_get_ack_deadline()
1670 return ackm->rx_ack_flush_deadline[pkt_space]; in ossl_ackm_get_ack_deadline()
1677 return pn >= h->watermark && ossl_uint_set_query(&h->set, pn) == 0; in ossl_ackm_is_rx_pn_processable()
1685 ackm->loss_detection_deadline_cb = fn; in ossl_ackm_set_loss_detection_deadline_callback()
1686 ackm->loss_detection_deadline_cb_arg = arg; in ossl_ackm_set_loss_detection_deadline_callback()
1695 ackm->ack_deadline_cb = fn; in ossl_ackm_set_ack_deadline_callback()
1696 ackm->ack_deadline_cb_arg = arg; in ossl_ackm_set_ack_deadline_callback()
1709 tx_pkt_history_remove(h, pkt->pkt_num); in ossl_ackm_mark_packet_pseudo_lost()
1710 pkt->lnext = NULL; in ossl_ackm_mark_packet_pseudo_lost()
1720 ossl_statm_get_rtt_info(ackm->statm, &rtt); in ossl_ackm_get_pto_duration()
1725 if (!ossl_time_is_infinite(ackm->rx_max_ack_delay)) in ossl_ackm_get_pto_duration()
1726 duration = ossl_time_add(duration, ackm->rx_max_ack_delay); in ossl_ackm_get_pto_duration()
1733 return ackm->largest_acked_pkt[pkt_space]; in ossl_ackm_get_largest_acked()
1738 ackm->rx_max_ack_delay = rx_max_ack_delay; in ossl_ackm_set_rx_max_ack_delay()
1743 ackm->tx_max_ack_delay = tx_max_ack_delay; in ossl_ackm_set_tx_max_ack_delay()