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_ip_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;
229 fformat (vam->ofp, "profile %s\n", p->name);
234 fformat (vam->ofp, " auth-method %U auth data 0x%U\n",
235 format_ikev2_auth_method, p->auth.method,
236 format_hex_bytes, p->auth.data,
237 clib_net_to_host_u32 (p->auth.data_len));
239 fformat (vam->ofp, " auth-method %U auth data %v\n",
240 format_ikev2_auth_method, p->auth.method, format (0,
248 fformat (vam->ofp, " local id-type data %U\n",
249 format_ikev2_id_type_and_data, &p->loc_id);
254 fformat (vam->ofp, " remote id-type data %U\n",
255 format_ikev2_id_type_and_data, &p->rem_id);
258 fformat (vam->ofp, " local traffic-selector addr %U - %U port %u - %u"
260 format_ip_address, &p->loc_ts.start_addr,
261 format_ip_address, &p->loc_ts.end_addr,
262 clib_net_to_host_u16 (p->loc_ts.start_port),
263 clib_net_to_host_u16 (p->loc_ts.end_port), p->loc_ts.protocol_id);
265 fformat (vam->ofp, " remote traffic-selector addr %U - %U port %u - %u"
267 format_ip_address, &p->rem_ts.start_addr,
268 format_ip_address, &p->rem_ts.end_addr,
269 clib_net_to_host_u16 (p->rem_ts.start_port),
270 clib_net_to_host_u16 (p->rem_ts.end_port), p->rem_ts.protocol_id);
271 u32 tun_itf = clib_net_to_host_u32 (p->tun_itf);
273 fformat (vam->ofp, " protected tunnel idx %d\n", tun_itf);
275 u32 sw_if_index = clib_net_to_host_u32 (p->responder.sw_if_index);
276 if (~0 != sw_if_index)
277 fformat (vam->ofp, " responder idx %d %U\n",
278 sw_if_index, format_ip_address, &p->responder.addr);
281 fformat (vam->ofp, " udp-encap\n");
283 u32 ipsec_over_udp_port = clib_net_to_host_u16 (p->ipsec_over_udp_port);
284 if (ipsec_over_udp_port != IPSEC_UDP_PORT_NONE)
285 fformat (vam->ofp, " ipsec-over-udp port %d\n", ipsec_over_udp_port);
287 u32 crypto_key_size = clib_net_to_host_u32 (p->ike_ts.crypto_key_size);
288 if (p->ike_ts.crypto_alg || p->ike_ts.integ_alg || p->ike_ts.dh_group
290 fformat (vam->ofp, " ike-crypto-alg %U %u ike-integ-alg %U ike-dh %U\n",
291 format_ikev2_transform_encr_type, p->ike_ts.crypto_alg,
292 crypto_key_size, format_ikev2_transform_integ_type,
293 p->ike_ts.integ_alg, format_ikev2_transform_dh_type,
296 crypto_key_size = clib_net_to_host_u32 (p->esp_ts.crypto_key_size);
297 if (p->esp_ts.crypto_alg || p->esp_ts.integ_alg)
298 fformat (vam->ofp, " esp-crypto-alg %U %u esp-integ-alg %U\n",
299 format_ikev2_transform_encr_type, p->esp_ts.crypto_alg,
301 format_ikev2_transform_integ_type, p->esp_ts.integ_alg);
303 fformat (vam->ofp, " lifetime %d jitter %d handover %d maxdata %d\n",
304 clib_net_to_host_u64 (p->lifetime),
305 clib_net_to_host_u32 (p->lifetime_jitter),
306 clib_net_to_host_u32 (p->handover),
307 clib_net_to_host_u64 (p->lifetime_maxdata));
309 vam->result_ready = 1;
313 api_ikev2_sa_dump (vat_main_t * vam)
315 ikev2_test_main_t *im = &ikev2_test_main;
316 vl_api_ikev2_sa_dump_t *mp;
317 vl_api_control_ping_t *mp_ping;
320 /* Construct the API message */
321 M (IKEV2_SA_DUMP, mp);
326 /* Use a control ping for synchronization */
328 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
329 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
330 mp_ping->_vl_msg_id = htons (im->ping_id);
331 mp_ping->client_index = vam->my_client_index;
332 vam->result_ready = 0;
336 /* Wait for a reply... */
342 vl_api_ikev2_sa_details_t_handler (vl_api_ikev2_sa_details_t * mp)
344 vat_main_t *vam = ikev2_test_main.vat_main;
345 vl_api_ikev2_sa_t *sa = &mp->sa;
348 vl_api_ikev2_keys_t *k = &sa->keys;
349 vl_api_ikev2_sa_t_endian (sa);
351 ip_address_decode2 (&sa->iaddr, &iaddr);
352 ip_address_decode2 (&sa->raddr, &raddr);
354 fformat (vam->ofp, "profile index %d sa index: %d\n",
355 mp->sa.profile_index, mp->sa.sa_index);
356 fformat (vam->ofp, " iip %U ispi %lx rip %U rspi %lx\n", format_ip_address,
357 &iaddr, sa->ispi, format_ip_address, &raddr, sa->rspi);
358 fformat (vam->ofp, " %U ", format_ikev2_sa_transform, &sa->encryption);
359 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->prf);
360 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &sa->integrity);
361 fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &sa->dh);
363 fformat (vam->ofp, " SK_d %U\n",
364 format_hex_bytes, k->sk_d, k->sk_d_len);
366 fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
367 format_hex_bytes, k->sk_ai, k->sk_ai_len, format_hex_bytes,
368 k->sk_ar, k->sk_ar_len);
370 fformat (vam->ofp, " SK_e i:%U\n r:%U\n", format_hex_bytes,
371 k->sk_ei, k->sk_ei_len, format_hex_bytes, k->sk_er, k->sk_er_len);
373 fformat (vam->ofp, " SK_p i:%U\n r:%U\n", format_hex_bytes,
374 k->sk_pi, k->sk_pi_len, format_hex_bytes, k->sk_pr, k->sk_pr_len);
376 fformat (vam->ofp, " identifier (i) %U\n",
377 format_ikev2_id_type_and_data, &sa->i_id);
378 fformat (vam->ofp, " identifier (r) %U\n",
379 format_ikev2_id_type_and_data, &sa->r_id);
381 vam->result_ready = 1;
385 api_ikev2_child_sa_dump (vat_main_t * vam)
387 unformat_input_t *i = vam->input;
388 ikev2_test_main_t *im = &ikev2_test_main;
389 vl_api_ikev2_child_sa_dump_t *mp;
390 vl_api_control_ping_t *mp_ping;
394 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
396 if (unformat (i, "sa_index %d", &sa_index))
400 errmsg ("parse error '%U'", format_unformat_error, i);
408 /* Construct the API message */
409 M (IKEV2_CHILD_SA_DUMP, mp);
411 mp->sa_index = clib_net_to_host_u32 (sa_index);
416 /* Use a control ping for synchronization */
418 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
419 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
420 mp_ping->_vl_msg_id = htons (im->ping_id);
421 mp_ping->client_index = vam->my_client_index;
422 vam->result_ready = 0;
426 /* Wait for a reply... */
432 vl_api_ikev2_child_sa_details_t_handler (vl_api_ikev2_child_sa_details_t * mp)
434 vat_main_t *vam = ikev2_test_main.vat_main;
435 vl_api_ikev2_child_sa_t *child_sa = &mp->child_sa;
436 vl_api_ikev2_keys_t *k = &child_sa->keys;
437 vl_api_ikev2_child_sa_t_endian (child_sa);
439 fformat (vam->ofp, " child sa %u:\n", child_sa->child_sa_index);
441 fformat (vam->ofp, " %U ", format_ikev2_sa_transform,
442 &child_sa->encryption);
443 fformat (vam->ofp, "%U ", format_ikev2_sa_transform, &child_sa->integrity);
444 fformat (vam->ofp, "%U \n", format_ikev2_sa_transform, &child_sa->esn);
446 fformat (vam->ofp, " spi(i) %lx spi(r) %lx\n",
447 child_sa->i_spi, child_sa->r_spi);
449 fformat (vam->ofp, " SK_e i:%U\n r:%U\n",
450 format_hex_bytes, k->sk_ei, k->sk_ei_len,
451 format_hex_bytes, k->sk_er, k->sk_er_len);
454 fformat (vam->ofp, " SK_a i:%U\n r:%U\n",
455 format_hex_bytes, k->sk_ai, k->sk_ai_len,
456 format_hex_bytes, k->sk_ar, k->sk_ar_len);
458 vam->result_ready = 1;
462 api_ikev2_traffic_selector_dump (vat_main_t * vam)
464 unformat_input_t *i = vam->input;
465 ikev2_test_main_t *im = &ikev2_test_main;
466 vl_api_ikev2_traffic_selector_dump_t *mp;
467 vl_api_control_ping_t *mp_ping;
468 int is_initiator = ~0;
470 int child_sa_index = ~0;
473 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
475 if (unformat (i, "initiator"))
477 else if (unformat (i, "responder"))
479 else if (unformat (i, "sa_index %d", &sa_index))
481 else if (unformat (i, "child_sa_index %d", &child_sa_index))
485 errmsg ("parse error '%U'", format_unformat_error, i);
490 if (child_sa_index == ~0 || sa_index == ~0 || is_initiator == ~0)
493 /* Construct the API message */
494 M (IKEV2_TRAFFIC_SELECTOR_DUMP, mp);
496 mp->is_initiator = is_initiator;
497 mp->sa_index = clib_host_to_net_u32 (sa_index);
498 mp->child_sa_index = clib_host_to_net_u32 (child_sa_index);
503 /* Use a control ping for synchronization */
505 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
506 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
507 mp_ping->_vl_msg_id = htons (im->ping_id);
508 mp_ping->client_index = vam->my_client_index;
509 vam->result_ready = 0;
513 /* Wait for a reply... */
519 vl_api_ikev2_traffic_selector_details_t_handler
520 (vl_api_ikev2_traffic_selector_details_t * mp)
522 vat_main_t *vam = ikev2_test_main.vat_main;
523 vl_api_ikev2_ts_t *ts = &mp->ts;
524 ip_address_t start_addr, end_addr;
525 vl_api_ikev2_ts_t_endian (ts);
527 ip_address_decode2 (&ts->start_addr, &start_addr);
528 ip_address_decode2 (&ts->end_addr, &end_addr);
530 fformat (vam->ofp, " %s protocol_id %u addr "
531 "%U - %U port %u - %u\n",
532 ts->is_local, ts->protocol_id,
533 format_ip_address, &start_addr,
534 format_ip_address, &end_addr, ts->start_port, ts->end_port);
535 vam->result_ready = 1;
539 api_ikev2_nonce_get (vat_main_t * vam)
541 unformat_input_t *i = vam->input;
542 ikev2_test_main_t *im = &ikev2_test_main;
543 vl_api_ikev2_nonce_get_t *mp;
544 vl_api_control_ping_t *mp_ping;
545 u32 is_initiator = ~0;
549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
551 if (unformat (i, "initiator"))
553 else if (unformat (i, "responder"))
555 else if (unformat (i, "sa_index %d", &sa_index))
559 errmsg ("parse error '%U'", format_unformat_error, i);
564 if (sa_index == ~0 || is_initiator == ~0)
567 /* Construct the API message */
568 M (IKEV2_NONCE_GET, mp);
570 mp->is_initiator = is_initiator;
571 mp->sa_index = clib_host_to_net_u32 (sa_index);
576 /* Use a control ping for synchronization */
578 im->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
579 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
580 mp_ping->_vl_msg_id = htons (im->ping_id);
581 mp_ping->client_index = vam->my_client_index;
582 vam->result_ready = 0;
586 /* Wait for a reply... */
592 vl_api_ikev2_nonce_get_reply_t_handler (vl_api_ikev2_nonce_get_reply_t * mp)
594 vat_main_t *vam = ikev2_test_main.vat_main;
595 mp->data_len = clib_net_to_host_u32 (mp->data_len);
597 fformat (vam->ofp, " nonce:%U\n",
598 format_hex_bytes, mp->nonce, mp->data_len);
600 vam->result_ready = 1;
604 api_ikev2_plugin_get_version (vat_main_t * vam)
606 ikev2_test_main_t *sm = &ikev2_test_main;
607 vl_api_ikev2_plugin_get_version_t *mp;
608 u32 msg_size = sizeof (*mp);
611 vam->result_ready = 0;
612 mp = vl_msg_api_alloc_as_if_client (msg_size);
613 clib_memset (mp, 0, msg_size);
614 mp->_vl_msg_id = ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION + sm->msg_id_base);
615 mp->client_index = vam->my_client_index;
620 /* Wait for a reply... */
625 static void vl_api_ikev2_plugin_get_version_reply_t_handler
626 (vl_api_ikev2_plugin_get_version_reply_t * mp)
628 vat_main_t *vam = ikev2_test_main.vat_main;
629 clib_warning ("IKEv2 plugin version: %d.%d", ntohl (mp->major),
631 vam->result_ready = 1;
635 api_ikev2_profile_set_ipsec_udp_port (vat_main_t * vam)
641 api_ikev2_profile_set_liveness (vat_main_t * vam)
643 unformat_input_t *i = vam->input;
644 vl_api_ikev2_profile_set_liveness_t *mp;
645 u32 period = 0, max_retries = 0;
648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
650 if (!unformat (i, "period %d max-retries %d", &period, &max_retries))
652 errmsg ("parse error '%U'", format_unformat_error, i);
657 M (IKEV2_PROFILE_SET_LIVENESS, mp);
659 mp->period = clib_host_to_net_u32 (period);
660 mp->max_retries = clib_host_to_net_u32 (max_retries);
669 api_ikev2_profile_add_del (vat_main_t * vam)
671 unformat_input_t *i = vam->input;
672 vl_api_ikev2_profile_add_del_t *mp;
677 const char *valid_chars = "a-zA-Z0-9_";
679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
681 if (unformat (i, "del"))
683 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
687 errmsg ("parse error '%U'", format_unformat_error, i);
694 errmsg ("profile name must be specified");
698 if (vec_len (name) > 64)
700 errmsg ("profile name too long");
704 M (IKEV2_PROFILE_ADD_DEL, mp);
706 clib_memcpy (mp->name, name, vec_len (name));
716 api_ikev2_profile_set_auth (vat_main_t * vam)
718 unformat_input_t *i = vam->input;
719 vl_api_ikev2_profile_set_auth_t *mp;
726 const char *valid_chars = "a-zA-Z0-9_";
728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
730 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
732 else if (unformat (i, "auth_method %U",
733 unformat_ikev2_auth_method, &auth_method))
735 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
737 else if (unformat (i, "auth_data %v", &data))
741 errmsg ("parse error '%U'", format_unformat_error, i);
748 errmsg ("profile name must be specified");
752 if (vec_len (name) > 64)
754 errmsg ("profile name too long");
760 errmsg ("auth_data must be specified");
766 errmsg ("auth_method must be specified");
770 M (IKEV2_PROFILE_SET_AUTH, mp);
773 mp->auth_method = (u8) auth_method;
774 mp->data_len = vec_len (data);
775 clib_memcpy (mp->name, name, vec_len (name));
776 clib_memcpy (mp->data, data, vec_len (data));
786 api_ikev2_profile_set_id (vat_main_t * vam)
788 unformat_input_t *i = vam->input;
789 vl_api_ikev2_profile_set_id_t *mp;
797 const char *valid_chars = "a-zA-Z0-9_";
799 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
801 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
803 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
805 else if (unformat (i, "id_data %U", unformat_ip_address, &ip))
807 data = vec_new (u8, ip_address_size (&ip));
808 clib_memcpy (data, ip_addr_bytes (&ip), ip_address_size (&ip));
810 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
812 else if (unformat (i, "id_data %v", &data))
814 else if (unformat (i, "local"))
816 else if (unformat (i, "remote"))
820 errmsg ("parse error '%U'", format_unformat_error, i);
827 errmsg ("profile name must be specified");
831 if (vec_len (name) > 64)
833 errmsg ("profile name too long");
839 errmsg ("id_data must be specified");
845 errmsg ("id_type must be specified");
849 M (IKEV2_PROFILE_SET_ID, mp);
851 mp->is_local = is_local;
852 mp->id_type = (u8) id_type;
853 mp->data_len = vec_len (data);
854 clib_memcpy (mp->name, name, vec_len (name));
855 clib_memcpy (mp->data, data, vec_len (data));
865 api_ikev2_profile_set_ts (vat_main_t * vam)
867 unformat_input_t *i = vam->input;
868 vl_api_ikev2_profile_set_ts_t *mp;
871 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
872 ip_address_t start_addr, end_addr;
873 u8 start_addr_set = 0, end_addr_set = 0;
875 const char *valid_chars = "a-zA-Z0-9_";
878 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
880 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
882 else if (unformat (i, "protocol %d", &proto))
884 else if (unformat (i, "start_port %d", &start_port))
886 else if (unformat (i, "end_port %d", &end_port))
889 if (unformat (i, "start_addr %U", unformat_ip_address, &start_addr))
891 else if (unformat (i, "end_addr %U", unformat_ip_address, &end_addr))
893 else if (unformat (i, "local"))
895 else if (unformat (i, "remote"))
899 errmsg ("parse error '%U'", format_unformat_error, i);
904 if (!start_addr_set || !end_addr_set)
906 errmsg ("missing start or end address");
912 errmsg ("profile name must be specified");
916 if (vec_len (name) > 64)
918 errmsg ("profile name too long");
922 M (IKEV2_PROFILE_SET_TS, mp);
924 mp->ts.is_local = is_local;
925 mp->ts.protocol_id = (u8) proto;
926 mp->ts.start_port = clib_host_to_net_u16 ((u16) start_port);
927 mp->ts.end_port = clib_host_to_net_u16 ((u16) end_port);
928 ip_address_encode2 (&start_addr, &mp->ts.start_addr);
929 ip_address_encode2 (&end_addr, &mp->ts.end_addr);
930 clib_memcpy (mp->name, name, vec_len (name));
939 api_ikev2_set_local_key (vat_main_t * vam)
941 unformat_input_t *i = vam->input;
942 vl_api_ikev2_set_local_key_t *mp;
946 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
948 if (unformat (i, "file %v", &file))
952 errmsg ("parse error '%U'", format_unformat_error, i);
959 errmsg ("RSA key file must be specified");
963 if (vec_len (file) > 256)
965 errmsg ("file name too long");
969 M (IKEV2_SET_LOCAL_KEY, mp);
971 clib_memcpy (mp->key_file, file, vec_len (file));
980 api_ikev2_profile_set_udp_encap (vat_main_t * vam)
982 unformat_input_t *i = vam->input;
983 vl_api_ikev2_set_responder_t *mp;
987 const char *valid_chars = "a-zA-Z0-9_";
989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
991 if (unformat (i, "%U udp-encap", unformat_token, valid_chars, &name))
995 errmsg ("parse error '%U'", format_unformat_error, i);
1000 if (!vec_len (name))
1002 errmsg ("profile name must be specified");
1006 if (vec_len (name) > 64)
1008 errmsg ("profile name too long");
1012 M (IKEV2_PROFILE_SET_UDP_ENCAP, mp);
1014 clib_memcpy (mp->name, name, vec_len (name));
1023 api_ikev2_set_tunnel_interface (vat_main_t * vam)
1029 api_ikev2_set_responder (vat_main_t * vam)
1031 unformat_input_t *i = vam->input;
1032 vl_api_ikev2_set_responder_t *mp;
1035 u32 sw_if_index = ~0;
1036 ip_address_t address;
1038 const char *valid_chars = "a-zA-Z0-9_";
1040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1043 (i, "%U interface %d address %U", unformat_token, valid_chars,
1044 &name, &sw_if_index, unformat_ip_address, &address))
1048 errmsg ("parse error '%U'", format_unformat_error, i);
1053 if (!vec_len (name))
1055 errmsg ("profile name must be specified");
1059 if (vec_len (name) > 64)
1061 errmsg ("profile name too long");
1065 M (IKEV2_SET_RESPONDER, mp);
1067 clib_memcpy (mp->name, name, vec_len (name));
1070 mp->responder.sw_if_index = clib_host_to_net_u32 (sw_if_index);
1071 ip_address_encode2 (&address, &mp->responder.addr);
1079 api_ikev2_set_ike_transforms (vat_main_t * vam)
1081 unformat_input_t *i = vam->input;
1082 vl_api_ikev2_set_ike_transforms_t *mp;
1085 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
1087 const char *valid_chars = "a-zA-Z0-9_";
1089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1091 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
1092 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
1096 errmsg ("parse error '%U'", format_unformat_error, i);
1101 if (!vec_len (name))
1103 errmsg ("profile name must be specified");
1107 if (vec_len (name) > 64)
1109 errmsg ("profile name too long");
1113 M (IKEV2_SET_IKE_TRANSFORMS, mp);
1115 clib_memcpy (mp->name, name, vec_len (name));
1117 mp->tr.crypto_alg = crypto_alg;
1118 mp->tr.crypto_key_size = clib_host_to_net_u32 (crypto_key_size);
1119 mp->tr.integ_alg = integ_alg;
1120 mp->tr.dh_group = dh_group;
1129 api_ikev2_set_esp_transforms (vat_main_t * vam)
1131 unformat_input_t *i = vam->input;
1132 vl_api_ikev2_set_esp_transforms_t *mp;
1135 u32 crypto_alg, crypto_key_size, integ_alg;
1137 const char *valid_chars = "a-zA-Z0-9_";
1139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1141 if (unformat (i, "%U %d %d %d", unformat_token, valid_chars, &name,
1142 &crypto_alg, &crypto_key_size, &integ_alg))
1146 errmsg ("parse error '%U'", format_unformat_error, i);
1151 if (!vec_len (name))
1153 errmsg ("profile name must be specified");
1157 if (vec_len (name) > 64)
1159 errmsg ("profile name too long");
1163 M (IKEV2_SET_ESP_TRANSFORMS, mp);
1165 clib_memcpy (mp->name, name, vec_len (name));
1167 mp->tr.crypto_alg = crypto_alg;
1168 mp->tr.crypto_key_size = clib_host_to_net_u32 (crypto_key_size);
1169 mp->tr.integ_alg = integ_alg;
1177 api_ikev2_set_sa_lifetime (vat_main_t * vam)
1179 unformat_input_t *i = vam->input;
1180 vl_api_ikev2_set_sa_lifetime_t *mp;
1183 u64 lifetime, lifetime_maxdata;
1184 u32 lifetime_jitter, handover;
1186 const char *valid_chars = "a-zA-Z0-9_";
1188 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1190 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
1191 &lifetime, &lifetime_jitter, &handover,
1196 errmsg ("parse error '%U'", format_unformat_error, i);
1201 if (!vec_len (name))
1203 errmsg ("profile name must be specified");
1207 if (vec_len (name) > 64)
1209 errmsg ("profile name too long");
1213 M (IKEV2_SET_SA_LIFETIME, mp);
1215 clib_memcpy (mp->name, name, vec_len (name));
1217 mp->lifetime = lifetime;
1218 mp->lifetime_jitter = lifetime_jitter;
1219 mp->handover = handover;
1220 mp->lifetime_maxdata = lifetime_maxdata;
1228 api_ikev2_initiate_sa_init (vat_main_t * vam)
1230 unformat_input_t *i = vam->input;
1231 vl_api_ikev2_initiate_sa_init_t *mp;
1235 const char *valid_chars = "a-zA-Z0-9_";
1237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1239 if (unformat (i, "%U", unformat_token, valid_chars, &name))
1243 errmsg ("parse error '%U'", format_unformat_error, i);
1248 if (!vec_len (name))
1250 errmsg ("profile name must be specified");
1254 if (vec_len (name) > 64)
1256 errmsg ("profile name too long");
1260 M (IKEV2_INITIATE_SA_INIT, mp);
1262 clib_memcpy (mp->name, name, vec_len (name));
1271 api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
1273 unformat_input_t *i = vam->input;
1274 vl_api_ikev2_initiate_del_ike_sa_t *mp;
1279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1281 if (unformat (i, "%lx", &ispi))
1285 errmsg ("parse error '%U'", format_unformat_error, i);
1290 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
1300 api_ikev2_initiate_del_child_sa (vat_main_t * vam)
1302 unformat_input_t *i = vam->input;
1303 vl_api_ikev2_initiate_del_child_sa_t *mp;
1308 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1310 if (unformat (i, "%x", &ispi))
1314 errmsg ("parse error '%U'", format_unformat_error, i);
1319 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
1329 api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
1331 unformat_input_t *i = vam->input;
1332 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
1337 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1339 if (unformat (i, "%x", &ispi))
1343 errmsg ("parse error '%U'", format_unformat_error, i);
1348 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
1357 #include <ikev2/ikev2.api_test.c>
1360 * fd.io coding-style-patch-verification: ON
1363 * eval: (c-set-style "gnu")