ipsec: api cleanup
[vpp.git] / src / vnet / ipsec / ipsec_api.c
index a3e0545..a0c2768 100644 (file)
 #include <vnet/fib/fib.h>
 #include <vnet/ipip/ipip.h>
 #include <vnet/tunnel/tunnel_types_api.h>
-
-#include <vnet/vnet_msg_enum.h>
-
-#if WITH_LIBSSL > 0
 #include <vnet/ipsec/ipsec.h>
 #include <vnet/ipsec/ipsec_tun.h>
 #include <vnet/ipsec/ipsec_itf.h>
-#endif /* IPSEC */
-
-#define vl_typedefs            /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
 
-#define vl_endianfun           /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vnet/vnet_all_api_h.h>
-#undef vl_printfun
+#include <vnet/format_fns.h>
+#include <vnet/ipsec/ipsec.api_enum.h>
+#include <vnet/ipsec/ipsec.api_types.h>
 
+#define REPLY_MSG_ID_BASE ipsec_main.msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-#define foreach_vpe_api_msg                                                   \
-  _ (IPSEC_SPD_ADD_DEL, ipsec_spd_add_del)                                    \
-  _ (IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd)                \
-  _ (IPSEC_SPD_ENTRY_ADD_DEL, ipsec_spd_entry_add_del)                        \
-  _ (IPSEC_SAD_ENTRY_ADD_DEL, ipsec_sad_entry_add_del)                        \
-  _ (IPSEC_SAD_ENTRY_ADD_DEL_V2, ipsec_sad_entry_add_del_v2)                  \
-  _ (IPSEC_SAD_ENTRY_ADD_DEL_V3, ipsec_sad_entry_add_del_v3)                  \
-  _ (IPSEC_SA_DUMP, ipsec_sa_dump)                                            \
-  _ (IPSEC_SA_V2_DUMP, ipsec_sa_v2_dump)                                      \
-  _ (IPSEC_SA_V3_DUMP, ipsec_sa_v3_dump)                                      \
-  _ (IPSEC_SPDS_DUMP, ipsec_spds_dump)                                        \
-  _ (IPSEC_SPD_DUMP, ipsec_spd_dump)                                          \
-  _ (IPSEC_SPD_INTERFACE_DUMP, ipsec_spd_interface_dump)                      \
-  _ (IPSEC_ITF_CREATE, ipsec_itf_create)                                      \
-  _ (IPSEC_ITF_DELETE, ipsec_itf_delete)                                      \
-  _ (IPSEC_ITF_DUMP, ipsec_itf_dump)                                          \
-  _ (IPSEC_SELECT_BACKEND, ipsec_select_backend)                              \
-  _ (IPSEC_BACKEND_DUMP, ipsec_backend_dump)                                  \
-  _ (IPSEC_TUNNEL_PROTECT_UPDATE, ipsec_tunnel_protect_update)                \
-  _ (IPSEC_TUNNEL_PROTECT_DEL, ipsec_tunnel_protect_del)                      \
-  _ (IPSEC_TUNNEL_PROTECT_DUMP, ipsec_tunnel_protect_dump)                    \
-  _ (IPSEC_SET_ASYNC_MODE, ipsec_set_async_mode)
-
 static void
 vl_api_ipsec_spd_add_del_t_handler (vl_api_ipsec_spd_add_del_t * mp)
 {
-#if WITH_LIBSSL == 0
-  clib_warning ("unimplemented");
-#else
-
   vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
   vl_api_ipsec_spd_add_del_reply_t *rmp;
   int rv;
@@ -91,7 +50,6 @@ vl_api_ipsec_spd_add_del_t_handler (vl_api_ipsec_spd_add_del_t * mp)
   rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
 
   REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
-#endif
 }
 
 static void vl_api_ipsec_interface_add_del_spd_t_handler
@@ -108,11 +66,7 @@ static void vl_api_ipsec_interface_add_del_spd_t_handler
 
   VALIDATE_SW_IF_INDEX (mp);
 
-#if WITH_LIBSSL > 0
   rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
 
   BAD_SW_IF_INDEX_LABEL;
 
@@ -132,8 +86,6 @@ static void vl_api_ipsec_tunnel_protect_update_t_handler
 
   VALIDATE_SW_IF_INDEX (&(mp->tunnel));
 
