ip: add support for buffer offload metadata in ip midchain
[vpp.git] / src / vnet / ip / ip6_forward.c
index 9ee3d11..06c473b 100644 (file)
@@ -71,7 +71,6 @@ ip6_add_interface_prefix_routes (ip6_main_t * im,
   ip_lookup_main_t *lm = &im->lookup_main;
   ip_interface_prefix_t *if_prefix;
 
-  /* *INDENT-OFF* */
   ip_interface_prefix_key_t key = {
     .prefix = {
       .fp_len = address_length,
@@ -85,7 +84,6 @@ ip6_add_interface_prefix_routes (ip6_main_t * im,
     },
     .sw_if_index = sw_if_index,
   };
-  /* *INDENT-ON* */
 
   /* If prefix already set on interface, just increment ref count & return */
   if_prefix = ip_get_interface_prefix (lm, &key);
@@ -178,7 +176,6 @@ ip6_del_interface_prefix_routes (ip6_main_t * im,
   ip_lookup_main_t *lm = &im->lookup_main;
   ip_interface_prefix_t *if_prefix;
 
-  /* *INDENT-OFF* */
   ip_interface_prefix_key_t key = {
     .prefix = {
       .fp_len = address_length,
@@ -192,13 +189,12 @@ ip6_del_interface_prefix_routes (ip6_main_t * im,
     },
     .sw_if_index = sw_if_index,
   };
-  /* *INDENT-ON* */
 
   if_prefix = ip_get_interface_prefix (lm, &key);
   if (!if_prefix)
     {
       clib_warning ("Prefix not found while deleting %U",
-                   format_ip4_address_and_length, address, address_length);
+                   format_ip6_address_and_length, address, address_length);
       return;
     }
 
@@ -283,7 +279,6 @@ ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
   ip_interface_address_t *ia = 0;
   ip6_address_t *result = 0;
 
-  /* *INDENT-OFF* */
   foreach_ip_interface_address (lm, ia, sw_if_index,
                                 1 /* honor unnumbered */,
   ({
@@ -291,7 +286,6 @@ ip6_interface_first_address (ip6_main_t * im, u32 sw_if_index)
     result = a;
     break;
   }));
-  /* *INDENT-ON* */
   return result;
 }
 
@@ -359,7 +353,6 @@ ip6_add_del_interface_address (vlib_main_t * vm,
                     vec_elt (im->fib_index_by_sw_if_index, sw_if_index));
   vec_add1 (addr_fib, ip6_af);
 
-  /* *INDENT-OFF* */
   if (!is_del)
     {
       /* When adding an address check that it does not conflict
@@ -417,7 +410,6 @@ ip6_add_del_interface_address (vlib_main_t * vm,
             }
       }
     }
-  /* *INDENT-ON* */
 
   if_address_index = ip_interface_address_find (lm, addr_fib, address_length);
 
@@ -537,7 +529,6 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
 
   fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
 
-  /* *INDENT-OFF* */
   foreach_ip_interface_address (&im->lookup_main, ia, sw_if_index,
                                 0 /* honor unnumbered */,
   ({
@@ -550,7 +541,6 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
       ip6_del_interface_routes (sw_if_index, im, fib_index,
                                a, ia->address_length);
   }));
-  /* *INDENT-ON* */
 
   return 0;
 }
@@ -558,7 +548,6 @@ ip6_sw_interface_admin_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
 VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_sw_interface_admin_up_down);
 
 /* Built-in ip6 unicast rx feature path definition */
-/* *INDENT-OFF* */
 VNET_FEATURE_ARC_INIT (ip6_unicast, static) =
 {
   .arc_name  = "ip6-unicast",
@@ -683,7 +672,6 @@ VNET_FEATURE_INIT (ip6_interface_output, static) = {
   .node_name = "interface-output",
   .runs_before = 0, /* not before any other features */
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
@@ -709,13 +697,11 @@ ip6_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
       vlib_main_t *vm = vlib_get_main ();
 
       vnet_sw_interface_update_unnumbered (sw_if_index, ~0, 0);
-      /* *INDENT-OFF* */
       foreach_ip_interface_address (lm6, ia, sw_if_index, 0,
       ({
         address = ip_interface_address_get_address (lm6, ia);
         ip6_add_del_interface_address(vm, sw_if_index, address, ia->address_length, 1);
       }));
-      /* *INDENT-ON* */
       ip6_mfib_interface_enable_disable (sw_if_index, 0);
 
       if (0 != im6->fib_index_by_sw_if_index[sw_if_index])
@@ -748,7 +734,6 @@ VLIB_NODE_FN (ip6_lookup_node) (vlib_main_t * vm,
 
 static u8 *format_ip6_lookup_trace (u8 * s, va_list * args);
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_lookup_node) =
 {
   .name = "ip6-lookup",
@@ -757,7 +742,6 @@ VLIB_REGISTER_NODE (ip6_lookup_node) =
   .n_next_nodes = IP6_LOOKUP_N_NEXT,
   .next_nodes = IP6_LOOKUP_NEXT_NODES,
 };
-/* *INDENT-ON* */
 
 VLIB_NODE_FN (ip6_load_balance_node) (vlib_main_t * vm,
                                      vlib_node_runtime_t * node,
@@ -935,7 +919,6 @@ VLIB_NODE_FN (ip6_load_balance_node) (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_load_balance_node) =
 {
   .name = "ip6-load-balance",
@@ -943,7 +926,6 @@ VLIB_REGISTER_NODE (ip6_load_balance_node) =
   .sibling_of = "ip6-lookup",
   .format_trace = format_ip6_lookup_trace,
 };
-/* *INDENT-ON* */
 
 typedef struct
 {
@@ -1227,22 +1209,17 @@ always_inline u8
 ip6_next_proto_is_tcp_udp (vlib_buffer_t * p0, ip6_header_t * ip0,
                           u32 * udp_offset0)
 {
-  u32 proto0;
-  proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_UDP, udp_offset0);
-  if (proto0 != IP_PROTOCOL_UDP)
-    {
-      proto0 = ip6_locate_header (p0, ip0, IP_PROTOCOL_TCP, udp_offset0);
-      proto0 = (proto0 == IP_PROTOCOL_TCP) ? proto0 : 0;
-    }
-  return proto0;
+  int nh = ip6_locate_header (p0, ip0, -1, udp_offset0);
+  if (nh > 0)
+    if (nh == IP_PROTOCOL_UDP || nh == IP_PROTOCOL_TCP)
+      return nh;
+  return 0;
 }
 
-/* *INDENT-OFF* */
 VNET_FEATURE_ARC_INIT (ip6_local) = {
   .arc_name = "ip6-local",
   .start_nodes = VNET_FEATURES ("ip6-local", "ip6-receive"),
 };
-/* *INDENT-ON* */
 
 static_always_inline u8
 ip6_tcp_udp_icmp_bad_length (vlib_main_t * vm, vlib_buffer_t * p0)
@@ -1279,7 +1256,7 @@ ip6_tcp_udp_icmp_bad_length (vlib_main_t * vm, vlib_buffer_t * p0)
     }
 
   n_bytes_left -= n_this_buffer;
-  n_bytes_left -= p0->total_length_not_including_first_buffer;
+  n_bytes_left -= vlib_buffer_length_in_chain (vm, p0) - p0->current_length;
 
   if (n_bytes_left == 0)
     return 0;
@@ -1322,7 +1299,7 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
          vlib_prefetch_buffer_data (b[3], LOAD);
        }
 
-      ip6_error_t error[2];
+      vl_counter_ip6_enum_t error[2];
       error[0] = IP6_ERROR_UNKNOWN_PROTOCOL;
       error[1] = IP6_ERROR_UNKNOWN_PROTOCOL;
 
@@ -1478,6 +1455,11 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
            vnet_buffer (b[1])->sw_if_index[VLIB_TX] != ~0 ?
            vnet_buffer (b[1])->sw_if_index[VLIB_TX] :
            vnet_buffer (b[1])->ip.fib_index;
+
+         vnet_buffer (b[0])->ip.rx_sw_if_index =
+           vnet_buffer (b[0])->sw_if_index[VLIB_RX];
+         vnet_buffer (b[1])->ip.rx_sw_if_index =
+           vnet_buffer (b[1])->sw_if_index[VLIB_RX];
          if (is_receive_dpo)
            {
              const receive_dpo_t *rd0, *rd1;
@@ -1485,15 +1467,10 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
                receive_dpo_get (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
              rd1 =
                receive_dpo_get (vnet_buffer (b[1])->ip.adj_index[VLIB_TX]);
-             vnet_buffer (b[0])->ip.rx_sw_if_index = rd0->rd_sw_if_index;
-             vnet_buffer (b[1])->ip.rx_sw_if_index = rd1->rd_sw_if_index;
-           }
-         else
-           {
-             vnet_buffer (b[0])->ip.rx_sw_if_index =
-               vnet_buffer (b[0])->ip.adj_index[VLIB_RX];
-             vnet_buffer (b[1])->ip.rx_sw_if_index =
-               vnet_buffer (b[1])->ip.adj_index[VLIB_RX];
+             if (rd0->rd_sw_if_index != ~0)
+               vnet_buffer (b[0])->ip.rx_sw_if_index = rd0->rd_sw_if_index;
+             if (rd1->rd_sw_if_index != ~0)
+               vnet_buffer (b[1])->ip.rx_sw_if_index = rd1->rd_sw_if_index;
            }
        }                       /* head_of_feature_arc */
 
@@ -1516,16 +1493,16 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
            {
              u32 next32 = next[0];
              vnet_feature_arc_start (arc_index,
-                                     vnet_buffer (b[0])->sw_if_index
-                                     [VLIB_RX], &next32, b[0]);
+                                     vnet_buffer (b[0])->ip.rx_sw_if_index,
+                                     &next32, b[0]);
              next[0] = next32;
            }
          if (PREDICT_TRUE (ip6_unknown[1]))
            {
              u32 next32 = next[1];
              vnet_feature_arc_start (arc_index,
-                                     vnet_buffer (b[1])->sw_if_index
-                                     [VLIB_RX], &next32, b[1]);
+                                     vnet_buffer (b[1])->ip.rx_sw_if_index,
+                                     &next32, b[1]);
              next[1] = next32;
            }
        }
