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_set_ipsec_udp_port (vat_main_t * vam)
109 api_ikev2_profile_set_liveness (vat_main_t * vam)
111 unformat_input_t *i = vam->input;
112 vl_api_ikev2_profile_set_liveness_t *mp;
113 u32 period = 0, max_retries = 0;
116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
118 if (!unformat (i, "period %d max-retries %d", &period, &max_retries))
120 errmsg ("parse error '%U'", format_unformat_error, i);
125 M (IKEV2_PROFILE_SET_LIVENESS, mp);
127 mp->period = clib_host_to_net_u32 (period);
128 mp->max_retries = clib_host_to_net_u32 (max_retries);
137 api_ikev2_profile_add_del (vat_main_t * vam)
139 unformat_input_t *i = vam->input;
140 vl_api_ikev2_profile_add_del_t *mp;
145 const char *valid_chars = "a-zA-Z0-9_";
147 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
149 if (unformat (i, "del"))
151 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
155 errmsg ("parse error '%U'", format_unformat_error, i);
162 errmsg ("profile name must be specified");
166 if (vec_len (name) > 64)
168 errmsg ("profile name too long");
172 M (IKEV2_PROFILE_ADD_DEL, mp);
174 clib_memcpy (mp->name, name, vec_len (name));
184 api_ikev2_profile_set_auth (vat_main_t * vam)
186 unformat_input_t *i = vam->input;
187 vl_api_ikev2_profile_set_auth_t *mp;
194 const char *valid_chars = "a-zA-Z0-9_";
196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
198 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
200 else if (unformat (i, "auth_method %U",
201 unformat_ikev2_auth_method, &auth_method))
203 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
205 else if (unformat (i, "auth_data %v", &data))
209 errmsg ("parse error '%U'", format_unformat_error, i);
216 errmsg ("profile name must be specified");
220 if (vec_len (name) > 64)
222 errmsg ("profile name too long");
228 errmsg ("auth_data must be specified");
234 errmsg ("auth_method must be specified");
238 M (IKEV2_PROFILE_SET_AUTH, mp);
241 mp->auth_method = (u8) auth_method;
242 mp->data_len = vec_len (data);
243 clib_memcpy (mp->name, name, vec_len (name));
244 clib_memcpy (mp->data, data, vec_len (data));
254 api_ikev2_profile_set_id (vat_main_t * vam)
256 unformat_input_t *i = vam->input;
257 vl_api_ikev2_profile_set_id_t *mp;
265 const char *valid_chars = "a-zA-Z0-9_";
267 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
269 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
271 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
273 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
275 data = vec_new (u8, 4);
276 clib_memcpy (data, ip4.as_u8, 4);
278 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
280 else if (unformat (i, "id_data %v", &data))
282 else if (unformat (i, "local"))
284 else if (unformat (i, "remote"))
288 errmsg ("parse error '%U'", format_unformat_error, i);
295 errmsg ("profile name must be specified");
299 if (vec_len (name) > 64)
301 errmsg ("profile name too long");
307 errmsg ("id_data must be specified");
313 errmsg ("id_type must be specified");
317 M (IKEV2_PROFILE_SET_ID, mp);
319 mp->is_local = is_local;
320 mp->id_type = (u8) id_type;
321 mp->data_len = vec_len (data);
322 clib_memcpy (mp->name, name, vec_len (name));
323 clib_memcpy (mp->data, data, vec_len (data));
333 api_ikev2_profile_set_ts (vat_main_t * vam)
335 unformat_input_t *i = vam->input;
336 vl_api_ikev2_profile_set_ts_t *mp;
339 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
340 ip4_address_t start_addr, end_addr;
342 const char *valid_chars = "a-zA-Z0-9_";
345 start_addr.as_u32 = 0;
346 end_addr.as_u32 = (u32) ~ 0;
348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
350 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
352 else if (unformat (i, "protocol %d", &proto))
354 else if (unformat (i, "start_port %d", &start_port))
356 else if (unformat (i, "end_port %d", &end_port))
359 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
361 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
363 else if (unformat (i, "local"))
365 else if (unformat (i, "remote"))
369 errmsg ("parse error '%U'", format_unformat_error, i);
376 errmsg ("profile name must be specified");
380 if (vec_len (name) > 64)
382 errmsg ("profile name too long");
386 M (IKEV2_PROFILE_SET_TS, mp);
388 mp->is_local = is_local;
389 mp->proto = (u8) proto;
390 mp->start_port = (u16) start_port;
391 mp->end_port = (u16) end_port;
392 mp->start_addr = start_addr.as_u32;
393 mp->end_addr = end_addr.as_u32;
394 clib_memcpy (mp->name, name, vec_len (name));
403 api_ikev2_set_local_key (vat_main_t * vam)
405 unformat_input_t *i = vam->input;
406 vl_api_ikev2_set_local_key_t *mp;
410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
412 if (unformat (i, "file %v", &file))
416 errmsg ("parse error '%U'", format_unformat_error, i);
423 errmsg ("RSA key file must be specified");
427 if (vec_len (file) > 256)
429 errmsg ("file name too long");
433 M (IKEV2_SET_LOCAL_KEY, mp);
435 clib_memcpy (mp->key_file, file, vec_len (file));
444 api_ikev2_profile_set_udp_encap (vat_main_t * vam)
446 unformat_input_t *i = vam->input;
447 vl_api_ikev2_set_responder_t *mp;
451 const char *valid_chars = "a-zA-Z0-9_";
453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
455 if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name))
459 errmsg ("parse error '%U'", format_unformat_error, i);
466 errmsg ("profile name must be specified");
470 if (vec_len (name) > 64)
472 errmsg ("profile name too long");
476 M (IKEV2_PROFILE_SET_UDP_ENCAP, mp);
478 clib_memcpy (mp->name, name, vec_len (name));
487 api_ikev2_set_tunnel_interface (vat_main_t * vam)
493 api_ikev2_set_responder (vat_main_t * vam)
495 unformat_input_t *i = vam->input;
496 vl_api_ikev2_set_responder_t *mp;
499 u32 sw_if_index = ~0;
500 ip4_address_t address;
502 const char *valid_chars = "a-zA-Z0-9_";
504 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
507 (i, "%U interface %d address %U", unformat_token, valid_chars,
508 &name, &sw_if_index, unformat_ip4_address, &address))
512 errmsg ("parse error '%U'", format_unformat_error, i);
519 errmsg ("profile name must be specified");
523 if (vec_len (name) > 64)
525 errmsg ("profile name too long");
529 M (IKEV2_SET_RESPONDER, mp);
531 clib_memcpy (mp->name, name, vec_len (name));
534 mp->sw_if_index = sw_if_index;
535 clib_memcpy (mp->address, &address, sizeof (address));
543 api_ikev2_set_ike_transforms (vat_main_t * vam)
545 unformat_input_t *i = vam->input;
546 vl_api_ikev2_set_ike_transforms_t *mp;
549 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
551 const char *valid_chars = "a-zA-Z0-9_";
553 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
555 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
556 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
560 errmsg ("parse error '%U'", format_unformat_error, i);
567 errmsg ("profile name must be specified");
571 if (vec_len (name) > 64)
573 errmsg ("profile name too long");
577 M (IKEV2_SET_IKE_TRANSFORMS, mp);
579 clib_memcpy (mp->name, name, vec_len (name));
581 mp->crypto_alg = crypto_alg;
582 mp->crypto_key_size = crypto_key_size;
583 mp->integ_alg = integ_alg;
584 mp->dh_group = dh_group;
593 api_ikev2_set_esp_transforms (vat_main_t * vam)
595 unformat_input_t *i = vam->input;
596 vl_api_ikev2_set_esp_transforms_t *mp;
599 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
601 const char *valid_chars = "a-zA-Z0-9_";
603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
605 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
606 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
610 errmsg ("parse error '%U'", format_unformat_error, i);
617 errmsg ("profile name must be specified");
621 if (vec_len (name) > 64)
623 errmsg ("profile name too long");
627 M (IKEV2_SET_ESP_TRANSFORMS, mp);
629 clib_memcpy (mp->name, name, vec_len (name));
631 mp->crypto_alg = crypto_alg;
632 mp->crypto_key_size = crypto_key_size;
633 mp->integ_alg = integ_alg;
634 mp->dh_group = dh_group;
642 api_ikev2_set_sa_lifetime (vat_main_t * vam)
644 unformat_input_t *i = vam->input;
645 vl_api_ikev2_set_sa_lifetime_t *mp;
648 u64 lifetime, lifetime_maxdata;
649 u32 lifetime_jitter, handover;
651 const char *valid_chars = "a-zA-Z0-9_";
653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
655 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
656 &lifetime, &lifetime_jitter, &handover,
661 errmsg ("parse error '%U'", format_unformat_error, i);
668 errmsg ("profile name must be specified");
672 if (vec_len (name) > 64)
674 errmsg ("profile name too long");
678 M (IKEV2_SET_SA_LIFETIME, mp);
680 clib_memcpy (mp->name, name, vec_len (name));
682 mp->lifetime = lifetime;
683 mp->lifetime_jitter = lifetime_jitter;
684 mp->handover = handover;
685 mp->lifetime_maxdata = lifetime_maxdata;
693 api_ikev2_initiate_sa_init (vat_main_t * vam)
695 unformat_input_t *i = vam->input;
696 vl_api_ikev2_initiate_sa_init_t *mp;
700 const char *valid_chars = "a-zA-Z0-9_";
702 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
704 if (unformat (i, "%U", unformat_token, valid_chars, &name))
708 errmsg ("parse error '%U'", format_unformat_error, i);
715 errmsg ("profile name must be specified");
719 if (vec_len (name) > 64)
721 errmsg ("profile name too long");
725 M (IKEV2_INITIATE_SA_INIT, mp);
727 clib_memcpy (mp->name, name, vec_len (name));
736 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
738 unformat_input_t *i = vam->input;
739 vl_api_ikev2_initiate_del_ike_sa_t *mp;
744 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
746 if (unformat (i, "%lx", &ispi))
750 errmsg ("parse error '%U'", format_unformat_error, i);
755 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
765 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
767 unformat_input_t *i = vam->input;
768 vl_api_ikev2_initiate_del_child_sa_t *mp;
773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
775 if (unformat (i, "%x", &ispi))
779 errmsg ("parse error '%U'", format_unformat_error, i);
784 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
794 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
796 unformat_input_t *i = vam->input;
797 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
804 if (unformat (i, "%x", &ispi))
808 errmsg ("parse error '%U'", format_unformat_error, i);
813 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
822 #include <ikev2/ikev2.api_test.c>
825 * fd.io coding-style-patch-verification: ON
828 * eval: (c-set-style "gnu")