aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/gre/node.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-12-14 08:51:32 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2017-12-16 19:39:26 +0000
commit33ce60d6759bbbfebb7d489aa591b696e140d870 (patch)
treeeda75c292952f754813648b5a49d0ca5f17a69f3 /src/vnet/gre/node.c
parent8e66b9bf4ba90279631e6a0e8ccc2eab5f9156c2 (diff)
GRE tunnel key includes the FIB table
- GRE tunnels with the same src,dst addresses are not the same tunnel - Two data-plane improvements: - the cached key was never updated and so useless - no need to dereference the tunnel's HW interface to get the sw_if_index Change-Id: I2f2ea6e08c759a810b753cec22c497e921a2ca01 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/gre/node.c')
-rw-r--r--src/vnet/gre/node.c174
1 files changed, 87 insertions, 87 deletions
diff --git a/src/vnet/gre/node.c b/src/vnet/gre/node.c
index 1a5fc87b116..7223b017df7 100644
--- a/src/vnet/gre/node.c
+++ b/src/vnet/gre/node.c
@@ -73,18 +73,20 @@ gre_input (vlib_main_t * vm,
{
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;
+ gre_tunnel_key_t cached_tunnel_key;
+
+ u32 cached_tunnel_sw_if_index = ~0, tunnel_sw_if_index = ~0;
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_key.gtk_v4, 0xff,
+ sizeof (cached_tunnel_key.gtk_v4));
else
- memset (&cached_tunnel_key6, 0xff, sizeof (cached_tunnel_key6));
+ memset (&cached_tunnel_key.gtk_v6, 0xff,
+ sizeof (cached_tunnel_key.gtk_v6));
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
@@ -107,10 +109,7 @@ gre_input (vlib_main_t * vm,
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];
+ gre_tunnel_key_t key0, key1;
/* Prefetch next iteration. */
{
@@ -143,11 +142,6 @@ gre_input (vlib_main_t * vm,
/* 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));
@@ -157,15 +151,6 @@ gre_input (vlib_main_t * vm,
/* 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));
@@ -210,34 +195,35 @@ gre_input (vlib_main_t * vm,
|| next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
|| next0 == GRE_INPUT_NEXT_MPLS_INPUT))
{
-
- u64 key4, key6[4];
- if (!is_ipv6)
+ if (is_ipv6)
{
- key4 = ((u64) (ip4_tun_dst0) << 32) | (u64) (ip4_tun_src0);
+ gre_mk_key6 (&ip6_0->dst_address,
+ &ip6_0->src_address,
+ vnet_buffer (b0)->ip.fib_index, &key0.gtk_v6);
}
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];
+ gre_mk_key4 (&ip4_0->dst_address,
+ &ip4_0->src_address,
+ vnet_buffer (b0)->ip.fib_index, &key0.gtk_v4);
}
- 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]))
+ if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4,
+ &key0.gtk_v4)) ||
+ (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6,
+ &key0.gtk_v6)))
{
- vnet_hw_interface_t *hi;
gre_tunnel_t *t;
uword *p;
if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
+ {
+ p = hash_get_mem (gm->tunnel_by_key4, &key0.gtk_v4);
+ }
else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
+ {
+ p = hash_get_mem (gm->tunnel_by_key6, &key0.gtk_v6);
+ }
if (!p)
{
next0 = GRE_INPUT_NEXT_DROP;
@@ -245,10 +231,17 @@ gre_input (vlib_main_t * vm,
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;
+ tunnel_sw_if_index = t->sw_if_index;
cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ cached_tunnel_key.gtk_v4 = key0.gtk_v4;
+ }
+ else
+ {
+ cached_tunnel_key.gtk_v6 = key0.gtk_v6;
+ }
}
else
{
@@ -276,34 +269,35 @@ gre_input (vlib_main_t * vm,
|| next1 == GRE_INPUT_NEXT_ETHERNET_INPUT
|| next1 == GRE_INPUT_NEXT_MPLS_INPUT))
{
- u64 key4, key6[4];
- if (!is_ipv6)
+ if (is_ipv6)
{
- key4 = ((u64) (ip4_tun_dst1) << 32) | (u64) (ip4_tun_src1);
+ gre_mk_key6 (&ip6_1->dst_address,
+ &ip6_1->src_address,
+ vnet_buffer (b1)->ip.fib_index, &key1.gtk_v6);
}
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];
+ gre_mk_key4 (&ip4_1->dst_address,
+ &ip4_1->src_address,
+ vnet_buffer (b1)->ip.fib_index, &key1.gtk_v4);
}
- 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]))
+ if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4,
+ &key1.gtk_v4)) ||
+ (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6,
+ &key1.gtk_v6)))
{
- vnet_hw_interface_t *hi;
gre_tunnel_t *t;
uword *p;
if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
+ {
+ p = hash_get_mem (gm->tunnel_by_key4, &key1.gtk_v4);
+ }
else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
-
+ {
+ p = hash_get_mem (gm->tunnel_by_key6, &key1.gtk_v6);
+ }
if (!p)
{
next1 = GRE_INPUT_NEXT_DROP;
@@ -311,10 +305,17 @@ gre_input (vlib_main_t * vm,
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;
+ tunnel_sw_if_index = t->sw_if_index;
cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ cached_tunnel_key.gtk_v4 = key1.gtk_v4;
+ }
+ else
+ {
+ cached_tunnel_key.gtk_v6 = key1.gtk_v6;
+ }
}
else
{
@@ -397,8 +398,7 @@ gre_input (vlib_main_t * vm,
u16 version0;
int verr0;
u32 i0, next0;
- u32 ip4_tun_src0, ip4_tun_dst0;
- u64 ip6_tun_src0[2], ip6_tun_dst0[2];
+ gre_tunnel_key_t key0;
bi0 = from[0];
to_next[0] = bi0;
@@ -413,18 +413,10 @@ gre_input (vlib_main_t * vm,
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));
}
@@ -453,34 +445,35 @@ gre_input (vlib_main_t * vm,
|| next0 == GRE_INPUT_NEXT_ETHERNET_INPUT
|| next0 == GRE_INPUT_NEXT_MPLS_INPUT))
{
- u64 key4, key6[4];
- if (!is_ipv6)
+ if (is_ipv6)
{
- key4 = ((u64) (ip4_tun_dst0) << 32) | (u64) (ip4_tun_src0);
+ gre_mk_key6 (&ip6_0->dst_address,
+ &ip6_0->src_address,
+ vnet_buffer (b0)->ip.fib_index, &key0.gtk_v6);
}
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];
+ gre_mk_key4 (&ip4_0->dst_address,
+ &ip4_0->src_address,
+ vnet_buffer (b0)->ip.fib_index, &key0.gtk_v4);
}
- 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]))
+ if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4,
+ &key0.gtk_v4)) ||
+ (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6,
+ &key0.gtk_v6)))
{
- vnet_hw_interface_t *hi;
gre_tunnel_t *t;
uword *p;
if (!is_ipv6)
- p = hash_get (gm->tunnel_by_key4, key4);
+ {
+ p = hash_get_mem (gm->tunnel_by_key4, &key0.gtk_v4);
+ }
else
- p = hash_get_mem (gm->tunnel_by_key6, key6);
-
+ {
+ p = hash_get_mem (gm->tunnel_by_key6, &key0.gtk_v6);
+ }
if (!p)
{
next0 = GRE_INPUT_NEXT_DROP;
@@ -488,10 +481,17 @@ gre_input (vlib_main_t * vm,
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;
+ tunnel_sw_if_index = t->sw_if_index;
cached_tunnel_sw_if_index = tunnel_sw_if_index;
+ if (!is_ipv6)
+ {
+ cached_tunnel_key.gtk_v4 = key0.gtk_v4;
+ }
+ else
+ {
+ cached_tunnel_key.gtk_v6 = key0.gtk_v6;
+ }
}
else
{