@@ -1622,15 +1599,16 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
            vnet_buffer (b[0])->sw_if_index[VLIB_TX] != ~0 ?
            vnet_buffer (b[0])->sw_if_index[VLIB_TX] :
            vnet_buffer (b[0])->ip.fib_index;
+
+         vnet_buffer (b[0])->ip.rx_sw_if_index =
+           vnet_buffer (b[0])->sw_if_index[VLIB_RX];
          if (is_receive_dpo)
            {
              receive_dpo_t *rd;
              rd = receive_dpo_get (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
-             vnet_buffer (b[0])->ip.rx_sw_if_index = rd->rd_sw_if_index;
+             if (rd->rd_sw_if_index != ~0)
+               vnet_buffer (b[0])->ip.rx_sw_if_index = rd->rd_sw_if_index;
            }
-         else
-           vnet_buffer (b[0])->ip.rx_sw_if_index =
-             vnet_buffer (b[0])->ip.adj_index[VLIB_RX];
        }                       /* head_of_feature_arc */
 
       next[0] = lm->local_next_by_ip_protocol[ip->protocol];
@@ -1645,8 +1623,8 @@ ip6_local_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
            {
              u32 next32 = next[0];
              vnet_feature_arc_start (arc_index,
-                                     vnet_buffer (b[0])->sw_if_index
-                                     [VLIB_RX], &next32, b[0]);
+                                     vnet_buffer (b[0])->ip.rx_sw_if_index,
+                                     &next32, b[0]);
              next[0] = next32;
            }
        }
