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 <vnet/ipsec/ipsec_sa.h>
25 #include <plugins/ikev2/ikev2.h>
26 #include <vnet/ip/ip_types_api.h>
28 #define __plugin_msg_base ikev2_test_main.msg_id_base
29 #include <vlibapi/vat_helper_macros.h>
31 /* Declare message IDs */
32 #include <vnet/format_fns.h>
33 #include <ikev2/ikev2.api_enum.h>
34 #include <ikev2/ikev2.api_types.h>
35 #include <vpp/api/vpe.api_types.h>
37 #define vl_endianfun /* define message structures */
38 #include <plugins/ikev2/ikev2.api.h>
43 /* API message ID base */
49 ikev2_test_main_t ikev2_test_main;
52 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
54 u32 *r = va_arg (*args, u32 *);
57 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
58 foreach_ikev2_auth_method
67 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
69 u32 *r = va_arg (*args, u32 *);
72 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
80 #define MACRO_FORMAT(lc) \
81 u8 * format_ikev2_##lc (u8 * s, va_list * args) \
83 u32 i = va_arg (*args, u32); \
88 return format (s, "unknown (%u)", i); \
90 s = format (s, "%s", t); \
94 #define _(v,f,str) case IKEV2_AUTH_METHOD_##f: t = str; break;
95 MACRO_FORMAT (auth_method)
97 #define _(v,f,str) case IKEV2_ID_TYPE_##f: t = str; break;
98 MACRO_FORMAT (id_type)
100 #define _(v,f,str) case IKEV2_TRANSFORM_TYPE_##f: t = str; break;
101 MACRO_FORMAT (transform_type)
103 #define _(v,f,str) case IKEV2_TRANSFORM_ENCR_TYPE_##f: t = str; break;
104 MACRO_FORMAT (transform_encr_type)
106 #define _(v,f,str) case IKEV2_TRANSFORM_PRF_TYPE_##f: t = str; break;
107 MACRO_FORMAT (transform_prf_type)
109 #define _(v,f,str) case IKEV2_TRANSFORM_INTEG_TYPE_##f: t = str; break;
110 MACRO_FORMAT (transform_integ_type)
112 #define _(v,f,str) case IKEV2_TRANSFORM_DH_TYPE_##f: t = str; break;
113 MACRO_FORMAT (transform_dh_type)
115 #define _(v,f,str) case IKEV2_TRANSFORM_ESN_TYPE_##f: t = str; break;
116 MACRO_FORMAT (transform_esn_type)
118 u8 *format_ikev2_id_type_and_data (u8 * s, va_list * args)
120 vl_api_ikev2_id_t *id = va_arg (*args, vl_api_ikev2_id_t *);
123 return format (s, "none");
125 s = format (s, "%U", format_ikev2_id_type, id->type);
130 return format (s, "none");
131 case IKEV2_ID_TYPE_ID_FQDN:
132 s = format (s, " %s", id->data);
134 case IKEV2_ID_TYPE_ID_RFC822_ADDR:
135 s = format (s, " %s", id->data);
137 case IKEV2_ID_TYPE_ID_IPV4_ADDR:
138 s = format (s, " %U", format_ip4_address, id->data);
140 case IKEV2_ID_TYPE_ID_KEY_ID:
141 s = format (s, " 0x%U", format_hex_bytes, id->data, id->data_len);
144 s = format (s, " %s", id->data);
151 format_ikev2_sa_transform (u8 * s, va_list * args)
153 vl_api_ikev2_sa_transform_t *tr =
154 va_arg (*args, vl_api_ikev2_sa_transform_t *);
159 if (tr->transform_type >= IKEV2_TRANSFORM_NUM_TYPES)
162 s = format (s, "%U:", format_ikev2_transform_type, tr->transform_type);
164 switch (tr->transform_type)
166 case IKEV2_TRANSFORM_TYPE_ENCR:
168 format (s, "%U", format_ikev2_transform_encr_type, tr->transform_id);
170 case IKEV2_TRANSFORM_TYPE_PRF:
171 s = format (s, "%U", format_ikev2_transform_prf_type, tr->transform_id);
173 case IKEV2_TRANSFORM_TYPE_INTEG:
175 format (s, "%U", format_ikev2_transform_integ_type, tr->transform_id);
177 case IKEV2_TRANSFORM_TYPE_DH:
178 s = format (s, "%U", format_ikev2_transform_dh_type, tr->transform_id);
180 case IKEV2_TRANSFORM_TYPE_ESN:
181 s = format (s, "%U", format_ikev2_transform_esn_type, tr->transform_id);
187 if (tr->transform_type == IKEV2_TRANSFORM_TYPE_ENCR &&
188 tr->transform_id == IKEV2_TRANSFORM_ENCR_TYPE_AES_CBC && tr->key_len)
189 s = format (s, "-%u", tr->key_len * 8);
195 api_ikev2_profile_dump (vat_main_t * vam)
197 ikev2_test_main_t *ik = &ikev2_test_main;
198 vl_api_ikev2_profile_dump_t *mp;
199 vl_api_control_ping_t *mp_ping;
202 /* Construct the API message */
203 M (IKEV2_PROFILE_DUMP, mp);
208 /* Use a control ping for synchronization */
210 ik->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
211 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
212 mp_ping->_vl_msg_id = htons (ik->ping_id);
213 mp_ping->client_index = vam->my_client_index;
215 vam->result_ready = 0;
218 /* Wait for a reply... */
223 static void vl_api_ikev2_profile_details_t_handler
224 (vl_api_ikev2_profile_details_t * mp)
226 vat_main_t *vam = ikev2_test_main.vat_main;
227 vl_api_ikev2_profile_t *p = &mp->profile;
228 ip4_address_t start_addr, end_addr;
230 fformat (vam->ofp, "profile %s\n", p->name);
235 fformat (vam->ofp, " auth-method %U auth data 0x%U\n",
236 format_ikev2_auth_method, p->auth.method,
237 format_hex_bytes, p->auth.data,
238 clib_net_to_host_u32 (p->auth.data_len));
240 fformat (vam->ofp, " auth-method %U auth data %v\n",
241 format_ikev2_auth_method, p->auth.method, format (0,
249 fformat (vam->ofp, " local id-type data %U\n",
250 format_ikev2_id_type_and_data, &p->loc_id);
255 fformat (vam->ofp, " remote id-type data %U\n",
256 format_ikev2_id_type_and_data, &p->rem_id);
259 ip4_address_decode (p->loc_ts.start_addr, &start_addr);
260 ip4_address_decode (p->loc_ts.end_addr, &end_addr);
261 fformat (vam->ofp, " local traffic-selector addr %U - %U port %u - %u"
263 format_ip4_address, &start_addr,
264 format_ip4_address, &end_addr,
265 clib_net_to_host_u16 (p->loc_ts.start_port),
266 clib_net_to_host_u16 (p->loc_ts.end_port), p->loc_ts.protocol_id);
268 ip4_address_decode (p->rem_ts.start_addr, &start_addr);
269 ip4_address_decode (p->rem_ts.end_addr, &end_addr);
270 fformat (vam->ofp, " remote traffic-selector addr %U - %U port %u - %u"
272 format_ip4_address, &start_addr,
273 format_ip4_address, &end_addr,
274 clib_net_to_host_u16 (p->rem_ts.start_port),
275 clib_net_to_host_u16 (p->rem_ts.end_port), p->rem_ts.protocol_id);
276 u32 tun_itf = clib_net_to_host_u32 (p->tun_itf);
278 fformat (vam->ofp, " protected tunnel idx %d\n", tun_itf);
280 u32 sw_if_index = clib_net_to_host_u32 (p->responder.sw_if_index);
281 if (~0 != sw_if_index)
282 fformat (vam->ofp, " responder idx %d %U\n",
283 sw_if_index, format_ip4_address, &p->responder.ip4);
286 fformat (vam->ofp, " udp-encap\n");
288 u32 ipsec_over_udp_port = clib_net_to_host_u16 (p->ipsec_over_udp_port);
289 if (ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
290 fformat (vam->ofp, " ipsec-over-udp port %d\n", ipsec_over_udp_port);
292 u32 crypto_key_size = clib_net_to_host_u32 (p->ike_ts.crypto_key_size);
293 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_group
295 fformat (vam->ofp, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U\n",
296 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg,
297 crypto_key_size, format_ikev2_transform_integ_type,
298 p->ike_ts.integ_alg, format_ikev2_transform_dh_type,
301 crypto_key_size = clib_net_to_host_u32 (p->esp_ts.crypto_key_size);
302 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg)
303 fformat (vam->ofp, " esp-crypto-alg %U %u esp-integ-alg %U\n",
304 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg,
306 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
308 fformat (vam->ofp, " lifetime %d jitter %d handover %d maxdata %d\n",
309 clib_net_to_host_u64 (p->lifetime),
310 clib_net_to_host_u32 (p->lifetime_jitter),
311 clib_net_to_host_u32 (p->handover),
312 clib_net_to_host_u64 (p->lifetime_maxdata));
314 vam->result_ready = 1;
318 api_ikev2_sa_dump (vat_main_t * vam)
320 ikev2_test_main_t *im = &ikev2_test_main;
321 vl_api_ikev2_sa_dump_t *mp;
322 vl_api_control_ping_t *mp_ping;
325 /* Construct the API message */
326 M (IKEV2_SA_DUMP, mp);
331 /* Use a control ping for synchronization */
333 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
334 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
335 mp_ping->_vl_msg_id = htons (im->ping_id);
336 mp_ping->client_index = vam->my_client_index;
337 vam->result_ready = 0;
341 /* Wait for a reply... */
347 vl_api_ikev2_sa_details_t_handler (vl_api_ikev2_sa_details_t * mp)
349 vat_main_t *vam = ikev2_test_main.vat_main;
350 vl_api_ikev2_sa_t *sa = &mp->sa;
353 vl_api_ikev2_keys_t *k = &sa->keys;
354 vl_api_ikev2_sa_t_endian (sa);
356 ip4_address_decode (sa->iaddr, &iaddr);
357 ip4_address_decode (sa->raddr, &raddr);
359 fformat (vam->ofp, "profile index %d sa index: %d\n",
360 mp->sa.profile_index, mp->sa.sa_index);
361 fformat (vam->ofp, " iip %U ispi %lx rip %U rspi %lx\n", format_ip4_address,
362 &iaddr, sa->ispi, format_ip4_address, &raddr, sa->rspi);
363 fformat (vam->ofp, " %U ", format_ikev2_sa_transform, &sa->encryption);
364 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->prf);
365 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->integrity);
366 fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &sa->dh);
368 fformat (vam->ofp, " SK_d %U\n",
369 format_hex_bytes, k->sk_d, k->sk_d_len);
371 fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
372 format_hex_bytes, k->sk_ai, k->sk_ai_len, format_hex_bytes,
373 k->sk_ar, k->sk_ar_len);
375 fformat (vam->ofp, " SK_e i:%U\n r:%U\n", format_hex_bytes,
376 k->sk_ei, k->sk_ei_len, format_hex_bytes, k->sk_er, k->sk_er_len);
378 fformat (vam->ofp, " SK_p i:%U\n r:%U\n", format_hex_bytes,
379 k->sk_pi, k->sk_pi_len, format_hex_bytes, k->sk_pr, k->sk_pr_len);
381 fformat (vam->ofp, " identifier (i) %U\n",
382 format_ikev2_id_type_and_data, &sa->i_id);
383 fformat (vam->ofp, " identifier (r) %U\n",
384 format_ikev2_id_type_and_data, &sa->r_id);
386 vam->result_ready = 1;
390 api_ikev2_child_sa_dump (vat_main_t * vam)
392 unformat_input_t *i = vam->input;
393 ikev2_test_main_t *im = &ikev2_test_main;
394 vl_api_ikev2_child_sa_dump_t *mp;
395 vl_api_control_ping_t *mp_ping;
399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
401 if (unformat (i, "sa_index %d", &sa_index))
405 errmsg ("parse error '%U'", format_unformat_error, i);
413 /* Construct the API message */
414 M (IKEV2_CHILD_SA_DUMP, mp);
416 mp->sa_index = clib_net_to_host_u32 (sa_index);
421 /* Use a control ping for synchronization */
423 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
424 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
425 mp_ping->_vl_msg_id = htons (im->ping_id);
426 mp_ping->client_index = vam->my_client_index;
427 vam->result_ready = 0;
431 /* Wait for a reply... */
437 vl_api_ikev2_child_sa_details_t_handler (vl_api_ikev2_child_sa_details_t * mp)
439 vat_main_t *vam = ikev2_test_main.vat_main;
440 vl_api_ikev2_child_sa_t *child_sa = &mp->child_sa;
441 vl_api_ikev2_keys_t *k = &child_sa->keys;
442 vl_api_ikev2_child_sa_t_endian (child_sa);
444 fformat (vam->ofp, " child sa %u:\n", child_sa->child_sa_index);
446 fformat (vam->ofp, " %U ", format_ikev2_sa_transform,
447 &child_sa->encryption);
448 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &child_sa->integrity);
449 fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &child_sa->esn);
451 fformat (vam->ofp, " spi(i) %lx spi(r) %lx\n",
452 child_sa->i_spi, child_sa->r_spi);
454 fformat (vam->ofp, " SK_e i:%U\n r:%U\n",
455 format_hex_bytes, k->sk_ei, k->sk_ei_len,
456 format_hex_bytes, k->sk_er, k->sk_er_len);
459 fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
460 format_hex_bytes, k->sk_ai, k->sk_ai_len,
461 format_hex_bytes, k->sk_ar, k->sk_ar_len);
463 vam->result_ready = 1;
467 api_ikev2_traffic_selector_dump (vat_main_t * vam)
469 unformat_input_t *i = vam->input;
470 ikev2_test_main_t *im = &ikev2_test_main;
471 vl_api_ikev2_traffic_selector_dump_t *mp;
472 vl_api_control_ping_t *mp_ping;
473 int is_initiator = ~0;
475 int child_sa_index = ~0;
478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
480 if (unformat (i, "initiator"))
482 else if (unformat (i, "responder"))
484 else if (unformat (i, "sa_index %d", &sa_index))
486 else if (unformat (i, "child_sa_index %d", &child_sa_index))
490 errmsg ("parse error '%U'", format_unformat_error, i);
495 if (child_sa_index == ~0 || sa_index == ~0 || is_initiator == ~0)
498 /* Construct the API message */
499 M (IKEV2_TRAFFIC_SELECTOR_DUMP, mp);
501 mp->is_initiator = is_initiator;
502 mp->sa_index = clib_host_to_net_u32 (sa_index);
503 mp->child_sa_index = clib_host_to_net_u32 (child_sa_index);
508 /* Use a control ping for synchronization */
510 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
511 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
512 mp_ping->_vl_msg_id = htons (im->ping_id);
513 mp_ping->client_index = vam->my_client_index;
514 vam->result_ready = 0;
518 /* Wait for a reply... */
524 vl_api_ikev2_traffic_selector_details_t_handler
525 (vl_api_ikev2_traffic_selector_details_t * mp)
527 vat_main_t *vam = ikev2_test_main.vat_main;
528 vl_api_ikev2_ts_t *ts = &mp->ts;
529 ip4_address_t start_addr;
530 ip4_address_t end_addr;
531 vl_api_ikev2_ts_t_endian (ts);
533 ip4_address_decode (ts->start_addr, &start_addr);
534 ip4_address_decode (ts->end_addr, &end_addr);
536 fformat (vam->ofp, " %s protocol_id %u addr "
537 "%U - %U port %u - %u\n",
538 ts->is_local, ts->protocol_id,
539 format_ip4_address, &start_addr,
540 format_ip4_address, &end_addr, ts->start_port, ts->end_port);
541 vam->result_ready = 1;
545 api_ikev2_nonce_get (vat_main_t * vam)
547 unformat_input_t *i = vam->input;
548 ikev2_test_main_t *im = &ikev2_test_main;
549 vl_api_ikev2_nonce_get_t *mp;
550 vl_api_control_ping_t *mp_ping;
551 u32 is_initiator = ~0;
555 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
557 if (unformat (i, "initiator"))
559 else if (unformat (i, "responder"))
561 else if (unformat (i, "sa_index %d", &sa_index))
565 errmsg ("parse error '%U'", format_unformat_error, i);
570 if (sa_index == ~0 || is_initiator == ~0)
573 /* Construct the API message */
574 M (IKEV2_NONCE_GET, mp);
576 mp->is_initiator = is_initiator;
577 mp->sa_index = clib_host_to_net_u32 (sa_index);
582 /* Use a control ping for synchronization */
584 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
585 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
586 mp_ping->_vl_msg_id = htons (im->ping_id);
587 mp_ping->client_index = vam->my_client_index;
588 vam->result_ready = 0;
592 /* Wait for a reply... */
598 vl_api_ikev2_nonce_get_reply_t_handler (vl_api_ikev2_nonce_get_reply_t * mp)
600 vat_main_t *vam = ikev2_test_main.vat_main;
601 mp->data_len = clib_net_to_host_u32 (mp->data_len);
603 fformat (vam->ofp, " nonce:%U\n",
604 format_hex_bytes, mp->nonce, mp->data_len);
606 vam->result_ready = 1;
610 api_ikev2_plugin_get_version (vat_main_t * vam)
612 ikev2_test_main_t *sm = &ikev2_test_main;
613 vl_api_ikev2_plugin_get_version_t *mp;
614 u32 msg_size = sizeof (*mp);
617 vam->result_ready = 0;
618 mp = vl_msg_api_alloc_as_if_client (msg_size);
619 clib_memset (mp, 0, msg_size);
620 mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base);
621 mp->client_index = vam->my_client_index;
626 /* Wait for a reply... */
631 static void vl_api_ikev2_plugin_get_version_reply_t_handler
632 (vl_api_ikev2_plugin_get_version_reply_t * mp)
634 vat_main_t *vam = ikev2_test_main.vat_main;
635 clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major),
637 vam->result_ready = 1;
641 api_ikev2_profile_set_ipsec_udp_port (vat_main_t * vam)
647 api_ikev2_profile_set_liveness (vat_main_t * vam)
649 unformat_input_t *i = vam->input;
650 vl_api_ikev2_profile_set_liveness_t *mp;
651 u32 period = 0, max_retries = 0;
654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
656 if (!unformat (i, "period %d max-retries %d", &period, &max_retries))
658 errmsg ("parse error '%U'", format_unformat_error, i);
663 M (IKEV2_PROFILE_SET_LIVENESS, mp);
665 mp->period = clib_host_to_net_u32 (period);
666 mp->max_retries = clib_host_to_net_u32 (max_retries);
675 api_ikev2_profile_add_del (vat_main_t * vam)
677 unformat_input_t *i = vam->input;
678 vl_api_ikev2_profile_add_del_t *mp;
683 const char *valid_chars = "a-zA-Z0-9_";
685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
687 if (unformat (i, "del"))
689 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
693 errmsg ("parse error '%U'", format_unformat_error, i);
700 errmsg ("profile name must be specified");
704 if (vec_len (name) > 64)
706 errmsg ("profile name too long");
710 M (IKEV2_PROFILE_ADD_DEL, mp);
712 clib_memcpy (mp->name, name, vec_len (name));
722 api_ikev2_profile_set_auth (vat_main_t * vam)
724 unformat_input_t *i = vam->input;
725 vl_api_ikev2_profile_set_auth_t *mp;
732 const char *valid_chars = "a-zA-Z0-9_";
734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
736 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
738 else if (unformat (i, "auth_method %U",
739 unformat_ikev2_auth_method, &auth_method))
741 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
743 else if (unformat (i, "auth_data %v", &data))
747 errmsg ("parse error '%U'", format_unformat_error, i);
754 errmsg ("profile name must be specified");
758 if (vec_len (name) > 64)
760 errmsg ("profile name too long");
766 errmsg ("auth_data must be specified");
772 errmsg ("auth_method must be specified");
776 M (IKEV2_PROFILE_SET_AUTH, mp);
779 mp->auth_method = (u8) auth_method;
780 mp->data_len = vec_len (data);
781 clib_memcpy (mp->name, name, vec_len (name));
782 clib_memcpy (mp->data, data, vec_len (data));
792 api_ikev2_profile_set_id (vat_main_t * vam)
794 unformat_input_t *i = vam->input;
795 vl_api_ikev2_profile_set_id_t *mp;
803 const char *valid_chars = "a-zA-Z0-9_";
805 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
807 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
809 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
811 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
813 data = vec_new (u8, 4);
814 clib_memcpy (data, ip4.as_u8, 4);
816 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
818 else if (unformat (i, "id_data %v", &data))
820 else if (unformat (i, "local"))
822 else if (unformat (i, "remote"))
826 errmsg ("parse error '%U'", format_unformat_error, i);
833 errmsg ("profile name must be specified");
837 if (vec_len (name) > 64)
839 errmsg ("profile name too long");
845 errmsg ("id_data must be specified");
851 errmsg ("id_type must be specified");
855 M (IKEV2_PROFILE_SET_ID, mp);
857 mp->is_local = is_local;
858 mp->id_type = (u8) id_type;
859 mp->data_len = vec_len (data);
860 clib_memcpy (mp->name, name, vec_len (name));
861 clib_memcpy (mp->data, data, vec_len (data));
871 api_ikev2_profile_set_ts (vat_main_t * vam)
873 unformat_input_t *i = vam->input;
874 vl_api_ikev2_profile_set_ts_t *mp;
877 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
878 ip4_address_t start_addr, end_addr;
880 const char *valid_chars = "a-zA-Z0-9_";
883 start_addr.as_u32 = 0;
884 end_addr.as_u32 = (u32) ~ 0;
886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
888 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
890 else if (unformat (i, "protocol %d", &proto))
892 else if (unformat (i, "start_port %d", &start_port))
894 else if (unformat (i, "end_port %d", &end_port))
897 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
899 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
901 else if (unformat (i, "local"))
903 else if (unformat (i, "remote"))
907 errmsg ("parse error '%U'", format_unformat_error, i);
914 errmsg ("profile name must be specified");
918 if (vec_len (name) > 64)
920 errmsg ("profile name too long");
924 M (IKEV2_PROFILE_SET_TS, mp);
926 mp->ts.is_local = is_local;
927 mp->ts.protocol_id = (u8) proto;
928 mp->ts.start_port = clib_host_to_net_u16 ((u16) start_port);
929 mp->ts.end_port = clib_host_to_net_u16 ((u16) end_port);
930 ip4_address_encode (&start_addr, mp->ts.start_addr);
931 ip4_address_encode (&end_addr, mp->ts.end_addr);
932 clib_memcpy (mp->name, name, vec_len (name));
941 api_ikev2_set_local_key (vat_main_t * vam)
943 unformat_input_t *i = vam->input;
944 vl_api_ikev2_set_local_key_t *mp;
948 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
950 if (unformat (i, "file %v", &file))
954 errmsg ("parse error '%U'", format_unformat_error, i);
961 errmsg ("RSA key file must be specified");
965 if (vec_len (file) > 256)
967 errmsg ("file name too long");
971 M (IKEV2_SET_LOCAL_KEY, mp);
973 clib_memcpy (mp->key_file, file, vec_len (file));
982 api_ikev2_profile_set_udp_encap (vat_main_t * vam)
984 unformat_input_t *i = vam->input;
985 vl_api_ikev2_set_responder_t *mp;
989 const char *valid_chars = "a-zA-Z0-9_";
991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
993 if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name))
997 errmsg ("parse error '%U'", format_unformat_error, i);
1002 if (!vec_len (name))
1004 errmsg ("profile name must be specified");
1008 if (vec_len (name) > 64)
1010 errmsg ("profile name too long");
1014 M (IKEV2_PROFILE_SET_UDP_ENCAP, mp);
1016 clib_memcpy (mp->name, name, vec_len (name));
1025 api_ikev2_set_tunnel_interface (vat_main_t * vam)
1031 api_ikev2_set_responder (vat_main_t * vam)
1033 unformat_input_t *i = vam->input;
1034 vl_api_ikev2_set_responder_t *mp;
1037 u32 sw_if_index = ~0;
1038 ip4_address_t address;
1040 const char *valid_chars = "a-zA-Z0-9_";
1042 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1045 (i, "%U interface %d address %U", unformat_token, valid_chars,
1046 &name, &sw_if_index, unformat_ip4_address, &address))
1050 errmsg ("parse error '%U'", format_unformat_error, i);
1055 if (!vec_len (name))
1057 errmsg ("profile name must be specified");
1061 if (vec_len (name) > 64)
1063 errmsg ("profile name too long");
1067 M (IKEV2_SET_RESPONDER, mp);
1069 clib_memcpy (mp->name, name, vec_len (name));
1072 mp->responder.sw_if_index = clib_host_to_net_u32 (sw_if_index);
1073 ip4_address_encode (&address, mp->responder.ip4);
1081 api_ikev2_set_ike_transforms (vat_main_t * vam)
1083 unformat_input_t *i = vam->input;
1084 vl_api_ikev2_set_ike_transforms_t *mp;
1087 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
1089 const char *valid_chars = "a-zA-Z0-9_";
1091 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1093 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
1094 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
1098 errmsg ("parse error '%U'", format_unformat_error, i);
1103 if (!vec_len (name))
1105 errmsg ("profile name must be specified");
1109 if (vec_len (name) > 64)
1111 errmsg ("profile name too long");
1115 M (IKEV2_SET_IKE_TRANSFORMS, mp);
1117 clib_memcpy (mp->name, name, vec_len (name));
1119 mp->tr.crypto_alg = crypto_alg;
1120 mp->tr.crypto_key_size = clib_host_to_net_u32 (crypto_key_size);
1121 mp->tr.integ_alg = integ_alg;
1122 mp->tr.dh_group = dh_group;
1131 api_ikev2_set_esp_transforms (vat_main_t * vam)
1133 unformat_input_t *i = vam->input;
1134 vl_api_ikev2_set_esp_transforms_t *mp;
1137 u32 crypto_alg, crypto_key_size, integ_alg;
1139 const char *valid_chars = "a-zA-Z0-9_";
1141 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1143 if (unformat (i, "%U %d %d %d", unformat_token, valid_chars, &name,
1144 &crypto_alg, &crypto_key_size, &integ_alg))
1148 errmsg ("parse error '%U'", format_unformat_error, i);
1153 if (!vec_len (name))
1155 errmsg ("profile name must be specified");
1159 if (vec_len (name) > 64)
1161 errmsg ("profile name too long");
1165 M (IKEV2_SET_ESP_TRANSFORMS, mp);
1167 clib_memcpy (mp->name, name, vec_len (name));
1169 mp->tr.crypto_alg = crypto_alg;
1170 mp->tr.crypto_key_size = clib_host_to_net_u32 (crypto_key_size);
1171 mp->tr.integ_alg = integ_alg;
1179 api_ikev2_set_sa_lifetime (vat_main_t * vam)
1181 unformat_input_t *i = vam->input;
1182 vl_api_ikev2_set_sa_lifetime_t *mp;
1185 u64 lifetime, lifetime_maxdata;
1186 u32 lifetime_jitter, handover;
1188 const char *valid_chars = "a-zA-Z0-9_";
1190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1192 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
1193 &lifetime, &lifetime_jitter, &handover,
1198 errmsg ("parse error '%U'", format_unformat_error, i);
1203 if (!vec_len (name))
1205 errmsg ("profile name must be specified");
1209 if (vec_len (name) > 64)
1211 errmsg ("profile name too long");
1215 M (IKEV2_SET_SA_LIFETIME, mp);
1217 clib_memcpy (mp->name, name, vec_len (name));
1219 mp->lifetime = lifetime;
1220 mp->lifetime_jitter = lifetime_jitter;
1221 mp->handover = handover;
1222 mp->lifetime_maxdata = lifetime_maxdata;
1230 api_ikev2_initiate_sa_init (vat_main_t * vam)
1232 unformat_input_t *i = vam->input;
1233 vl_api_ikev2_initiate_sa_init_t *mp;
1237 const char *valid_chars = "a-zA-Z0-9_";
1239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1241 if (unformat (i, "%U", unformat_token, valid_chars, &name))
1245 errmsg ("parse error '%U'", format_unformat_error, i);
1250 if (!vec_len (name))
1252 errmsg ("profile name must be specified");
1256 if (vec_len (name) > 64)
1258 errmsg ("profile name too long");
1262 M (IKEV2_INITIATE_SA_INIT, mp);
1264 clib_memcpy (mp->name, name, vec_len (name));
1273 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
1275 unformat_input_t *i = vam->input;
1276 vl_api_ikev2_initiate_del_ike_sa_t *mp;
1281 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1283 if (unformat (i, "%lx", &ispi))
1287 errmsg ("parse error '%U'", format_unformat_error, i);
1292 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
1302 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
1304 unformat_input_t *i = vam->input;
1305 vl_api_ikev2_initiate_del_child_sa_t *mp;
1310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1312 if (unformat (i, "%x", &ispi))
1316 errmsg ("parse error '%U'", format_unformat_error, i);
1321 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
1331 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
1333 unformat_input_t *i = vam->input;
1334 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
1339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1341 if (unformat (i, "%x", &ispi))
1345 errmsg ("parse error '%U'", format_unformat_error, i);
1350 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
1359 #include <ikev2/ikev2.api_test.c>
1362 * fd.io coding-style-patch-verification: ON
1365 * eval: (c-set-style "gnu")