VPP-19: Split the lookup.h IP_LOOKUP_NEXT enum.
[vpp.git] / vnet / vnet / ip / ip6_forward.c
index 43d8350..e49d242 100644 (file)
@@ -378,6 +378,8 @@ ip6_add_del_route_next_hop (ip6_main_t * im,
             else
             {
              ip_adjacency_t add_adj;
+             memset (&add_adj, 0, sizeof(add_adj));
+             add_adj.n_adj = 1;
              add_adj.lookup_next_index = IP_LOOKUP_NEXT_INDIRECT;
              add_adj.indirect.next_hop.ip6.as_u64[0] = next_hop->as_u64[0];
              add_adj.indirect.next_hop.ip6.as_u64[1] = next_hop->as_u64[1];
@@ -676,9 +678,6 @@ ip6_lookup_inline (vlib_main_t * vm,
   n_left_from = frame->n_vectors;
   next = node->cached_next_index;
 
-  if (node->flags & VLIB_NODE_FLAG_TRACE)
-    ip6_forward_next_trace(vm, node, frame, VLIB_TX);
-
   while (n_left_from > 0)
     {
       vlib_get_next_frame (vm, node, next,
@@ -763,9 +762,9 @@ ip6_lookup_inline (vlib_main_t * vm,
 
          /* Only process the HBH Option Header if explicitly configured to do so */
           next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index0 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
+           adj_index0 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
           next1 = (ip1->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index1 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj1->lookup_next_index;
+           adj_index1 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj1->lookup_next_index;
 
           vnet_buffer (p0)->ip.flow_hash = 
             vnet_buffer(p1)->ip.flow_hash = 0;
@@ -894,7 +893,7 @@ ip6_lookup_inline (vlib_main_t * vm,
 
          /* Only process the HBH Option Header if explicitly configured to do so */
           next0 = (ip0->protocol == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) && im->hbh_enabled &&
-           adj_index0 ? IP_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
+           adj_index0 ? IP6_LOOKUP_NEXT_HOP_BY_HOP : adj0->lookup_next_index;
 
           vnet_buffer (p0)->ip.flow_hash = 0;
 
@@ -937,6 +936,9 @@ ip6_lookup_inline (vlib_main_t * vm,
       vlib_put_next_frame (vm, node, next, n_left_to_next);
     }
 
+  if (node->flags & VLIB_NODE_FLAG_TRACE)
+      ip6_forward_next_trace(vm, node, frame, VLIB_TX);
+
   return frame->n_vectors;
 }
 
@@ -1260,16 +1262,16 @@ ip6_lookup (vlib_main_t * vm,
   return ip6_lookup_inline (vm, node, frame, /* is_indirect */ 0);
 }
 
-static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args);
+static u8 * format_ip6_lookup_trace (u8 * s, va_list * args);
 
 VLIB_REGISTER_NODE (ip6_lookup_node) = {
   .function = ip6_lookup,
   .name = "ip6-lookup",
   .vector_size = sizeof (u32),
 
-  .format_trace = format_ip6_forward_next_trace,
+  .format_trace = format_ip6_lookup_trace,
 
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
+  .n_next_nodes = IP6_LOOKUP_N_NEXT,
   .next_nodes = IP6_LOOKUP_NEXT_NODES,
 };
 
@@ -1288,11 +1290,9 @@ VLIB_REGISTER_NODE (ip6_indirect_node) = {
   .function = ip6_indirect,
   .name = "ip6-indirect",
   .vector_size = sizeof (u32),
-
-  .format_trace = format_ip6_forward_next_trace,
-
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = IP6_LOOKUP_NEXT_NODES,
+  .sibling_of = "ip6-lookup",
+  .format_trace = format_ip6_lookup_trace,
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_indirect_node, ip6_indirect)
@@ -1309,39 +1309,53 @@ typedef struct {
 
 static u8 * format_ip6_forward_next_trace (u8 * s, va_list * args)
 {
-  vlib_main_t * vm = va_arg (*args, vlib_main_t *);
-  vlib_node_t * node = va_arg (*args, vlib_node_t *);
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+  uword indent = format_get_indent (s);
+
+  s = format(s, "%U%U",
+             format_white_space, indent,
+             format_ip6_header, t->packet_data);
+  return s;
+}
+
+static u8 * format_ip6_lookup_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
   ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
   vnet_main_t * vnm = vnet_get_main();
   ip6_main_t * im = &ip6_main;
-  ip_adjacency_t * adj;
   uword indent = format_get_indent (s);
 
-  char *fib_or_interface = "fib";
-  if ((node == vlib_get_node(vm, ip6_rewrite_node.index)) ||
-      (node == vlib_get_node(vm, ip6_rewrite_local_node.index))) {
-    fib_or_interface = "tx_sw_if_index";
-  }
+  s = format (s, "fib %d adj-idx %d : %U flow hash: 0x%08x",
+              t->fib_index, t->adj_index, format_ip_adjacency,
+              vnm, &im->lookup_main, t->adj_index, t->flow_hash);
+  s = format(s, "\n%U%U",
+             format_white_space, indent,
+             format_ip6_header, t->packet_data);
+  return s;
+}
 
-  adj = ip_get_adjacency (&im->lookup_main, t->adj_index);
-  s = format (s, "%s %d adj-idx %d : %U flow hash: 0x%08x",
-              fib_or_interface,
-             t->fib_index, t->adj_index, format_ip_adjacency,
-             vnm, &im->lookup_main, t->adj_index, t->flow_hash);
-  switch (adj->lookup_next_index)
-    {
-    case IP_LOOKUP_NEXT_REWRITE:
-      s = format (s, "\n%U%U",
-                 format_white_space, indent,
-                 format_ip_adjacency_packet_data,
-                 vnm, &im->lookup_main, t->adj_index,
-                 t->packet_data, sizeof (t->packet_data));
-      break;
 
-    default:
-      break;
-    }
+static u8 * format_ip6_rewrite_trace (u8 * s, va_list * args)
+{
+  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+  ip6_forward_next_trace_t * t = va_arg (*args, ip6_forward_next_trace_t *);
+  vnet_main_t * vnm = vnet_get_main();
+  ip6_main_t * im = &ip6_main;
+  uword indent = format_get_indent (s);
 
+  s = format (s, "tx_sw_if_index %d adj-idx %d : %U flow hash: 0x%08x",
+              t->fib_index, t->adj_index, format_ip_adjacency,
+              vnm, &im->lookup_main, t->adj_index, t->flow_hash);
+  s = format (s, "\n%U%U",
+              format_white_space, indent,
+              format_ip_adjacency_packet_data,
+              vnm, &im->lookup_main, t->adj_index,
+              t->packet_data, sizeof (t->packet_data));
   return s;
 }
 
@@ -2459,7 +2473,7 @@ VLIB_REGISTER_NODE (ip6_rewrite_node) = {
   .name = "ip6-rewrite",
   .vector_size = sizeof (u32),
 
-  .format_trace = format_ip6_forward_next_trace,
+  .format_trace = format_ip6_rewrite_trace,
 
   .n_next_nodes = 1,
   .next_nodes = {
@@ -2476,12 +2490,9 @@ VLIB_REGISTER_NODE (ip6_rewrite_local_node) = {
 
   .sibling_of = "ip6-rewrite",
 
-  .format_trace = format_ip6_forward_next_trace,
+  .format_trace = format_ip6_rewrite_trace,
 
-  .n_next_nodes = 1,
-  .next_nodes = {
-    [IP6_REWRITE_NEXT_DROP] = "error-drop",
-  },
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_rewrite_local_node, ip6_rewrite_local)
@@ -2672,7 +2683,7 @@ ip6_hop_by_hop (vlib_main_t * vm,
     out0:
       /* Has the classifier flagged this buffer for special treatment? */
       if ((error0 == 0) && (vnet_buffer(b0)->l2_classify.opaque_index == OI_DECAP))
-       next0 = IP_LOOKUP_NEXT_POP_HOP_BY_HOP;
+       next0 = IP6_LOOKUP_NEXT_POP_HOP_BY_HOP;
 
       if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) {
        ip6_hop_by_hop_trace_t *t = vlib_add_trace(vm, node, b0, sizeof (*t));
@@ -2697,13 +2708,13 @@ ip6_hop_by_hop (vlib_main_t * vm,
 VLIB_REGISTER_NODE (ip6_hop_by_hop_node) = {
   .function = ip6_hop_by_hop,
   .name = "ip6-hop-by-hop",
+  .sibling_of = "ip6-lookup",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_hop_by_hop_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
   .n_errors = ARRAY_LEN(ip6_hop_by_hop_error_strings),
   .error_strings = ip6_hop_by_hop_error_strings,
-  .n_next_nodes = IP_LOOKUP_N_NEXT,
-  .next_nodes = IP6_LOOKUP_NEXT_NODES,
+  .n_next_nodes = 0,
 };
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_hop_by_hop_node, ip6_hop_by_hop)