tcp: make syn-rcvd timeout configurable
[vpp.git] / src / plugins / ikev2 / ikev2_cli.c
index ad9ae60..975774c 100644 (file)
@@ -15,7 +15,6 @@
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
 #include <vppinfra/error.h>
-#include <vnet/udp/udp.h>
 #include <vnet/ipsec/ipsec_sa.h>
 #include <plugins/ikev2/ikev2.h>
 #include <plugins/ikev2/ikev2_priv.h>
@@ -28,18 +27,24 @@ format_ikev2_id_type_and_data (u8 * s, va_list * args)
   if (id->type == 0 || vec_len (id->data) == 0)
     return format (s, "none");
 
-  s = format (s, "%U", format_ikev2_id_type, id->type);
+  s = format (s, "id-type %U data ", format_ikev2_id_type, id->type);
 
-  if (id->type == IKEV2_ID_TYPE_ID_FQDN ||
-      id->type == IKEV2_ID_TYPE_ID_RFC822_ADDR)
+  switch (id->type)
     {
-      s = format (s, " %v", id->data);
-    }
-  else
-    {
-      s =
-       format (s, " %U", format_hex_bytes, &id->data,
-               (uword) (vec_len (id->data)));
+    case IKEV2_ID_TYPE_ID_IPV4_ADDR:
+      s = format (s, "%U", format_ip4_address, id->data);
+      break;
+    case IKEV2_ID_TYPE_ID_IPV6_ADDR:
+      s = format (s, "%U", format_ip6_address, id->data);
+      break;
+    case IKEV2_ID_TYPE_ID_FQDN:        /* fallthrough */
+    case IKEV2_ID_TYPE_ID_RFC822_ADDR:
+      s = format (s, "%v", id->data);
+      break;
+    default:
+      s = format (s, "0x%U", format_hex_bytes, &id->data,
+                 (uword) (vec_len (id->data)));
+      break;
     }
 
   return s;
@@ -69,12 +74,16 @@ format_ikev2_child_sa (u8 * s, va_list * va)
   ikev2_ts_t *ts;
   ikev2_sa_transform_t *tr;
   u8 *c = 0;
+  vlib_main_t *vm = vlib_get_main ();
 
   u32 indent = format_get_indent (s);
   indent += 1;
 
   s = format (s, "child sa %u:", index);
 
+  s = format (s, "\n    uptime: %f (s)\n    ",
+             vlib_time_now (vm) - child->timestamp);
+
   tr = ikev2_sa_get_td_for_type (child->r_proposals,
                                 IKEV2_TRANSFORM_TYPE_ENCR);
   c = format (c, "%U ", format_ikev2_sa_transform, tr);
@@ -116,6 +125,12 @@ format_ikev2_child_sa (u8 * s, va_list * va)
   return s;
 }
 
+static char *stateNames[] = {
+#define _(v, f, s) s,
+  foreach_ikev2_state
+#undef _
+};
+
 static u8 *
 format_ikev2_sa (u8 * s, va_list * va)
 {
@@ -124,6 +139,12 @@ format_ikev2_sa (u8 * s, va_list * va)
   ikev2_sa_transform_t *tr;
   ikev2_child_sa_t *child;
   u32 indent = 1;
+  vlib_main_t *vm = vlib_get_main ();
+
+  ikev2_main_t *km = &ikev2_main;
+  ikev2_profile_t *p;
+
+  p = pool_elt_at_index (km->profiles, sa->profile_index);
 
   s = format (s, "iip %U ispi %lx rip %U rspi %lx",
              format_ip_address, &sa->iaddr, sa->ispi,
@@ -145,6 +166,16 @@ format_ikev2_sa (u8 * s, va_list * va)
   tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
   s = format (s, "%U", format_ikev2_sa_transform, tr);
 
+  s = format (s, "\n profile: %v", p->name);
+
+  if (sa->state <= IKEV2_STATE_NO_PROPOSAL_CHOSEN)
+    {
+      s = format (s, "\n state: %s", stateNames[sa->state]);
+    }
+
+  s =
+    format (s, "\n uptime: %f (s)\n", vlib_time_now (vm) - sa->auth_timestamp);
+
   s = format (s, "\n%U", format_white_space, indent);
 
   s = format (s, "nonce i:%U\n%Ur:%U\n",
@@ -186,6 +217,14 @@ format_ikev2_sa (u8 * s, va_list * va)
                format_ikev2_child_sa, child, child - sa->childs);
   }
 
+  s = format (s, "Stats:\n");
+  s = format (s, " keepalives :%u\n", sa->stats.n_keepalives);
+  s = format (s, " rekey :%u\n", sa->stats.n_rekey_req);
+  s = format (s, " SA init :%u (retransmit: %u)\n", sa->stats.n_sa_init_req,
+             sa->stats.n_init_retransmit);
+  s = format (s, " retransmit: %u\n", sa->stats.n_retransmit);
+  s = format (s, " SA auth :%u\n", sa->stats.n_sa_auth_req);
+
   return s;
 }
 
