2 *------------------------------------------------------------------
3 * ipsec_api.c - ipsec api
5 * Copyright (c) 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 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 #include <vnet/api_errno.h>
23 #include <vpp/app/version.h>
24 #include <vnet/ip/ip_types_api.h>
25 #include <ikev2/ikev2.h>
26 #include <ikev2/ikev2_priv.h>
28 /* define message IDs */
29 #include <vnet/format_fns.h>
30 #include <plugins/ikev2/ikev2.api_enum.h>
31 #include <plugins/ikev2/ikev2.api_types.h>
34 #define vl_endianfun /* define message structures */
35 #include <plugins/ikev2/ikev2.api.h>
36 #include <plugins/ikev2/ikev2_types.api.h>
39 extern ikev2_main_t ikev2_main;
41 #define IKEV2_PLUGIN_VERSION_MAJOR 1
42 #define IKEV2_PLUGIN_VERSION_MINOR 0
43 #define REPLY_MSG_ID_BASE ikev2_main.msg_id_base
44 #include <vlibapi/api_helper_macros.h>
46 #define IKEV2_MAX_DATA_LEN (1 << 10)
49 ikev2_encode_sa_index (u32 sai, u32 ti)
51 return (ti << 16) | sai;
55 ikev2_decode_sa_index (u32 api_sai, u32 * sai, u32 * ti)
57 *sai = api_sai & 0xffff;
62 cp_ike_transforms (vl_api_ikev2_ike_transforms_t * vl_api_ts,
63 ikev2_transforms_set * ts)
65 vl_api_ts->crypto_alg = ts->crypto_alg;
66 vl_api_ts->integ_alg = ts->integ_alg;
67 vl_api_ts->dh_group = ts->dh_type;
68 vl_api_ts->crypto_key_size = ts->crypto_key_size;
72 cp_esp_transforms (vl_api_ikev2_esp_transforms_t * vl_api_ts,
73 ikev2_transforms_set * ts)
75 vl_api_ts->crypto_alg = ts->crypto_alg;
76 vl_api_ts->integ_alg = ts->integ_alg;
77 vl_api_ts->crypto_key_size = ts->crypto_key_size;
81 cp_id (vl_api_ikev2_id_t * vl_api_id, ikev2_id_t * id)
87 vl_api_id->type = id->type;
88 size_data = sizeof (vl_api_id->data) - 1; // size without zero ending character
89 if (vec_len (id->data) < size_data)
90 size_data = vec_len (id->data);
92 vl_api_id->data_len = size_data;
93 clib_memcpy (vl_api_id->data, id->data, size_data);
97 cp_ts (vl_api_ikev2_ts_t * vl_api_ts, ikev2_ts_t * ts, u8 is_local)
99 vl_api_ts->is_local = is_local;
100 vl_api_ts->protocol_id = ts->protocol_id;
101 vl_api_ts->start_port = ts->start_port;
102 vl_api_ts->end_port = ts->end_port;
103 ip_address_encode2 (&ts->start_addr, &vl_api_ts->start_addr);
104 ip_address_encode2 (&ts->end_addr, &vl_api_ts->end_addr);
108 cp_auth (vl_api_ikev2_auth_t * vl_api_auth, ikev2_auth_t * auth)
110 vl_api_auth->method = auth->method;
111 vl_api_auth->data_len = vec_len (auth->data);
112 vl_api_auth->hex = auth->hex;
113 clib_memcpy (&vl_api_auth->data, auth->data, vec_len (auth->data));
117 cp_responder (vl_api_ikev2_responder_t * vl_api_responder,
118 ikev2_responder_t * responder)
120 vl_api_responder->sw_if_index = responder->sw_if_index;
121 ip_address_encode2 (&responder->addr, &vl_api_responder->addr);
125 cp_sa_transform (vl_api_ikev2_sa_transform_t * vl_tr,
126 ikev2_sa_transform_t * tr)
128 vl_tr->transform_type = tr->type;
129 vl_tr->key_len = tr->key_len;
130 vl_tr->key_trunc = tr->key_trunc;
131 vl_tr->block_size = tr->block_size;
132 vl_tr->dh_group = tr->dh_group;
133 vl_tr->transform_id = tr->encr_type;
137 send_profile (ikev2_profile_t * profile, vl_api_registration_t * reg,
140 vl_api_ikev2_profile_details_t *rmp = 0;
142 rmp = vl_msg_api_alloc (sizeof (*rmp) + vec_len (profile->auth.data));
143 clib_memset (rmp, 0, sizeof (*rmp) + vec_len (profile->auth.data));
144 ikev2_main_t *im = &ikev2_main;
145 rmp->_vl_msg_id = ntohs (VL_API_IKEV2_PROFILE_DETAILS + im->msg_id_base);
146 rmp->context = context;
148 int size_data = sizeof (rmp->profile.name) - 1;
149 if (vec_len (profile->name) < size_data)
150 size_data = vec_len (profile->name);
151 clib_memcpy (rmp->profile.name, profile->name, size_data);
153 cp_ike_transforms (&rmp->profile.ike_ts, &profile->ike_ts);
154 cp_esp_transforms (&rmp->profile.esp_ts, &profile->esp_ts);
156 cp_id (&rmp->profile.loc_id, &profile->loc_id);
157 cp_id (&rmp->profile.rem_id, &profile->rem_id);
159 cp_ts (&rmp->profile.rem_ts, &profile->rem_ts, 0 /* is_local */ );
160 cp_ts (&rmp->profile.loc_ts, &profile->loc_ts, 1 /* is_local */ );
162 cp_auth (&rmp->profile.auth, &profile->auth);
164 cp_responder (&rmp->profile.responder, &profile->responder);
166 rmp->profile.udp_encap = profile->udp_encap;
167 rmp->profile.tun_itf = profile->tun_itf;
168 rmp->profile.natt_disabled = profile->natt_disabled;
169 rmp->profile.ipsec_over_udp_port = profile->ipsec_over_udp_port;
171 rmp->profile.lifetime = profile->lifetime;
172 rmp->profile.lifetime_maxdata = profile->lifetime_maxdata;
173 rmp->profile.lifetime_jitter = profile->lifetime_jitter;
174 rmp->profile.handover = profile->handover;
176 vl_api_ikev2_profile_t_endian (&rmp->profile);
178 vl_api_send_msg (reg, (u8 *) rmp);
182 vl_api_ikev2_profile_dump_t_handler (vl_api_ikev2_profile_dump_t * mp)
184 ikev2_main_t *im = &ikev2_main;
185 ikev2_profile_t *profile;
186 vl_api_registration_t *reg;
187 reg = vl_api_client_index_to_registration (mp->client_index);
192 pool_foreach (profile, im->profiles)
194 send_profile (profile, reg, mp->context);
200 ikev2_copy_stats (vl_api_ikev2_sa_stats_t *dst, const ikev2_stats_t *src)
202 dst->n_rekey_req = src->n_rekey_req;
203 dst->n_keepalives = src->n_keepalives;
204 dst->n_retransmit = src->n_retransmit;
205 dst->n_init_sa_retransmit = src->n_init_retransmit;
206 dst->n_sa_init_req = src->n_sa_init_req;
207 dst->n_sa_auth_req = src->n_sa_auth_req;
211 send_sa (ikev2_sa_t * sa, vl_api_ikev2_sa_dump_t * mp, u32 api_sa_index)
213 vl_api_ikev2_sa_details_t *rmp = 0;
215 ikev2_sa_transform_t *tr;
218 REPLY_MACRO2_ZERO (VL_API_IKEV2_SA_DETAILS,
220 vl_api_ikev2_sa_t *rsa = &rmp->sa;
221 vl_api_ikev2_keys_t* k = &rsa->keys;
222 rsa->profile_index = rsa->profile_index;
223 rsa->sa_index = api_sa_index;
224 ip_address_encode2 (&sa->iaddr, &rsa->iaddr);
225 ip_address_encode2 (&sa->raddr, &rsa->raddr);
226 rsa->ispi = sa->ispi;
227 rsa->rspi = sa->rspi;
228 cp_id(&rsa->i_id, &sa->i_id);
229 cp_id(&rsa->r_id, &sa->r_id);
231 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
233 cp_sa_transform (&rsa->encryption, tr);
235 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
237 cp_sa_transform (&rsa->prf, tr);
239 tr = ikev2_sa_get_td_for_type (sa->r_proposals,
240 IKEV2_TRANSFORM_TYPE_INTEG);
242 cp_sa_transform (&rsa->integrity, tr);
244 tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
246 cp_sa_transform (&rsa->dh, tr);
248 k->sk_d_len = vec_len (sa->sk_d);
249 clib_memcpy (&k->sk_d, sa->sk_d, k->sk_d_len);
251 k->sk_ai_len = vec_len (sa->sk_ai);
252 clib_memcpy (&k->sk_ai, sa->sk_ai, k->sk_ai_len);
254 k->sk_ar_len = vec_len (sa->sk_ar);
255 clib_memcpy (&k->sk_ar, sa->sk_ar, k->sk_ar_len);
257 k->sk_ei_len = vec_len (sa->sk_ei);
258 clib_memcpy (&k->sk_ei, sa->sk_ei, k->sk_ei_len);
260 k->sk_er_len = vec_len (sa->sk_er);
261 clib_memcpy (&k->sk_er, sa->sk_er, k->sk_er_len);
263 k->sk_pi_len = vec_len (sa->sk_pi);
264 clib_memcpy (&k->sk_pi, sa->sk_pi, k->sk_pi_len);
266 k->sk_pr_len = vec_len (sa->sk_pr);
267 clib_memcpy (&k->sk_pr, sa->sk_pr, k->sk_pr_len);
269 ikev2_copy_stats (&rsa->stats, &sa->stats);
271 vl_api_ikev2_sa_t_endian(rsa);
277 vl_api_ikev2_sa_dump_t_handler (vl_api_ikev2_sa_dump_t * mp)
279 ikev2_main_t *km = &ikev2_main;
280 ikev2_main_per_thread_data_t *tkm;
283 vec_foreach (tkm, km->per_thread_data)
286 pool_foreach (sa, tkm->sas)
288 u32 api_sa_index = ikev2_encode_sa_index (sa - tkm->sas,
289 tkm - km->per_thread_data);
290 send_sa (sa, mp, api_sa_index);
298 send_child_sa (ikev2_child_sa_t * child,
299 vl_api_ikev2_child_sa_dump_t * mp, u32 child_sa_index,
302 vl_api_ikev2_child_sa_details_t *rmp = 0;
304 ikev2_sa_transform_t *tr;
307 REPLY_MACRO2_ZERO (VL_API_IKEV2_CHILD_SA_DETAILS,
309 vl_api_ikev2_keys_t *k = &rmp->child_sa.keys;
310 rmp->child_sa.child_sa_index = child_sa_index;
311 rmp->child_sa.sa_index = sa_index;
312 rmp->child_sa.i_spi =
313 child->i_proposals ? child->i_proposals[0].spi : 0;
314 rmp->child_sa.r_spi =
315 child->r_proposals ? child->r_proposals[0].spi : 0;
317 tr = ikev2_sa_get_td_for_type (child->r_proposals,
318 IKEV2_TRANSFORM_TYPE_ENCR);
320 cp_sa_transform (&rmp->child_sa.encryption, tr);
322 tr = ikev2_sa_get_td_for_type (child->r_proposals,
323 IKEV2_TRANSFORM_TYPE_INTEG);
325 cp_sa_transform (&rmp->child_sa.integrity, tr);
327 tr = ikev2_sa_get_td_for_type (child->r_proposals,
328 IKEV2_TRANSFORM_TYPE_ESN);
330 cp_sa_transform (&rmp->child_sa.esn, tr);
332 k->sk_ei_len = vec_len (child->sk_ei);
333 clib_memcpy (&k->sk_ei, child->sk_ei, k->sk_ei_len);
335 k->sk_er_len = vec_len (child->sk_er);
336 clib_memcpy (&k->sk_er, child->sk_er, k->sk_er_len);
338 if (vec_len (child->sk_ai))
340 k->sk_ai_len = vec_len (child->sk_ai);
341 clib_memcpy (&k->sk_ai, child->sk_ai,
344 k->sk_ar_len = vec_len (child->sk_ar);
345 clib_memcpy (&k->sk_ar, child->sk_ar,
349 vl_api_ikev2_child_sa_t_endian (&rmp->child_sa);
355 vl_api_ikev2_child_sa_dump_t_handler (vl_api_ikev2_child_sa_dump_t * mp)
357 ikev2_main_t *im = &ikev2_main;
358 ikev2_main_per_thread_data_t *tkm;
360 ikev2_child_sa_t *child;
361 u32 sai = ~0, ti = ~0;
363 ikev2_decode_sa_index (clib_net_to_host_u32 (mp->sa_index), &sai, &ti);
365 if (vec_len (im->per_thread_data) <= ti)
368 tkm = vec_elt_at_index (im->per_thread_data, ti);
370 if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
373 sa = pool_elt_at_index (tkm->sas, sai);
375 vec_foreach (child, sa->childs)
377 u32 child_sa_index = child - sa->childs;
378 send_child_sa (child, mp, child_sa_index, sai);
383 vl_api_ikev2_traffic_selector_dump_t_handler
384 (vl_api_ikev2_traffic_selector_dump_t * mp)
386 ikev2_main_t *im = &ikev2_main;
387 ikev2_main_per_thread_data_t *tkm;
389 ikev2_child_sa_t *child;
391 u32 sai = ~0, ti = ~0;
393 u32 api_sa_index = clib_net_to_host_u32 (mp->sa_index);
394 u32 child_sa_index = clib_net_to_host_u32 (mp->child_sa_index);
395 ikev2_decode_sa_index (api_sa_index, &sai, &ti);
397 if (vec_len (im->per_thread_data) <= ti)
400 tkm = vec_elt_at_index (im->per_thread_data, ti);
402 if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
405 sa = pool_elt_at_index (tkm->sas, sai);
407 if (vec_len (sa->childs) <= child_sa_index)
410 child = vec_elt_at_index (sa->childs, child_sa_index);
412 vec_foreach (ts, mp->is_initiator ? child->tsi : child->tsr)
414 vl_api_ikev2_traffic_selector_details_t *rmp = 0;
418 REPLY_MACRO2_ZERO (VL_API_IKEV2_TRAFFIC_SELECTOR_DETAILS,
420 rmp->ts.sa_index = api_sa_index;
421 rmp->ts.child_sa_index = child_sa_index;
422 cp_ts (&rmp->ts, ts, mp->is_initiator);
423 vl_api_ikev2_ts_t_endian (&rmp->ts);
430 vl_api_ikev2_nonce_get_t_handler (vl_api_ikev2_nonce_get_t * mp)
432 ikev2_main_t *im = &ikev2_main;
433 ikev2_main_per_thread_data_t *tkm;
435 u32 sai = ~0, ti = ~0;
437 ikev2_decode_sa_index (clib_net_to_host_u32 (mp->sa_index), &sai, &ti);
439 if (vec_len (im->per_thread_data) <= ti)
442 tkm = vec_elt_at_index (im->per_thread_data, ti);
444 if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
447 sa = pool_elt_at_index (tkm->sas, sai);
449 u8 *nonce = mp->is_initiator ? sa->i_nonce : sa->r_nonce;
450 vl_api_ikev2_nonce_get_reply_t *rmp = 0;
451 int data_len = vec_len (nonce);
455 REPLY_MACRO3_ZERO (VL_API_IKEV2_NONCE_GET_REPLY, data_len,
457 rmp->data_len = clib_host_to_net_u32 (data_len);
458 clib_memcpy (rmp->nonce, nonce, data_len);
464 vl_api_ikev2_plugin_get_version_t_handler (vl_api_ikev2_plugin_get_version_t *
467 ikev2_main_t *im = &ikev2_main;
468 vl_api_ikev2_plugin_get_version_reply_t *rmp;
469 int msg_size = sizeof (*rmp);
470 vl_api_registration_t *reg;
472 reg = vl_api_client_index_to_registration (mp->client_index);
476 rmp = vl_msg_api_alloc (msg_size);
477 clib_memset (rmp, 0, msg_size);
479 ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION_REPLY + im->msg_id_base);
480 rmp->context = mp->context;
481 rmp->major = htonl (IKEV2_PLUGIN_VERSION_MAJOR);
482 rmp->minor = htonl (IKEV2_PLUGIN_VERSION_MINOR);
484 vl_api_send_msg (reg, (u8 *) rmp);
488 vl_api_ikev2_profile_set_liveness_t_handler
489 (vl_api_ikev2_profile_set_liveness_t * mp)
491 vl_api_ikev2_profile_set_liveness_reply_t *rmp;
496 error = ikev2_set_liveness_params (clib_net_to_host_u32 (mp->period),
497 clib_net_to_host_u32 (mp->max_retries));
500 ikev2_log_error ("%U", format_clib_error, error);
501 clib_error_free (error);
502 rv = VNET_API_ERROR_UNSPECIFIED;
505 rv = VNET_API_ERROR_UNIMPLEMENTED;
508 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_LIVENESS_REPLY);
512 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
514 vl_api_ikev2_profile_add_del_reply_t *rmp;
518 vlib_main_t *vm = vlib_get_main ();
520 u8 *tmp = format (0, "%s", mp->name);
521 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
525 ikev2_log_error ("%U", format_clib_error, error);
526 clib_error_free (error);
527 rv = VNET_API_ERROR_UNSPECIFIED;
530 rv = VNET_API_ERROR_UNIMPLEMENTED;
533 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
537 vl_api_ikev2_profile_set_auth_t_handler
538 (vl_api_ikev2_profile_set_auth_t * mp)
540 vl_api_ikev2_profile_set_auth_reply_t *rmp;
544 vlib_main_t *vm = vlib_get_main ();
546 int data_len = ntohl (mp->data_len);
547 if (data_len > 0 && data_len <= IKEV2_MAX_DATA_LEN)
549 u8 *tmp = format (0, "%s", mp->name);
550 u8 *data = vec_new (u8, data_len);
551 clib_memcpy (data, mp->data, data_len);
553 ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
558 ikev2_log_error ("%U", format_clib_error, error);
559 clib_error_free (error);
560 rv = VNET_API_ERROR_UNSPECIFIED;
564 rv = VNET_API_ERROR_INVALID_VALUE;
566 rv = VNET_API_ERROR_UNIMPLEMENTED;
569 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
573 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
575 vl_api_ikev2_profile_set_id_reply_t *rmp;
579 vlib_main_t *vm = vlib_get_main ();
581 u8 *tmp = format (0, "%s", mp->name);
582 int data_len = ntohl (mp->data_len);
583 if (data_len > 0 && data_len <= IKEV2_MAX_DATA_LEN)
585 u8 *data = vec_new (u8, data_len);
586 clib_memcpy (data, mp->data, data_len);
587 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
592 ikev2_log_error ("%U", format_clib_error, error);
593 clib_error_free (error);
594 rv = VNET_API_ERROR_UNSPECIFIED;
598 rv = VNET_API_ERROR_INVALID_VALUE;
600 rv = VNET_API_ERROR_UNIMPLEMENTED;
603 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
607 vl_api_ikev2_profile_set_udp_encap_t_handler
608 (vl_api_ikev2_profile_set_udp_encap_t * mp)
610 vl_api_ikev2_profile_set_udp_encap_reply_t *rmp;
614 vlib_main_t *vm = vlib_get_main ();
616 u8 *tmp = format (0, "%s", mp->name);
617 error = ikev2_set_profile_udp_encap (vm, tmp);
621 ikev2_log_error ("%U", format_clib_error, error);
622 clib_error_free (error);
623 rv = VNET_API_ERROR_UNSPECIFIED;
626 rv = VNET_API_ERROR_UNIMPLEMENTED;
629 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_UDP_ENCAP_REPLY);
633 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
635 vl_api_ikev2_profile_set_ts_reply_t *rmp;
639 vlib_main_t *vm = vlib_get_main ();
641 u8 *tmp = format (0, "%s", mp->name);
642 ip_address_t start_addr, end_addr;
643 ip_address_decode2 (&mp->ts.start_addr, &start_addr);
644 ip_address_decode2 (&mp->ts.end_addr, &end_addr);
646 ikev2_set_profile_ts (vm, tmp, mp->ts.protocol_id,
647 clib_net_to_host_u16 (mp->ts.start_port),
648 clib_net_to_host_u16 (mp->ts.end_port),
649 start_addr, end_addr, mp->ts.is_local);
653 ikev2_log_error ("%U", format_clib_error, error);
654 clib_error_free (error);
655 rv = VNET_API_ERROR_UNSPECIFIED;
658 rv = VNET_API_ERROR_UNIMPLEMENTED;
661 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
665 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
667 vl_api_ikev2_set_local_key_reply_t *rmp;
671 vlib_main_t *vm = vlib_get_main ();
674 error = ikev2_set_local_key (vm, mp->key_file);
677 ikev2_log_error ("%U", format_clib_error, error);
678 clib_error_free (error);
679 rv = VNET_API_ERROR_UNSPECIFIED;
682 rv = VNET_API_ERROR_UNIMPLEMENTED;
685 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
689 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
691 vl_api_ikev2_set_responder_reply_t *rmp;
695 vlib_main_t *vm = vlib_get_main ();
698 u8 *tmp = format (0, "%s", mp->name);
700 ip_address_decode2 (&mp->responder.addr, &ip);
701 u32 sw_if_index = clib_net_to_host_u32 (mp->responder.sw_if_index);
703 error = ikev2_set_profile_responder (vm, tmp, sw_if_index, ip);
707 ikev2_log_error ("%U", format_clib_error, error);
708 clib_error_free (error);
709 rv = VNET_API_ERROR_UNSPECIFIED;
712 rv = VNET_API_ERROR_UNIMPLEMENTED;
715 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
719 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
722 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
726 vlib_main_t *vm = vlib_get_main ();
729 u8 *tmp = format (0, "%s", mp->name);
732 ikev2_set_profile_ike_transforms (vm, tmp, mp->tr.crypto_alg,
735 ntohl (mp->tr.crypto_key_size));
739 ikev2_log_error ("%U", format_clib_error, error);
740 clib_error_free (error);
741 rv = VNET_API_ERROR_UNSPECIFIED;
744 rv = VNET_API_ERROR_UNIMPLEMENTED;
747 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
751 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
754 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
758 vlib_main_t *vm = vlib_get_main ();
761 u8 *tmp = format (0, "%s", mp->name);
764 ikev2_set_profile_esp_transforms (vm, tmp, mp->tr.crypto_alg,
766 ntohl (mp->tr.crypto_key_size));
770 ikev2_log_error ("%U", format_clib_error, error);
771 clib_error_free (error);
772 rv = VNET_API_ERROR_UNSPECIFIED;
775 rv = VNET_API_ERROR_UNIMPLEMENTED;
778 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
782 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
784 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
788 vlib_main_t *vm = vlib_get_main ();
791 u8 *tmp = format (0, "%s", mp->name);
794 ikev2_set_profile_sa_lifetime (vm, tmp,
795 clib_net_to_host_u64 (mp->lifetime),
796 ntohl (mp->lifetime_jitter),
797 ntohl (mp->handover),
799 (mp->lifetime_maxdata));
803 ikev2_log_error ("%U", format_clib_error, error);
804 clib_error_free (error);
805 rv = VNET_API_ERROR_UNSPECIFIED;
808 rv = VNET_API_ERROR_UNIMPLEMENTED;
811 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
815 vl_api_ikev2_profile_set_ipsec_udp_port_t_handler
816 (vl_api_ikev2_profile_set_ipsec_udp_port_t * mp)
818 vl_api_ikev2_profile_set_ipsec_udp_port_reply_t *rmp;
822 vlib_main_t *vm = vlib_get_main ();
824 u8 *tmp = format (0, "%s", mp->name);
827 ikev2_set_profile_ipsec_udp_port (vm, tmp,
828 clib_net_to_host_u16 (mp->port),
832 rv = VNET_API_ERROR_UNIMPLEMENTED;
835 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_IPSEC_UDP_PORT_REPLY);
839 vl_api_ikev2_set_tunnel_interface_t_handler
840 (vl_api_ikev2_set_tunnel_interface_t * mp)
842 vl_api_ikev2_set_tunnel_interface_reply_t *rmp;
845 VALIDATE_SW_IF_INDEX (mp);
848 u8 *tmp = format (0, "%s", mp->name);
851 error = ikev2_set_profile_tunnel_interface (vlib_get_main (), tmp,
852 ntohl (mp->sw_if_index));
856 ikev2_log_error ("%U", format_clib_error, error);
857 clib_error_free (error);
858 rv = VNET_API_ERROR_UNSPECIFIED;
862 rv = VNET_API_ERROR_UNIMPLEMENTED;
865 BAD_SW_IF_INDEX_LABEL;
866 REPLY_MACRO (VL_API_IKEV2_SET_TUNNEL_INTERFACE_REPLY);
870 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
872 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
876 vlib_main_t *vm = vlib_get_main ();
879 u8 *tmp = format (0, "%s", mp->name);
881 error = ikev2_initiate_sa_init (vm, tmp);
885 ikev2_log_error ("%U", format_clib_error, error);
886 clib_error_free (error);
887 rv = VNET_API_ERROR_UNSPECIFIED;
890 rv = VNET_API_ERROR_UNIMPLEMENTED;
893 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
897 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
900 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
904 vlib_main_t *vm = vlib_get_main ();
907 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
910 ikev2_log_error ("%U", format_clib_error, error);
911 clib_error_free (error);
912 rv = VNET_API_ERROR_UNSPECIFIED;
915 rv = VNET_API_ERROR_UNIMPLEMENTED;
918 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
922 vl_api_ikev2_initiate_del_child_sa_t_handler
923 (vl_api_ikev2_initiate_del_child_sa_t * mp)
925 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
929 vlib_main_t *vm = vlib_get_main ();
932 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
935 ikev2_log_error ("%U", format_clib_error, error);
936 clib_error_free (error);
937 rv = VNET_API_ERROR_UNSPECIFIED;
940 rv = VNET_API_ERROR_UNIMPLEMENTED;
943 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
947 vl_api_ikev2_profile_disable_natt_t_handler
948 (vl_api_ikev2_profile_disable_natt_t * mp)
950 vl_api_ikev2_profile_disable_natt_reply_t *rmp;
956 u8 *tmp = format (0, "%s", mp->name);
957 error = ikev2_profile_natt_disable (tmp);
961 ikev2_log_error ("%U", format_clib_error, error);
962 clib_error_free (error);
963 rv = VNET_API_ERROR_UNSPECIFIED;
966 rv = VNET_API_ERROR_UNIMPLEMENTED;
969 REPLY_MACRO (VL_API_IKEV2_PROFILE_DISABLE_NATT_REPLY);
973 vl_api_ikev2_initiate_rekey_child_sa_t_handler
974 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
976 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
980 vlib_main_t *vm = vlib_get_main ();
983 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
986 ikev2_log_error ("%U", format_clib_error, error);
987 clib_error_free (error);
988 rv = VNET_API_ERROR_UNSPECIFIED;
991 rv = VNET_API_ERROR_UNIMPLEMENTED;
994 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
997 #include <ikev2/ikev2.api.c>
998 static clib_error_t *
999 ikev2_api_init (vlib_main_t * vm)
1001 ikev2_main_t *im = &ikev2_main;
1003 /* Ask for a correctly-sized block of API message decode slots */
1004 im->msg_id_base = setup_message_id_table ();
1009 VLIB_INIT_FUNCTION (ikev2_api_init);
1012 * fd.io coding-style-patch-verification: ON
1015 * eval: (c-set-style "gnu")