misc: remove GNU Indent directives
[vpp.git] / src / vnet / udp / udp_input.c
index 95595c3..a904611 100644 (file)
 #include <vppinfra/elog.h>
 
 #include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
 #include <vnet/ip/ip.h>
 #include <vnet/udp/udp.h>
 #include <vnet/udp/udp_packet.h>
 #include <vnet/session/session.h>
 
-static char *udp_error_strings[] = {
-#define udp_error(n,s) s,
+static vlib_error_desc_t udp_error_counters[] = {
+#define udp_error(f, n, s, d) { #n, d, VL_COUNTER_SEVERITY_##s },
 #include "udp_error.def"
 #undef udp_error
 };
@@ -116,6 +115,7 @@ udp_connection_accept (udp_connection_t * listener, session_dgram_hdr_t * hdr,
   uc->c_fib_index = listener->c_fib_index;
   uc->mss = listener->mss;
   uc->flags |= UDP_CONN_F_CONNECTED;
+  uc->cfg_flags = listener->cfg_flags;
 
   if (session_dgram_accept (&uc->connection, listener->c_s_index,
                            listener->c_thread_index))
@@ -123,8 +123,8 @@ udp_connection_accept (udp_connection_t * listener, session_dgram_hdr_t * hdr,
       udp_connection_free (uc);
       return 0;
     }
-  udp_connection_share_port (clib_net_to_host_u16
-                            (uc->c_lcl_port), uc->c_is_ip4);
+
+  udp_connection_share_port (uc->c_lcl_port, uc->c_is_ip4);
   return uc;
 }
 
@@ -135,36 +135,47 @@ udp_connection_enqueue (udp_connection_t * uc0, session_t * s0,
 {
   int wrote0;
 
-  clib_spinlock_lock (&uc0->rx_lock);
+  if (!(uc0->flags & UDP_CONN_F_CONNECTED))
+    {
+      clib_spinlock_lock (&uc0->rx_lock);
+
+      wrote0 = session_enqueue_dgram_connection_cl (
+       s0, hdr0, b, TRANSPORT_PROTO_UDP, queue_event);
+
+      clib_spinlock_unlock (&uc0->rx_lock);
+
+      /* Expect cl udp enqueue to fail because fifo enqueue */
+      if (PREDICT_FALSE (wrote0 == 0))
+       *error0 = UDP_ERROR_FIFO_FULL;
+
+      return;
+    }
 
   if (svm_fifo_max_enqueue_prod (s0->rx_fifo)
       < hdr0->data_length + sizeof (session_dgram_hdr_t))
     {
       *error0 = UDP_ERROR_FIFO_FULL;
-      goto unlock_rx_lock;
+      return;
     }
 
   /* If session is owned by another thread and rx event needed,
    * enqueue event now while we still have the peeker lock */
   if (s0->thread_index != thread_index)
     {
-      wrote0 = session_enqueue_dgram_connection (s0, hdr0, b,
-                                                TRANSPORT_PROTO_UDP,
-                                                /* queue event */ 0);
-      if (queue_event && !svm_fifo_has_event (s0->rx_fifo))
-       session_enqueue_notify (s0);
+      wrote0 = session_enqueue_dgram_connection2 (
+       s0, hdr0, b, TRANSPORT_PROTO_UDP,
+       queue_event && !svm_fifo_has_event (s0->rx_fifo));
     }
   else
     {
-      wrote0 = session_enqueue_dgram_connection (s0, hdr0, b,
-                                                TRANSPORT_PROTO_UDP,
-                                                queue_event);
+      wrote0 = session_enqueue_dgram_connection (
+       s0, hdr0, b, TRANSPORT_PROTO_UDP, queue_event);
     }
-  ASSERT (wrote0 > 0);
-
-unlock_rx_lock:
 
-  clib_spinlock_unlock (&uc0->rx_lock);
+  /* In some rare cases, session_enqueue_dgram_connection can fail because a
+   * chunk cannot be allocated in the RX FIFO */
+  if (PREDICT_FALSE (wrote0 == 0))
+    *error0 = UDP_ERROR_FIFO_NOMEM;
 }
 
 always_inline session_t *
@@ -183,6 +194,7 @@ udp_parse_and_lookup_buffer (vlib_buffer_t * b, session_dgram_hdr_t * hdr,
   hdr->lcl_port = udp->dst_port;
   hdr->rmt_port = udp->src_port;
   hdr->is_ip4 = is_ip4;
+  hdr->gso_size = 0;
 
   if (is_ip4)
     {
@@ -212,6 +224,10 @@ udp_parse_and_lookup_buffer (vlib_buffer_t * b, session_dgram_hdr_t * hdr,
                                udp->src_port, TRANSPORT_PROTO_UDP);
     }
 
+  /* Set the sw_if_index[VLIB_RX] to the interface we received
+   * the connection on (the local interface) */
+  vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->ip.rx_sw_if_index;
+
   if (PREDICT_TRUE (!(b->flags & VLIB_BUFFER_NEXT_PRESENT)))
     b->current_length = hdr->data_length;
   else
@@ -225,10 +241,9 @@ always_inline uword
 udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                    vlib_frame_t * frame, u8 is_ip4)
 {
-  u32 n_left_from, *from, errors, *first_buffer;
+  u32 thread_index = vm->thread_index, n_left_from, *from, *first_buffer;
   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
   u16 err_counters[UDP_N_ERROR] = { 0 };
-  u32 thread_index = vm->thread_index;
 
   from = first_buffer = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -250,15 +265,11 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          goto done;
        }
 
-      /*
-       * If session exists pool peeker lock is taken at this point unless
-       * the session is already on the right thread or is a listener
-       */
-
       if (s0->session_state == SESSION_STATE_OPENED)
        {
          u8 queue_event = 1;
          uc0 = udp_connection_from_transport (session_get_transport (s0));
+         uc0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
          if (uc0->flags & UDP_CONN_F_CONNECTED)
            {
              if (s0->thread_index != thread_index)
@@ -272,10 +283,8 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                  ASSERT (s0->session_index == uc0->c_s_index);
 
                  /*
-                  * Drop the peeker lock on pool resize and ask session
-                  * layer for a new session.
+                  * Ask session layer for a new session.
                   */
-                 session_pool_remove_peeker (s0->thread_index);
                  session_dgram_connect_notify (&uc0->connection,
                                                s0->thread_index, &s0);
                  queue_event = 0;
@@ -285,9 +294,9 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            }
          udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0],
                                  queue_event, &error0);
-         session_pool_remove_peeker (s0->thread_index);
        }
-      else if (s0->session_state == SESSION_STATE_READY)
+      else if (s0->session_state == SESSION_STATE_READY ||
+              s0->session_state == SESSION_STATE_ACCEPTING)
        {
          uc0 = udp_connection_from_transport (session_get_transport (s0));
          udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0], 1,
@@ -305,6 +314,7 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                  goto done;
                }
              s0 = session_get (uc0->c_s_index, uc0->c_thread_index);
+             uc0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
              error0 = UDP_ERROR_ACCEPT;
            }
          udp_connection_enqueue (uc0, s0, &hdr0, thread_index, b[0], 1,
@@ -313,24 +323,20 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       else
        {
          error0 = UDP_ERROR_NOT_READY;
-         session_pool_remove_peeker (s0->thread_index);
        }
 
     done:
+      if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
+       udp_trace_buffer (vm, node, b[0], s0, error0);
 
       b += 1;
       n_left_from -= 1;
 
       udp_inc_err_counter (err_counters, error0, 1);
-
-      if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
-       udp_trace_buffer (vm, node, b[0], s0, error0);
     }
 
   vlib_buffer_free (vm, first_buffer, frame->n_vectors);
-  errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_UDP,
-                                             thread_index);
-  err_counters[UDP_ERROR_MQ_FULL] = errors;
+  session_main_flush_enqueue_events (TRANSPORT_PROTO_UDP, thread_index);
   udp_store_err_counters (vm, is_ip4, err_counters);
   return frame->n_vectors;
 }
@@ -342,7 +348,6 @@ udp4_input (vlib_main_t * vm, vlib_node_runtime_t * node,
   return udp46_input_inline (vm, node, frame, 1);
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (udp4_input_node) =
 {
   .function = udp4_input,
@@ -350,8 +355,8 @@ VLIB_REGISTER_NODE (udp4_input_node) =
   .vector_size = sizeof (u32),
   .format_trace = format_udp_input_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = ARRAY_LEN (udp_error_strings),
-  .error_strings = udp_error_strings,
+  .n_errors = UDP_N_ERROR,
+  .error_counters = udp_error_counters,
   .n_next_nodes = UDP_INPUT_N_NEXT,
   .next_nodes = {
 #define _(s, n) [UDP_INPUT_NEXT_##s] = n,
@@ -359,7 +364,6 @@ VLIB_REGISTER_NODE (udp4_input_node) =
 #undef _
   },
 };
-/* *INDENT-ON* */
 
 static uword
 udp6_input (vlib_main_t * vm, vlib_node_runtime_t * node,
@@ -368,7 +372,6 @@ udp6_input (vlib_main_t * vm, vlib_node_runtime_t * node,
   return udp46_input_inline (vm, node, frame, 0);
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (udp6_input_node) =
 {
   .function = udp6_input,
@@ -376,8 +379,8 @@ VLIB_REGISTER_NODE (udp6_input_node) =
   .vector_size = sizeof (u32),
   .format_trace = format_udp_input_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = ARRAY_LEN (udp_error_strings),
-  .error_strings = udp_error_strings,
+  .n_errors = UDP_N_ERROR,
+  .error_counters = udp_error_counters,
   .n_next_nodes = UDP_INPUT_N_NEXT,
   .next_nodes = {
 #define _(s, n) [UDP_INPUT_NEXT_##s] = n,
@@ -385,7 +388,6 @@ VLIB_REGISTER_NODE (udp6_input_node) =
 #undef _
   },
 };
-/* *INDENT-ON* */
 
 /*
  * fd.io coding-style-patch-verification: ON