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") 34 #define _(s,n) GRE_INPUT_NEXT_##s, 50 #ifndef CLIB_MARCH_VARIANT 58 s =
format (s,
"GRE: tunnel %d len %d src %U dst %U",
92 tr->
src.as_u64[0] = tr->
src.as_u64[1] = 0;
93 tr->
dst.as_u64[0] = tr->
dst.as_u64[1] = 0;
103 u32 * cached_tun_sw_if_index,
int is_ipv6)
110 *next = GRE_INPUT_NEXT_DROP;
112 *tun_sw_if_index = ~0;
118 *cached_tun_sw_if_index = *tun_sw_if_index = tun->
sw_if_index;
132 u32 *from, n_left_from;
135 u16 cached_protocol = ~0;
137 u32 cached_tun_sw_if_index = ~0;
149 while (n_left_from >= 2)
161 u32 tun_sw_if_index[2];
176 gre[0] = (
void *) (ip6[0] + 1);
177 gre[1] = (
void *) (ip6[1] + 1);
186 gre[0] = (
void *) (ip4[0] + 1);
187 gre[1] = (
void *) (ip4[1] + 1);
194 nidx[0] = cached_next_index;
198 cached_next_index = nidx[0] =
204 nidx[1] = cached_next_index;
208 cached_next_index = nidx[1] =
221 ? node->
errors[GRE_ERROR_UNKNOWN_PROTOCOL]
222 : node->
errors[GRE_ERROR_NONE];
224 ? node->
errors[GRE_ERROR_UNKNOWN_PROTOCOL]
225 : node->
errors[GRE_ERROR_NONE];
227 version[0] = clib_net_to_host_u16 (gre[0]->flags_and_version);
228 version[1] = clib_net_to_host_u16 (gre[1]->flags_and_version);
232 b[0]->
error = version[0]
233 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION] : b[0]->
error;
234 next[0] = version[0] ? GRE_INPUT_NEXT_DROP : next[0];
235 b[1]->
error = version[1]
236 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION] : b[1]->
error;
237 next[1] = version[1] ? GRE_INPUT_NEXT_DROP : next[1];
247 type[0], 0, &key[0].
gtk_v6);
251 type[1], 0, &key[1].
gtk_v6);
260 type[0], 0, &key[0].
gtk_v4);
264 type[1], 0, &key[1].
gtk_v4);
269 tun_sw_if_index[0] = cached_tun_sw_if_index;
270 tun_sw_if_index[1] = cached_tun_sw_if_index;
273 &tun_sw_if_index[0], &cached_tun_sw_if_index,
277 &tun_sw_if_index[1], &cached_tun_sw_if_index,
283 interface_main.combined_sw_if_counters
294 interface_main.combined_sw_if_counters
304 gre_trace (vm, node, b[0], tun_sw_if_index[0], ip6[0], ip4[0],
307 gre_trace (vm, node, b[1], tun_sw_if_index[1], ip6[1], ip4[1],
315 while (n_left_from >= 1)
327 u32 tun_sw_if_index[1];
339 gre[0] = (
void *) (ip6[0] + 1);
346 gre[0] = (
void *) (ip4[0] + 1);
352 nidx[0] = cached_next_index;
356 cached_next_index = nidx[0] =
366 ? node->
errors[GRE_ERROR_UNKNOWN_PROTOCOL]
367 : node->
errors[GRE_ERROR_NONE];
369 version[0] = clib_net_to_host_u16 (gre[0]->flags_and_version);
372 b[0]->
error = version[0]
373 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION] : b[0]->
error;
374 next[0] = version[0] ? GRE_INPUT_NEXT_DROP : next[0];
383 type[0], 0, &key[0].
gtk_v6);
391 type[0], 0, &key[0].
gtk_v4);
395 tun_sw_if_index[0] = cached_tun_sw_if_index;
398 &tun_sw_if_index[0], &cached_tun_sw_if_index,
404 interface_main.combined_sw_if_counters
414 gre_trace (vm, node, b[0], tun_sw_if_index[0], ip6[0], ip4[0],
436 return gre_input (vm, node, from_frame, 0);
443 return gre_input (vm, node, from_frame, 1);
447 #define gre_error(n,s) s, 454 .name =
"gre4-input",
456 .vector_size =
sizeof (
u32),
463 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 474 .name =
"gre6-input",
476 .vector_size =
sizeof (
u32),
485 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 496 #ifndef CLIB_MARCH_VARIANT 522 clib_host_to_net_u16 (protocol));
542 vlib_node_t *ethernet_input, *ip4_input, *ip6_input, *mpls_unicast_input;
566 ASSERT (mpls_unicast_input);
uword * tunnel_by_key6
Hash mapping to tunnels with ipv6 src/dst addr.
format_function_t format_gre_header_with_length
Transparent Ethernet Bridging - the tunnel is in L2 mode.
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)
static void gre_tunnel_get(const gre_main_t *gm, vlib_node_runtime_t *node, vlib_buffer_t *b, u16 *next, const gre_tunnel_key_t *key, gre_tunnel_key_t *cached_key, u32 *tun_sw_if_index, u32 *cached_tun_sw_if_index, int is_ipv6)
A GRE payload protocol registration.
static uword gre_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, const int is_ipv6)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define VLIB_NODE_FN(node)
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)
enum gre_tunnel_type_t_ gre_tunnel_type_t
The GRE tunnel type.
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)
#define sparse_vec_validate(v, i)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
gre_tunnel_type_t tunnel_type
GRE tunnel type.
unformat_function_t unformat_gre_header
#define vlib_call_init_function(vm, x)
u8 * format_gre_rx_trace(u8 *s, va_list *args)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
uword * tunnel_by_key4
Hash mapping to tunnels with ipv4 src/dst addr.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
A representation of a GRE tunnel.
static int gre_match_key4(const gre_tunnel_key4_t *key1, const gre_tunnel_key4_t *key2)
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.
vl_api_address_union_t src_address
format_function_t * format_buffer
static int gre_match_key6(const gre_tunnel_key6_t *key1, const gre_tunnel_key6_t *key2)
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)
#define VLIB_REGISTER_NODE(x,...)
void gre_register_input_protocol(vlib_main_t *vm, gre_protocol_t protocol, u32 node_index, gre_tunnel_type_t tunnel_type)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
unformat_function_t * unformat_buffer
static void gre_mk_key4(ip4_address_t src, ip4_address_t dst, u32 fib_index, u8 ttype, u16 session_id, gre_tunnel_key4_t *key)
unformat_function_t * unformat_edit
#define vlib_prefetch_buffer_data(b, type)
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)
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.
next_info_t * next_by_protocol
Union of the two possible key types.
static void gre_mk_key6(const ip6_address_t *src, const ip6_address_t *dst, u32 fib_index, u8 ttype, u16 session_id, gre_tunnel_key6_t *key)
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.
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
unformat_function_t unformat_pg_gre_header
vl_api_gbp_endpoint_tun_t tun
#define hash_get_mem(h, key)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
static gre_protocol_info_t * gre_get_protocol_info(gre_main_t *em, gre_protocol_t protocol)
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
static void * sparse_vec_new(uword elt_bytes, uword sparse_index_bits)
static void gre_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, u32 tun_sw_if_index, const ip6_header_t *ip6, const ip4_header_t *ip4, int is_ipv6)
#define SPARSE_VEC_INVALID_INDEX