api: binary api cleanup
[vpp.git] / src / vnet / l2 / l2_vtr.c
index 95a4f15..bfd1dcb 100644 (file)
@@ -61,7 +61,7 @@ l2pbb_configure (vlib_main_t * vlib_main,
 
   l2_output_config_t *config = 0;
   vnet_hw_interface_t *hi;
-  hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index);
+  hi = vnet_get_sup_hw_interface_api_visible_or_null (vnet_main, sw_if_index);
 
   if (!hi)
     {
@@ -91,10 +91,10 @@ l2pbb_configure (vlib_main_t * vlib_main,
     }
   else if (vtr_op == L2_VTR_PUSH_2)
     {
-      clib_memcpy (in_config->macs_tags.b_dst_address, b_dmac,
-                  sizeof (in_config->macs_tags.b_dst_address));
-      clib_memcpy (in_config->macs_tags.b_src_address, b_smac,
-                  sizeof (in_config->macs_tags.b_src_address));
+      clib_memcpy_fast (in_config->macs_tags.b_dst_address, b_dmac,
+                       sizeof (in_config->macs_tags.b_dst_address));
+      clib_memcpy_fast (in_config->macs_tags.b_src_address, b_smac,
+                       sizeof (in_config->macs_tags.b_src_address));
       in_config->macs_tags.b_type =
        clib_net_to_host_u16 (ETHERNET_TYPE_DOT1AD);
       in_config->macs_tags.priority_dei_id =
@@ -149,7 +149,7 @@ l2vtr_configure (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_ind
   u32 push_outer_et;
   u32 cfg_tags;
 
-  hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index);
+  hi = vnet_get_sup_hw_interface_api_visible_or_null (vnet_main, sw_if_index);
   if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index))
     {
       error = VNET_API_ERROR_INVALID_INTERFACE;        /* non-ethernet interface */
@@ -177,7 +177,7 @@ l2vtr_configure (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_ind
   vtr_tag1 = clib_net_to_host_u16 (vtr_tag1);
   vtr_tag2 = clib_net_to_host_u16 (vtr_tag2);
 
-  /* Determine number of vlan tags with explictly configured values */
+  /* Determine number of vlan tags with explicitly configured values */
   cfg_tags = 0;
   if (hw_no_tags || si->sub.eth.flags.no_tags)
     {
@@ -229,9 +229,6 @@ l2vtr_configure (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_ind
        }
       in_config->pop_bytes = 8;
       in_config->push_bytes = 0;
-
-      out_config->push_bytes = in_config->pop_bytes;
-      out_config->pop_bytes = in_config->push_bytes;
       break;
 
     case L2_VTR_PUSH_1:
@@ -367,7 +364,7 @@ l2vtr_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, u3
   *vtr_tag2 = 0;
   *push_dot1q = 0;
 
-  hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index);
+  hi = vnet_get_sup_hw_interface_api_visible_or_null (vnet_main, sw_if_index);
   if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index))
     {
       /* non-ethernet interface */
@@ -681,6 +678,72 @@ VLIB_CLI_COMMAND (int_l2_vtr_cli, static) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * Get pbb tag rewrite on the given interface.
+ * Return 1 if there is an error, 0 if ok
+ */
+u32
+l2pbb_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index,
+          u32 * vtr_op, u16 * outer_tag, ethernet_header_t * eth_hdr,
+          u16 * b_vlanid, u32 * i_sid)
+{
+  u32 error = 1;
+  ptr_config_t *in_config;
+
+  if (!vtr_op || !outer_tag || !b_vlanid || !i_sid)
+    {
+      clib_warning ("invalid arguments");
+      error = VNET_API_ERROR_INVALID_ARGUMENT;
+      goto done;
+    }
+
+  *vtr_op = L2_VTR_DISABLED;
+  *outer_tag = 0;
+  *b_vlanid = 0;
+  *i_sid = 0;
+
+  if (sw_if_index >= vec_len (l2output_main.configs))
+    {
+      /* no specific config (return disabled) */
+      goto done;
+    }
+
+  /* Get the config for this interface */
+  in_config =
+    &(vec_elt_at_index (l2output_main.configs, sw_if_index)->input_pbb_vtr);
+
+  if (in_config->push_and_pop_bytes == 0)
+    {
+      /* DISABLED */
+      goto done;
+    }
+  else
+    {
+      if (in_config->pop_bytes && in_config->push_bytes)
+       *vtr_op = L2_VTR_TRANSLATE_2_1;
+      else if (in_config->pop_bytes)
+       *vtr_op = L2_VTR_POP_2;
+      else if (in_config->push_bytes)
+       *vtr_op = L2_VTR_PUSH_2;
+
+      clib_memcpy_fast (&eth_hdr->dst_address,
+                       in_config->macs_tags.b_dst_address,
+                       sizeof (eth_hdr->dst_address));
+      clib_memcpy_fast (&eth_hdr->src_address,
+                       in_config->macs_tags.b_src_address,
+                       sizeof (eth_hdr->src_address));
+
+      *b_vlanid =
+       clib_host_to_net_u16 (in_config->macs_tags.priority_dei_id) & 0xFFF;
+      *i_sid =
+       clib_host_to_net_u32 (in_config->macs_tags.
+                             priority_dei_uca_res_sid) & 0xFFFFF;
+      error = 0;
+    }
+done:
+  return error;
+}
+
 /**
  * Set subinterface pbb vtr enable/disable.
  * The CLI format is: