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_add_del (vat_main_t * vam)
111 unformat_input_t *i = vam->input;
112 vl_api_ikev2_profile_add_del_t *mp;
117 const char *valid_chars = "a-zA-Z0-9_";
119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
121 if (unformat (i, "del"))
123 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
127 errmsg ("parse error '%U'", format_unformat_error, i);
134 errmsg ("profile name must be specified");
138 if (vec_len (name) > 64)
140 errmsg ("profile name too long");
144 M (IKEV2_PROFILE_ADD_DEL, mp);
146 clib_memcpy (mp->name, name, vec_len (name));
156 api_ikev2_profile_set_auth (vat_main_t * vam)
158 unformat_input_t *i = vam->input;
159 vl_api_ikev2_profile_set_auth_t *mp;
166 const char *valid_chars = "a-zA-Z0-9_";
168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
170 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
172 else if (unformat (i, "auth_method %U",
173 unformat_ikev2_auth_method, &auth_method))
175 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
177 else if (unformat (i, "auth_data %v", &data))
181 errmsg ("parse error '%U'", format_unformat_error, i);
188 errmsg ("profile name must be specified");
192 if (vec_len (name) > 64)
194 errmsg ("profile name too long");
200 errmsg ("auth_data must be specified");
206 errmsg ("auth_method must be specified");
210 M (IKEV2_PROFILE_SET_AUTH, mp);
213 mp->auth_method = (u8) auth_method;
214 mp->data_len = vec_len (data);
215 clib_memcpy (mp->name, name, vec_len (name));
216 clib_memcpy (mp->data, data, vec_len (data));
226 api_ikev2_profile_set_id (vat_main_t * vam)
228 unformat_input_t *i = vam->input;
229 vl_api_ikev2_profile_set_id_t *mp;
237 const char *valid_chars = "a-zA-Z0-9_";
239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
241 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
243 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
245 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
247 data = vec_new (u8, 4);
248 clib_memcpy (data, ip4.as_u8, 4);
250 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
252 else if (unformat (i, "id_data %v", &data))
254 else if (unformat (i, "local"))
256 else if (unformat (i, "remote"))
260 errmsg ("parse error '%U'", format_unformat_error, i);
267 errmsg ("profile name must be specified");
271 if (vec_len (name) > 64)
273 errmsg ("profile name too long");
279 errmsg ("id_data must be specified");
285 errmsg ("id_type must be specified");
289 M (IKEV2_PROFILE_SET_ID, mp);
291 mp->is_local = is_local;
292 mp->id_type = (u8) id_type;
293 mp->data_len = vec_len (data);
294 clib_memcpy (mp->name, name, vec_len (name));
295 clib_memcpy (mp->data, data, vec_len (data));
305 api_ikev2_profile_set_ts (vat_main_t * vam)
307 unformat_input_t *i = vam->input;
308 vl_api_ikev2_profile_set_ts_t *mp;
311 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
312 ip4_address_t start_addr, end_addr;
314 const char *valid_chars = "a-zA-Z0-9_";
317 start_addr.as_u32 = 0;
318 end_addr.as_u32 = (u32) ~ 0;
320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
322 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
324 else if (unformat (i, "protocol %d", &proto))
326 else if (unformat (i, "start_port %d", &start_port))
328 else if (unformat (i, "end_port %d", &end_port))
331 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
333 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
335 else if (unformat (i, "local"))
337 else if (unformat (i, "remote"))
341 errmsg ("parse error '%U'", format_unformat_error, i);
348 errmsg ("profile name must be specified");
352 if (vec_len (name) > 64)
354 errmsg ("profile name too long");
358 M (IKEV2_PROFILE_SET_TS, mp);
360 mp->is_local = is_local;
361 mp->proto = (u8) proto;
362 mp->start_port = (u16) start_port;
363 mp->end_port = (u16) end_port;
364 mp->start_addr = start_addr.as_u32;
365 mp->end_addr = end_addr.as_u32;
366 clib_memcpy (mp->name, name, vec_len (name));
375 api_ikev2_set_local_key (vat_main_t * vam)
377 unformat_input_t *i = vam->input;
378 vl_api_ikev2_set_local_key_t *mp;
382 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
384 if (unformat (i, "file %v", &file))
388 errmsg ("parse error '%U'", format_unformat_error, i);
395 errmsg ("RSA key file must be specified");
399 if (vec_len (file) > 256)
401 errmsg ("file name too long");
405 M (IKEV2_SET_LOCAL_KEY, mp);
407 clib_memcpy (mp->key_file, file, vec_len (file));
416 api_ikev2_profile_set_udp_encap (vat_main_t * vam)
418 unformat_input_t *i = vam->input;
419 vl_api_ikev2_set_responder_t *mp;
423 const char *valid_chars = "a-zA-Z0-9_";
425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
427 if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name))
431 errmsg ("parse error '%U'", format_unformat_error, i);
438 errmsg ("profile name must be specified");
442 if (vec_len (name) > 64)
444 errmsg ("profile name too long");
448 M (IKEV2_PROFILE_SET_UDP_ENCAP, mp);
450 clib_memcpy (mp->name, name, vec_len (name));
459 api_ikev2_set_tunnel_interface (vat_main_t * vam)
465 api_ikev2_set_responder (vat_main_t * vam)
467 unformat_input_t *i = vam->input;
468 vl_api_ikev2_set_responder_t *mp;
471 u32 sw_if_index = ~0;
472 ip4_address_t address;
474 const char *valid_chars = "a-zA-Z0-9_";
476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
479 (i, "%U interface %d address %U", unformat_token, valid_chars,
480 &name, &sw_if_index, unformat_ip4_address, &address))
484 errmsg ("parse error '%U'", format_unformat_error, i);
491 errmsg ("profile name must be specified");
495 if (vec_len (name) > 64)
497 errmsg ("profile name too long");
501 M (IKEV2_SET_RESPONDER, mp);
503 clib_memcpy (mp->name, name, vec_len (name));
506 mp->sw_if_index = sw_if_index;
507 clib_memcpy (mp->address, &address, sizeof (address));
515 api_ikev2_set_ike_transforms (vat_main_t * vam)
517 unformat_input_t *i = vam->input;
518 vl_api_ikev2_set_ike_transforms_t *mp;
521 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
523 const char *valid_chars = "a-zA-Z0-9_";
525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
527 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
528 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
532 errmsg ("parse error '%U'", format_unformat_error, i);
539 errmsg ("profile name must be specified");
543 if (vec_len (name) > 64)
545 errmsg ("profile name too long");
549 M (IKEV2_SET_IKE_TRANSFORMS, mp);
551 clib_memcpy (mp->name, name, vec_len (name));
553 mp->crypto_alg = crypto_alg;
554 mp->crypto_key_size = crypto_key_size;
555 mp->integ_alg = integ_alg;
556 mp->dh_group = dh_group;
565 api_ikev2_set_esp_transforms (vat_main_t * vam)
567 unformat_input_t *i = vam->input;
568 vl_api_ikev2_set_esp_transforms_t *mp;
571 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
573 const char *valid_chars = "a-zA-Z0-9_";
575 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
577 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
578 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
582 errmsg ("parse error '%U'", format_unformat_error, i);
589 errmsg ("profile name must be specified");
593 if (vec_len (name) > 64)
595 errmsg ("profile name too long");
599 M (IKEV2_SET_ESP_TRANSFORMS, mp);
601 clib_memcpy (mp->name, name, vec_len (name));
603 mp->crypto_alg = crypto_alg;
604 mp->crypto_key_size = crypto_key_size;
605 mp->integ_alg = integ_alg;
606 mp->dh_group = dh_group;
614 api_ikev2_set_sa_lifetime (vat_main_t * vam)
616 unformat_input_t *i = vam->input;
617 vl_api_ikev2_set_sa_lifetime_t *mp;
620 u64 lifetime, lifetime_maxdata;
621 u32 lifetime_jitter, handover;
623 const char *valid_chars = "a-zA-Z0-9_";
625 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
627 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
628 &lifetime, &lifetime_jitter, &handover,
633 errmsg ("parse error '%U'", format_unformat_error, i);
640 errmsg ("profile name must be specified");
644 if (vec_len (name) > 64)
646 errmsg ("profile name too long");
650 M (IKEV2_SET_SA_LIFETIME, mp);
652 clib_memcpy (mp->name, name, vec_len (name));
654 mp->lifetime = lifetime;
655 mp->lifetime_jitter = lifetime_jitter;
656 mp->handover = handover;
657 mp->lifetime_maxdata = lifetime_maxdata;
665 api_ikev2_initiate_sa_init (vat_main_t * vam)
667 unformat_input_t *i = vam->input;
668 vl_api_ikev2_initiate_sa_init_t *mp;
672 const char *valid_chars = "a-zA-Z0-9_";
674 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
676 if (unformat (i, "%U", unformat_token, valid_chars, &name))
680 errmsg ("parse error '%U'", format_unformat_error, i);
687 errmsg ("profile name must be specified");
691 if (vec_len (name) > 64)
693 errmsg ("profile name too long");
697 M (IKEV2_INITIATE_SA_INIT, mp);
699 clib_memcpy (mp->name, name, vec_len (name));
708 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
710 unformat_input_t *i = vam->input;
711 vl_api_ikev2_initiate_del_ike_sa_t *mp;
716 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
718 if (unformat (i, "%lx", &ispi))
722 errmsg ("parse error '%U'", format_unformat_error, i);
727 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
737 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
739 unformat_input_t *i = vam->input;
740 vl_api_ikev2_initiate_del_child_sa_t *mp;
745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
747 if (unformat (i, "%x", &ispi))
751 errmsg ("parse error '%U'", format_unformat_error, i);
756 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
766 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
768 unformat_input_t *i = vam->input;
769 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
774 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
776 if (unformat (i, "%x", &ispi))
780 errmsg ("parse error '%U'", format_unformat_error, i);
785 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
794 #include <ikev2/ikev2.api_test.c>
797 * fd.io coding-style-patch-verification: ON
800 * eval: (c-set-style "gnu")