-int
-vnet_lisp_set_map_request_mode (u8 mode)
-{
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
-
- if (vnet_lisp_enable_disable_status () == 0)
- {
- clib_warning ("LISP is disabled!");
- return VNET_API_ERROR_LISP_DISABLED;
- }
-
- if (mode >= _MR_MODE_MAX)
- {
- clib_warning ("Invalid LISP map request mode %d!", mode);
- return VNET_API_ERROR_INVALID_ARGUMENT;
- }
-
- lcm->map_request_mode = mode;
- return 0;
-}
-
-static clib_error_t *
-lisp_map_request_mode_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- unformat_input_t _i, *i = &_i;
- map_request_mode_t mr_mode = _MR_MODE_MAX;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, i))
- return 0;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "dst-only"))
- mr_mode = MR_MODE_DST_ONLY;
- else if (unformat (i, "src-dst"))
- mr_mode = MR_MODE_SRC_DST;
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- goto done;
- }
- }
-
- if (_MR_MODE_MAX == mr_mode)
- {
- clib_warning ("No LISP map request mode entered!");
- return 0;
- }
-
- vnet_lisp_set_map_request_mode (mr_mode);
-done:
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
- .path = "lisp map-request mode",
- .short_help = "lisp map-request mode dst-only|src-dst",
- .function = lisp_map_request_mode_command_fn,
-};
-/* *INDENT-ON* */
-
-static u8 *
-format_lisp_map_request_mode (u8 * s, va_list * args)
-{
- u32 mode = va_arg (*args, u32);
-
- switch (mode)
- {
- case 0:
- return format (0, "dst-only");
- case 1:
- return format (0, "src-dst");
- }
- return 0;
-}
-
-static clib_error_t *
-lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
- vnet_lisp_get_map_request_mode ());
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
- .path = "show lisp map-request mode",
- .short_help = "show lisp map-request mode",
- .function = lisp_show_map_request_mode_command_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- lisp_msmr_t *mr;
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
-
- vec_foreach (mr, lcm->map_resolvers)
- {
- vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
- }
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
- .path = "show lisp map-resolvers",
- .short_help = "show lisp map-resolvers",
- .function = lisp_show_map_resolvers_command_fn,
-};
-/* *INDENT-ON* */
-
-int
-vnet_lisp_pitr_set_locator_set (u8 * locator_set_name, u8 is_add)
-{
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- u32 locator_set_index = ~0;
- mapping_t *m;
- uword *p;
-
- if (vnet_lisp_enable_disable_status () == 0)
- {
- clib_warning ("LISP is disabled!");
- return VNET_API_ERROR_LISP_DISABLED;
- }
-
- p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
- if (!p)
- {
- clib_warning ("locator-set %v doesn't exist", locator_set_name);
- return -1;
- }
- locator_set_index = p[0];
-
- if (is_add)
- {
- pool_get (lcm->mapping_pool, m);
- m->locator_set_index = locator_set_index;
- m->local = 1;
- lcm->pitr_map_index = m - lcm->mapping_pool;
-
- /* enable pitr mode */
- lcm->lisp_pitr = 1;
- }
- else
- {
- /* remove pitr mapping */
- pool_put_index (lcm->mapping_pool, lcm->pitr_map_index);
-
- /* disable pitr mode */
- lcm->lisp_pitr = 0;
- }
- return 0;
-}
-
-static clib_error_t *
-lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- u8 locator_name_set = 0;
- u8 *locator_set_name = 0;
- u8 is_add = 1;
- unformat_input_t _line_input, *line_input = &_line_input;
- clib_error_t *error = 0;
- int rv = 0;
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "ls %_%v%_", &locator_set_name))
- locator_name_set = 1;
- else if (unformat (line_input, "disable"))
- is_add = 0;
- else
- return clib_error_return (0, "parse error");
- }
-
- if (!locator_name_set)
- {
- clib_warning ("No locator set specified!");
- goto done;
- }
- rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
- if (0 != rv)
- {
- error = clib_error_return (0, "failed to %s pitr!",
- is_add ? "add" : "delete");
- }
-
-done:
- if (locator_set_name)
- vec_free (locator_set_name);
- return error;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
- .path = "lisp pitr",
- .short_help = "lisp pitr [disable] ls <locator-set-name>",
- .function = lisp_pitr_set_locator_set_command_fn,
-};
-/* *INDENT-ON* */
-
-static clib_error_t *
-lisp_show_pitr_command_fn (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd)
-{
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- mapping_t *m;
- locator_set_t *ls;
- u8 *tmp_str = 0;
-
- vlib_cli_output (vm, "%=20s%=16s",
- "pitr", lcm->lisp_pitr ? "locator-set" : "");
-
- if (!lcm->lisp_pitr)
- {
- vlib_cli_output (vm, "%=20s", "disable");
- return 0;
- }
-
- if (~0 == lcm->pitr_map_index)
- {
- tmp_str = format (0, "N/A");
- }
- else
- {
- m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
- if (~0 != m->locator_set_index)
- {
- ls =
- pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
- tmp_str = format (0, "%s", ls->name);
- }
- else
- {
- tmp_str = format (0, "N/A");
- }
- }
- vec_add1 (tmp_str, 0);
-
- vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
-
- vec_free (tmp_str);
-
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
- .path = "show lisp pitr",
- .short_help = "Show pitr",
- .function = lisp_show_pitr_command_fn,
-};
-/* *INDENT-ON* */
-
-static u8 *
-format_eid_entry (u8 * s, va_list * args)
-{
- vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
- lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
- mapping_t *mapit = va_arg (*args, mapping_t *);
- locator_set_t *ls = va_arg (*args, locator_set_t *);
- gid_address_t *gid = &mapit->eid;
- u32 ttl = mapit->ttl;
- u8 aut = mapit->authoritative;
- u32 *loc_index;
- u8 first_line = 1;
- u8 *loc;
-
- u8 *type = ls->local ? format (0, "local(%s)", ls->name)
- : format (0, "remote");
-
- if (vec_len (ls->locator_indices) == 0)
- {
- s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
- type, ttl, aut);
- }
- else
- {
- vec_foreach (loc_index, ls->locator_indices)
- {
- locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
- if (l->local)
- loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
- l->sw_if_index);
- else
- loc = format (0, "%U", format_ip_address,
- &gid_address_ip (&l->address));
-
- if (first_line)
- {
- s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
- gid, type, loc, ttl, aut);
- first_line = 0;
- }
- else
- s = format (s, "%55s%v\n", "", loc);
- }
- }
- return s;
-}
-
-static clib_error_t *
-lisp_show_eid_table_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
- mapping_t *mapit;
- unformat_input_t _line_input, *line_input = &_line_input;
- u32 mi;
- gid_address_t eid;
- u8 print_all = 1;
- u8 filter = 0;
-
- memset (&eid, 0, sizeof (eid));
-
- /* Get a line of input. */
- if (!unformat_user (input, unformat_line_input, line_input))
- return 0;
-
- while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
- print_all = 0;
- else if (unformat (line_input, "local"))
- filter = 1;
- else if (unformat (line_input, "remote"))
- filter = 2;
- else
- return clib_error_return (0, "parse error: '%U'",
- format_unformat_error, line_input);
- }
-
- vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
- "EID", "type", "locators", "ttl", "autoritative");
-
- if (print_all)
- {
- /* *INDENT-OFF* */
- pool_foreach (mapit, lcm->mapping_pool,
- ({
- locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
- mapit->locator_set_index);
- if (filter && !((1 == filter && ls->local) ||
- (2 == filter && !ls->local)))
- {
- continue;
- }
- vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
- lcm, mapit, ls);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
- if ((u32) ~ 0 == mi)
- return 0;
-
- mapit = pool_elt_at_index (lcm->mapping_pool, mi);
- locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
- mapit->locator_set_index);
-
- if (filter && !((1 == filter && ls->local) ||
- (2 == filter && !ls->local)))
- {
- return 0;
- }
-
- vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
- lcm, mapit, ls);