tcp: validate connections in output
[vpp.git] / src / vnet / tcp / tcp_input.c
index 4695fbb..1a9eff5 100755 (executable)
@@ -300,8 +300,8 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0,
   if (PREDICT_FALSE (tcp_segment_check_paws (tc0)))
     {
       *error0 = TCP_ERROR_PAWS;
-      TCP_EVT_DBG (TCP_EVT_PAWS_FAIL, tc0, vnet_buffer (b0)->tcp.seq_number,
-                  vnet_buffer (b0)->tcp.seq_end);
+      TCP_EVT (TCP_EVT_PAWS_FAIL, tc0, vnet_buffer (b0)->tcp.seq_number,
+              vnet_buffer (b0)->tcp.seq_end);
 
       /* If it just so happens that a segment updates tsval_recent for a
        * segment over 24 days old, invalidate tsval_recent. */
@@ -318,7 +318,7 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0,
       else if (!tcp_rst (th0))
        {
          tcp_program_ack (tc0);
-         TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp);
+         TCP_EVT (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp);
          goto error;
        }
     }
@@ -335,13 +335,13 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0,
          if (tc0->state == TCP_STATE_SYN_RCVD)
            {
              tcp_send_synack (tc0);
-             TCP_EVT_DBG (TCP_EVT_SYN_RCVD, tc0, 0);
+             TCP_EVT (TCP_EVT_SYN_RCVD, tc0, 0);
              *error0 = TCP_ERROR_SYNS_RCVD;
            }
          else
            {
              tcp_program_ack (tc0);
-             TCP_EVT_DBG (TCP_EVT_SYNACK_RCVD, tc0);
+             TCP_EVT (TCP_EVT_SYNACK_RCVD, tc0);
              *error0 = TCP_ERROR_SYN_ACKS_RCVD;
            }
          goto error;
@@ -365,11 +365,21 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0,
 
       *error0 = TCP_ERROR_RCV_WND;
 
+      /* If we advertised a zero rcv_wnd and the segment is in the past or the
+       * next one that we expect, it is probably a window probe */
+      if ((tc0->flags & TCP_CONN_ZERO_RWND_SENT)
+         && seq_lt (vnet_buffer (b0)->tcp.seq_end,
+                    tc0->rcv_las + tc0->rcv_opts.mss))
+       *error0 = TCP_ERROR_ZERO_RWND;
+
+      tc0->errors.below_data_wnd += seq_lt (vnet_buffer (b0)->tcp.seq_end,
+                                           tc0->rcv_las);
+
       /* If not RST, send dup ack */
       if (!tcp_rst (th0))
        {
          tcp_program_dupack (tc0);
-         TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp);
+         TCP_EVT (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp);
        }
       goto error;
 
@@ -1115,7 +1125,7 @@ tcp_rcv_sacks (tcp_connection_t * tc, u32 ack)
          || sb->holes[sb->head].start == ack + sb->snd_una_adv);
   ASSERT (sb->last_lost_bytes <= sb->lost_bytes);
 
-  TCP_EVT_DBG (TCP_EVT_CC_SCOREBOARD, tc);
+  TCP_EVT (TCP_EVT_CC_SCOREBOARD, tc);
 }
 #endif /* CLIB_MARCH_VARIANT */
 
@@ -1136,7 +1146,7 @@ tcp_update_snd_wnd (tcp_connection_t * tc, u32 seq, u32 ack, u32 snd_wnd)
       tc->snd_wnd = snd_wnd;
       tc->snd_wl1 = seq;
       tc->snd_wl2 = ack;
-      TCP_EVT_DBG (TCP_EVT_SND_WND, tc);
+      TCP_EVT (TCP_EVT_SND_WND, tc);
 
       if (PREDICT_FALSE (tc->snd_wnd < tc->snd_mss))
        {
@@ -1174,7 +1184,8 @@ tcp_cc_init_congestion (tcp_connection_t * tc)
   tc->prev_ssthresh = tc->ssthresh;
   tc->prev_cwnd = tc->cwnd;
   tc->cc_algo->congestion (tc);
-  TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 4);
+  tc->fr_occurences += 1;
+  TCP_EVT (TCP_EVT_CC_EVT, tc, 4);
 }
 #endif /* CLIB_MARCH_VARIANT */
 
