From fc7b77db7e651505aa8c3a9c5cff7191334f91bd Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Fri, 27 Sep 2019 14:02:13 +0200 Subject: ikev2: remove api boilerplate Type: refactor Change-Id: Ib46ed3e65e75a97995a3e251d87324fec6595024 Signed-off-by: Ole Troan --- src/plugins/ikev2/CMakeLists.txt | 2 - src/plugins/ikev2/ikev2.api | 13 ++++ src/plugins/ikev2/ikev2_all_api.h | 17 ---- src/plugins/ikev2/ikev2_api.c | 92 ++-------------------- src/plugins/ikev2/ikev2_msg_enum.h | 28 ------- src/plugins/ikev2/ikev2_test.c | 156 +++++++------------------------------ 6 files changed, 47 insertions(+), 261 deletions(-) delete mode 100644 src/plugins/ikev2/ikev2_all_api.h delete mode 100644 src/plugins/ikev2/ikev2_msg_enum.h diff --git a/src/plugins/ikev2/CMakeLists.txt b/src/plugins/ikev2/CMakeLists.txt index d3ba271f3ad..13297c6dbac 100644 --- a/src/plugins/ikev2/CMakeLists.txt +++ b/src/plugins/ikev2/CMakeLists.txt @@ -29,6 +29,4 @@ add_vpp_plugin(ikev2 INSTALL_HEADERS ikev2.h ikev2_priv.h - ikev2_msg_enum.h - ikev2_all_api.h ) diff --git a/src/plugins/ikev2/ikev2.api b/src/plugins/ikev2/ikev2.api index 6c47482ae12..8c9649f6cb3 100644 --- a/src/plugins/ikev2/ikev2.api +++ b/src/plugins/ikev2/ikev2.api @@ -52,6 +52,7 @@ autoreply define ikev2_profile_add_del u8 name[64]; u8 is_add; + option vat_help = "name [del]"; }; /** \brief IKEv2: Set IKEv2 profile authentication method @@ -74,6 +75,7 @@ autoreply define ikev2_profile_set_auth u8 is_hex; u32 data_len; u8 data[data_len]; + option vat_help = "name auth_method (auth_data 0x | auth_data )"; }; /** \brief IKEv2: Set IKEv2 profile local/remote identification @@ -96,6 +98,7 @@ autoreply define ikev2_profile_set_id u8 id_type; u32 data_len; u8 data[data_len]; + option vat_help = "name id_type (id_data 0x | id_data ) (local|remote)"; }; /** \brief IKEv2: Set IKEv2 profile traffic selector parameters @@ -122,6 +125,7 @@ autoreply define ikev2_profile_set_ts u16 end_port; u32 start_addr; u32 end_addr; + option vat_help = "name protocol start_port end_port start_addr end_addr (local|remote)"; }; /** \brief IKEv2: Set IKEv2 local RSA private key @@ -136,6 +140,7 @@ autoreply define ikev2_set_local_key u32 context; u8 key_file[256]; + option vat_help = "file "; }; /** \brief IKEv2: Set IKEv2 responder interface and IP address @@ -154,6 +159,7 @@ autoreply define ikev2_set_responder u8 name[64]; u32 sw_if_index; u8 address[4]; + option vat_help = " interface address "; }; /** \brief IKEv2: Set IKEv2 IKE transforms in SA_INIT proposal (RFC 7296) @@ -177,6 +183,7 @@ autoreply define ikev2_set_ike_transforms u32 crypto_key_size; u32 integ_alg; u32 dh_group; + option vat_help = " "; }; /** \brief IKEv2: Set IKEv2 ESP transforms in SA_INIT proposal (RFC 7296) @@ -200,6 +207,7 @@ autoreply define ikev2_set_esp_transforms u32 crypto_key_size; u32 integ_alg; u32 dh_group; + option vat_help = " "; }; /** \brief IKEv2: Set Child SA lifetime, limited by time and/or data @@ -223,6 +231,7 @@ autoreply define ikev2_set_sa_lifetime u32 lifetime_jitter; u32 handover; u64 lifetime_maxdata; + option vat_help = " "; }; /** \brief IKEv2: Initiate the SA_INIT exchange @@ -238,6 +247,7 @@ autoreply define ikev2_initiate_sa_init u32 context; u8 name[64]; + option vat_help = ""; }; /** \brief IKEv2: Initiate the delete IKE SA exchange @@ -253,6 +263,7 @@ autoreply define ikev2_initiate_del_ike_sa u32 context; u64 ispi; + option vat_help = ""; }; /** \brief IKEv2: Initiate the delete Child SA exchange @@ -268,6 +279,7 @@ autoreply define ikev2_initiate_del_child_sa u32 context; u32 ispi; + option vat_help = ""; }; /** \brief IKEv2: Initiate the rekey Child SA exchange @@ -283,6 +295,7 @@ autoreply define ikev2_initiate_rekey_child_sa u32 context; u32 ispi; + option vat_help = ""; }; /* diff --git a/src/plugins/ikev2/ikev2_all_api.h b/src/plugins/ikev2/ikev2_all_api.h deleted file mode 100644 index 2ab112a7ea6..00000000000 --- a/src/plugins/ikev2/ikev2_all_api.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* Include the generated file, see BUILT_SOURCES in Makefile.am */ -#include - diff --git a/src/plugins/ikev2/ikev2_api.c b/src/plugins/ikev2/ikev2_api.c index b7b8d6ddcee..d85b2f5f999 100644 --- a/src/plugins/ikev2/ikev2_api.c +++ b/src/plugins/ikev2/ikev2_api.c @@ -26,26 +26,8 @@ #include /* define message IDs */ -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#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 -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version +#include +#include extern ikev2_main_t ikev2_main; @@ -54,22 +36,6 @@ extern ikev2_main_t ikev2_main; #define REPLY_MSG_ID_BASE ikev2_main.msg_id_base #include -#define foreach_ikev2_api_msg \ -_(IKEV2_PLUGIN_GET_VERSION, ikev2_plugin_get_version) \ -_(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \ -_(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \ -_(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \ -_(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \ -_(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \ -_(IKEV2_SET_RESPONDER, ikev2_set_responder) \ -_(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \ -_(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \ -_(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \ -_(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \ -_(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \ -_(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \ -_(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa) - static void vl_api_ikev2_plugin_get_version_t_handler (vl_api_ikev2_plugin_get_version_t * mp) @@ -397,64 +363,16 @@ static void REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY); } -/* - * ikev2_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 -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (ikev2_main_t * im, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + im->msg_id_base); - foreach_vl_msg_name_crc_ikev2; -#undef _ -} - -static clib_error_t * -ikev2_plugin_api_hookup (vlib_main_t * vm) -{ - ikev2_main_t *im = &ikev2_main; -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N + im->msg_id_base, #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_ikev2_api_msg; -#undef _ - - return (NULL); -} - +#include static clib_error_t * ikev2_api_init (vlib_main_t * vm) { ikev2_main_t *im = &ikev2_main; - clib_error_t *error = 0; - u8 *name; - - name = format (0, "ikev2_%08x%c", api_version, 0); /* Ask for a correctly-sized block of API message decode slots */ - im->msg_id_base = vl_msg_api_get_msg_ids ((char *) name, - VL_MSG_FIRST_AVAILABLE); - - error = ikev2_plugin_api_hookup (vm); - - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (im, &api_main); - - vec_free (name); + im->msg_id_base = setup_message_id_table (); - return (error); + return 0; } VLIB_INIT_FUNCTION (ikev2_api_init); diff --git a/src/plugins/ikev2/ikev2_msg_enum.h b/src/plugins/ikev2/ikev2_msg_enum.h deleted file mode 100644 index 63dbfafb8c0..00000000000 --- a/src/plugins/ikev2/ikev2_msg_enum.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef included_ikev2_msg_enum_h -#define included_ikev2_msg_enum_h - -#include - -#define vl_msg_id(n,h) n, -typedef enum { -#include - /* We'll want to know how many messages IDs we need... */ - VL_MSG_FIRST_AVAILABLE, -} vl_msg_id_t; -#undef vl_msg_id - -#endif diff --git a/src/plugins/ikev2/ikev2_test.c b/src/plugins/ikev2/ikev2_test.c index 57724b84161..c740d478240 100644 --- a/src/plugins/ikev2/ikev2_test.c +++ b/src/plugins/ikev2/ikev2_test.c @@ -27,28 +27,8 @@ #include /* Declare message IDs */ -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -/* declare message handlers for each api */ - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) -#define vl_printfun -#include -#undef vl_printfun - -/* Get the API version number. */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version +#include +#include typedef struct { @@ -87,66 +67,36 @@ unformat_ikev2_id_type (unformat_input_t * input, va_list * args) return 1; } -/* - * Generate boilerplate reply handlers, which - * dig the return value out of the xxx_reply_t API message, - * stick it into vam->retval, and set vam->result_ready - * - * Could also do this by pointing N message decode slots at - * a single function, but that could break in subtle ways. - */ +static int +api_ikev2_plugin_get_version (vat_main_t * vam) +{ + ikev2_test_main_t *sm = &ikev2_test_main; + vl_api_ikev2_plugin_get_version_t *mp; + u32 msg_size = sizeof (*mp); + int ret; -#define foreach_standard_reply_retval_handler \ -_(ikev2_profile_add_del_reply) \ -_(ikev2_profile_set_auth_reply) \ -_(ikev2_profile_set_id_reply) \ -_(ikev2_profile_set_ts_reply) \ -_(ikev2_set_local_key_reply) \ -_(ikev2_set_responder_reply) \ -_(ikev2_set_ike_transforms_reply) \ -_(ikev2_set_esp_transforms_reply) \ -_(ikev2_set_sa_lifetime_reply) \ -_(ikev2_initiate_sa_init_reply) \ -_(ikev2_initiate_del_ike_sa_reply) \ -_(ikev2_initiate_del_child_sa_reply) \ -_(ikev2_initiate_rekey_child_sa_reply) - -#define _(n) \ - static void vl_api_##n##_t_handler \ - (vl_api_##n##_t * mp) \ - { \ - vat_main_t * vam = ikev2_test_main.vat_main; \ - i32 retval = ntohl(mp->retval); \ - if (vam->async_mode) { \ - vam->async_errors += (retval < 0); \ - } else { \ - vam->retval = retval; \ - vam->result_ready = 1; \ - } \ - } -foreach_standard_reply_retval_handler; -#undef _ + vam->result_ready = 0; + mp = vl_msg_api_alloc_as_if_client (msg_size); + clib_memset (mp, 0, msg_size); + mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base); + mp->client_index = vam->my_client_index; -/* - * Table of message reply handlers, must include boilerplate handlers - * we just generated - */ + /* send it... */ + S (mp); -#define foreach_vpe_api_reply_msg \ -_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \ -_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \ -_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \ -_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \ -_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \ -_(IKEV2_SET_RESPONDER_REPLY, ikev2_set_responder_reply) \ -_(IKEV2_SET_IKE_TRANSFORMS_REPLY, ikev2_set_ike_transforms_reply) \ -_(IKEV2_SET_ESP_TRANSFORMS_REPLY, ikev2_set_esp_transforms_reply) \ -_(IKEV2_SET_SA_LIFETIME_REPLY, ikev2_set_sa_lifetime_reply) \ -_(IKEV2_INITIATE_SA_INIT_REPLY, ikev2_initiate_sa_init_reply) \ -_(IKEV2_INITIATE_DEL_IKE_SA_REPLY, ikev2_initiate_del_ike_sa_reply) \ -_(IKEV2_INITIATE_DEL_CHILD_SA_REPLY, ikev2_initiate_del_child_sa_reply) \ -_(IKEV2_INITIATE_REKEY_CHILD_SA_REPLY, ikev2_initiate_rekey_child_sa_reply) + /* Wait for a reply... */ + W (ret); + return ret; +} +static void vl_api_ikev2_plugin_get_version_reply_t_handler + (vl_api_ikev2_plugin_get_version_reply_t * mp) +{ + vat_main_t *vam = ikev2_test_main.vat_main; + clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major), + ntohl (mp->minor)); + vam->result_ready = 1; +} static int api_ikev2_profile_add_del (vat_main_t * vam) @@ -785,55 +735,7 @@ api_ikev2_initiate_rekey_child_sa (vat_main_t * vam) return ret; } - -/* List of API message constructors, CLI names map to api_xxx */ -#define foreach_vpe_api_msg \ -_(ikev2_profile_add_del, "name [del]") \ -_(ikev2_profile_set_auth, "name auth_method \n" \ - "(auth_data 0x | auth_data )") \ -_(ikev2_profile_set_id, "name id_type \n" \ - "(id_data 0x | id_data ) (local|remote)") \ -_(ikev2_profile_set_ts, "name protocol \n" \ - "start_port end_port start_addr end_addr \n" \ - "(local|remote)") \ -_(ikev2_set_local_key, "file ") \ -_(ikev2_set_responder, " interface address ") \ -_(ikev2_set_ike_transforms, " ") \ -_(ikev2_set_esp_transforms, " ") \ -_(ikev2_set_sa_lifetime, " ") \ -_(ikev2_initiate_sa_init, "") \ -_(ikev2_initiate_del_ike_sa, "") \ -_(ikev2_initiate_del_child_sa, "") \ -_(ikev2_initiate_rekey_child_sa, "") - -static void -ikev2_api_hookup (vat_main_t * vam) -{ - ikev2_test_main_t *sm = &ikev2_test_main; - /* Hook up handlers for replies from the data plane plug-in */ -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ - #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_reply_msg; -#undef _ - - /* API messages we can send */ -#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n); - foreach_vpe_api_msg; -#undef _ - - /* Help strings */ -#define _(n,h) hash_set_mem (vam->help_by_name, #n, h); - foreach_vpe_api_msg; -#undef _ -} - -VAT_PLUGIN_REGISTER (ikev2); +#include /* * fd.io coding-style-patch-verification: ON -- cgit 1.2.3-korg