aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Hotham <david.hotham@metaswitch.com>2016-09-19 09:55:07 -0700
committerJohn Lo <loj@cisco.com>2016-09-19 19:01:59 +0000
commita8cd30937e5dc8a3bf629e1ee667550e267e5651 (patch)
treeafdc2648efdb29bf6e0dde24aa581041c88b46cf
parent16b7aaafac0bd06a9c330457eea9f6f674906606 (diff)
Add support for transparent ethernet bridging to GRE
Change-Id: Iaa3cefe223eb48b128893029a17e092b72a5157c Signed-off-by: David Hotham <david.hotham@metaswitch.com>
-rw-r--r--vnet/vnet/ethernet/node.c3
-rw-r--r--vnet/vnet/gre/gre.c45
-rw-r--r--vnet/vnet/gre/gre.h2
-rw-r--r--vnet/vnet/gre/interface.c38
-rw-r--r--vnet/vnet/gre/node.c28
-rw-r--r--vnet/vnet/gre/packet.h1
-rw-r--r--vpp-api-test/vat/api_format.c17
-rw-r--r--vpp/vpp-api/api.c2
-rw-r--r--vpp/vpp-api/custom_dump.c3
-rw-r--r--vpp/vpp-api/vpe.api2
10 files changed, 109 insertions, 32 deletions
diff --git a/vnet/vnet/ethernet/node.c b/vnet/vnet/ethernet/node.c
index 74d4f476d7a..a8a4fcd074d 100644
--- a/vnet/vnet/ethernet/node.c
+++ b/vnet/vnet/ethernet/node.c
@@ -238,7 +238,8 @@ determine_next_node (ethernet_main_t * em,
{
*next0 = em->l2_next;
// record the L2 len and reset the buffer so the L2 header is preserved
- vnet_buffer (b0)->l2.l2_len = b0->current_data;
+ u32 eth_start = vnet_buffer (b0)->ethernet.start_of_ethernet_header;
+ vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start;
vlib_buffer_advance (b0, -ethernet_buffer_header_size (b0));
// check for common IP/MPLS ethertypes
diff --git a/vnet/vnet/gre/gre.c b/vnet/vnet/gre/gre.c
index 6d375159818..f00977c8cd6 100644
--- a/vnet/vnet/gre/gre.c
+++ b/vnet/vnet/gre/gre.c
@@ -283,17 +283,25 @@ gre_interface_tx (vlib_main_t * vm,
vnet_buffer (b0)->sw_if_index[VLIB_TX] = t->outer_fib_index;
vnet_buffer (b1)->sw_if_index[VLIB_TX] = t->outer_fib_index;
- ip0 = vlib_buffer_get_current (b0);
- gre_protocol0 = clib_net_to_host_u16 (0x800);
- gre_protocol0 =
- ((ip0->ip_version_and_header_length & 0xF0) == 0x60) ?
- 0x86DD : gre_protocol0;
-
- ip1 = vlib_buffer_get_current (b1);
- gre_protocol1 = clib_net_to_host_u16 (0x800);
- gre_protocol1 =
- ((ip1->ip_version_and_header_length & 0xF0) == 0x60) ?
- 0x86DD : gre_protocol1;
+ if (PREDICT_FALSE(t->teb))
+ {
+ gre_protocol0 = clib_net_to_host_u16(GRE_PROTOCOL_teb);
+ gre_protocol1 = clib_net_to_host_u16(GRE_PROTOCOL_teb);
+ }
+ else
+ {
+ ip0 = vlib_buffer_get_current (b0);
+ gre_protocol0 = clib_net_to_host_u16 (0x800);
+ gre_protocol0 =
+ ((ip0->ip_version_and_header_length & 0xF0) == 0x60) ?
+ 0x86DD : gre_protocol0;
+
+ ip1 = vlib_buffer_get_current (b1);
+ gre_protocol1 = clib_net_to_host_u16 (0x800);
+ gre_protocol1 =
+ ((ip1->ip_version_and_header_length & 0xF0) == 0x60) ?
+ 0x86DD : gre_protocol1;
+ }
vlib_buffer_advance (b0, -sizeof(*h0));
vlib_buffer_advance (b1, -sizeof(*h1));
@@ -366,10 +374,17 @@ gre_interface_tx (vlib_main_t * vm,
vnet_buffer (b0)->sw_if_index[VLIB_TX] = t->outer_fib_index;
ip0 = vlib_buffer_get_current (b0);
- gre_protocol0 = clib_net_to_host_u16 (0x800);
- gre_protocol0 =
- ((ip0->ip_version_and_header_length & 0xF0) == 0x60) ?
- 0x86DD : gre_protocol0;
+ if (PREDICT_FALSE(t->teb))
+ {
+ gre_protocol0 = clib_net_to_host_u16(GRE_PROTOCOL_teb);
+ }
+ else
+ {
+ gre_protocol0 = clib_net_to_host_u16 (0x800);
+ gre_protocol0 =
+ ((ip0->ip_version_and_header_length & 0xF0) == 0x60) ?
+ 0x86DD : gre_protocol0;
+ }
vlib_buffer_advance (b0, -sizeof(*h0));
diff --git a/vnet/vnet/gre/gre.h b/vnet/vnet/gre/gre.h
index d875be990c6..ad599d2f09e 100644
--- a/vnet/vnet/gre/gre.h
+++ b/vnet/vnet/gre/gre.h
@@ -55,6 +55,7 @@ typedef struct {
u32 outer_fib_index;
u32 hw_if_index;
u32 sw_if_index;
+ u8 teb;
} gre_tunnel_t;
typedef struct {
@@ -127,6 +128,7 @@ typedef struct {
ip4_address_t src, dst;
u32 outer_fib_id;
+ u8 teb;
} vnet_gre_add_del_tunnel_args_t;
int vnet_gre_add_del_tunnel
diff --git a/vnet/vnet/gre/interface.c b/vnet/vnet/gre/interface.c
index 03591e1ff41..864c384b992 100644
--- a/vnet/vnet/gre/interface.c
+++ b/vnet/vnet/gre/interface.c
@@ -26,10 +26,11 @@ u8 * format_gre_tunnel (u8 * s, va_list * args)
gre_main_t * gm = &gre_main;
s = format (s,
- "[%d] %U (src) %U (dst) outer_fib_index %d",
+ "[%d] %U (src) %U (dst) payload %s outer_fib_index %d",
t - gm->tunnels,
format_ip4_address, &t->tunnel_src,
format_ip4_address, &t->tunnel_dst,
+ (t->teb ? "teb" : "ip"),
t->outer_fib_index);
return s;
}
@@ -47,6 +48,8 @@ int vnet_gre_add_del_tunnel
u32 outer_fib_index;
uword * p;
u64 key;
+ u8 address[6];
+ clib_error_t *error;
key = (u64)a->src.as_u32 << 32 | (u64)a->dst.as_u32;
p = hash_get (gm->tunnel_by_key, key);
@@ -87,12 +90,34 @@ int vnet_gre_add_del_tunnel
(&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
vnet_interface_counter_unlock(im);
} else {
+ if (a->teb)
+ {
+ /* 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_class.index, t - gm->tunnels, address, &hw_if_index,
+ 0);
+
+ if (error)
+ {
+ clib_error_report (error);
+ return VNET_API_ERROR_INVALID_REGISTRATION;
+ }
+ } 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;
+ }
+ hi = vnet_get_hw_interface (vnm, hw_if_index);
+ sw_if_index = hi->sw_if_index;
}
t->hw_if_index = hw_if_index;
@@ -112,6 +137,7 @@ int vnet_gre_add_del_tunnel
/* Standard default gre MTU. */
hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] = 9000;
+ t->teb = a->teb;
clib_memcpy (&t->tunnel_src, &a->src, sizeof (t->tunnel_src));
clib_memcpy (&t->tunnel_dst, &a->dst, sizeof (t->tunnel_dst));
@@ -156,6 +182,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
vnet_gre_add_del_tunnel_args_t _a, * a = &_a;
ip4_address_t src, dst;
u32 outer_fib_id = 0;
+ u8 teb = 0;
int rv;
u32 num_m_args = 0;
u8 is_add = 1;
@@ -174,6 +201,8 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
num_m_args++;
else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
;
+ else if (unformat (line_input, "teb"))
+ teb = 1;
else
return clib_error_return (0, "unknown input `%U'",
format_unformat_error, input);
@@ -189,6 +218,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
memset (a, 0, sizeof (*a));
a->is_add = is_add;
a->outer_fib_id = outer_fib_id;
+ a->teb = teb;
clib_memcpy(&a->src, &src, sizeof(src));
clib_memcpy(&a->dst, &dst, sizeof(dst));
@@ -214,7 +244,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm,
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>] [del]",
+ "[outer-fib-id <fib>] [teb] [del]",
.function = create_gre_tunnel_command_fn,
};
diff --git a/vnet/vnet/gre/node.c b/vnet/vnet/gre/node.c
index 97f9dac2e2b..d5ea4b65ddb 100644
--- a/vnet/vnet/gre/node.c
+++ b/vnet/vnet/gre/node.c
@@ -23,6 +23,7 @@
#define foreach_gre_input_next \
_(PUNT, "error-punt") \
_(DROP, "error-drop") \
+_(ETHERNET_INPUT, "ethernet-input") \
_(IP4_INPUT, "ip4-input") \
_(IP6_INPUT, "ip6-input")
@@ -160,9 +161,11 @@ gre_input (vlib_main_t * vm,
: b1->error;
next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1;
+
/* RPF check for ip4/ip6 input */
- if (PREDICT_FALSE(next0 == GRE_INPUT_NEXT_IP4_INPUT
- || next0 == GRE_INPUT_NEXT_IP6_INPUT))
+ if (PREDICT_FALSE(next0 == GRE_INPUT_NEXT_IP4_INPUT
+ || next0 == GRE_INPUT_NEXT_IP6_INPUT
+ || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT))
{
u64 key = ((u64)(vnet_buffer(b0)->gre.dst) << 32) |
(u64)(vnet_buffer(b0)->gre.src);
@@ -207,11 +210,13 @@ gre_input (vlib_main_t * vm,
len /* bytes */);
vnet_buffer(b0)->sw_if_index[VLIB_TX] = tunnel_fib_index;
+ vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
}
drop0:
- if (PREDICT_FALSE(next1 == GRE_INPUT_NEXT_IP4_INPUT
- || next1 == GRE_INPUT_NEXT_IP6_INPUT))
+ if (PREDICT_FALSE(next1 == GRE_INPUT_NEXT_IP4_INPUT
+ || next1 == GRE_INPUT_NEXT_IP6_INPUT
+ || next1 == GRE_INPUT_NEXT_ETHERNET_INPUT))
{
u64 key = ((u64)(vnet_buffer(b1)->gre.dst) << 32) |
(u64)(vnet_buffer(b1)->gre.src);
@@ -256,6 +261,7 @@ drop0:
len /* bytes */);
vnet_buffer(b1)->sw_if_index[VLIB_TX] = tunnel_fib_index;
+ vnet_buffer(b1)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
}
drop1:
if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
@@ -326,11 +332,13 @@ drop1:
: 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 */
- if (PREDICT_FALSE(next0 == GRE_INPUT_NEXT_IP4_INPUT
- || next0 == GRE_INPUT_NEXT_IP6_INPUT))
+ if (PREDICT_FALSE(next0 == GRE_INPUT_NEXT_IP4_INPUT
+ || next0 == GRE_INPUT_NEXT_IP6_INPUT
+ || next0 == GRE_INPUT_NEXT_ETHERNET_INPUT))
{
u64 key = ((u64)(vnet_buffer(b0)->gre.dst) << 32) |
(u64)(vnet_buffer(b0)->gre.src);
@@ -375,6 +383,7 @@ drop1:
len /* bytes */);
vnet_buffer(b0)->sw_if_index[VLIB_TX] = tunnel_fib_index;
+ vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index;
}
drop:
@@ -476,7 +485,7 @@ gre_setup_node (vlib_main_t * vm, u32 node_index)
static clib_error_t * gre_input_init (vlib_main_t * vm)
{
gre_input_runtime_t * rt;
- vlib_node_t *ip4_input, *ip6_input, *mpls_unicast_input;
+ vlib_node_t *ethernet_input, *ip4_input, *ip6_input, *mpls_unicast_input;
{
clib_error_t * error;
@@ -494,6 +503,8 @@ static clib_error_t * gre_input_init (vlib_main_t * vm)
/* 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");
@@ -501,6 +512,9 @@ static clib_error_t * gre_input_init (vlib_main_t * vm)
mpls_unicast_input = vlib_get_node_by_name (vm, (u8 *)"mpls-gre-input");
ASSERT(mpls_unicast_input);
+ gre_register_input_protocol (vm, GRE_PROTOCOL_teb,
+ ethernet_input->index);
+
gre_register_input_protocol (vm, GRE_PROTOCOL_ip4,
ip4_input->index);
diff --git a/vnet/vnet/gre/packet.h b/vnet/vnet/gre/packet.h
index 573f2624bf8..cc2ccda9eff 100644
--- a/vnet/vnet/gre/packet.h
+++ b/vnet/vnet/gre/packet.h
@@ -21,6 +21,7 @@
#define foreach_gre_protocol \
_ (0x0800, ip4) \
_ (0x86DD, ip6) \
+_ (0x6558, teb) \
_ (0x0806, arp) \
_ (0x8847, mpls_unicast) \
_ (0x894F, nsh)
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index e29b47e3862..1fbe9244909 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -9446,6 +9446,7 @@ api_gre_add_del_tunnel (vat_main_t * vam)
f64 timeout;
ip4_address_t src4, dst4;
u8 is_add = 1;
+ u8 teb = 0;
u8 src_set = 0;
u8 dst_set = 0;
u32 outer_fib_id = 0;
@@ -9460,6 +9461,8 @@ api_gre_add_del_tunnel (vat_main_t * vam)
dst_set = 1;
else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
;
+ else if (unformat (line_input, "teb"))
+ teb = 1;
else
{
errmsg ("parse error '%U'\n", format_unformat_error, line_input);
@@ -9485,6 +9488,7 @@ api_gre_add_del_tunnel (vat_main_t * vam)
clib_memcpy (&mp->dst_address, &dst4, sizeof (dst4));
mp->outer_fib_id = ntohl (outer_fib_id);
mp->is_add = is_add;
+ mp->teb = teb;
S;
W;
@@ -9497,10 +9501,11 @@ static void vl_api_gre_tunnel_details_t_handler
{
vat_main_t *vam = &vat_main;
- fformat (vam->ofp, "%11d%15U%15U%14d\n",
+ fformat (vam->ofp, "%11d%15U%15U%6d%14d\n",
ntohl (mp->sw_if_index),
format_ip4_address, &mp->src_address,
- format_ip4_address, &mp->dst_address, ntohl (mp->outer_fib_id));
+ format_ip4_address, &mp->dst_address,
+ mp->teb, ntohl (mp->outer_fib_id));
}
static void vl_api_gre_tunnel_details_t_handler_json
@@ -9523,6 +9528,7 @@ static void vl_api_gre_tunnel_details_t_handler_json
vat_json_object_add_ip4 (node, "src_address", ip4);
clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
vat_json_object_add_ip4 (node, "dst_address", ip4);
+ vat_json_object_add_uint (node, "teb", mp->teb);
vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
}
@@ -9551,8 +9557,9 @@ api_gre_tunnel_dump (vat_main_t * vam)
if (!vam->json_output)
{
- fformat (vam->ofp, "%11s%15s%15s%14s\n",
- "sw_if_index", "src_address", "dst_address", "outer_fib_id");
+ fformat (vam->ofp, "%11s%15s%15s%6s%14s\n",
+ "sw_if_index", "src_address", "dst_address", "teb",
+ "outer_fib_id");
}
/* Get list of gre-tunnel interfaces */
@@ -15281,7 +15288,7 @@ _(vxlan_add_del_tunnel, \
" [decap-next l2|ip4|ip6] [del]") \
_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
_(gre_add_del_tunnel, \
- "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
+ "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [teb] [del]\n") \
_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
_(l2_fib_clear_table, "") \
_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c
index c1da5aa93cf..62dd000f5f9 100644
--- a/vpp/vpp-api/api.c
+++ b/vpp/vpp-api/api.c
@@ -4989,6 +4989,7 @@ static void vl_api_gre_add_del_tunnel_t_handler
memset (a, 0, sizeof (*a));
a->is_add = mp->is_add;
+ a->teb = mp->teb;
/* ip addresses sent in network byte order */
clib_memcpy (&(a->src), mp->src_address, 4);
@@ -5018,6 +5019,7 @@ static void send_gre_tunnel_details
clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].table_id);
+ rmp->teb = t->teb;
rmp->sw_if_index = htonl (t->sw_if_index);
rmp->context = context;
diff --git a/vpp/vpp-api/custom_dump.c b/vpp/vpp-api/custom_dump.c
index a92e6803198..cc37368de10 100644
--- a/vpp/vpp-api/custom_dump.c
+++ b/vpp/vpp-api/custom_dump.c
@@ -1446,6 +1446,9 @@ static void *vl_api_gre_add_del_tunnel_t_print
(ip46_address_t *) & (mp->src_address),
mp->is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4);
+ if (mp->teb)
+ s = format (s, "teb ");
+
if (mp->outer_fib_id)
s = format (s, "outer-fib-id %d ", ntohl (mp->outer_fib_id));
diff --git a/vpp/vpp-api/vpe.api b/vpp/vpp-api/vpe.api
index ae4c12d4569..2434517e8cc 100644
--- a/vpp/vpp-api/vpe.api
+++ b/vpp/vpp-api/vpe.api
@@ -2013,6 +2013,7 @@ define gre_add_del_tunnel
u32 context;
u8 is_add;
u8 is_ipv6;
+ u8 teb;
u8 src_address[16];
u8 dst_address[16];
u32 outer_fib_id;
@@ -2037,6 +2038,7 @@ define gre_tunnel_details
u32 context;
u32 sw_if_index;
u8 is_ipv6;
+ u8 teb;
u8 src_address[16];
u8 dst_address[16];
u32 outer_fib_id;