hs-test: fix LDPreloadIperfVppTest
[vpp.git] / src / vnet / unix / tuntap.c
index 103b649..f1102dc 100644 (file)
@@ -172,7 +172,7 @@ tuntap_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
 
       /* Re-set iovecs if present. */
       if (tm->threads[thread_index].iovecs)
-       _vec_len (tm->threads[thread_index].iovecs) = 0;
+       vec_set_len (tm->threads[thread_index].iovecs, 0);
 
       /** VLIB buffer chain -> Unix iovec(s). */
       vec_add2 (tm->threads[thread_index].iovecs, iov, 1);
@@ -217,14 +217,12 @@ tuntap_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
   return n_packets;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (tuntap_tx_node,static) = {
   .function = tuntap_tx,
   .name = "tuntap-tx",
   .type = VLIB_NODE_TYPE_INTERNAL,
   .vector_size = 4,
 };
-/* *INDENT-ON* */
 
 /**
  * @brief TUNTAP receive node
@@ -260,7 +258,7 @@ tuntap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          vlib_buffer_alloc (vm,
                             tm->threads[thread_index].rx_buffers + n_left,
                             VLIB_FRAME_SIZE - n_left);
-       _vec_len (tm->threads[thread_index].rx_buffers) = n_left + n_alloc;
+       vec_set_len (tm->threads[thread_index].rx_buffers, n_left + n_alloc);
       }
   }
 
@@ -324,7 +322,7 @@ tuntap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
        + VNET_INTERFACE_COUNTER_RX,
        thread_index, tm->sw_if_index, 1, n_bytes_in_packet);
 
-    _vec_len (tm->threads[thread_index].rx_buffers) = i_rx;
+    vec_set_len (tm->threads[thread_index].rx_buffers, i_rx);
   }
 
   b = vlib_get_buffer (vm, bi);
@@ -336,14 +334,6 @@ tuntap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
     vnet_buffer (b)->sw_if_index[VLIB_RX] = tm->sw_if_index;
     vnet_buffer (b)->sw_if_index[VLIB_TX] = (u32) ~ 0;
 
-    /*
-     * Turn this on if you run into
-     * "bad monkey" contexts, and you want to know exactly
-     * which nodes they've visited...
-     */
-    if (VLIB_BUFFER_TRACE_TRAJECTORY)
-      b->pre_data[0] = 0;
-
     b->error = node->errors[0];
 
     if (tm->is_ether)
@@ -374,15 +364,13 @@ tuntap_rx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          next_index = VNET_DEVICE_INPUT_NEXT_DROP;
       }
 
-    vnet_feature_start_device_input_x1 (tm->sw_if_index, &next_index, b);
+    vnet_feature_start_device_input (tm->sw_if_index, &next_index, b);
 
     vlib_set_next_frame_buffer (vm, node, next_index, bi);
 
-    if (n_trace > 0)
-      {
-       vlib_trace_buffer (vm, node, next_index, b, /* follow_chain */ 1);
-       vlib_set_trace_count (vm, node, n_trace - 1);
-      }
+    if (PREDICT_FALSE (n_trace > 0 && vlib_trace_buffer (vm, node, next_index, b,      /* follow_chain */
+                                                        1)))
+      vlib_set_trace_count (vm, node, n_trace - 1);
   }
 
   return 1;
