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;
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];
248 type[0], TUNNEL_MODE_P2P, 0, &key[0].
gtk_v6);
252 type[1], TUNNEL_MODE_P2P, 0, &key[1].
gtk_v6);
261 type[0], TUNNEL_MODE_P2P, 0, &key[0].
gtk_v4);
265 type[1], TUNNEL_MODE_P2P, 0, &key[1].
gtk_v4);
270 tun_sw_if_index[0] = cached_tun_sw_if_index;
271 tun_sw_if_index[1] = cached_tun_sw_if_index;
274 &tun_sw_if_index[0], &cached_tun_sw_if_index,
278 &tun_sw_if_index[1], &cached_tun_sw_if_index,
284 interface_main.combined_sw_if_counters
295 interface_main.combined_sw_if_counters
305 gre_trace (vm, node, b[0], tun_sw_if_index[0], ip6[0], ip4[0],
308 gre_trace (vm, node, b[1], tun_sw_if_index[1], ip6[1], ip4[1],
316 while (n_left_from >= 1)
328 u32 tun_sw_if_index[1];
340 gre[0] = (
void *) (ip6[0] + 1);
347 gre[0] = (
void *) (ip4[0] + 1);
353 nidx[0] = cached_next_index;
357 cached_next_index = nidx[0] =
367 ? node->
errors[GRE_ERROR_UNKNOWN_PROTOCOL]
368 : node->
errors[GRE_ERROR_NONE];
370 version[0] = clib_net_to_host_u16 (gre[0]->flags_and_version);
373 b[0]->
error = version[0]
374 ? node->
errors[GRE_ERROR_UNSUPPORTED_VERSION] : b[0]->
error;
375 next[0] = version[0] ? GRE_INPUT_NEXT_DROP : next[0];
384 type[0], TUNNEL_MODE_P2P, 0, &key[0].
gtk_v6);
392 type[0], TUNNEL_MODE_P2P, 0, &key[0].
gtk_v4);
396 tun_sw_if_index[0] = cached_tun_sw_if_index;
399 &tun_sw_if_index[0], &cached_tun_sw_if_index,
405 interface_main.combined_sw_if_counters
415 gre_trace (vm, node, b[0], tun_sw_if_index[0], ip6[0], ip4[0],
448 #define gre_error(n,s) s, 455 .name =
"gre4-input",
457 .vector_size =
sizeof (
u32),
464 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 475 .name =
"gre6-input",
477 .vector_size =
sizeof (
u32),
486 #define _(s,n) [GRE_INPUT_NEXT_##s] = n, 497 #ifndef CLIB_MARCH_VARIANT 523 clib_host_to_net_u16 (protocol));
543 vlib_node_t *ethernet_input, *ip4_input, *ip6_input, *mpls_unicast_input;
567 ASSERT (mpls_unicast_input);
570 ethernet_input->
index, GRE_TUNNEL_TYPE_TEB);
573 ip4_input->
index, GRE_TUNNEL_TYPE_L3);
576 ip6_input->
index, GRE_TUNNEL_TYPE_L3);
579 mpls_unicast_input->
index, GRE_TUNNEL_TYPE_L3);
static void gre_mk_key6(const ip6_address_t *src, const ip6_address_t *dst, u32 fib_index, gre_tunnel_type_t ttype, tunnel_mode_t tmode, u16 session_id, gre_tunnel_key6_t *key)
uword * tunnel_by_key6
Hash mapping to tunnels with ipv6 src/dst addr.
format_function_t format_gre_header_with_length
static void gre_setup_node(vlib_main_t *vm, u32 node_index)
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.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
A GRE payload protocol registration.
#define VLIB_NODE_FN(node)
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 uword gre_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, const int is_ipv6)
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)
static pg_node_t * pg_get_node(uword node_index)
static void gre_mk_key4(ip4_address_t src, ip4_address_t dst, u32 fib_index, gre_tunnel_type_t ttype, tunnel_mode_t tmode, u16 session_id, gre_tunnel_key4_t *key)
static clib_error_t * gre_input_init(vlib_main_t *vm)
vl_api_ip_proto_t protocol
vlib_node_registration_t gre4_input_node
(constructor) VLIB_REGISTER_NODE (gre4_input_node)
#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)
vl_api_fib_path_type_t type
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.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
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.
#define foreach_gre_input_next
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)
format_function_t format_ip46_address
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)
sll srl srl sll sra u16x4 i
unformat_function_t * unformat_buffer
unformat_function_t * unformat_edit
u8 * format_gre_rx_trace(u8 *s, va_list *args)
#define vlib_prefetch_buffer_data(b, type)
vlib_main_t vlib_node_runtime_t * node
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 * 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_node_registration_t gre6_input_node
(constructor) VLIB_REGISTER_NODE (gre6_input_node)
VLIB buffer representation.
static char * gre_error_strings[]
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)
enum gre_tunnel_type_t_ gre_tunnel_type_t
The GRE tunnel type.
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by 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)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
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)
#define SPARSE_VEC_INVALID_INDEX