IPSEC-GRE: fixes and API update to common types.
[vpp.git] / src / vnet / ipsec-gre / ipsec_gre.c
index 758807b..cdb23dd 100644 (file)
 #include <vnet/vnet.h>
 #include <vnet/ipsec-gre/ipsec_gre.h>
 
+extern ipsec_gre_main_t ipsec_gre_main;
+
+#ifndef CLIB_MARCH_VARIANT
 ipsec_gre_main_t ipsec_gre_main;
+#endif /* CLIB_MARCH_VARIANT */
 
 /**
  * @brief IPv4 and GRE header union.
@@ -53,7 +57,7 @@ typedef struct
   u32 sa_id; /**< tunnel IPSec SA id */
 } ipsec_gre_tx_trace_t;
 
-u8 *
+static u8 *
 format_ipsec_gre_tx_trace (u8 * s, va_list * args)
 {
   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -92,9 +96,9 @@ format_ipsec_gre_tx_trace (u8 * s, va_list * args)
  * <em>Next Index:</em>
  * - Dispatches the packet to the esp-encrypt node.
 */
-static uword
-ipsec_gre_interface_tx (vlib_main_t * vm,
-                       vlib_node_runtime_t * node, vlib_frame_t * frame)
+VNET_DEVICE_CLASS_TX_FN (ipsec_gre_device_class) (vlib_main_t * vm,
+                                                 vlib_node_runtime_t * node,
+                                                 vlib_frame_t * frame)
 {
   ipsec_gre_main_t *igm = &ipsec_gre_main;
   u32 next_index;
@@ -102,6 +106,8 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
   vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
   ipsec_gre_tunnel_t *t = pool_elt_at_index (igm->tunnels, rd->dev_instance);
 
+  u16 l2_gre_protocol_ethertype = clib_net_to_host_u16 (GRE_PROTOCOL_teb);
+
   /* Vector of buffer / pkt indices we're supposed to process */
   from = vlib_frame_vector_args (frame);
 
@@ -127,7 +133,6 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
          ip4_and_gre_union_t *h0, *h1;
          u32 bi0, next0, bi1, next1;
          __attribute__ ((unused)) u8 error0, error1;
-         u16 gre_protocol0, gre_protocol1;
 
          /* Prefetch the next iteration */
          {
@@ -164,12 +169,6 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
          b0 = vlib_get_buffer (vm, bi0);
          b1 = vlib_get_buffer (vm, bi1);
 
-         ip0 = vlib_buffer_get_current (b0);
-         gre_protocol0 = clib_net_to_host_u16 (0x01);
-
-         ip1 = vlib_buffer_get_current (b1);
-         gre_protocol1 = clib_net_to_host_u16 (0x01);
-
          vlib_buffer_advance (b0, -sizeof (*h0));
          vlib_buffer_advance (b1, -sizeof (*h1));
 
@@ -184,13 +183,13 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
          h1->as_u64[2] = 0;
 
          ip0 = &h0->ip4_and_gre.ip4;
-         h0->ip4_and_gre.gre.protocol = gre_protocol0;
+         h0->ip4_and_gre.gre.protocol = l2_gre_protocol_ethertype;
          ip0->ip_version_and_header_length = 0x45;
          ip0->ttl = 254;
          ip0->protocol = IP_PROTOCOL_GRE;
 
          ip1 = &h1->ip4_and_gre.ip4;
-         h1->ip4_and_gre.gre.protocol = gre_protocol1;
+         h1->ip4_and_gre.gre.protocol = l2_gre_protocol_ethertype;
          ip1->ip_version_and_header_length = 0x45;
          ip1->ttl = 254;
          ip1->protocol = IP_PROTOCOL_GRE;
@@ -256,7 +255,6 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
          ip4_and_gre_union_t *h0;
          u32 bi0, next0;
          __attribute__ ((unused)) u8 error0;
-         u16 gre_protocol0;
 
          bi0 = to_next[0] = from[0];
          from += 1;
@@ -266,8 +264,6 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
 
          b0 = vlib_get_buffer (vm, bi0);
 
-         gre_protocol0 = clib_net_to_host_u16 (0x01);
-
          vlib_buffer_advance (b0, -sizeof (*h0));
 
          h0 = vlib_buffer_get_current (b0);
@@ -276,7 +272,7 @@ ipsec_gre_interface_tx (vlib_main_t * vm,
          h0->as_u64[2] = 0;
 
          ip0 = &h0->ip4_and_gre.ip4;
-         h0->ip4_and_gre.gre.protocol = gre_protocol0;
+         h0->ip4_and_gre.gre.protocol = l2_gre_protocol_ethertype;
          ip0->ip_version_and_header_length = 0x45;
          ip0->ttl = 254;
          ip0->protocol = IP_PROTOCOL_GRE;
@@ -355,17 +351,15 @@ VNET_DEVICE_CLASS (ipsec_gre_device_class) = {
   .format_device_name = format_ipsec_gre_tunnel_name,
   .format_device = format_ipsec_gre_device,
   .format_tx_trace = format_ipsec_gre_tx_trace,
-  .tx_function = ipsec_gre_interface_tx,
   .admin_up_down_function = ipsec_gre_interface_admin_up_down,
 };
 
-VLIB_DEVICE_TX_FUNCTION_MULTIARCH (ipsec_gre_device_class,
-                                  ipsec_gre_interface_tx)
-
 
+#ifndef CLIB_MARCH_VARIANT
 VNET_HW_INTERFACE_CLASS (ipsec_gre_hw_interface_class) = {
   .name = "IPSEC-GRE",
 };
+#endif /* CLIB_MARCH_VARIANT */
 /* *INDENT-ON* */
 
 static clib_error_t *