ipsec: Performance improvement of ipsec4_output_node using flow cache
[vpp.git] / src / vnet / gso / node.c
index 23213a7..037f800 100644 (file)
 #include <vnet/ip/ip6.h>
 #include <vnet/udp/udp_packet.h>
 
+#define foreach_gso_error                                                     \
+  _ (NO_BUFFERS, "no buffers to segment GSO")                                 \
+  _ (UNHANDLED_TYPE, "unhandled gso type")
+
+static char *gso_error_strings[] = {
+#define _(sym, string) string,
+  foreach_gso_error
+#undef _
+};
+
+typedef enum
+{
+#define _(sym, str) GSO_ERROR_##sym,
+  foreach_gso_error
+#undef _
+    GSO_N_ERROR,
+} gso_error_t;
+
+typedef enum
+{
+  GSO_NEXT_DROP,
+  GSO_N_NEXT,
+} gso_next_t;
+
 typedef struct
 {
   u32 flags;
@@ -97,7 +121,6 @@ tso_segment_ipip_tunnel_fixup (vlib_main_t * vm,
       i++;
     }
   return n_tx_bytes;
-
 }
 
 static_always_inline void
@@ -144,7 +167,8 @@ tso_segment_vxlan_tunnel_headers_fixup (vlib_main_t * vm, vlib_buffer_t * b,
        {
          udp->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip4);
        }
-      b->flags &= ~VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+      /* FIXME: it should be OUTER_UDP_CKSUM */
+      vnet_buffer_offload_flags_clear (b, VNET_BUFFER_OFFLOAD_F_UDP_CKSUM);
     }
 }
 
@@ -282,7 +306,8 @@ tso_fixup_segmented_buf (vlib_main_t * vm, vlib_buffer_t * b0, u8 tcp_flags,
          tcp->checksum = 0;
          tcp->checksum =
            ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip6, &bogus);
-         b0->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
+         vnet_buffer_offload_flags_clear (b0,
+                                          VNET_BUFFER_OFFLOAD_F_TCP_CKSUM);
        }
     }
   else
@@ -296,8 +321,8 @@ tso_fixup_segmented_buf (vlib_main_t * vm, vlib_buffer_t * b0, u8 tcp_flags,
          tcp->checksum = 0;
          tcp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip4);
        }
-      b0->flags &= ~VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
-      b0->flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
+      vnet_buffer_offload_flags_clear (b0, (VNET_BUFFER_OFFLOAD_F_IP_CKSUM |
+                                           VNET_BUFFER_OFFLOAD_F_TCP_CKSUM));
     }
 
   if (!is_l2 && ((gho->gho_flags & GHO_F_TUNNEL) == 0))
@@ -458,9 +483,8 @@ drop_one_buffer_and_count (vlib_main_t * vm, vnet_main_t * vnm,
 
   vlib_error_drop_buffers (vm, node, pbi0,
                           /* buffer stride */ 1,
-                          /* n_buffers */ 1,
-                          VNET_INTERFACE_OUTPUT_NEXT_DROP,
-                          node->node_index, drop_error_code);
+                          /* n_buffers */ 1, GSO_NEXT_DROP, node->node_index,
+                          drop_error_code);
 }
 
 static_always_inline uword
