Lines Matching +full:frame +full:- +full:number
2 * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
23 * database keeping a list of packet information structures in packet number
24 * order which can also be looked up directly by packet number.
44 * The lowest packet number which may currently be added to the history list
46 * list non-monotonically, so packet numbers must be greater than or equal
52 * Packet number of the highest packet info structure we have yet appended
63 /* Using low bits of the packet number as the hash should be enough */ in tx_pkt_info_hash()
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()
106 * There should not be any existing packet with this number in tx_pkt_history_add_actual()
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()
140 /* Retrieve a packet information structure by packet number. */
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()
168 * RX Packet Number Tracking
198 * packet number we have received, because only in this case do we know for sure
213 * that it has not processed another packet with the same packet number from
214 * the same packet number space."
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
239 * number below which all packets are immediately dropped."
245 * minimum packet number that increases as ranges are discarded is one way to
260 * only a small number of recent PNs, and all older PNs have an assumed state.
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
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
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
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
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
376 * provably ACKed. This occurs when an ACK frame is received by the TX side of
383 * transmitted contains an ACK frame, by setting the field to the Largest Acked
384 * field of that frame. Otherwise, this field should be set to QUIC_PN_INVALID.
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()
488 /* The maximum number of times we allow PTO to be doubled. */
491 /* Default maximum amount of time to leave an ACK-eliciting packet un-ACK'd. */
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. */
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
591 * wait to send us an ACK after receiving an ACK-eliciting packet).
597 * to wait before generating an ACK after receiving an ACK-eliciting
616 * Get TX history for a given packet number space. Must not have been
621 assert(!ackm->discarded[pkt_space]); in get_tx_history()
623 return &ackm->tx_history[pkt_space]; in get_tx_history()
627 * Get RX history for a given packet number space. Must not have been
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
668 * list of PN ranges contained in the ACK frame. The packet structures in the
680 assert(ack->num_ack_ranges > 0); in ackm_detect_and_remove_newly_acked_pkts()
684 * by packet number. 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()
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()
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()
745 * Create a singly-linked list of newly detected-lost packets in the given
746 * packet number space. Returns the head of the list or NULL if no packets were
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()
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()
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()
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()
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()
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()
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()
1344 * frame. 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.
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()
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()
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()
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()
1534 * RFC 9000 s. 13.2.1: "An endpoint MUST acknowledge all ack-eliciting 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()
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()
1580 * Add the packet number to our history list of PNs we have not yet provably 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()
1589 * number of packets. 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()
1621 * maximum number of ranges. in ackm_fill_rx_ack_ranges()
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()
1638 OSSL_TIME now = ackm->now(ackm->now_arg); 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()
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()