Remove the unused 'create VRF if needed' API parameters
[vpp.git] / src / vnet / ip / ip6_forward.c
index 1002f6b..a14bf09 100644 (file)
  * This file contains the source code for IPv6 forwarding.
  */
 
-void
-ip6_forward_next_trace (vlib_main_t * vm,
-                       vlib_node_runtime_t * node,
-                       vlib_frame_t * frame,
-                       vlib_rx_or_tx_t which_adj_index);
 
 always_inline uword
 ip6_lookup_inline (vlib_main_t * vm,
@@ -998,7 +993,7 @@ format_ip6_forward_next_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 *);
-  uword indent = format_get_indent (s);
+  u32 indent = format_get_indent (s);
 
   s = format (s, "%U%U",
              format_white_space, indent,
@@ -1012,7 +1007,7 @@ 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 *);
-  uword indent = format_get_indent (s);
+  u32 indent = format_get_indent (s);
 
   s = format (s, "fib %d dpo-idx %d flow hash: 0x%08x",
              t->fib_index, t->adj_index, t->flow_hash);
@@ -1029,7 +1024,7 @@ 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 *);
-  uword indent = format_get_indent (s);
+  u32 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,
@@ -1133,70 +1128,6 @@ ip6_forward_next_trace (vlib_main_t * vm,
     }
 }
 
-static uword
-ip6_drop_or_punt (vlib_main_t * vm,
-                 vlib_node_runtime_t * node,
-                 vlib_frame_t * frame, ip6_error_t error_code)
-{
-  u32 *buffers = vlib_frame_vector_args (frame);
-  uword n_packets = frame->n_vectors;
-
-  vlib_error_drop_buffers (vm, node, buffers,
-                          /* stride */ 1,
-                          n_packets,
-                          /* next */ 0,
-                          ip6_input_node.index, error_code);
-
-  if (node->flags & VLIB_NODE_FLAG_TRACE)
-    ip6_forward_next_trace (vm, node, frame, VLIB_TX);
-
-  return n_packets;
-}
-
-static uword
-ip6_drop (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
-  return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_DROP);
-}
-
-static uword
-ip6_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
-  return ip6_drop_or_punt (vm, node, frame, IP6_ERROR_ADJACENCY_PUNT);
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ip6_drop_node, static) =
-{
-  .function = ip6_drop,
-  .name = "ip6-drop",
-  .vector_size = sizeof (u32),
-  .format_trace = format_ip6_forward_next_trace,
-  .n_next_nodes = 1,
-  .next_nodes =
-  {
-    [0] = "error-drop",},
-};
-/* *INDENT-ON* */
-
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_drop_node, ip6_drop);
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ip6_punt_node, static) =
-{
-  .function = ip6_punt,
-  .name = "ip6-punt",
-  .vector_size = sizeof (u32),
-  .format_trace = format_ip6_forward_next_trace,
-  .n_next_nodes = 1,
-  .next_nodes =
-  {
-    [0] = "error-punt",},
-};
-/* *INDENT-ON* */
-
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_punt_node, ip6_punt);
-
 /* Compute TCP/UDP/ICMP6 checksum in software. */
 u16
 ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
@@ -1337,8 +1268,17 @@ ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
   return proto0;
 }
 
+/* *INDENT-OFF* */
+VNET_FEATURE_ARC_INIT (ip6_local) =
+{
+  .arc_name  = "ip6-local",
+  .start_nodes = VNET_FEATURES ("ip6-local"),
+};
+/* *INDENT-ON* */
+
 static uword
-ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
+                 vlib_frame_t * frame, int head_of_feature_arc)
 {
   ip6_main_t *im = &ip6_main;
   ip_lookup_main_t *lm = &im->lookup_main;
@@ -1346,6 +1286,7 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
   u32 *from, *to_next, n_left_from, n_left_to_next;
   vlib_node_runtime_t *error_node =
     vlib_node_get_runtime (vm, ip6_input_node.index);
+  u8 arc_index = vnet_feat_arc_ip6_local.feature_arc_index;
 
   from = vlib_frame_vector_args (frame);
   n_left_from = frame->n_vectors;
@@ -1377,29 +1318,37 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          to_next += 2;
          n_left_to_next -= 2;
 
+         error0 = error1 = IP6_ERROR_UNKNOWN_PROTOCOL;
+
          p0 = vlib_get_buffer (vm, pi0);
          p1 = vlib_get_buffer (vm, pi1);
 
          ip0 = vlib_buffer_get_current (p0);
          ip1 = vlib_buffer_get_current (p1);
 
+         if (head_of_feature_arc == 0)
+           goto skip_checks;
+
          vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
          vnet_buffer (p1)->l3_hdr_offset = p1->current_data;
 
          type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
          type1 = lm->builtin_protocol_by_ip_protocol[ip1->protocol];
 
-         next0 = lm->local_next_by_ip_protocol[ip0->protocol];
-         next1 = lm->local_next_by_ip_protocol[ip1->protocol];
-
          flags0 = p0->flags;
          flags1 = p1->flags;
 
          is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
          is_tcp_udp1 = ip6_next_proto_is_tcp_udp (p1, ip1, &udp_offset1);
 
-         good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
-         good_l4_csum1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
+         good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
+                          || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
+                              || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
+           != 0;
+         good_l4_csum1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
+                          || (flags1 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
+                              || flags1 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
+           != 0;
          len_diff0 = 0;
          len_diff1 = 0;
 
@@ -1485,6 +1434,29 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
                        ? IP6_ERROR_SRC_LOOKUP_MISS : error1);
            }
 
+         /* TODO maybe move to lookup? */
+         vnet_buffer (p0)->ip.fib_index =
+           vec_elt (im->fib_index_by_sw_if_index,
+                    vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+         vnet_buffer (p0)->ip.fib_index =
+           (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+            (u32) ~ 0) ? vnet_buffer (p0)->ip.
+           fib_index : vnet_buffer (p0)->sw_if_index[VLIB_TX];
+
+         vnet_buffer (p1)->ip.fib_index =
+           vec_elt (im->fib_index_by_sw_if_index,
+                    vnet_buffer (p1)->sw_if_index[VLIB_RX]);
+         vnet_buffer (p1)->ip.fib_index =
+           (vnet_buffer (p1)->sw_if_index[VLIB_TX] ==
+            (u32) ~ 0) ? vnet_buffer (p1)->ip.
+           fib_index : vnet_buffer (p1)->sw_if_index[VLIB_TX];
+
+
+       skip_checks:
+
+         next0 = lm->local_next_by_ip_protocol[ip0->protocol];
+         next1 = lm->local_next_by_ip_protocol[ip1->protocol];
+
          next0 =
            error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
          next1 =
@@ -1493,6 +1465,18 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          p0->error = error_node->errors[error0];
          p1->error = error_node->errors[error1];
 
+         if (head_of_feature_arc)
+           {
+             if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
+               vnet_feature_arc_start (arc_index,
+                                       vnet_buffer (p0)->sw_if_index
+                                       [VLIB_RX], &next0, p0);
+             if (PREDICT_TRUE (error1 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
+               vnet_feature_arc_start (arc_index,
+                                       vnet_buffer (p1)->sw_if_index
+                                       [VLIB_RX], &next1, p1);
+           }
+
          vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
                                           to_next, n_left_to_next,
                                           pi0, pi1, next0, next1);
@@ -1515,15 +1499,23 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
          to_next += 1;
          n_left_to_next -= 1;
 
+         error0 = IP6_ERROR_UNKNOWN_PROTOCOL;
+
          p0 = vlib_get_buffer (vm, pi0);
          ip0 = vlib_buffer_get_current (p0);
+
+         if (head_of_feature_arc == 0)
+           goto skip_check;
+
          vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
 
          type0 = lm->builtin_protocol_by_ip_protocol[ip0->protocol];
-         next0 = lm->local_next_by_ip_protocol[ip0->protocol];
          flags0 = p0->flags;
          is_tcp_udp0 = ip6_next_proto_is_tcp_udp (p0, ip0, &udp_offset0);
-         good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
+         good_l4_csum0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT
+                          || (flags0 & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM
+                              || flags0 & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM))
+           != 0;
 
          len_diff0 = 0;
          if (PREDICT_TRUE (is_tcp_udp0))
@@ -1573,10 +1565,29 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
                        ? IP6_ERROR_SRC_LOOKUP_MISS : error0);
            }
 
