MAP - add the domain struct directly into the dat-path and avoid the indirectiob throught the map-DPO
Change-Id: Ifb72a1c1258440fdc4845aca8aecf2abd63526b1
Signed-off-by: Neale Ranns <nranns@cisco.com>
diff --git a/src/vnet/map/ip4_map.c b/src/vnet/map/ip4_map.c
index 2be9ad3..1a20d70 100644
--- a/src/vnet/map/ip4_map.c
+++ b/src/vnet/map/ip4_map.c
@@ -293,12 +293,10 @@
p1 = vlib_get_buffer (vm, pi1);
ip40 = vlib_buffer_get_current (p0);
ip41 = vlib_buffer_get_current (p1);
- d0 =
- ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
- &map_domain_index0);
- d1 =
- ip4_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX],
- &map_domain_index1);
+ map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ d0 = ip4_map_get_domain (map_domain_index0);
+ map_domain_index1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
+ d1 = ip4_map_get_domain (map_domain_index1);
ASSERT (d0);
ASSERT (d1);
@@ -464,9 +462,8 @@
p0 = vlib_get_buffer (vm, pi0);
ip40 = vlib_buffer_get_current (p0);
- d0 =
- ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
- &map_domain_index0);
+ map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ d0 = ip4_map_get_domain (map_domain_index0);
ASSERT (d0);
/*
@@ -597,9 +594,8 @@
p0 = vlib_get_buffer (vm, pi0);
ip60 = vlib_buffer_get_current (p0);
ip40 = (ip4_header_t *) (ip60 + 1);
- d0 =
- ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
- &map_domain_index0);
+ map_domain_index0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ d0 = ip4_map_get_domain (map_domain_index0);
map_ip4_reass_lock ();
map_ip4_reass_t *r = map_ip4_reass_get (ip40->src_address.as_u32,
diff --git a/src/vnet/map/ip4_map_t.c b/src/vnet/map/ip4_map_t.c
index 15974d8..b63d76b 100644
--- a/src/vnet/map/ip4_map_t.c
+++ b/src/vnet/map/ip4_map_t.c
@@ -1100,10 +1100,12 @@
next1 = IP4_MAPT_NEXT_DROP;
}
- d0 = ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
- &vnet_buffer (p0)->map_t.map_domain_index);
- d1 = ip4_map_get_domain (vnet_buffer (p1)->ip.adj_index[VLIB_TX],
- &vnet_buffer (p1)->map_t.map_domain_index);
+ vnet_buffer (p0)->map_t.map_domain_index =
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ d0 = ip4_map_get_domain (vnet_buffer (p0)->map_t.map_domain_index);
+ vnet_buffer (p1)->map_t.map_domain_index =
+ vnet_buffer (p1)->ip.adj_index[VLIB_TX];
+ d1 = ip4_map_get_domain (vnet_buffer (p1)->map_t.map_domain_index);
vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
vnet_buffer (p1)->map_t.mtu = d1->mtu ? d1->mtu : ~0;
@@ -1213,8 +1215,9 @@
next0 = IP4_MAPT_NEXT_DROP;
}
- d0 = ip4_map_get_domain (vnet_buffer (p0)->ip.adj_index[VLIB_TX],
- &vnet_buffer (p0)->map_t.map_domain_index);
+ vnet_buffer (p0)->map_t.map_domain_index =
+ vnet_buffer (p0)->ip.adj_index[VLIB_TX];
+ d0 = ip4_map_get_domain (vnet_buffer (p0)->map_t.map_domain_index);
vnet_buffer (p0)->map_t.mtu = d0->mtu ? d0->mtu : ~0;
diff --git a/src/vnet/map/map.c b/src/vnet/map/map.c
index 99305af..811a0ab 100644
--- a/src/vnet/map/map.c
+++ b/src/vnet/map/map.c
@@ -177,7 +177,6 @@
map_main_t *mm = &map_main;
dpo_id_t dpo_v4 = DPO_INVALID;
dpo_id_t dpo_v6 = DPO_INVALID;
- fib_node_index_t fei;
map_domain_t *d;
/* Sanity check on the src prefix length */
@@ -268,57 +267,28 @@
dpo_reset (&dpo_v4);
/*
- * Multiple MAP domains may share same source IPv6 TEP.
- * In this case the route will exist and be MAP sourced.
- * Find the adj (if any) already contributed and modify it
+ * construct a DPO to use the v6 domain
*/
- fib_prefix_t pfx6 = {
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_len = d->ip6_src_len,
- .fp_addr = {
- .ip6 = d->ip6_src,
- }
- ,
- };
- fei = fib_table_lookup_exact_match (0, &pfx6);
-
- if (FIB_NODE_INDEX_INVALID != fei)
- {
- dpo_id_t dpo = DPO_INVALID;
-
- if (fib_entry_get_dpo_for_source (fei, FIB_SOURCE_MAP, &dpo))
- {
- /*
- * modify the existing MAP to indicate it's shared
- * skip to route add.
- */
- const dpo_id_t *md_dpo;
- map_dpo_t *md;
-
- ASSERT (DPO_LOAD_BALANCE == dpo.dpoi_type);
-
- md_dpo = load_balance_get_bucket (dpo.dpoi_index, 0);
- md = map_dpo_get (md_dpo->dpoi_index);
-
- md->md_domain = ~0;
- dpo_copy (&dpo_v6, md_dpo);
- dpo_reset (&dpo);
-
- goto route_add;
- }
- }
-
if (d->flags & MAP_DOMAIN_TRANSLATION)
map_t_dpo_create (DPO_PROTO_IP6, *map_domain_index, &dpo_v6);
else
map_dpo_create (DPO_PROTO_IP6, *map_domain_index, &dpo_v6);
-route_add:
/*
+ * Multiple MAP domains may share same source IPv6 TEP. Which is just dandy.
+ * We are not tracking the sharing. So a v4 lookup to find the correct
+ * domain post decap/trnaslate is always done
+ *
* Create ip6 route. This is a reference counted add. If the prefix
* already exists and is MAP sourced, it is now MAP source n+1 times
* and will need to be removed n+1 times.
*/
+ fib_prefix_t pfx6 = {
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_len = d->ip6_src_len,
+ .fp_addr.ip6 = d->ip6_src,
+ };
+
fib_table_entry_special_dpo_add (0, &pfx6,
FIB_SOURCE_MAP,
FIB_ENTRY_FLAG_EXCLUSIVE, &dpo_v6);
diff --git a/src/vnet/map/map.h b/src/vnet/map/map.h
index 616d42c..644e80f 100644
--- a/src/vnet/map/map.h
+++ b/src/vnet/map/map.h
@@ -416,17 +416,11 @@
* Get the MAP domain from an IPv4 lookup adjacency.
*/
static_always_inline map_domain_t *
-ip4_map_get_domain (u32 mdi,
- u32 *map_domain_index)
+ip4_map_get_domain (u32 mdi)
{
map_main_t *mm = &map_main;
- map_dpo_t *md;
- md = map_dpo_get(mdi);
-
- ASSERT(md);
- *map_domain_index = md->md_domain;
- return pool_elt_at_index(mm->domains, *map_domain_index);
+ return pool_elt_at_index(mm->domains, mdi);
}
/*
@@ -435,23 +429,21 @@
* The IPv4 address is used otherwise.
*/
static_always_inline map_domain_t *
-ip6_map_get_domain (u32 mdi, ip4_address_t *addr,
- u32 *map_domain_index, u8 *error)
+ip6_map_get_domain (u32 mdi,
+ ip4_address_t *addr,
+ u32 *map_domain_index,
+ u8 *error)
{
map_main_t *mm = &map_main;
- map_dpo_t *md;
/*
* Disable direct MAP domain lookup on decap, until the security check is updated to verify IPv4 SA.
* (That's done implicitly when MAP domain is looked up in the IPv4 FIB)
*/
#ifdef MAP_NONSHARED_DOMAIN_ENABLED
- md = map_dpo_get(mdi);
-
- ASSERT(md);
- *map_domain_index = md->md_domain;
- if (*map_domain_index != ~0)
- return pool_elt_at_index(mm->domains, *map_domain_index);
+#error "How can you be sure this domain is not shared?"
+ *map_domain_index = mdi;
+ return pool_elt_at_index(mm->domains, mdi);
#endif
u32 lbi = ip4_fib_forwarding_lookup(0, addr);
@@ -459,8 +451,7 @@
if (PREDICT_TRUE(dpo->dpoi_type == map_dpo_type ||
dpo->dpoi_type == map_t_dpo_type))
{
- md = map_dpo_get(dpo->dpoi_index);
- *map_domain_index = md->md_domain;
+ *map_domain_index = dpo->dpoi_index;
return pool_elt_at_index(mm->domains, *map_domain_index);
}
*error = MAP_ERROR_NO_DOMAIN;
diff --git a/src/vnet/map/map_dpo.c b/src/vnet/map/map_dpo.c
index df2b5fa..430c1fb 100644
--- a/src/vnet/map/map_dpo.c
+++ b/src/vnet/map/map_dpo.c
@@ -17,48 +17,20 @@
#include <vnet/map/map_dpo.h>
/**
- * pool of all MPLS Label DPOs
- */
-map_dpo_t *map_dpo_pool;
-
-/**
* The register MAP DPO type
*/
dpo_type_t map_dpo_type;
dpo_type_t map_t_dpo_type;
-static map_dpo_t *
-map_dpo_alloc (void)
-{
- map_dpo_t *md;
-
- pool_get_aligned(map_dpo_pool, md, CLIB_CACHE_LINE_BYTES);
- memset(md, 0, sizeof(*md));
-
- return (md);
-}
-
-static index_t
-map_dpo_get_index (map_dpo_t *md)
-{
- return (md - map_dpo_pool);
-}
-
void
map_dpo_create (dpo_proto_t dproto,
u32 domain_index,
dpo_id_t *dpo)
{
- map_dpo_t *md;
-
- md = map_dpo_alloc();
- md->md_domain = domain_index;
- md->md_proto = dproto;
-
dpo_set(dpo,
map_dpo_type,
dproto,
- map_dpo_get_index(md));
+ domain_index);
}
void
@@ -66,16 +38,10 @@
u32 domain_index,
dpo_id_t *dpo)
{
- map_dpo_t *md;
-
- md = map_dpo_alloc();
- md->md_domain = domain_index;
- md->md_proto = dproto;
-
dpo_set(dpo,
map_t_dpo_type,
dproto,
- map_dpo_get_index(md));
+ domain_index);
}
@@ -84,14 +50,8 @@
{
index_t index = va_arg (*args, index_t);
CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
- map_dpo_t *md;
- md = map_dpo_get(index);
-
- return (format(s, "map:[%d]:%U domain:%d",
- index,
- format_dpo_proto, md->md_proto,
- md->md_domain));
+ return (format(s, "map: domain:%d", index));
}
u8*
@@ -99,40 +59,19 @@
{
index_t index = va_arg (*args, index_t);
CLIB_UNUSED(u32 indent) = va_arg (*args, u32);
- map_dpo_t *md;
- md = map_dpo_get(index);
-
- return (format(s, "map-t:[%d]:%U domain:%d",
- index,
- format_dpo_proto, md->md_proto,
- md->md_domain));
+ return (format(s, "map-t: domain:%d", index));
}
static void
map_dpo_lock (dpo_id_t *dpo)
{
- map_dpo_t *md;
-
- md = map_dpo_get(dpo->dpoi_index);
-
- md->md_locks++;
}
static void
map_dpo_unlock (dpo_id_t *dpo)
{
- map_dpo_t *md;
-
- md = map_dpo_get(dpo->dpoi_index);
-
- md->md_locks--;
-
- if (0 == md->md_locks)
- {
- pool_put(map_dpo_pool, md);
- }
}
const static dpo_vft_t md_vft = {
diff --git a/src/vnet/map/map_dpo.h b/src/vnet/map/map_dpo.h
index be510db..63bf478 100644
--- a/src/vnet/map/map_dpo.h
+++ b/src/vnet/map/map_dpo.h
@@ -22,23 +22,6 @@
/**
* A representation of a MAP DPO
*/
-typedef struct map_dpo_t
-{
- /**
- * The dat-plane protocol
- */
- dpo_proto_t md_proto;
-
- /**
- * the MAP domain index
- */
- u32 md_domain;
-
- /**
- * Number of locks/users of the label
- */
- u16 md_locks;
-} map_dpo_t;
extern void map_dpo_create (dpo_proto_t dproto,
u32 domain_index,
@@ -52,16 +35,9 @@
/*
* Encapsulation violation for fast data-path access
*/
-extern map_dpo_t *map_dpo_pool;
extern dpo_type_t map_dpo_type;
extern dpo_type_t map_t_dpo_type;
-static inline map_dpo_t *
-map_dpo_get (index_t index)
-{
- return (pool_elt_at_index(map_dpo_pool, index));
-}
-
extern void map_dpo_module_init(void);
#endif