summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2020-04-09 07:34:08 -0400
committerMatthew Smith <mgsmith@netgate.com>2020-04-22 16:05:10 +0000
commit07bbaef593939e9d03ba131e03296587472514ce (patch)
tree9b8d175c427094064716fcb0068d431913f7d4f0 /src
parent0b04209edac55487c108ff5f2faf51cbd4c2cee7 (diff)
gre: Optimise encap node for tunnel types
Type: improvement Change-Id: I6627e22110be94c8127486ae009761494e734c04 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/gre/gre.c44
-rw-r--r--src/vnet/gre/gre.h3
-rw-r--r--src/vnet/gre/interface.c7
3 files changed, 45 insertions, 9 deletions
diff --git a/src/vnet/gre/gre.c b/src/vnet/gre/gre.c
index a4f38880a39..db16fa979cc 100644
--- a/src/vnet/gre/gre.c
+++ b/src/vnet/gre/gre.c
@@ -498,8 +498,10 @@ typedef enum
* @brief TX function. Only called for L2 payload including TEB or ERSPAN.
* L3 traffic uses the adj-midchains.
*/
-VLIB_NODE_FN (gre_encap_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+static_always_inline u32
+gre_encap_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame, gre_tunnel_type_t type)
{
gre_main_t *gm = &gre_main;
u32 *from, n_left_from;
@@ -537,7 +539,7 @@ VLIB_NODE_FN (gre_encap_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = adj_index[0];
vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = adj_index[1];
- if (PREDICT_FALSE (gt[0]->type == GRE_TUNNEL_TYPE_ERSPAN))
+ if (type == GRE_TUNNEL_TYPE_ERSPAN)
{
/* Encap GRE seq# and ERSPAN type II header */
erspan_t2_t *h0;
@@ -551,7 +553,7 @@ VLIB_NODE_FN (gre_encap_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
h0->t2_u64 = hdr;
h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[0]->session_id);
}
- if (PREDICT_FALSE (gt[1]->type == GRE_TUNNEL_TYPE_ERSPAN))
+ if (type == GRE_TUNNEL_TYPE_ERSPAN)
{
/* Encap GRE seq# and ERSPAN type II header */
erspan_t2_t *h0;
@@ -604,12 +606,13 @@ VLIB_NODE_FN (gre_encap_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = adj_index[0];
- if (PREDICT_FALSE (gt[0]->type == GRE_TUNNEL_TYPE_ERSPAN))
+ if (type == GRE_TUNNEL_TYPE_ERSPAN)
{
/* Encap GRE seq# and ERSPAN type II header */
erspan_t2_t *h0;
u32 seq_num;
u64 hdr;
+ ASSERT (gt[0]->type == GRE_TUNNEL_TYPE_ERSPAN);
vlib_buffer_advance (b[0], -sizeof (erspan_t2_t));
h0 = vlib_buffer_get_current (b[0]);
seq_num = clib_atomic_fetch_add (&gt[0]->gre_sn->seq_num, 1);
@@ -649,10 +652,37 @@ static char *gre_error_strings[] = {
#undef gre_error
};
+VLIB_NODE_FN (gre_teb_encap_node) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return (gre_encap_inline (vm, node, frame, GRE_TUNNEL_TYPE_TEB));
+}
+
+VLIB_NODE_FN (gre_erspan_encap_node) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return (gre_encap_inline (vm, node, frame, GRE_TUNNEL_TYPE_ERSPAN));
+}
+
/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (gre_encap_node) =
+VLIB_REGISTER_NODE (gre_teb_encap_node) =
+{
+ .name = "gre-teb-encap",
+ .vector_size = sizeof (u32),
+ .format_trace = format_gre_tx_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = GRE_N_ERROR,
+ .error_strings = gre_error_strings,
+ .n_next_nodes = GRE_ENCAP_N_NEXT,
+ .next_nodes = {
+ [GRE_ENCAP_NEXT_L2_MIDCHAIN] = "adj-l2-midchain",
+ },
+};
+VLIB_REGISTER_NODE (gre_erspan_encap_node) =
{
- .name = "gre-encap",
+ .name = "gre-erspan-encap",
.vector_size = sizeof (u32),
.format_trace = format_gre_tx_trace,
.type = VLIB_NODE_TYPE_INTERNAL,
diff --git a/src/vnet/gre/gre.h b/src/vnet/gre/gre.h
index 14798d85842..07f375d9124 100644
--- a/src/vnet/gre/gre.h
+++ b/src/vnet/gre/gre.h
@@ -340,7 +340,8 @@ format_function_t format_gre_header_with_length;
extern vlib_node_registration_t gre4_input_node;
extern vlib_node_registration_t gre6_input_node;
-extern vlib_node_registration_t gre_encap_node;
+extern vlib_node_registration_t gre_erspan_encap_node;
+extern vlib_node_registration_t gre_teb_encap_node;
extern vnet_device_class_t gre_device_class;
/* Parse gre protocol as 0xXXXX or protocol name.
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index 6efa3da13b8..f5a1bde527f 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -377,7 +377,12 @@ vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a,
}
/* Set GRE tunnel interface output node (not used for L3 payload) */
- vnet_set_interface_output_node (vnm, hw_if_index, gre_encap_node.index);
+ if (GRE_TUNNEL_TYPE_ERSPAN == t->type)
+ vnet_set_interface_output_node (vnm, hw_if_index,
+ gre_erspan_encap_node.index);
+ else
+ vnet_set_interface_output_node (vnm, hw_if_index,
+ gre_teb_encap_node.index);
hi = vnet_get_hw_interface (vnm, hw_if_index);
sw_if_index = hi->sw_if_index;