LISP: add P-ITR/P-ETR/xTR API handlers, ONE-24
[vpp.git] / src / vnet / lisp-cp / lisp_cli.c
index a2088dd..07c1c2c 100644 (file)
@@ -25,6 +25,7 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm,
   vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
   unformat_input_t _line_input, *line_input = &_line_input;
   u32 vni = ~0;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -38,14 +39,14 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm,
        {
          vlib_cli_output (vm, "parse error: '%U'",
                           format_unformat_error, line_input);
-         return 0;
+         goto done;
        }
     }
 
   if (~0 == vni)
     {
       vlib_cli_output (vm, "error: no vni specified!");
-      return 0;
+      goto done;
     }
 
   adjs = vnet_lisp_adjacencies_get_by_vni (vni);
@@ -57,7 +58,10 @@ lisp_show_adjacencies_command_fn (vlib_main_t * vm,
   }
   vec_free (adjs);
 
-  return 0;
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -77,6 +81,7 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm,
   u8 is_add = 1, ip_set = 0;
   ip_address_t ip;
   unformat_input_t _line_input, *line_input = &_line_input;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -94,14 +99,14 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm,
        {
          vlib_cli_output (vm, "parse error: '%U'",
                           format_unformat_error, line_input);
-         return 0;
+         goto done;
        }
     }
 
   if (!ip_set)
     {
       vlib_cli_output (vm, "map-server ip address not set!");
-      return 0;
+      goto done;
     }
 
   rv = vnet_lisp_add_del_map_server (&ip, is_add);
@@ -109,7 +114,10 @@ lisp_add_del_map_server_command_fn (vlib_main_t * vm,
     vlib_cli_output (vm, "failed to %s map-server!",
                     is_add ? "add" : "delete");
 
-  return 0;
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -164,6 +172,7 @@ lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
        ;
       else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name))
        {
+         vec_terminate_c_string (locator_set_name);
          p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name);
          if (!p)
            {
@@ -191,7 +200,7 @@ lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input,
   if (key && (0 == key_id))
     {
       vlib_cli_output (vm, "invalid key_id!");
-      return 0;
+      goto done;;
     }
 
   gid_address_copy (&a->eid, &eid);
@@ -213,6 +222,8 @@ done:
     vec_free (locator_set_name);
   gid_address_free (&a->eid);
   vec_free (a->key);
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -233,6 +244,7 @@ lisp_eid_table_map_command_fn (vlib_main_t * vm,
   u8 is_add = 1, is_l2 = 0;
   u32 vni = 0, dp_id = 0;
   unformat_input_t _line_input, *line_input = &_line_input;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -250,11 +262,16 @@ lisp_eid_table_map_command_fn (vlib_main_t * vm,
        is_l2 = 1;
       else
        {
-         return unformat_parse_error (line_input);
+         error = unformat_parse_error (line_input);
+         goto done;
        }
     }
   vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add);
-  return 0;
+
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -378,8 +395,19 @@ lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
 
   /* add as static remote mapping, i.e., not authoritative and infinite
    * ttl */
-  rv = vnet_lisp_add_del_mapping (&eid, rlocs, action, 0, ~0, is_add,
-                                 1 /* is_static */ , 0);
+  if (is_add)
+    {
+      vnet_lisp_add_del_mapping_args_t _map_args, *map_args = &_map_args;
+      memset (map_args, 0, sizeof (map_args[0]));
+      gid_address_copy (&map_args->eid, &eid);
+      map_args->action = action;
+      map_args->is_static = 1;
+      map_args->authoritative = 0;
+      map_args->ttl = ~0;
+      rv = vnet_lisp_add_mapping (map_args, rlocs, NULL, NULL);
+    }
+  else
+    rv = vnet_lisp_del_mapping (&eid, NULL);
 
   if (rv)
     clib_warning ("failed to %s remote mapping!", is_add ? "add" : "delete");
@@ -479,7 +507,7 @@ lisp_add_del_adjacency_command_fn (vlib_main_t * vm, unformat_input_t * input,
          != ip_prefix_version (leid_ippref)))
     {
       clib_warning ("remote and local EIDs are of different types!");
-      return error;
+      goto done;
     }
 
   memset (a, 0, sizeof (a[0]));
