24 #define foreach_gre_input_next \ 25 _(PUNT, "error-punt") \ 26 _(DROP, "error-drop") \ 27 _(ETHERNET_INPUT, "ethernet-input") \ 28 _(IP4_INPUT, "ip4-input") \ 29 _(IP6_INPUT, "ip6-input") \ 30 _(MPLS_INPUT, "mpls-input") 33 #define _(s,n) GRE_INPUT_NEXT_##s, 53 s =
format (s,
"GRE: tunnel %d len %d src %U dst %U",
73 __attribute__((unused))
u32 n_left_from, next_index, * from, * to_next;
74 u64 cached_tunnel_key4;
75 u64 cached_tunnel_key6[4];
76 u32 cached_tunnel_sw_if_index = 0, tunnel_sw_if_index = 0;
83 memset (&cached_tunnel_key4, 0xff,
sizeof(cached_tunnel_key4));
85 memset (&cached_tunnel_key6, 0xff,
sizeof(cached_tunnel_key6));
92 while (n_left_from > 0)
97 to_next, n_left_to_next);
99 while (n_left_from >= 4 && n_left_to_next >= 2)
104 u16 version0, version1;
106 u32 i0, i1, next0, next1, protocol0, protocol1;
109 u32 ip4_tun_src0, ip4_tun_dst0;
110 u32 ip4_tun_src1, ip4_tun_dst1;
111 u64 ip6_tun_src0[2], ip6_tun_dst0[2];
112 u64 ip6_tun_src1[2], ip6_tun_dst1[2];
192 b0->
error = verr0 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION]
194 next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
195 b1->
error = verr1 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION]
197 next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1;
202 || next0 == GRE_INPUT_NEXT_IP6_INPUT
203 || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
204 || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
210 key4 = ((
u64)(ip4_tun_dst0) << 32) | (
u64)(ip4_tun_src0);
214 key6[0] = ip6_tun_dst0[0];
215 key6[1] = ip6_tun_dst0[1];
216 key6[2] = ip6_tun_src0[0];
217 key6[3] = ip6_tun_src0[1];
220 if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
221 (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
222 cached_tunnel_key6[1] != key6[1] &&
223 cached_tunnel_key6[2] != key6[2] &&
224 cached_tunnel_key6[3] != key6[3]))
236 next0 = GRE_INPUT_NEXT_DROP;
237 b0->
error = node->
errors[GRE_ERROR_NO_SUCH_TUNNEL];
245 cached_tunnel_sw_if_index = tunnel_sw_if_index;
249 tunnel_sw_if_index = cached_tunnel_sw_if_index;
254 next0 = GRE_INPUT_NEXT_DROP;
269 || next1 == GRE_INPUT_NEXT_IP6_INPUT
270 || next1 == GRE_INPUT_NEXT_ETHERNET_INPUT
271 || next1 == GRE_INPUT_NEXT_MPLS_INPUT))
276 key4 = ((
u64)(ip4_tun_dst1) << 32) | (
u64)(ip4_tun_src1);
280 key6[0] = ip6_tun_dst1[0];
281 key6[1] = ip6_tun_dst1[1];
282 key6[2] = ip6_tun_src1[0];
283 key6[3] = ip6_tun_src1[1];
286 if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
287 (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
288 cached_tunnel_key6[1] != key6[1] &&
289 cached_tunnel_key6[2] != key6[2] &&
290 cached_tunnel_key6[3] != key6[3]))
303 next1 = GRE_INPUT_NEXT_DROP;
304 b1->
error = node->
errors[GRE_ERROR_NO_SUCH_TUNNEL];
312 cached_tunnel_sw_if_index = tunnel_sw_if_index;
316 tunnel_sw_if_index = cached_tunnel_sw_if_index;
321 next1 = GRE_INPUT_NEXT_DROP;
381 to_next, n_left_to_next,
382 bi0, bi1, next0, next1);
385 while (n_left_from > 0 && n_left_to_next > 0)
395 u32 ip4_tun_src0, ip4_tun_dst0;
396 u32 ip6_tun_src0[4], ip6_tun_dst0[4];
407 ip6_0 = (
void *)ip4_0;
433 ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE];
437 b0->
error = verr0 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION]
439 next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
447 || next0 == GRE_INPUT_NEXT_IP6_INPUT
448 || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
449 || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
454 key4 = ((
u64)(ip4_tun_dst0) << 32) | (
u64)(ip4_tun_src0);
458 key6[0] = ip6_tun_dst0[0];
459 key6[1] = ip6_tun_dst0[1];
460 key6[2] = ip6_tun_src0[0];
461 key6[3] = ip6_tun_src0[1];
464 if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
465 (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
466 cached_tunnel_key6[1] != key6[1] &&
467 cached_tunnel_key6[2] != key6[2] &&
468 cached_tunnel_key6[3] != key6[3]))
481 next0 = GRE_INPUT_NEXT_DROP;
482 b0->
error = node->
errors[GRE_ERROR_NO_SUCH_TUNNEL];
490 cached_tunnel_sw_if_index = tunnel_sw_if_index;
494 tunnel_sw_if_index = cached_tunnel_sw_if_index;
499 next0 = GRE_INPUT_NEXT_DROP;
537 to_next, n_left_to_next,
544 GRE_ERROR_PKTS_DECAP, from_frame->
n_vectors);
553 return gre_input(vm, node, from_frame, 0);
561 return gre_input(vm, node, from_frame, 1);
565 #define gre_error(n,s) s, 572 .name =
"gre4-input",
574 .vector_size =
sizeof (
u32),
581 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 593 .name =
"gre6-input",
595 .vector_size =
sizeof (
u32),
604 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 641 clib_host_to_net_u16 (protocol));
683 ASSERT(mpls_unicast_input);
686 ethernet_input->
index);
695 mpls_unicast_input->
index);
uword * tunnel_by_key6
Hash mapping ipv6 src/dst addr pair to tunnel.
sll srl srl sll sra u16x4 i
format_function_t format_gre_header_with_length
static uword gre4_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
void ip6_register_protocol(u32 protocol, u32 node_index)
vnet_interface_main_t interface_main
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
A GRE payload protocol registration.
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
void ip4_register_protocol(u32 protocol, u32 node_index)
vlib_error_t * errors
Vector of errors for this node.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
static pg_node_t * pg_get_node(uword node_index)
vlib_node_registration_t gre6_input_node
(constructor) VLIB_REGISTER_NODE (gre6_input_node)
static void gre_setup_node(vlib_main_t *vm, u32 node_index)
#define foreach_gre_input_next
static char * gre_error_strings[]
#define VLIB_INIT_FUNCTION(x)
vlib_combined_counter_main_t * combined_sw_if_counters
#define sparse_vec_validate(v, i)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static uword gre_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, u8 is_ipv6)
static void sparse_vec_index2(void *v, u32 si0, u32 si1, u32 *i0_return, u32 *i1_return)
unformat_function_t unformat_gre_header
#define vlib_call_init_function(vm, x)
u8 * format_gre_rx_trace(u8 *s, va_list *args)
uword * tunnel_by_key4
Hash mapping ipv4 src/dst addr pair to tunnel.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
A representation of a GRE tunnel.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
u32 node_index
Node which handles this type.
format_function_t * format_buffer
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static clib_error_t * gre_input_init(vlib_main_t *vm)
static clib_error_t * gre_init(vlib_main_t *vm)
static_always_inline uword vlib_get_thread_index(void)
#define CLIB_PREFETCH(addr, size, type)
#define VLIB_BUFFER_IS_TRACED
unformat_function_t * unformat_buffer
unformat_function_t * unformat_edit
vlib_node_registration_t gre4_input_node
(constructor) VLIB_REGISTER_NODE (gre4_input_node)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static uword sparse_vec_index(void *v, uword sparse_index)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
u32 next_index
Next index for this type.
gre_tunnel_t * tunnels
pool of tunnel instances
#define clib_error_report(e)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
void gre_register_input_protocol(vlib_main_t *vm, gre_protocol_t protocol, u32 node_index)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
unformat_function_t unformat_pg_gre_header
static uword ethernet_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define hash_get_mem(h, key)
#define VLIB_REGISTER_NODE(x,...)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
static uword gre6_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
static gre_protocol_info_t * gre_get_protocol_info(gre_main_t *em, gre_protocol_t protocol)
static void * sparse_vec_new(uword elt_bytes, uword sparse_index_bits)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
VLIB_NODE_FUNCTION_MULTIARCH(ethernet_input_not_l2_node, ethernet_input_not_l2)
#define SPARSE_VEC_INVALID_INDEX