@@ -1186,7 +1197,7 @@ tcp_cc_recovery_exit (tcp_connection_t * tc)
   tc->snd_rxt_ts = 0;
   tc->rtt_ts = 0;
   tcp_recovery_off (tc);
-  TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3);
+  TCP_EVT (TCP_EVT_CC_EVT, tc, 3);
 }
 
 #ifndef CLIB_MARCH_VARIANT
@@ -1201,7 +1212,7 @@ tcp_cc_fastrecovery_clear (tcp_connection_t * tc)
   tcp_fastrecovery_first_off (tc);
   tc->flags &= ~TCP_CONN_FRXT_PENDING;
 
-  TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3);
+  TCP_EVT (TCP_EVT_CC_EVT, tc, 3);
 }
 #endif /* CLIB_MARCH_VARIANT */
 
@@ -1222,7 +1233,7 @@ tcp_cc_congestion_undo (tcp_connection_t * tc)
     }
   tcp_cc_undo_recovery (tc);
   ASSERT (tc->rto_boff == 0);
-  TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 5);
+  TCP_EVT (TCP_EVT_CC_EVT, tc, 5);
 }
 
 static inline u8
@@ -1328,7 +1339,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs,
    */
   else if (is_dack && !tcp_in_recovery (tc))
     {
-      TCP_EVT_DBG (TCP_EVT_DUPACK_RCVD, tc, 1);
+      TCP_EVT (TCP_EVT_DUPACK_RCVD, tc, 1);
       ASSERT (tc->snd_una != tc->snd_nxt || tc->sack_sb.last_sacked_bytes);
 
       tc->rcv_dupacks++;
@@ -1356,20 +1367,9 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs,
            }
 
          tcp_cc_init_congestion (tc);
-         tcp_cc_rcv_cong_ack (tc, TCP_CC_DUPACK, rs);
 
          if (tcp_opts_sack_permitted (&tc->rcv_opts))
-           {
-             tc->cwnd = tc->ssthresh;
-             scoreboard_init_high_rxt (&tc->sack_sb, tc->snd_una);
-           }
-         else
-           {
-             /* Post retransmit update cwnd to ssthresh and account for the
-              * three segments that have left the network and should've been
-              * buffered at the receiver XXX */
-             tc->cwnd = tc->ssthresh + 3 * tc->snd_mss;
-           }
+           scoreboard_init_high_rxt (&tc->sack_sb, tc->snd_una);
 
          /* Constrain rate until we get a partial ack */
          pacer_wnd = clib_max (0.1 * tc->cwnd, 2 * tc->snd_mss);
@@ -1414,7 +1414,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs,
     return;
 
 partial_ack:
-  TCP_EVT_DBG (TCP_EVT_CC_PACK, tc);
+  TCP_EVT (TCP_EVT_CC_PACK, tc);
 
   /*
    * Legitimate ACK. 1) See if we can exit recovery
@@ -1510,7 +1510,7 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b,
   tcp_rate_sample_t rs = { 0 };
   u8 is_dack;
 
-  TCP_EVT_DBG (TCP_EVT_CC_STAT, tc);
+  TCP_EVT (TCP_EVT_CC_STAT, tc);
 
   /* If the ACK acks something not yet sent (SEG.ACK > SND.NXT) */
   if (PREDICT_FALSE (seq_gt (vnet_buffer (b)->tcp.ack_number, tc->snd_nxt)))
@@ -1524,18 +1524,18 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b,
          goto process_ack;
        }
 
+      tc->errors.above_ack_wnd += 1;
       *error = TCP_ERROR_ACK_FUTURE;