-#if WITH_LIBSSL > 0
-
   for (ii = 0; ii < mp->tunnel.n_sa_in; ii++)
     vec_add1 (sa_ins, ntohl (mp->tunnel.sa_in[ii]));
 
@@ -141,9 +93,6 @@ static void vl_api_ipsec_tunnel_protect_update_t_handler
 
   rv = ipsec_tun_protect_update (sw_if_index, &nh,
                                 ntohl (mp->tunnel.sa_out), sa_ins);
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
 
   BAD_SW_IF_INDEX_LABEL;
 
@@ -163,12 +112,8 @@ static void vl_api_ipsec_tunnel_protect_del_t_handler
 
   VALIDATE_SW_IF_INDEX (mp);
 
-#if WITH_LIBSSL > 0
   ip_address_decode2 (&mp->nh, &nh);
   rv = ipsec_tun_protect_del (sw_if_index, &nh);
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
 
   BAD_SW_IF_INDEX_LABEL;
 
@@ -194,7 +139,8 @@ send_ipsec_tunnel_protect_details (index_t itpi, void *arg)
 
   mp = vl_msg_api_alloc (sizeof (*mp) + (sizeof (u32) * itp->itp_n_sa_in));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_TUNNEL_PROTECT_DETAILS);
+  mp->_vl_msg_id =
+    ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_TUNNEL_PROTECT_DETAILS);
   mp->context = ctx->context;
 
   mp->tun.sw_if_index = htonl (itp->itp_sw_if_index);
@@ -222,7 +168,6 @@ vl_api_ipsec_tunnel_protect_dump_t_handler (vl_api_ipsec_tunnel_protect_dump_t
   vl_api_registration_t *reg;
   u32 sw_if_index;
 
-#if WITH_LIBSSL > 0
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -243,9 +188,6 @@ vl_api_ipsec_tunnel_protect_dump_t_handler (vl_api_ipsec_tunnel_protect_dump_t
       ipsec_tun_protect_walk_itf (sw_if_index,
                                  send_ipsec_tunnel_protect_details, &ctx);
     }
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static int
@@ -276,7 +218,6 @@ static void vl_api_ipsec_spd_entry_add_del_t_handler
 
   stat_index = ~0;
 
-#if WITH_LIBSSL > 0
   ipsec_policy_t p;
 
   clib_memset (&p, 0, sizeof (p));
@@ -320,11 +261,6 @@ static void vl_api_ipsec_spd_entry_add_del_t_handler
   if (rv)
     goto out;
 
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-  goto out;
-#endif
-
 out:
   /* *INDENT-OFF* */
   REPLY_MACRO2 (VL_API_IPSEC_SPD_ENTRY_ADD_DEL_REPLY,
@@ -354,8 +290,6 @@ static void vl_api_ipsec_sad_entry_add_del_t_handler
   };
   int rv;
 
-#if WITH_LIBSSL > 0
-
   id = ntohl (mp->entry.sad_id);
   spi = ntohl (mp->entry.spi);
 
@@ -390,10 +324,6 @@ static void vl_api_ipsec_sad_entry_add_del_t_handler
   else
     rv = ipsec_sa_unlock_id (id);
 
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
-
 out:
   /* *INDENT-OFF* */
   REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_REPLY,
@@ -424,8 +354,6 @@ static void vl_api_ipsec_sad_entry_add_del_v2_t_handler
     .t_hop_limit = 255,
   };
 
-#if WITH_LIBSSL > 0
-
   id = ntohl (mp->entry.sad_id);
   spi = ntohl (mp->entry.spi);
 
@@ -467,10 +395,6 @@ static void vl_api_ipsec_sad_entry_add_del_v2_t_handler
   else
     rv = ipsec_sa_unlock_id (id);
 
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
-
 out:
   /* *INDENT-OFF* */
   REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_V2_REPLY,
