ip: punt redirect add nh in api
[vpp.git] / src / vnet / ip / ip6_punt_drop.c
index a1f0ebe..4edb673 100644 (file)
@@ -28,11 +28,38 @@ VNET_FEATURE_ARC_INIT (ip6_punt) =
 VNET_FEATURE_ARC_INIT (ip6_drop) =
 {
   .arc_name  = "ip6-drop",
-  .start_nodes = VNET_FEATURES ("ip6-drop"),
+  .start_nodes = VNET_FEATURES ("ip6-drop", "ip6-not-enabled"),
 };
 /* *INDENT-ON* */
 
+extern ip_punt_policer_t ip6_punt_policer_cfg;
+
+#ifndef CLIB_MARCH_VARIANT
 ip_punt_policer_t ip6_punt_policer_cfg;
+#endif /* CLIB_MARCH_VARIANT */
+
+static char *ip6_punt_policer_handoff_error_strings[] = { "congestion drop" };
+
+VLIB_NODE_FN (ip6_punt_policer_handoff_node)
+(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
+{
+  return policer_handoff (vm, node, frame, ip6_punt_policer_cfg.fq_index,
+                         ip6_punt_policer_cfg.policer_index);
+}
+
+VLIB_REGISTER_NODE (ip6_punt_policer_handoff_node) = {
+  .name = "ip6-punt-policer-handoff",
+  .vector_size = sizeof (u32),
+  .format_trace = format_policer_handoff_trace,
+  .type = VLIB_NODE_TYPE_INTERNAL,
+  .n_errors = ARRAY_LEN(ip6_punt_policer_handoff_error_strings),
+  .error_strings = ip6_punt_policer_handoff_error_strings,
+
+  .n_next_nodes = 1,
+  .next_nodes = {
+    [0] = "error-drop",
+  },
+};
 
 static char *ip6_punt_policer_error_strings[] = {
 #define _(sym,string) string,
@@ -40,9 +67,9 @@ static char *ip6_punt_policer_error_strings[] = {
 #undef _
 };
 
-static uword
-ip6_punt_policer (vlib_main_t * vm,
-                 vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_punt_policer_node) (vlib_main_t * vm,
+                                     vlib_node_runtime_t * node,
+                                     vlib_frame_t * frame)
 {
   return (ip_punt_policer (vm, node, frame,
                           vnet_feat_arc_ip6_punt.feature_arc_index,
@@ -52,8 +79,7 @@ ip6_punt_policer (vlib_main_t * vm,
 
 /* *INDENT-OFF* */
 
-VLIB_REGISTER_NODE (ip6_punt_policer_node, static) = {
-  .function = ip6_punt_policer,
+VLIB_REGISTER_NODE (ip6_punt_policer_node) = {
   .name = "ip6-punt-policer",
   .vector_size = sizeof (u32),
   .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
@@ -64,12 +90,10 @@ VLIB_REGISTER_NODE (ip6_punt_policer_node, static) = {
   /* edit / add dispositions here */
   .next_nodes = {
     [IP_PUNT_POLICER_NEXT_DROP] = "ip6-drop",
+    [IP_PUNT_POLICER_NEXT_HANDOFF] = "ip6-punt-policer-handoff",
   },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_policer_node,
-                              ip6_punt_policer);
-
 VNET_FEATURE_INIT (ip6_punt_policer_node, static) = {
   .arc_name = "ip6-punt",
   .node_name = "ip6-punt-policer",
@@ -77,8 +101,20 @@ VNET_FEATURE_INIT (ip6_punt_policer_node, static) = {
 };
 /* *INDENT-ON* */
 
-static uword
-ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+                             vlib_frame_t * frame)
+{
+  if (node->flags & VLIB_NODE_FLAG_TRACE)
+    ip6_forward_next_trace (vm, node, frame, VLIB_TX);
+
+  return ip_drop_or_punt (vm, node, frame,
+                         vnet_feat_arc_ip6_drop.feature_arc_index);
+
+}
+
+VLIB_NODE_FN (ip6_not_enabled_node) (vlib_main_t * vm,
+                                    vlib_node_runtime_t * node,
+                                    vlib_frame_t * frame)
 {
   if (node->flags & VLIB_NODE_FLAG_TRACE)
     ip6_forward_next_trace (vm, node, frame, VLIB_TX);
@@ -88,8 +124,8 @@ ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
 
 }
 
-static uword
-ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_punt_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+                             vlib_frame_t * frame)
 {
   if (node->flags & VLIB_NODE_FLAG_TRACE)
     ip6_forward_next_trace (vm, node, frame, VLIB_TX);
@@ -99,9 +135,8 @@ ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
 }
 
 /* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ip6_drop_node, static) =
+VLIB_REGISTER_NODE (ip6_drop_node) =
 {
-  .function = ip6_drop,
   .name = "ip6-drop",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_forward_next_trace,
@@ -111,11 +146,19 @@ VLIB_REGISTER_NODE (ip6_drop_node, static) =
   },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
+VLIB_REGISTER_NODE (ip6_not_enabled_node) =
+{
+  .name = "ip6-not-enabled",
+  .vector_size = sizeof (u32),
+  .format_trace = format_ip6_forward_next_trace,
+  .n_next_nodes = 1,
+  .next_nodes = {
+    [0] = "error-drop",
+  },
+};
 
-VLIB_REGISTER_NODE (ip6_punt_node, static) =
+VLIB_REGISTER_NODE (ip6_punt_node) =
 {
-  .function = ip6_punt,
   .name = "ip6-punt",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_forward_next_trace,
@@ -125,8 +168,6 @@ VLIB_REGISTER_NODE (ip6_punt_node, static) =
   },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
-
 VNET_FEATURE_INIT (ip6_punt_end_of_arc, static) = {
   .arc_name = "ip6-punt",
   .node_name = "error-punt",
@@ -140,6 +181,7 @@ VNET_FEATURE_INIT (ip6_drop_end_of_arc, static) = {
 };
 /* *INDENT-ON */
 
+#ifndef CLIB_MARCH_VARIANT
 void
 ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
 {
@@ -148,6 +190,7 @@ ip6_punt_policer_add_del (u8 is_add, u32 policer_index)
   vnet_feature_enable_disable ("ip6-punt", "ip6-punt-policer",
                                0, is_add, 0, 0);
 }
+#endif /* CLIB_MARCH_VARIANT */
 
 static clib_error_t *
 ip6_punt_police_cmd (vlib_main_t * vm,
@@ -207,14 +250,8 @@ VLIB_CLI_COMMAND (ip6_punt_policer_command, static) =
   .function = ip6_punt_police_cmd,
   .short_help = "ip6 punt policer [add|del] <index>",
 };
-/* *INDENT-ON* */
 
-ip_punt_redirect_t ip6_punt_redirect_cfg = {
-  .any_rx_sw_if_index = {
-                        .tx_sw_if_index = ~0,
-                        }
-  ,
-};
+/* *INDENT-ON* */
 
 #define foreach_ip6_punt_redirect_error         \
 _(DROP, "ip6 punt redirect drop")
@@ -233,18 +270,17 @@ static char *ip6_punt_redirect_error_strings[] = {
 #undef _
 };
 
-static uword
-ip6_punt_redirect (vlib_main_t * vm,
-                  vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_punt_redirect_node) (vlib_main_t * vm,
+                                      vlib_node_runtime_t * node,
+                                      vlib_frame_t * frame)
 {
   return (ip_punt_redirect (vm, node, frame,
                            vnet_feat_arc_ip6_punt.feature_arc_index,
-                           &ip6_punt_redirect_cfg));
+                           FIB_PROTOCOL_IP6));
 }
 
 /* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ip6_punt_redirect_node, static) = {
-  .function = ip6_punt_redirect,
+VLIB_REGISTER_NODE (ip6_punt_redirect_node) = {
   .name = "ip6-punt-redirect",
   .vector_size = sizeof (u32),
   .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
@@ -260,9 +296,6 @@ VLIB_REGISTER_NODE (ip6_punt_redirect_node, static) = {
   },
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_redirect_node,
-                              ip6_punt_redirect);
-
 VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
   .arc_name = "ip6-punt",
   .node_name = "ip6-punt-redirect",
@@ -270,17 +303,15 @@ VNET_FEATURE_INIT (ip6_punt_redirect_node, static) = {
 };
 /* *INDENT-ON* */
 
+#ifndef CLIB_MARCH_VARIANT
+
 void
-ip6_punt_redirect_add (u32 rx_sw_if_index,
-                      u32 tx_sw_if_index, ip46_address_t * nh)
+ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
+                            const fib_route_path_t *rpaths)
 {
-  ip_punt_redirect_rx_t rx = {
-    .tx_sw_if_index = tx_sw_if_index,
-    .nh = *nh,
-  };
-
-  ip_punt_redirect_add (&ip6_punt_redirect_cfg,
-                       rx_sw_if_index, &rx, FIB_PROTOCOL_IP6, VNET_LINK_IP6);
+  ip_punt_redirect_add (FIB_PROTOCOL_IP6,
+                       rx_sw_if_index,
+                       FIB_FORW_CHAIN_TYPE_UNICAST_IP6, rpaths);
 
   vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 1, 0, 0);
 }
@@ -290,8 +321,9 @@ ip6_punt_redirect_del (u32 rx_sw_if_index)
 {
   vnet_feature_enable_disable ("ip6-punt", "ip6-punt-redirect", 0, 0, 0, 0);
 
-  ip_punt_redirect_del (&ip6_punt_redirect_cfg, rx_sw_if_index);
+  ip_punt_redirect_del (FIB_PROTOCOL_IP6, rx_sw_if_index);
 }
+#endif /* CLIB_MARCH_VARIANT */
 
 static clib_error_t *
 ip6_punt_redirect_cmd (vlib_main_t * vm,
@@ -299,10 +331,10 @@ ip6_punt_redirect_cmd (vlib_main_t * vm,
                       vlib_cli_command_t * cmd)
 {
   unformat_input_t _line_input, *line_input = &_line_input;
+  fib_route_path_t *rpaths = NULL, rpath;
+  dpo_proto_t payload_proto = DPO_PROTO_IP6;
   clib_error_t *error = 0;
-  u32 rx_sw_if_index;
-  u32 tx_sw_if_index;
-  ip46_address_t nh;
+  u32 rx_sw_if_index = ~0;
   vnet_main_t *vnm;
   u8 is_add;
 
@@ -319,18 +351,13 @@ ip6_punt_redirect_cmd (vlib_main_t * vm,
       else if (unformat (line_input, "add"))
        is_add = 1;
       else if (unformat (line_input, "rx all"))
-       rx_sw_if_index = ~0;
+       rx_sw_if_index = 0;
       else if (unformat (line_input, "rx %U",
                         unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
        ;
-      else if (unformat (line_input, "via %U %U",
-                        unformat_ip6_address,
-                        &nh.ip6,
-                        unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
-       ;
       else if (unformat (line_input, "via %U",
-                        unformat_vnet_sw_interface, vnm, &tx_sw_if_index))
-       memset (&nh, 0, sizeof (nh));
+                        unformat_fib_route_path, &rpath, &payload_proto))
+       vec_add1 (rpaths, rpath);
       else
        {
          error = unformat_parse_error (line_input);
@@ -338,12 +365,24 @@ ip6_punt_redirect_cmd (vlib_main_t * vm,
        }
     }
 
+  if (~0 == rx_sw_if_index)
+    {
+      error = unformat_parse_error (line_input);
+      goto done;
+    }
+
   if (is_add)
-    ip6_punt_redirect_add (rx_sw_if_index, tx_sw_if_index, &nh);
+    {
+      if (vec_len (rpaths))
+       ip6_punt_redirect_add_paths (rx_sw_if_index, rpaths);
+    }
   else
-    ip6_punt_redirect_del (rx_sw_if_index);
+    {
+      ip6_punt_redirect_del (rx_sw_if_index);
+    }
 
 done:
+  vec_free (rpaths);
   unformat_free (line_input);
   return (error);
 }
@@ -362,12 +401,16 @@ VLIB_CLI_COMMAND (ip6_punt_redirect_command, static) =
 };
 /* *INDENT-ON* */
 
+#ifndef CLIB_MARCH_VARIANT
+
+#endif /* CLIB_MARCH_VARIANT */
+
 static clib_error_t *
 ip6_punt_redirect_show_cmd (vlib_main_t * vm,
                            unformat_input_t * main_input,
                            vlib_cli_command_t * cmd)
 {
-  vlib_cli_output (vm, "%U", format_ip_punt_redirect, &ip6_punt_redirect_cfg);
+  vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP6);
 
   return (NULL);
 }
@@ -382,7 +425,7 @@ VLIB_CLI_COMMAND (show_ip6_punt_redirect_command, static) =
 {
   .path = "show ip6 punt redirect",
   .function = ip6_punt_redirect_show_cmd,
-  .short_help = "show ip6 punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
+  .short_help = "show ip6 punt redirect",
   .is_mp_safe = 1,
 };
 /* *INDENT-ON* */