@@ -512,6 +540,7 @@ lisp_map_request_mode_command_fn (vlib_main_t * vm,
 {
   unformat_input_t _i, *i = &_i;
   map_request_mode_t mr_mode = _MR_MODE_MAX;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, i))
@@ -533,12 +562,15 @@ lisp_map_request_mode_command_fn (vlib_main_t * vm,
   if (_MR_MODE_MAX == mr_mode)
     {
       clib_warning ("No LISP map request mode entered!");
-      return 0;
+      goto done;
     }
 
   vnet_lisp_set_map_request_mode (mr_mode);
+
 done:
-  return 0;
+  unformat_free (i);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -630,7 +662,10 @@ lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
       else if (unformat (line_input, "disable"))
        is_add = 0;
       else
-       return clib_error_return (0, "parse error");
+       {
+         error = clib_error_return (0, "parse error");
+         goto done;
+       }
     }
 
   if (!locator_name_set)
@@ -638,6 +673,7 @@ lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
       clib_warning ("No locator set specified!");
       goto done;
     }
+  vec_terminate_c_string (locator_set_name);
   rv = vnet_lisp_pitr_set_locator_set (locator_set_name, is_add);
   if (0 != rv)
     {
@@ -648,6 +684,8 @@ lisp_pitr_set_locator_set_command_fn (vlib_main_t * vm,
 done:
   if (locator_set_name)
     vec_free (locator_set_name);
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -667,11 +705,11 @@ lisp_show_pitr_command_fn (vlib_main_t * vm,
   mapping_t *m;
   locator_set_t *ls;
   u8 *tmp_str = 0;
+  u8 status = lcm->flags & LISP_FLAG_PITR_MODE;
 
-  vlib_cli_output (vm, "%=20s%=16s",
-                  "pitr", lcm->lisp_pitr ? "locator-set" : "");
+  vlib_cli_output (vm, "%=20s%=16s", "pitr", status ? "locator-set" : "");
 
-  if (!lcm->lisp_pitr)
+  if (!status)
     {
       vlib_cli_output (vm, "%=20s", "disable");
       return 0;
@@ -771,6 +809,7 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm,
   gid_address_t eid;
   u8 print_all = 1;
   u8 filter = 0;
+  clib_error_t *error = NULL;
 
   memset (&eid, 0, sizeof (eid));
 
@@ -787,8 +826,11 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm,
       else if (unformat (line_input, "remote"))
        filter = 2;
       else
-       return clib_error_return (0, "parse error: '%U'",
-                                 format_unformat_error, line_input);
+       {
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
   vlib_cli_output (vm, "%-35s%-20s%-30s%-20s%-s",
@@ -818,7 +860,7 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm,
     {
       mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, &eid);
       if ((u32) ~ 0 == mi)
-       return 0;
+       goto done;
 
       mapit = pool_elt_at_index (lcm->mapping_pool, mi);
       locator_set_t *ls = pool_elt_at_index (lcm->locator_set_pool,
@@ -827,14 +869,17 @@ lisp_show_eid_table_command_fn (vlib_main_t * vm,
       if (filter && !((1 == filter && ls->local) ||
                      (2 == filter && !ls->local)))
        {
-         return 0;
+         goto done;
        }
 
       vlib_cli_output (vm, "%U,", format_eid_entry, lcm->vnet_main,
                       lcm, mapit, ls);
     }
 
-  return 0;
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -853,6 +898,7 @@ lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
   unformat_input_t _line_input, *line_input = &_line_input;
   u8 is_enabled = 0;
   u8 is_set = 0;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -869,16 +915,24 @@ lisp_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input,
        is_set = 1;
       else
        {
-         return clib_error_return (0, "parse error: '%U'",
-                                   format_unformat_error, line_input);
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
        }
     }
 
   if (!is_set)
-    return clib_error_return (0, "state not set");
+    {
+      error = clib_error_return (0, "state not set");
+      goto done;
+    }
 
   vnet_lisp_enable_disable (is_enabled);
-  return 0;
+
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -897,6 +951,7 @@ lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
   unformat_input_t _line_input, *line_input = &_line_input;
   u8 is_enabled = 0;
   u8 is_set = 0;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -915,18 +970,22 @@ lisp_map_register_enable_disable_command_fn (vlib_main_t * vm,
        {
          vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
                           line_input);
-         return 0;
+         goto done;
        }
     }
 
   if (!is_set)
     {
       vlib_cli_output (vm, "state not set!");
-      return 0;
+      goto done;
     }
 
   vnet_lisp_map_register_enable_disable (is_enabled);
-  return 0;
+
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -945,6 +1004,7 @@ lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
   unformat_input_t _line_input, *line_input = &_line_input;
   u8 is_enabled = 0;
   u8 is_set = 0;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -963,18 +1023,22 @@ lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm,
        {
          vlib_cli_output (vm, "parse error: '%U'", format_unformat_error,
                           line_input);
-         return 0;
+         goto done;
        }
     }
 
   if (!is_set)
     {
       vlib_cli_output (vm, "state not set!");
-      return 0;
+      goto done;
     }
 
   vnet_lisp_rloc_probe_enable_disable (is_enabled);
-  return 0;
+
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -1022,6 +1086,7 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
   uword *vni_table = 0;
   u8 is_l2 = 0;
+  clib_error_t *error = NULL;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -1040,14 +1105,17 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
          is_l2 = 0;
        }
       else
-       return clib_error_return (0, "parse error: '%U'",
-                                 format_unformat_error, line_input);
+       {
+         error = clib_error_return (0, "parse error: '%U'",
+                                    format_unformat_error, line_input);
+         goto done;
+       }
     }
 
   if (!vni_table)
     {
       vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
-      return 0;
+      goto done;
     }
 
   vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
@@ -1059,7 +1127,10 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
   }));
   /* *INDENT-ON* */
 
