ipv6: vectorized ext header check
[vpp.git] / src / vnet / ip / ip6_hop_by_hop.c
index df2a932..da01970 100644 (file)
  * in-band OAM can be enabled for IPv6 traffic.
  */
 
+#ifndef CLIB_MARCH_VARIANT
 ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
+#endif /* CLIB_MARCH_VARIANT */
 
 #define foreach_ip6_hbyh_ioam_input_next       \
   _(IP6_REWRITE, "ip6-rewrite")                        \
   _(IP6_LOOKUP, "ip6-lookup")                  \
-  _(DROP, "error-drop")
+  _(DROP, "ip6-drop")
 
 typedef enum
 {
@@ -56,6 +58,7 @@ typedef enum
     IP6_HBYH_IOAM_INPUT_N_NEXT,
 } ip6_hbyh_ioam_input_next_t;
 
+#ifndef CLIB_MARCH_VARIANT
 static uword
 unformat_opaque_ioam (unformat_input_t * input, va_list * args)
 {
@@ -103,7 +106,7 @@ ip6_hbh_add_register_option (u8 option,
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->add_options));
+  ASSERT ((u32) option < ARRAY_LEN (hm->add_options));
 
   /* Already registered */
   if (hm->add_options[option])
@@ -120,7 +123,7 @@ ip6_hbh_add_unregister_option (u8 option)
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->add_options));
+  ASSERT ((u32) option < ARRAY_LEN (hm->add_options));
 
   /* Not registered */
   if (!hm->add_options[option])
@@ -138,7 +141,7 @@ ip6_hbh_config_handler_register (u8 option,
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->config_handler));
+  ASSERT ((u32) option < ARRAY_LEN (hm->config_handler));
 
   /* Already registered  */
   if (hm->config_handler[option])
@@ -154,7 +157,7 @@ ip6_hbh_config_handler_unregister (u8 option)
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->config_handler));
+  ASSERT ((u32) option < ARRAY_LEN (hm->config_handler));
 
   /* Not registered */
   if (!hm->config_handler[option])
@@ -171,7 +174,7 @@ ip6_hbh_flow_handler_register (u8 option,
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->flow_handler));
+  ASSERT ((u32) option < ARRAY_LEN (hm->flow_handler));
 
   /* Already registered */
   if (hm->flow_handler[option])
@@ -187,7 +190,7 @@ ip6_hbh_flow_handler_unregister (u8 option)
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->flow_handler));
+  ASSERT ((u32) option < ARRAY_LEN (hm->flow_handler));
 
   /* Not registered */
   if (!hm->flow_handler[option])
@@ -196,6 +199,7 @@ ip6_hbh_flow_handler_unregister (u8 option)
   hm->flow_handler[option] = NULL;
   return (0);
 }
+#endif /* CLIB_MARCH_VARIANT */
 
 typedef struct
 {
@@ -215,7 +219,7 @@ format_ip6_add_hop_by_hop_trace (u8 * s, va_list * args)
   return s;
 }
 
-vlib_node_registration_t ip6_add_hop_by_hop_node;
+extern vlib_node_registration_t ip6_add_hop_by_hop_node;
 
 #define foreach_ip6_add_hop_by_hop_error \
 _(PROCESSED, "Pkts w/ added ip6 hop-by-hop options")
@@ -234,9 +238,9 @@ static char *ip6_add_hop_by_hop_error_strings[] = {
 #undef _
 };
 
-static uword
-ip6_add_hop_by_hop_node_fn (vlib_main_t * vm,
-                           vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_add_hop_by_hop_node) (vlib_main_t * vm,
+                                       vlib_node_runtime_t * node,
+                                       vlib_frame_t * frame)
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
   u32 n_left_from, *from, *to_next;
