* @param rlocs vector of remote locators
* @param action action for negative map-reply
* @param is_add add mapping if non-zero, delete otherwise
+ * @param del_all if set, delete all remote mappings
* @return return code
*/
int
vnet_lisp_add_del_remote_mapping (gid_address_t * deid, gid_address_t * seid,
- ip_address_t * rlocs, u8 action, u8 is_add)
+ ip_address_t * rlocs, u8 action, u8 is_add,
+ u8 del_all)
{
vnet_lisp_add_del_mapping_args_t _dm_args, * dm_args = &_dm_args;
vnet_lisp_add_del_mapping_args_t _sm_args, * sm_args = &_sm_args;
ip_address_t * dl;
int rc = -1;
+ if (del_all)
+ return vnet_lisp_clear_all_remote_mappings ();
+
memset (sm_args, 0, sizeof (sm_args[0]));
memset (dm_args, 0, sizeof (dm_args[0]));
memset (ls, 0, sizeof (ls[0]));
return rc;
}
+int
+vnet_lisp_clear_all_remote_mappings (void)
+{
+ int rv = 0;
+ u32 mi, * map_indices = 0, * map_indexp;
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main ();
+ vnet_lisp_add_del_mapping_args_t _dm_args, * dm_args = &_dm_args;
+ vnet_lisp_add_del_locator_set_args_t _ls, * ls = &_ls;
+
+ pool_foreach_index (mi, lcm->mapping_pool,
+ ({
+ vec_add1 (map_indices, mi);
+ }));
+
+ vec_foreach (map_indexp, map_indices)
+ {
+ mapping_t * map = pool_elt_at_index (lcm->mapping_pool, map_indexp[0]);
+ if (!map->local)
+ {
+ del_fwd_entry (lcm, 0, map_indexp[0]);
+
+ dm_args->is_add = 0;
+ gid_address_copy (&dm_args->deid, &map->eid);
+ dm_args->locator_set_index = map->locator_set_index;
+
+ /* delete mapping associated to fwd entry */
+ vnet_lisp_add_del_mapping (dm_args, 0);
+
+ ls->is_add = 0;
+ ls->local = 0;
+ ls->index = map->locator_set_index;
+ /* delete locator set */
+ rv = vnet_lisp_add_del_locator_set (ls, 0);
+ if (rv != 0)
+ goto cleanup;
+ }
+ }
+
+cleanup:
+ if (map_indices)
+ vec_free (map_indices);
+ return rv;
+}
+
/**
* Handler for add/del remote mapping CLI.
*
{
clib_error_t * error = 0;
unformat_input_t _line_input, * line_input = &_line_input;
- u8 is_add = 1;
+ u8 is_add = 1, del_all = 0;
ip_address_t rloc, * rlocs = 0;
ip_prefix_t * deid_ippref, * seid_ippref;
gid_address_t seid, deid;
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (line_input, "del"))
+ if (unformat (line_input, "del-all"))
+ del_all = 1;
+ else if (unformat (line_input, "del"))
is_add = 0;
- if (unformat (line_input, "add"))
+ else if (unformat (line_input, "add"))
;
else if (unformat (line_input, "deid %U",
unformat_ip_prefix, deid_ippref))
}
}
- if (!deid_set)
+ if (!del_all)
{
- clib_warning ("missing deid!");
- goto done;
- }
+ if (!deid_set)
+ {
+ clib_warning ("missing deid!");
+ goto done;
+ }
- if (is_add
- && (ip_prefix_version (deid_ippref)
- != ip_prefix_version (seid_ippref)))
- {
- clib_warning ("source and destination EIDs are not"
- " in the same IP family!");
- goto done;
- }
+ if (is_add
+ && (ip_prefix_version (deid_ippref)
+ != ip_prefix_version (seid_ippref)))
+ {
+ clib_warning ("source and destination EIDs are not"
+ " in the same IP family!");
+ goto done;
+ }
- if (is_add && (~0 == action)
- && 0 == vec_len (rlocs))
- {
- clib_warning ("no action set for negative map-reply!");
- goto done;
+ if (is_add && (~0 == action)
+ && 0 == vec_len (rlocs))
+ {
+ clib_warning ("no action set for negative map-reply!");
+ goto done;
+ }
}
int rv = vnet_lisp_add_del_remote_mapping (&deid, &seid, rlocs,
- action, is_add);
+ action, is_add, del_all);
if (rv)
clib_warning ("failed to %s remote mapping!",
is_add ? "add" : "delete");
VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = {
.path = "lisp remote-mapping",
- .short_help = "lisp remote-mapping add|del vni <vni>"
+ .short_help = "lisp remote-mapping add|del [del-all] vni <vni>"
"deid <dest-eid> seid <src-eid> [action <no-action|natively-forward|"
"send-map-request|drop>] rloc <dst-locator> [rloc <dst-locator> ... ]",
.function = lisp_add_del_remote_mapping_command_fn,
}
}
-int
-vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
- u32 * ls_result)
+static inline
+uword *get_locator_set_index(vnet_lisp_add_del_locator_set_args_t * a,
+ uword * p)
{
lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
- locator_set_t * ls;
- locator_t * loc, * itloc;
- uword _p = (u32)~0, * p = &_p;
- u32 loc_index, ls_index, ** ls_indexes;
- u32 **eid_indexes;
- if (a->is_add)
- {
- /* check if overwrite */
- if (a->local)
- p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
- else
- *p = a->index;
+ ASSERT(a != NULL);
+ ASSERT(p != NULL);
- /* overwrite */
- if (p && p[0] != (u32)~0)
- {
- ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
- if (!ls)
- {
- clib_warning("locator-set %d to be overwritten doesn't exist!",
- p[0]);
- return -1;
- }
+ /* find locator-set */
+ if (a->local)
+ {
+ p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
+ }
+ else
+ {
+ *p = a->index;
+ }
- /* clean locator to locator-set vectors and remove locators if
- * they're not part of another locator-set */
- clean_locator_to_locator_set (lcm, p[0]);
+ return p;
+}
- /* remove locator indices from locator set */
- vec_free(ls->locator_indices);
+static inline
+int is_locator_in_locator_set(lisp_cp_main_t * lcm, locator_set_t * ls,
+ locator_t * loc)
+{
+ locator_t * itloc;
+ u32 * locit;
- ls_index = p[0];
+ ASSERT(ls != NULL);
+ ASSERT(loc != NULL);
- if (ls_result)
- ls_result[0] = p[0];
- }
- /* new locator-set */
- else
+ vec_foreach(locit, ls->locator_indices)
+ {
+ itloc = pool_elt_at_index(lcm->locator_pool, locit[0]);
+ if (itloc->sw_if_index == loc->sw_if_index ||
+ !gid_address_cmp(&itloc->address, &loc->address))
{
- pool_get(lcm->locator_set_pool, ls);
- ls_index = ls - lcm->locator_set_pool;
+ clib_warning("Duplicate locator");
+ return VNET_API_ERROR_VALUE_EXIST;
+ }
+ }
- if (a->local)
- {
- ls->name = vec_dup(a->name);
+ return 0;
+}
- if (!lcm->locator_set_index_by_name)
- lcm->locator_set_index_by_name = hash_create_vec(
- /* size */0, sizeof(ls->name[0]), sizeof(uword));
- hash_set_mem(lcm->locator_set_index_by_name, ls->name, ls_index);
+static inline
+void remove_locator_from_locator_set(locator_set_t * ls, u32 * locit,
+ u32 ls_index, u32 loc_id)
+{
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ u32 ** ls_indexes = NULL;
- /* mark as local locator-set */
- vec_add1(lcm->local_locator_set_indexes, ls_index);
- }
- ls->local = a->local;
- if (ls_result)
- ls_result[0] = ls_index;
- }
+ ASSERT(ls != NULL);
+ ASSERT(locit != NULL);
- /* allocate locators */
- vec_foreach (itloc, a->locators)
- {
- pool_get(lcm->locator_pool, loc);
- loc[0] = itloc[0];
- loc_index = loc - lcm->locator_pool;
+ ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
+ locit[0]);
+ pool_put_index(lcm->locator_pool, locit[0]);
+ vec_del1(ls->locator_indices, loc_id);
+ vec_del1(ls_indexes[0], ls_index);
+}
- vec_add1(ls->locator_indices, loc_index);
+int
+vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
+ locator_set_t * ls, u32 * ls_result)
+{
+ lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ locator_t * loc = NULL, *itloc = NULL;
+ uword _p = (u32)~0, * p = &_p;
+ u32 loc_index = ~0, ls_index = ~0, * locit = NULL, ** ls_indexes = NULL;
+ u32 loc_id = ~0;
+ int ret = 0;
- vec_validate (lcm->locator_to_locator_sets, loc_index);
- ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
- loc_index);
- vec_add1(ls_indexes[0], ls_index);
- }
- }
- else
+ ASSERT(a != NULL);
+
+ p = get_locator_set_index(a, p);
+ if (!p)
{
- /* find locator-set */
- if (a->local)
- {
- p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
- if (!p)
- {
- clib_warning("locator-set %v doesn't exists", a->name);
- return -1;
- }
- }
- else
- *p = a->index;
+ clib_warning("locator-set %v doesn't exist", a->name);
+ return VNET_API_ERROR_INVALID_ARGUMENT;
+ }
+ if (ls == 0)
+ {
ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
if (!ls)
{
- clib_warning("locator-set with index %d doesn't exists", p[0]);
- return -1;
+ clib_warning("locator-set %d to be overwritten doesn't exist!",
+ p[0]);
+ return VNET_API_ERROR_INVALID_ARGUMENT;
}
-// /* XXX what happens when a mapping is configured to use the loc-set ? */
-// if (vec_len (vec_elt_at_index(lcm->locator_set_to_eids, p[0])) != 0)
-// {
-// clib_warning ("Can't delete a locator that supports a mapping!");
-// return -1;
-// }
-
- if (vec_len(lcm->locator_set_to_eids) != 0)
- {
- eid_indexes = vec_elt_at_index(lcm->locator_set_to_eids, p[0]);
- if (vec_len(eid_indexes[0]) != 0)
- {
- clib_warning ("Can't delete a locator that supports a mapping!");
- return -1;
- }
- }
+ }
- /* clean locator to locator-sets data */
- clean_locator_to_locator_set (lcm, p[0]);
+ if (a->is_add)
+ {
- if (ls->local)
- {
- u32 it, lsi;
+ if (ls_result)
+ ls_result[0] = p[0];
- vec_foreach_index(it, lcm->local_locator_set_indexes)
+ /* allocate locators */
+ vec_foreach (itloc, a->locators)
{
- lsi = vec_elt(lcm->local_locator_set_indexes, it);
- if (lsi == p[0])
+ ret = is_locator_in_locator_set(lcm, ls, itloc);
+ if (0 != ret)
{
- vec_del1(lcm->local_locator_set_indexes, it);
- break;
+ return ret;
}
+
+ pool_get(lcm->locator_pool, loc);
+ loc[0] = itloc[0];
+ loc_index = loc - lcm->locator_pool;
+
+ vec_add1(ls->locator_indices, loc_index);
+
+ vec_validate (lcm->locator_to_locator_sets, loc_index);
+ ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
+ loc_index);
+ vec_add1(ls_indexes[0], ls_index);
}
- hash_unset_mem(lcm->locator_set_index_by_name, ls->name);
- vec_free(ls->name);
- }
- pool_put(lcm->locator_set_pool, ls);
- }
- return 0;
-}
+ }
+ else
+ {
+ ls_index = p[0];
-static inline
-uword *vnet_lisp_get_locator(vnet_lisp_add_del_locator_set_args_t * a,
- uword *p)
-{
- lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
+ itloc = a->locators;
+ loc_id = 0;
+ vec_foreach (locit, ls->locator_indices)
+ {
+ loc = pool_elt_at_index(lcm->locator_pool, locit[0]);
- ASSERT(a != NULL);
- ASSERT(p != NULL);
+ if (loc->local && loc->sw_if_index == itloc->sw_if_index)
+ {
+ remove_locator_from_locator_set(ls, locit,
+ ls_index, loc_id);
+ }
+ if (0 == loc->local &&
+ !gid_address_cmp(&loc->address, &itloc->address))
+ {
+ remove_locator_from_locator_set(ls, locit,
+ ls_index, loc_id);
+ }
- /* find locator-set */
- if (a->local)
- {
- p = hash_get_mem(lcm->locator_set_index_by_name, a->name);
- }
- else
- {
- *p = a->index;
- }
+ loc_id++;
+ }
+ }
- return p;
+ return 0;
}
int
-vnet_lisp_add_del_locator_set_name (vnet_lisp_add_del_locator_set_args_t * a,
- u32 * ls_result)
+vnet_lisp_add_del_locator_set (vnet_lisp_add_del_locator_set_args_t * a,
+ u32 * ls_result)
{
lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
locator_set_t * ls;
uword _p = (u32)~0, * p = &_p;
- u32 ls_index = ~0;
- u32 **eid_indexes = NULL;
-
- ASSERT(a != NULL);
- ASSERT(ls_result != NULL);
-
- p = vnet_lisp_get_locator(a, p);
+ u32 ls_index;
+ u32 ** eid_indexes;
+ int ret = 0;
if (a->is_add)
{
+ p = get_locator_set_index(a, p);
+
/* overwrite */
if (p && p[0] != (u32)~0)
{
{
clib_warning("locator-set %d to be overwritten doesn't exist!",
p[0]);
- return VNET_API_ERROR_UNSPECIFIED;
+ return -1;
}
/* clean locator to locator-set vectors and remove locators if
else
{
pool_get(lcm->locator_set_pool, ls);
+ memset(ls, 0, sizeof(*ls));
ls_index = ls - lcm->locator_set_pool;
if (a->local)
vec_add1(lcm->local_locator_set_indexes, ls_index);
}
ls->local = a->local;
- ls->locator_indices = NULL;
if (ls_result)
ls_result[0] = ls_index;
}
+
+ ret = vnet_lisp_add_del_locator(a, ls, NULL);
+ if (0 != ret)
+ {
+ return ret;
+ }
}
else
{
- if (!p)
- {
- clib_warning("locator-set %v doesn't exists", a->name);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
-
- ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
- if (!ls)
- {
- clib_warning("locator-set with index %d doesn't exists", p[0]);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
+ p = get_locator_set_index(a, p);
+ if (!p)
+ {
+ clib_warning("locator-set %v doesn't exists", a->name);
+ return -1;
+ }
+
+ ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
+ if (!ls)
+ {
+ clib_warning("locator-set with index %d doesn't exists", p[0]);
+ return -1;
+ }
if (vec_len(lcm->locator_set_to_eids) != 0)
{
u32 it, lsi;
vec_foreach_index(it, lcm->local_locator_set_indexes)
- {
- lsi = vec_elt(lcm->local_locator_set_indexes, it);
- if (lsi == p[0])
- {
- vec_del1(lcm->local_locator_set_indexes, it);
- break;
- }
- }
- hash_unset_mem(lcm->locator_set_index_by_name, ls->name);
- vec_free(ls->name);
- }
- pool_put(lcm->locator_set_pool, ls);
- }
- return 0;
-}
-
-int
-vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t *a,
- u32 *ls_result)
-{
- lisp_cp_main_t * lcm = vnet_lisp_cp_get_main();
- locator_set_t *ls = NULL;
- locator_t *loc = NULL, *itloc = NULL;
- uword _p = (u32)~0, * p = &_p;
- u32 loc_index = ~0, ls_index = ~0, *locit = NULL, **ls_indexes = NULL;
- u32 i = ~0;
-
- ASSERT(a != NULL);
- ASSERT(ls_result != NULL);
-
- p = vnet_lisp_get_locator(a, p);
- if (!p) {
- clib_warning("locator-set %v doesn't exists", a->name);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
-
- ls_index = p[0];
-
- if (a->is_add)
- {
- ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
- if (!ls)
- {
- clib_warning("locator-set %d to be overwritten doesn't exist!",
- p[0]);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
-
- if (ls_result)
- ls_result[0] = p[0];
-
- /* allocate locators */
- itloc = a->locators;
- pool_get(lcm->locator_pool, loc);
- loc[0] = itloc[0];
- loc_index = loc - lcm->locator_pool;
-
- vec_add1(ls->locator_indices, loc_index);
-
- vec_validate (lcm->locator_to_locator_sets, loc_index);
- ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
- loc_index);
- vec_add1(ls_indexes[0], ls_index);
- }
- else
- {
- ls = pool_elt_at_index(lcm->locator_set_pool, p[0]);
- if (!ls)
- {
- clib_warning("locator-set with index %d doesn't exists", p[0]);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
-
- if (ls->local)
- {
- itloc = a->locators;
- i = 0;
- vec_foreach (locit, ls->locator_indices)
{
- loc = pool_elt_at_index(lcm->locator_pool, locit[0]);
- if (loc->local && loc->sw_if_index == itloc->sw_if_index)
+ lsi = vec_elt(lcm->local_locator_set_indexes, it);
+ if (lsi == p[0])
{
- ls_indexes = vec_elt_at_index(lcm->locator_to_locator_sets,
- locit[0]);
- pool_put_index(lcm->locator_pool, locit[0]);
- vec_del1(ls->locator_indices, i);
- vec_del1(ls_indexes[0], ls_index);
+ vec_del1(lcm->local_locator_set_indexes, it);
+ break;
}
- i++;
}
- }
+ hash_unset_mem(lcm->locator_set_index_by_name, ls->name);
+ }
+ vec_free(ls->name);
+ vec_free(ls->locator_indices);
+ pool_put(lcm->locator_set_pool, ls);
}
return 0;
}