@@ -395,9 +383,9 @@ static char *tuntap_rx_error_strings[] = {
   "unknown packet type",
 };
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (tuntap_rx_node,static) = {
   .function = tuntap_rx,
+  .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED,
   .name = "tuntap-rx",
   .sibling_of = "device-input",
   .type = VLIB_NODE_TYPE_INPUT,
@@ -406,7 +394,6 @@ VLIB_REGISTER_NODE (tuntap_rx_node,static) = {
   .n_errors = 1,
   .error_strings = tuntap_rx_error_strings,
 };
-/* *INDENT-ON* */
 
 /**
  * @brief Gets called when file descriptor is ready from epoll.
@@ -633,12 +620,12 @@ tuntap_config (vlib_main_t * vm, unformat_input_t * input)
   if (have_normal_interface)
     {
       vnet_main_t *vnm = vnet_get_main ();
-      error = ethernet_register_interface
-       (vnm, tuntap_dev_class.index, 0 /* device instance */ ,
-        tm->ether_dst_mac /* ethernet address */ ,
-        &tm->hw_if_index, 0 /* flag change */ );
-      if (error)
-       clib_error_report (error);
+      vnet_eth_interface_registration_t eir = {};
+
+      eir.dev_class_index = tuntap_dev_class.index;
+      eir.address = tm->ether_dst_mac;
+      tm->hw_if_index = vnet_eth_register_interface (vnm, &eir);
+
       tm->sw_if_index = tm->hw_if_index;
       vm->os_punt_frame = tuntap_nopunt_frame;
     }
@@ -666,6 +653,7 @@ tuntap_config (vlib_main_t * vm, unformat_input_t * input)
     clib_file_t template = { 0 };
     template.read_function = tuntap_read_ready;
     template.file_descriptor = tm->dev_net_tun_fd;
+    template.description = format (0, "vnet tuntap");
     tm->clib_file_index = clib_file_add (&file_main, &template);
   }
 
@@ -920,7 +908,7 @@ tuntap_punt_frame (vlib_main_t * vm,
                   vlib_node_runtime_t * node, vlib_frame_t * frame)
 {
   tuntap_tx (vm, node, frame);
-  vlib_frame_free (vm, node, frame);
+  vlib_frame_free (vm, frame);
 }
 
 /**
@@ -938,15 +926,13 @@ tuntap_nopunt_frame (vlib_main_t * vm,
   u32 *buffers = vlib_frame_vector_args (frame);
   uword n_packets = frame->n_vectors;
   vlib_buffer_free (vm, buffers, n_packets);
-  vlib_frame_free (vm, node, frame);
+  vlib_frame_free (vm, frame);
 }
 
-/* *INDENT-OFF* */
 VNET_HW_INTERFACE_CLASS (tuntap_interface_class,static) = {
   .name = "tuntap",
   .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
 };
-/* *INDENT-ON* */
 
 /**
  * @brief Format tun/tap interface name
@@ -992,13 +978,11 @@ tuntap_intfc_tx (vlib_main_t * vm,
   return n_buffers;
 }
 
-/* *INDENT-OFF* */
 VNET_DEVICE_CLASS (tuntap_dev_class,static) = {
   .name = "tuntap",
   .tx_function = tuntap_intfc_tx,
   .format_device_name = format_tuntap_interface_name,
 };
-/* *INDENT-ON* */
 
 /**
  * @brief tun/tap node init
@@ -1011,7 +995,6 @@ VNET_DEVICE_CLASS (tuntap_dev_class,static) = {
 static clib_error_t *
 tuntap_init (vlib_main_t * vm)
 {
-  clib_error_t *error;
   ip4_main_t *im4 = &ip4_main;
   ip6_main_t *im6 = &ip6_main;
   ip4_add_del_interface_address_callback_t cb4;
@@ -1019,10 +1002,6 @@ tuntap_init (vlib_main_t * vm)
   tuntap_main_t *tm = &tuntap_main;
   vlib_thread_main_t *m = vlib_get_thread_main ();
 
-  error = vlib_call_init_function (vm, ip4_init);
-  if (error)
-    return error;
-
   mhash_init (&tm->subif_mhash, sizeof (u32), sizeof (subif_address_t));
 
   cb4.function = tuntap_ip4_add_del_interface_address;
@@ -1038,7 +1017,10 @@ tuntap_init (vlib_main_t * vm)
   return 0;
 }
 
-VLIB_INIT_FUNCTION (tuntap_init);
+VLIB_INIT_FUNCTION (tuntap_init) =
+{
+  .runs_after = VLIB_INITS("ip4_init"),
+};
 
 /*
  * fd.io coding-style-patch-verification: ON