diff options
author | Ole Troan <ot@cisco.com> | 2016-08-25 00:24:08 +0200 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2016-08-25 12:58:57 +0000 |
commit | 07e7eab371951c41b413a689779258a619565a13 (patch) | |
tree | b6fa7c3bd6267034395b956eebd3a4eccba5e45b | |
parent | 50a4e1429477e41848b1cdb632aab20cb8154386 (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>
-rw-r--r-- | vnet/vnet/map/map.c | 49 | ||||
-rw-r--r-- | vpp-api-test/vat/api_format.c | 2 |
2 files changed, 31 insertions, 20 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 diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index 7f0f9fa7f20..7dcd0597a64 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -11224,7 +11224,7 @@ api_map_add_domain (vat_main_t * vam) } } - if (num_m_args != 6) + if (num_m_args < 3) { errmsg ("mandatory argument(s) missing\n"); return -99; |