LCOV - code coverage report
Current view: top level - plugins/lisp/lisp-cp - lisp_cli.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 26 714 3.6 %
Date: 2023-10-26 01:39:38 Functions: 52 81 64.2 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : 
      16             : #include <lisp/lisp-cp/control.h>
      17             : #include <lisp/lisp-gpe/lisp_gpe.h>
      18             : 
      19             : static clib_error_t *
      20           0 : lisp_show_adjacencies_command_fn (vlib_main_t * vm,
      21             :                                   unformat_input_t * input,
      22             :                                   vlib_cli_command_t * cmd)
      23             : {
      24             :   lisp_adjacency_t *adjs, *adj;
      25           0 :   vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
      26           0 :   unformat_input_t _line_input, *line_input = &_line_input;
      27           0 :   u32 vni = ~0;
      28           0 :   clib_error_t *error = NULL;
      29             : 
      30             :   /* Get a line of input. */
      31           0 :   if (!unformat_user (input, unformat_line_input, line_input))
      32           0 :     return 0;
      33             : 
      34           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
      35             :     {
      36           0 :       if (unformat (line_input, "vni %d", &vni))
      37             :         ;
      38             :       else
      39             :         {
      40           0 :           vlib_cli_output (vm, "parse error: '%U'",
      41             :                            format_unformat_error, line_input);
      42           0 :           goto done;
      43             :         }
      44             :     }
      45             : 
      46           0 :   if (~0 == vni)
      47             :     {
      48           0 :       vlib_cli_output (vm, "error: no vni specified!");
      49           0 :       goto done;
      50             :     }
      51             : 
      52           0 :   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
      53             : 
      54           0 :   vec_foreach (adj, adjs)
      55             :   {
      56           0 :     vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
      57             :                      format_gid_address, &adj->reid);
      58             :   }
      59           0 :   vec_free (adjs);
      60             : 
      61           0 : done:
      62           0 :   unformat_free (line_input);
      63             : 
      64           0 :   return error;
      65             : }
      66             : 
      67             : /* *INDENT-OFF* */
      68      123991 : VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
      69             :     .path = "show lisp adjacencies",
      70             :     .short_help = "show lisp adjacencies",
      71             :     .function = lisp_show_adjacencies_command_fn,
      72             : };
      73             : /* *INDENT-ON* */
      74             : 
      75             : static clib_error_t *
      76           0 : lisp_add_del_map_server_command_fn (vlib_main_t * vm,
      77             :                                     unformat_input_t * input,
      78             :                                     vlib_cli_command_t * cmd)
      79             : {
      80           0 :   int rv = 0;
      81           0 :   u8 is_add = 1, ip_set = 0;
      82             :   ip_address_t ip;
      83           0 :   unformat_input_t _line_input, *line_input = &_line_input;
      84           0 :   clib_error_t *error = NULL;
      85             : 
      86             :   /* Get a line of input. */
      87           0 :   if (!unformat_user (input, unformat_line_input, line_input))
      88           0 :     return 0;
      89             : 
      90           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
      91             :     {
      92           0 :       if (unformat (line_input, "add"))
      93           0 :         is_add = 1;
      94           0 :       else if (unformat (line_input, "del"))
      95           0 :         is_add = 0;
      96           0 :       else if (unformat (line_input, "%U", unformat_ip_address, &ip))
      97           0 :         ip_set = 1;
      98             :       else
      99             :         {
     100           0 :           vlib_cli_output (vm, "parse error: '%U'",
     101             :                            format_unformat_error, line_input);
     102           0 :           goto done;
     103             :         }
     104             :     }
     105             : 
     106           0 :   if (!ip_set)
     107             :     {
     108           0 :       vlib_cli_output (vm, "map-server ip address not set!");
     109           0 :       goto done;
     110             :     }
     111             : 
     112           0 :   rv = vnet_lisp_add_del_map_server (&ip, is_add);
     113           0 :   if (!rv)
     114           0 :     vlib_cli_output (vm, "failed to %s map-server!",
     115             :                      is_add ? "add" : "delete");
     116             : 
     117           0 : done:
     118           0 :   unformat_free (line_input);
     119             : 
     120           0 :   return error;
     121             : }
     122             : 
     123             : /* *INDENT-OFF* */
     124      123991 : VLIB_CLI_COMMAND (lisp_add_del_map_server_command) = {
     125             :     .path = "lisp map-server",
     126             :     .short_help = "lisp map-server add|del <ip>",
     127             :     .function = lisp_add_del_map_server_command_fn,
     128             : };
     129             : /* *INDENT-ON* */
     130             : 
     131             : 
     132             : static clib_error_t *
     133           0 : lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
     134             :                                    vlib_cli_command_t * cmd)
     135             : {
     136           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     137           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     138           0 :   u8 is_add = 1;
     139             :   gid_address_t eid;
     140           0 :   gid_address_t *eids = 0;
     141           0 :   clib_error_t *error = 0;
     142           0 :   u8 *locator_set_name = 0;
     143           0 :   u32 locator_set_index = 0, map_index = 0;
     144             :   uword *p;
     145           0 :   vnet_lisp_add_del_mapping_args_t _a, *a = &_a;
     146           0 :   int rv = 0;
     147           0 :   u32 vni = 0;
     148           0 :   u8 *key = 0;
     149           0 :   u32 key_id = 0;
     150             : 
     151           0 :   clib_memset (&eid, 0, sizeof (eid));
     152           0 :   clib_memset (a, 0, sizeof (*a));
     153             : 
     154             :   /* Get a line of input. */
     155           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     156           0 :     return 0;
     157             : 
     158           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     159             :     {
     160           0 :       if (unformat (line_input, "add"))
     161           0 :         is_add = 1;
     162           0 :       else if (unformat (line_input, "del"))
     163           0 :         is_add = 0;
     164           0 :       else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
     165             :         ;
     166           0 :       else if (unformat (line_input, "vni %d", &vni))
     167           0 :         gid_address_vni (&eid) = vni;
     168           0 :       else if (unformat (line_input, "secret-key %_%v%_", &key))
     169             :         ;
     170           0 :       else if (unformat (line_input, "key-id %U", unformat_hmac_key_id,
     171             :                          &key_id))
     172             :         ;
     173           0 :       else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
     174             :         {
     175           0 :           vec_terminate_c_string (locator_set_name);
     176           0 :           p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
     177           0 :           if (!p)
     178             :             {
     179           0 :               error = clib_error_return (0, "locator-set %s doesn't exist",
     180             :                                          locator_set_name);
     181           0 :               goto done;
     182             :             }
     183           0 :           locator_set_index = p[0];
     184             :         }
     185             :       else
     186             :         {
     187           0 :           error = unformat_parse_error (line_input);
     188           0 :           goto done;
     189             :         }
     190             :     }
     191             :   /* XXX treat batch configuration */
     192             : 
     193           0 :   if (GID_ADDR_SRC_DST == gid_address_type (&eid))
     194             :     {
     195             :       error =
     196           0 :         clib_error_return (0, "src/dst is not supported for local EIDs!");
     197           0 :       goto done;
     198             :     }
     199             : 
     200           0 :   if (key && (0 == key_id))
     201             :     {
     202           0 :       vlib_cli_output (vm, "invalid key_id!");
     203           0 :       goto done;;
     204             :     }
     205             : 
     206           0 :   gid_address_copy (&a->eid, &eid);
     207           0 :   a->is_add = is_add;
     208           0 :   a->locator_set_index = locator_set_index;
     209           0 :   a->local = 1;
     210           0 :   a->key = key;
     211           0 :   a->key_id = key_id;
     212             : 
     213           0 :   rv = vnet_lisp_add_del_local_mapping (a, &map_index);
     214           0 :   if (0 != rv)
     215             :     {
     216           0 :       error = clib_error_return (0, "failed to %s local mapping!",
     217             :                                  is_add ? "add" : "delete");
     218             :     }
     219           0 : done:
     220           0 :   vec_free (eids);
     221           0 :   if (locator_set_name)
     222           0 :     vec_free (locator_set_name);
     223           0 :   gid_address_free (&a->eid);
     224           0 :   vec_free (a->key);
     225           0 :   unformat_free (line_input);
     226             : 
     227           0 :   return error;
     228             : }
     229             : 
     230             : /* *INDENT-OFF* */
     231      123991 : VLIB_CLI_COMMAND (lisp_add_del_local_eid_command) = {
     232             :     .path = "lisp eid-table",
     233             :     .short_help = "lisp eid-table add/del [vni <vni>] eid <eid> "
     234             :       "locator-set <locator-set> [key <secret-key> key-id sha1|sha256 ]",
     235             :     .function = lisp_add_del_local_eid_command_fn,
     236             : };
     237             : /* *INDENT-ON* */
     238             : 
     239             : static clib_error_t *
     240           0 : lisp_eid_table_map_command_fn (vlib_main_t * vm,
     241             :                                unformat_input_t * input,
     242             :                                vlib_cli_command_t * cmd)
     243             : {
     244           0 :   u8 is_add = 1, is_l2 = 0;
     245           0 :   u32 vni = 0, dp_id = 0;
     246           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     247           0 :   clib_error_t *error = NULL;
     248             : 
     249             :   /* Get a line of input. */
     250           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     251           0 :     return 0;
     252             : 
     253           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     254             :     {
     255           0 :       if (unformat (line_input, "del"))
     256           0 :         is_add = 0;
     257           0 :       else if (unformat (line_input, "vni %d", &vni))
     258             :         ;
     259           0 :       else if (unformat (line_input, "vrf %d", &dp_id))
     260             :         ;
     261           0 :       else if (unformat (line_input, "bd %d", &dp_id))
     262           0 :         is_l2 = 1;
     263             :       else
     264             :         {
     265           0 :           error = unformat_parse_error (line_input);
     266           0 :           goto done;
     267             :         }
     268             :     }
     269           0 :   vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
     270             : 
     271           0 : done:
     272           0 :   unformat_free (line_input);
     273             : 
     274           0 :   return error;
     275             : }
     276             : 
     277             : /* *INDENT-OFF* */
     278      123991 : VLIB_CLI_COMMAND (lisp_eid_table_map_command) = {
     279             :     .path = "lisp eid-table map",
     280             :     .short_help = "lisp eid-table map [del] vni <vni> vrf <vrf> | bd <bdi>",
     281             :     .function = lisp_eid_table_map_command_fn,
     282             : };
     283             : /* *INDENT-ON* */
     284             : 
     285             : /**
     286             :  * Handler for add/del remote mapping CLI.
     287             :  *
     288             :  * @param vm vlib context
     289             :  * @param input input from user
     290             :  * @param cmd cmd
     291             :  * @return pointer to clib error structure
     292             :  */
     293             : static clib_error_t *
     294           0 : lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
     295             :                                         unformat_input_t * input,
     296             :                                         vlib_cli_command_t * cmd)
     297             : {
     298           0 :   clib_error_t *error = 0;
     299           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     300           0 :   u8 is_add = 1, del_all = 0;
     301           0 :   locator_t rloc, *rlocs = 0, *curr_rloc = 0;
     302             :   gid_address_t eid;
     303           0 :   u8 eid_set = 0;
     304           0 :   u32 vni, action = ~0, p, w;
     305             :   int rv;
     306             : 
     307             :   /* Get a line of input. */
     308           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     309           0 :     return 0;
     310             : 
     311           0 :   clib_memset (&eid, 0, sizeof (eid));
     312           0 :   clib_memset (&rloc, 0, sizeof (rloc));
     313             : 
     314           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     315             :     {
     316           0 :       if (unformat (line_input, "del-all"))
     317           0 :         del_all = 1;
     318           0 :       else if (unformat (line_input, "del"))
     319           0 :         is_add = 0;
     320           0 :       else if (unformat (line_input, "add"))
     321             :         ;
     322           0 :       else if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
     323           0 :         eid_set = 1;
     324           0 :       else if (unformat (line_input, "vni %u", &vni))
     325             :         {
     326           0 :           gid_address_vni (&eid) = vni;
     327             :         }
     328           0 :       else if (unformat (line_input, "p %d w %d", &p, &w))
     329             :         {
     330           0 :           if (!curr_rloc)
     331             :             {
     332           0 :               clib_warning
     333             :                 ("No RLOC configured for setting priority/weight!");
     334           0 :               goto done;
     335             :             }
     336           0 :           curr_rloc->priority = p;
     337           0 :           curr_rloc->weight = w;
     338             :         }
     339           0 :       else if (unformat (line_input, "rloc %U", unformat_ip_address,
     340             :                          &gid_address_ip (&rloc.address)))
     341             :         {
     342             :           /* since rloc is stored in ip prefix we need to set prefix length */
     343           0 :           ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
     344             : 
     345           0 :           u8 version = gid_address_ip_version (&rloc.address);
     346           0 :           ip_prefix_len (pref) = ip_address_max_len (version);
     347             : 
     348           0 :           vec_add1 (rlocs, rloc);
     349           0 :           curr_rloc = &rlocs[vec_len (rlocs) - 1];
     350             :         }
     351           0 :       else if (unformat (line_input, "action %U",
     352             :                          unformat_negative_mapping_action, &action))
     353             :         ;
     354             :       else
     355             :         {
     356           0 :           clib_warning ("parse error");
     357           0 :           goto done;
     358             :         }
     359             :     }
     360             : 
     361           0 :   if (!eid_set)
     362             :     {
     363           0 :       clib_warning ("missing eid!");
     364           0 :       goto done;
     365             :     }
     366             : 
     367           0 :   if (!del_all)
     368             :     {
     369           0 :       if (is_add && (~0 == action) && 0 == vec_len (rlocs))
     370             :         {
     371           0 :           clib_warning ("no action set for negative map-reply!");
     372           0 :           goto done;
     373             :         }
     374             :     }
     375             :   else
     376             :     {
     377           0 :       vnet_lisp_clear_all_remote_adjacencies ();
     378           0 :       goto done;
     379             :     }
     380             : 
     381             :   /* TODO build src/dst with seid */
     382             : 
     383             :   /* if it's a delete, clean forwarding */
     384           0 :   if (!is_add)
     385             :     {
     386           0 :       vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
     387           0 :       clib_memset (a, 0, sizeof (a[0]));
     388           0 :       gid_address_copy (&a->reid, &eid);
     389           0 :       if (vnet_lisp_add_del_adjacency (a))
     390             :         {
     391           0 :           clib_warning ("failed to delete adjacency!");
     392           0 :           goto done;
     393             :         }
     394             :     }
     395             : 
     396             :   /* add as static remote mapping, i.e., not authoritative and infinite
     397             :    * ttl */
     398           0 :   if (is_add)
     399             :     {
     400           0 :       vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
     401           0 :       clib_memset (map_args, 0, sizeof (map_args[0]));
     402           0 :       gid_address_copy (&map_args->eid, &eid);
     403           0 :       map_args->action = action;
     404           0 :       map_args->is_static = 1;
     405           0 :       map_args->authoritative = 0;
     406           0 :       map_args->ttl = ~0;
     407           0 :       rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
     408             :     }
     409             :   else
     410           0 :     rv = vnet_lisp_del_mapping (&eid, NULL);
     411             : 
     412           0 :   if (rv)
     413           0 :     clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
     414             : 
     415           0 : done:
     416           0 :   vec_free (rlocs);
     417           0 :   unformat_free (line_input);
     418           0 :   return error;
     419             : }
     420             : 
     421             : /* *INDENT-OFF* */
     422      123991 : VLIB_CLI_COMMAND (lisp_add_del_remote_mapping_command) = {
     423             :     .path = "lisp remote-mapping",
     424             :     .short_help = "lisp remote-mapping add|del [del-all] vni <vni> "
     425             :                   "eid <est-eid> [action <no-action|natively-forward|"
     426             :                   "send-map-request|drop>] rloc <dst-locator> p <prio> "
     427             :                   "w <weight> [rloc <dst-locator> ... ]",
     428             :     .function = lisp_add_del_remote_mapping_command_fn,
     429             : };
     430             : /* *INDENT-ON* */
     431             : 
     432             : /**
     433             :  * Handler for add/del adjacency CLI.
     434             :  */
     435             : static clib_error_t *
     436           0 : lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
     437             :                                    vlib_cli_command_t * cmd)
     438             : {
     439           0 :   clib_error_t *error = 0;
     440           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     441           0 :   vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
     442           0 :   u8 is_add = 1;
     443             :   ip_prefix_t *reid_ippref, *leid_ippref;
     444             :   gid_address_t leid, reid;
     445           0 :   u8 *dmac = gid_address_mac (&reid);
     446           0 :   u8 *smac = gid_address_mac (&leid);
     447           0 :   u8 reid_set = 0, leid_set = 0;
     448             :   u32 vni;
     449             : 
     450             :   /* Get a line of input. */
     451           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     452           0 :     return 0;
     453             : 
     454           0 :   clib_memset (&reid, 0, sizeof (reid));
     455           0 :   clib_memset (&leid, 0, sizeof (leid));
     456             : 
     457           0 :   leid_ippref = &gid_address_ippref (&leid);
     458           0 :   reid_ippref = &gid_address_ippref (&reid);
     459             : 
     460           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     461             :     {
     462           0 :       if (unformat (line_input, "del"))
     463           0 :         is_add = 0;
     464           0 :       else if (unformat (line_input, "add"))
     465             :         ;
     466           0 :       else if (unformat (line_input, "reid %U",
     467             :                          unformat_ip_prefix, reid_ippref))
     468             :         {
     469           0 :           gid_address_type (&reid) = GID_ADDR_IP_PREFIX;
     470           0 :           reid_set = 1;
     471             :         }
     472           0 :       else if (unformat (line_input, "reid %U", unformat_mac_address, dmac))
     473             :         {
     474           0 :           gid_address_type (&reid) = GID_ADDR_MAC;
     475           0 :           reid_set = 1;
     476             :         }
     477           0 :       else if (unformat (line_input, "vni %u", &vni))
     478             :         {
     479           0 :           gid_address_vni (&leid) = vni;
     480           0 :           gid_address_vni (&reid) = vni;
     481             :         }
     482           0 :       else if (unformat (line_input, "leid %U",
     483             :                          unformat_ip_prefix, leid_ippref))
     484             :         {
     485           0 :           gid_address_type (&leid) = GID_ADDR_IP_PREFIX;
     486           0 :           leid_set = 1;
     487             :         }
     488           0 :       else if (unformat (line_input, "leid %U", unformat_mac_address, smac))
     489             :         {
     490           0 :           gid_address_type (&leid) = GID_ADDR_MAC;
     491           0 :           leid_set = 1;
     492             :         }
     493             :       else
     494             :         {
     495           0 :           clib_warning ("parse error");
     496           0 :           goto done;
     497             :         }
     498             :     }
     499             : 
     500           0 :   if (!reid_set || !leid_set)
     501             :     {
     502           0 :       clib_warning ("missing remote or local eid!");
     503           0 :       goto done;
     504             :     }
     505             : 
     506           0 :   if ((gid_address_type (&leid) != gid_address_type (&reid))
     507           0 :       || (gid_address_type (&reid) == GID_ADDR_IP_PREFIX
     508           0 :           && ip_prefix_version (reid_ippref)
     509           0 :           != ip_prefix_version (leid_ippref)))
     510             :     {
     511           0 :       clib_warning ("remote and local EIDs are of different types!");
     512           0 :       goto done;
     513             :     }
     514             : 
     515           0 :   clib_memset (a, 0, sizeof (a[0]));
     516           0 :   gid_address_copy (&a->leid, &leid);
     517           0 :   gid_address_copy (&a->reid, &reid);
     518           0 :   a->is_add = is_add;
     519             : 
     520           0 :   if (vnet_lisp_add_del_adjacency (a))
     521           0 :     clib_warning ("failed to %s adjacency!", is_add ? "add" : "delete");
     522             : 
     523           0 : done:
     524           0 :   unformat_free (line_input);
     525           0 :   return error;
     526             : }
     527             : 
     528             : /* *INDENT-OFF* */
     529      123991 : VLIB_CLI_COMMAND (lisp_add_del_adjacency_command) = {
     530             :     .path = "lisp adjacency",
     531             :     .short_help = "lisp adjacency add|del vni <vni> reid <remote-eid> "
     532             :       "leid <local-eid>",
     533             :     .function = lisp_add_del_adjacency_command_fn,
     534             : };
     535             : /* *INDENT-ON* */
     536             : 
     537             : 
     538             : static clib_error_t *
     539           0 : lisp_map_request_mode_command_fn (vlib_main_t * vm,
     540             :                                   unformat_input_t * input,
     541             :                                   vlib_cli_command_t * cmd)
     542             : {
     543           0 :   unformat_input_t _i, *i = &_i;
     544           0 :   map_request_mode_t mr_mode = _MR_MODE_MAX;
     545           0 :   clib_error_t *error = NULL;
     546             : 
     547             :   /* Get a line of input. */
     548           0 :   if (!unformat_user (input, unformat_line_input, i))
     549           0 :     return 0;
     550             : 
     551           0 :   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     552             :     {
     553           0 :       if (unformat (i, "dst-only"))
     554           0 :         mr_mode = MR_MODE_DST_ONLY;
     555           0 :       else if (unformat (i, "src-dst"))
     556           0 :         mr_mode = MR_MODE_SRC_DST;
     557             :       else
     558             :         {
     559           0 :           clib_warning ("parse error '%U'", format_unformat_error, i);
     560           0 :           goto done;
     561             :         }
     562             :     }
     563             : 
     564           0 :   if (_MR_MODE_MAX == mr_mode)
     565             :     {
     566           0 :       clib_warning ("No LISP map request mode entered!");
     567           0 :       goto done;
     568             :     }
     569             : 
     570           0 :   vnet_lisp_set_map_request_mode (mr_mode);
     571             : 
     572           0 : done:
     573           0 :   unformat_free (i);
     574             : 
     575           0 :   return error;
     576             : }
     577             : 
     578             : /* *INDENT-OFF* */
     579      123991 : VLIB_CLI_COMMAND (lisp_map_request_mode_command) = {
     580             :     .path = "lisp map-request mode",
     581             :     .short_help = "lisp map-request mode dst-only|src-dst",
     582             :     .function = lisp_map_request_mode_command_fn,
     583             : };
     584             : /* *INDENT-ON* */
     585             : 
     586             : 
     587             : static u8 *
     588           0 : format_lisp_map_request_mode (u8 * s, va_list * args)
     589             : {
     590           0 :   u32 mode = va_arg (*args, u32);
     591             : 
     592           0 :   switch (mode)
     593             :     {
     594           0 :     case 0:
     595           0 :       return format (0, "dst-only");
     596           0 :     case 1:
     597           0 :       return format (0, "src-dst");
     598             :     }
     599           0 :   return 0;
     600             : }
     601             : 
     602             : static clib_error_t *
     603           0 : lisp_show_map_request_mode_command_fn (vlib_main_t * vm,
     604             :                                        unformat_input_t * input,
     605             :                                        vlib_cli_command_t * cmd)
     606             : {
     607           0 :   vlib_cli_output (vm, "map-request mode: %U", format_lisp_map_request_mode,
     608           0 :                    vnet_lisp_get_map_request_mode ());
     609           0 :   return 0;
     610             : }
     611             : 
     612             : /* *INDENT-OFF* */
     613      123991 : VLIB_CLI_COMMAND (lisp_show_map_request_mode_command) = {
     614             :     .path = "show lisp map-request mode",
     615             :     .short_help = "show lisp map-request mode",
     616             :     .function = lisp_show_map_request_mode_command_fn,
     617             : };
     618             : /* *INDENT-ON* */
     619             : 
     620             : static clib_error_t *
     621           0 : lisp_show_map_resolvers_command_fn (vlib_main_t * vm,
     622             :                                     unformat_input_t * input,
     623             :                                     vlib_cli_command_t * cmd)
     624             : {
     625             :   lisp_msmr_t *mr;
     626           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     627             : 
     628           0 :   vec_foreach (mr, lcm->map_resolvers)
     629             :   {
     630           0 :     vlib_cli_output (vm, "%U", format_ip_address, &mr->address);
     631             :   }
     632           0 :   return 0;
     633             : }
     634             : 
     635             : /* *INDENT-OFF* */
     636      123991 : VLIB_CLI_COMMAND (lisp_show_map_resolvers_command) = {
     637             :     .path = "show lisp map-resolvers",
     638             :     .short_help = "show lisp map-resolvers",
     639             :     .function = lisp_show_map_resolvers_command_fn,
     640             : };
     641             : /* *INDENT-ON* */
     642             : 
     643             : 
     644             : static clib_error_t *
     645           0 : lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
     646             :                                       unformat_input_t * input,
     647             :                                       vlib_cli_command_t * cmd)
     648             : {
     649           0 :   u8 locator_name_set = 0;
     650           0 :   u8 *locator_set_name = 0;
     651           0 :   u8 is_add = 1;
     652           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     653           0 :   clib_error_t *error = 0;
     654           0 :   int rv = 0;
     655             : 
     656             :   /* Get a line of input. */
     657           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     658           0 :     return 0;
     659             : 
     660           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     661             :     {
     662           0 :       if (unformat (line_input, "ls %_%v%_", &locator_set_name))
     663           0 :         locator_name_set = 1;
     664           0 :       else if (unformat (line_input, "disable"))
     665           0 :         is_add = 0;
     666             :       else
     667             :         {
     668           0 :           error = clib_error_return (0, "parse error");
     669           0 :           goto done;
     670             :         }
     671             :     }
     672             : 
     673           0 :   if (!locator_name_set)
     674             :     {
     675           0 :       clib_warning ("No locator set specified!");
     676           0 :       goto done;
     677             :     }
     678           0 :   vec_terminate_c_string (locator_set_name);
     679           0 :   rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
     680           0 :   if (0 != rv)
     681             :     {
     682           0 :       error = clib_error_return (0, "failed to %s pitr!",
     683             :                                  is_add ? "add" : "delete");
     684             :     }
     685             : 
     686           0 : done:
     687           0 :   if (locator_set_name)
     688           0 :     vec_free (locator_set_name);
     689           0 :   unformat_free (line_input);
     690             : 
     691           0 :   return error;
     692             : }
     693             : 
     694             : /* *INDENT-OFF* */
     695      123991 : VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = {
     696             :     .path = "lisp pitr",
     697             :     .short_help = "lisp pitr [disable] ls <locator-set-name>",
     698             :     .function = lisp_pitr_set_locator_set_command_fn,
     699             : };
     700             : /* *INDENT-ON* */
     701             : 
     702             : static clib_error_t *
     703           0 : lisp_show_pitr_command_fn (vlib_main_t * vm,
     704             :                            unformat_input_t * input, vlib_cli_command_t * cmd)
     705             : {
     706           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     707             :   mapping_t *m;
     708             :   locator_set_t *ls;
     709           0 :   u8 *tmp_str = 0;
     710           0 :   u8 status = lcm->flags & LISP_FLAG_PITR_MODE;
     711             : 
     712           0 :   vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : "");
     713             : 
     714           0 :   if (!status)
     715             :     {
     716           0 :       vlib_cli_output (vm, "%=20s", "disable");
     717           0 :       return 0;
     718             :     }
     719             : 
     720           0 :   if (~0 == lcm->pitr_map_index)
     721             :     {
     722           0 :       tmp_str = format (0, "N/A");
     723             :     }
     724             :   else
     725             :     {
     726           0 :       m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index);
     727           0 :       if (~0 != m->locator_set_index)
     728             :         {
     729           0 :           ls =
     730           0 :             pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index);
     731           0 :           tmp_str = format (0, "%s", ls->name);
     732             :         }
     733             :       else
     734             :         {
     735           0 :           tmp_str = format (0, "N/A");
     736             :         }
     737             :     }
     738           0 :   vec_add1 (tmp_str, 0);
     739             : 
     740           0 :   vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
     741             : 
     742           0 :   vec_free (tmp_str);
     743             : 
     744           0 :   return 0;
     745             : }
     746             : 
     747             : /* *INDENT-OFF* */
     748      123991 : VLIB_CLI_COMMAND (lisp_show_pitr_command) = {
     749             :     .path = "show lisp pitr",
     750             :     .short_help = "Show pitr",
     751             :     .function = lisp_show_pitr_command_fn,
     752             : };
     753             : /* *INDENT-ON* */
     754             : 
     755             : static u8 *
     756           0 : format_eid_entry (u8 * s, va_list * args)
     757             : {
     758           0 :   vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
     759           0 :   lisp_cp_main_t *lcm = va_arg (*args, lisp_cp_main_t *);
     760           0 :   mapping_t *mapit = va_arg (*args, mapping_t *);
     761           0 :   locator_set_t *ls = va_arg (*args, locator_set_t *);
     762           0 :   gid_address_t *gid = &mapit->eid;
     763           0 :   u32 ttl = mapit->ttl;
     764           0 :   u8 aut = mapit->authoritative;
     765             :   u32 *loc_index;
     766           0 :   u8 first_line = 1;
     767             :   u8 *loc;
     768             : 
     769           0 :   u8 *type = ls->local ? format (0, "local(%s)", ls->name)
     770           0 :     : format (0, "remote");
     771             : 
     772           0 :   if (vec_len (ls->locator_indices) == 0)
     773             :     {
     774           0 :       s = format (s, "%-35U%-30s%-20u%-u", format_gid_address, gid,
     775             :                   type, ttl, aut);
     776             :     }
     777             :   else
     778             :     {
     779           0 :       vec_foreach (loc_index, ls->locator_indices)
     780             :       {
     781           0 :         locator_t *l = pool_elt_at_index (lcm->locator_pool, loc_index[0]);
     782           0 :         if (l->local)
     783           0 :           loc = format (0, "%U", format_vnet_sw_if_index_name, vnm,
     784             :                         l->sw_if_index);
     785             :         else
     786           0 :           loc = format (0, "%U", format_ip_address,
     787             :                         &gid_address_ip (&l->address));
     788             : 
     789           0 :         if (first_line)
     790             :           {
     791           0 :             s = format (s, "%-35U%-20s%-30v%-20u%-u\n", format_gid_address,
     792             :                         gid, type, loc, ttl, aut);
     793           0 :             first_line = 0;
     794             :           }
     795             :         else
     796           0 :           s = format (s, "%55s%v\n", "", loc);
     797             :       }
     798             :     }
     799           0 :   return s;
     800             : }
     801             : 
     802             : static clib_error_t *
     803           0 : lisp_show_eid_table_command_fn (vlib_main_t * vm,
     804             :                                 unformat_input_t * input,
     805             :                                 vlib_cli_command_t * cmd)
     806             : {
     807           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
     808             :   mapping_t *mapit;
     809           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     810             :   u32 mi;
     811             :   gid_address_t eid;
     812           0 :   u8 print_all = 1;
     813           0 :   u8 filter = 0;
     814           0 :   clib_error_t *error = NULL;
     815             : 
     816           0 :   clib_memset (&eid, 0, sizeof (eid));
     817             : 
     818             :   /* Get a line of input. */
     819           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     820           0 :     return 0;
     821             : 
     822           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     823             :     {
     824           0 :       if (unformat (line_input, "eid %U", unformat_gid_address, &eid))
     825           0 :         print_all = 0;
     826           0 :       else if (unformat (line_input, "local"))
     827           0 :         filter = 1;
     828           0 :       else if (unformat (line_input, "remote"))
     829           0 :         filter = 2;
     830             :       else
     831             :         {
     832           0 :           error = clib_error_return (0, "parse error: '%U'",
     833             :                                      format_unformat_error, line_input);
     834           0 :           goto done;
     835             :         }
     836             :     }
     837             : 
     838           0 :   vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
     839             :                    "EID", "type", "locators", "ttl", "authoritative");
     840             : 
     841           0 :   if (print_all)
     842             :     {
     843             :       /* *INDENT-OFF* */
     844           0 :       pool_foreach (mapit, lcm->mapping_pool)
     845             :        {
     846           0 :         if (mapit->pitr_set)
     847           0 :           continue;
     848             : 
     849           0 :         locator_set_t * ls = pool_elt_at_index (lcm->locator_set_pool,
     850             :                                                 mapit->locator_set_index);
     851           0 :         if (filter && !((1 == filter && ls->local) ||
     852           0 :           (2 == filter && !ls->local)))
     853             :           {
     854           0 :             continue;
     855             :           }
     856           0 :         vlib_cli_output (vm, "%U", format_eid_entry, lcm->vnet_main,
     857             :                          lcm, mapit, ls);
     858             :       }
     859             :       /* *INDENT-ON* */
     860             :     }
     861             :   else
     862             :     {
     863           0 :       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
     864           0 :       if ((u32) ~ 0 == mi)
     865           0 :         goto done;
     866             : 
     867           0 :       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
     868           0 :       locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
     869             :                                              mapit->locator_set_index);
     870             : 
     871           0 :       if (filter && !((1 == filter && ls->local) ||
     872           0 :                       (2 == filter && !ls->local)))
     873             :         {
     874           0 :           goto done;
     875             :         }
     876             : 
     877           0 :       vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
     878             :                        lcm, mapit, ls);
     879             :     }
     880             : 
     881           0 : done:
     882           0 :   unformat_free (line_input);
     883             : 
     884           0 :   return error;
     885             : }
     886             : 
     887             : /* *INDENT-OFF* */
     888      123991 : VLIB_CLI_COMMAND (lisp_cp_show_eid_table_command) = {
     889             :     .path = "show lisp eid-table",
     890             :     .short_help = "show lisp eid-table [local|remote|eid <eid>]",
     891             :     .function = lisp_show_eid_table_command_fn,
     892             : };
     893             : /* *INDENT-ON* */
     894             : 
     895             : 
     896             : static clib_error_t *
     897           0 : lisp_enable_command_fn (vlib_main_t * vm, unformat_input_t * input,
     898             :                         vlib_cli_command_t * cmd)
     899             : {
     900           0 :   if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     901           0 :     return clib_error_return (0, "parse error: '%U'", format_unformat_error,
     902             :                               input);
     903             : 
     904           0 :   vnet_lisp_enable_disable (1);
     905             : 
     906           0 :   return 0;
     907             : }
     908             : 
     909             : /* *INDENT-OFF* */
     910      123991 : VLIB_CLI_COMMAND (lisp_cp_enable_command) = {
     911             :     .path = "lisp enable",
     912             :     .short_help = "lisp enable",
     913             :     .function = lisp_enable_command_fn,
     914             : };
     915             : /* *INDENT-ON* */
     916             : 
     917             : static clib_error_t *
     918           0 : lisp_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
     919             :                          vlib_cli_command_t * cmd)
     920             : {
     921           0 :   if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     922           0 :     return clib_error_return (0, "parse error: '%U'", format_unformat_error,
     923             :                               input);
     924             : 
     925           0 :   vnet_lisp_enable_disable (0);
     926             : 
     927           0 :   return 0;
     928             : }
     929             : 
     930             : /* *INDENT-OFF* */
     931      123991 : VLIB_CLI_COMMAND (lisp_cp_disable_command) = {
     932             :     .path = "lisp disable",
     933             :     .short_help = "lisp disable",
     934             :     .function = lisp_disable_command_fn,
     935             : };
     936             : /* *INDENT-ON* */
     937             : 
     938             : static clib_error_t *
     939           0 : lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
     940             :                                              unformat_input_t * input,
     941             :                                              vlib_cli_command_t * cmd)
     942             : {
     943           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     944           0 :   u8 is_enabled = 0;
     945           0 :   u8 is_set = 0;
     946           0 :   clib_error_t *error = NULL;
     947             : 
     948             :   /* Get a line of input. */
     949           0 :   if (!unformat_user (input, unformat_line_input, line_input))
     950           0 :     return clib_error_return (0, "expected enable | disable");
     951             : 
     952           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     953             :     {
     954           0 :       if (unformat (line_input, "enable"))
     955             :         {
     956           0 :           is_set = 1;
     957           0 :           is_enabled = 1;
     958             :         }
     959           0 :       else if (unformat (line_input, "disable"))
     960           0 :         is_set = 1;
     961             :       else
     962             :         {
     963           0 :           vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
     964             :                            line_input);
     965           0 :           goto done;
     966             :         }
     967             :     }
     968             : 
     969           0 :   if (!is_set)
     970             :     {
     971           0 :       vlib_cli_output (vm, "state not set!");
     972           0 :       goto done;
     973             :     }
     974             : 
     975           0 :   vnet_lisp_map_register_enable_disable (is_enabled);
     976             : 
     977           0 : done:
     978           0 :   unformat_free (line_input);
     979             : 
     980           0 :   return error;
     981             : }
     982             : 
     983             : /* *INDENT-OFF* */
     984      123991 : VLIB_CLI_COMMAND (lisp_map_register_enable_disable_command) = {
     985             :     .path = "lisp map-register",
     986             :     .short_help = "lisp map-register [enable|disable]",
     987             :     .function = lisp_map_register_enable_disable_command_fn,
     988             : };
     989             : /* *INDENT-ON* */
     990             : 
     991             : static clib_error_t *
     992           0 : lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
     993             :                                            unformat_input_t * input,
     994             :                                            vlib_cli_command_t * cmd)
     995             : {
     996           0 :   unformat_input_t _line_input, *line_input = &_line_input;
     997           0 :   u8 is_enabled = 0;
     998           0 :   u8 is_set = 0;
     999           0 :   clib_error_t *error = NULL;
    1000             : 
    1001             :   /* Get a line of input. */
    1002           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1003           0 :     return clib_error_return (0, "expected enable | disable");
    1004             : 
    1005           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1006             :     {
    1007           0 :       if (unformat (line_input, "enable"))
    1008             :         {
    1009           0 :           is_set = 1;
    1010           0 :           is_enabled = 1;
    1011             :         }
    1012           0 :       else if (unformat (line_input, "disable"))
    1013           0 :         is_set = 1;
    1014             :       else
    1015             :         {
    1016           0 :           vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
    1017             :                            line_input);
    1018           0 :           goto done;
    1019             :         }
    1020             :     }
    1021             : 
    1022           0 :   if (!is_set)
    1023             :     {
    1024           0 :       vlib_cli_output (vm, "state not set!");
    1025           0 :       goto done;
    1026             :     }
    1027             : 
    1028           0 :   vnet_lisp_rloc_probe_enable_disable (is_enabled);
    1029             : 
    1030           0 : done:
    1031           0 :   unformat_free (line_input);
    1032             : 
    1033           0 :   return error;
    1034             : }
    1035             : 
    1036             : /* *INDENT-OFF* */
    1037      123991 : VLIB_CLI_COMMAND (lisp_rloc_probe_enable_disable_command) = {
    1038             :     .path = "lisp rloc-probe",
    1039             :     .short_help = "lisp rloc-probe [enable|disable]",
    1040             :     .function = lisp_rloc_probe_enable_disable_command_fn,
    1041             : };
    1042             : /* *INDENT-ON* */
    1043             : 
    1044             : static u8 *
    1045           0 : format_lisp_status (u8 * s, va_list * args)
    1046             : {
    1047           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1048           0 :   return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled");
    1049             : }
    1050             : 
    1051             : static clib_error_t *
    1052           0 : lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input,
    1053             :                              vlib_cli_command_t * cmd)
    1054             : {
    1055           0 :   u8 *msg = 0;
    1056           0 :   msg = format (msg, "feature: %U\ngpe: %U\n",
    1057             :                 format_lisp_status, format_vnet_lisp_gpe_status);
    1058           0 :   vlib_cli_output (vm, "%v", msg);
    1059           0 :   vec_free (msg);
    1060           0 :   return 0;
    1061             : }
    1062             : 
    1063             : /* *INDENT-OFF* */
    1064      123991 : VLIB_CLI_COMMAND (lisp_show_status_command) = {
    1065             :     .path = "show lisp status",
    1066             :     .short_help = "show lisp status",
    1067             :     .function = lisp_show_status_command_fn,
    1068             : };
    1069             : /* *INDENT-ON* */
    1070             : 
    1071             : static clib_error_t *
    1072           0 : lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
    1073             :                                     unformat_input_t * input,
    1074             :                                     vlib_cli_command_t * cmd)
    1075             : {
    1076             :   hash_pair_t *p;
    1077           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1078           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1079           0 :   uword *vni_table = 0;
    1080           0 :   u8 is_l2 = 0;
    1081           0 :   clib_error_t *error = NULL;
    1082             : 
    1083             :   /* Get a line of input. */
    1084           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1085           0 :     return 0;
    1086             : 
    1087           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1088             :     {
    1089           0 :       if (unformat (line_input, "l2"))
    1090             :         {
    1091           0 :           vni_table = lcm->bd_id_by_vni;
    1092           0 :           is_l2 = 1;
    1093             :         }
    1094           0 :       else if (unformat (line_input, "l3"))
    1095             :         {
    1096           0 :           vni_table = lcm->table_id_by_vni;
    1097           0 :           is_l2 = 0;
    1098             :         }
    1099             :       else
    1100             :         {
    1101           0 :           error = clib_error_return (0, "parse error: '%U'",
    1102             :                                      format_unformat_error, line_input);
    1103           0 :           goto done;
    1104             :         }
    1105             :     }
    1106             : 
    1107           0 :   if (!vni_table)
    1108             :     {
    1109           0 :       vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
    1110           0 :       goto done;
    1111             :     }
    1112             : 
    1113           0 :   vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
    1114             : 
    1115             :   /* *INDENT-OFF* */
    1116           0 :   hash_foreach_pair (p, vni_table,
    1117             :   ({
    1118             :     vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
    1119             :   }));
    1120             :   /* *INDENT-ON* */
    1121             : 
    1122           0 : done:
    1123           0 :   unformat_free (line_input);
    1124             : 
    1125           0 :   return error;
    1126             : }
    1127             : 
    1128             : /* *INDENT-OFF* */
    1129      123991 : VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
    1130             :     .path = "show lisp eid-table map",
    1131             :     .short_help = "show lisp eid-table map l2|l3",
    1132             :     .function = lisp_show_eid_table_map_command_fn,
    1133             : };
    1134             : /* *INDENT-ON* */
    1135             : 
    1136             : 
    1137             : static clib_error_t *
    1138           0 : lisp_add_del_locator_set_command_fn (vlib_main_t * vm,
    1139             :                                      unformat_input_t * input,
    1140             :                                      vlib_cli_command_t * cmd)
    1141             : {
    1142           0 :   lisp_gpe_main_t *lgm = &lisp_gpe_main;
    1143           0 :   vnet_main_t *vnm = lgm->vnet_main;
    1144           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1145           0 :   u8 is_add = 1;
    1146           0 :   clib_error_t *error = 0;
    1147           0 :   u8 *locator_set_name = 0;
    1148           0 :   locator_t locator, *locators = 0;
    1149           0 :   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
    1150           0 :   u32 ls_index = 0;
    1151           0 :   int rv = 0;
    1152             : 
    1153           0 :   clib_memset (&locator, 0, sizeof (locator));
    1154           0 :   clib_memset (a, 0, sizeof (a[0]));
    1155             : 
    1156             :   /* Get a line of input. */
    1157           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1158           0 :     return clib_error_return (0, "missing parameters");
    1159             : 
    1160           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1161             :     {
    1162           0 :       if (unformat (line_input, "add %_%v%_", &locator_set_name))
    1163           0 :         is_add = 1;
    1164           0 :       else if (unformat (line_input, "del %_%v%_", &locator_set_name))
    1165           0 :         is_add = 0;
    1166           0 :       else if (unformat (line_input, "iface %U p %d w %d",
    1167             :                          unformat_vnet_sw_interface, vnm,
    1168             :                          &locator.sw_if_index, &locator.priority,
    1169             :                          &locator.weight))
    1170             :         {
    1171           0 :           locator.local = 1;
    1172           0 :           locator.state = 1;
    1173           0 :           vec_add1 (locators, locator);
    1174             :         }
    1175             :       else
    1176             :         {
    1177           0 :           error = unformat_parse_error (line_input);
    1178           0 :           goto done;
    1179             :         }
    1180             :     }
    1181             : 
    1182           0 :   vec_terminate_c_string (locator_set_name);
    1183           0 :   a->name = locator_set_name;
    1184           0 :   a->locators = locators;
    1185           0 :   a->is_add = is_add;
    1186           0 :   a->local = 1;
    1187             : 
    1188           0 :   rv = vnet_lisp_add_del_locator_set (a, &ls_index);
    1189           0 :   if (0 != rv)
    1190             :     {
    1191           0 :       error = clib_error_return (0, "failed to %s locator-set!",
    1192             :                                  is_add ? "add" : "delete");
    1193             :     }
    1194             : 
    1195           0 : done:
    1196           0 :   vec_free (locators);
    1197           0 :   if (locator_set_name)
    1198           0 :     vec_free (locator_set_name);
    1199           0 :   unformat_free (line_input);
    1200             : 
    1201           0 :   return error;
    1202             : }
    1203             : 
    1204             : /* *INDENT-OFF* */
    1205      123991 : VLIB_CLI_COMMAND (lisp_cp_add_del_locator_set_command) = {
    1206             :     .path = "lisp locator-set",
    1207             :     .short_help = "lisp locator-set add/del <name> [iface <iface-name> "
    1208             :         "p <priority> w <weight>]",
    1209             :     .function = lisp_add_del_locator_set_command_fn,
    1210             : };
    1211             : /* *INDENT-ON* */
    1212             : 
    1213             : static clib_error_t *
    1214           0 : lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
    1215             :                                         unformat_input_t * input,
    1216             :                                         vlib_cli_command_t * cmd)
    1217             : {
    1218           0 :   lisp_gpe_main_t *lgm = &lisp_gpe_main;
    1219           0 :   vnet_main_t *vnm = lgm->vnet_main;
    1220           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1221           0 :   u8 is_add = 1;
    1222           0 :   clib_error_t *error = 0;
    1223           0 :   u8 *locator_set_name = 0;
    1224           0 :   u8 locator_set_name_set = 0;
    1225           0 :   locator_t locator, *locators = 0;
    1226           0 :   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
    1227           0 :   u32 ls_index = 0;
    1228             : 
    1229           0 :   clib_memset (&locator, 0, sizeof (locator));
    1230           0 :   clib_memset (a, 0, sizeof (a[0]));
    1231             : 
    1232             :   /* Get a line of input. */
    1233           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1234           0 :     return 0;
    1235             : 
    1236           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1237             :     {
    1238           0 :       if (unformat (line_input, "add"))
    1239           0 :         is_add = 1;
    1240           0 :       else if (unformat (line_input, "del"))
    1241           0 :         is_add = 0;
    1242           0 :       else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
    1243           0 :         locator_set_name_set = 1;
    1244           0 :       else if (unformat (line_input, "iface %U p %d w %d",
    1245             :                          unformat_vnet_sw_interface, vnm,
    1246             :                          &locator.sw_if_index, &locator.priority,
    1247             :                          &locator.weight))
    1248             :         {
    1249           0 :           locator.local = 1;
    1250           0 :           vec_add1 (locators, locator);
    1251             :         }
    1252             :       else
    1253             :         {
    1254           0 :           error = unformat_parse_error (line_input);
    1255           0 :           goto done;
    1256             :         }
    1257             :     }
    1258             : 
    1259           0 :   if (!locator_set_name_set)
    1260             :     {
    1261           0 :       error = clib_error_return (0, "locator_set name not set!");
    1262           0 :       goto done;
    1263             :     }
    1264             : 
    1265           0 :   a->name = locator_set_name;
    1266           0 :   a->locators = locators;
    1267           0 :   a->is_add = is_add;
    1268           0 :   a->local = 1;
    1269             : 
    1270           0 :   vnet_lisp_add_del_locator (a, 0, &ls_index);
    1271             : 
    1272           0 : done:
    1273           0 :   vec_free (locators);
    1274           0 :   vec_free (locator_set_name);
    1275           0 :   unformat_free (line_input);
    1276             : 
    1277           0 :   return error;
    1278             : }
    1279             : 
    1280             : /* *INDENT-OFF* */
    1281      123991 : VLIB_CLI_COMMAND (lisp_cp_add_del_locator_in_set_command) = {
    1282             :     .path = "lisp locator",
    1283             :     .short_help = "lisp locator add/del locator-set <name> iface <iface-name> "
    1284             :                   "p <priority> w <weight>",
    1285             :     .function = lisp_add_del_locator_in_set_command_fn,
    1286             : };
    1287             : /* *INDENT-ON* */
    1288             : 
    1289             : static clib_error_t *
    1290           0 : lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
    1291             :                                       unformat_input_t * input,
    1292             :                                       vlib_cli_command_t * cmd)
    1293             : {
    1294             :   locator_set_t *lsit;
    1295             :   locator_t *loc;
    1296             :   u32 *locit;
    1297           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1298             : 
    1299           0 :   vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
    1300             :                    "Priority", "Weight");
    1301             : 
    1302             :   /* *INDENT-OFF* */
    1303           0 :   pool_foreach (lsit, lcm->locator_set_pool)
    1304             :    {
    1305           0 :     u8 * msg = 0;
    1306           0 :     int next_line = 0;
    1307           0 :     if (lsit->local)
    1308             :       {
    1309           0 :         msg = format (msg, "%v", lsit->name);
    1310             :       }
    1311             :     else
    1312             :       {
    1313           0 :         msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
    1314             :       }
    1315           0 :     vec_foreach (locit, lsit->locator_indices)
    1316             :       {
    1317           0 :         if (next_line)
    1318             :           {
    1319           0 :             msg = format (msg, "%16s", " ");
    1320             :           }
    1321           0 :         loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
    1322           0 :         if (loc->local)
    1323           0 :           msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority,
    1324           0 :                         loc->weight);
    1325             :         else
    1326           0 :           msg = format (msg, "%16U%16d%16d\n", format_ip_address,
    1327           0 :                         &gid_address_ip(&loc->address), loc->priority,
    1328           0 :                         loc->weight);
    1329           0 :         next_line = 1;
    1330             :       }
    1331           0 :     vlib_cli_output (vm, "%v", msg);
    1332           0 :     vec_free (msg);
    1333             :   }
    1334             :   /* *INDENT-ON* */
    1335           0 :   return 0;
    1336             : }
    1337             : 
    1338             : /* *INDENT-OFF* */
    1339      123991 : VLIB_CLI_COMMAND (lisp_cp_show_locator_sets_command) = {
    1340             :     .path = "show lisp locator-set",
    1341             :     .short_help = "Shows locator-sets",
    1342             :     .function = lisp_cp_show_locator_sets_command_fn,
    1343             : };
    1344             : /* *INDENT-ON* */
    1345             : 
    1346             : 
    1347             : static clib_error_t *
    1348           0 : lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
    1349             :                                       unformat_input_t * input,
    1350             :                                       vlib_cli_command_t * cmd)
    1351             : {
    1352           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1353           0 :   u8 is_add = 1, addr_set = 0;
    1354             :   ip_address_t ip_addr;
    1355           0 :   clib_error_t *error = 0;
    1356           0 :   int rv = 0;
    1357           0 :   vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a;
    1358             : 
    1359             :   /* Get a line of input. */
    1360           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1361           0 :     return 0;
    1362             : 
    1363           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1364             :     {
    1365           0 :       if (unformat (line_input, "add"))
    1366           0 :         is_add = 1;
    1367           0 :       else if (unformat (line_input, "del"))
    1368           0 :         is_add = 0;
    1369           0 :       else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr))
    1370           0 :         addr_set = 1;
    1371             :       else
    1372             :         {
    1373           0 :           error = unformat_parse_error (line_input);
    1374           0 :           goto done;
    1375             :         }
    1376             :     }
    1377             : 
    1378           0 :   if (!addr_set)
    1379             :     {
    1380           0 :       error = clib_error_return (0, "Map-resolver address must be set!");
    1381           0 :       goto done;
    1382             :     }
    1383             : 
    1384           0 :   a->is_add = is_add;
    1385           0 :   a->address = ip_addr;
    1386           0 :   rv = vnet_lisp_add_del_map_resolver (a);
    1387           0 :   if (0 != rv)
    1388             :     {
    1389           0 :       error = clib_error_return (0, "failed to %s map-resolver!",
    1390             :                                  is_add ? "add" : "delete");
    1391             :     }
    1392             : 
    1393           0 : done:
    1394           0 :   unformat_free (line_input);
    1395             : 
    1396           0 :   return error;
    1397             : }
    1398             : 
    1399             : /* *INDENT-OFF* */
    1400      123991 : VLIB_CLI_COMMAND (lisp_add_del_map_resolver_command) = {
    1401             :     .path = "lisp map-resolver",
    1402             :     .short_help = "lisp map-resolver add/del <ip_address>",
    1403             :     .function = lisp_add_del_map_resolver_command_fn,
    1404             : };
    1405             : /* *INDENT-ON* */
    1406             : 
    1407             : 
    1408             : static clib_error_t *
    1409           0 : lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
    1410             :                                         unformat_input_t * input,
    1411             :                                         vlib_cli_command_t * cmd)
    1412             : {
    1413           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1414           0 :   u8 is_add = 1;
    1415           0 :   u8 *locator_set_name = 0;
    1416           0 :   clib_error_t *error = 0;
    1417           0 :   int rv = 0;
    1418           0 :   vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a;
    1419             : 
    1420             :   /* Get a line of input. */
    1421           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1422           0 :     return 0;
    1423             : 
    1424           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1425             :     {
    1426           0 :       if (unformat (line_input, "del"))
    1427           0 :         is_add = 0;
    1428           0 :       else if (unformat (line_input, "add %_%v%_", &locator_set_name))
    1429           0 :         is_add = 1;
    1430             :       else
    1431             :         {
    1432           0 :           error = unformat_parse_error (line_input);
    1433           0 :           goto done;
    1434             :         }
    1435             :     }
    1436             : 
    1437           0 :   vec_terminate_c_string (locator_set_name);
    1438           0 :   a->is_add = is_add;
    1439           0 :   a->locator_set_name = locator_set_name;
    1440           0 :   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
    1441           0 :   if (0 != rv)
    1442             :     {
    1443           0 :       error = clib_error_return (0, "failed to %s map-request itr-rlocs!",
    1444             :                                  is_add ? "add" : "delete");
    1445             :     }
    1446             : 
    1447           0 : done:
    1448           0 :   vec_free (locator_set_name);
    1449           0 :   unformat_free (line_input);
    1450             : 
    1451           0 :   return error;
    1452             : }
    1453             : 
    1454             : /* *INDENT-OFF* */
    1455      123991 : VLIB_CLI_COMMAND (lisp_add_del_map_request_command) = {
    1456             :     .path = "lisp map-request itr-rlocs",
    1457             :     .short_help = "lisp map-request itr-rlocs add/del <locator_set_name>",
    1458             :     .function = lisp_add_del_mreq_itr_rlocs_command_fn,
    1459             : };
    1460             : /* *INDENT-ON* */
    1461             : 
    1462             : static clib_error_t *
    1463           0 : lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
    1464             :                                      unformat_input_t * input,
    1465             :                                      vlib_cli_command_t * cmd)
    1466             : {
    1467           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1468             :   locator_set_t *loc_set;
    1469             : 
    1470           0 :   vlib_cli_output (vm, "%=20s", "itr-rlocs");
    1471             : 
    1472           0 :   if (~0 == lcm->mreq_itr_rlocs)
    1473             :     {
    1474           0 :       return 0;
    1475             :     }
    1476             : 
    1477           0 :   loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs);
    1478             : 
    1479           0 :   vlib_cli_output (vm, "%=20s", loc_set->name);
    1480             : 
    1481           0 :   return 0;
    1482             : }
    1483             : 
    1484             : /* *INDENT-OFF* */
    1485      123991 : VLIB_CLI_COMMAND (lisp_show_map_request_command) = {
    1486             :     .path = "show lisp map-request itr-rlocs",
    1487             :     .short_help = "Shows map-request itr-rlocs",
    1488             :     .function = lisp_show_mreq_itr_rlocs_command_fn,
    1489             : };
    1490             : /* *INDENT-ON* */
    1491             : 
    1492             : static clib_error_t *
    1493           0 : lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
    1494             :                                           unformat_input_t * input,
    1495             :                                           vlib_cli_command_t * cmd)
    1496             : {
    1497           0 :   u8 is_add = 1, ip_set = 0;
    1498           0 :   unformat_input_t _line_input, *line_input = &_line_input;
    1499           0 :   clib_error_t *error = 0;
    1500             :   ip_address_t ip;
    1501             : 
    1502             :   /* Get a line of input. */
    1503           0 :   if (!unformat_user (input, unformat_line_input, line_input))
    1504           0 :     return 0;
    1505             : 
    1506           0 :   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    1507             :     {
    1508           0 :       if (unformat (line_input, "%U", unformat_ip_address, &ip))
    1509           0 :         ip_set = 1;
    1510           0 :       else if (unformat (line_input, "disable"))
    1511           0 :         is_add = 0;
    1512             :       else
    1513             :         {
    1514           0 :           error = clib_error_return (0, "parse error");
    1515           0 :           goto done;
    1516             :         }
    1517             :     }
    1518             : 
    1519           0 :   if (!ip_set)
    1520             :     {
    1521           0 :       clib_warning ("No petr IP specified!");
    1522           0 :       goto done;
    1523             :     }
    1524             : 
    1525           0 :   if (vnet_lisp_use_petr (&ip, is_add))
    1526             :     {
    1527           0 :       error = clib_error_return (0, "failed to %s petr!",
    1528             :                                  is_add ? "add" : "delete");
    1529             :     }
    1530             : 
    1531           0 : done:
    1532           0 :   unformat_free (line_input);
    1533             : 
    1534           0 :   return error;
    1535             : }
    1536             : 
    1537             : /* *INDENT-OFF* */
    1538      123991 : VLIB_CLI_COMMAND (lisp_use_petr_set_locator_set_command) = {
    1539             :     .path = "lisp use-petr",
    1540             :     .short_help = "lisp use-petr [disable] <petr-ip>",
    1541             :     .function = lisp_use_petr_set_locator_set_command_fn,
    1542             : };
    1543             : 
    1544             : static clib_error_t *
    1545           0 : lisp_show_petr_command_fn (vlib_main_t * vm,
    1546             :                            unformat_input_t * input, vlib_cli_command_t * cmd)
    1547             : {
    1548           0 :   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
    1549             :   mapping_t *m;
    1550             :   locator_set_t *ls;
    1551             :   locator_t *loc;
    1552           0 :   u8 *tmp_str = 0;
    1553           0 :   u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR;
    1554           0 :   vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : "");
    1555             : 
    1556           0 :   if (!use_petr)
    1557             :     {
    1558           0 :       vlib_cli_output (vm, "%=20s", "disable");
    1559           0 :       return 0;
    1560             :     }
    1561             : 
    1562           0 :   if (~0 == lcm->petr_map_index)
    1563             :     {
    1564           0 :       tmp_str = format (0, "N/A");
    1565             :     }
    1566             :   else
    1567             :     {
    1568           0 :       m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
    1569           0 :       if (~0 != m->locator_set_index)
    1570             :         {
    1571           0 :           ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index);
    1572           0 :           loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]);
    1573           0 :           tmp_str = format (0, "%U", format_ip_address, &loc->address);
    1574             :         }
    1575             :       else
    1576             :         {
    1577           0 :           tmp_str = format (0, "N/A");
    1578             :         }
    1579             :     }
    1580           0 :   vec_add1 (tmp_str, 0);
    1581             : 
    1582           0 :   vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str);
    1583             : 
    1584           0 :   vec_free (tmp_str);
    1585             : 
    1586           0 :   return 0;
    1587             : }
    1588             : 
    1589             : /* *INDENT-OFF* */
    1590      123991 : VLIB_CLI_COMMAND (lisp_show_petr_command) = {
    1591             :     .path = "show lisp petr",
    1592             :     .short_help = "Show petr",
    1593             :     .function = lisp_show_petr_command_fn,
    1594             : };
    1595             : /* *INDENT-ON* */
    1596             : 
    1597             : /*
    1598             :  * fd.io coding-style-patch-verification: ON
    1599             :  *
    1600             :  * Local Variables:
    1601             :  * eval: (c-set-style "gnu")
    1602             :  * End:
    1603             :  */

Generated by: LCOV version 1.14