2 *------------------------------------------------------------------
5 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vppinfra/error.h>
24 #include <plugins/ikev2/ikev2.h>
26 #define __plugin_msg_base ikev2_test_main.msg_id_base
27 #include <vlibapi/vat_helper_macros.h>
29 /* Declare message IDs */
30 #include <vnet/format_fns.h>
31 #include <ikev2/ikev2.api_enum.h>
32 #include <ikev2/ikev2.api_types.h>
36 /* API message ID base */
41 ikev2_test_main_t ikev2_test_main;
44 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
46 u32 *r = va_arg (*args, u32 *);
49 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
50 foreach_ikev2_auth_method
58 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
60 u32 *r = va_arg (*args, u32 *);
63 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
72 api_ikev2_plugin_get_version (vat_main_t * vam)
74 ikev2_test_main_t *sm = &ikev2_test_main;
75 vl_api_ikev2_plugin_get_version_t *mp;
76 u32 msg_size = sizeof (*mp);
79 vam->result_ready = 0;
80 mp = vl_msg_api_alloc_as_if_client (msg_size);
81 clib_memset (mp, 0, msg_size);
82 mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base);
83 mp->client_index = vam->my_client_index;
88 /* Wait for a reply... */
93 static void vl_api_ikev2_plugin_get_version_reply_t_handler
94 (vl_api_ikev2_plugin_get_version_reply_t * mp)
96 vat_main_t *vam = ikev2_test_main.vat_main;
97 clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major),
99 vam->result_ready = 1;
103 api_ikev2_profile_add_del (vat_main_t * vam)
105 unformat_input_t *i = vam->input;
106 vl_api_ikev2_profile_add_del_t *mp;
111 const char *valid_chars = "a-zA-Z0-9_";
113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
115 if (unformat (i, "del"))
117 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
121 errmsg ("parse error '%U'", format_unformat_error, i);
128 errmsg ("profile name must be specified");
132 if (vec_len (name) > 64)
134 errmsg ("profile name too long");
138 M (IKEV2_PROFILE_ADD_DEL, mp);
140 clib_memcpy (mp->name, name, vec_len (name));
150 api_ikev2_profile_set_auth (vat_main_t * vam)
152 unformat_input_t *i = vam->input;
153 vl_api_ikev2_profile_set_auth_t *mp;
160 const char *valid_chars = "a-zA-Z0-9_";
162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
164 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
166 else if (unformat (i, "auth_method %U",
167 unformat_ikev2_auth_method, &auth_method))
169 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
171 else if (unformat (i, "auth_data %v", &data))
175 errmsg ("parse error '%U'", format_unformat_error, i);
182 errmsg ("profile name must be specified");
186 if (vec_len (name) > 64)
188 errmsg ("profile name too long");
194 errmsg ("auth_data must be specified");
200 errmsg ("auth_method must be specified");
204 M (IKEV2_PROFILE_SET_AUTH, mp);
207 mp->auth_method = (u8) auth_method;
208 mp->data_len = vec_len (data);
209 clib_memcpy (mp->name, name, vec_len (name));
210 clib_memcpy (mp->data, data, vec_len (data));
220 api_ikev2_profile_set_id (vat_main_t * vam)
222 unformat_input_t *i = vam->input;
223 vl_api_ikev2_profile_set_id_t *mp;
231 const char *valid_chars = "a-zA-Z0-9_";
233 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
235 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
237 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
239 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
241 data = vec_new (u8, 4);
242 clib_memcpy (data, ip4.as_u8, 4);
244 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
246 else if (unformat (i, "id_data %v", &data))
248 else if (unformat (i, "local"))
250 else if (unformat (i, "remote"))
254 errmsg ("parse error '%U'", format_unformat_error, i);
261 errmsg ("profile name must be specified");
265 if (vec_len (name) > 64)
267 errmsg ("profile name too long");
273 errmsg ("id_data must be specified");
279 errmsg ("id_type must be specified");
283 M (IKEV2_PROFILE_SET_ID, mp);
285 mp->is_local = is_local;
286 mp->id_type = (u8) id_type;
287 mp->data_len = vec_len (data);
288 clib_memcpy (mp->name, name, vec_len (name));
289 clib_memcpy (mp->data, data, vec_len (data));
299 api_ikev2_profile_set_ts (vat_main_t * vam)
301 unformat_input_t *i = vam->input;
302 vl_api_ikev2_profile_set_ts_t *mp;
305 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
306 ip4_address_t start_addr, end_addr;
308 const char *valid_chars = "a-zA-Z0-9_";
311 start_addr.as_u32 = 0;
312 end_addr.as_u32 = (u32) ~ 0;
314 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
316 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
318 else if (unformat (i, "protocol %d", &proto))
320 else if (unformat (i, "start_port %d", &start_port))
322 else if (unformat (i, "end_port %d", &end_port))
325 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
327 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
329 else if (unformat (i, "local"))
331 else if (unformat (i, "remote"))
335 errmsg ("parse error '%U'", format_unformat_error, i);
342 errmsg ("profile name must be specified");
346 if (vec_len (name) > 64)
348 errmsg ("profile name too long");
352 M (IKEV2_PROFILE_SET_TS, mp);
354 mp->is_local = is_local;
355 mp->proto = (u8) proto;
356 mp->start_port = (u16) start_port;
357 mp->end_port = (u16) end_port;
358 mp->start_addr = start_addr.as_u32;
359 mp->end_addr = end_addr.as_u32;
360 clib_memcpy (mp->name, name, vec_len (name));
369 api_ikev2_set_local_key (vat_main_t * vam)
371 unformat_input_t *i = vam->input;
372 vl_api_ikev2_set_local_key_t *mp;
376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
378 if (unformat (i, "file %v", &file))
382 errmsg ("parse error '%U'", format_unformat_error, i);
389 errmsg ("RSA key file must be specified");
393 if (vec_len (file) > 256)
395 errmsg ("file name too long");
399 M (IKEV2_SET_LOCAL_KEY, mp);
401 clib_memcpy (mp->key_file, file, vec_len (file));
410 api_ikev2_profile_set_udp_encap (vat_main_t * vam)
412 unformat_input_t *i = vam->input;
413 vl_api_ikev2_set_responder_t *mp;
417 const char *valid_chars = "a-zA-Z0-9_";
419 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
421 if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name))
425 errmsg ("parse error '%U'", format_unformat_error, i);
432 errmsg ("profile name must be specified");
436 if (vec_len (name) > 64)
438 errmsg ("profile name too long");
442 M (IKEV2_PROFILE_SET_UDP_ENCAP, mp);
444 clib_memcpy (mp->name, name, vec_len (name));
453 api_ikev2_set_tunnel_interface (vat_main_t * vam)
459 api_ikev2_set_responder (vat_main_t * vam)
461 unformat_input_t *i = vam->input;
462 vl_api_ikev2_set_responder_t *mp;
465 u32 sw_if_index = ~0;
466 ip4_address_t address;
468 const char *valid_chars = "a-zA-Z0-9_";
470 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
473 (i, "%U interface %d address %U", unformat_token, valid_chars,
474 &name, &sw_if_index, unformat_ip4_address, &address))
478 errmsg ("parse error '%U'", format_unformat_error, i);
485 errmsg ("profile name must be specified");
489 if (vec_len (name) > 64)
491 errmsg ("profile name too long");
495 M (IKEV2_SET_RESPONDER, mp);
497 clib_memcpy (mp->name, name, vec_len (name));
500 mp->sw_if_index = sw_if_index;
501 clib_memcpy (mp->address, &address, sizeof (address));
509 api_ikev2_set_ike_transforms (vat_main_t * vam)
511 unformat_input_t *i = vam->input;
512 vl_api_ikev2_set_ike_transforms_t *mp;
515 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
517 const char *valid_chars = "a-zA-Z0-9_";
519 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
521 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
522 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
526 errmsg ("parse error '%U'", format_unformat_error, i);
533 errmsg ("profile name must be specified");
537 if (vec_len (name) > 64)
539 errmsg ("profile name too long");
543 M (IKEV2_SET_IKE_TRANSFORMS, mp);
545 clib_memcpy (mp->name, name, vec_len (name));
547 mp->crypto_alg = crypto_alg;
548 mp->crypto_key_size = crypto_key_size;
549 mp->integ_alg = integ_alg;
550 mp->dh_group = dh_group;
559 api_ikev2_set_esp_transforms (vat_main_t * vam)
561 unformat_input_t *i = vam->input;
562 vl_api_ikev2_set_esp_transforms_t *mp;
565 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
567 const char *valid_chars = "a-zA-Z0-9_";
569 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
571 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
572 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
576 errmsg ("parse error '%U'", format_unformat_error, i);
583 errmsg ("profile name must be specified");
587 if (vec_len (name) > 64)
589 errmsg ("profile name too long");
593 M (IKEV2_SET_ESP_TRANSFORMS, mp);
595 clib_memcpy (mp->name, name, vec_len (name));
597 mp->crypto_alg = crypto_alg;
598 mp->crypto_key_size = crypto_key_size;
599 mp->integ_alg = integ_alg;
600 mp->dh_group = dh_group;
608 api_ikev2_set_sa_lifetime (vat_main_t * vam)
610 unformat_input_t *i = vam->input;
611 vl_api_ikev2_set_sa_lifetime_t *mp;
614 u64 lifetime, lifetime_maxdata;
615 u32 lifetime_jitter, handover;
617 const char *valid_chars = "a-zA-Z0-9_";
619 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
621 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
622 &lifetime, &lifetime_jitter, &handover,
627 errmsg ("parse error '%U'", format_unformat_error, i);
634 errmsg ("profile name must be specified");
638 if (vec_len (name) > 64)
640 errmsg ("profile name too long");
644 M (IKEV2_SET_SA_LIFETIME, mp);
646 clib_memcpy (mp->name, name, vec_len (name));
648 mp->lifetime = lifetime;
649 mp->lifetime_jitter = lifetime_jitter;
650 mp->handover = handover;
651 mp->lifetime_maxdata = lifetime_maxdata;
659 api_ikev2_initiate_sa_init (vat_main_t * vam)
661 unformat_input_t *i = vam->input;
662 vl_api_ikev2_initiate_sa_init_t *mp;
666 const char *valid_chars = "a-zA-Z0-9_";
668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
670 if (unformat (i, "%U", unformat_token, valid_chars, &name))
674 errmsg ("parse error '%U'", format_unformat_error, i);
681 errmsg ("profile name must be specified");
685 if (vec_len (name) > 64)
687 errmsg ("profile name too long");
691 M (IKEV2_INITIATE_SA_INIT, mp);
693 clib_memcpy (mp->name, name, vec_len (name));
702 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
704 unformat_input_t *i = vam->input;
705 vl_api_ikev2_initiate_del_ike_sa_t *mp;
710 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
712 if (unformat (i, "%lx", &ispi))
716 errmsg ("parse error '%U'", format_unformat_error, i);
721 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
731 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
733 unformat_input_t *i = vam->input;
734 vl_api_ikev2_initiate_del_child_sa_t *mp;
739 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
741 if (unformat (i, "%x", &ispi))
745 errmsg ("parse error '%U'", format_unformat_error, i);
750 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
760 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
762 unformat_input_t *i = vam->input;
763 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
768 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
770 if (unformat (i, "%x", &ispi))
774 errmsg ("parse error '%U'", format_unformat_error, i);
779 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
788 #include <ikev2/ikev2.api_test.c>
791 * fd.io coding-style-patch-verification: ON
794 * eval: (c-set-style "gnu")