@@ -1673,6 +1651,8 @@ VLIB_REGISTER_NODE (ip6_local_node) =
   .name = "ip6-local",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_forward_next_trace,
+  .n_errors = IP6_N_ERROR,
+  .error_counters = ip6_error_counters,
   .n_next_nodes = IP_LOCAL_N_NEXT,
   .next_nodes =
   {
@@ -1680,7 +1660,7 @@ VLIB_REGISTER_NODE (ip6_local_node) =
     [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-full-reassembly",
+    [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-local-full-reassembly",
   },
 };
 
@@ -1991,13 +1971,6 @@ ip6_rewrite_inline_with_gso (vlib_main_t * vm,
 
          if (is_midchain)
            {
-             /* before we paint on the next header, update the L4
-              * checksums if required, since there's no offload on a tunnel */
-             vnet_calc_checksums_inline (vm, p0, 0 /* is_ip4 */ ,
-                                         1 /* is_ip6 */ );
-             vnet_calc_checksums_inline (vm, p1, 0 /* is_ip4 */ ,
-                                         1 /* is_ip6 */ );
-
              /* Guess we are only writing on ipv6 header. */
              vnet_rewrite_two_headers (adj0[0], adj1[0],
                                        ip0, ip1, sizeof (ip6_header_t));
@@ -2091,9 +2064,6 @@ ip6_rewrite_inline_with_gso (vlib_main_t * vm,
 
          if (is_midchain)
            {
-             vnet_calc_checksums_inline (vm, p0, 0 /* is_ip4 */ ,
-                                         1 /* is_ip6 */ );
-
              /* Guess we are only writing on ip6 header. */
              vnet_rewrite_one_header (adj0[0], ip0, sizeof (ip6_header_t));
            }
@@ -2243,14 +2213,12 @@ VLIB_NODE_FN (ip6_mcast_midchain_node) (vlib_main_t * vm,
     return ip6_rewrite_inline (vm, node, frame, 0, 1, 1);
 }
 
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (ip6_midchain_node) =
-{
+VLIB_REGISTER_NODE (ip6_midchain_node) = {
   .name = "ip6-midchain",
   .vector_size = sizeof (u32),
   .format_trace = format_ip6_forward_next_trace,
   .sibling_of = "ip6-rewrite",
-  };
+};
 
 VLIB_REGISTER_NODE (ip6_rewrite_node) =
 {
@@ -2291,7 +2259,6 @@ VLIB_REGISTER_NODE (ip6_mcast_midchain_node) =
   .sibling_of = "ip6-rewrite",
 };
 
-/* *INDENT-ON* */
 
 /*
  * Hop-by-Hop handling
@@ -2305,7 +2272,6 @@ _(PROCESSED, "pkts with ip6 hop-by-hop options") \
 _(FORMAT, "incorrectly formatted hop-by-hop options") \
 _(UNKNOWN_OPTION, "unknown ip6 hop-by-hop options")
 
-/* *INDENT-OFF* */
 typedef enum
 {
 #define _(sym,str) IP6_HOP_BY_HOP_ERROR_##sym,
@@ -2313,7 +2279,6 @@ typedef enum
 #undef _
   IP6_HOP_BY_HOP_N_ERROR,
 } ip6_hop_by_hop_error_t;
-/* *INDENT-ON* */
 
 /*
  * Primary h-b-h handler trace support
@@ -2740,7 +2705,6 @@ VLIB_NODE_FN (ip6_hop_by_hop_node) (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
 {
   .name = "ip6-hop-by-hop",
@@ -2752,7 +2716,6 @@ VLIB_REGISTER_NODE (ip6_hop_by_hop_node) =
   .error_strings = ip6_hop_by_hop_error_strings,
   .n_next_nodes = 0,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 ip6_hop_by_hop_init (vlib_main_t * vm)
@@ -3004,14 +2967,12 @@ set_ip6_flow_hash_command_fn (vlib_main_t * vm,
  * @cliexend
  * @endparblock
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (set_ip6_flow_hash_command, static) = {
   .path = "set ip6 flow-hash",
   .short_help = "set ip6 flow-hash table <table-id> [src] [dst] [sport] "
                "[dport] [proto] [reverse] [flowlabel]",
   .function = set_ip6_flow_hash_command_fn,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 show_ip6_local_command_fn (vlib_main_t * vm,
@@ -3052,14 +3013,12 @@ show_ip6_local_command_fn (vlib_main_t * vm,
  * 115
  * @cliexend
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_ip6_local, static) =
 {
   .path = "show ip6 local",
   .function = show_ip6_local_command_fn,
   .short_help = "show ip6 local",
 };
-/* *INDENT-ON* */
 
 #ifndef CLIB_MARCH_VARIANT
 int
@@ -3171,7 +3130,6 @@ set_ip6_classify_command_fn (vlib_main_t * vm,
  * Example of how to assign a classification table to an interface:
  * @cliexcmd{set ip6 classify intfc GigabitEthernet2/0/0 table-index 1}
 ?*/
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
 {
   .path = "set ip6 classify",
@@ -3179,7 +3137,6 @@ VLIB_CLI_COMMAND (set_ip6_classify_command, static) =
   "set ip6 classify intfc <interface> table-index <classify-idx>",
   .function = set_ip6_classify_command_fn,
 };
-/* *INDENT-ON* */
 
 /*
  * fd.io coding-style-patch-verification: ON