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>
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
25 #include <vnet/ip/ip.h>
27 #include <vnet/vnet_msg_enum.h>
30 #include <vnet/ipsec/ipsec.h>
31 #include <vnet/ipsec/ikev2.h>
34 #define vl_typedefs /* define message structures */
35 #include <vnet/vnet_all_api_h.h>
38 #define vl_endianfun /* define message structures */
39 #include <vnet/vnet_all_api_h.h>
42 /* instantiate all the print functions we know about */
43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #include <vnet/vnet_all_api_h.h>
48 #include <vlibapi/api_helper_macros.h>
50 #define foreach_vpe_api_msg \
51 _(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del) \
52 _(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd) \
53 _(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry) \
54 _(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry) \
55 _(IPSEC_SA_SET_KEY, ipsec_sa_set_key) \
56 _(IPSEC_SA_DUMP, ipsec_sa_dump) \
57 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
58 _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \
59 _(IPSEC_TUNNEL_IF_SET_KEY, ipsec_tunnel_if_set_key) \
60 _(IPSEC_TUNNEL_IF_SET_SA, ipsec_tunnel_if_set_sa) \
61 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
62 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
63 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
64 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
65 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
66 _(IKEV2_SET_RESPONDER, ikev2_set_responder) \
67 _(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \
68 _(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \
69 _(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \
70 _(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \
71 _(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \
72 _(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \
73 _(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa)
75 static void vl_api_ipsec_spd_add_del_t_handler
76 (vl_api_ipsec_spd_add_del_t * mp)
79 clib_warning ("unimplemented");
82 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
83 vl_api_ipsec_spd_add_del_reply_t *rmp;
86 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
88 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
92 static void vl_api_ipsec_interface_add_del_spd_t_handler
93 (vl_api_ipsec_interface_add_del_spd_t * mp)
95 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
96 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
98 u32 sw_if_index __attribute__ ((unused));
99 u32 spd_id __attribute__ ((unused));
101 sw_if_index = ntohl (mp->sw_if_index);
102 spd_id = ntohl (mp->spd_id);
104 VALIDATE_SW_IF_INDEX (mp);
107 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
109 rv = VNET_API_ERROR_UNIMPLEMENTED;
112 BAD_SW_IF_INDEX_LABEL;
114 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
117 static void vl_api_ipsec_spd_add_del_entry_t_handler
118 (vl_api_ipsec_spd_add_del_entry_t * mp)
120 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
121 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
127 memset (&p, 0, sizeof (p));
129 p.id = ntohl (mp->spd_id);
130 p.priority = ntohl (mp->priority);
131 p.is_outbound = mp->is_outbound;
132 p.is_ipv6 = mp->is_ipv6;
134 if (mp->is_ipv6 || mp->is_ip_any)
136 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
137 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
138 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
139 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
143 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
144 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
145 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
146 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
148 p.protocol = mp->protocol;
149 p.rport.start = ntohs (mp->remote_port_start);
150 p.rport.stop = ntohs (mp->remote_port_stop);
151 p.lport.start = ntohs (mp->local_port_start);
152 p.lport.stop = ntohs (mp->local_port_stop);
153 /* policy action resolve unsupported */
154 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
156 clib_warning ("unsupported action: 'resolve'");
157 rv = VNET_API_ERROR_UNIMPLEMENTED;
160 p.policy = mp->policy;
161 p.sa_id = ntohl (mp->sa_id);
163 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
170 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
173 rv = VNET_API_ERROR_UNIMPLEMENTED;
178 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
181 static void vl_api_ipsec_sad_add_del_entry_t_handler
182 (vl_api_ipsec_sad_add_del_entry_t * mp)
184 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
185 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
188 ipsec_main_t *im = &ipsec_main;
191 memset (&sa, 0, sizeof (sa));
193 sa.id = ntohl (mp->sad_id);
194 sa.spi = ntohl (mp->spi);
195 sa.protocol = mp->protocol;
196 /* check for unsupported crypto-alg */
197 if (mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
199 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
200 mp->crypto_algorithm);
201 rv = VNET_API_ERROR_UNIMPLEMENTED;
204 sa.crypto_alg = mp->crypto_algorithm;
205 sa.crypto_key_len = mp->crypto_key_length;
206 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
207 /* check for unsupported integ-alg */
208 if (mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
210 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
211 mp->integrity_algorithm);
212 rv = VNET_API_ERROR_UNIMPLEMENTED;
216 sa.integ_alg = mp->integrity_algorithm;
217 sa.integ_key_len = mp->integrity_key_length;
218 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
219 sa.use_esn = mp->use_extended_sequence_number;
220 sa.is_tunnel = mp->is_tunnel;
221 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
222 sa.udp_encap = mp->udp_encap;
223 if (sa.is_tunnel_ip6)
225 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
226 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
230 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
231 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
233 sa.use_anti_replay = mp->use_anti_replay;
235 ASSERT (im->cb.check_support_cb);
236 clib_error_t *err = im->cb.check_support_cb (&sa);
239 clib_warning ("%s", err->what);
240 rv = VNET_API_ERROR_UNIMPLEMENTED;
244 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
246 rv = VNET_API_ERROR_UNIMPLEMENTED;
251 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
255 send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg,
258 vl_api_ipsec_spd_details_t *mp;
260 mp = vl_msg_api_alloc (sizeof (*mp));
261 memset (mp, 0, sizeof (*mp));
262 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
263 mp->context = context;
265 mp->spd_id = htonl (p->id);
266 mp->priority = htonl (p->priority);
267 mp->is_outbound = p->is_outbound;
268 mp->is_ipv6 = p->is_ipv6;
271 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
272 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
273 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
274 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
278 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
279 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
280 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
281 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
283 mp->local_start_port = htons (p->lport.start);
284 mp->local_stop_port = htons (p->lport.stop);
285 mp->remote_start_port = htons (p->rport.start);
286 mp->remote_stop_port = htons (p->rport.stop);
287 mp->protocol = p->protocol;
288 mp->policy = p->policy;
289 mp->sa_id = htonl (p->sa_id);
290 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
291 mp->packets = clib_host_to_net_u64 (p->counter.packets);
293 vl_api_send_msg (reg, (u8 *) mp);
297 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
299 vl_api_registration_t *reg;
300 ipsec_main_t *im = &ipsec_main;
301 ipsec_policy_t *policy;
306 reg = vl_api_client_index_to_registration (mp->client_index);
310 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
315 spd = pool_elt_at_index (im->spds, spd_index);
318 pool_foreach (policy, spd->policies,
320 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
321 send_ipsec_spd_details (policy, reg,
326 clib_warning ("unimplemented");
331 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
333 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
334 vl_api_ipsec_sa_set_key_reply_t *rmp;
338 sa.id = ntohl (mp->sa_id);
339 sa.crypto_key_len = mp->crypto_key_length;
340 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
341 sa.integ_key_len = mp->integrity_key_length;
342 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
344 rv = ipsec_set_sa_key (vm, &sa);
346 rv = VNET_API_ERROR_UNIMPLEMENTED;
349 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
353 vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t *
356 vl_api_ipsec_tunnel_if_add_del_reply_t *rmp;
357 ipsec_main_t *im = &ipsec_main;
358 vnet_main_t *vnm = im->vnet_main;
359 u32 sw_if_index = ~0;
363 ipsec_add_del_tunnel_args_t tun;
365 memset (&tun, 0, sizeof (ipsec_add_del_tunnel_args_t));
367 tun.is_add = mp->is_add;
369 tun.anti_replay = mp->anti_replay;
370 tun.local_spi = ntohl (mp->local_spi);
371 tun.remote_spi = ntohl (mp->remote_spi);
372 tun.crypto_alg = mp->crypto_alg;
373 tun.local_crypto_key_len = mp->local_crypto_key_len;
374 tun.remote_crypto_key_len = mp->remote_crypto_key_len;
375 tun.integ_alg = mp->integ_alg;
376 tun.local_integ_key_len = mp->local_integ_key_len;
377 tun.remote_integ_key_len = mp->remote_integ_key_len;
378 memcpy (&tun.local_ip, mp->local_ip, 4);
379 memcpy (&tun.remote_ip, mp->remote_ip, 4);
380 memcpy (&tun.local_crypto_key, &mp->local_crypto_key,
381 mp->local_crypto_key_len);
382 memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key,
383 mp->remote_crypto_key_len);
384 memcpy (&tun.local_integ_key, &mp->local_integ_key,
385 mp->local_integ_key_len);
386 memcpy (&tun.remote_integ_key, &mp->remote_integ_key,
387 mp->remote_integ_key_len);
388 tun.renumber = mp->renumber;
389 tun.show_instance = ntohl (mp->show_instance);
391 rv = ipsec_add_del_tunnel_if_internal (vnm, &tun, &sw_if_index);
394 rv = VNET_API_ERROR_UNIMPLEMENTED;
397 REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, (
405 send_ipsec_sa_details (ipsec_sa_t * sa, vl_api_registration_t * reg,
406 u32 context, u32 sw_if_index)
408 vl_api_ipsec_sa_details_t *mp;
410 mp = vl_msg_api_alloc (sizeof (*mp));
411 memset (mp, 0, sizeof (*mp));
412 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
413 mp->context = context;
415 mp->sa_id = htonl (sa->id);
416 mp->sw_if_index = htonl (sw_if_index);
418 mp->spi = htonl (sa->spi);
419 mp->protocol = sa->protocol;
421 mp->crypto_alg = sa->crypto_alg;
422 mp->crypto_key_len = sa->crypto_key_len;
423 memcpy (mp->crypto_key, sa->crypto_key, sa->crypto_key_len);
425 mp->integ_alg = sa->integ_alg;
426 mp->integ_key_len = sa->integ_key_len;
427 memcpy (mp->integ_key, sa->integ_key, sa->integ_key_len);
429 mp->use_esn = sa->use_esn;
430 mp->use_anti_replay = sa->use_anti_replay;
432 mp->is_tunnel = sa->is_tunnel;
433 mp->is_tunnel_ip6 = sa->is_tunnel_ip6;
437 if (sa->is_tunnel_ip6)
439 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip6, 16);
440 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip6, 16);
444 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip4, 4);
445 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip4, 4);
449 mp->salt = clib_host_to_net_u32 (sa->salt);
450 mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
451 mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
454 mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
455 mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
457 if (sa->use_anti_replay)
458 mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
459 mp->total_data_size = clib_host_to_net_u64 (sa->total_data_size);
460 mp->udp_encap = sa->udp_encap;
462 vl_api_send_msg (reg, (u8 *) mp);
467 vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
469 vl_api_registration_t *reg;
470 ipsec_main_t *im = &ipsec_main;
471 vnet_main_t *vnm = im->vnet_main;
473 ipsec_tunnel_if_t *t;
474 u32 *sa_index_to_tun_if_index = 0;
477 reg = vl_api_client_index_to_registration (mp->client_index);
478 if (!reg || pool_elts (im->sad) == 0)
481 vec_validate_init_empty (sa_index_to_tun_if_index, vec_len (im->sad) - 1,
485 pool_foreach (t, im->tunnel_interfaces,
487 vnet_hw_interface_t *hi;
488 u32 sw_if_index = ~0;
490 hi = vnet_get_hw_interface (vnm, t->hw_if_index);
491 sw_if_index = hi->sw_if_index;
492 sa_index_to_tun_if_index[t->input_sa_index] = sw_if_index;
493 sa_index_to_tun_if_index[t->output_sa_index] = sw_if_index;
496 pool_foreach (sa, im->sad,
498 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == sa->id)
499 send_ipsec_sa_details (sa, reg, mp->context,
500 sa_index_to_tun_if_index[sa - im->sad]);
504 vec_free (sa_index_to_tun_if_index);
506 clib_warning ("unimplemented");
512 vl_api_ipsec_tunnel_if_set_key_t_handler (vl_api_ipsec_tunnel_if_set_key_t *
515 vl_api_ipsec_tunnel_if_set_key_reply_t *rmp;
516 ipsec_main_t *im = &ipsec_main;
517 vnet_main_t *vnm = im->vnet_main;
518 vnet_sw_interface_t *sw;
523 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
525 switch (mp->key_type)
527 case IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO:
528 case IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO:
529 if (mp->alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
530 mp->alg >= IPSEC_CRYPTO_N_ALG)
532 rv = VNET_API_ERROR_UNIMPLEMENTED;
536 case IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG:
537 case IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG:
538 if (mp->alg >= IPSEC_INTEG_N_ALG)
540 rv = VNET_API_ERROR_UNIMPLEMENTED;
544 case IPSEC_IF_SET_KEY_TYPE_NONE:
546 rv = VNET_API_ERROR_UNIMPLEMENTED;
551 key = vec_new (u8, mp->key_len);
552 clib_memcpy (key, mp->key, mp->key_len);
554 rv = ipsec_set_interface_key (vnm, sw->hw_if_index, mp->key_type, mp->alg,
558 clib_warning ("unimplemented");
562 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_KEY_REPLY);
567 vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp)
569 vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp;
570 ipsec_main_t *im = &ipsec_main;
571 vnet_main_t *vnm = im->vnet_main;
572 vnet_sw_interface_t *sw;
576 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
578 rv = ipsec_set_interface_sa (vnm, sw->hw_if_index, ntohl (mp->sa_id),
581 clib_warning ("unimplemented");
584 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY);
589 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
591 vl_api_ikev2_profile_add_del_reply_t *rmp;
595 vlib_main_t *vm = vlib_get_main ();
597 u8 *tmp = format (0, "%s", mp->name);
598 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
601 rv = VNET_API_ERROR_UNSPECIFIED;
603 rv = VNET_API_ERROR_UNIMPLEMENTED;
606 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
610 vl_api_ikev2_profile_set_auth_t_handler
611 (vl_api_ikev2_profile_set_auth_t * mp)
613 vl_api_ikev2_profile_set_auth_reply_t *rmp;
617 vlib_main_t *vm = vlib_get_main ();
619 u8 *tmp = format (0, "%s", mp->name);
620 u8 *data = vec_new (u8, mp->data_len);
621 clib_memcpy (data, mp->data, mp->data_len);
622 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
626 rv = VNET_API_ERROR_UNSPECIFIED;
628 rv = VNET_API_ERROR_UNIMPLEMENTED;
631 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
635 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
637 vl_api_ikev2_profile_add_del_reply_t *rmp;
641 vlib_main_t *vm = vlib_get_main ();
643 u8 *tmp = format (0, "%s", mp->name);
644 u8 *data = vec_new (u8, mp->data_len);
645 clib_memcpy (data, mp->data, mp->data_len);
646 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
650 rv = VNET_API_ERROR_UNSPECIFIED;
652 rv = VNET_API_ERROR_UNIMPLEMENTED;
655 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
659 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
661 vl_api_ikev2_profile_set_ts_reply_t *rmp;
665 vlib_main_t *vm = vlib_get_main ();
667 u8 *tmp = format (0, "%s", mp->name);
668 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
669 mp->end_port, (ip4_address_t) mp->start_addr,
670 (ip4_address_t) mp->end_addr, mp->is_local);
673 rv = VNET_API_ERROR_UNSPECIFIED;
675 rv = VNET_API_ERROR_UNIMPLEMENTED;
678 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
682 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
684 vl_api_ikev2_profile_set_ts_reply_t *rmp;
688 vlib_main_t *vm = vlib_get_main ();
691 error = ikev2_set_local_key (vm, mp->key_file);
693 rv = VNET_API_ERROR_UNSPECIFIED;
695 rv = VNET_API_ERROR_UNIMPLEMENTED;
698 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
702 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
704 vl_api_ikev2_set_responder_reply_t *rmp;
708 vlib_main_t *vm = vlib_get_main ();
711 u8 *tmp = format (0, "%s", mp->name);
713 clib_memcpy (&ip4, mp->address, sizeof (ip4));
715 error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
718 rv = VNET_API_ERROR_UNSPECIFIED;
720 rv = VNET_API_ERROR_UNIMPLEMENTED;
723 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
727 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
730 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
734 vlib_main_t *vm = vlib_get_main ();
737 u8 *tmp = format (0, "%s", mp->name);
740 ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
741 mp->dh_group, mp->crypto_key_size);
744 rv = VNET_API_ERROR_UNSPECIFIED;
746 rv = VNET_API_ERROR_UNIMPLEMENTED;
749 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
753 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
756 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
760 vlib_main_t *vm = vlib_get_main ();
763 u8 *tmp = format (0, "%s", mp->name);
766 ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
767 mp->dh_group, mp->crypto_key_size);
770 rv = VNET_API_ERROR_UNSPECIFIED;
772 rv = VNET_API_ERROR_UNIMPLEMENTED;
775 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
779 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
781 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
785 vlib_main_t *vm = vlib_get_main ();
788 u8 *tmp = format (0, "%s", mp->name);
791 ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
792 mp->handover, mp->lifetime_maxdata);
795 rv = VNET_API_ERROR_UNSPECIFIED;
797 rv = VNET_API_ERROR_UNIMPLEMENTED;
800 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
804 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
806 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
810 vlib_main_t *vm = vlib_get_main ();
813 u8 *tmp = format (0, "%s", mp->name);
815 error = ikev2_initiate_sa_init (vm, tmp);
818 rv = VNET_API_ERROR_UNSPECIFIED;
820 rv = VNET_API_ERROR_UNIMPLEMENTED;
823 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
827 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
830 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
834 vlib_main_t *vm = vlib_get_main ();
837 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
839 rv = VNET_API_ERROR_UNSPECIFIED;
841 rv = VNET_API_ERROR_UNIMPLEMENTED;
844 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
848 vl_api_ikev2_initiate_del_child_sa_t_handler
849 (vl_api_ikev2_initiate_del_child_sa_t * mp)
851 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
855 vlib_main_t *vm = vlib_get_main ();
858 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
860 rv = VNET_API_ERROR_UNSPECIFIED;
862 rv = VNET_API_ERROR_UNIMPLEMENTED;
865 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
869 vl_api_ikev2_initiate_rekey_child_sa_t_handler
870 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
872 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
876 vlib_main_t *vm = vlib_get_main ();
879 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
881 rv = VNET_API_ERROR_UNSPECIFIED;
883 rv = VNET_API_ERROR_UNIMPLEMENTED;
886 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
891 * Add vpe's API message handlers to the table.
892 * vlib has alread mapped shared memory and
893 * added the client registration handlers.
894 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
896 #define vl_msg_name_crc_list
897 #include <vnet/vnet_all_api_h.h>
898 #undef vl_msg_name_crc_list
901 setup_message_id_table (api_main_t * am)
903 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
904 foreach_vl_msg_name_crc_ipsec;
908 static clib_error_t *
909 ipsec_api_hookup (vlib_main_t * vm)
911 api_main_t *am = &api_main;
914 vl_msg_api_set_handlers(VL_API_##N, #n, \
915 vl_api_##n##_t_handler, \
917 vl_api_##n##_t_endian, \
918 vl_api_##n##_t_print, \
919 sizeof(vl_api_##n##_t), 1);
924 * Set up the (msg_name, crc, message-id) table
926 setup_message_id_table (am);
931 VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
934 * fd.io coding-style-patch-verification: ON
937 * eval: (c-set-style "gnu")