tcp: fix error counters
[vpp.git] / src / vnet / tcp / tcp_input.c
index 11491a6..fa2961e 100644 (file)
@@ -594,7 +594,7 @@ tcp_handle_postponed_dequeues (tcp_worker_ctx_t * wrk)
 
       tc->burst_acked = 0;
     }
-  _vec_len (wrk->pending_deq_acked) = 0;
+  vec_set_len (wrk->pending_deq_acked, 0);
 }
 
 static void
@@ -629,11 +629,15 @@ tcp_update_snd_wnd (tcp_connection_t * tc, u32 seq, u32 ack, u32 snd_wnd)
 
       if (PREDICT_FALSE (tc->snd_wnd < tc->snd_mss))
        {
-         /* Set persist timer if not set and we just got 0 wnd */
-         if (!tcp_timer_is_active (tc, TCP_TIMER_PERSIST)
-             && !tcp_timer_is_active (tc, TCP_TIMER_RETRANSMIT))
+         if (!tcp_timer_is_active (tc, TCP_TIMER_RETRANSMIT))
            {
              tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index);
+
+             /* Set persist timer if we just got 0 wnd. If already set,
+              * update it because some data sent with snd_wnd < snd_mss was
+              * acked. */
+             if (tcp_timer_is_active (tc, TCP_TIMER_PERSIST))
+               tcp_persist_timer_reset (&wrk->timer_wheel, tc);
              tcp_persist_timer_set (&wrk->timer_wheel, tc);
            }
        }
@@ -802,15 +806,6 @@ tcp_cc_update (tcp_connection_t * tc, tcp_rate_sample_t * rs)
 
   /* If a cumulative ack, make sure dupacks is 0 */
   tc->rcv_dupacks = 0;
-
-  /* When dupacks hits the threshold we only enter fast retransmit if
-   * cumulative ack covers more than snd_congestion. Should snd_una
-   * wrap this test may fail under otherwise valid circumstances.
-   * Therefore, proactively update snd_congestion when wrap detected. */
-  if (PREDICT_FALSE
-      (seq_leq (tc->snd_congestion, tc->snd_una - tc->bytes_acked)
-       && seq_gt (tc->snd_congestion, tc->snd_una)))
-    tc->snd_congestion = tc->snd_una - 1;
 }
 
 /**
@@ -1104,7 +1099,7 @@ tcp_handle_disconnects (tcp_worker_ctx_t * wrk)
          tcp_disconnect_pending_off (tc);
          session_transport_closing_notify (&tc->connection);
        }
-      _vec_len (wrk->pending_disconnects) = 0;
+      vec_set_len (wrk->pending_disconnects, 0);
     }
 
   if (vec_len (wrk->pending_resets))
@@ -1117,7 +1112,7 @@ tcp_handle_disconnects (tcp_worker_ctx_t * wrk)
          tcp_disconnect_pending_off (tc);
          tcp_handle_rst (tc);
        }
-      _vec_len (wrk->pending_resets) = 0;
+      vec_set_len (wrk->pending_resets, 0);
     }
 }
 
@@ -1154,7 +1149,6 @@ 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 (TCP_EVT_INPUT, tc, 0, data_len, written);
 
@@ -1162,17 +1156,20 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b,
   if (PREDICT_TRUE (written == data_len))
     {
       tc->rcv_nxt += written;
+      tc->bytes_in += written;
     }
   /* If more data written than expected, account for out-of-order bytes. */
   else if (written > data_len)
     {
       tc->rcv_nxt += written;
+      tc->bytes_in += data_len;
       TCP_EVT (TCP_EVT_CC_INPUT, tc, data_len, written);
     }
   else if (written > 0)
     {
       /* We've written something but FIFO is probably full now */
       tc->rcv_nxt += written;
+      tc->bytes_in += written;
       error = TCP_ERROR_PARTIALLY_ENQUEUED;
     }
   else
@@ -1431,44 +1428,6 @@ tcp_established_trace_frame (vlib_main_t * vm, vlib_node_runtime_t * node,
     }
 }
 
