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_SPDS_DUMP, ipsec_spds_dump) \
58 _(IPSEC_SPD_DUMP, ipsec_spd_dump) \
59 _(IPSEC_SPD_INTERFACE_DUMP, ipsec_spd_interface_dump) \
60 _(IPSEC_TUNNEL_IF_ADD_DEL, ipsec_tunnel_if_add_del) \
61 _(IPSEC_TUNNEL_IF_SET_KEY, ipsec_tunnel_if_set_key) \
62 _(IPSEC_TUNNEL_IF_SET_SA, ipsec_tunnel_if_set_sa) \
63 _(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
64 _(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
65 _(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
66 _(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
67 _(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
68 _(IKEV2_SET_RESPONDER, ikev2_set_responder) \
69 _(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \
70 _(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \
71 _(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \
72 _(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \
73 _(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \
74 _(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \
75 _(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa) \
76 _(IPSEC_SELECT_BACKEND, ipsec_select_backend) \
77 _(IPSEC_BACKEND_DUMP, ipsec_backend_dump)
80 vl_api_ipsec_spd_add_del_t_handler (vl_api_ipsec_spd_add_del_t * mp)
83 clib_warning ("unimplemented");
86 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
87 vl_api_ipsec_spd_add_del_reply_t *rmp;
90 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
92 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
96 static void vl_api_ipsec_interface_add_del_spd_t_handler
97 (vl_api_ipsec_interface_add_del_spd_t * mp)
99 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
100 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
102 u32 sw_if_index __attribute__ ((unused));
103 u32 spd_id __attribute__ ((unused));
105 sw_if_index = ntohl (mp->sw_if_index);
106 spd_id = ntohl (mp->spd_id);
108 VALIDATE_SW_IF_INDEX (mp);
111 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
113 rv = VNET_API_ERROR_UNIMPLEMENTED;
116 BAD_SW_IF_INDEX_LABEL;
118 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
121 static void vl_api_ipsec_spd_add_del_entry_t_handler
122 (vl_api_ipsec_spd_add_del_entry_t * mp)
124 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
125 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
131 clib_memset (&p, 0, sizeof (p));
133 p.id = ntohl (mp->spd_id);
134 p.priority = ntohl (mp->priority);
135 p.is_outbound = mp->is_outbound;
136 p.is_ipv6 = mp->is_ipv6;
138 if (mp->is_ipv6 || mp->is_ip_any)
140 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
141 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
142 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
143 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
147 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
148 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
149 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
150 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
152 p.protocol = mp->protocol;
153 p.rport.start = ntohs (mp->remote_port_start);
154 p.rport.stop = ntohs (mp->remote_port_stop);
155 p.lport.start = ntohs (mp->local_port_start);
156 p.lport.stop = ntohs (mp->local_port_stop);
157 /* policy action resolve unsupported */
158 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
160 clib_warning ("unsupported action: 'resolve'");
161 rv = VNET_API_ERROR_UNIMPLEMENTED;
164 p.policy = mp->policy;
165 p.sa_id = ntohl (mp->sa_id);
167 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
174 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
177 rv = VNET_API_ERROR_UNIMPLEMENTED;
182 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
185 static void vl_api_ipsec_sad_add_del_entry_t_handler
186 (vl_api_ipsec_sad_add_del_entry_t * mp)
188 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
189 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
192 ipsec_main_t *im = &ipsec_main;
195 clib_memset (&sa, 0, sizeof (sa));
197 sa.id = ntohl (mp->sad_id);
198 sa.spi = ntohl (mp->spi);
199 sa.protocol = mp->protocol;
200 /* check for unsupported crypto-alg */
201 if (mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
203 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
204 mp->crypto_algorithm);
205 rv = VNET_API_ERROR_UNIMPLEMENTED;
208 sa.crypto_alg = mp->crypto_algorithm;
209 sa.crypto_key_len = mp->crypto_key_length;
210 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
211 /* check for unsupported integ-alg */
212 if (mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
214 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
215 mp->integrity_algorithm);
216 rv = VNET_API_ERROR_UNIMPLEMENTED;
220 sa.integ_alg = mp->integrity_algorithm;
221 sa.integ_key_len = mp->integrity_key_length;
222 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
223 sa.use_esn = mp->use_extended_sequence_number;
224 sa.is_tunnel = mp->is_tunnel;
225 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
226 sa.udp_encap = mp->udp_encap;
227 if (sa.is_tunnel_ip6)
229 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
230 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
234 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
235 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
237 sa.use_anti_replay = mp->use_anti_replay;
239 clib_error_t *err = ipsec_check_support_cb (im, &sa);
242 clib_warning ("%s", err->what);
243 rv = VNET_API_ERROR_UNIMPLEMENTED;
247 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
249 rv = VNET_API_ERROR_UNIMPLEMENTED;
254 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
258 send_ipsec_spds_details (ipsec_spd_t * spd, vl_api_registration_t * reg,
261 vl_api_ipsec_spds_details_t *mp;
263 mp = vl_msg_api_alloc (sizeof (*mp));
264 clib_memset (mp, 0, sizeof (*mp));
265 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS);
266 mp->context = context;
268 mp->spd_id = htonl (spd->id);
269 mp->npolicies = htonl (pool_len (spd->policies));
271 vl_api_send_msg (reg, (u8 *) mp);
275 vl_api_ipsec_spds_dump_t_handler (vl_api_ipsec_spds_dump_t * mp)
277 vl_api_registration_t *reg;
278 ipsec_main_t *im = &ipsec_main;
281 reg = vl_api_client_index_to_registration (mp->client_index);
286 pool_foreach (spd, im->spds, ({
287 send_ipsec_spds_details (spd, reg, mp->context);
291 clib_warning ("unimplemented");
296 send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg,
299 vl_api_ipsec_spd_details_t *mp;
301 mp = vl_msg_api_alloc (sizeof (*mp));
302 clib_memset (mp, 0, sizeof (*mp));
303 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
304 mp->context = context;
306 mp->spd_id = htonl (p->id);
307 mp->priority = htonl (p->priority);
308 mp->is_outbound = p->is_outbound;
309 mp->is_ipv6 = p->is_ipv6;
312 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
313 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
314 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
315 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
319 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
320 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
321 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
322 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
324 mp->local_start_port = htons (p->lport.start);
325 mp->local_stop_port = htons (p->lport.stop);
326 mp->remote_start_port = htons (p->rport.start);
327 mp->remote_stop_port = htons (p->rport.stop);
328 mp->protocol = p->protocol;
329 mp->policy = p->policy;
330 mp->sa_id = htonl (p->sa_id);
331 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
332 mp->packets = clib_host_to_net_u64 (p->counter.packets);
334 vl_api_send_msg (reg, (u8 *) mp);
338 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
340 vl_api_registration_t *reg;
341 ipsec_main_t *im = &ipsec_main;
342 ipsec_policy_t *policy;
347 reg = vl_api_client_index_to_registration (mp->client_index);
351 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
356 spd = pool_elt_at_index (im->spds, spd_index);
359 pool_foreach (policy, spd->policies,
361 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
362 send_ipsec_spd_details (policy, reg,
367 clib_warning ("unimplemented");
372 send_ipsec_spd_interface_details (vl_api_registration_t * reg, u32 spd_index,
373 u32 sw_if_index, u32 context)
375 vl_api_ipsec_spd_interface_details_t *mp;
377 mp = vl_msg_api_alloc (sizeof (*mp));
378 clib_memset (mp, 0, sizeof (*mp));
379 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS);
380 mp->context = context;
382 mp->spd_index = htonl (spd_index);
383 mp->sw_if_index = htonl (sw_if_index);
385 vl_api_send_msg (reg, (u8 *) mp);
389 vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t *
392 ipsec_main_t *im = &ipsec_main;
393 vl_api_registration_t *reg;
397 reg = vl_api_client_index_to_registration (mp->client_index);
401 if (mp->spd_index_valid)
403 spd_index = ntohl (mp->spd_index);
405 hash_foreach(k, v, im->spd_index_by_sw_if_index, ({
407 send_ipsec_spd_interface_details(reg, v, k, mp->context);
414 hash_foreach(k, v, im->spd_index_by_sw_if_index, ({
415 send_ipsec_spd_interface_details(reg, v, k, mp->context);
421 clib_warning ("unimplemented");
426 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
428 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
429 vl_api_ipsec_sa_set_key_reply_t *rmp;
433 sa.id = ntohl (mp->sa_id);
434 sa.crypto_key_len = mp->crypto_key_length;
435 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
436 sa.integ_key_len = mp->integrity_key_length;
437 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
439 rv = ipsec_set_sa_key (vm, &sa);
441 rv = VNET_API_ERROR_UNIMPLEMENTED;
444 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
448 vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t *
451 vl_api_ipsec_tunnel_if_add_del_reply_t *rmp;
452 ipsec_main_t *im = &ipsec_main;
453 vnet_main_t *vnm = im->vnet_main;
454 u32 sw_if_index = ~0;
458 ipsec_add_del_tunnel_args_t tun;
460 clib_memset (&tun, 0, sizeof (ipsec_add_del_tunnel_args_t));
462 tun.is_add = mp->is_add;
464 tun.anti_replay = mp->anti_replay;
465 tun.local_spi = ntohl (mp->local_spi);
466 tun.remote_spi = ntohl (mp->remote_spi);
467 tun.crypto_alg = mp->crypto_alg;
468 tun.local_crypto_key_len = mp->local_crypto_key_len;
469 tun.remote_crypto_key_len = mp->remote_crypto_key_len;
470 tun.integ_alg = mp->integ_alg;
471 tun.local_integ_key_len = mp->local_integ_key_len;
472 tun.remote_integ_key_len = mp->remote_integ_key_len;
473 memcpy (&tun.local_ip, mp->local_ip, 4);
474 memcpy (&tun.remote_ip, mp->remote_ip, 4);
475 memcpy (&tun.local_crypto_key, &mp->local_crypto_key,
476 mp->local_crypto_key_len);
477 memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key,
478 mp->remote_crypto_key_len);
479 memcpy (&tun.local_integ_key, &mp->local_integ_key,
480 mp->local_integ_key_len);
481 memcpy (&tun.remote_integ_key, &mp->remote_integ_key,
482 mp->remote_integ_key_len);
483 tun.renumber = mp->renumber;
484 tun.show_instance = ntohl (mp->show_instance);
486 rv = ipsec_add_del_tunnel_if_internal (vnm, &tun, &sw_if_index);
489 rv = VNET_API_ERROR_UNIMPLEMENTED;
492 REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, (
500 send_ipsec_sa_details (ipsec_sa_t * sa, vl_api_registration_t * reg,
501 u32 context, u32 sw_if_index)
503 vl_api_ipsec_sa_details_t *mp;
505 mp = vl_msg_api_alloc (sizeof (*mp));
506 clib_memset (mp, 0, sizeof (*mp));
507 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
508 mp->context = context;
510 mp->sa_id = htonl (sa->id);
511 mp->sw_if_index = htonl (sw_if_index);
513 mp->spi = htonl (sa->spi);
514 mp->protocol = sa->protocol;
516 mp->crypto_alg = sa->crypto_alg;
517 mp->crypto_key_len = sa->crypto_key_len;
518 memcpy (mp->crypto_key, sa->crypto_key, sa->crypto_key_len);
520 mp->integ_alg = sa->integ_alg;
521 mp->integ_key_len = sa->integ_key_len;
522 memcpy (mp->integ_key, sa->integ_key, sa->integ_key_len);
524 mp->use_esn = sa->use_esn;
525 mp->use_anti_replay = sa->use_anti_replay;
527 mp->is_tunnel = sa->is_tunnel;
528 mp->is_tunnel_ip6 = sa->is_tunnel_ip6;
532 if (sa->is_tunnel_ip6)
534 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip6, 16);
535 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip6, 16);
539 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip4, 4);
540 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip4, 4);
544 mp->salt = clib_host_to_net_u32 (sa->salt);
545 mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
546 mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
549 mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
550 mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
552 if (sa->use_anti_replay)
553 mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
554 mp->total_data_size = clib_host_to_net_u64 (sa->total_data_size);
555 mp->udp_encap = sa->udp_encap;
557 vl_api_send_msg (reg, (u8 *) mp);
562 vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
564 vl_api_registration_t *reg;
565 ipsec_main_t *im = &ipsec_main;
566 vnet_main_t *vnm = im->vnet_main;
568 ipsec_tunnel_if_t *t;
569 u32 *sa_index_to_tun_if_index = 0;
572 reg = vl_api_client_index_to_registration (mp->client_index);
573 if (!reg || pool_elts (im->sad) == 0)
576 vec_validate_init_empty (sa_index_to_tun_if_index, vec_len (im->sad) - 1,
580 pool_foreach (t, im->tunnel_interfaces,
582 vnet_hw_interface_t *hi;
583 u32 sw_if_index = ~0;
585 hi = vnet_get_hw_interface (vnm, t->hw_if_index);
586 sw_if_index = hi->sw_if_index;
587 sa_index_to_tun_if_index[t->input_sa_index] = sw_if_index;
588 sa_index_to_tun_if_index[t->output_sa_index] = sw_if_index;
591 pool_foreach (sa, im->sad,
593 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == sa->id)
594 send_ipsec_sa_details (sa, reg, mp->context,
595 sa_index_to_tun_if_index[sa - im->sad]);
599 vec_free (sa_index_to_tun_if_index);
601 clib_warning ("unimplemented");
607 vl_api_ipsec_tunnel_if_set_key_t_handler (vl_api_ipsec_tunnel_if_set_key_t *
610 vl_api_ipsec_tunnel_if_set_key_reply_t *rmp;
611 ipsec_main_t *im = &ipsec_main;
612 vnet_main_t *vnm = im->vnet_main;
613 vnet_sw_interface_t *sw;
618 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
620 switch (mp->key_type)
622 case IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO:
623 case IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO:
624 if (mp->alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
625 mp->alg >= IPSEC_CRYPTO_N_ALG)
627 rv = VNET_API_ERROR_UNIMPLEMENTED;
631 case IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG:
632 case IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG:
633 if (mp->alg >= IPSEC_INTEG_N_ALG)
635 rv = VNET_API_ERROR_UNIMPLEMENTED;
639 case IPSEC_IF_SET_KEY_TYPE_NONE:
641 rv = VNET_API_ERROR_UNIMPLEMENTED;
646 key = vec_new (u8, mp->key_len);
647 clib_memcpy (key, mp->key, mp->key_len);
649 rv = ipsec_set_interface_key (vnm, sw->hw_if_index, mp->key_type, mp->alg,
653 clib_warning ("unimplemented");
657 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_KEY_REPLY);
662 vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp)
664 vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp;
665 ipsec_main_t *im = &ipsec_main;
666 vnet_main_t *vnm = im->vnet_main;
667 vnet_sw_interface_t *sw;
671 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
673 rv = ipsec_set_interface_sa (vnm, sw->hw_if_index, ntohl (mp->sa_id),
676 clib_warning ("unimplemented");
679 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY);
684 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
686 vl_api_ikev2_profile_add_del_reply_t *rmp;
690 vlib_main_t *vm = vlib_get_main ();
692 u8 *tmp = format (0, "%s", mp->name);
693 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
696 rv = VNET_API_ERROR_UNSPECIFIED;
698 rv = VNET_API_ERROR_UNIMPLEMENTED;
701 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
705 vl_api_ikev2_profile_set_auth_t_handler
706 (vl_api_ikev2_profile_set_auth_t * mp)
708 vl_api_ikev2_profile_set_auth_reply_t *rmp;
712 vlib_main_t *vm = vlib_get_main ();
714 u8 *tmp = format (0, "%s", mp->name);
715 u8 *data = vec_new (u8, mp->data_len);
716 clib_memcpy (data, mp->data, mp->data_len);
717 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
721 rv = VNET_API_ERROR_UNSPECIFIED;
723 rv = VNET_API_ERROR_UNIMPLEMENTED;
726 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
730 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
732 vl_api_ikev2_profile_add_del_reply_t *rmp;
736 vlib_main_t *vm = vlib_get_main ();
738 u8 *tmp = format (0, "%s", mp->name);
739 u8 *data = vec_new (u8, mp->data_len);
740 clib_memcpy (data, mp->data, mp->data_len);
741 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
745 rv = VNET_API_ERROR_UNSPECIFIED;
747 rv = VNET_API_ERROR_UNIMPLEMENTED;
750 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
754 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
756 vl_api_ikev2_profile_set_ts_reply_t *rmp;
760 vlib_main_t *vm = vlib_get_main ();
762 u8 *tmp = format (0, "%s", mp->name);
763 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
764 mp->end_port, (ip4_address_t) mp->start_addr,
765 (ip4_address_t) mp->end_addr, mp->is_local);
768 rv = VNET_API_ERROR_UNSPECIFIED;
770 rv = VNET_API_ERROR_UNIMPLEMENTED;
773 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
777 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
779 vl_api_ikev2_profile_set_ts_reply_t *rmp;
783 vlib_main_t *vm = vlib_get_main ();
786 error = ikev2_set_local_key (vm, mp->key_file);
788 rv = VNET_API_ERROR_UNSPECIFIED;
790 rv = VNET_API_ERROR_UNIMPLEMENTED;
793 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
797 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
799 vl_api_ikev2_set_responder_reply_t *rmp;
803 vlib_main_t *vm = vlib_get_main ();
806 u8 *tmp = format (0, "%s", mp->name);
808 clib_memcpy (&ip4, mp->address, sizeof (ip4));
810 error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
813 rv = VNET_API_ERROR_UNSPECIFIED;
815 rv = VNET_API_ERROR_UNIMPLEMENTED;
818 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
822 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
825 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
829 vlib_main_t *vm = vlib_get_main ();
832 u8 *tmp = format (0, "%s", mp->name);
835 ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
836 mp->dh_group, mp->crypto_key_size);
839 rv = VNET_API_ERROR_UNSPECIFIED;
841 rv = VNET_API_ERROR_UNIMPLEMENTED;
844 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
848 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
851 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
855 vlib_main_t *vm = vlib_get_main ();
858 u8 *tmp = format (0, "%s", mp->name);
861 ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
862 mp->dh_group, mp->crypto_key_size);
865 rv = VNET_API_ERROR_UNSPECIFIED;
867 rv = VNET_API_ERROR_UNIMPLEMENTED;
870 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
874 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
876 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
880 vlib_main_t *vm = vlib_get_main ();
883 u8 *tmp = format (0, "%s", mp->name);
886 ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
887 mp->handover, mp->lifetime_maxdata);
890 rv = VNET_API_ERROR_UNSPECIFIED;
892 rv = VNET_API_ERROR_UNIMPLEMENTED;
895 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
899 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
901 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
905 vlib_main_t *vm = vlib_get_main ();
908 u8 *tmp = format (0, "%s", mp->name);
910 error = ikev2_initiate_sa_init (vm, tmp);
913 rv = VNET_API_ERROR_UNSPECIFIED;
915 rv = VNET_API_ERROR_UNIMPLEMENTED;
918 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
922 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
925 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
929 vlib_main_t *vm = vlib_get_main ();
932 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
934 rv = VNET_API_ERROR_UNSPECIFIED;
936 rv = VNET_API_ERROR_UNIMPLEMENTED;
939 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
943 vl_api_ikev2_initiate_del_child_sa_t_handler
944 (vl_api_ikev2_initiate_del_child_sa_t * mp)
946 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
950 vlib_main_t *vm = vlib_get_main ();
953 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
955 rv = VNET_API_ERROR_UNSPECIFIED;
957 rv = VNET_API_ERROR_UNIMPLEMENTED;
960 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
964 vl_api_ikev2_initiate_rekey_child_sa_t_handler
965 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
967 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
971 vlib_main_t *vm = vlib_get_main ();
974 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
976 rv = VNET_API_ERROR_UNSPECIFIED;
978 rv = VNET_API_ERROR_UNIMPLEMENTED;
981 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
986 * Add vpe's API message handlers to the table.
987 * vlib has already mapped shared memory and
988 * added the client registration handlers.
989 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
991 #define vl_msg_name_crc_list
992 #include <vnet/vnet_all_api_h.h>
993 #undef vl_msg_name_crc_list
996 setup_message_id_table (api_main_t * am)
998 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
999 foreach_vl_msg_name_crc_ipsec;
1004 vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp)
1006 vl_api_registration_t *rp;
1007 ipsec_main_t *im = &ipsec_main;
1008 u32 context = mp->context;
1010 rp = vl_api_client_index_to_registration (mp->client_index);
1014 clib_warning ("Client %d AWOL", mp->client_index);
1018 ipsec_ah_backend_t *ab;
1019 ipsec_esp_backend_t *eb;
1021 pool_foreach (ab, im->ah_backends, {
1022 vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1023 clib_memset (mp, 0, sizeof (*mp));
1024 mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1025 mp->context = context;
1026 snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name),
1028 mp->protocol = IPSEC_PROTOCOL_AH;
1029 mp->index = ab - im->ah_backends;
1030 mp->active = mp->index == im->ah_current_backend ? 1 : 0;
1031 vl_api_send_msg (rp, (u8 *)mp);
1033 pool_foreach (eb, im->esp_backends, {
1034 vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1035 clib_memset (mp, 0, sizeof (*mp));
1036 mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1037 mp->context = context;
1038 snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name),
1040 mp->protocol = IPSEC_PROTOCOL_ESP;
1041 mp->index = eb - im->esp_backends;
1042 mp->active = mp->index == im->esp_current_backend ? 1 : 0;
1043 vl_api_send_msg (rp, (u8 *)mp);
1049 vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp)
1051 ipsec_main_t *im = &ipsec_main;
1052 vl_api_ipsec_select_backend_reply_t *rmp;
1054 if (pool_elts (im->sad) > 0)
1056 rv = VNET_API_ERROR_INSTANCE_IN_USE;
1060 switch (mp->protocol)
1062 case IPSEC_PROTOCOL_ESP:
1063 if (pool_is_free_index (im->esp_backends, mp->index))
1065 rv = VNET_API_ERROR_INVALID_VALUE;
1068 ipsec_select_esp_backend (im, mp->index);
1070 case IPSEC_PROTOCOL_AH:
1071 if (pool_is_free_index (im->ah_backends, mp->index))
1073 rv = VNET_API_ERROR_INVALID_VALUE;
1076 ipsec_select_ah_backend (im, mp->index);
1079 rv = VNET_API_ERROR_INVALID_VALUE;
1083 clib_warning ("unimplemented"); /* FIXME */
1086 REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY);
1089 static clib_error_t *
1090 ipsec_api_hookup (vlib_main_t * vm)
1092 api_main_t *am = &api_main;
1095 vl_msg_api_set_handlers(VL_API_##N, #n, \
1096 vl_api_##n##_t_handler, \
1098 vl_api_##n##_t_endian, \
1099 vl_api_##n##_t_print, \
1100 sizeof(vl_api_##n##_t), 1);
1101 foreach_vpe_api_msg;
1105 * Set up the (msg_name, crc, message-id) table
1107 setup_message_id_table (am);
1112 VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
1115 * fd.io coding-style-patch-verification: ON
1118 * eval: (c-set-style "gnu")