diff options
author | Neale Ranns <nranns@cisco.com> | 2020-04-09 07:34:08 -0400 |
---|---|---|
committer | Matthew Smith <mgsmith@netgate.com> | 2020-04-22 16:05:10 +0000 |
commit | 07bbaef593939e9d03ba131e03296587472514ce (patch) | |
tree | 9b8d175c427094064716fcb0068d431913f7d4f0 /src/vnet/gre/gre.c | |
parent | 0b04209edac55487c108ff5f2faf51cbd4c2cee7 (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/vnet/gre/gre.c')
-rw-r--r-- | src/vnet/gre/gre.c | 44 |
1 files changed, 37 insertions, 7 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 (>[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, |