@@ -321,8 +325,8 @@ ip6_add_hop_by_hop_node_fn (vlib_main_t * vm,
          hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
          hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
          /* $$$ tune, rewrite_length is a multiple of 8 */
-         clib_memcpy (hbh0, rewrite, rewrite_length);
-         clib_memcpy (hbh1, rewrite, rewrite_length);
+         clib_memcpy_fast (hbh0, rewrite, rewrite_length);
+         clib_memcpy_fast (hbh1, rewrite, rewrite_length);
          /* Patch the protocol chain, insert the h-b-h (type 0) header */
          hbh0->protocol = ip0->protocol;
          hbh1->protocol = ip1->protocol;
@@ -399,7 +403,7 @@ ip6_add_hop_by_hop_node_fn (vlib_main_t * vm,
 
          hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
          /* $$$ tune, rewrite_length is a multiple of 8 */
-         clib_memcpy (hbh0, rewrite, rewrite_length);
+         clib_memcpy_fast (hbh0, rewrite, rewrite_length);
          /* Patch the protocol chain, insert the h-b-h (type 0) header */
          hbh0->protocol = ip0->protocol;
          ip0->protocol = 0;
@@ -437,7 +441,7 @@ ip6_add_hop_by_hop_node_fn (vlib_main_t * vm,
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_add_hop_by_hop_node) = /* *INDENT-OFF* */
 {
-  .function = ip6_add_hop_by_hop_node_fn,.name =
+  .name =
     "ip6-add-hop-by-hop",.vector_size = sizeof (u32),.format_trace =
     format_ip6_add_hop_by_hop_trace,.type =
     VLIB_NODE_TYPE_INTERNAL,.n_errors =
@@ -455,8 +459,6 @@ VLIB_REGISTER_NODE (ip6_add_hop_by_hop_node) =      /* *INDENT-OFF* */
 
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_add_hop_by_hop_node,
-                             ip6_add_hop_by_hop_node_fn);
 /* The main h-b-h tracer was already invoked, no need to do much here */
 typedef struct
 {
@@ -476,6 +478,7 @@ format_ip6_pop_hop_by_hop_trace (u8 * s, va_list * args)
   return s;
 }
 
+#ifndef CLIB_MARCH_VARIANT
 int
 ip6_hbh_pop_register_option (u8 option,
                             int options (vlib_buffer_t * b,
@@ -484,7 +487,7 @@ ip6_hbh_pop_register_option (u8 option,
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->pop_options));
+  ASSERT ((u32) option < ARRAY_LEN (hm->pop_options));
 
   /* Already registered */
   if (hm->pop_options[option])
@@ -500,7 +503,7 @@ ip6_hbh_pop_unregister_option (u8 option)
 {
   ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
 
-  ASSERT (option < ARRAY_LEN (hm->pop_options));
+  ASSERT ((u32) option < ARRAY_LEN (hm->pop_options));
 
   /* Not registered */
   if (!hm->pop_options[option])
@@ -509,8 +512,9 @@ ip6_hbh_pop_unregister_option (u8 option)
   hm->pop_options[option] = NULL;
   return (0);
 }
+#endif /* CLIB_MARCH_VARIANT */
 
-vlib_node_registration_t ip6_pop_hop_by_hop_node;
+extern vlib_node_registration_t ip6_pop_hop_by_hop_node;
 
 #define foreach_ip6_pop_hop_by_hop_error                \
 _(PROCESSED, "Pkts w/ removed ip6 hop-by-hop options")  \
@@ -577,12 +581,10 @@ ioam_pop_hop_by_hop_processing (vlib_main_t * vm,
     }
 }
 
-static uword
-ip6_pop_hop_by_hop_node_fn (vlib_main_t * vm,
-                           vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (ip6_pop_hop_by_hop_node) (vlib_main_t * vm,
+                                       vlib_node_runtime_t * node,
+                                       vlib_frame_t * frame)
 {
-  ip6_main_t *im = &ip6_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
   u32 n_left_from, *from, *to_next;
   ip_lookup_next_t next_index;
   u32 processed = 0;
@@ -640,8 +642,8 @@ ip6_pop_hop_by_hop_node_fn (vlib_main_t * vm,
          ip1 = vlib_buffer_get_current (b1);
          adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
          adj_index1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
-         adj0 = ip_get_adjacency (lm, adj_index0);
-         adj1 = ip_get_adjacency (lm, adj_index1);
+         adj0 = adj_get (adj_index0);
+         adj1 = adj_get (adj_index1);
 
          next0 = adj0->lookup_next_index;
          next1 = adj1->lookup_next_index;
@@ -729,7 +731,7 @@ ip6_pop_hop_by_hop_node_fn (vlib_main_t * vm,
 
          ip0 = vlib_buffer_get_current (b0);
          adj_index0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
-         adj0 = ip_get_adjacency (lm, adj_index0);
+         adj0 = adj_get (adj_index0);
 
          /* Default use the next_index from the adjacency. */
          next0 = adj0->lookup_next_index;
@@ -781,7 +783,7 @@ ip6_pop_hop_by_hop_node_fn (vlib_main_t * vm,
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (ip6_pop_hop_by_hop_node) =
 {
-  .function = ip6_pop_hop_by_hop_node_fn,.name =
+  .name =
     "ip6-pop-hop-by-hop",.vector_size = sizeof (u32),.format_trace =
     format_ip6_pop_hop_by_hop_trace,.type =
     VLIB_NODE_TYPE_INTERNAL,.sibling_of = "ip6-lookup",.n_errors =
@@ -792,8 +794,7 @@ VLIB_REGISTER_NODE (ip6_pop_hop_by_hop_node) =
 
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_pop_hop_by_hop_node,
-                             ip6_pop_hop_by_hop_node_fn);
+#ifndef CLIB_MARCH_VARIANT
 static clib_error_t *
 ip6_hop_by_hop_ioam_init (vlib_main_t * vm)
 {
@@ -811,9 +812,9 @@ ip6_hop_by_hop_ioam_init (vlib_main_t * vm)
   hm->unix_time_0 = (u32) time (0);    /* Store starting time */
   hm->vlib_time_0 = vlib_time_now (vm);
   hm->ioam_flag = IOAM_HBYH_MOD;
-  memset (hm->add_options, 0, sizeof (hm->add_options));
-  memset (hm->pop_options, 0, sizeof (hm->pop_options));
-  memset (hm->options_size, 0, sizeof (hm->options_size));
+  clib_memset (hm->add_options, 0, sizeof (hm->add_options));
+  clib_memset (hm->pop_options, 0, sizeof (hm->pop_options));
+  clib_memset (hm->options_size, 0, sizeof (hm->options_size));
 
   vnet_classify_register_unformat_opaque_index_fn (unformat_opaque_ioam);
 
@@ -1159,6 +1160,7 @@ vnet_register_ioam_end_of_path_callback (void *cb)
   hm->ioam_end_of_path_cb = cb;
 }
 
+#endif /* CLIB_MARCH_VARIANT */
 /*
  * fd.io coding-style-patch-verification: ON
  *