-      TCP_EVT_DBG (TCP_EVT_ACK_RCV_ERR, tc, 0,
-                  vnet_buffer (b)->tcp.ack_number);
+      TCP_EVT (TCP_EVT_ACK_RCV_ERR, tc, 0, vnet_buffer (b)->tcp.ack_number);
       return -1;
     }
 
   /* If old ACK, probably it's an old dupack */
   if (PREDICT_FALSE (seq_lt (vnet_buffer (b)->tcp.ack_number, tc->snd_una)))
     {
+      tc->errors.below_ack_wnd += 1;
       *error = TCP_ERROR_ACK_OLD;
-      TCP_EVT_DBG (TCP_EVT_ACK_RCV_ERR, tc, 1,
-                  vnet_buffer (b)->tcp.ack_number);
+      TCP_EVT (TCP_EVT_ACK_RCV_ERR, tc, 1, vnet_buffer (b)->tcp.ack_number);
       if (tcp_in_fastrecovery (tc) && tc->rcv_dupacks == TCP_DUPACK_THRESHOLD)
        tcp_cc_handle_event (tc, 0, 1);
       /* Don't drop yet */
@@ -1547,6 +1547,7 @@ process_ack:
   /*
    * Looks okay, process feedback
    */
+
   if (tcp_opts_sack_permitted (&tc->rcv_opts))
     tcp_rcv_sacks (tc, vnet_buffer (b)->tcp.ack_number);
 
@@ -1568,7 +1569,7 @@ process_ack:
   if (tc->flags & TCP_CONN_RATE_SAMPLE)
     tcp_bt_sample_delivery_rate (tc, &rs);
 
-  TCP_EVT_DBG (TCP_EVT_ACK_RCVD, tc);
+  TCP_EVT (TCP_EVT_ACK_RCVD, tc);
 
   /*
    * Check if we have congestion event
@@ -1577,6 +1578,7 @@ process_ack:
   if (tcp_ack_is_cc_event (tc, b, prev_snd_wnd, prev_snd_una, &is_dack))
     {
       tcp_cc_handle_event (tc, &rs, is_dack);
+      tc->dupacks_in += is_dack;
       if (!tcp_in_cong_recovery (tc))
        {
          *error = TCP_ERROR_ACK_OK;
@@ -1642,8 +1644,8 @@ tcp_rcv_fin (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b,
    * in CLOSE-WAIT, set timer (reuse WAITCLOSE). */
   tcp_connection_set_state (tc, TCP_STATE_CLOSE_WAIT);
   tcp_program_disconnect (wrk, tc);
-  tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME);
-  TCP_EVT_DBG (TCP_EVT_FIN_RCVD, tc);
+  tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time);
+  TCP_EVT (TCP_EVT_FIN_RCVD, tc);
   *error = TCP_ERROR_FIN_RCVD;
 }
 
@@ -1741,8 +1743,9 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b,
   ASSERT (data_len);
   written = session_enqueue_stream_connection (&tc->connection, b, 0,
                                               1 /* queue event */ , 1);
+  tc->bytes_in += written;
 
-  TCP_EVT_DBG (TCP_EVT_INPUT, tc, 0, data_len, written);
+  TCP_EVT (TCP_EVT_INPUT, tc, 0, data_len, written);
 
   /* Update rcv_nxt */
   if (PREDICT_TRUE (written == data_len))
@@ -1753,7 +1756,7 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b,
   else if (written > data_len)
     {
       tc->rcv_nxt += written;
-      TCP_EVT_DBG (TCP_EVT_CC_INPUT, tc, data_len, written);
+      TCP_EVT (TCP_EVT_CC_INPUT, tc, data_len, written);
     }
   else if (written > 0)
     {
@@ -1796,11 +1799,12 @@ tcp_session_enqueue_ooo (tcp_connection_t * tc, vlib_buffer_t * b,
   /* Nothing written */
   if (rv)
     {
-      TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, 0);
+      TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, 0);
       return TCP_ERROR_FIFO_FULL;
     }
 
