X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fikev2%2Fikev2_test.c;h=9ff4bbcc58ca808f7c5203c4bb14e35a001c5723;hb=b29d523af039ac007238300a7316ba9e3e44ce25;hp=57724b8416143f6e438841154412feba5901cad6;hpb=21a438465ca0dee88d13d9dd9621929116c95614;p=vpp.git diff --git a/src/plugins/ikev2/ikev2_test.c b/src/plugins/ikev2/ikev2_test.c index 57724b84161..9ff4bbcc58c 100644 --- a/src/plugins/ikev2/ikev2_test.c +++ b/src/plugins/ikev2/ikev2_test.c @@ -27,28 +27,9 @@ #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 +#include typedef struct { @@ -87,66 +68,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) @@ -455,6 +406,55 @@ api_ikev2_set_local_key (vat_main_t * vam) return ret; } +static int +api_ikev2_profile_set_udp_encap (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_ikev2_set_responder_t *mp; + int ret; + u8 *name = 0; + + const char *valid_chars = "a-zA-Z0-9_"; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name)) + vec_add1 (name, 0); + else + { + errmsg ("parse error '%U'", format_unformat_error, i); + return -99; + } + } + + if (!vec_len (name)) + { + errmsg ("profile name must be specified"); + return -99; + } + + if (vec_len (name) > 64) + { + errmsg ("profile name too long"); + return -99; + } + + M (IKEV2_PROFILE_SET_UDP_ENCAP, mp); + + clib_memcpy (mp->name, name, vec_len (name)); + vec_free (name); + + S (mp); + W (ret); + return ret; +} + +static int +api_ikev2_set_tunnel_interface (vat_main_t * vam) +{ + return (0); +} + static int api_ikev2_set_responder (vat_main_t * vam) { @@ -785,55 +785,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