-always_inline void
-tcp_node_inc_counter_i (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node,
-                       u8 is_ip4, u32 evt, u32 val)
-{
-  if (is_ip4)
-    vlib_node_increment_counter (vm, tcp4_node, evt, val);
-  else
-    vlib_node_increment_counter (vm, tcp6_node, evt, val);
-}
-
-#define tcp_maybe_inc_counter(node_id, err, count)                     \
-{                                                                      \
-  if (next0 != tcp_next_drop (is_ip4))                                 \
-    tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index,           \
-                            tcp6_##node_id##_node.index, is_ip4, err,  \
-                           1);                                         \
-}
-#define tcp_inc_counter(node_id, err, count)                           \
-  tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index,             \
-                          tcp6_##node_id##_node.index, is_ip4,         \
-                          err, count)
-#define tcp_maybe_inc_err_counter(cnts, err)                           \
-{                                                                      \
-  cnts[err] += (next0 != tcp_next_drop (is_ip4));                      \
-}
-#define tcp_inc_err_counter(cnts, err, val)                            \
-{                                                                      \
-  cnts[err] += val;                                                    \
-}
-#define tcp_store_err_counters(node_id, cnts)                          \
-{                                                                      \
-  int i;                                                               \
-  for (i = 0; i < TCP_N_ERROR; i++)                                    \
-    if (cnts[i])                                                       \
-      tcp_inc_counter(node_id, i, cnts[i]);                            \
-}
-
-
 always_inline uword
 tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                          vlib_frame_t * frame, int is_ip4)
@@ -2662,7 +2621,6 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
 
   while (n_left_from > 0)
     {
-      u32 error = TCP_ERROR_NONE;
       tcp_connection_t *lc, *child;
 
       /* Flags initialized with connection state after lookup */
@@ -2677,14 +2635,14 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
                                   thread_index);
          if (tc->state != TCP_STATE_TIME_WAIT)
            {
-             error = TCP_ERROR_CREATE_EXISTS;
+             tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1);
              goto done;
            }
 
          if (PREDICT_FALSE (!syn_during_timewait (tc, b[0], &tw_iss)))
            {
              /* This SYN can't be accepted */
-             error = TCP_ERROR_CREATE_EXISTS;
+             tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1);
              goto done;
            }
 
@@ -2694,7 +2652,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
          /* listener was cleaned up */
          if (!lc)
            {
-             error = TCP_ERROR_NO_LISTENER;
+             tcp_inc_counter (listen, TCP_ERROR_NO_LISTENER, 1);
              goto done;
            }
        }
@@ -2704,7 +2662,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
        tcp_lookup_connection (lc->c_fib_index, b[0], thread_index, is_ip4);
       if (PREDICT_FALSE (child->state != TCP_STATE_LISTEN))
        {
-         error = TCP_ERROR_CREATE_EXISTS;
+         tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1);
          goto done;
        }
 
@@ -2721,7 +2679,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
 
       if (tcp_options_parse (tcp_buffer_hdr (b[0]), &child->rcv_opts, 1))
        {
-         error = TCP_ERROR_OPTIONS;
+         tcp_inc_counter (listen, TCP_ERROR_OPTIONS, 1);
          tcp_connection_free (child);
          goto done;
        }
@@ -2751,7 +2709,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
                                 lc->c_thread_index, 0 /* notify */ ))
        {
          tcp_connection_cleanup (child);
-         error = TCP_ERROR_CREATE_SESSION_FAIL;
+         tcp_inc_counter (listen, TCP_ERROR_CREATE_SESSION_FAIL, 1);
          goto done;
        }
 
@@ -2759,12 +2717,11 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
       child->tx_fifo_size = transport_tx_fifo_size (&child->connection);
 
       tcp_send_synack (child);
+      n_syns += 1;
 
     done:
-
       b += 1;
       n_left_from -= 1;
-      n_syns += (error == TCP_ERROR_NONE);
     }
 
   tcp_inc_counter (listen, TCP_ERROR_SYNS_RCVD, n_syns);
@@ -2937,6 +2894,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
   tcp_main_t *tm = vnet_get_tcp_main ();
   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
   u16 nexts[VLIB_FRAME_SIZE], *next;
+  u16 err_counters[TCP_N_ERROR] = { 0 };
 
   tcp_update_time_now (tcp_get_worker (thread_index));
 
@@ -2989,7 +2947,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          else
            {
              tcp_input_set_error_next (tm, &next[0], &error0, is_ip4);
-             b[0]->error = node->errors[error0];
+             tcp_inc_err_counter (err_counters, error0, 1);
            }
 
          if (PREDICT_TRUE (tc1 != 0))
@@ -3001,7 +2959,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          else
            {
              tcp_input_set_error_next (tm, &next[1], &error1, is_ip4);
-             b[1]->error = node->errors[error1];
+             tcp_inc_err_counter (err_counters, error1, 1);
            }
        }
 
@@ -3032,7 +2990,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       else
        {
          tcp_input_set_error_next (tm, &next[0], &error0, is_ip4);
-         b[0]->error = node->errors[error0];
+         tcp_inc_err_counter (err_counters, error0, 1);
        }
 
       b += 1;
@@ -3043,6 +3001,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
   if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
     tcp_input_trace_frame (vm, node, bufs, frame->n_vectors, is_ip4);
 
+  tcp_store_err_counters (input, err_counters);
   vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
   return frame->n_vectors;
 }