-  TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, data_len);
+  TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, data_len);
+  tc->bytes_in += data_len;
 
   /* Update SACK list if in use */
   if (tcp_opts_sack_permitted (&tc->rcv_opts))
@@ -1820,7 +1824,7 @@ tcp_session_enqueue_ooo (tcp_connection_t * tc, vlib_buffer_t * b,
          end = start + ooo_segment_length (s0->rx_fifo, newest);
          tcp_update_sack_list (tc, start, end);
          svm_fifo_newest_ooo_segment_reset (s0->rx_fifo);
-         TCP_EVT_DBG (TCP_EVT_CC_SACKS, tc);
+         TCP_EVT (TCP_EVT_CC_SACKS, tc);
        }
     }
 
@@ -1889,6 +1893,7 @@ tcp_segment_rcv (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
   vlib_buffer_advance (b, vnet_buffer (b)->tcp.data_offset);
   n_data_bytes = vnet_buffer (b)->tcp.data_len;
   ASSERT (n_data_bytes);
+  tc->data_segs_in += 1;
 
   /* Handle out-of-order data */
   if (PREDICT_FALSE (vnet_buffer (b)->tcp.seq_number != tc->rcv_nxt))
@@ -1922,7 +1927,9 @@ tcp_segment_rcv (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
       /* RFC2581: Enqueue and send DUPACK for fast retransmit */
       error = tcp_session_enqueue_ooo (tc, b, n_data_bytes);
       tcp_program_dupack (tc);
-      TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc, vnet_buffer (b)->tcp);
+      TCP_EVT (TCP_EVT_DUPACK_SENT, tc, vnet_buffer (b)->tcp);
+      tc->errors.above_data_wnd += seq_gt (vnet_buffer (b)->tcp.seq_end,
+                                          tc->rcv_las + tc->rcv_wnd);
       goto done;
     }
 
@@ -1934,7 +1941,7 @@ in_order:
   if (tcp_can_delack (tc))
     {
       if (!tcp_timer_is_active (tc, TCP_TIMER_DELACK))
-       tcp_timer_set (tc, TCP_TIMER_DELACK, TCP_DELACK_TIME);
+       tcp_timer_set (tc, TCP_TIMER_DELACK, tcp_cfg.delack_time);
       goto done;
     }
 
@@ -2120,7 +2127,7 @@ tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       /* 1-4: check SEQ, RST, SYN */
       if (PREDICT_FALSE (tcp_segment_validate (wrk, tc0, b0, th0, &error0)))
        {
-         TCP_EVT_DBG (TCP_EVT_SEG_INVALID, tc0, vnet_buffer (b0)->tcp);
+         TCP_EVT (TCP_EVT_SEG_INVALID, tc0, vnet_buffer (b0)->tcp);
          goto done;
        }
 
@@ -2289,7 +2296,6 @@ always_inline uword
 tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                       vlib_frame_t * from_frame, int is_ip4)
 {
-  tcp_main_t *tm = vnet_get_tcp_main ();
   u32 n_left_from, *from, *first_buffer, errors = 0;
   u32 my_thread_index = vm->thread_index;
   tcp_worker_ctx_t *wrk = tcp_get_worker (my_thread_index);
@@ -2420,13 +2426,9 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
       /* Valid SYN or SYN-ACK. Move connection from half-open pool to
        * current thread pool. */
-      pool_get (tm->connections[my_thread_index], new_tc0);
-      clib_memcpy_fast (new_tc0, tc0, sizeof (*new_tc0));
-      new_tc0->c_c_index = new_tc0 - tm->connections[my_thread_index];
-      new_tc0->c_thread_index = my_thread_index;
+      new_tc0 = tcp_connection_alloc_w_base (my_thread_index, tc0);
       new_tc0->rcv_nxt = vnet_buffer (b0)->tcp.seq_end;
       new_tc0->irs = seq0;
-      new_tc0->timers[TCP_TIMER_ESTABLISH_AO] = TCP_TIMER_HANDLE_INVALID;
       new_tc0->timers[TCP_TIMER_RETRANSMIT_SYN] = TCP_TIMER_HANDLE_INVALID;
       new_tc0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
 
@@ -2479,7 +2481,7 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            transport_tx_fifo_size (&new_tc0->connection);
          /* Update rtt with the syn-ack sample */
          tcp_estimate_initial_rtt (new_tc0);
-         TCP_EVT_DBG (TCP_EVT_SYNACK_RCVD, new_tc0);
+         TCP_EVT (TCP_EVT_SYNACK_RCVD, new_tc0);
          error0 = TCP_ERROR_SYN_ACKS_RCVD;
        }
       /* SYN: Simultaneous open. Change state to SYN-RCVD and send SYN-ACK */
