tcp: close connection if not recovered after max tries 41/20041/8
authorFlorin Coras <fcoras@cisco.com>
Fri, 7 Jun 2019 22:31:06 +0000 (15:31 -0700)
committerJohn Lo <loj@cisco.com>
Sat, 8 Jun 2019 01:36:00 +0000 (01:36 +0000)
Type: feature

Change-Id: Ia8af6a62a2be2265bc42955d90e8c2222bdb8f50
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/tcp/tcp.h
src/vnet/tcp/tcp_output.c

index 48bbb3e..98808c1 100644 (file)
@@ -112,6 +112,7 @@ extern timer_expiration_handler tcp_timer_retransmit_syn_handler;
 #define TCP_RTT_MAX 30 * THZ   /* 30s (probably too much) */
 #define TCP_RTO_SYN_RETRIES 3  /* SYN retries without doubling RTO */
 #define TCP_RTO_INIT 1 * THZ   /* Initial retransmit timer */
+#define TCP_RTO_BOFF_MAX 8     /* Max number of retries before reset */
 
 /** TCP connection flags */
 #define foreach_tcp_connection_flag             \
index 03caa07..c9ffd00 100644 (file)
@@ -1517,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;