docs: vnet comment nitfixes
[vpp.git] / src / vnet / mpls / interface.c
index ec541f7..e6c3dfe 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include <vnet/vnet.h>
-#include <vnet/pg/pg.h>
 #include <vnet/mpls/mpls.h>
 #include <vnet/fib/mpls_fib.h>
 #include <vnet/fib/ip4_fib.h>
@@ -42,6 +41,8 @@ mpls_sw_interface_enable_disable (mpls_main_t * mm,
                                   u8 is_api)
 {
   fib_node_index_t lfib_index;
+  vnet_main_t *vnm = vnet_get_main ();
+  vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
 
   vec_validate_init_empty (mm->mpls_enabled_by_sw_if_index, sw_if_index, 0);
 
@@ -62,7 +63,7 @@ mpls_sw_interface_enable_disable (mpls_main_t * mm,
       fib_table_lock(lfib_index, FIB_PROTOCOL_MPLS,
                      (is_api? FIB_SOURCE_API: FIB_SOURCE_CLI));
 
-      vec_validate(mm->fib_index_by_sw_if_index, 0);
+      vec_validate(mm->fib_index_by_sw_if_index, sw_if_index);
       mm->fib_index_by_sw_if_index[sw_if_index] = lfib_index;
     }
   else
@@ -79,6 +80,11 @@ mpls_sw_interface_enable_disable (mpls_main_t * mm,
   vnet_feature_enable_disable ("mpls-input", "mpls-not-enabled",
                                sw_if_index, !is_enable, 0, 0);
 
+  if (is_enable)
+    hi->l3_if_count++;
+  else if (hi->l3_if_count)
+    hi->l3_if_count--;
+
   return (0);
 }
 
@@ -122,7 +128,7 @@ mpls_interface_enable_disable (vlib_main_t * vm,
 }
 
 /*?
- * This command enables an interface to accpet MPLS packets
+ * This command enables an interface to accept MPLS packets
  *
  * @cliexpar
  * @cliexstart{set interface mpls}
@@ -134,3 +140,72 @@ VLIB_CLI_COMMAND (set_interface_ip_table_command, static) = {
   .function = mpls_interface_enable_disable,
   .short_help = "Enable/Disable an interface for MPLS forwarding",
 };
+
+static void
+show_mpls_one_interface (vnet_main_t *vnm, vlib_main_t *vm, u32 sw_if_index,
+                        bool verbose)
+{
+  mpls_main_t *mm = &mpls_main;
+  u8 enabled;
+
+  enabled = mm->mpls_enabled_by_sw_if_index[sw_if_index];
+
+  if (enabled)
+    {
+      vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnm,
+                      sw_if_index);
+      vlib_cli_output (vm, "  MPLS enabled");
+    }
+  else if (verbose)
+    {
+      vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnm,
+                      sw_if_index);
+      vlib_cli_output (vm, "  MPLS disabled");
+    }
+}
+
+static walk_rc_t
+show_mpls_interface_walk (vnet_main_t *vnm, vnet_sw_interface_t *si, void *ctx)
+{
+  show_mpls_one_interface (vnm, ctx, si->sw_if_index, false);
+
+  return (WALK_CONTINUE);
+}
+
+static clib_error_t *
+show_mpls_interface (vlib_main_t *vm, unformat_input_t *input,
+                    vlib_cli_command_t *cmd)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  u32 sw_if_index;
+
+  sw_if_index = ~0;
+
+  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
+    ;
+
+  if (~0 == sw_if_index)
+    {
+      vnet_sw_interface_walk (vnm, show_mpls_interface_walk, vm);
+    }
+  else
+    {
+      show_mpls_one_interface (vnm, vm, sw_if_index, true);
+    }
+
+  return NULL;
+}
+
+/*?
+ * This command displays the MPLS forwarding state of an interface
+ *
+ * @cliexpar
+ * @cliexstart{show mpls interface}
+ *  set mpls interface GigEthernet0/8/0
+ * @cliexend
+ ?*/
+VLIB_CLI_COMMAND (show_mpls_interface_command, static) = {
+  .path = "show mpls interface",
+  .function = show_mpls_interface,
+  .short_help = "Show MPLS interface forwarding",
+};