@@ -2492,7 +2494,7 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            {
              tcp_connection_cleanup (new_tc0);
              tcp_send_reset_w_pkt (tc0, b0, my_thread_index, is_ip4);
-             TCP_EVT_DBG (TCP_EVT_RST_SENT, tc0);
+             TCP_EVT (TCP_EVT_RST_SENT, tc0);
              error0 = TCP_ERROR_CREATE_SESSION_FAIL;
              goto drop;
            }
@@ -2690,7 +2692,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
          /* Switch state to ESTABLISHED */
          tc0->state = TCP_STATE_ESTABLISHED;
-         TCP_EVT_DBG (TCP_EVT_STATE_CHANGE, tc0);
+         TCP_EVT (TCP_EVT_STATE_CHANGE, tc0);
 
          /* Initialize session variables */
          tc0->snd_una = vnet_buffer (b0)->tcp.ack_number;
@@ -2701,7 +2703,6 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
          /* Reset SYN-ACK retransmit and SYN_RCV establish timers */
          tcp_retransmit_timer_reset (tc0);
-         tcp_timer_reset (tc0, TCP_TIMER_ESTABLISH);
          if (session_stream_accept_notify (&tc0->connection))
            {
              error0 = TCP_ERROR_MSG_QUEUE_FULL;
@@ -2734,7 +2735,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              /* If a fin was received and data was acked extend wait */
              else if ((tc0->flags & TCP_CONN_FINRCVD) && tc0->bytes_acked)
                tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE,
-                                 TCP_CLOSEWAIT_TIME);
+                                 tcp_cfg.closewait_time);
            }
          /* If FIN is ACKed */
          else if (tc0->snd_una == tc0->snd_nxt)
@@ -2748,7 +2749,8 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              if (tc0->flags & TCP_CONN_FINRCVD)
                {
                  tcp_connection_set_state (tc0, TCP_STATE_CLOSED);
-                 tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME);
+                 tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE,
+                                tcp_cfg.cleanup_time);
                  session_transport_closed_notify (&tc0->connection);
                  goto drop;
                }
@@ -2756,7 +2758,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              tcp_connection_set_state (tc0, TCP_STATE_FIN_WAIT_2);
              /* Enable waitclose because we're willing to wait for peer's
               * FIN but not indefinitely. */
-             tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
+             tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.finwait2_time);
 
              /* Don't try to deq the FIN acked */
              if (tc0->burst_acked > 1)
@@ -2789,7 +2791,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          tcp_send_fin (tc0);
          tcp_connection_timers_reset (tc0);
          tcp_connection_set_state (tc0, TCP_STATE_LAST_ACK);
-         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
+         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time);
          break;
        case TCP_STATE_CLOSING:
          /* In addition to the processing for the ESTABLISHED state, if
@@ -2803,7 +2805,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
          tcp_connection_timers_reset (tc0);
          tcp_connection_set_state (tc0, TCP_STATE_TIME_WAIT);
-         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME);
+         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time);
          session_transport_closed_notify (&tc0->connection);
          goto drop;
 
@@ -2830,7 +2832,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
           * we can't ensure that we have no packets already enqueued
           * to output. Rely instead on the waitclose timer */
          tcp_connection_timers_reset (tc0);