@@ -494,8 +418,6 @@ vl_api_ipsec_sad_entry_add_del_v3_t_handler (
   tunnel_t tun;
   int rv;
 
-#if WITH_LIBSSL > 0
-
   id = ntohl (mp->entry.sad_id);
   spi = ntohl (mp->entry.spi);
 
@@ -535,10 +457,6 @@ vl_api_ipsec_sad_entry_add_del_v3_t_handler (
   else
     rv = ipsec_sa_unlock_id (id);
 
-#else
-  rv = VNET_API_ERROR_UNIMPLEMENTED;
-#endif
-
 out:
   REPLY_MACRO2 (VL_API_IPSEC_SAD_ENTRY_ADD_DEL_V3_REPLY,
                { rmp->stat_index = htonl (sa_index); });
@@ -553,7 +471,7 @@ send_ipsec_spds_details (ipsec_spd_t * spd, vl_api_registration_t * reg,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SPDS_DETAILS);
   mp->context = context;
 
   mp->spd_id = htonl (spd->id);
@@ -571,19 +489,14 @@ vl_api_ipsec_spds_dump_t_handler (vl_api_ipsec_spds_dump_t * mp)
   vl_api_registration_t *reg;
   ipsec_main_t *im = &ipsec_main;
   ipsec_spd_t *spd;
-#if WITH_LIBSSL > 0
+
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
 
-  /* *INDENT-OFF* */
   pool_foreach (spd, im->spds)  {
     send_ipsec_spds_details (spd, reg, mp->context);
   }
-  /* *INDENT-ON* */
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 vl_api_ipsec_spd_action_t
@@ -610,7 +523,7 @@ send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SPD_DETAILS);
   mp->context = context;
 
   mp->entry.spd_id = htonl (p->id);
@@ -647,7 +560,7 @@ vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
   ipsec_spd_t *spd;
   uword *p;
   u32 spd_index, *ii;
-#if WITH_LIBSSL > 0
+
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -659,7 +572,6 @@ vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
   spd_index = p[0];
   spd = pool_elt_at_index (im->spds, spd_index);
 
-  /* *INDENT-OFF* */
   FOR_EACH_IPSEC_SPD_POLICY_TYPE(ptype) {
     vec_foreach(ii, spd->policies[ptype])
       {
@@ -669,10 +581,6 @@ vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
           send_ipsec_spd_details (policy, reg, mp->context);
       }
   }
-  /* *INDENT-ON* */
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static void
@@ -683,7 +591,8 @@ send_ipsec_spd_interface_details (vl_api_registration_t * reg, u32 spd_index,
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS);
+  mp->_vl_msg_id =
+    ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SPD_INTERFACE_DETAILS);
   mp->context = context;
 
   mp->spd_index = htonl (spd_index);
@@ -700,7 +609,6 @@ vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t *
   vl_api_registration_t *reg;
   u32 k, v, spd_index;
 
-#if WITH_LIBSSL > 0
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -717,16 +625,10 @@ vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t *
     }
   else
     {
-      /* *INDENT-OFF* */
       hash_foreach(k, v, im->spd_index_by_sw_if_index, ({
         send_ipsec_spd_interface_details(reg, v, k, mp->context);
       }));
-      /* *INDENT-ON* */
     }
-
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static void
@@ -761,9 +663,40 @@ vl_api_ipsec_itf_delete_t_handler (vl_api_ipsec_itf_delete_t * mp)
   REPLY_MACRO (VL_API_IPSEC_ITF_DELETE_REPLY);
 }
 
+static walk_rc_t
+send_ipsec_itf_details (ipsec_itf_t *itf, void *arg)
+{
+  ipsec_dump_walk_ctx_t *ctx = arg;
+  vl_api_ipsec_itf_details_t *mp;
+
+  mp = vl_msg_api_alloc (sizeof (*mp));
+  clib_memset (mp, 0, sizeof (*mp));
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_ITF_DETAILS);
+  mp->context = ctx->context;
+
+  mp->itf.mode = tunnel_mode_encode (itf->ii_mode);
+  mp->itf.user_instance = htonl (itf->ii_user_instance);
+  mp->itf.sw_if_index = htonl (itf->ii_sw_if_index);
+  vl_api_send_msg (ctx->reg, (u8 *) mp);
+
+  return (WALK_CONTINUE);
+}
+
 static void
 vl_api_ipsec_itf_dump_t_handler (vl_api_ipsec_itf_dump_t * mp)
 {
+  vl_api_registration_t *reg;
+
+  reg = vl_api_client_index_to_registration (mp->client_index);
+  if (!reg)
+    return;
+
+  ipsec_dump_walk_ctx_t ctx = {
+    .reg = reg,
+    .context = mp->context,
+  };
+
+  ipsec_itf_walk (send_ipsec_itf_details, &ctx);
 }
 
 typedef struct ipsec_sa_dump_match_ctx_t_
@@ -786,7 +719,7 @@ ipsec_sa_dump_match_sa (index_t itpi, void *arg)
       ctx->sw_if_index = itp->itp_sw_if_index;
       return (WALK_STOP);
     }
-  /* *INDENT-OFF* */
+
   FOR_EACH_IPSEC_PROTECT_INPUT_SAI (itp, sai,
   ({
     if (sai == ctx->sai)
@@ -795,7 +728,6 @@ ipsec_sa_dump_match_sa (index_t itpi, void *arg)
         return (WALK_STOP);
       }
   }));
-  /* *INDENT-OFF* */
 
   return (WALK_CONTINUE);
 }
@@ -805,11 +737,10 @@ send_ipsec_sa_details (ipsec_sa_t * sa, void *arg)
 {
   ipsec_dump_walk_ctx_t *ctx = arg;
   vl_api_ipsec_sa_details_t *mp;
-  ipsec_main_t *im = &ipsec_main;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SA_DETAILS);
   mp->context = ctx->context;
 
   mp->entry.sad_id = htonl (sa->id);
@@ -829,8 +760,8 @@ send_ipsec_sa_details (ipsec_sa_t * sa, void *arg)
   if (ipsec_sa_is_set_IS_PROTECT (sa))
     {
       ipsec_sa_dump_match_ctx_t ctx = {
-        .sai = sa - im->sad,
-        .sw_if_index = ~0,
+       .sai = sa - ipsec_sa_pool,
+       .sw_if_index = ~0,
       };
       ipsec_tun_protect_walk (ipsec_sa_dump_match_sa, &ctx);
 
@@ -872,7 +803,6 @@ vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
 {
   vl_api_registration_t *reg;
 
-#if WITH_LIBSSL > 0
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -883,10 +813,6 @@ vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
   };
 
   ipsec_sa_walk (send_ipsec_sa_details, &ctx);
-
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static walk_rc_t
@@ -894,11 +820,10 @@ send_ipsec_sa_v2_details (ipsec_sa_t * sa, void *arg)
 {
   ipsec_dump_walk_ctx_t *ctx = arg;
   vl_api_ipsec_sa_v2_details_t *mp;
-  ipsec_main_t *im = &ipsec_main;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_V2_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SA_V2_DETAILS);
   mp->context = ctx->context;
 
   mp->entry.sad_id = htonl (sa->id);
@@ -918,8 +843,8 @@ send_ipsec_sa_v2_details (ipsec_sa_t * sa, void *arg)
   if (ipsec_sa_is_set_IS_PROTECT (sa))
     {
       ipsec_sa_dump_match_ctx_t ctx = {
-        .sai = sa - im->sad,
-        .sw_if_index = ~0,
+       .sai = sa - ipsec_sa_pool,
+       .sw_if_index = ~0,
       };
       ipsec_tun_protect_walk (ipsec_sa_dump_match_sa, &ctx);
 
@@ -965,7 +890,6 @@ vl_api_ipsec_sa_v2_dump_t_handler (vl_api_ipsec_sa_v2_dump_t *mp)
 {
   vl_api_registration_t *reg;
 
-#if WITH_LIBSSL > 0
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -976,10 +900,6 @@ vl_api_ipsec_sa_v2_dump_t_handler (vl_api_ipsec_sa_v2_dump_t *mp)
   };
 
   ipsec_sa_walk (send_ipsec_sa_v2_details, &ctx);
-
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static walk_rc_t
@@ -987,11 +907,10 @@ send_ipsec_sa_v3_details (ipsec_sa_t *sa, void *arg)
 {
   ipsec_dump_walk_ctx_t *ctx = arg;
   vl_api_ipsec_sa_v3_details_t *mp;
-  ipsec_main_t *im = &ipsec_main;
 
   mp = vl_msg_api_alloc (sizeof (*mp));
   clib_memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_V3_DETAILS);
+  mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_SA_V3_DETAILS);
   mp->context = ctx->context;
 
   mp->entry.sad_id = htonl (sa->id);
@@ -1010,7 +929,7 @@ send_ipsec_sa_v3_details (ipsec_sa_t *sa, void *arg)
   if (ipsec_sa_is_set_IS_PROTECT (sa))
     {
       ipsec_sa_dump_match_ctx_t ctx = {
-       .sai = sa - im->sad,
+       .sai = sa - ipsec_sa_pool,
        .sw_if_index = ~0,
       };
       ipsec_tun_protect_walk (ipsec_sa_dump_match_sa, &ctx);
@@ -1051,7 +970,6 @@ vl_api_ipsec_sa_v3_dump_t_handler (vl_api_ipsec_sa_v3_dump_t *mp)
 {
   vl_api_registration_t *reg;
 
-#if WITH_LIBSSL > 0
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
     return;
@@ -1062,10 +980,6 @@ vl_api_ipsec_sa_v3_dump_t_handler (vl_api_ipsec_sa_v3_dump_t *mp)
   };
 
   ipsec_sa_walk (send_ipsec_sa_v3_details, &ctx);
-
-#else
-  clib_warning ("unimplemented");
-#endif
 }
 
 static void
@@ -1089,7 +1003,7 @@ vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp)
   pool_foreach (ab, im->ah_backends) {
     vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
     clib_memset (mp, 0, sizeof (*mp));
-    mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
+    mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_BACKEND_DETAILS);
     mp->context = context;
     snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name),
               ab->name);
@@ -1101,7 +1015,7 @@ vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp)
   pool_foreach (eb, im->esp_backends) {
     vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
     clib_memset (mp, 0, sizeof (*mp));
-    mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
+    mp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_IPSEC_BACKEND_DETAILS);
     mp->context = context;
     snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name),
               eb->name);
@@ -1120,7 +1034,7 @@ vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp)
   vl_api_ipsec_select_backend_reply_t *rmp;
   ipsec_protocol_t protocol;
   int rv = 0;
-  if (pool_elts (im->sad) > 0)
+  if (pool_elts (ipsec_sa_pool) > 0)
     {
       rv = VNET_API_ERROR_INSTANCE_IN_USE;
       goto done;
@@ -1131,7 +1045,6 @@ vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp)
   if (rv)
     goto done;
 
-#if WITH_LIBSSL > 0
   switch (protocol)
     {
     case IPSEC_PROTOCOL_ESP:
@@ -1144,9 +1057,6 @@ vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp)
       rv = VNET_API_ERROR_INVALID_PROTOCOL;
       break;
     }
-#else
-  clib_warning ("unimplemented");      /* FIXME */
-#endif
 done:
   REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY);
 }
@@ -1157,50 +1067,19 @@ vl_api_ipsec_set_async_mode_t_handler (vl_api_ipsec_set_async_mode_t * mp)
   vl_api_ipsec_set_async_mode_reply_t *rmp;
   int rv = 0;
 
-  vnet_crypto_request_async_mode (mp->async_enable);
   ipsec_set_async_mode (mp->async_enable);
 
   REPLY_MACRO (VL_API_IPSEC_SET_ASYNC_MODE_REPLY);
 }
 
-/*
- * ipsec_api_hookup
- * Add vpe's API message handlers to the table.
- * vlib has already mapped shared memory and
- * added the client registration handlers.
- * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
- */
-#define vl_msg_name_crc_list
-#include <vnet/vnet_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (api_main_t * am)
-{
-#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
-  foreach_vl_msg_name_crc_ipsec;
-#undef _
-}
-
+#include <vnet/ipsec/ipsec.api.c>
 static clib_error_t *
 ipsec_api_hookup (vlib_main_t * vm)
 {
-  api_main_t *am = vlibapi_get_main ();
-
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers(VL_API_##N, #n,                     \
-                           vl_api_##n##_t_handler,              \
-                           vl_noop_handler,                     \
-                           vl_api_##n##_t_endian,               \
-                           vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1);
-  foreach_vpe_api_msg;
-#undef _
-
   /*
    * Set up the (msg_name, crc, message-id) table
    */
-  setup_message_id_table (am);
+  REPLY_MSG_ID_BASE = setup_message_id_table ();
 
   return 0;
 }