24 #ifndef CLIB_MARCH_VARIANT 63 #ifndef CLIB_MARCH_VARIANT 71 s =
format (s,
"GRE: tunnel %d len %d src %U dst %U",
88 s =
format (s,
"0x%04x", p);
98 u32 max_header_bytes = va_arg (*args,
u32);
100 u32 indent, header_bytes;
102 header_bytes =
sizeof (h[0]);
103 if (max_header_bytes != 0 && header_bytes > max_header_bytes)
104 return format (s,
"gre header truncated");
110 if (max_header_bytes != 0 && header_bytes < max_header_bytes)
118 max_header_bytes - header_bytes);
136 u16 *result = va_arg (*args,
u16 *);
156 u16 *result = va_arg (*args,
u16 *);
159 *result = clib_host_to_net_u16 ((
u16) * result);
166 u8 **result = va_arg (*args,
u8 **);
173 h->
protocol = clib_host_to_net_u16 (p);
178 u32 n_bytes =
sizeof (h[0]);
193 return (GRE_PROTOCOL_ip4);
195 return (GRE_PROTOCOL_ip6);
197 return (GRE_PROTOCOL_mpls_unicast);
199 return (GRE_PROTOCOL_teb);
201 return (GRE_PROTOCOL_arp);
207 return (GRE_PROTOCOL_ip4);
216 ip4_and_gre_header_t *h4;
217 ip6_and_gre_header_t *h6;
237 h4 = (ip4_and_gre_header_t *) rewrite;
239 h4->ip4.ip_version_and_header_length = 0x45;
243 h4->ip4.src_address.as_u32 = t->
tunnel_src.ip4.as_u32;
250 h6 = (ip6_and_gre_header_t *) rewrite;
252 h6->ip6.ip_version_traffic_class_and_flow_label =
253 clib_host_to_net_u32 (6 << 28);
254 h6->ip6.hop_limit = 255;
255 h6->ip6.protocol = IP_PROTOCOL_GRE;
257 h6->ip6.src_address.as_u64[0] = t->
tunnel_src.ip6.as_u64[0];
258 h6->ip6.src_address.as_u64[1] = t->
tunnel_src.ip6.as_u64[1];
265 gre->
protocol = clib_host_to_net_u16 (GRE_PROTOCOL_erspan);
275 #define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40 345 u32 *from, n_left_from;
352 n_left_from = frame->n_vectors;
355 while (n_left_from >= 2)
368 (sw_if_index[1] !=
vnet_buffer (b[1])->sw_if_index[VLIB_TX]))
390 h0->seq_num = clib_host_to_net_u32 (seq_num);
392 h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[0]->session_id);
404 h0->seq_num = clib_host_to_net_u32 (seq_num);
406 h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[1]->session_id);
432 while (n_left_from >= 1)
457 h0->seq_num = clib_host_to_net_u32 (seq_num);
459 h0->t2.cos_en_t_session |= clib_host_to_net_u16 (gt[0]->session_id);
481 GRE_ERROR_PKTS_ENCAP, frame->n_vectors);
483 return frame->n_vectors;
487 #define gre_error(n,s) s, 496 .vector_size =
sizeof (
u32),
508 #ifndef CLIB_MARCH_VARIANT 512 u32 dev_instance = va_arg (*args,
u32);
517 return format (s,
"<improperly-referenced>");
526 u32 dev_instance = va_arg (*args,
u32);
529 s =
format (s,
"GRE tunnel: id %d\n", dev_instance);
535 .name =
"GRE tunnel device",
565 pi->
name = protocol_name;
608 #define _(n,s) add_protocol (gm, GRE_PROTOCOL_##s, #s);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
fib_protocol_t fp_proto
protocol type
uword * seq_num_by_key
Hash mapping tunnel src/dst addr and fib-idx to sequence number.
VNET_HW_INTERFACE_CLASS(gre_hw_interface_class)
#define hash_set(h, key, value)
uword * tunnel_by_key6
Hash mapping to tunnels with ipv6 src/dst addr.
Key for a IPv6 GRE Tunnel We use a different type so that the V4 key hash is as small as possible...
uword * protocol_info_by_protocol
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * ip4_lookup_init(vlib_main_t *vm)
vnet_link_t adj_get_link_type(adj_index_t ai)
Return the link type of the adjacency.
gre_protocol_t protocol
GRE protocol type in host byte order.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
char * name
Name (a c string).
A GRE payload protocol registration.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define hash_set_mem(h, key, value)
#define VLIB_NODE_FN(node)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
u32 * tunnel_index_by_sw_if_index
Mapping from sw_if_index to tunnel index.
VNET_DEVICE_CLASS(gre_device_class)
#define clib_memcpy(d, s, n)
Hash key for GRE header seq number generation for ERSPAN encap.
unformat_function_t * unformat_pg_edit
ip4_and_gre_header_t ip4_and_gre
#define VLIB_INIT_FUNCTION(x)
static void gre4_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0, const void *data)
IPv4 and GRE header union.
void gre_tunnel_stack(adj_index_t ai)
gre_tunnel_stack
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static_always_inline void vlib_buffer_enqueue_to_single_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 next_index, u32 count)
ip6_and_gre_header_t ip6_and_gre
adj_index_t l2_adj_index
an L2 tunnel always rquires an L2 midchain.
#define vlib_call_init_function(vm, x)
ip46_address_t tunnel_src
The tunnel's source/local address.
uword unformat_gre_header(unformat_input_t *input, va_list *args)
#define hash_create_string(elts, value_bytes)
#define hash_create_mem(elts, key_bytes, value_bytes)
uword * tunnel_by_key4
Hash mapping to tunnels with ipv4 src/dst addr.
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
A representation of a GRE tunnel.
vlib_node_registration_t gre_encap_node
(constructor) VLIB_REGISTER_NODE (gre_encap_node)
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
format_function_t * format_header
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.
void gre_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
u8 * format_gre_tx_trace(u8 *s, va_list *args)
format_function_t * format_buffer
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
uword * protocol_info_by_name
Hash tables mapping name/protocol to protocol info index.
static u8 * format_gre_tunnel_name(u8 *s, va_list *args)
static clib_error_t * gre_input_init(vlib_main_t *vm)
static clib_error_t * gre_init(vlib_main_t *vm)
Key for a IPv4 GRE Tunnel.
#define VLIB_REGISTER_NODE(x,...)
clib_error_t * ip_main_init(vlib_main_t *vm)
static u8 * format_gre_device(u8 *s, va_list *args)
void adj_nbr_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, const void *fixup_data, adj_flags_t flags, u8 *rewrite)
adj_nbr_midchain_update_rewrite
u32 adj_index_t
An index for adjacencies.
u8 * format_gre_header_with_length(u8 *s, va_list *args)
#define hash_create(elts, value_bytes)
static u8 * gre_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
u32 next_index
Next index for this type.
static void gre6_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0, const void *data)
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
static int gre_proto_from_vnet_link(vnet_link_t link)
gre_tunnel_t * tunnels
pool of tunnel instances
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
vnet_hw_interface_class_t gre_hw_interface_class
#define clib_atomic_fetch_add(a, b)
enum adj_flags_t_ adj_flags_t
Flags on an IP adjacency.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vnet_device_class_t gre_device_class
clib_error_t * gre_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
ERSPAN type 2 - the tunnel is for port mirror SPAN output.
static void add_protocol(gre_main_t *gm, gre_protocol_t protocol, char *protocol_name)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
uword unformat_gre_protocol_host_byte_order(unformat_input_t *input, va_list *args)
#define GRE_FLAGS_SEQUENCE
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
a point 2 point interface
u8 * format_gre_header(u8 *s, va_list *args)
unformat_function_t unformat_pg_gre_header
u8 * format_gre_protocol(u8 *s, va_list *args)
fib_prefix_t tunnel_dst
The tunnel's destination/remote address.
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)
gre_protocol_info_t * protocol_infos
GRE payload protocol registrations.
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 clib_error_t * ip6_lookup_init(vlib_main_t *vm)
uword unformat_gre_protocol_net_byte_order(unformat_input_t *input, va_list *args)
static char * gre_error_strings[]
static u16 ip4_header_checksum(ip4_header_t *i)