hsa: fix vpp_echo mq locking
[vpp.git] / src / plugins / gtpu / gtpu_decap.c
index b0be32e..2228992 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * decap.c: gtpu tunnel decap packet processing
  *
- * Copyright (c) 2013 Cisco and/or its affiliates.
+ * Copyright (c) 2017 Intel and/or its affiliates.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
@@ -19,8 +19,8 @@
 #include <vnet/pg/pg.h>
 #include <gtpu/gtpu.h>
 
-vlib_node_registration_t gtpu4_input_node;
-vlib_node_registration_t gtpu6_input_node;
+extern vlib_node_registration_t gtpu4_input_node;
+extern vlib_node_registration_t gtpu6_input_node;
 
 typedef struct {
   u32 next_index;
@@ -87,7 +87,7 @@ gtpu_input (vlib_main_t * vm,
   if (is_ip4)
     last_key4.as_u64 = ~0;
   else
-    memset (&last_key6, 0xff, sizeof (last_key6));
+    clib_memset (&last_key6, 0xff, sizeof (last_key6));
 
   from = vlib_frame_vector_args (from_frame);
   n_left_from = from_frame->n_vectors;
@@ -213,7 +213,7 @@ gtpu_input (vlib_main_t * vm,
               tunnel_index0 = last_tunnel_index;
            t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
              {
                error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -256,14 +256,14 @@ gtpu_input (vlib_main_t * vm,
                     next0 = GTPU_INPUT_NEXT_DROP;
                     goto trace0;
                   }
-                clib_memcpy (&last_key6, &key6_0, sizeof(key6_0));
+                clib_memcpy_fast (&last_key6, &key6_0, sizeof(key6_0));
                 tunnel_index0 = last_tunnel_index = p0[0];
               }
             else
               tunnel_index0 = last_tunnel_index;
            t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
              {
                error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -387,7 +387,7 @@ gtpu_input (vlib_main_t * vm,
               tunnel_index1 = last_tunnel_index;
            t1 = pool_elt_at_index (gtm->tunnels, tunnel_index1);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b1, t1, is_ip4) == 0))
              {
                error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -432,14 +432,14 @@ gtpu_input (vlib_main_t * vm,
                     goto trace1;
                   }
 
-                clib_memcpy (&last_key6, &key6_1, sizeof(key6_1));
+                clib_memcpy_fast (&last_key6, &key6_1, sizeof(key6_1));
                 tunnel_index1 = last_tunnel_index = p1[0];
               }
             else
               tunnel_index1 = last_tunnel_index;
            t1 = pool_elt_at_index (gtm->tunnels, tunnel_index1);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b1, t1, is_ip4) == 0))
              {
                error1 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -616,7 +616,7 @@ gtpu_input (vlib_main_t * vm,
               tunnel_index0 = last_tunnel_index;
            t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
              {
                error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -659,14 +659,14 @@ gtpu_input (vlib_main_t * vm,
                     next0 = GTPU_INPUT_NEXT_DROP;
                     goto trace00;
                   }
-                clib_memcpy (&last_key6, &key6_0, sizeof(key6_0));
+                clib_memcpy_fast (&last_key6, &key6_0, sizeof(key6_0));
                 tunnel_index0 = last_tunnel_index = p0[0];
               }
             else
               tunnel_index0 = last_tunnel_index;
            t0 = pool_elt_at_index (gtm->tunnels, tunnel_index0);
 
-           /* Validate GTPU tunnel encap-fib index agaist packet */
+           /* Validate GTPU tunnel encap-fib index against packet */
            if (PREDICT_FALSE (validate_gtpu_fib (b0, t0, is_ip4) == 0))
              {
                error0 = GTPU_ERROR_NO_SUCH_TUNNEL;
@@ -784,16 +784,14 @@ gtpu_input (vlib_main_t * vm,
   return from_frame->n_vectors;
 }
 
-static uword
-gtpu4_input (vlib_main_t * vm,
+VLIB_NODE_FN (gtpu4_input_node) (vlib_main_t * vm,
              vlib_node_runtime_t * node,
              vlib_frame_t * from_frame)
 {
        return gtpu_input(vm, node, from_frame, /* is_ip4 */ 1);
 }
 
-static uword
-gtpu6_input (vlib_main_t * vm,
+VLIB_NODE_FN (gtpu6_input_node) (vlib_main_t * vm,
              vlib_node_runtime_t * node,
              vlib_frame_t * from_frame)
 {
@@ -808,7 +806,6 @@ static char * gtpu_error_strings[] = {
 };
 
 VLIB_REGISTER_NODE (gtpu4_input_node) = {
-  .function = gtpu4_input,
   .name = "gtpu4-input",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -828,10 +825,7 @@ VLIB_REGISTER_NODE (gtpu4_input_node) = {
   // $$$$ .unformat_buffer = unformat_gtpu_header,
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (gtpu4_input_node, gtpu4_input)
-
 VLIB_REGISTER_NODE (gtpu6_input_node) = {
-  .function = gtpu6_input,
   .name = "gtpu6-input",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -851,9 +845,6 @@ VLIB_REGISTER_NODE (gtpu6_input_node) = {
   // $$$$ .unformat_buffer = unformat_gtpu_header,
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (gtpu6_input_node, gtpu6_input)
-
-
 typedef enum {
   IP_GTPU_BYPASS_NEXT_DROP,
   IP_GTPU_BYPASS_NEXT_GTPU,
@@ -933,8 +924,8 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
            }
 
          /* Setup packet for next IP feature */
-         vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0);
-         vnet_feature_next(vnet_buffer(b1)->sw_if_index[VLIB_RX], &next1, b1);
+         vnet_feature_next(&next0, b0);
+         vnet_feature_next(&next1, b1);
 
          if (is_ip4)
            {
@@ -982,7 +973,7 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
            }
 
          flags0 = b0->flags;
-         good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+         good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
 
          /* Don't verify UDP checksum for packets with explicit zero checksum. */
          good_udp0 |= udp0->checksum == 0;
@@ -998,14 +989,14 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
          /* Verify UDP checksum */
          if (PREDICT_FALSE (!good_udp0))
            {
-             if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+             if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
                {
                  if (is_ip4)
                    flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
                  else
                    flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
                  good_udp0 =
-                   (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+                   (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
                }
            }
 
@@ -1064,7 +1055,7 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
            }
 
          flags1 = b1->flags;
-         good_udp1 = (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+         good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
 
          /* Don't verify UDP checksum for packets with explicit zero checksum. */
          good_udp1 |= udp1->checksum == 0;
@@ -1080,14 +1071,14 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
          /* Verify UDP checksum */
          if (PREDICT_FALSE (!good_udp1))
            {
-             if ((flags1 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+             if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
                {
                  if (is_ip4)
                    flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
                  else
                    flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
                  good_udp1 =
-                   (flags1 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+                   (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
                }
            }
 
@@ -1141,7 +1132,7 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
            ip60 = vlib_buffer_get_current (b0);
 
          /* Setup packet for next IP feature */
-         vnet_feature_next(vnet_buffer(b0)->sw_if_index[VLIB_RX], &next0, b0);
+         vnet_feature_next(&next0, b0);
 
          if (is_ip4)
            /* Treat IP4 frag packets as "experimental" protocol for now
@@ -1182,7 +1173,7 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
            }
 
          flags0 = b0->flags;
-         good_udp0 = (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+         good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
 
          /* Don't verify UDP checksum for packets with explicit zero checksum. */
          good_udp0 |= udp0->checksum == 0;
@@ -1198,14 +1189,14 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
          /* Verify UDP checksum */
          if (PREDICT_FALSE (!good_udp0))
            {
-             if ((flags0 & IP_BUFFER_L4_CHECKSUM_COMPUTED) == 0)
+             if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
                {
                  if (is_ip4)
                    flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
                  else
                    flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
                  good_udp0 =
-                   (flags0 & IP_BUFFER_L4_CHECKSUM_CORRECT) != 0;
+                   (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
                }
            }
 
@@ -1242,8 +1233,7 @@ ip_gtpu_bypass_inline (vlib_main_t * vm,
   return frame->n_vectors;
 }
 
-static uword
-ip4_gtpu_bypass (vlib_main_t * vm,
+VLIB_NODE_FN (ip4_gtpu_bypass_node) (vlib_main_t * vm,
                  vlib_node_runtime_t * node,
                  vlib_frame_t * frame)
 {
@@ -1251,7 +1241,6 @@ ip4_gtpu_bypass (vlib_main_t * vm,
 }
 
 VLIB_REGISTER_NODE (ip4_gtpu_bypass_node) = {
-  .function = ip4_gtpu_bypass,
   .name = "ip4-gtpu-bypass",
   .vector_size = sizeof (u32),
 
@@ -1265,16 +1254,15 @@ VLIB_REGISTER_NODE (ip4_gtpu_bypass_node) = {
   .format_trace = format_ip4_forward_next_trace,
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_gtpu_bypass_node,ip4_gtpu_bypass)
-
+#ifndef CLIB_MARCH_VARIANT
 /* Dummy init function to get us linked in. */
 clib_error_t * ip4_gtpu_bypass_init (vlib_main_t * vm)
 { return 0; }
 
 VLIB_INIT_FUNCTION (ip4_gtpu_bypass_init);
+#endif /* CLIB_MARCH_VARIANT */
 
-static uword
-ip6_gtpu_bypass (vlib_main_t * vm,
+VLIB_NODE_FN (ip6_gtpu_bypass_node) (vlib_main_t * vm,
                  vlib_node_runtime_t * node,
                  vlib_frame_t * frame)
 {
@@ -1282,7 +1270,6 @@ ip6_gtpu_bypass (vlib_main_t * vm,
 }
 
 VLIB_REGISTER_NODE (ip6_gtpu_bypass_node) = {
-  .function = ip6_gtpu_bypass,
   .name = "ip6-gtpu-bypass",
   .vector_size = sizeof (u32),
 
@@ -1296,10 +1283,10 @@ VLIB_REGISTER_NODE (ip6_gtpu_bypass_node) = {
   .format_trace = format_ip6_forward_next_trace,
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_gtpu_bypass_node,ip6_gtpu_bypass)
-
+#ifndef CLIB_MARCH_VARIANT
 /* Dummy init function to get us linked in. */
 clib_error_t * ip6_gtpu_bypass_init (vlib_main_t * vm)
 { return 0; }
 
 VLIB_INIT_FUNCTION (ip6_gtpu_bypass_init);
+#endif /* CLIB_MARCH_VARIANT */