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 <ikev2/ikev2.api_enum.h>
31 #include <ikev2/ikev2.api_types.h>
35 /* API message ID base */
40 ikev2_test_main_t ikev2_test_main;
43 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
45 u32 *r = va_arg (*args, u32 *);
48 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
49 foreach_ikev2_auth_method
57 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
59 u32 *r = va_arg (*args, u32 *);
62 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
71 api_ikev2_plugin_get_version (vat_main_t * vam)
73 ikev2_test_main_t *sm = &ikev2_test_main;
74 vl_api_ikev2_plugin_get_version_t *mp;
75 u32 msg_size = sizeof (*mp);
78 vam->result_ready = 0;
79 mp = vl_msg_api_alloc_as_if_client (msg_size);
80 clib_memset (mp, 0, msg_size);
81 mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base);
82 mp->client_index = vam->my_client_index;
87 /* Wait for a reply... */
92 static void vl_api_ikev2_plugin_get_version_reply_t_handler
93 (vl_api_ikev2_plugin_get_version_reply_t * mp)
95 vat_main_t *vam = ikev2_test_main.vat_main;
96 clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major),
98 vam->result_ready = 1;
102 api_ikev2_profile_add_del (vat_main_t * vam)
104 unformat_input_t *i = vam->input;
105 vl_api_ikev2_profile_add_del_t *mp;
110 const char *valid_chars = "a-zA-Z0-9_";
112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
114 if (unformat (i, "del"))
116 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
120 errmsg ("parse error '%U'", format_unformat_error, i);
127 errmsg ("profile name must be specified");
131 if (vec_len (name) > 64)
133 errmsg ("profile name too long");
137 M (IKEV2_PROFILE_ADD_DEL, mp);
139 clib_memcpy (mp->name, name, vec_len (name));
149 api_ikev2_profile_set_auth (vat_main_t * vam)
151 unformat_input_t *i = vam->input;
152 vl_api_ikev2_profile_set_auth_t *mp;
159 const char *valid_chars = "a-zA-Z0-9_";
161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
163 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
165 else if (unformat (i, "auth_method %U",
166 unformat_ikev2_auth_method, &auth_method))
168 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
170 else if (unformat (i, "auth_data %v", &data))
174 errmsg ("parse error '%U'", format_unformat_error, i);
181 errmsg ("profile name must be specified");
185 if (vec_len (name) > 64)
187 errmsg ("profile name too long");
193 errmsg ("auth_data must be specified");
199 errmsg ("auth_method must be specified");
203 M (IKEV2_PROFILE_SET_AUTH, mp);
206 mp->auth_method = (u8) auth_method;
207 mp->data_len = vec_len (data);
208 clib_memcpy (mp->name, name, vec_len (name));
209 clib_memcpy (mp->data, data, vec_len (data));
219 api_ikev2_profile_set_id (vat_main_t * vam)
221 unformat_input_t *i = vam->input;
222 vl_api_ikev2_profile_set_id_t *mp;
230 const char *valid_chars = "a-zA-Z0-9_";
232 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
234 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
236 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
238 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
240 data = vec_new (u8, 4);
241 clib_memcpy (data, ip4.as_u8, 4);
243 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
245 else if (unformat (i, "id_data %v", &data))
247 else if (unformat (i, "local"))
249 else if (unformat (i, "remote"))
253 errmsg ("parse error '%U'", format_unformat_error, i);
260 errmsg ("profile name must be specified");
264 if (vec_len (name) > 64)
266 errmsg ("profile name too long");
272 errmsg ("id_data must be specified");
278 errmsg ("id_type must be specified");
282 M (IKEV2_PROFILE_SET_ID, mp);
284 mp->is_local = is_local;
285 mp->id_type = (u8) id_type;
286 mp->data_len = vec_len (data);
287 clib_memcpy (mp->name, name, vec_len (name));
288 clib_memcpy (mp->data, data, vec_len (data));
298 api_ikev2_profile_set_ts (vat_main_t * vam)
300 unformat_input_t *i = vam->input;
301 vl_api_ikev2_profile_set_ts_t *mp;
304 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
305 ip4_address_t start_addr, end_addr;
307 const char *valid_chars = "a-zA-Z0-9_";
310 start_addr.as_u32 = 0;
311 end_addr.as_u32 = (u32) ~ 0;
313 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
315 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
317 else if (unformat (i, "protocol %d", &proto))
319 else if (unformat (i, "start_port %d", &start_port))
321 else if (unformat (i, "end_port %d", &end_port))
324 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
326 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
328 else if (unformat (i, "local"))
330 else if (unformat (i, "remote"))
334 errmsg ("parse error '%U'", format_unformat_error, i);
341 errmsg ("profile name must be specified");
345 if (vec_len (name) > 64)
347 errmsg ("profile name too long");
351 M (IKEV2_PROFILE_SET_TS, mp);
353 mp->is_local = is_local;
354 mp->proto = (u8) proto;
355 mp->start_port = (u16) start_port;
356 mp->end_port = (u16) end_port;
357 mp->start_addr = start_addr.as_u32;
358 mp->end_addr = end_addr.as_u32;
359 clib_memcpy (mp->name, name, vec_len (name));
368 api_ikev2_set_local_key (vat_main_t * vam)
370 unformat_input_t *i = vam->input;
371 vl_api_ikev2_set_local_key_t *mp;
375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
377 if (unformat (i, "file %v", &file))
381 errmsg ("parse error '%U'", format_unformat_error, i);
388 errmsg ("RSA key file must be specified");
392 if (vec_len (file) > 256)
394 errmsg ("file name too long");
398 M (IKEV2_SET_LOCAL_KEY, mp);
400 clib_memcpy (mp->key_file, file, vec_len (file));
409 api_ikev2_set_responder (vat_main_t * vam)
411 unformat_input_t *i = vam->input;
412 vl_api_ikev2_set_responder_t *mp;
415 u32 sw_if_index = ~0;
416 ip4_address_t address;
418 const char *valid_chars = "a-zA-Z0-9_";
420 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
423 (i, "%U interface %d address %U", unformat_token, valid_chars,
424 &name, &sw_if_index, unformat_ip4_address, &address))
428 errmsg ("parse error '%U'", format_unformat_error, i);
435 errmsg ("profile name must be specified");
439 if (vec_len (name) > 64)
441 errmsg ("profile name too long");
445 M (IKEV2_SET_RESPONDER, mp);
447 clib_memcpy (mp->name, name, vec_len (name));
450 mp->sw_if_index = sw_if_index;
451 clib_memcpy (mp->address, &address, sizeof (address));
459 api_ikev2_set_ike_transforms (vat_main_t * vam)
461 unformat_input_t *i = vam->input;
462 vl_api_ikev2_set_ike_transforms_t *mp;
465 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
467 const char *valid_chars = "a-zA-Z0-9_";
469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
471 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
472 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
476 errmsg ("parse error '%U'", format_unformat_error, i);
483 errmsg ("profile name must be specified");
487 if (vec_len (name) > 64)
489 errmsg ("profile name too long");
493 M (IKEV2_SET_IKE_TRANSFORMS, mp);
495 clib_memcpy (mp->name, name, vec_len (name));
497 mp->crypto_alg = crypto_alg;
498 mp->crypto_key_size = crypto_key_size;
499 mp->integ_alg = integ_alg;
500 mp->dh_group = dh_group;
509 api_ikev2_set_esp_transforms (vat_main_t * vam)
511 unformat_input_t *i = vam->input;
512 vl_api_ikev2_set_esp_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_ESP_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;
558 api_ikev2_set_sa_lifetime (vat_main_t * vam)
560 unformat_input_t *i = vam->input;
561 vl_api_ikev2_set_sa_lifetime_t *mp;
564 u64 lifetime, lifetime_maxdata;
565 u32 lifetime_jitter, handover;
567 const char *valid_chars = "a-zA-Z0-9_";
569 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
571 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
572 &lifetime, &lifetime_jitter, &handover,
577 errmsg ("parse error '%U'", format_unformat_error, i);
584 errmsg ("profile name must be specified");
588 if (vec_len (name) > 64)
590 errmsg ("profile name too long");
594 M (IKEV2_SET_SA_LIFETIME, mp);
596 clib_memcpy (mp->name, name, vec_len (name));
598 mp->lifetime = lifetime;
599 mp->lifetime_jitter = lifetime_jitter;
600 mp->handover = handover;
601 mp->lifetime_maxdata = lifetime_maxdata;
609 api_ikev2_initiate_sa_init (vat_main_t * vam)
611 unformat_input_t *i = vam->input;
612 vl_api_ikev2_initiate_sa_init_t *mp;
616 const char *valid_chars = "a-zA-Z0-9_";
618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
620 if (unformat (i, "%U", unformat_token, valid_chars, &name))
624 errmsg ("parse error '%U'", format_unformat_error, i);
631 errmsg ("profile name must be specified");
635 if (vec_len (name) > 64)
637 errmsg ("profile name too long");
641 M (IKEV2_INITIATE_SA_INIT, mp);
643 clib_memcpy (mp->name, name, vec_len (name));
652 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
654 unformat_input_t *i = vam->input;
655 vl_api_ikev2_initiate_del_ike_sa_t *mp;
660 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
662 if (unformat (i, "%lx", &ispi))
666 errmsg ("parse error '%U'", format_unformat_error, i);
671 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
681 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
683 unformat_input_t *i = vam->input;
684 vl_api_ikev2_initiate_del_child_sa_t *mp;
689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
691 if (unformat (i, "%x", &ispi))
695 errmsg ("parse error '%U'", format_unformat_error, i);
700 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
710 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
712 unformat_input_t *i = vam->input;
713 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
718 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
720 if (unformat (i, "%x", &ispi))
724 errmsg ("parse error '%U'", format_unformat_error, i);
729 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
738 #include <ikev2/ikev2.api_test.c>
741 * fd.io coding-style-patch-verification: ON
744 * eval: (c-set-style "gnu")