-  return 0;
+done:
+  unformat_free (line_input);
+
+  return error;
 }
 
 /* *INDENT-OFF* */
@@ -1131,6 +1202,8 @@ done:
   vec_free (locators);
   if (locator_set_name)
     vec_free (locator_set_name);
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -1205,6 +1278,8 @@ lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm,
 done:
   vec_free (locators);
   vec_free (locator_set_name);
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -1322,6 +1397,8 @@ lisp_add_del_map_resolver_command_fn (vlib_main_t * vm,
     }
 
 done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -1363,6 +1440,7 @@ lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
        }
     }
 
+  vec_terminate_c_string (locator_set_name);
   a->is_add = is_add;
   a->locator_set_name = locator_set_name;
   rv = vnet_lisp_add_del_mreq_itr_rlocs (a);
@@ -1372,11 +1450,11 @@ lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm,
                                 is_add ? "add" : "delete");
     }
 
+done:
   vec_free (locator_set_name);
+  unformat_free (line_input);
 
-done:
   return error;
-
 }
 
 /* *INDENT-OFF* */
@@ -1438,7 +1516,10 @@ lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
       else if (unformat (line_input, "disable"))
        is_add = 0;
       else
-       return clib_error_return (0, "parse error");
+       {
+         error = clib_error_return (0, "parse error");
+         goto done;
+       }
     }
 
   if (!ip_set)
@@ -1454,6 +1535,8 @@ lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm,
     }
 
 done:
+  unformat_free (line_input);
+
   return error;
 }
 
@@ -1515,10 +1598,8 @@ VLIB_CLI_COMMAND (lisp_show_petr_command) = {
     .short_help = "Show petr",
     .function = lisp_show_petr_command_fn,
 };
-
 /* *INDENT-ON* */
 
-/* *INDENT-ON* */
 /*
  * fd.io coding-style-patch-verification: ON
  *