IPv4/6 reassembly
[vpp.git] / src / vnet / ip / ip6_forward.c
index 54582d3..5b06ca7 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,
@@ -441,11 +436,11 @@ ip6_sw_interface_enable_disable (u32 sw_if_index, u32 is_enable)
        return;
     }
 
-  vnet_feature_enable_disable ("ip6-unicast", "ip6-drop", sw_if_index,
+  vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
                               !is_enable, 0, 0);
 
-  vnet_feature_enable_disable ("ip6-multicast", "ip6-drop", sw_if_index,
-                              !is_enable, 0, 0);
+  vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
+                              sw_if_index, !is_enable, 0, 0);
 }
 
 /* get first interface address */
@@ -627,10 +622,10 @@ VNET_FEATURE_INIT (ip6_vxlan_bypass, static) =
   .runs_before = VNET_FEATURES ("ip6-lookup"),
 };
 
-VNET_FEATURE_INIT (ip6_drop, static) =
+VNET_FEATURE_INIT (ip6_not_enabled, static) =
 {
   .arc_name = "ip6-unicast",
-  .node_name = "ip6-drop",
+  .node_name = "ip6-not-enabled",
   .runs_before = VNET_FEATURES ("ip6-lookup"),
 };
 
@@ -655,9 +650,9 @@ VNET_FEATURE_INIT (ip6_vpath_mc, static) = {
   .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
 };
 
-VNET_FEATURE_INIT (ip6_drop_mc, static) = {
+VNET_FEATURE_INIT (ip6_not_enabled_mc, static) = {
   .arc_name = "ip6-multicast",
-  .node_name = "ip6-drop",
+  .node_name = "ip6-not-enabled",
   .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
 };
 
@@ -671,7 +666,7 @@ VNET_FEATURE_INIT (ip6_mc_lookup, static) = {
 VNET_FEATURE_ARC_INIT (ip6_output, static) =
 {
   .arc_name  = "ip6-output",
-  .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain"),
+  .start_nodes = VNET_FEATURES ("ip6-rewrite", "ip6-midchain", "ip6-dvr-dpo"),
   .arc_index_ptr = &ip6_main.lookup_main.output_feature_arc_index,
 };
 
@@ -716,11 +711,11 @@ ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
       ip6_mfib_interface_enable_disable (sw_if_index, 0);
     }
 
-  vnet_feature_enable_disable ("ip6-unicast", "ip6-drop", sw_if_index,
+  vnet_feature_enable_disable ("ip6-unicast", "ip6-not-enabled", sw_if_index,
                               is_add, 0, 0);
 
-  vnet_feature_enable_disable ("ip6-multicast", "ip6-drop", sw_if_index,
-                              is_add, 0, 0);
+  vnet_feature_enable_disable ("ip6-multicast", "ip6-not-enabled",
+                              sw_if_index, is_add, 0, 0);
 
   return /* no error */ 0;
 }
@@ -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,
@@ -1410,8 +1341,14 @@ ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          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;
 
@@ -1497,6 +1434,24 @@ ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                        ? 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];
@@ -1557,7 +1512,10 @@ ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          type0 = lm->builtin_protocol_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))
@@ -1607,11 +1565,20 @@ ip6_local_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                        ? 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)
@@ -1649,10 +1616,11 @@ 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",
+    [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly",
   },
 };
 /* *INDENT-ON* */
@@ -1936,7 +1904,7 @@ VLIB_REGISTER_NODE (ip6_discover_neighbor_node) =
   .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
   .next_nodes =
   {
-    [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
+    [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
     [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
   },
 };
@@ -1954,7 +1922,7 @@ VLIB_REGISTER_NODE (ip6_glean_node) =
   .n_next_nodes = IP6_DISCOVER_NEIGHBOR_N_NEXT,
   .next_nodes =
   {
-    [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "error-drop",
+    [IP6_DISCOVER_NEIGHBOR_NEXT_DROP] = "ip6-drop",
     [IP6_DISCOVER_NEIGHBOR_NEXT_REPLY_TX] = "interface-output",
   },
 };
@@ -2263,8 +2231,10 @@ ip6_rewrite_inline (vlib_main_t * vm,
 
          if (is_midchain)
            {
-             adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
-             adj1->sub_type.midchain.fixup_func (vm, adj1, p1);
+             adj0->sub_type.midchain.fixup_func
+               (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
+             adj1->sub_type.midchain.fixup_func
+               (vm, adj1, p1, adj1->sub_type.midchain.fixup_data);
            }
          if (is_mcast)
            {
@@ -2374,7 +2344,8 @@ ip6_rewrite_inline (vlib_main_t * vm,
 
          if (is_midchain)
            {
-             adj0->sub_type.midchain.fixup_func (vm, adj0, p0);
+             adj0->sub_type.midchain.fixup_func
+               (vm, adj0, p0, adj0->sub_type.midchain.fixup_data);
            }
          if (is_mcast)
            {
@@ -2466,7 +2437,7 @@ VLIB_REGISTER_NODE (ip6_rewrite_node) =
   .n_next_nodes = 2,
   .next_nodes =
   {
-    [IP6_REWRITE_NEXT_DROP] = "error-drop",
+    [IP6_REWRITE_NEXT_DROP] = "ip6-drop",
     [IP6_REWRITE_NEXT_ICMP_ERROR] = "ip6-icmp-error",
   },
 };
@@ -3528,14 +3499,9 @@ ip6_config (vlib_main_t * vm, unformat_input_t * input)
     {
       if (unformat (input, "hash-buckets %d", &tmp))
        nbuckets = tmp;
-      else if (unformat (input, "heap-size %dm", &tmp))
-       heapsize = ((u64) tmp) << 20;
-      else if (unformat (input, "heap-size %dM", &tmp))
-       heapsize = ((u64) tmp) << 20;
-      else if (unformat (input, "heap-size %dg", &tmp))
-       heapsize = ((u64) tmp) << 30;
-      else if (unformat (input, "heap-size %dG", &tmp))
-       heapsize = ((u64) tmp) << 30;
+      else if (unformat (input, "heap-size %U",
+                        unformat_memory_size, &heapsize))
+       ;
       else
        return clib_error_return (0, "unknown input '%U'",
                                  format_unformat_error, input);