+         vnet_buffer (p0)->ip.fib_index =
+           vec_elt (im->fib_index_by_sw_if_index,
+                    vnet_buffer (p0)->sw_if_index[VLIB_RX]);
+         vnet_buffer (p0)->ip.fib_index =
+           (vnet_buffer (p0)->sw_if_index[VLIB_TX] ==
+            (u32) ~ 0) ? vnet_buffer (p0)->ip.
+           fib_index : vnet_buffer (p0)->sw_if_index[VLIB_TX];
+
+       skip_check:
+
+         next0 = lm->local_next_by_ip_protocol[ip0->protocol];
          next0 =
            error0 != IP6_ERROR_UNKNOWN_PROTOCOL ? IP_LOCAL_NEXT_DROP : next0;
          p0->error = error_node->errors[error0];
 
+         if (head_of_feature_arc)
+           {
+             if (PREDICT_TRUE (error0 == (u8) IP6_ERROR_UNKNOWN_PROTOCOL))
+               vnet_feature_arc_start (arc_index,
+                                       vnet_buffer (p0)->sw_if_index
+                                       [VLIB_RX], &next0, p0);
+           }
+
          vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
                                           to_next, n_left_to_next,
                                           pi0, next0);
@@ -1588,6 +1599,12 @@ ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
   return frame->n_vectors;
 }
 
+static uword
+ip6_local (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+  return ip6_local_inline (vm, node, frame, 1 /* head of feature arc */ );
+}
+
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_local_node, static) =
 {
@@ -1598,8 +1615,8 @@ VLIB_REGISTER_NODE (ip6_local_node, static) =
   .n_next_nodes = IP_LOCAL_N_NEXT,
   .next_nodes =
   {
-    [IP_LOCAL_NEXT_DROP] = "error-drop",
-    [IP_LOCAL_NEXT_PUNT] = "error-punt",
+    [IP_LOCAL_NEXT_DROP] = "ip6-drop",
+    [IP_LOCAL_NEXT_PUNT] = "ip6-punt",
     [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
     [IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
   },
@@ -1608,6 +1625,33 @@ VLIB_REGISTER_NODE (ip6_local_node, static) =
 
 VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_node, ip6_local);
 
+
+static uword
+ip6_local_end_of_arc (vlib_main_t * vm,
+                     vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+  return ip6_local_inline (vm, node, frame, 0 /* head of feature arc */ );
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_local_end_of_arc_node,static) = {
+  .function = ip6_local_end_of_arc,
+  .name = "ip6-local-end-of-arc",
+  .vector_size = sizeof (u32),
+
+  .format_trace = format_ip6_forward_next_trace,
+  .sibling_of = "ip6-local",
+};
+
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_local_end_of_arc_node, ip6_local_end_of_arc)
+
+VNET_FEATURE_INIT (ip6_local_end_of_arc, static) = {
+  .arc_name = "ip6-local",
+  .node_name = "ip6-local-end-of-arc",
+  .runs_before = 0, /* not before any other features */
+};
+/* *INDENT-ON* */
+
 void
 ip6_register_protocol (u32 protocol, u32 node_index)
 {
@@ -1963,6 +2007,14 @@ ip6_probe_neighbor (vlib_main_t * vm, ip6_address_t * dst, u32 sw_if_index)
                            VNET_LINK_IP6, &nh, sw_if_index);
   adj = adj_get (ai);
 
+  /* Peer has been previously resolved, retrieve glean adj instead */
+  if (adj->lookup_next_index == IP_LOOKUP_NEXT_REWRITE)
+    {
+      adj_unlock (ai);
+      ai = adj_glean_add_or_lock (FIB_PROTOCOL_IP6, sw_if_index, &nh);
+      adj = adj_get (ai);
+    }
+
   vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t));
   vlib_buffer_advance (b, -adj->rewrite_header.data_bytes);
 
@@ -3271,7 +3323,14 @@ show_ip6_local_command_fn (vlib_main_t * vm,
   for (i = 0; i < ARRAY_LEN (lm->local_next_by_ip_protocol); i++)
     {
       if (lm->local_next_by_ip_protocol[i] != IP_LOCAL_NEXT_PUNT)
-       vlib_cli_output (vm, "%d", i);
+       {
+
+         u32 node_index = vlib_get_node (vm,
+                                         ip6_local_node.index)->
+           next_nodes[lm->local_next_by_ip_protocol[i]];
+         vlib_cli_output (vm, "%d: %U", i, format_vlib_node_name, vm,
+                          node_index);
+       }
     }
   return 0;
 }