tcp: add option to pass opaque to next node
[vpp.git] / src / vnet / tcp / tcp_output.c
index 518a80d..1adac95 100644 (file)
@@ -1132,7 +1132,6 @@ tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b)
   tcp_push_hdr_i (tc, b, tc->snd_nxt, /* compute opts */ 0, /* burst */ 1,
                  /* update_snd_nxt */ 1);
   tc->snd_una_max = seq_max (tc->snd_nxt, tc->snd_una_max);
-  ASSERT (seq_leq (tc->snd_una_max, tc->snd_una + tc->snd_wnd));
   tcp_validate_txf_size (tc, tc->snd_una_max - tc->snd_una);
   /* If not tracking an ACK, start tracking */
   if (tc->rtt_ts == 0 && !tcp_in_cong_recovery (tc))
@@ -1518,6 +1517,19 @@ tcp_timer_retransmit_handler_i (u32 index, u8 is_syn)
          tcp_update_rto (tc);
        }
 
+      /* Peer is dead or network connectivity is lost. Close connection.
+       * RFC 1122 section 4.2.3.5 recommends a value of at least 100s. For
+       * a min rto of 0.2s we need to retry about 8 times. */
+      if (tc->rto_boff >= TCP_RTO_BOFF_MAX)
+       {
+         tcp_send_reset (tc);
+         tcp_connection_set_state (tc, TCP_STATE_CLOSED);
+         session_transport_closing_notify (&tc->connection);
+         tcp_connection_timers_reset (tc);
+         tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME);
+         return;
+       }
+
       /* Increment RTO backoff (also equal to number of retries) and go back
        * to first un-acked byte  */
       tc->rto_boff += 1;
@@ -1892,12 +1904,13 @@ tcp_fast_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
   ASSERT (tcp_in_fastrecovery (tc));
   TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 0);
 
+  snd_space = tcp_available_cc_snd_space (tc);
+
   if (!tcp_fastrecovery_first (tc))
     goto send_unsent;
 
   /* RFC 6582: [If a partial ack], retransmit the first unacknowledged
    * segment. */
-  snd_space = tc->sack_sb.last_bytes_delivered;
   while (snd_space > 0 && n_segs < burst_size)
     {
       n_written = tcp_prepare_retransmit_segment (wrk, tc, offset,
@@ -1920,7 +1933,6 @@ tcp_fast_retransmit_no_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
 send_unsent:
 
   /* RFC 6582: Send a new segment if permitted by the new value of cwnd. */
-  snd_space = tcp_available_cc_snd_space (tc);
   if (snd_space < tc->snd_mss || tc->snd_mss == 0)
     goto done;
 
@@ -2050,6 +2062,13 @@ tcp_output_handle_packet (tcp_connection_t * tc0, vlib_buffer_t * b0,
       return;
     }
 
+  /* If next_index is not drop use it */
+  if (tc0->next_node_index)
+    {
+      *next0 = tc0->next_node_index;
+      vnet_buffer (b0)->tcp.next_node_opaque = tc0->next_node_opaque;
+    }
+
   vnet_buffer (b0)->sw_if_index[VLIB_TX] = tc0->c_fib_index;
   vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;