tcp: close session on retransmit failure
[vpp.git] / src / vnet / tcp / tcp_output.c
index c7e9792..64e3b1a 100644 (file)
@@ -1518,6 +1518,7 @@ tcp_timer_retransmit_handler (u32 tc_index)
          tcp_send_reset (tc);
          tcp_connection_set_state (tc, TCP_STATE_CLOSED);
          session_transport_closing_notify (&tc->connection);
+         session_transport_closed_notify (&tc->connection);
          tcp_connection_timers_reset (tc);
          tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time);
          return;
@@ -1850,6 +1851,9 @@ tcp_retransmit_should_retry_head (tcp_connection_t * tc,
   u32 tx_adv_sack = sb->high_sacked - tc->snd_congestion;
   f64 rr = (f64) tc->ssthresh / tc->prev_cwnd;
 
+  if (tcp_fastrecovery_first (tc))
+    return 1;
+
   return (tx_adv_sack > (tc->snd_una - tc->prr_start) * rr);
 }
 
@@ -1911,8 +1915,8 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
       && tc->rxt_head != tc->snd_una
       && tcp_retransmit_should_retry_head (tc, sb))
     {
-      n_written = tcp_prepare_retransmit_segment (wrk, tc, 0, tc->snd_mss,
-                                                 &b);
+      max_bytes = clib_min (tc->snd_mss, tc->snd_congestion - tc->snd_una);
+      n_written = tcp_prepare_retransmit_segment (wrk, tc, 0, max_bytes, &b);
       if (!n_written)
        {
          tcp_program_retransmit (tc);
@@ -1928,6 +1932,8 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
       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);
 
@@ -2036,14 +2042,14 @@ 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;
+  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_fastrecovery (tc));
+  ASSERT (tcp_in_cong_recovery (tc));
   TCP_EVT (TCP_EVT_CC_EVT, tc, 0);
 
   burst_bytes = transport_connection_tx_pacer_burst (&tc->connection);
@@ -2064,8 +2070,12 @@ tcp_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
    * segment. */
   while (snd_space > 0 && n_segs < burst_size)
     {
-      n_written = tcp_prepare_retransmit_segment (wrk, tc, offset,
-                                                 tc->snd_mss, &b);
+      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)
@@ -2094,7 +2104,7 @@ send_unsent:
       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 (max_deq > n_segs_now * tc->snd_mss)
+      if (n_segs_now && max_deq > n_segs_now * tc->snd_mss)
        tcp_program_retransmit (tc);
       n_segs += n_segs_now;
     }
@@ -2169,6 +2179,9 @@ tcp_do_retransmit (tcp_connection_t * tc, u32 max_burst_size)
   tcp_worker_ctx_t *wrk;
   u32 n_segs;
 
+  if (PREDICT_FALSE (tc->state == TCP_STATE_CLOSED))
+    return 0;
+
   wrk = tcp_get_worker (tc->c_thread_index);
 
   if (tcp_opts_sack_permitted (&tc->rcv_opts))