/* Fixup the payload length field in the GRE tunnel encap that was applied
* at the midchain node */
ip0->payload_length =
- clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0))
- - sizeof (*ip0);
+ clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
+ sizeof (*ip0));
}
void
{
gre_main_t *gm = &gre_main;
gre_tunnel_t *t;
- u32 ti;
+ adj_flags_t af;
u8 is_ipv6;
+ u32 ti;
ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
t = pool_elt_at_index (gm->tunnels, ti);
is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
+ af = ADJ_FLAG_MIDCHAIN_IP_STACK;
+
+ if (VNET_LINK_ETHERNET == adj_get_link_type (ai))
+ af |= ADJ_FLAG_MIDCHAIN_NO_COUNT;
adj_nbr_midchain_update_rewrite
- (ai, !is_ipv6 ? gre4_fixup : gre6_fixup, NULL,
- (VNET_LINK_ETHERNET == adj_get_link_type (ai) ?
- ADJ_FLAG_MIDCHAIN_NO_COUNT : ADJ_FLAG_NONE),
+ (ai, !is_ipv6 ? gre4_fixup : gre6_fixup, NULL, af,
gre_build_rewrite (vnm, sw_if_index, adj_get_link_type (ai), NULL));
gre_tunnel_stack (ai);
typedef enum
{
- GRE_ENCAP_NEXT_DROP,
GRE_ENCAP_NEXT_L2_MIDCHAIN,
GRE_ENCAP_N_NEXT,
} gre_encap_next_t;
-#define NEXT_IDX (GRE_ENCAP_NEXT_L2_MIDCHAIN)
-
/**
* @brief TX function. Only called for L2 payload including TEB or ERSPAN.
* L3 traffic uses the adj-midchains.
n_left_from = frame->n_vectors;
/* Speculatively send the first buffer to the last disposition we used */
- next_index = node->cached_next_index;
+ next_index = GRE_ENCAP_NEXT_L2_MIDCHAIN;
while (n_left_from > 0)
{
adj_index0 = gt0->l2_adj_index;
}
- if (sw_if_index0 == vnet_buffer (b1)->sw_if_index[VLIB_TX])
- {
- sw_if_index1 = sw_if_index0;
- gt1 = gt0;
- adj_index1 = adj_index0;
- }
- else if (sw_if_index1 != vnet_buffer (b1)->sw_if_index[VLIB_TX])
+ if (sw_if_index1 != vnet_buffer (b1)->sw_if_index[VLIB_TX])
{
- sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
- vnet_hw_interface_t *hi1 =
- vnet_get_sup_hw_interface (vnm, sw_if_index1);
- gt1 = &gm->tunnels[hi1->dev_instance];
- adj_index1 = gt1->l2_adj_index;
+ if (sw_if_index0 == vnet_buffer (b1)->sw_if_index[VLIB_TX])
+ {
+ sw_if_index1 = sw_if_index0;
+ gt1 = gt0;
+ adj_index1 = adj_index0;
+ }
+ else
+ {
+ sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
+ vnet_hw_interface_t *hi1 =
+ vnet_get_sup_hw_interface (vnm, sw_if_index1);
+ gt1 = &gm->tunnels[hi1->dev_instance];
+ adj_index1 = gt1->l2_adj_index;
+ }
}
vnet_buffer (b0)->ip.adj_index[VLIB_TX] = adj_index0;
/* Encap GRE seq# and ERSPAN type II header */
vlib_buffer_advance (b0, -sizeof (erspan_t2_t));
erspan_t2_t *h0 = vlib_buffer_get_current (b0);
- u32 seq_num = clib_smp_atomic_add (>0->gre_sn->seq_num, 1);
- u64 ver1 = clib_host_to_net_u64 (0x1000000000000000);
+ u32 seq_num = clib_atomic_fetch_add (>0->gre_sn->seq_num, 1);
+ u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
h0->seq_num = clib_host_to_net_u32 (seq_num);
- h0->t2_u64 = ver1; /* all 0's except ver=1 */
- h0->t2.cos_en_t_session =
+ h0->t2_u64 = hdr;
+ h0->t2.cos_en_t_session |=
clib_host_to_net_u16 (gt0->session_id);
}
if (PREDICT_FALSE (gt1->type == GRE_TUNNEL_TYPE_ERSPAN))
/* Encap GRE seq# and ERSPAN type II header */
vlib_buffer_advance (b1, -sizeof (erspan_t2_t));
erspan_t2_t *h1 = vlib_buffer_get_current (b1);
- u32 seq_num = clib_smp_atomic_add (>1->gre_sn->seq_num, 1);
- u64 ver1 = clib_host_to_net_u64 (0x1000000000000000);
+ u32 seq_num = clib_atomic_fetch_add (>1->gre_sn->seq_num, 1);
+ u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
h1->seq_num = clib_host_to_net_u32 (seq_num);
- h1->t2_u64 = ver1; /* all 0's except ver=1 */
- h1->t2.cos_en_t_session =
+ h1->t2_u64 = hdr;
+ h1->t2.cos_en_t_session |=
clib_host_to_net_u16 (gt1->session_id);
}
tr1->dst = gt1->tunnel_dst.fp_addr;
tr1->length = vlib_buffer_length_in_chain (vm, b1);
}
-
- vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, bi1, NEXT_IDX, NEXT_IDX);
}
while (n_left_from > 0 && n_left_to_next > 0)
/* Encap GRE seq# and ERSPAN type II header */
vlib_buffer_advance (b0, -sizeof (erspan_t2_t));
erspan_t2_t *h0 = vlib_buffer_get_current (b0);
- u32 seq_num = clib_smp_atomic_add (>0->gre_sn->seq_num, 1);
- u64 ver1 = clib_host_to_net_u64 (0x1000000000000000);
+ u32 seq_num = clib_atomic_fetch_add (>0->gre_sn->seq_num, 1);
+ u64 hdr = clib_host_to_net_u64 (ERSPAN_HDR2);
h0->seq_num = clib_host_to_net_u32 (seq_num);
- h0->t2_u64 = ver1; /* all 0's except ver=1 */
- h0->t2.cos_en_t_session =
+ h0->t2_u64 = hdr;
+ h0->t2.cos_en_t_session |=
clib_host_to_net_u16 (gt0->session_id);
}
tr->dst = gt0->tunnel_dst.fp_addr;
tr->length = vlib_buffer_length_in_chain (vm, b0);
}
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0, NEXT_IDX);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
.error_strings = gre_error_strings,
.n_next_nodes = GRE_ENCAP_N_NEXT,
.next_nodes = {
- [GRE_ENCAP_NEXT_DROP] = "error-drop",
[GRE_ENCAP_NEXT_L2_MIDCHAIN] = "adj-l2-midchain",
},
};
ip_main_t *im = &ip_main;
ip_protocol_info_t *pi;
- memset (gm, 0, sizeof (gm[0]));
+ clib_memset (gm, 0, sizeof (gm[0]));
gm->vlib_main = vm;
gm->vnet_main = vnet_get_main ();
VLIB_INIT_FUNCTION (gre_init);
-gre_main_t *
-gre_get_main (vlib_main_t * vm)
-{
- vlib_call_init_function (vm, gre_init);
- return &gre_main;
-}
-
-
/*
* fd.io coding-style-patch-verification: ON
*