-         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME);
+         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.cleanup_time);
 
          goto drop;
 
@@ -2847,7 +2849,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            goto drop;
 
          tcp_program_ack (tc0);
-         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME);
+         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time);
          goto drop;
 
          break;
@@ -2879,7 +2881,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       if (!is_fin0)
        goto drop;
 
-      TCP_EVT_DBG (TCP_EVT_FIN_RCVD, tc0);
+      TCP_EVT (TCP_EVT_FIN_RCVD, tc0);
 
       switch (tc0->state)
        {
@@ -2889,7 +2891,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          tcp_program_ack (tc0);
          tcp_connection_set_state (tc0, TCP_STATE_CLOSE_WAIT);
          tcp_program_disconnect (wrk, tc0);
-         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME);
+         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time);
          break;
        case TCP_STATE_SYN_RCVD:
          /* Send FIN-ACK, enter LAST-ACK and because the app was not
@@ -2899,7 +2901,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          tc0->rcv_nxt += 1;
          tcp_send_fin (tc0);
          tcp_connection_set_state (tc0, TCP_STATE_LAST_ACK);
-         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
+         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time);
          break;
        case TCP_STATE_CLOSE_WAIT:
        case TCP_STATE_CLOSING:
@@ -2915,14 +2917,16 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
               * sending it. Since we already received a fin, do not wait
               * for too long. */
              tc0->flags |= TCP_CONN_FINRCVD;
-             tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME);
+             tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE,
+                               tcp_cfg.closewait_time);
            }
          else
            {
              tcp_connection_set_state (tc0, TCP_STATE_CLOSING);
              tcp_program_ack (tc0);
              /* Wait for ACK for our FIN but not forever */
-             tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME);
+             tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE,
+                               tcp_cfg.closing_time);
            }
          break;
        case TCP_STATE_FIN_WAIT_2:
@@ -2930,7 +2934,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          tc0->rcv_nxt += 1;
          tcp_connection_set_state (tc0, TCP_STATE_TIME_WAIT);
          tcp_connection_timers_reset (tc0);
-         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME);
+         tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time);
          tcp_program_ack (tc0);
          session_transport_closed_notify (&tc0->connection);
          break;
@@ -2938,7 +2942,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          /* Remain in the TIME-WAIT state. Restart the time-wait
           * timeout.
           */
-         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME);
+         tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time);
          break;
        }
       error0 = TCP_ERROR_FIN_RCVD;
@@ -3091,6 +3095,7 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       child0->c_is_ip4 = is_ip4;
       child0->state = TCP_STATE_SYN_RCVD;
       child0->c_fib_index = lc0->c_fib_index;
+      child0->cc_algo = lc0->cc_algo;
 
       if (is_ip4)
        {
@@ -3144,10 +3149,9 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          goto drop;
        }
 
-      TCP_EVT_DBG (TCP_EVT_SYN_RCVD, child0, 1);
+      TCP_EVT (TCP_EVT_SYN_RCVD, child0, 1);
       child0->tx_fifo_size = transport_tx_fifo_size (&child0->connection);
       tcp_send_synack (child0);
-      tcp_timer_set (child0, TCP_TIMER_ESTABLISH, TCP_SYN_RCVD_TIME);
 
     drop:
 
@@ -3398,6 +3402,7 @@ tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc,
   flags = tcp->flags & filter_flags;
   *next = tm->dispatch_table[tc->state][flags].next;
   *error = tm->dispatch_table[tc->state][flags].error;
+  tc->segs_in += 1;
 
   if (PREDICT_FALSE (*error == TCP_ERROR_DISPATCH
                     || *next == TCP_INPUT_NEXT_RESET))
@@ -3797,6 +3802,8 @@ do {                                                              \
     TCP_ERROR_NONE);
   _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_ACK,
     TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE);
+  _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_RST,
+    TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE);
   _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_RST | TCP_FLAG_ACK,
     TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE);
   /* FIN confirming that the peer (app) has closed */