IPSEC; dpdk backend for tunnel interface encryption
[vpp.git] / src / vnet / ipsec-gre / node.c
index d20f248..6a3aaa1 100644 (file)
@@ -43,7 +43,7 @@ typedef struct {
   ip4_address_t dst;
 } ipsec_gre_rx_trace_t;
 
-u8 * format_ipsec_gre_rx_trace (u8 * s, va_list * args)
+static u8 * format_ipsec_gre_rx_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 *);
@@ -83,8 +83,7 @@ u8 * format_ipsec_gre_rx_trace (u8 * s, va_list * args)
  * <em>Next Index:</em>
  * - Dispatches the packet to the l2-input node.
 */
-static uword
-ipsec_gre_input (vlib_main_t * vm,
+VLIB_NODE_FN (ipsec_gre_input_node) (vlib_main_t * vm,
                  vlib_node_runtime_t * node,
                  vlib_frame_t * from_frame)
 {
@@ -92,6 +91,8 @@ ipsec_gre_input (vlib_main_t * vm,
   u32 n_left_from, next_index, * from, * to_next;
   u64 cached_tunnel_key = (u64) ~0;
   u32 cached_tunnel_sw_if_index = 0, tunnel_sw_if_index;
+  u32 tun_src0, tun_dst0;
+  u32 tun_src1, tun_dst1;
 
   from = vlib_frame_vector_args (from_frame);
   n_left_from = from_frame->n_vectors;
@@ -146,10 +147,10 @@ ipsec_gre_input (vlib_main_t * vm,
           ip1 = vlib_buffer_get_current (b1);
 
           /* Save src + dst ip4 address */
-          vnet_buffer(b0)->gre.src = ip0->src_address.as_u32;
-          vnet_buffer(b0)->gre.dst = ip0->dst_address.as_u32;
-          vnet_buffer(b1)->gre.src = ip1->src_address.as_u32;
-          vnet_buffer(b1)->gre.dst = ip1->dst_address.as_u32;
+          tun_src0 = ip0->src_address.as_u32;
+          tun_dst0 = ip0->dst_address.as_u32;
+          tun_src1 = ip1->src_address.as_u32;
+          tun_dst1 = ip1->dst_address.as_u32;
 
           vlib_buffer_advance (b0, sizeof (*ip0));
           vlib_buffer_advance (b1, sizeof (*ip1));
@@ -159,25 +160,23 @@ ipsec_gre_input (vlib_main_t * vm,
 
           protocol0 = clib_net_to_host_u16 (h0->protocol);
           protocol1 = clib_net_to_host_u16 (h1->protocol);
-          if (PREDICT_TRUE(protocol0 == 0x0001))
+          if (PREDICT_TRUE(protocol0 == GRE_PROTOCOL_teb))
             {
               next0 = IPSEC_GRE_INPUT_NEXT_L2_INPUT;
               b0->error = node->errors[IPSEC_GRE_ERROR_NONE];
             }
           else
             {
-              clib_warning("unknown GRE protocol: %d", protocol0);
               b0->error = node->errors[IPSEC_GRE_ERROR_UNKNOWN_PROTOCOL];
               next0 = IPSEC_GRE_INPUT_NEXT_DROP;
             }
-          if (PREDICT_TRUE(protocol1 == 0x0001))
+          if (PREDICT_TRUE(protocol1 == GRE_PROTOCOL_teb))
             {
               next1 = IPSEC_GRE_INPUT_NEXT_L2_INPUT;
               b1->error = node->errors[IPSEC_GRE_ERROR_NONE];
             }
           else
             {
-              clib_warning("unknown GRE protocol: %d", protocol1);
               b1->error = node->errors[IPSEC_GRE_ERROR_UNKNOWN_PROTOCOL];
               next1 = IPSEC_GRE_INPUT_NEXT_DROP;
             }
@@ -197,8 +196,7 @@ ipsec_gre_input (vlib_main_t * vm,
           /* For L2 payload set input sw_if_index to GRE tunnel for learning */
           if (PREDICT_TRUE(next0 == IPSEC_GRE_INPUT_NEXT_L2_INPUT))
             {
-              u64 key = ((u64)(vnet_buffer(b0)->gre.dst) << 32) |
-                         (u64)(vnet_buffer(b0)->gre.src);
+              u64 key = ((u64)(tun_dst0) << 32) | (u64)(tun_src0);
 
               if (cached_tunnel_key != key)
                 {
@@ -230,8 +228,7 @@ drop0:
           /* For L2 payload set input sw_if_index to GRE tunnel for learning */
           if (PREDICT_TRUE(next1 == IPSEC_GRE_INPUT_NEXT_L2_INPUT))
             {
-              u64 key = ((u64)(vnet_buffer(b1)->gre.dst) << 32) |
-                         (u64)(vnet_buffer(b1)->gre.src);
+              u64 key = ((u64)(tun_dst1) << 32) | (u64)(tun_src1);
 
               if (cached_tunnel_key != key)
                 {
@@ -297,6 +294,7 @@ drop1:
           u16 version0, protocol0;
           int verr0;
          u32 next0;
+         u32 tun_src0, tun_dst0;
 
          bi0 = from[0];
          to_next[0] = bi0;
@@ -308,22 +306,21 @@ drop1:
          b0 = vlib_get_buffer (vm, bi0);
           ip0 = vlib_buffer_get_current (b0);
 
-          vnet_buffer(b0)->gre.src = ip0->src_address.as_u32;
-          vnet_buffer(b0)->gre.dst = ip0->dst_address.as_u32;
+          tun_src0 = ip0->src_address.as_u32;
+          tun_dst0 = ip0->dst_address.as_u32;
 
           vlib_buffer_advance (b0, sizeof (*ip0));
 
          h0 = vlib_buffer_get_current (b0);
 
           protocol0 = clib_net_to_host_u16 (h0->protocol);
-          if (PREDICT_TRUE(protocol0 == 0x0001))
+          if (PREDICT_TRUE(protocol0 == GRE_PROTOCOL_teb))
             {
               next0 = IPSEC_GRE_INPUT_NEXT_L2_INPUT;
               b0->error = node->errors[IPSEC_GRE_ERROR_NONE];
             }
           else
             {
-              clib_warning("unknown GRE protocol: %d", protocol0);
               b0->error = node->errors[IPSEC_GRE_ERROR_UNKNOWN_PROTOCOL];
               next0 = IPSEC_GRE_INPUT_NEXT_DROP;
             }
@@ -335,10 +332,9 @@ drop1:
           next0 = verr0 ? IPSEC_GRE_INPUT_NEXT_DROP : next0;
 
           /* For L2 payload set input sw_if_index to GRE tunnel for learning */
-          if (PREDICT_FALSE(next0 == IPSEC_GRE_INPUT_NEXT_L2_INPUT))
+          if (PREDICT_TRUE(next0 == IPSEC_GRE_INPUT_NEXT_L2_INPUT))
             {
-              u64 key = ((u64)(vnet_buffer(b0)->gre.dst) << 32) |
-                         (u64)(vnet_buffer(b0)->gre.src);
+              u64 key = ((u64)(tun_dst0) << 32) | (u64)(tun_src0);
 
               if (cached_tunnel_key != key)
                 {
@@ -398,7 +394,6 @@ static char * ipsec_gre_error_strings[] = {
 };
 
 VLIB_REGISTER_NODE (ipsec_gre_input_node) = {
-  .function = ipsec_gre_input,
   .name = "ipsec-gre-input",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -416,8 +411,6 @@ VLIB_REGISTER_NODE (ipsec_gre_input_node) = {
   .format_trace = format_ipsec_gre_rx_trace,
 };
 
-VLIB_NODE_FUNCTION_MULTIARCH (ipsec_gre_input_node, ipsec_gre_input)
-
 static clib_error_t * ipsec_gre_input_init (vlib_main_t * vm)
 {
   {