+ bi = vlib_get_buffer_index (vm, b);
+ tcp_enqueue_to_output (wrk, b, bi, tc->c_is_ip4);
+ n_segs = 1;
+
+ tc->rxt_head = tc->snd_una;
+ tc->rxt_delivered += n_written;
+ tc->prr_delivered += n_written;
+ ASSERT (tc->rxt_delivered <= tc->snd_rxt_bytes);
+ }
+
+ tcp_fastrecovery_first_off (tc);
+
+ TCP_EVT (TCP_EVT_CC_EVT, tc, 0);
+ hole = scoreboard_get_hole (sb, sb->cur_rxt_hole);
+
+ max_deq = transport_max_tx_dequeue (&tc->connection);
+ max_deq -= tc->snd_nxt - tc->snd_una;
+
+ while (snd_space > 0 && n_segs < burst_size)
+ {
+ hole = scoreboard_next_rxt_hole (sb, hole, max_deq != 0, &can_rescue,
+ &snd_limited);
+ if (!hole)
+ {
+ /* We are out of lost holes to retransmit so send some new data. */
+ if (max_deq > tc->snd_mss)
+ {
+ u32 n_segs_new;
+ int av_wnd;
+
+ /* Make sure we don't exceed available window and leave space
+ * for one more packet, to avoid zero window acks */
+ av_wnd = (int) tc->snd_wnd - (tc->snd_nxt - tc->snd_una);
+ av_wnd = clib_max (av_wnd - tc->snd_mss, 0);
+ snd_space = clib_min (snd_space, av_wnd);
+ snd_space = clib_min (max_deq, snd_space);
+ burst_size = clib_min (burst_size - n_segs,
+ snd_space / tc->snd_mss);
+ burst_size = clib_min (burst_size, TCP_RXT_MAX_BURST);
+ n_segs_new = tcp_transmit_unsent (wrk, tc, burst_size);
+ if (max_deq > n_segs_new * tc->snd_mss)
+ tcp_program_retransmit (tc);
+
+ n_segs += n_segs_new;
+ goto done;
+ }
+
+ if (tcp_in_recovery (tc) || !can_rescue
+ || scoreboard_rescue_rxt_valid (sb, tc))
+ break;
+
+ /* If rescue rxt undefined or less than snd_una then one segment of
+ * up to SMSS octets that MUST include the highest outstanding
+ * unSACKed sequence number SHOULD be returned, and RescueRxt set to
+ * RecoveryPoint. HighRxt MUST NOT be updated.
+ */
+ hole = scoreboard_last_hole (sb);
+ max_bytes = clib_min (tc->snd_mss, hole->end - hole->start);
+ max_bytes = clib_min (max_bytes, snd_space);
+ offset = hole->end - tc->snd_una - max_bytes;
+ n_written = tcp_prepare_retransmit_segment (wrk, tc, offset,
+ max_bytes, &b);
+ if (!n_written)
+ goto done;
+
+ sb->rescue_rxt = tc->snd_congestion;
+ bi = vlib_get_buffer_index (vm, b);
+ tcp_enqueue_to_output (wrk, b, bi, tc->c_is_ip4);
+ n_segs += 1;
+ break;
+ }
+
+ max_bytes = clib_min (hole->end - sb->high_rxt, snd_space);
+ max_bytes = snd_limited ? clib_min (max_bytes, tc->snd_mss) : max_bytes;
+ if (max_bytes == 0)
+ break;
+
+ offset = sb->high_rxt - tc->snd_una;
+ n_written = tcp_prepare_retransmit_segment (wrk, tc, offset, max_bytes,
+ &b);
+ ASSERT (n_written <= snd_space);
+
+ /* Nothing left to retransmit */
+ if (n_written == 0)
+ break;
+
+ bi = vlib_get_buffer_index (vm, b);
+ tcp_enqueue_to_output (wrk, b, bi, tc->c_is_ip4);
+
+ sb->high_rxt += n_written;
+ ASSERT (seq_leq (sb->high_rxt, tc->snd_nxt));
+
+ snd_space -= n_written;
+ n_segs += 1;
+ }
+
+ if (hole)
+ tcp_program_retransmit (tc);
+
+done:
+
+ transport_connection_tx_pacer_reset_bucket (&tc->connection, 0);
+ return n_segs;
+}
+
+/**
+ * Fast retransmit without SACK info
+ */
+static int
+tcp_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
+ u32 burst_size)
+{
+ u32 n_written = 0, offset = 0, bi, max_deq, n_segs_now, max_bytes;
+ u32 burst_bytes, sent_bytes;
+ vlib_main_t *vm = wrk->vm;
+ int snd_space, n_segs = 0;
+ u8 cc_limited = 0;
+ vlib_buffer_t *b;
+
+ ASSERT (tcp_in_cong_recovery (tc));
+ TCP_EVT (TCP_EVT_CC_EVT, tc, 0);
+
+ burst_bytes = transport_connection_tx_pacer_burst (&tc->connection);
+ burst_size = clib_min (burst_size, burst_bytes / tc->snd_mss);
+ if (!burst_size)
+ {
+ tcp_program_retransmit (tc);
+ return 0;
+ }
+
+ snd_space = tcp_available_cc_snd_space (tc);
+ cc_limited = snd_space < burst_bytes;
+
+ if (!tcp_fastrecovery_first (tc))
+ goto send_unsent;
+
+ /* RFC 6582: [If a partial ack], retransmit the first unacknowledged
+ * segment. */
+ while (snd_space > 0 && n_segs < burst_size)
+ {
+ max_bytes = clib_min (tc->snd_mss,
+ tc->snd_congestion - tc->snd_una - offset);
+ if (!max_bytes)
+ break;
+ n_written = tcp_prepare_retransmit_segment (wrk, tc, offset, max_bytes,
+ &b);
+
+ /* Nothing left to retransmit */
+ if (n_written == 0)
+ break;
+
+ bi = vlib_get_buffer_index (vm, b);
+ tcp_enqueue_to_output (wrk, b, bi, tc->c_is_ip4);
+ snd_space -= n_written;
+ offset += n_written;
+ n_segs += 1;
+ }
+
+ if (n_segs == burst_size)
+ goto done;
+
+send_unsent:
+
+ /* RFC 6582: Send a new segment if permitted by the new value of cwnd. */
+ if (snd_space < tc->snd_mss || tc->snd_mss == 0)
+ goto done;
+
+ max_deq = transport_max_tx_dequeue (&tc->connection);
+ max_deq -= tc->snd_nxt - tc->snd_una;
+ if (max_deq)
+ {
+ snd_space = clib_min (max_deq, snd_space);
+ burst_size = clib_min (burst_size - n_segs, snd_space / tc->snd_mss);
+ n_segs_now = tcp_transmit_unsent (wrk, tc, burst_size);
+ if (n_segs_now && max_deq > n_segs_now * tc->snd_mss)
+ tcp_program_retransmit (tc);
+ n_segs += n_segs_now;
+ }