aboutsummaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2016-08-25 00:24:08 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2016-08-25 12:58:57 +0000
commit07e7eab371951c41b413a689779258a619565a13 (patch)
treeb6fa7c3bd6267034395b956eebd3a4eccba5e45b /vnet
parent50a4e1429477e41848b1cdb632aab20cb8154386 (diff)
VPP-228 VPP-326: MAP: Adding additional API/CLI input parameter checks.
Added checks for EA bits length + PSID length > 64. Removed incorrect check in VAT that required all arguments as mandatory. Change-Id: I33a138612d199d7c5ce59abe1a7d7ecede3522bc Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/map/map.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/vnet/vnet/map/map.c b/vnet/vnet/map/map.c
index 0108c7b0267..17ecf460f51 100644
--- a/vnet/vnet/map/map.c
+++ b/vnet/vnet/map/map.c
@@ -166,13 +166,9 @@ map_create_domain (ip4_address_t * ip4_prefix,
ip_adjacency_t adj;
ip4_add_del_route_args_t args4;
ip6_add_del_route_args_t args6;
- u8 suffix_len;
+ u8 suffix_len, suffix_shift;
uword *p;
- /* EA bits must be within the first 64 bits */
- if (ea_bits_len > 0 && (ip6_prefix_len + ea_bits_len) > 64)
- return -1;
-
/* Sanity check on the src prefix length */
if (flags & MAP_DOMAIN_TRANSLATION)
{
@@ -187,11 +183,34 @@ map_create_domain (ip4_address_t * ip4_prefix,
if (ip6_src_len != 128)
{
clib_warning
- ("MAP-E requires a BR address, not a prefix (ip6_src_len should be 128).");
+ ("MAP-E requires a BR address, not a prefix (ip6_src_len should "
+ "be 128).");
return -1;
}
}
+ /* How many, and which bits to grab from the IPv4 DA */
+ if (ip4_prefix_len + ea_bits_len < 32)
+ {
+ flags |= MAP_DOMAIN_PREFIX;
+ suffix_len = suffix_shift = 32 - ip4_prefix_len - ea_bits_len;
+ }
+ else
+ {
+ suffix_shift = 0;
+ suffix_len = 32 - ip4_prefix_len;
+ }
+
+ /* EA bits must be within the first 64 bits */
+ if (ea_bits_len > 0 && ((ip6_prefix_len + ea_bits_len) > 64 ||
+ ip6_prefix_len + suffix_len + psid_length > 64))
+ {
+ clib_warning
+ ("Embedded Address bits must be within the first 64 bits of "
+ "the IPv6 prefix");
+ return -1;
+ }
+
/* Get domain index */
pool_get_aligned (mm->domains, d, CLIB_CACHE_LINE_BYTES);
memset (d, 0, sizeof (*d));
@@ -209,18 +228,7 @@ map_create_domain (ip4_address_t * ip4_prefix,
d->psid_length = psid_length;
d->mtu = mtu;
d->flags = flags;
-
- /* How many, and which bits to grab from the IPv4 DA */
- if (ip4_prefix_len + ea_bits_len < 32)
- {
- d->flags |= MAP_DOMAIN_PREFIX;
- suffix_len = d->suffix_shift = 32 - ip4_prefix_len - ea_bits_len;
- }
- else
- {
- d->suffix_shift = 0;
- suffix_len = 32 - ip4_prefix_len;
- }
+ d->suffix_shift = suffix_shift;
d->suffix_mask = (1 << suffix_len) - 1;
d->psid_shift = 16 - psid_length - psid_offset;
@@ -274,7 +282,10 @@ map_create_domain (ip4_address_t * ip4_prefix,
p = (uword *) & adj6->rewrite_data[0];
p[0] = ~0;
- /* Add refcount, so we don't accidentially delete the route underneath someone */
+ /*
+ * Add refcount, so we don't accidentially delete the route
+ * underneath someone
+ */
p[1]++;
}
else