@@ -219,8 +258,7 @@ show_ikev2_sa_command_fn (vlib_main_t * vm,
 
   vec_foreach (tkm, km->per_thread_data)
   {
-    /* *INDENT-OFF* */
-    pool_foreach (sa, tkm->sas, ({
+    pool_foreach (sa, tkm->sas)  {
       if (show_one)
         {
           if (sa->rspi == rspi)
@@ -231,8 +269,7 @@ show_ikev2_sa_command_fn (vlib_main_t * vm,
         }
       else
         s = format (s, "%U\n", format_ikev2_sa, sa, details);
-    }));
-    /* *INDENT-ON* */
+    }
   }
 
   vlib_cli_output (vm, "%v", s);
@@ -240,13 +277,26 @@ show_ikev2_sa_command_fn (vlib_main_t * vm,
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_ikev2_sa_command, static) = {
     .path = "show ikev2 sa",
     .short_help = "show ikev2 sa [rspi <rspi>] [details]",
     .function = show_ikev2_sa_command_fn,
 };
-/* *INDENT-ON* */
+
+static clib_error_t *
+ikev2_disable_dpd_command_fn (vlib_main_t * vm,
+                             unformat_input_t * input,
+                             vlib_cli_command_t * cmd)
+{
+  ikev2_disable_dpd ();
+  return 0;
+}
+
+VLIB_CLI_COMMAND (ikev2_cli_disable_dpd_command, static) = {
+  .path = "ikev2 dpd disable",
+  .short_help = "ikev2 dpd disable",
+  .function = ikev2_disable_dpd_command_fn,
+};
 
 static uword
 unformat_ikev2_token (unformat_input_t * input, va_list * va)
@@ -414,6 +464,15 @@ ikev2_profile_add_del_command_fn (vlib_main_t * vm,
            ikev2_set_profile_responder (vm, name, responder_sw_if_index, ip);
          goto done;
        }
+      else if (unformat (line_input, "set %U responder %U %v",
+                        unformat_ikev2_token, &name,
+                        unformat_vnet_sw_interface, vnm,
+                        &responder_sw_if_index, &data))
+       {
+         r = ikev2_set_profile_responder_hostname (vm, name, data,
+                                                   responder_sw_if_index);
+         goto done;
+       }
       else if (unformat (line_input, "set %U tunnel %U",
                         unformat_ikev2_token, &name,
                         unformat_vnet_sw_interface, vnm, &tun_sw_if_index))
@@ -494,6 +553,12 @@ ikev2_profile_add_del_command_fn (vlib_main_t * vm,
            r = clib_error_return (0, "Error: %U", format_vnet_api_errno, rv);
          goto done;
        }
+      else if (unformat (line_input, "set %U disable natt",
+                        unformat_ikev2_token, &name))
+       {
+         r = ikev2_profile_natt_disable (name);
+         goto done;
+       }
       else
        break;
     }
@@ -508,7 +573,6 @@ done:
   return r;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
     .path = "ikev2 profile",
     .short_help =
@@ -525,10 +589,10 @@ VLIB_CLI_COMMAND (ikev2_profile_add_del_command, static) = {
     "ikev2 profile set <id> ike-crypto-alg <crypto alg> <key size> ike-integ-alg <integ alg> ike-dh <dh type>\n"
     "ikev2 profile set <id> esp-crypto-alg <crypto alg> <key size> "
       "[esp-integ-alg <integ alg>]\n"
-    "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>",
+    "ikev2 profile set <id> sa-lifetime <seconds> <jitter> <handover> <max bytes>"
+    "ikev2 profile set <id> disable natt\n",
     .function = ikev2_profile_add_del_command_fn,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 show_ikev2_profile_command_fn (vlib_main_t * vm,
@@ -538,8 +602,7 @@ show_ikev2_profile_command_fn (vlib_main_t * vm,
   ikev2_main_t *km = &ikev2_main;
   ikev2_profile_t *p;
 
-  /* *INDENT-OFF* */
-  pool_foreach (p, km->profiles, ({
+  pool_foreach (p, km->profiles)  {
     vlib_cli_output(vm, "profile %v", p->name);
 
     if (p->auth.data)
@@ -554,36 +617,10 @@ show_ikev2_profile_command_fn (vlib_main_t * vm,
       }
 
     if (p->loc_id.data)
-      {
-        if (p->loc_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
-          vlib_cli_output(vm, "  local id-type %U data %U",
-                          format_ikev2_id_type, p->loc_id.type,
-                          format_ip_address, p->loc_id.data);
-        else if (p->loc_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
-          vlib_cli_output(vm, "  local id-type %U data 0x%U",
-                          format_ikev2_id_type, p->loc_id.type,
-                          format_hex_bytes, p->loc_id.data,
-                          vec_len(p->loc_id.data));
-        else
-          vlib_cli_output(vm, "  local id-type %U data %v",
-                          format_ikev2_id_type, p->loc_id.type, p->loc_id.data);
-      }
+      vlib_cli_output(vm, "  local %U", format_ikev2_id_type_and_data, &p->loc_id);
 
     if (p->rem_id.data)
-      {
-        if (p->rem_id.type == IKEV2_ID_TYPE_ID_IPV4_ADDR)
-          vlib_cli_output(vm, "  remote id-type %U data %U",
-                          format_ikev2_id_type, p->rem_id.type,
-                          format_ip_address, p->rem_id.data);
-        else if (p->rem_id.type == IKEV2_ID_TYPE_ID_KEY_ID)
-          vlib_cli_output(vm, "  remote id-type %U data 0x%U",
-                          format_ikev2_id_type, p->rem_id.type,
-                          format_hex_bytes, p->rem_id.data,
-                          vec_len(p->rem_id.data));
-        else
-          vlib_cli_output(vm, "  remote id-type %U data %v",
-                          format_ikev2_id_type, p->rem_id.type, p->rem_id.data);
-      }
+      vlib_cli_output(vm, "  remote %U", format_ikev2_id_type_and_data, &p->rem_id);
 
     if (!ip_address_is_zero (&p->loc_ts.start_addr))
       vlib_cli_output(vm, "  local traffic-selector addr %U - %U port %u - %u"
@@ -604,12 +641,16 @@ show_ikev2_profile_command_fn (vlib_main_t * vm,
       vlib_cli_output(vm, "  protected tunnel %U",
                       format_vnet_sw_if_index_name, vnet_get_main(), p->tun_itf);
     if (~0 != p->responder.sw_if_index)
-      vlib_cli_output(vm, "  responder %U %U",
-                      format_vnet_sw_if_index_name, vnet_get_main(), p->responder.sw_if_index,
-                      format_ip_address, &p->responder.addr);
+      vlib_cli_output (vm, "  responder %U %U %v",
+                      format_vnet_sw_if_index_name, vnet_get_main (),
+                      p->responder.sw_if_index, format_ip_address,
+                      &p->responder.addr, p->responder.hostname);
     if (p->udp_encap)
       vlib_cli_output(vm, "  udp-encap");
 
+    if (p->natt_disabled)
+      vlib_cli_output(vm, "  NAT-T disabled");
+
     if (p->ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
       vlib_cli_output(vm, "  ipsec-over-udp port %d", p->ipsec_over_udp_port);
 
@@ -626,19 +667,16 @@ show_ikev2_profile_command_fn (vlib_main_t * vm,
 
     vlib_cli_output(vm, "  lifetime %d jitter %d handover %d maxdata %d",
                     p->lifetime, p->lifetime_jitter, p->handover, p->lifetime_maxdata);
-  }));
-  /* *INDENT-ON* */
+  }
 
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_ikev2_profile_command, static) = {
     .path = "show ikev2 profile",
     .short_help = "show ikev2 profile",
     .function = show_ikev2_profile_command_fn,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 set_ikev2_liveness_period_fn (vlib_main_t * vm,
@@ -671,13 +709,11 @@ done:
   return r;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (set_ikev2_liveness_command, static) = {
   .path = "ikev2 set liveness",
   .short_help = "ikev2 set liveness <period> <max-retires>",
   .function = set_ikev2_liveness_period_fn,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 set_ikev2_local_key_command_fn (vlib_main_t * vm,
@@ -711,14 +747,12 @@ done:
   return r;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (set_ikev2_local_key_command, static) = {
     .path = "set ikev2 local key",
     .short_help =
     "set ikev2 local key <file>",
     .function = set_ikev2_local_key_command_fn,
 };
-/* *INDENT-ON* */
 
 
 static clib_error_t *
@@ -769,22 +803,15 @@ done:
   return r;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (ikev2_initiate_command, static) = {
     .path = "ikev2 initiate",
     .short_help =
         "ikev2 initiate sa-init <profile id>\n"
         "ikev2 initiate del-child-sa <child sa ispi>\n"
         "ikev2 initiate del-sa <sa ispi>\n"
-        "ikev2 initiate rekey-child-sa <profile id> <child sa ispi>\n",
+        "ikev2 initiate rekey-child-sa <child sa ispi>\n",
     .function = ikev2_initiate_command_fn,
 };
-/* *INDENT-ON* */
-
-void
-ikev2_cli_reference (void)
-{
-}
 
 static clib_error_t *
 ikev2_set_log_level_command_fn (vlib_main_t * vm,
@@ -814,13 +841,11 @@ done:
   return error;
 }
 
-/* *INDENT-OFF* */
 VLIB_CLI_COMMAND (ikev2_set_log_level_command, static) = {
   .path = "ikev2 set logging level",
   .function = ikev2_set_log_level_command_fn,
   .short_help = "ikev2 set logging level <0-5>",
 };
-/* *INDENT-ON* */
 
 /*
  * fd.io coding-style-patch-verification: ON