@@ -522,28 +546,30 @@ vnet_gso_node_inline (vlib_main_t * vm,
            if (PREDICT_FALSE (hi->sw_if_index != swif0))
              {
                hi0 = vnet_get_sup_hw_interface (vnm, swif0);
-               if ((hi0->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 &&
+               if ((hi0->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) ==
+                     0 &&
                    (b[0]->flags & VNET_BUFFER_F_GSO))
                  break;
              }
            if (PREDICT_FALSE (hi->sw_if_index != swif1))
              {
                hi1 = vnet_get_sup_hw_interface (vnm, swif1);
-               if (!(hi1->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) &&
+               if (!(hi1->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) &&
                    (b[1]->flags & VNET_BUFFER_F_GSO))
                  break;
              }
            if (PREDICT_FALSE (hi->sw_if_index != swif2))
              {
                hi2 = vnet_get_sup_hw_interface (vnm, swif2);
-               if ((hi2->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 &&
+               if ((hi2->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) ==
+                     0 &&
                    (b[2]->flags & VNET_BUFFER_F_GSO))
                  break;
              }
            if (PREDICT_FALSE (hi->sw_if_index != swif3))
              {
                hi3 = vnet_get_sup_hw_interface (vnm, swif3);
-               if (!(hi3->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) &&
+               if (!(hi3->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) &&
                    (b[3]->flags & VNET_BUFFER_F_GSO))
                  break;
              }
@@ -614,7 +640,7 @@ vnet_gso_node_inline (vlib_main_t * vm,
          if (PREDICT_FALSE (hi->sw_if_index != swif0))
            {
              hi0 = vnet_get_sup_hw_interface (vnm, swif0);
-             if ((hi0->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO) == 0 &&
+             if ((hi0->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) == 0 &&
                  (b[0]->flags & VNET_BUFFER_F_GSO))
                do_segmentation0 = 1;
            }
@@ -667,7 +693,7 @@ vnet_gso_node_inline (vlib_main_t * vm,
                          /* not supported yet */
                          drop_one_buffer_and_count (vm, vnm, node, from - 1,
                                                     hi->sw_if_index,
-                                                    VNET_INTERFACE_OUTPUT_ERROR_UNHANDLED_GSO_TYPE);
+                                                    GSO_ERROR_UNHANDLED_TYPE);
                          b += 1;
                          continue;
                        }
@@ -686,7 +712,7 @@ vnet_gso_node_inline (vlib_main_t * vm,
                    {
                      drop_one_buffer_and_count (vm, vnm, node, from - 1,
                                                 hi->sw_if_index,
-                                                VNET_INTERFACE_OUTPUT_ERROR_NO_BUFFERS_FOR_GSO);
+                                                GSO_ERROR_NO_BUFFERS);
                      b += 1;
                      continue;
                    }
@@ -773,7 +799,8 @@ vnet_gso_inline (vlib_main_t * vm,
       hi = vnet_get_sup_hw_interface (vnm,
                                      vnet_buffer (b)->sw_if_index[VLIB_TX]);
 
-      if (hi->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO)
+      if (hi->caps & (VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO |
+                     VNET_HW_INTERFACE_CAP_SUPPORTS_VXLAN_TNL_GSO))
        return vnet_gso_node_inline (vm, node, frame, vnm, hi,
                                     is_l2, is_ip4, is_ip6,
                                     /* do_segmentation */ 0);
@@ -819,8 +846,12 @@ VLIB_REGISTER_NODE (gso_l2_ip4_node) = {
   .vector_size = sizeof (u32),
   .format_trace = format_gso_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = 0,
-  .n_next_nodes = 0,
+  .n_errors = ARRAY_LEN(gso_error_strings),
+  .error_strings = gso_error_strings,
+  .n_next_nodes = GSO_N_NEXT,
+  .next_nodes = {
+        [GSO_NEXT_DROP] = "error-drop",
+  },
   .name = "gso-l2-ip4",
 };
 
@@ -828,8 +859,12 @@ VLIB_REGISTER_NODE (gso_l2_ip6_node) = {
   .vector_size = sizeof (u32),
   .format_trace = format_gso_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = 0,
-  .n_next_nodes = 0,
+  .n_errors = ARRAY_LEN(gso_error_strings),
+  .error_strings = gso_error_strings,
+  .n_next_nodes = GSO_N_NEXT,
+  .next_nodes = {
+        [GSO_NEXT_DROP] = "error-drop",
+  },
   .name = "gso-l2-ip6",
 };
 
@@ -837,8 +872,12 @@ VLIB_REGISTER_NODE (gso_ip4_node) = {
   .vector_size = sizeof (u32),
   .format_trace = format_gso_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = 0,
-  .n_next_nodes = 0,
+  .n_errors = ARRAY_LEN(gso_error_strings),
+  .error_strings = gso_error_strings,
+  .n_next_nodes = GSO_N_NEXT,
+  .next_nodes = {
+        [GSO_NEXT_DROP] = "error-drop",
+  },
   .name = "gso-ip4",
 };
 
@@ -846,8 +885,12 @@ VLIB_REGISTER_NODE (gso_ip6_node) = {
   .vector_size = sizeof (u32),
   .format_trace = format_gso_trace,
   .type = VLIB_NODE_TYPE_INTERNAL,
-  .n_errors = 0,
-  .n_next_nodes = 0,
+  .n_errors = ARRAY_LEN(gso_error_strings),
+  .error_strings = gso_error_strings,
+  .n_next_nodes = GSO_N_NEXT,
+  .next_nodes = {
+        [GSO_NEXT_DROP] = "error-drop",
+  },
   .name = "gso-ip6",
 };