summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/gre/gre.c290
-rw-r--r--src/vnet/gre/gre.h65
-rw-r--r--src/vnet/gre/interface.c566
-rw-r--r--src/vnet/gre/node.c880
-rw-r--r--src/vnet/gre/packet.h14
-rw-r--r--src/vnet/gre/pg.c31
6 files changed, 968 insertions, 878 deletions
diff --git a/src/vnet/gre/gre.c b/src/vnet/gre/gre.c
index 99421855bed..785476d0905 100644
--- a/src/vnet/gre/gre.c
+++ b/src/vnet/gre/gre.c
@@ -21,15 +21,19 @@
gre_main_t gre_main;
-typedef struct {
- union {
+typedef struct
+{
+ union
+ {
ip4_and_gre_header_t ip4_and_gre;
u64 as_u64[3];
};
} ip4_and_gre_union_t;
-typedef struct {
- union {
+typedef struct
+{
+ union
+ {
ip6_and_gre_header_t ip6_and_gre;
u64 as_u64[3];
};
@@ -37,7 +41,8 @@ typedef struct {
/* Packet trace structure */
-typedef struct {
+typedef struct
+{
/* Tunnel-id / index in tunnel vector */
u32 tunnel_id;
@@ -49,11 +54,12 @@ typedef struct {
ip46_address_t dst;
} gre_tx_trace_t;
-u8 * format_gre_tx_trace (u8 * s, va_list * args)
+u8 *
+format_gre_tx_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- gre_tx_trace_t * t = va_arg (*args, gre_tx_trace_t *);
+ gre_tx_trace_t *t = va_arg (*args, gre_tx_trace_t *);
s = format (s, "GRE: tunnel %d len %d src %U dst %U",
t->tunnel_id, clib_net_to_host_u16 (t->length),
@@ -62,11 +68,12 @@ u8 * format_gre_tx_trace (u8 * s, va_list * args)
return s;
}
-u8 * format_gre_protocol (u8 * s, va_list * args)
+u8 *
+format_gre_protocol (u8 * s, va_list * args)
{
gre_protocol_t p = va_arg (*args, u32);
- gre_main_t * gm = &gre_main;
- gre_protocol_info_t * pi = gre_get_protocol_info (gm, p);
+ gre_main_t *gm = &gre_main;
+ gre_protocol_info_t *pi = gre_get_protocol_info (gm, p);
if (pi)
s = format (s, "%s", pi->name);
@@ -76,10 +83,11 @@ u8 * format_gre_protocol (u8 * s, va_list * args)
return s;
}
-u8 * format_gre_header_with_length (u8 * s, va_list * args)
+u8 *
+format_gre_header_with_length (u8 * s, va_list * args)
{
- gre_main_t * gm = &gre_main;
- gre_header_t * h = va_arg (*args, gre_header_t *);
+ gre_main_t *gm = &gre_main;
+ gre_header_t *h = va_arg (*args, gre_header_t *);
u32 max_header_bytes = va_arg (*args, u32);
gre_protocol_t p = clib_net_to_host_u16 (h->protocol);
u32 indent, header_bytes;
@@ -94,8 +102,8 @@ u8 * format_gre_header_with_length (u8 * s, va_list * args)
if (max_header_bytes != 0 && header_bytes > max_header_bytes)
{
- gre_protocol_info_t * pi = gre_get_protocol_info (gm, p);
- vlib_node_t * node = vlib_get_node (gm->vlib_main, pi->node_index);
+ gre_protocol_info_t *pi = gre_get_protocol_info (gm, p);
+ vlib_node_t *node = vlib_get_node (gm->vlib_main, pi->node_index);
if (node->format_buffer)
s = format (s, "\n%U%U",
format_white_space, indent,
@@ -106,9 +114,10 @@ u8 * format_gre_header_with_length (u8 * s, va_list * args)
return s;
}
-u8 * format_gre_header (u8 * s, va_list * args)
+u8 *
+format_gre_header (u8 * s, va_list * args)
{
- gre_header_t * h = va_arg (*args, gre_header_t *);
+ gre_header_t *h = va_arg (*args, gre_header_t *);
return format (s, "%U", format_gre_header_with_length, h, 0);
}
@@ -117,15 +126,15 @@ uword
unformat_gre_protocol_host_byte_order (unformat_input_t * input,
va_list * args)
{
- u16 * result = va_arg (*args, u16 *);
- gre_main_t * gm = &gre_main;
+ u16 *result = va_arg (*args, u16 *);
+ gre_main_t *gm = &gre_main;
int i;
/* Named type. */
if (unformat_user (input, unformat_vlib_number_by_name,
gm->protocol_info_by_name, &i))
{
- gre_protocol_info_t * pi = vec_elt_at_index (gm->protocol_infos, i);
+ gre_protocol_info_t *pi = vec_elt_at_index (gm->protocol_infos, i);
*result = pi->protocol;
return 1;
}
@@ -137,29 +146,28 @@ uword
unformat_gre_protocol_net_byte_order (unformat_input_t * input,
va_list * args)
{
- u16 * result = va_arg (*args, u16 *);
- if (! unformat_user (input, unformat_gre_protocol_host_byte_order, result))
+ u16 *result = va_arg (*args, u16 *);
+ if (!unformat_user (input, unformat_gre_protocol_host_byte_order, result))
return 0;
- *result = clib_host_to_net_u16 ((u16) *result);
+ *result = clib_host_to_net_u16 ((u16) * result);
return 1;
}
uword
unformat_gre_header (unformat_input_t * input, va_list * args)
{
- u8 ** result = va_arg (*args, u8 **);
- gre_header_t _h, * h = &_h;
+ u8 **result = va_arg (*args, u8 **);
+ gre_header_t _h, *h = &_h;
u16 p;
- if (! unformat (input, "%U",
- unformat_gre_protocol_host_byte_order, &p))
+ if (!unformat (input, "%U", unformat_gre_protocol_host_byte_order, &p))
return 0;
h->protocol = clib_host_to_net_u16 (p);
/* Add header to result. */
{
- void * p;
+ void *p;
u32 n_bytes = sizeof (h[0]);
vec_add2 (*result, p, n_bytes);
@@ -172,36 +180,35 @@ unformat_gre_header (unformat_input_t * input, va_list * args)
static int
gre_proto_from_vnet_link (vnet_link_t link)
{
- switch (link)
+ switch (link)
{
case VNET_LINK_IP4:
- return (GRE_PROTOCOL_ip4);
+ return (GRE_PROTOCOL_ip4);
case VNET_LINK_IP6:
- return (GRE_PROTOCOL_ip6);
+ return (GRE_PROTOCOL_ip6);
case VNET_LINK_MPLS:
- return (GRE_PROTOCOL_mpls_unicast);
+ return (GRE_PROTOCOL_mpls_unicast);
case VNET_LINK_ETHERNET:
- return (GRE_PROTOCOL_teb);
+ return (GRE_PROTOCOL_teb);
case VNET_LINK_ARP:
- return (GRE_PROTOCOL_arp);
+ return (GRE_PROTOCOL_arp);
case VNET_LINK_NSH:
- ASSERT(0);
- break;
+ ASSERT (0);
+ break;
}
- ASSERT(0);
- return (GRE_PROTOCOL_ip4);
+ ASSERT (0);
+ return (GRE_PROTOCOL_ip4);
}
-static u8*
+static u8 *
gre_build_rewrite (vnet_main_t * vnm,
u32 sw_if_index,
- vnet_link_t link_type,
- const void *dst_address)
+ vnet_link_t link_type, const void *dst_address)
{
- gre_main_t * gm = &gre_main;
- ip4_and_gre_header_t * h4;
- ip6_and_gre_header_t * h6;
- u8* rewrite = NULL;
+ gre_main_t *gm = &gre_main;
+ ip4_and_gre_header_t *h4;
+ ip6_and_gre_header_t *h6;
+ u8 *rewrite = NULL;
gre_tunnel_t *t;
u32 ti;
u8 is_ipv6;
@@ -209,18 +216,19 @@ gre_build_rewrite (vnet_main_t * vnm,
ti = gm->tunnel_index_by_sw_if_index[sw_if_index];
if (~0 == ti)
- /* not one of ours */
- return (0);
+ /* not one of ours */
+ return (0);
- t = pool_elt_at_index(gm->tunnels, ti);
+ t = pool_elt_at_index (gm->tunnels, ti);
is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
if (!is_ipv6)
{
- vec_validate(rewrite, sizeof(*h4)-1);
- h4 = (ip4_and_gre_header_t*)rewrite;
- h4->gre.protocol = clib_host_to_net_u16(gre_proto_from_vnet_link(link_type));
+ vec_validate (rewrite, sizeof (*h4) - 1);
+ h4 = (ip4_and_gre_header_t *) rewrite;
+ h4->gre.protocol =
+ clib_host_to_net_u16 (gre_proto_from_vnet_link (link_type));
h4->ip4.ip_version_and_header_length = 0x45;
h4->ip4.ttl = 254;
@@ -232,11 +240,13 @@ gre_build_rewrite (vnet_main_t * vnm,
}
else
{
- vec_validate(rewrite, sizeof(*h6)-1);
- h6 = (ip6_and_gre_header_t*)rewrite;
- h6->gre.protocol = clib_host_to_net_u16(gre_proto_from_vnet_link(link_type));
+ vec_validate (rewrite, sizeof (*h6) - 1);
+ h6 = (ip6_and_gre_header_t *) rewrite;
+ h6->gre.protocol =
+ clib_host_to_net_u16 (gre_proto_from_vnet_link (link_type));
- h6->ip6.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
+ h6->ip6.ip_version_traffic_class_and_flow_label =
+ clib_host_to_net_u32 (6 << 28);
h6->ip6.hop_limit = 255;
h6->ip6.protocol = IP_PROTOCOL_GRE;
/* fixup ip6 header length and checksum after-the-fact */
@@ -252,59 +262,55 @@ gre_build_rewrite (vnet_main_t * vnm,
#define is_v4_packet(_h) ((*(u8*) _h) & 0xF0) == 0x40
void
-gre4_fixup (vlib_main_t *vm,
- ip_adjacency_t *adj,
- vlib_buffer_t *b0)
+gre4_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
{
- ip4_header_t * ip0;
+ ip4_header_t *ip0;
- ip0 = vlib_buffer_get_current (b0);
+ ip0 = vlib_buffer_get_current (b0);
- /* Fixup the checksum and len fields in the GRE tunnel encap
- * that was applied at the midchain node */
- ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
- ip0->checksum = ip4_header_checksum (ip0);
+ /* Fixup the checksum and len fields in the GRE tunnel encap
+ * that was applied at the midchain node */
+ ip0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0));
+ ip0->checksum = ip4_header_checksum (ip0);
}
void
-gre6_fixup (vlib_main_t *vm,
- ip_adjacency_t *adj,
- vlib_buffer_t *b0)
+gre6_fixup (vlib_main_t * vm, ip_adjacency_t * adj, vlib_buffer_t * b0)
{
- ip6_header_t * ip0;
+ ip6_header_t *ip0;
- ip0 = vlib_buffer_get_current (b0);
+ ip0 = vlib_buffer_get_current (b0);
- /* 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);
+ /* 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);
}
void
-gre_update_adj (vnet_main_t * vnm,
- u32 sw_if_index,
- adj_index_t ai)
+gre_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
{
- gre_main_t * gm = &gre_main;
- gre_tunnel_t *t;
- u32 ti;
- u8 is_ipv6;
-
- 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;
-
- adj_nbr_midchain_update_rewrite (ai, !is_ipv6 ? gre4_fixup : gre6_fixup,
- (VNET_LINK_ETHERNET == adj_get_link_type (ai) ?
- ADJ_FLAG_MIDCHAIN_NO_COUNT :
- ADJ_FLAG_NONE),
- gre_build_rewrite(vnm, sw_if_index,
- adj_get_link_type(ai),
- NULL));
-
- gre_tunnel_stack(ai);
+ gre_main_t *gm = &gre_main;
+ gre_tunnel_t *t;
+ u32 ti;
+ u8 is_ipv6;
+
+ 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;
+
+ adj_nbr_midchain_update_rewrite (ai, !is_ipv6 ? gre4_fixup : gre6_fixup,
+ (VNET_LINK_ETHERNET ==
+ adj_get_link_type (ai) ?
+ ADJ_FLAG_MIDCHAIN_NO_COUNT :
+ ADJ_FLAG_NONE), gre_build_rewrite (vnm,
+ sw_if_index,
+ adj_get_link_type
+ (ai),
+ NULL));
+
+ gre_tunnel_stack (ai);
}
/**
@@ -312,13 +318,12 @@ gre_update_adj (vnet_main_t * vnm,
*/
static uword
gre_interface_tx_inline (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- gre_main_t * gm = &gre_main;
+ gre_main_t *gm = &gre_main;
u32 next_index;
- u32 * from, * to_next, n_left_from, n_left_to_next;
- vnet_interface_output_runtime_t * rd = (void *) node->runtime_data;
+ u32 *from, *to_next, n_left_from, n_left_to_next;
+ vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
const gre_tunnel_t *gt = pool_elt_at_index (gm->tunnels, rd->dev_instance);
u8 is_ipv6 = gt->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
@@ -342,7 +347,7 @@ gre_interface_tx_inline (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- vlib_buffer_t * b0;
+ vlib_buffer_t *b0;
u32 bi0;
bi0 = from[0];
@@ -352,18 +357,18 @@ gre_interface_tx_inline (vlib_main_t * vm,
n_left_from -= 1;
n_left_to_next -= 1;
- b0 = vlib_get_buffer(vm, bi0);
+ b0 = vlib_get_buffer (vm, bi0);
- vnet_buffer(b0)->ip.adj_index[VLIB_TX] = gt->l2_adj_index;
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX] = gt->l2_adj_index;
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
{
gre_tx_trace_t *tr = vlib_add_trace (vm, node,
b0, sizeof (*tr));
- tr->tunnel_id = gt - gm->tunnels;
- tr->src = gt->tunnel_src;
- tr->dst = gt->tunnel_src;
- tr->length = vlib_buffer_length_in_chain (vm, b0);
+ tr->tunnel_id = gt - gm->tunnels;
+ tr->src = gt->tunnel_src;
+ tr->dst = gt->tunnel_src;
+ tr->length = vlib_buffer_length_in_chain (vm, b0);
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
@@ -375,7 +380,7 @@ gre_interface_tx_inline (vlib_main_t * vm,
}
vlib_node_increment_counter (vm, !is_ipv6 ? gre4_input_node.index :
- gre6_input_node.index,
+ gre6_input_node.index,
GRE_ERROR_PKTS_ENCAP, frame->n_vectors);
return frame->n_vectors;
@@ -383,33 +388,34 @@ gre_interface_tx_inline (vlib_main_t * vm,
static uword
gre_interface_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (gre_interface_tx_inline (vm, node, frame));
+ return (gre_interface_tx_inline (vm, node, frame));
}
static uword
gre_teb_interface_tx (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
{
- return (gre_interface_tx_inline (vm, node, frame));
+ return (gre_interface_tx_inline (vm, node, frame));
}
-static u8 * format_gre_tunnel_name (u8 * s, va_list * args)
+static u8 *
+format_gre_tunnel_name (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
return format (s, "gre%d", dev_instance);
}
-static u8 * format_gre_tunnel_teb_name (u8 * s, va_list * args)
+static u8 *
+format_gre_tunnel_teb_name (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
return format (s, "teb-gre%d", dev_instance);
}
-static u8 * format_gre_device (u8 * s, va_list * args)
+static u8 *
+format_gre_device (u8 * s, va_list * args)
{
u32 dev_instance = va_arg (*args, u32);
CLIB_UNUSED (int verbose) = va_arg (*args, int);
@@ -418,6 +424,7 @@ static u8 * format_gre_device (u8 * s, va_list * args)
return s;
}
+/* *INDENT-OFF* */
VNET_DEVICE_CLASS (gre_device_class) = {
.name = "GRE tunnel device",
.format_device_name = format_gre_tunnel_name,
@@ -429,9 +436,12 @@ VNET_DEVICE_CLASS (gre_device_class) = {
.clear counter = 0;
#endif
};
+/* *INDENT-ON* */
+
+/* *INDENT-OFF* */
VLIB_DEVICE_TX_FUNCTION_MULTIARCH (gre_device_class,
- gre_interface_tx)
+ gre_interface_tx)
VNET_DEVICE_CLASS (gre_device_teb_class) = {
.name = "GRE TEB tunnel device",
@@ -445,8 +455,11 @@ VNET_DEVICE_CLASS (gre_device_teb_class) = {
#endif
};
+/* *INDENT-ON* */
+
+/* *INDENT-OFF* */
VLIB_DEVICE_TX_FUNCTION_MULTIARCH (gre_device_teb_class,
- gre_teb_interface_tx)
+ gre_teb_interface_tx)
VNET_HW_INTERFACE_CLASS (gre_hw_interface_class) = {
.name = "GRE",
@@ -456,12 +469,12 @@ VNET_HW_INTERFACE_CLASS (gre_hw_interface_class) = {
.update_adjacency = gre_update_adj,
.flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
};
+/* *INDENT-ON* */
-static void add_protocol (gre_main_t * gm,
- gre_protocol_t protocol,
- char * protocol_name)
+static void
+add_protocol (gre_main_t * gm, gre_protocol_t protocol, char *protocol_name)
{
- gre_protocol_info_t * pi;
+ gre_protocol_info_t *pi;
u32 i;
vec_add2 (gm->protocol_infos, pi, 1);
@@ -475,16 +488,17 @@ static void add_protocol (gre_main_t * gm,
hash_set_mem (gm->protocol_info_by_name, pi->name, i);
}
-static clib_error_t * gre_init (vlib_main_t * vm)
+static clib_error_t *
+gre_init (vlib_main_t * vm)
{
- gre_main_t * gm = &gre_main;
- clib_error_t * error;
- ip_main_t * im = &ip_main;
- ip_protocol_info_t * pi;
+ gre_main_t *gm = &gre_main;
+ clib_error_t *error;
+ ip_main_t *im = &ip_main;
+ ip_protocol_info_t *pi;
memset (gm, 0, sizeof (gm[0]));
gm->vlib_main = vm;
- gm->vnet_main = vnet_get_main();
+ gm->vnet_main = vnet_get_main ();
if ((error = vlib_call_init_function (vm, ip_main_init)))
return error;
@@ -503,20 +517,28 @@ static clib_error_t * gre_init (vlib_main_t * vm)
gm->protocol_info_by_name = hash_create_string (0, sizeof (uword));
gm->protocol_info_by_protocol = hash_create (0, sizeof (uword));
gm->tunnel_by_key4 = hash_create (0, sizeof (uword));
- gm->tunnel_by_key6 = hash_create_mem (0, sizeof(u64[4]), sizeof (uword));
+ gm->tunnel_by_key6 = hash_create_mem (0, sizeof (u64[4]), sizeof (uword));
#define _(n,s) add_protocol (gm, GRE_PROTOCOL_##s, #s);
foreach_gre_protocol
#undef _
-
- return vlib_call_init_function (vm, gre_input_init);
+ return vlib_call_init_function (vm, gre_input_init);
}
VLIB_INIT_FUNCTION (gre_init);
-gre_main_t * gre_get_main (vlib_main_t * vm)
+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
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/gre/gre.h b/src/vnet/gre/gre.h
index 9c12eb4bc13..f597d42d428 100644
--- a/src/vnet/gre/gre.h
+++ b/src/vnet/gre/gre.h
@@ -27,7 +27,8 @@
extern vnet_hw_interface_class_t gre_hw_interface_class;
-typedef enum {
+typedef enum
+{
#define gre_error(n,s) GRE_ERROR_##n,
#include <vnet/gre/error.def>
#undef gre_error
@@ -37,9 +38,10 @@ typedef enum {
/**
* A GRE payload protocol registration
*/
-typedef struct {
+typedef struct
+{
/** Name (a c string). */
- char * name;
+ char *name;
/** GRE protocol type in host byte order. */
gre_protocol_t protocol;
@@ -76,7 +78,8 @@ typedef enum gre_tunnel_tyoe_t_
/**
* @brief A representation of a GRE tunnel
*/
-typedef struct {
+typedef struct
+{
/**
* Linkage into the FIB object graph
*/
@@ -125,7 +128,8 @@ typedef struct {
/**
* @brief GRE related global data
*/
-typedef struct {
+typedef struct
+{
/**
* pool of tunnel instances
*/
@@ -134,64 +138,68 @@ typedef struct {
/**
* GRE payload protocol registrations
*/
- gre_protocol_info_t * protocol_infos;
+ gre_protocol_info_t *protocol_infos;
/**
* Hash tables mapping name/protocol to protocol info index.
*/
- uword * protocol_info_by_name, * protocol_info_by_protocol;
+ uword *protocol_info_by_name, *protocol_info_by_protocol;
/**
* Hash mapping ipv4 src/dst addr pair to tunnel
*/
- uword * tunnel_by_key4;
+ uword *tunnel_by_key4;
/**
* Hash mapping ipv6 src/dst addr pair to tunnel
*/
- uword * tunnel_by_key6;
+ uword *tunnel_by_key6;
/**
* Free vlib hw_if_indices.
* A free list per-tunnel type since the interfaces ctreated are fo different
* types and we cannot change the type.
*/
- u32 * free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES];
+ u32 *free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES];
/**
* Mapping from sw_if_index to tunnel index
*/
- u32 * tunnel_index_by_sw_if_index;
+ u32 *tunnel_index_by_sw_if_index;
/* Sparse vector mapping gre protocol in network byte order
to next index. */
- u16 * next_by_protocol;
+ u16 *next_by_protocol;
/* convenience */
- vlib_main_t * vlib_main;
- vnet_main_t * vnet_main;
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
} gre_main_t;
/**
* @brief IPv4 and GRE header.
*/
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
ip4_header_t ip4;
gre_header_t gre;
}) ip4_and_gre_header_t;
+/* *INDENT-ON* */
/**
* @brief IPv6 and GRE header.
*/
+/* *INDENT-OFF* */
typedef CLIB_PACKED (struct {
ip6_header_t ip6;
gre_header_t gre;
}) ip6_and_gre_header_t;
+/* *INDENT-ON* */
always_inline gre_protocol_info_t *
gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol)
{
- uword * p = hash_get (em->protocol_info_by_protocol, protocol);
+ uword *p = hash_get (em->protocol_info_by_protocol, protocol);
return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
}
@@ -200,17 +208,14 @@ extern gre_main_t gre_main;
/* Register given node index to take input for given gre type. */
void
gre_register_input_type (vlib_main_t * vm,
- gre_protocol_t protocol,
- u32 node_index);
+ gre_protocol_t protocol, u32 node_index);
-extern clib_error_t * gre_interface_admin_up_down (vnet_main_t * vnm,
- u32 hw_if_index,
- u32 flags);
+extern clib_error_t *gre_interface_admin_up_down (vnet_main_t * vnm,
+ u32 hw_if_index, u32 flags);
extern void gre_tunnel_stack (adj_index_t ai);
extern void gre_update_adj (vnet_main_t * vnm,
- u32 sw_if_index,
- adj_index_t ai);
+ u32 sw_if_index, adj_index_t ai);
format_function_t format_gre_protocol;
format_function_t format_gre_header;
@@ -232,13 +237,13 @@ unformat_function_t unformat_pg_gre_header;
void
gre_register_input_protocol (vlib_main_t * vm,
- gre_protocol_t protocol,
- u32 node_index);
+ gre_protocol_t protocol, u32 node_index);
/* manually added to the interface output node in gre.c */
#define GRE_OUTPUT_NEXT_LOOKUP 1
-typedef struct {
+typedef struct
+{
u8 is_add;
ip46_address_t src, dst;
@@ -248,6 +253,14 @@ typedef struct {
} vnet_gre_add_del_tunnel_args_t;
int vnet_gre_add_del_tunnel
- (vnet_gre_add_del_tunnel_args_t *a, u32 * sw_if_indexp);
+ (vnet_gre_add_del_tunnel_args_t * a, u32 * sw_if_indexp);
#endif /* included_gre_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c
index ae5da93e0f0..c17d22e9ee0 100644
--- a/src/vnet/gre/interface.c
+++ b/src/vnet/gre/interface.c
@@ -28,12 +28,11 @@
static const char *gre_tunnel_type_names[] = GRE_TUNNEL_TYPE_NAMES;
static inline u64
-gre4_mk_key (const ip4_address_t *src,
- const ip4_address_t *dst,
- u32 out_fib_index)
+gre4_mk_key (const ip4_address_t * src,
+ const ip4_address_t * dst, u32 out_fib_index)
{
// FIXME. the fib index should be part of the key
- return ((u64)src->as_u32 << 32 | (u64)dst->as_u32);
+ return ((u64) src->as_u32 << 32 | (u64) dst->as_u32);
}
static u8 *
@@ -41,49 +40,45 @@ format_gre_tunnel_type (u8 * s, va_list * args)
{
gre_tunnel_type_t type = va_arg (*args, gre_tunnel_type_t);
- return (format(s, "%s", gre_tunnel_type_names[type]));
+ return (format (s, "%s", gre_tunnel_type_names[type]));
}
static u8 *
format_gre_tunnel (u8 * s, va_list * args)
{
- gre_tunnel_t * t = va_arg (*args, gre_tunnel_t *);
- gre_main_t * gm = &gre_main;
+ gre_tunnel_t *t = va_arg (*args, gre_tunnel_t *);
+ gre_main_t *gm = &gre_main;
u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
if (!is_ipv6)
- s = format (s,
- "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
- t - gm->tunnels,
- format_ip4_address, &t->tunnel_src.ip4,
- format_ip4_address, &t->tunnel_dst.fp_addr.ip4,
- format_gre_tunnel_type, t->type,
- t->outer_fib_index);
+ s = format (s,
+ "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
+ t - gm->tunnels,
+ format_ip4_address, &t->tunnel_src.ip4,
+ format_ip4_address, &t->tunnel_dst.fp_addr.ip4,
+ format_gre_tunnel_type, t->type, t->outer_fib_index);
else
- s = format (s,
- "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
- t - gm->tunnels,
- format_ip6_address, &t->tunnel_src.ip6,
- format_ip6_address, &t->tunnel_dst.fp_addr.ip6,
- format_gre_tunnel_type, t->type,
- t->outer_fib_index);
+ s = format (s,
+ "[%d] %U (src) %U (dst) payload %U outer_fib_index %d",
+ t - gm->tunnels,
+ format_ip6_address, &t->tunnel_src.ip6,
+ format_ip6_address, &t->tunnel_dst.fp_addr.ip6,
+ format_gre_tunnel_type, t->type, t->outer_fib_index);
return s;
}
static gre_tunnel_t *
-gre_tunnel_db_find (const ip46_address_t *src,
- const ip46_address_t *dst,
- u32 out_fib_index,
- u8 is_ipv6)
+gre_tunnel_db_find (const ip46_address_t * src,
+ const ip46_address_t * dst, u32 out_fib_index, u8 is_ipv6)
{
- gre_main_t * gm = &gre_main;
- uword * p;
+ gre_main_t *gm = &gre_main;
+ uword *p;
u64 key4, key6[4];
if (!is_ipv6)
{
- key4 = gre4_mk_key(&src->ip4, &dst->ip4, out_fib_index);
+ key4 = gre4_mk_key (&src->ip4, &dst->ip4, out_fib_index);
p = hash_get (gm->tunnel_by_key4, key4);
}
else
@@ -102,16 +97,16 @@ gre_tunnel_db_find (const ip46_address_t *src,
}
static void
-gre_tunnel_db_add (const gre_tunnel_t *t)
+gre_tunnel_db_add (const gre_tunnel_t * t)
{
- gre_main_t * gm = &gre_main;
+ gre_main_t *gm = &gre_main;
u64 key4, key6[4], *key6_copy;
u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
if (!is_ipv6)
{
- key4 = gre4_mk_key(&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
- t->outer_fib_index);
+ key4 = gre4_mk_key (&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
+ t->outer_fib_index);
hash_set (gm->tunnel_by_key4, key4, t - gm->tunnels);
}
else
@@ -127,16 +122,16 @@ gre_tunnel_db_add (const gre_tunnel_t *t)
}
static void
-gre_tunnel_db_remove (const gre_tunnel_t *t)
+gre_tunnel_db_remove (const gre_tunnel_t * t)
{
- gre_main_t * gm = &gre_main;
+ gre_main_t *gm = &gre_main;
u64 key4, key6[4];
u8 is_ipv6 = t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6 ? 1 : 0;
if (!is_ipv6)
{
- key4 = gre4_mk_key(&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
- t->outer_fib_index);
+ key4 = gre4_mk_key (&t->tunnel_src.ip4, &t->tunnel_dst.fp_addr.ip4,
+ t->outer_fib_index);
hash_unset (gm->tunnel_by_key4, key4);
}
else
@@ -151,11 +146,11 @@ gre_tunnel_db_remove (const gre_tunnel_t *t)
}
static gre_tunnel_t *
-gre_tunnel_from_fib_node (fib_node_t *node)
+gre_tunnel_from_fib_node (fib_node_t * node)
{
- ASSERT(FIB_NODE_TYPE_GRE_TUNNEL == node->fn_type);
- return ((gre_tunnel_t*) (((char*)node) -
- STRUCT_OFFSET_OF(gre_tunnel_t, node)));
+ ASSERT (FIB_NODE_TYPE_GRE_TUNNEL == node->fn_type);
+ return ((gre_tunnel_t *) (((char *) node) -
+ STRUCT_OFFSET_OF (gre_tunnel_t, node)));
}
/**
@@ -166,37 +161,37 @@ gre_tunnel_from_fib_node (fib_node_t *node)
void
gre_tunnel_stack (adj_index_t ai)
{
- gre_main_t * gm = &gre_main;
- ip_adjacency_t *adj;
- gre_tunnel_t *gt;
- u32 sw_if_index;
-
- adj = adj_get(ai);
- sw_if_index = adj->rewrite_header.sw_if_index;
-
- if ((vec_len(gm->tunnel_index_by_sw_if_index) < sw_if_index) ||
- (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
- return;
-
- gt = pool_elt_at_index(gm->tunnels,
- gm->tunnel_index_by_sw_if_index[sw_if_index]);
-
- /*
- * find the adjacency that is contributed by the FIB entry
- * that this tunnel resovles via, and use it as the next adj
- * in the midchain
- */
- if (vnet_hw_interface_get_flags(vnet_get_main(),
- gt->hw_if_index) &
- VNET_HW_INTERFACE_FLAG_LINK_UP)
+ gre_main_t *gm = &gre_main;
+ ip_adjacency_t *adj;
+ gre_tunnel_t *gt;
+ u32 sw_if_index;
+
+ adj = adj_get (ai);
+ sw_if_index = adj->rewrite_header.sw_if_index;
+
+ if ((vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) ||
+ (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
+ return;
+
+ gt = pool_elt_at_index (gm->tunnels,
+ gm->tunnel_index_by_sw_if_index[sw_if_index]);
+
+ /*
+ * find the adjacency that is contributed by the FIB entry
+ * that this tunnel resovles via, and use it as the next adj
+ * in the midchain
+ */
+ if (vnet_hw_interface_get_flags (vnet_get_main (),
+ gt->hw_if_index) &
+ VNET_HW_INTERFACE_FLAG_LINK_UP)
{
- adj_nbr_midchain_stack(
- ai,
- fib_entry_contribute_ip_forwarding(gt->fib_entry_index));
+ adj_nbr_midchain_stack (ai,
+ fib_entry_contribute_ip_forwarding
+ (gt->fib_entry_index));
}
- else
+ else
{
- adj_nbr_midchain_unstack(ai);
+ adj_nbr_midchain_unstack (ai);
}
}
@@ -204,69 +199,64 @@ gre_tunnel_stack (adj_index_t ai)
* @brief Call back when restacking all adjacencies on a GRE interface
*/
static adj_walk_rc_t
-gre_adj_walk_cb (adj_index_t ai,
- void *ctx)
+gre_adj_walk_cb (adj_index_t ai, void *ctx)
{
- gre_tunnel_stack(ai);
+ gre_tunnel_stack (ai);
- return (ADJ_WALK_RC_CONTINUE);
+ return (ADJ_WALK_RC_CONTINUE);
}
static void
-gre_tunnel_restack (gre_tunnel_t *gt)
+gre_tunnel_restack (gre_tunnel_t * gt)
{
- fib_protocol_t proto;
+ fib_protocol_t proto;
- /*
- * walk all the adjacencies on th GRE interface and restack them
- */
- FOR_EACH_FIB_IP_PROTOCOL(proto)
- {
- adj_nbr_walk(gt->sw_if_index,
- proto,
- gre_adj_walk_cb,
- NULL);
- }
+ /*
+ * walk all the adjacencies on th GRE interface and restack them
+ */
+ FOR_EACH_FIB_IP_PROTOCOL (proto)
+ {
+ adj_nbr_walk (gt->sw_if_index, proto, gre_adj_walk_cb, NULL);
+ }
}
/**
* Function definition to backwalk a FIB node
*/
static fib_node_back_walk_rc_t
-gre_tunnel_back_walk (fib_node_t *node,
- fib_node_back_walk_ctx_t *ctx)
+gre_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
{
- gre_tunnel_restack(gre_tunnel_from_fib_node(node));
+ gre_tunnel_restack (gre_tunnel_from_fib_node (node));
- return (FIB_NODE_BACK_WALK_CONTINUE);
+ return (FIB_NODE_BACK_WALK_CONTINUE);
}
/**
* Function definition to get a FIB node from its index
*/
-static fib_node_t*
+static fib_node_t *
gre_tunnel_fib_node_get (fib_node_index_t index)
{
- gre_tunnel_t * gt;
- gre_main_t * gm;
+ gre_tunnel_t *gt;
+ gre_main_t *gm;
- gm = &gre_main;
- gt = pool_elt_at_index(gm->tunnels, index);
+ gm = &gre_main;
+ gt = pool_elt_at_index (gm->tunnels, index);
- return (&gt->node);
+ return (&gt->node);
}
/**
* Function definition to inform the FIB node that its last lock has gone.
*/
static void
-gre_tunnel_last_lock_gone (fib_node_t *node)
+gre_tunnel_last_lock_gone (fib_node_t * node)
{
- /*
- * The MPLS GRE tunnel is a root of the graph. As such
- * it never has children and thus is never locked.
- */
- ASSERT(0);
+ /*
+ * The MPLS GRE tunnel is a root of the graph. As such
+ * it never has children and thus is never locked.
+ */
+ ASSERT (0);
}
/*
@@ -274,21 +264,20 @@ gre_tunnel_last_lock_gone (fib_node_t *node)
* for participation in the FIB object graph.
*/
const static fib_node_vft_t gre_vft = {
- .fnv_get = gre_tunnel_fib_node_get,
- .fnv_last_lock = gre_tunnel_last_lock_gone,
- .fnv_back_walk = gre_tunnel_back_walk,
+ .fnv_get = gre_tunnel_fib_node_get,
+ .fnv_last_lock = gre_tunnel_last_lock_gone,
+ .fnv_back_walk = gre_tunnel_back_walk,
};
static int
-vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
- u32 * sw_if_indexp)
+vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
{
- gre_main_t * gm = &gre_main;
- vnet_main_t * vnm = gm->vnet_main;
- ip4_main_t * im4 = &ip4_main;
- ip6_main_t * im6 = &ip6_main;
- gre_tunnel_t * t;
- vnet_hw_interface_t * hi;
+ gre_main_t *gm = &gre_main;
+ vnet_main_t *vnm = gm->vnet_main;
+ ip4_main_t *im4 = &ip4_main;
+ ip6_main_t *im6 = &ip6_main;
+ gre_tunnel_t *t;
+ vnet_hw_interface_t *hi;
u32 hw_if_index, sw_if_index;
u32 outer_fib_index;
u8 address[6];
@@ -296,32 +285,33 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
u8 is_ipv6 = a->is_ipv6;
if (!is_ipv6)
- outer_fib_index = ip4_fib_index_from_table_id(a->outer_fib_id);
+ outer_fib_index = ip4_fib_index_from_table_id (a->outer_fib_id);
else
- outer_fib_index = ip6_fib_index_from_table_id(a->outer_fib_id);
+ outer_fib_index = ip6_fib_index_from_table_id (a->outer_fib_id);
if (~0 == outer_fib_index)
return VNET_API_ERROR_NO_SUCH_FIB;
- t = gre_tunnel_db_find(&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
+ t = gre_tunnel_db_find (&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
if (NULL != t)
return VNET_API_ERROR_INVALID_VALUE;
pool_get_aligned (gm->tunnels, t, CLIB_CACHE_LINE_BYTES);
memset (t, 0, sizeof (*t));
- fib_node_init(&t->node, FIB_NODE_TYPE_GRE_TUNNEL);
+ fib_node_init (&t->node, FIB_NODE_TYPE_GRE_TUNNEL);
if (a->teb)
- t->type = GRE_TUNNEL_TYPE_TEB;
+ t->type = GRE_TUNNEL_TYPE_TEB;
else
- t->type = GRE_TUNNEL_TYPE_L3;
+ t->type = GRE_TUNNEL_TYPE_L3;
- if (vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) > 0) {
- vnet_interface_main_t * im = &vnm->interface_main;
+ if (vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) > 0)
+ {
+ vnet_interface_main_t *im = &vnm->interface_main;
hw_if_index = gm->free_gre_tunnel_hw_if_indices[t->type]
- [vec_len (gm->free_gre_tunnel_hw_if_indices[t->type])-1];
+ [vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) - 1];
_vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) -= 1;
hi = vnet_get_hw_interface (vnm, hw_if_index);
@@ -330,54 +320,58 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
/* clear old stats of freed tunnel before reuse */
sw_if_index = hi->sw_if_index;
- vnet_interface_counter_lock(im);
- vlib_zero_combined_counter
- (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX], sw_if_index);
+ vnet_interface_counter_lock (im);
vlib_zero_combined_counter
- (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_RX], sw_if_index);
- vlib_zero_simple_counter
- (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
- vnet_interface_counter_unlock(im);
+ (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
+ sw_if_index);
+ vlib_zero_combined_counter (&im->combined_sw_if_counters
+ [VNET_INTERFACE_COUNTER_RX], sw_if_index);
+ vlib_zero_simple_counter (&im->sw_if_counters
+ [VNET_INTERFACE_COUNTER_DROP], sw_if_index);
+ vnet_interface_counter_unlock (im);
if (GRE_TUNNEL_TYPE_TEB == t->type)
- {
- t->l2_tx_arc = vlib_node_add_named_next(vlib_get_main(),
- hi->tx_node_index,
- "adj-l2-midchain");
- }
- } else {
+ {
+ t->l2_tx_arc = vlib_node_add_named_next (vlib_get_main (),
+ hi->tx_node_index,
+ "adj-l2-midchain");
+ }
+ }
+ else
+ {
if (GRE_TUNNEL_TYPE_TEB == t->type)
- {
- /* Default MAC address (d00b:eed0:0000 + sw_if_index) */
- memset (address, 0, sizeof (address));
- address[0] = 0xd0;
- address[1] = 0x0b;
- address[2] = 0xee;
- address[3] = 0xd0;
- address[4] = t - gm->tunnels;
-
- error = ethernet_register_interface(vnm,
- gre_device_teb_class.index,
- t - gm->tunnels, address,
- &hw_if_index,
- 0);
-
- if (error)
- {
- clib_error_report (error);
- return VNET_API_ERROR_INVALID_REGISTRATION;
- }
- hi = vnet_get_hw_interface (vnm, hw_if_index);
-
- t->l2_tx_arc = vlib_node_add_named_next(vlib_get_main(),
- hi->tx_node_index,
- "adj-l2-midchain");
- } else {
- hw_if_index = vnet_register_interface(vnm,
- gre_device_class.index,
- t - gm->tunnels,
- gre_hw_interface_class.index,
- t - gm->tunnels);
- }
+ {
+ /* Default MAC address (d00b:eed0:0000 + sw_if_index) */
+ memset (address, 0, sizeof (address));
+ address[0] = 0xd0;
+ address[1] = 0x0b;
+ address[2] = 0xee;
+ address[3] = 0xd0;
+ address[4] = t - gm->tunnels;
+
+ error = ethernet_register_interface (vnm,
+ gre_device_teb_class.index,
+ t - gm->tunnels, address,
+ &hw_if_index, 0);
+
+ if (error)
+ {
+ clib_error_report (error);
+ return VNET_API_ERROR_INVALID_REGISTRATION;
+ }
+ hi = vnet_get_hw_interface (vnm, hw_if_index);
+
+ t->l2_tx_arc = vlib_node_add_named_next (vlib_get_main (),
+ hi->tx_node_index,
+ "adj-l2-midchain");
+ }
+ else
+ {
+ hw_if_index = vnet_register_interface (vnm,
+ gre_device_class.index,
+ t - gm->tunnels,
+ gre_hw_interface_class.index,
+ t - gm->tunnels);
+ }
hi = vnet_get_hw_interface (vnm, hw_if_index);
sw_if_index = hi->sw_if_index;
}
@@ -393,16 +387,18 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
if (!is_ipv6)
{
vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
- hi->min_packet_bytes = 64 + sizeof (gre_header_t) + sizeof (ip4_header_t);
+ hi->min_packet_bytes =
+ 64 + sizeof (gre_header_t) + sizeof (ip4_header_t);
}
else
{
vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
- hi->min_packet_bytes = 64 + sizeof (gre_header_t) + sizeof (ip6_header_t);
+ hi->min_packet_bytes =
+ 64 + sizeof (gre_header_t) + sizeof (ip6_header_t);
}
hi->per_packet_overhead_bytes =
- /* preamble */ 8 + /* inter frame gap */ 12;
+ /* preamble */ 8 + /* inter frame gap */ 12;
/* Standard default gre MTU. */
hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] = 9000;
@@ -419,26 +415,23 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
t->tunnel_dst.fp_proto = !is_ipv6 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
t->tunnel_dst.fp_addr = a->dst;
- gre_tunnel_db_add(t);
+ gre_tunnel_db_add (t);
t->fib_entry_index =
- fib_table_entry_special_add(outer_fib_index,
- &t->tunnel_dst,
- FIB_SOURCE_RR,
- FIB_ENTRY_FLAG_NONE);
+ fib_table_entry_special_add (outer_fib_index,
+ &t->tunnel_dst,
+ FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE);
t->sibling_index =
- fib_entry_child_add(t->fib_entry_index,
- FIB_NODE_TYPE_GRE_TUNNEL,
- t - gm->tunnels);
+ fib_entry_child_add (t->fib_entry_index,
+ FIB_NODE_TYPE_GRE_TUNNEL, t - gm->tunnels);
if (GRE_TUNNEL_TYPE_TEB == t->type)
- {
- t->l2_adj_index = adj_nbr_add_or_lock(t->tunnel_dst.fp_proto,
- VNET_LINK_ETHERNET,
- &zero_addr,
- sw_if_index);
- gre_update_adj(vnm, t->sw_if_index, t->l2_adj_index);
- }
+ {
+ t->l2_adj_index = adj_nbr_add_or_lock (t->tunnel_dst.fp_proto,
+ VNET_LINK_ETHERNET,
+ &zero_addr, sw_if_index);
+ gre_update_adj (vnm, t->sw_if_index, t->l2_adj_index);
+ }
if (sw_if_indexp)
*sw_if_indexp = sw_if_index;
@@ -447,39 +440,37 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a,
}
static int
-vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t *a,
- u32 * sw_if_indexp)
+vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a,
+ u32 * sw_if_indexp)
{
- gre_main_t * gm = &gre_main;
- vnet_main_t * vnm = gm->vnet_main;
- gre_tunnel_t * t;
+ gre_main_t *gm = &gre_main;
+ vnet_main_t *vnm = gm->vnet_main;
+ gre_tunnel_t *t;
u32 sw_if_index;
- t = gre_tunnel_db_find(&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
+ t = gre_tunnel_db_find (&a->src, &a->dst, a->outer_fib_id, a->is_ipv6);
if (NULL == t)
return VNET_API_ERROR_NO_SUCH_ENTRY;
sw_if_index = t->sw_if_index;
- vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */);
+ vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ );
/* make sure tunnel is removed from l2 bd or xconnect */
- set_int_l2_mode(gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0);
+ set_int_l2_mode (gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0);
vec_add1 (gm->free_gre_tunnel_hw_if_indices[t->type], t->hw_if_index);
gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0;
if (GRE_TUNNEL_TYPE_TEB == t->type)
- adj_unlock(t->l2_adj_index);
+ adj_unlock (t->l2_adj_index);
if (t->l2_adj_index != ADJ_INDEX_INVALID)
- adj_unlock(t->l2_adj_index);
+ adj_unlock (t->l2_adj_index);
- fib_entry_child_remove(t->fib_entry_index,
- t->sibling_index);
- fib_table_entry_delete_index(t->fib_entry_index,
- FIB_SOURCE_RR);
+ fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
+ fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
- gre_tunnel_db_remove(t);
- fib_node_deinit(&t->node);
+ gre_tunnel_db_remove (t);
+ fib_node_deinit (&t->node);
pool_put (gm->tunnels, t);
if (sw_if_indexp)
@@ -489,54 +480,55 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t *a,
}
int
-vnet_gre_add_del_tunnel (vnet_gre_add_del_tunnel_args_t *a,
- u32 * sw_if_indexp)
+vnet_gre_add_del_tunnel (vnet_gre_add_del_tunnel_args_t * a,
+ u32 * sw_if_indexp)
{
if (a->is_add)
- return (vnet_gre_tunnel_add(a, sw_if_indexp));
+ return (vnet_gre_tunnel_add (a, sw_if_indexp));
else
- return (vnet_gre_tunnel_delete(a, sw_if_indexp));
+ return (vnet_gre_tunnel_delete (a, sw_if_indexp));
}
clib_error_t *
gre_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
- gre_main_t * gm = &gre_main;
- vnet_hw_interface_t * hi;
+ gre_main_t *gm = &gre_main;
+ vnet_hw_interface_t *hi;
gre_tunnel_t *t;
u32 ti;
hi = vnet_get_hw_interface (vnm, hw_if_index);
if (NULL == gm->tunnel_index_by_sw_if_index ||
- hi->sw_if_index >= vec_len(gm->tunnel_index_by_sw_if_index))
- return (NULL);
+ hi->sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index))
+ return (NULL);
ti = gm->tunnel_index_by_sw_if_index[hi->sw_if_index];
if (~0 == ti)
- /* not one of ours */
- return (NULL);
+ /* not one of ours */
+ return (NULL);
- t = pool_elt_at_index(gm->tunnels, ti);
+ t = pool_elt_at_index (gm->tunnels, ti);
if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
- vnet_hw_interface_set_flags (vnm, hw_if_index, VNET_HW_INTERFACE_FLAG_LINK_UP);
+ vnet_hw_interface_set_flags (vnm, hw_if_index,
+ VNET_HW_INTERFACE_FLAG_LINK_UP);
else
- vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */);
+ vnet_hw_interface_set_flags (vnm, hw_if_index, 0 /* down */ );
- gre_tunnel_restack(t);
+ gre_tunnel_restack (t);
return /* no error */ 0;
}
static clib_error_t *
create_gre_tunnel_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
- unformat_input_t _line_input, * line_input = &_line_input;
- vnet_gre_add_del_tunnel_args_t _a, * a = &_a;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
ip46_address_t src, dst;
u32 outer_fib_id = 0;
u8 teb = 0;
@@ -549,35 +541,48 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
u8 ipv6_set = 0;
/* Get a line of input. */
- if (! unformat_user (input, unformat_line_input, line_input))
+ if (!unformat_user (input, unformat_line_input, line_input))
return 0;
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (line_input, "del"))
- is_add = 0;
- else if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4)) {
- num_m_args++;
- ipv4_set = 1;
- } else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4)) {
- num_m_args++;
- ipv4_set = 1;
- } else if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6)) {
- num_m_args++;
- ipv6_set = 1;
- } else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6)) {
- num_m_args++;
- ipv6_set = 1;
- } else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
- ;
- else if (unformat (line_input, "teb"))
- teb = 1;
- else
- {
- error = clib_error_return (0, "unknown input `%U'",
- format_unformat_error, line_input);
- goto done;
- }
- }
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "del"))
+ is_add = 0;
+ else
+ if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
+ {
+ num_m_args++;
+ ipv4_set = 1;
+ }
+ else
+ if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
+ {
+ num_m_args++;
+ ipv4_set = 1;
+ }
+ else
+ if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
+ {
+ num_m_args++;
+ ipv6_set = 1;
+ }
+ else
+ if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
+ {
+ num_m_args++;
+ ipv6_set = 1;
+ }
+ else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
+ ;
+ else if (unformat (line_input, "teb"))
+ teb = 1;
+ else
+ {
+ error = clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
+ }
if (num_m_args < 2)
{
@@ -585,18 +590,19 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
goto done;
}
- if ((ipv4_set && memcmp (&src.ip4, &dst.ip4, sizeof(src.ip4)) == 0) ||
- (ipv6_set && memcmp (&src.ip6, &dst.ip6, sizeof(src.ip6)) == 0))
+ if ((ipv4_set && memcmp (&src.ip4, &dst.ip4, sizeof (src.ip4)) == 0) ||
+ (ipv6_set && memcmp (&src.ip6, &dst.ip6, sizeof (src.ip6)) == 0))
{
error = clib_error_return (0, "src and dst are identical");
goto done;
}
if (ipv4_set && ipv6_set)
- return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
+ return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
- if ((ipv4_set && memcmp (&dst.ip4, &zero_addr.ip4, sizeof(dst.ip4)) == 0) ||
- (ipv6_set && memcmp (&dst.ip6, &zero_addr.ip6, sizeof(dst.ip6)) == 0))
+ if ((ipv4_set && memcmp (&dst.ip4, &zero_addr.ip4, sizeof (dst.ip4)) == 0)
+ || (ipv6_set
+ && memcmp (&dst.ip6, &zero_addr.ip6, sizeof (dst.ip6)) == 0))
{
error = clib_error_return (0, "dst address cannot be zero");
goto done;
@@ -608,34 +614,36 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
a->is_ipv6 = ipv6_set;
if (!ipv6_set)
{
- clib_memcpy(&a->src.ip4, &src.ip4, sizeof(src.ip4));
- clib_memcpy(&a->dst.ip4, &dst.ip4, sizeof(dst.ip4));
+ clib_memcpy (&a->src.ip4, &src.ip4, sizeof (src.ip4));
+ clib_memcpy (&a->dst.ip4, &dst.ip4, sizeof (dst.ip4));
}
else
{
- clib_memcpy(&a->src.ip6, &src.ip6, sizeof(src.ip6));
- clib_memcpy(&a->dst.ip6, &dst.ip6, sizeof(dst.ip6));
+ clib_memcpy (&a->src.ip6, &src.ip6, sizeof (src.ip6));
+ clib_memcpy (&a->dst.ip6, &dst.ip6, sizeof (dst.ip6));
}
if (is_add)
- rv = vnet_gre_tunnel_add(a, &sw_if_index);
+ rv = vnet_gre_tunnel_add (a, &sw_if_index);
else
- rv = vnet_gre_tunnel_delete(a, &sw_if_index);
+ rv = vnet_gre_tunnel_delete (a, &sw_if_index);
- switch(rv)
+ switch (rv)
{
case 0:
- vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
+ vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
+ vnet_get_main (), sw_if_index);
break;
case VNET_API_ERROR_INVALID_VALUE:
error = clib_error_return (0, "GRE tunnel already exists...");
goto done;
case VNET_API_ERROR_NO_SUCH_FIB:
error = clib_error_return (0, "outer fib ID %d doesn't exist\n",
- outer_fib_id);
+ outer_fib_id);
goto done;
default:
- error = clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv);
+ error =
+ clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv);
goto done;
}
@@ -645,20 +653,22 @@ done:
return error;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = {
.path = "create gre tunnel",
.short_help = "create gre tunnel src <addr> dst <addr> "
"[outer-fib-id <fib>] [teb] [del]",
.function = create_gre_tunnel_command_fn,
};
+/* *INDENT-ON* */
static clib_error_t *
show_gre_tunnel_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
- gre_main_t * gm = &gre_main;
- gre_tunnel_t * t;
+ gre_main_t *gm = &gre_main;
+ gre_tunnel_t *t;
u32 ti = ~0;
if (pool_elts (gm->tunnels) == 0)
@@ -667,38 +677,52 @@ show_gre_tunnel_command_fn (vlib_main_t * vm,
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "%d", &ti))
- ;
+ ;
else
- break;
+ break;
}
if (~0 == ti)
{
+ /* *INDENT-OFF* */
pool_foreach (t, gm->tunnels,
({
vlib_cli_output (vm, "%U", format_gre_tunnel, t);
}));
+ /* *INDENT-ON* */
}
else
- {
- t = pool_elt_at_index(gm->tunnels, ti);
+ {
+ t = pool_elt_at_index (gm->tunnels, ti);
vlib_cli_output (vm, "%U", format_gre_tunnel, t);
- }
+ }
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_gre_tunnel_command, static) = {
.path = "show gre tunnel",
.function = show_gre_tunnel_command_fn,
};
+/* *INDENT-ON* */
/* force inclusion from application's main.c */
-clib_error_t *gre_interface_init (vlib_main_t *vm)
+clib_error_t *
+gre_interface_init (vlib_main_t * vm)
{
- fib_node_register_type(FIB_NODE_TYPE_GRE_TUNNEL, &gre_vft);
+ fib_node_register_type (FIB_NODE_TYPE_GRE_TUNNEL, &gre_vft);
return 0;
}
-VLIB_INIT_FUNCTION(gre_interface_init);
+
+VLIB_INIT_FUNCTION (gre_interface_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/gre/node.c b/src/vnet/gre/node.c
index acf15f247f0..e10f116fa6d 100644
--- a/src/vnet/gre/node.c
+++ b/src/vnet/gre/node.c
@@ -29,14 +29,16 @@ _(IP4_INPUT, "ip4-input") \
_(IP6_INPUT, "ip6-input") \
_(MPLS_INPUT, "mpls-input")
-typedef enum {
+typedef enum
+{
#define _(s,n) GRE_INPUT_NEXT_##s,
foreach_gre_input_next
#undef _
- GRE_INPUT_N_NEXT,
+ GRE_INPUT_N_NEXT,
} gre_input_next_t;
-typedef struct {
+typedef struct
+{
u32 tunnel_id;
u32 length;
ip46_address_t src;
@@ -44,45 +46,45 @@ typedef struct {
u8 is_ipv6;
} gre_rx_trace_t;
-u8 * format_gre_rx_trace (u8 * s, va_list * args)
+u8 *
+format_gre_rx_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- gre_rx_trace_t * t = va_arg (*args, gre_rx_trace_t *);
+ gre_rx_trace_t *t = va_arg (*args, gre_rx_trace_t *);
s = format (s, "GRE: tunnel %d len %d src %U dst %U",
- t->tunnel_id, clib_net_to_host_u16(t->length),
- format_ip46_address, &t->src, IP46_TYPE_ANY,
- format_ip46_address, &t->dst, IP46_TYPE_ANY);
+ t->tunnel_id, clib_net_to_host_u16 (t->length),
+ format_ip46_address, &t->src, IP46_TYPE_ANY,
+ format_ip46_address, &t->dst, IP46_TYPE_ANY);
return s;
}
-typedef struct {
+typedef struct
+{
/* Sparse vector mapping gre protocol in network byte order
to next index. */
- u16 * next_by_protocol;
+ u16 *next_by_protocol;
} gre_input_runtime_t;
always_inline uword
gre_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame,
- u8 is_ipv6)
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame, u8 is_ipv6)
{
- gre_main_t * gm = &gre_main;
- __attribute__((unused)) u32 n_left_from, next_index, * from, * to_next;
+ gre_main_t *gm = &gre_main;
+ __attribute__ ((unused)) u32 n_left_from, next_index, *from, *to_next;
u64 cached_tunnel_key4;
u64 cached_tunnel_key6[4];
u32 cached_tunnel_sw_if_index = 0, tunnel_sw_if_index = 0;
- u32 thread_index = vlib_get_thread_index();
+ u32 thread_index = vlib_get_thread_index ();
u32 len;
vnet_interface_main_t *im = &gm->vnet_main->interface_main;
if (!is_ipv6)
- memset (&cached_tunnel_key4, 0xff, sizeof(cached_tunnel_key4));
+ memset (&cached_tunnel_key4, 0xff, sizeof (cached_tunnel_key4));
else
- memset (&cached_tunnel_key6, 0xff, sizeof(cached_tunnel_key6));
+ memset (&cached_tunnel_key6, 0xff, sizeof (cached_tunnel_key6));
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
@@ -93,27 +95,26 @@ gre_input (vlib_main_t * vm,
{
u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index,
- to_next, n_left_to_next);
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from >= 4 && n_left_to_next >= 2)
{
u32 bi0, bi1;
- vlib_buffer_t * b0, * b1;
- gre_header_t * h0, * h1;
- u16 version0, version1;
- int verr0, verr1;
+ vlib_buffer_t *b0, *b1;
+ gre_header_t *h0, *h1;
+ u16 version0, version1;
+ int verr0, verr1;
u32 i0, i1, next0, next1, protocol0, protocol1;
- ip4_header_t *ip4_0, *ip4_1;
- ip6_header_t *ip6_0, *ip6_1;
- u32 ip4_tun_src0, ip4_tun_dst0;
- u32 ip4_tun_src1, ip4_tun_dst1;
- u64 ip6_tun_src0[2], ip6_tun_dst0[2];
- u64 ip6_tun_src1[2], ip6_tun_dst1[2];
+ ip4_header_t *ip4_0, *ip4_1;
+ ip6_header_t *ip6_0, *ip6_1;
+ u32 ip4_tun_src0, ip4_tun_dst0;
+ u32 ip4_tun_src1, ip4_tun_dst1;
+ u64 ip6_tun_src0[2], ip6_tun_dst0[2];
+ u64 ip6_tun_src1[2], ip6_tun_dst1[2];
/* Prefetch next iteration. */
{
- vlib_buffer_t * p2, * p3;
+ vlib_buffer_t *p2, *p3;
p2 = vlib_get_buffer (vm, from[2]);
p3 = vlib_get_buffer (vm, from[3]);
@@ -137,38 +138,38 @@ gre_input (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
b1 = vlib_get_buffer (vm, bi1);
- if (!is_ipv6)
- {
- /* ip4_local hands us the ip header, not the gre header */
- ip4_0 = vlib_buffer_get_current (b0);
- ip4_1 = vlib_buffer_get_current (b1);
- /* Save src + dst ip4 address, e.g. for mpls-o-gre */
- ip4_tun_src0 = ip4_0->src_address.as_u32;
- ip4_tun_dst0 = ip4_0->dst_address.as_u32;
- ip4_tun_src1 = ip4_1->src_address.as_u32;
- ip4_tun_dst1 = ip4_1->dst_address.as_u32;
-
- vlib_buffer_advance (b0, sizeof (*ip4_0));
- vlib_buffer_advance (b1, sizeof (*ip4_1));
- }
- else
- {
- /* ip6_local hands us the ip header, not the gre header */
- ip6_0 = vlib_buffer_get_current (b0);
- ip6_1 = vlib_buffer_get_current (b1);
- /* Save src + dst ip6 address, e.g. for mpls-o-gre */
- ip6_tun_src0[0] = ip6_0->src_address.as_u64[0];
- ip6_tun_src0[1] = ip6_0->src_address.as_u64[1];
- ip6_tun_dst0[0] = ip6_0->dst_address.as_u64[0];
- ip6_tun_dst0[1] = ip6_0->dst_address.as_u64[1];
- ip6_tun_src1[0] = ip6_1->src_address.as_u64[0];
- ip6_tun_src1[1] = ip6_1->src_address.as_u64[1];
- ip6_tun_dst1[0] = ip6_1->dst_address.as_u64[0];
- ip6_tun_dst1[1] = ip6_1->dst_address.as_u64[1];
-
- vlib_buffer_advance (b0, sizeof (*ip6_0));
- vlib_buffer_advance (b1, sizeof (*ip6_1));
- }
+ if (!is_ipv6)
+ {
+ /* ip4_local hands us the ip header, not the gre header */
+ ip4_0 = vlib_buffer_get_current (b0);
+ ip4_1 = vlib_buffer_get_current (b1);
+ /* Save src + dst ip4 address, e.g. for mpls-o-gre */
+ ip4_tun_src0 = ip4_0->src_address.as_u32;
+ ip4_tun_dst0 = ip4_0->dst_address.as_u32;
+ ip4_tun_src1 = ip4_1->src_address.as_u32;
+ ip4_tun_dst1 = ip4_1->dst_address.as_u32;
+
+ vlib_buffer_advance (b0, sizeof (*ip4_0));
+ vlib_buffer_advance (b1, sizeof (*ip4_1));
+ }
+ else
+ {
+ /* ip6_local hands us the ip header, not the gre header */
+ ip6_0 = vlib_buffer_get_current (b0);
+ ip6_1 = vlib_buffer_get_current (b1);
+ /* Save src + dst ip6 address, e.g. for mpls-o-gre */
+ ip6_tun_src0[0] = ip6_0->src_address.as_u64[0];
+ ip6_tun_src0[1] = ip6_0->src_address.as_u64[1];
+ ip6_tun_dst0[0] = ip6_0->dst_address.as_u64[0];
+ ip6_tun_dst0[1] = ip6_0->dst_address.as_u64[1];
+ ip6_tun_src1[0] = ip6_1->src_address.as_u64[0];
+ ip6_tun_src1[1] = ip6_1->src_address.as_u64[1];
+ ip6_tun_dst1[0] = ip6_1->dst_address.as_u64[0];
+ ip6_tun_dst1[1] = ip6_1->dst_address.as_u64[1];
+
+ vlib_buffer_advance (b0, sizeof (*ip6_0));
+ vlib_buffer_advance (b1, sizeof (*ip6_1));
+ }
h0 = vlib_buffer_get_current (b0);
h1 = vlib_buffer_get_current (b1);
@@ -177,205 +178,209 @@ gre_input (vlib_main_t * vm,
protocol0 = h0->protocol;
protocol1 = h1->protocol;
sparse_vec_index2 (gm->next_by_protocol, protocol0, protocol1,
- &i0, &i1);
- next0 = vec_elt(gm->next_by_protocol, i0);
- next1 = vec_elt(gm->next_by_protocol, i1);
-
- b0->error = node->errors[i0 == SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE];
- b1->error = node->errors[i1 == SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE];
-
- version0 = clib_net_to_host_u16 (h0->flags_and_version);
- verr0 = version0 & GRE_VERSION_MASK;
- version1 = clib_net_to_host_u16 (h1->flags_and_version);
- verr1 = version1 & GRE_VERSION_MASK;
-
- b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
- : b0->error;
- next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
- b1->error = verr1 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
- : b1->error;
- next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1;
-
-
- /* RPF check for ip4/ip6 input */
- if (PREDICT_TRUE(next0 == GRE_INPUT_NEXT_IP4_INPUT
- || next0 == GRE_INPUT_NEXT_IP6_INPUT
- || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
- || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
- {
-
- u64 key4, key6[4];
- if (!is_ipv6)
- {
- key4 = ((u64)(ip4_tun_dst0) << 32) | (u64)(ip4_tun_src0);
- }
- else
- {
- key6[0] = ip6_tun_dst0[0];
- key6[1] = ip6_tun_dst0[1];
- key6[2] = ip6_tun_src0[0];
- key6[3] = ip6_tun_src0[1];
- }
-
- if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
- (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
- cached_tunnel_key6[1] != key6[1] &&
- cached_tunnel_key6[2] != key6[2] &&
- cached_tunnel_key6[3] != key6[3]))
- {
- vnet_hw_interface_t * hi;
- gre_tunnel_t * t;
- uword * p;
-
- if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
- else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
- if (!p)
- {
- next0 = GRE_INPUT_NEXT_DROP;
- b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
- goto drop0;
- }
- t = pool_elt_at_index (gm->tunnels, p[0]);
- hi = vnet_get_hw_interface (gm->vnet_main,
- t->hw_if_index);
- tunnel_sw_if_index = hi->sw_if_index;
-
- cached_tunnel_sw_if_index = tunnel_sw_if_index;
- }
- else
- {
- tunnel_sw_if_index = cached_tunnel_sw_if_index;
- }
- }
- else
- {
- next0 = GRE_INPUT_NEXT_DROP;
- goto drop0;
- }
- len = vlib_buffer_length_in_chain (vm, b0);
- vlib_increment_combined_counter (im->combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index,
- tunnel_sw_if_index,
- 1 /* packets */,
- len /* bytes */);
-
- vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
-
-drop0:
- if (PREDICT_TRUE(next1 == GRE_INPUT_NEXT_IP4_INPUT
- || next1 == GRE_INPUT_NEXT_IP6_INPUT
- || next1 == GRE_INPUT_NEXT_ETHERNET_INPUT
- || next1 == GRE_INPUT_NEXT_MPLS_INPUT))
- {
- u64 key4, key6[4];
- if (!is_ipv6)
- {
- key4 = ((u64)(ip4_tun_dst1) << 32) | (u64)(ip4_tun_src1);
- }
- else
- {
- key6[0] = ip6_tun_dst1[0];
- key6[1] = ip6_tun_dst1[1];
- key6[2] = ip6_tun_src1[0];
- key6[3] = ip6_tun_src1[1];
- }
-
- if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
- (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
- cached_tunnel_key6[1] != key6[1] &&
- cached_tunnel_key6[2] != key6[2] &&
- cached_tunnel_key6[3] != key6[3]))
- {
- vnet_hw_interface_t * hi;
- gre_tunnel_t * t;
- uword * p;
-
- if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
- else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
-
- if (!p)
- {
- next1 = GRE_INPUT_NEXT_DROP;
- b1->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
- goto drop1;
- }
- t = pool_elt_at_index (gm->tunnels, p[0]);
- hi = vnet_get_hw_interface (gm->vnet_main,
- t->hw_if_index);
- tunnel_sw_if_index = hi->sw_if_index;
-
- cached_tunnel_sw_if_index = tunnel_sw_if_index;
- }
- else
- {
- tunnel_sw_if_index = cached_tunnel_sw_if_index;
- }
- }
- else
- {
- next1 = GRE_INPUT_NEXT_DROP;
- goto drop1;
- }
- len = vlib_buffer_length_in_chain (vm, b1);
- vlib_increment_combined_counter (im->combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index,
- tunnel_sw_if_index,
- 1 /* packets */,
- len /* bytes */);
-
- vnet_buffer(b1)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
-
-drop1:
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- gre_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
- tr->tunnel_id = tunnel_sw_if_index;
- if (!is_ipv6)
- {
- tr->length = ip4_0->length;
- tr->src.ip4.as_u32 = ip4_0->src_address.as_u32;
- tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32;
- }
- else
- {
- tr->length = ip6_0->payload_length;
- tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0];
- tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1];
- tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0];
- tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1];
- }
- }
-
- if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
- {
- gre_rx_trace_t *tr = vlib_add_trace (vm, node,
- b1, sizeof (*tr));
- tr->tunnel_id = tunnel_sw_if_index;
- if (!is_ipv6)
- {
- tr->length = ip4_1->length;
- tr->src.ip4.as_u32 = ip4_1->src_address.as_u32;
- tr->dst.ip4.as_u32 = ip4_1->dst_address.as_u32;
- }
- else
- {
- tr->length = ip6_1->payload_length;
- tr->src.ip6.as_u64[0] = ip6_1->src_address.as_u64[0];
- tr->src.ip6.as_u64[1] = ip6_1->src_address.as_u64[1];
- tr->dst.ip6.as_u64[0] = ip6_1->dst_address.as_u64[0];
- tr->dst.ip6.as_u64[1] = ip6_1->dst_address.as_u64[1];
- }
- }
-
- vlib_buffer_advance (b0, sizeof (*h0));
- vlib_buffer_advance (b1, sizeof (*h1));
+ &i0, &i1);
+ next0 = vec_elt (gm->next_by_protocol, i0);
+ next1 = vec_elt (gm->next_by_protocol, i1);
+
+ b0->error =
+ node->errors[i0 ==
+ SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL
+ : GRE_ERROR_NONE];
+ b1->error =
+ node->errors[i1 ==
+ SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL
+ : GRE_ERROR_NONE];
+
+ version0 = clib_net_to_host_u16 (h0->flags_and_version);
+ verr0 = version0 & GRE_VERSION_MASK;
+ version1 = clib_net_to_host_u16 (h1->flags_and_version);
+ verr1 = version1 & GRE_VERSION_MASK;
+
+ b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
+ : b0->error;
+ next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
+ b1->error = verr1 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
+ : b1->error;
+ next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1;
+
+
+ /* RPF check for ip4/ip6 input */
+ if (PREDICT_TRUE (next0 == GRE_INPUT_NEXT_IP4_INPUT
+ || next0 == GRE_INPUT_NEXT_IP6_INPUT
+ || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
+ || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
+ {
+
+ u64 key4, key6[4];
+ if (!is_ipv6)
+ {
+ key4 = ((u64) (ip4_tun_dst0) << 32) | (u64) (ip4_tun_src0);
+ }
+ else
+ {
+ key6[0] = ip6_tun_dst0[0];
+ key6[1] = ip6_tun_dst0[1];
+ key6[2] = ip6_tun_src0[0];
+ key6[3] = ip6_tun_src0[1];
+ }
+
+ if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
+ (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
+ cached_tunnel_key6[1] != key6[1] &&
+ cached_tunnel_key6[2] != key6[2] &&
+ cached_tunnel_key6[3] != key6[3]))
+ {
+ vnet_hw_interface_t *hi;
+ gre_tunnel_t *t;
+ uword *p;
+
+ if (!is_ipv6)
+ p = hash_get (gm->tunnel_by_key4, key4);
+ else
+ p = hash_get_mem (gm->tunnel_by_key6, key6);
+ if (!p)
+ {
+ next0 = GRE_INPUT_NEXT_DROP;
+ b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
+ goto drop0;
+ }
+ t = pool_elt_at_index (gm->tunnels, p[0]);
+ hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index);
+ tunnel_sw_if_index = hi->sw_if_index;
+
+ cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ }
+ else
+ {
+ tunnel_sw_if_index = cached_tunnel_sw_if_index;
+ }
+ }
+ else
+ {
+ next0 = GRE_INPUT_NEXT_DROP;
+ goto drop0;
+ }
+ len = vlib_buffer_length_in_chain (vm, b0);
+ vlib_increment_combined_counter (im->combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ thread_index,
+ tunnel_sw_if_index,
+ 1 /* packets */ ,
+ len /* bytes */ );
+
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
+
+ drop0:
+ if (PREDICT_TRUE (next1 == GRE_INPUT_NEXT_IP4_INPUT
+ || next1 == GRE_INPUT_NEXT_IP6_INPUT
+ || next1 == GRE_INPUT_NEXT_ETHERNET_INPUT
+ || next1 == GRE_INPUT_NEXT_MPLS_INPUT))
+ {
+ u64 key4, key6[4];
+ if (!is_ipv6)
+ {
+ key4 = ((u64) (ip4_tun_dst1) << 32) | (u64) (ip4_tun_src1);
+ }
+ else
+ {
+ key6[0] = ip6_tun_dst1[0];
+ key6[1] = ip6_tun_dst1[1];
+ key6[2] = ip6_tun_src1[0];
+ key6[3] = ip6_tun_src1[1];
+ }
+
+ if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
+ (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
+ cached_tunnel_key6[1] != key6[1] &&
+ cached_tunnel_key6[2] != key6[2] &&
+ cached_tunnel_key6[3] != key6[3]))
+ {
+ vnet_hw_interface_t *hi;
+ gre_tunnel_t *t;
+ uword *p;
+
+ if (!is_ipv6)
+ p = hash_get (gm->tunnel_by_key4, key4);
+ else
+ p = hash_get_mem (gm->tunnel_by_key6, key6);
+
+ if (!p)
+ {
+ next1 = GRE_INPUT_NEXT_DROP;
+ b1->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
+ goto drop1;
+ }
+ t = pool_elt_at_index (gm->tunnels, p[0]);
+ hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index);
+ tunnel_sw_if_index = hi->sw_if_index;
+
+ cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ }
+ else
+ {
+ tunnel_sw_if_index = cached_tunnel_sw_if_index;
+ }
+ }
+ else
+ {
+ next1 = GRE_INPUT_NEXT_DROP;
+ goto drop1;
+ }
+ len = vlib_buffer_length_in_chain (vm, b1);
+ vlib_increment_combined_counter (im->combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ thread_index,
+ tunnel_sw_if_index,
+ 1 /* packets */ ,
+ len /* bytes */ );
+
+ vnet_buffer (b1)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
+
+ drop1:
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ gre_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
+ tr->tunnel_id = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ tr->length = ip4_0->length;
+ tr->src.ip4.as_u32 = ip4_0->src_address.as_u32;
+ tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32;
+ }
+ else
+ {
+ tr->length = ip6_0->payload_length;
+ tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0];
+ tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1];
+ tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0];
+ tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1];
+ }
+ }
+
+ if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ gre_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b1, sizeof (*tr));
+ tr->tunnel_id = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ tr->length = ip4_1->length;
+ tr->src.ip4.as_u32 = ip4_1->src_address.as_u32;
+ tr->dst.ip4.as_u32 = ip4_1->dst_address.as_u32;
+ }
+ else
+ {
+ tr->length = ip6_1->payload_length;
+ tr->src.ip6.as_u64[0] = ip6_1->src_address.as_u64[0];
+ tr->src.ip6.as_u64[1] = ip6_1->src_address.as_u64[1];
+ tr->dst.ip6.as_u64[0] = ip6_1->dst_address.as_u64[0];
+ tr->dst.ip6.as_u64[1] = ip6_1->dst_address.as_u64[1];
+ }
+ }
+
+ vlib_buffer_advance (b0, sizeof (*h0));
+ vlib_buffer_advance (b1, sizeof (*h1));
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
@@ -385,15 +390,15 @@ drop1:
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
- vlib_buffer_t * b0;
- gre_header_t * h0;
- ip4_header_t * ip4_0;
- ip6_header_t * ip6_0;
- u16 version0;
- int verr0;
+ vlib_buffer_t *b0;
+ gre_header_t *h0;
+ ip4_header_t *ip4_0;
+ ip6_header_t *ip6_0;
+ u16 version0;
+ int verr0;
u32 i0, next0;
- u32 ip4_tun_src0, ip4_tun_dst0;
- u32 ip6_tun_src0[4], ip6_tun_dst0[4];
+ u32 ip4_tun_src0, ip4_tun_dst0;
+ u32 ip6_tun_src0[4], ip6_tun_dst0[4];
bi0 = from[0];
to_next[0] = bi0;
@@ -403,135 +408,134 @@ drop1:
n_left_to_next -= 1;
b0 = vlib_get_buffer (vm, bi0);
- ip4_0 = vlib_buffer_get_current (b0);
- ip6_0 = (void *)ip4_0;
-
- if (!is_ipv6)
- {
- ip4_tun_src0 = ip4_0->src_address.as_u32;
- ip4_tun_dst0 = ip4_0->dst_address.as_u32;
-
- vlib_buffer_advance (b0, sizeof (*ip4_0));
- }
- else
- {
- ip6_tun_src0[0] = ip6_0->src_address.as_u64[0];
- ip6_tun_src0[1] = ip6_0->src_address.as_u64[1];
- ip6_tun_dst0[0] = ip6_0->dst_address.as_u64[0];
- ip6_tun_dst0[1] = ip6_0->dst_address.as_u64[1];
-
- vlib_buffer_advance (b0, sizeof (*ip6_0));
- }
+ ip4_0 = vlib_buffer_get_current (b0);
+ ip6_0 = (void *) ip4_0;
+
+ if (!is_ipv6)
+ {
+ ip4_tun_src0 = ip4_0->src_address.as_u32;
+ ip4_tun_dst0 = ip4_0->dst_address.as_u32;
+
+ vlib_buffer_advance (b0, sizeof (*ip4_0));
+ }
+ else
+ {
+ ip6_tun_src0[0] = ip6_0->src_address.as_u64[0];
+ ip6_tun_src0[1] = ip6_0->src_address.as_u64[1];
+ ip6_tun_dst0[0] = ip6_0->dst_address.as_u64[0];
+ ip6_tun_dst0[1] = ip6_0->dst_address.as_u64[1];
+
+ vlib_buffer_advance (b0, sizeof (*ip6_0));
+ }
h0 = vlib_buffer_get_current (b0);
i0 = sparse_vec_index (gm->next_by_protocol, h0->protocol);
- next0 = vec_elt(gm->next_by_protocol, i0);
+ next0 = vec_elt (gm->next_by_protocol, i0);
b0->error =
- node->errors[i0 == SPARSE_VEC_INVALID_INDEX
- ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE];
-
- version0 = clib_net_to_host_u16 (h0->flags_and_version);
- verr0 = version0 & GRE_VERSION_MASK;
- b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
- : b0->error;
- next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
-
-
- /* For IP payload we need to find source interface
- so we can increase counters and help forward node to
- pick right FIB */
- /* RPF check for ip4/ip6 input */
- if (PREDICT_TRUE(next0 == GRE_INPUT_NEXT_IP4_INPUT
- || next0 == GRE_INPUT_NEXT_IP6_INPUT
- || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
- || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
- {
- u64 key4, key6[4];
- if (!is_ipv6)
- {
- key4 = ((u64)(ip4_tun_dst0) << 32) | (u64)(ip4_tun_src0);
- }
- else
- {
- key6[0] = ip6_tun_dst0[0];
- key6[1] = ip6_tun_dst0[1];
- key6[2] = ip6_tun_src0[0];
- key6[3] = ip6_tun_src0[1];
- }
-
- if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
- (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
- cached_tunnel_key6[1] != key6[1] &&
- cached_tunnel_key6[2] != key6[2] &&
- cached_tunnel_key6[3] != key6[3]))
- {
- vnet_hw_interface_t * hi;
- gre_tunnel_t * t;
- uword * p;
-
- if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
- else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
-
- if (!p)
- {
- next0 = GRE_INPUT_NEXT_DROP;
- b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
- goto drop;
- }
- t = pool_elt_at_index (gm->tunnels, p[0]);
- hi = vnet_get_hw_interface (gm->vnet_main,
- t->hw_if_index);
- tunnel_sw_if_index = hi->sw_if_index;
-
- cached_tunnel_sw_if_index = tunnel_sw_if_index;
- }
- else
- {
- tunnel_sw_if_index = cached_tunnel_sw_if_index;
- }
- }
- else
- {
- next0 = GRE_INPUT_NEXT_DROP;
- goto drop;
- }
- len = vlib_buffer_length_in_chain (vm, b0);
- vlib_increment_combined_counter (im->combined_sw_if_counters
- + VNET_INTERFACE_COUNTER_RX,
- thread_index,
- tunnel_sw_if_index,
- 1 /* packets */,
- len /* bytes */);
-
- vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
-
-drop:
- if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- gre_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
- tr->tunnel_id = tunnel_sw_if_index;
- if (!is_ipv6)
- {
- tr->length = ip4_0->length;
- tr->src.ip4.as_u32 = ip4_0->src_address.as_u32;
- tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32;
- }
- else
- {
- tr->length = ip6_0->payload_length;
- tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0];
- tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1];
- tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0];
- tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1];
- }
- }
-
- vlib_buffer_advance (b0, sizeof (*h0));
+ node->errors[i0 == SPARSE_VEC_INVALID_INDEX
+ ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE];
+
+ version0 = clib_net_to_host_u16 (h0->flags_and_version);
+ verr0 = version0 & GRE_VERSION_MASK;
+ b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION]
+ : b0->error;
+ next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0;
+
+
+ /* For IP payload we need to find source interface
+ so we can increase counters and help forward node to
+ pick right FIB */
+ /* RPF check for ip4/ip6 input */
+ if (PREDICT_TRUE (next0 == GRE_INPUT_NEXT_IP4_INPUT
+ || next0 == GRE_INPUT_NEXT_IP6_INPUT
+ || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
+ || next0 == GRE_INPUT_NEXT_MPLS_INPUT))
+ {
+ u64 key4, key6[4];
+ if (!is_ipv6)
+ {
+ key4 = ((u64) (ip4_tun_dst0) << 32) | (u64) (ip4_tun_src0);
+ }
+ else
+ {
+ key6[0] = ip6_tun_dst0[0];
+ key6[1] = ip6_tun_dst0[1];
+ key6[2] = ip6_tun_src0[0];
+ key6[3] = ip6_tun_src0[1];
+ }
+
+ if ((!is_ipv6 && cached_tunnel_key4 != key4) ||
+ (is_ipv6 && cached_tunnel_key6[0] != key6[0] &&
+ cached_tunnel_key6[1] != key6[1] &&
+ cached_tunnel_key6[2] != key6[2] &&
+ cached_tunnel_key6[3] != key6[3]))
+ {
+ vnet_hw_interface_t *hi;
+ gre_tunnel_t *t;
+ uword *p;
+
+ if (!is_ipv6)
+ p = hash_get (gm->tunnel_by_key4, key4);
+ else
+ p = hash_get_mem (gm->tunnel_by_key6, key6);
+
+ if (!p)
+ {
+ next0 = GRE_INPUT_NEXT_DROP;
+ b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL];
+ goto drop;
+ }
+ t = pool_elt_at_index (gm->tunnels, p[0]);
+ hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index);
+ tunnel_sw_if_index = hi->sw_if_index;
+
+ cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ }
+ else
+ {
+ tunnel_sw_if_index = cached_tunnel_sw_if_index;
+ }
+ }
+ else
+ {
+ next0 = GRE_INPUT_NEXT_DROP;
+ goto drop;
+ }
+ len = vlib_buffer_length_in_chain (vm, b0);
+ vlib_increment_combined_counter (im->combined_sw_if_counters
+ + VNET_INTERFACE_COUNTER_RX,
+ thread_index,
+ tunnel_sw_if_index,
+ 1 /* packets */ ,
+ len /* bytes */ );
+
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
+
+ drop:
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ gre_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
+ tr->tunnel_id = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ tr->length = ip4_0->length;
+ tr->src.ip4.as_u32 = ip4_0->src_address.as_u32;
+ tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32;
+ }
+ else
+ {
+ tr->length = ip6_0->payload_length;
+ tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0];
+ tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1];
+ tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0];
+ tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1];
+ }
+ }
+
+ vlib_buffer_advance (b0, sizeof (*h0));
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
@@ -540,33 +544,34 @@ drop:
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_node_increment_counter (vm, !is_ipv6 ? gre4_input_node.index : gre6_input_node.index,
- GRE_ERROR_PKTS_DECAP, from_frame->n_vectors);
+ vlib_node_increment_counter (vm,
+ !is_ipv6 ? gre4_input_node.index :
+ gre6_input_node.index, GRE_ERROR_PKTS_DECAP,
+ from_frame->n_vectors);
return from_frame->n_vectors;
}
static uword
gre4_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return gre_input(vm, node, from_frame, /* is_ip6 */ 0);
+ return gre_input (vm, node, from_frame, /* is_ip6 */ 0);
}
static uword
gre6_input (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- vlib_frame_t * from_frame)
+ vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return gre_input(vm, node, from_frame, /* is_ip6 */ 1);
+ return gre_input (vm, node, from_frame, /* is_ip6 */ 1);
}
-static char * gre_error_strings[] = {
+static char *gre_error_strings[] = {
#define gre_error(n,s) s,
#include "error.def"
#undef gre_error
};
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (gre4_input_node) = {
.function = gre4_input,
.name = "gre4-input",
@@ -587,7 +592,9 @@ VLIB_REGISTER_NODE (gre4_input_node) = {
.format_trace = format_gre_rx_trace,
.unformat_buffer = unformat_gre_header,
};
+/* *INDENT-ON* */
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (gre6_input_node) = {
.function = gre6_input,
.name = "gre6-input",
@@ -610,22 +617,21 @@ VLIB_REGISTER_NODE (gre6_input_node) = {
.format_trace = format_gre_rx_trace,
.unformat_buffer = unformat_gre_header,
};
+/* *INDENT-ON* */
VLIB_NODE_FUNCTION_MULTIARCH (gre4_input_node, gre4_input)
VLIB_NODE_FUNCTION_MULTIARCH (gre6_input_node, gre6_input)
-
-void
-gre_register_input_protocol (vlib_main_t * vm,
- gre_protocol_t protocol,
- u32 node_index)
+ void
+ gre_register_input_protocol (vlib_main_t * vm,
+ gre_protocol_t protocol, u32 node_index)
{
- gre_main_t * em = &gre_main;
- gre_protocol_info_t * pi;
- u16 * n;
+ gre_main_t *em = &gre_main;
+ gre_protocol_info_t *pi;
+ u16 *n;
u32 i;
{
- clib_error_t * error = vlib_call_init_function (vm, gre_input_init);
+ clib_error_t *error = vlib_call_init_function (vm, gre_input_init);
if (error)
clib_error_report (error);
}
@@ -634,32 +640,33 @@ gre_register_input_protocol (vlib_main_t * vm,
pi->node_index = node_index;
pi->next_index = vlib_node_add_next (vm, gre4_input_node.index, node_index);
i = vlib_node_add_next (vm, gre6_input_node.index, node_index);
- ASSERT(i == pi->next_index);
+ ASSERT (i == pi->next_index);
/* Setup gre protocol -> next index sparse vector mapping. */
n = sparse_vec_validate (em->next_by_protocol,
- clib_host_to_net_u16 (protocol));
+ clib_host_to_net_u16 (protocol));
n[0] = pi->next_index;
}
static void
gre_setup_node (vlib_main_t * vm, u32 node_index)
{
- vlib_node_t * n = vlib_get_node (vm, node_index);
- pg_node_t * pn = pg_get_node (node_index);
+ vlib_node_t *n = vlib_get_node (vm, node_index);
+ pg_node_t *pn = pg_get_node (node_index);
n->format_buffer = format_gre_header_with_length;
n->unformat_buffer = unformat_gre_header;
pn->unformat_edit = unformat_pg_gre_header;
}
-static clib_error_t * gre_input_init (vlib_main_t * vm)
+static clib_error_t *
+gre_input_init (vlib_main_t * vm)
{
- gre_main_t * gm = &gre_main;
+ gre_main_t *gm = &gre_main;
vlib_node_t *ethernet_input, *ip4_input, *ip6_input, *mpls_unicast_input;
{
- clib_error_t * error;
+ clib_error_t *error;
error = vlib_call_init_function (vm, gre_init);
if (error)
clib_error_report (error);
@@ -669,30 +676,27 @@ static clib_error_t * gre_input_init (vlib_main_t * vm)
gre_setup_node (vm, gre6_input_node.index);
gm->next_by_protocol = sparse_vec_new
- (/* elt bytes */ sizeof (gm->next_by_protocol[0]),
+ ( /* elt bytes */ sizeof (gm->next_by_protocol[0]),
/* bits in index */ BITS (((gre_header_t *) 0)->protocol));
/* These could be moved to the supported protocol input node defn's */
- ethernet_input = vlib_get_node_by_name (vm, (u8 *)"ethernet-input");
- ASSERT(ethernet_input);
- ip4_input = vlib_get_node_by_name (vm, (u8 *)"ip4-input");
- ASSERT(ip4_input);
- ip6_input = vlib_get_node_by_name (vm, (u8 *)"ip6-input");
- ASSERT(ip6_input);
- mpls_unicast_input = vlib_get_node_by_name (vm, (u8 *)"mpls-input");
- ASSERT(mpls_unicast_input);
+ ethernet_input = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
+ ASSERT (ethernet_input);
+ ip4_input = vlib_get_node_by_name (vm, (u8 *) "ip4-input");
+ ASSERT (ip4_input);
+ ip6_input = vlib_get_node_by_name (vm, (u8 *) "ip6-input");
+ ASSERT (ip6_input);
+ mpls_unicast_input = vlib_get_node_by_name (vm, (u8 *) "mpls-input");
+ ASSERT (mpls_unicast_input);
- gre_register_input_protocol (vm, GRE_PROTOCOL_teb,
- ethernet_input->index);
+ gre_register_input_protocol (vm, GRE_PROTOCOL_teb, ethernet_input->index);
- gre_register_input_protocol (vm, GRE_PROTOCOL_ip4,
- ip4_input->index);
+ gre_register_input_protocol (vm, GRE_PROTOCOL_ip4, ip4_input->index);
- gre_register_input_protocol (vm, GRE_PROTOCOL_ip6,
- ip6_input->index);
+ gre_register_input_protocol (vm, GRE_PROTOCOL_ip6, ip6_input->index);
gre_register_input_protocol (vm, GRE_PROTOCOL_mpls_unicast,
- mpls_unicast_input->index);
+ mpls_unicast_input->index);
ip4_register_protocol (IP_PROTOCOL_GRE, gre4_input_node.index);
ip6_register_protocol (IP_PROTOCOL_GRE, gre6_input_node.index);
@@ -701,3 +705,11 @@ static clib_error_t * gre_input_init (vlib_main_t * vm)
}
VLIB_INIT_FUNCTION (gre_input_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/gre/packet.h b/src/vnet/gre/packet.h
index cc2ccda9eff..64b39f2c40b 100644
--- a/src/vnet/gre/packet.h
+++ b/src/vnet/gre/packet.h
@@ -26,13 +26,15 @@ _ (0x0806, arp) \
_ (0x8847, mpls_unicast) \
_ (0x894F, nsh)
-typedef enum {
+typedef enum
+{
#define _(n,f) GRE_PROTOCOL_##f = n,
foreach_gre_protocol
#undef _
} gre_protocol_t;
-typedef struct {
+typedef struct
+{
/* flags and version */
u16 flags_and_version;
/* unimplemented at the moment */
@@ -53,3 +55,11 @@ typedef struct {
} gre_header_t;
#endif /* included_vnet_gre_packet_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/gre/pg.c b/src/vnet/gre/pg.c
index cc065d3b6b5..38a3a07ebad 100644
--- a/src/vnet/gre/pg.c
+++ b/src/vnet/gre/pg.c
@@ -19,7 +19,8 @@
#include <vnet/pg/pg.h>
#include <vnet/gre/gre.h>
-typedef struct {
+typedef struct
+{
pg_edit_t flags_and_version;
pg_edit_t protocol;
} pg_gre_header_t;
@@ -34,10 +35,10 @@ pg_gre_header_init (pg_gre_header_t * e)
uword
unformat_pg_gre_header (unformat_input_t * input, va_list * args)
{
- pg_stream_t * s = va_arg (*args, pg_stream_t *);
- pg_gre_header_t * h;
+ pg_stream_t *s = va_arg (*args, pg_stream_t *);
+ pg_gre_header_t *h;
u32 group_index, error;
-
+
h = pg_create_edit_group (s, sizeof (h[0]), sizeof (gre_header_t),
&group_index);
pg_gre_header_init (h);
@@ -45,15 +46,15 @@ unformat_pg_gre_header (unformat_input_t * input, va_list * args)
pg_edit_set_fixed (&h->flags_and_version, 0);
error = 1;
- if (! unformat (input, "%U",
- unformat_pg_edit,
- unformat_gre_protocol_net_byte_order, &h->protocol))
+ if (!unformat (input, "%U",
+ unformat_pg_edit,
+ unformat_gre_protocol_net_byte_order, &h->protocol))
goto done;
{
- gre_main_t * pm = &gre_main;
- gre_protocol_info_t * pi = 0;
- pg_node_t * pg_node = 0;
+ gre_main_t *pm = &gre_main;
+ gre_protocol_info_t *pi = 0;
+ pg_node_t *pg_node = 0;
if (h->protocol.type == PG_EDIT_FIXED)
{
@@ -69,9 +70,17 @@ unformat_pg_gre_header (unformat_input_t * input, va_list * args)
}
error = 0;
- done:
+done:
if (error)
pg_free_edit_group (s);
return error == 0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */