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 tun.udp_encap = mp->udp_encap;
474 memcpy (&tun.local_ip, mp->local_ip, 4);
475 memcpy (&tun.remote_ip, mp->remote_ip, 4);
476 memcpy (&tun.local_crypto_key, &mp->local_crypto_key,
477 mp->local_crypto_key_len);
478 memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key,
479 mp->remote_crypto_key_len);
480 memcpy (&tun.local_integ_key, &mp->local_integ_key,
481 mp->local_integ_key_len);
482 memcpy (&tun.remote_integ_key, &mp->remote_integ_key,
483 mp->remote_integ_key_len);
484 tun.renumber = mp->renumber;
485 tun.show_instance = ntohl (mp->show_instance);
487 rv = ipsec_add_del_tunnel_if_internal (vnm, &tun, &sw_if_index);
490 rv = VNET_API_ERROR_UNIMPLEMENTED;
493 REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, (
501 send_ipsec_sa_details (ipsec_sa_t * sa, vl_api_registration_t * reg,
502 u32 context, u32 sw_if_index)
504 vl_api_ipsec_sa_details_t *mp;
506 mp = vl_msg_api_alloc (sizeof (*mp));
507 clib_memset (mp, 0, sizeof (*mp));
508 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
509 mp->context = context;
511 mp->sa_id = htonl (sa->id);
512 mp->sw_if_index = htonl (sw_if_index);
514 mp->spi = htonl (sa->spi);
515 mp->protocol = sa->protocol;
517 mp->crypto_alg = sa->crypto_alg;
518 mp->crypto_key_len = sa->crypto_key_len;
519 memcpy (mp->crypto_key, sa->crypto_key, sa->crypto_key_len);
521 mp->integ_alg = sa->integ_alg;
522 mp->integ_key_len = sa->integ_key_len;
523 memcpy (mp->integ_key, sa->integ_key, sa->integ_key_len);
525 mp->use_esn = sa->use_esn;
526 mp->use_anti_replay = sa->use_anti_replay;
528 mp->is_tunnel = sa->is_tunnel;
529 mp->is_tunnel_ip6 = sa->is_tunnel_ip6;
533 if (sa->is_tunnel_ip6)
535 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip6, 16);
536 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip6, 16);
540 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip4, 4);
541 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip4, 4);
545 mp->salt = clib_host_to_net_u32 (sa->salt);
546 mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
547 mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
550 mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
551 mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
553 if (sa->use_anti_replay)
554 mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
555 mp->total_data_size = clib_host_to_net_u64 (sa->total_data_size);
556 mp->udp_encap = sa->udp_encap;
558 vl_api_send_msg (reg, (u8 *) mp);
563 vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
565 vl_api_registration_t *reg;
566 ipsec_main_t *im = &ipsec_main;
567 vnet_main_t *vnm = im->vnet_main;
569 ipsec_tunnel_if_t *t;
570 u32 *sa_index_to_tun_if_index = 0;
573 reg = vl_api_client_index_to_registration (mp->client_index);
574 if (!reg || pool_elts (im->sad) == 0)
577 vec_validate_init_empty (sa_index_to_tun_if_index, vec_len (im->sad) - 1,
581 pool_foreach (t, im->tunnel_interfaces,
583 vnet_hw_interface_t *hi;
584 u32 sw_if_index = ~0;
586 hi = vnet_get_hw_interface (vnm, t->hw_if_index);
587 sw_if_index = hi->sw_if_index;
588 sa_index_to_tun_if_index[t->input_sa_index] = sw_if_index;
589 sa_index_to_tun_if_index[t->output_sa_index] = sw_if_index;
592 pool_foreach (sa, im->sad,
594 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == sa->id)
595 send_ipsec_sa_details (sa, reg, mp->context,
596 sa_index_to_tun_if_index[sa - im->sad]);
600 vec_free (sa_index_to_tun_if_index);
602 clib_warning ("unimplemented");
608 vl_api_ipsec_tunnel_if_set_key_t_handler (vl_api_ipsec_tunnel_if_set_key_t *
611 vl_api_ipsec_tunnel_if_set_key_reply_t *rmp;
612 ipsec_main_t *im = &ipsec_main;
613 vnet_main_t *vnm = im->vnet_main;
614 vnet_sw_interface_t *sw;
619 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
621 switch (mp->key_type)
623 case IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO:
624 case IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO:
625 if (mp->alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
626 mp->alg >= IPSEC_CRYPTO_N_ALG)
628 rv = VNET_API_ERROR_UNIMPLEMENTED;
632 case IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG:
633 case IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG:
634 if (mp->alg >= IPSEC_INTEG_N_ALG)
636 rv = VNET_API_ERROR_UNIMPLEMENTED;
640 case IPSEC_IF_SET_KEY_TYPE_NONE:
642 rv = VNET_API_ERROR_UNIMPLEMENTED;
647 key = vec_new (u8, mp->key_len);
648 clib_memcpy (key, mp->key, mp->key_len);
650 rv = ipsec_set_interface_key (vnm, sw->hw_if_index, mp->key_type, mp->alg,
654 clib_warning ("unimplemented");
658 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_KEY_REPLY);
663 vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp)
665 vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp;
666 ipsec_main_t *im = &ipsec_main;
667 vnet_main_t *vnm = im->vnet_main;
668 vnet_sw_interface_t *sw;
672 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
674 rv = ipsec_set_interface_sa (vnm, sw->hw_if_index, ntohl (mp->sa_id),
677 clib_warning ("unimplemented");
680 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY);
685 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
687 vl_api_ikev2_profile_add_del_reply_t *rmp;
691 vlib_main_t *vm = vlib_get_main ();
693 u8 *tmp = format (0, "%s", mp->name);
694 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
697 rv = VNET_API_ERROR_UNSPECIFIED;
699 rv = VNET_API_ERROR_UNIMPLEMENTED;
702 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
706 vl_api_ikev2_profile_set_auth_t_handler
707 (vl_api_ikev2_profile_set_auth_t * mp)
709 vl_api_ikev2_profile_set_auth_reply_t *rmp;
713 vlib_main_t *vm = vlib_get_main ();
715 u8 *tmp = format (0, "%s", mp->name);
716 u8 *data = vec_new (u8, mp->data_len);
717 clib_memcpy (data, mp->data, mp->data_len);
718 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
722 rv = VNET_API_ERROR_UNSPECIFIED;
724 rv = VNET_API_ERROR_UNIMPLEMENTED;
727 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
731 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
733 vl_api_ikev2_profile_add_del_reply_t *rmp;
737 vlib_main_t *vm = vlib_get_main ();
739 u8 *tmp = format (0, "%s", mp->name);
740 u8 *data = vec_new (u8, mp->data_len);
741 clib_memcpy (data, mp->data, mp->data_len);
742 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
746 rv = VNET_API_ERROR_UNSPECIFIED;
748 rv = VNET_API_ERROR_UNIMPLEMENTED;
751 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
755 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
757 vl_api_ikev2_profile_set_ts_reply_t *rmp;
761 vlib_main_t *vm = vlib_get_main ();
763 u8 *tmp = format (0, "%s", mp->name);
764 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
765 mp->end_port, (ip4_address_t) mp->start_addr,
766 (ip4_address_t) mp->end_addr, mp->is_local);
769 rv = VNET_API_ERROR_UNSPECIFIED;
771 rv = VNET_API_ERROR_UNIMPLEMENTED;
774 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
778 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
780 vl_api_ikev2_profile_set_ts_reply_t *rmp;
784 vlib_main_t *vm = vlib_get_main ();
787 error = ikev2_set_local_key (vm, mp->key_file);
789 rv = VNET_API_ERROR_UNSPECIFIED;
791 rv = VNET_API_ERROR_UNIMPLEMENTED;
794 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
798 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
800 vl_api_ikev2_set_responder_reply_t *rmp;
804 vlib_main_t *vm = vlib_get_main ();
807 u8 *tmp = format (0, "%s", mp->name);
809 clib_memcpy (&ip4, mp->address, sizeof (ip4));
811 error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
814 rv = VNET_API_ERROR_UNSPECIFIED;
816 rv = VNET_API_ERROR_UNIMPLEMENTED;
819 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
823 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
826 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
830 vlib_main_t *vm = vlib_get_main ();
833 u8 *tmp = format (0, "%s", mp->name);
836 ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
837 mp->dh_group, mp->crypto_key_size);
840 rv = VNET_API_ERROR_UNSPECIFIED;
842 rv = VNET_API_ERROR_UNIMPLEMENTED;
845 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
849 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
852 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
856 vlib_main_t *vm = vlib_get_main ();
859 u8 *tmp = format (0, "%s", mp->name);
862 ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
863 mp->dh_group, mp->crypto_key_size);
866 rv = VNET_API_ERROR_UNSPECIFIED;
868 rv = VNET_API_ERROR_UNIMPLEMENTED;
871 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
875 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
877 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
881 vlib_main_t *vm = vlib_get_main ();
884 u8 *tmp = format (0, "%s", mp->name);
887 ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
888 mp->handover, mp->lifetime_maxdata);
891 rv = VNET_API_ERROR_UNSPECIFIED;
893 rv = VNET_API_ERROR_UNIMPLEMENTED;
896 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
900 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
902 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
906 vlib_main_t *vm = vlib_get_main ();
909 u8 *tmp = format (0, "%s", mp->name);
911 error = ikev2_initiate_sa_init (vm, tmp);
914 rv = VNET_API_ERROR_UNSPECIFIED;
916 rv = VNET_API_ERROR_UNIMPLEMENTED;
919 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
923 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
926 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
930 vlib_main_t *vm = vlib_get_main ();
933 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
935 rv = VNET_API_ERROR_UNSPECIFIED;
937 rv = VNET_API_ERROR_UNIMPLEMENTED;
940 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
944 vl_api_ikev2_initiate_del_child_sa_t_handler
945 (vl_api_ikev2_initiate_del_child_sa_t * mp)
947 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
951 vlib_main_t *vm = vlib_get_main ();
954 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
956 rv = VNET_API_ERROR_UNSPECIFIED;
958 rv = VNET_API_ERROR_UNIMPLEMENTED;
961 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
965 vl_api_ikev2_initiate_rekey_child_sa_t_handler
966 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
968 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
972 vlib_main_t *vm = vlib_get_main ();
975 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
977 rv = VNET_API_ERROR_UNSPECIFIED;
979 rv = VNET_API_ERROR_UNIMPLEMENTED;
982 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
987 * Add vpe's API message handlers to the table.
988 * vlib has already mapped shared memory and
989 * added the client registration handlers.
990 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
992 #define vl_msg_name_crc_list
993 #include <vnet/vnet_all_api_h.h>
994 #undef vl_msg_name_crc_list
997 setup_message_id_table (api_main_t * am)
999 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1000 foreach_vl_msg_name_crc_ipsec;
1005 vl_api_ipsec_backend_dump_t_handler (vl_api_ipsec_backend_dump_t * mp)
1007 vl_api_registration_t *rp;
1008 ipsec_main_t *im = &ipsec_main;
1009 u32 context = mp->context;
1011 rp = vl_api_client_index_to_registration (mp->client_index);
1015 clib_warning ("Client %d AWOL", mp->client_index);
1019 ipsec_ah_backend_t *ab;
1020 ipsec_esp_backend_t *eb;
1022 pool_foreach (ab, im->ah_backends, {
1023 vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1024 clib_memset (mp, 0, sizeof (*mp));
1025 mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1026 mp->context = context;
1027 snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (ab->name),
1029 mp->protocol = IPSEC_PROTOCOL_AH;
1030 mp->index = ab - im->ah_backends;
1031 mp->active = mp->index == im->ah_current_backend ? 1 : 0;
1032 vl_api_send_msg (rp, (u8 *)mp);
1034 pool_foreach (eb, im->esp_backends, {
1035 vl_api_ipsec_backend_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
1036 clib_memset (mp, 0, sizeof (*mp));
1037 mp->_vl_msg_id = ntohs (VL_API_IPSEC_BACKEND_DETAILS);
1038 mp->context = context;
1039 snprintf ((char *)mp->name, sizeof (mp->name), "%.*s", vec_len (eb->name),
1041 mp->protocol = IPSEC_PROTOCOL_ESP;
1042 mp->index = eb - im->esp_backends;
1043 mp->active = mp->index == im->esp_current_backend ? 1 : 0;
1044 vl_api_send_msg (rp, (u8 *)mp);
1050 vl_api_ipsec_select_backend_t_handler (vl_api_ipsec_select_backend_t * mp)
1052 ipsec_main_t *im = &ipsec_main;
1053 vl_api_ipsec_select_backend_reply_t *rmp;
1055 if (pool_elts (im->sad) > 0)
1057 rv = VNET_API_ERROR_INSTANCE_IN_USE;
1061 switch (mp->protocol)
1063 case IPSEC_PROTOCOL_ESP:
1064 if (pool_is_free_index (im->esp_backends, mp->index))
1066 rv = VNET_API_ERROR_INVALID_VALUE;
1069 ipsec_select_esp_backend (im, mp->index);
1071 case IPSEC_PROTOCOL_AH:
1072 if (pool_is_free_index (im->ah_backends, mp->index))
1074 rv = VNET_API_ERROR_INVALID_VALUE;
1077 ipsec_select_ah_backend (im, mp->index);
1080 rv = VNET_API_ERROR_INVALID_VALUE;
1084 clib_warning ("unimplemented"); /* FIXME */
1087 REPLY_MACRO (VL_API_IPSEC_SELECT_BACKEND_REPLY);
1090 static clib_error_t *
1091 ipsec_api_hookup (vlib_main_t * vm)
1093 api_main_t *am = &api_main;
1096 vl_msg_api_set_handlers(VL_API_##N, #n, \
1097 vl_api_##n##_t_handler, \
1099 vl_api_##n##_t_endian, \
1100 vl_api_##n##_t_print, \
1101 sizeof(vl_api_##n##_t), 1);
1102 foreach_vpe_api_msg;
1106 * Set up the (msg_name, crc, message-id) table
1108 setup_message_id_table (am);
1113 VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
1116 * fd.io coding-style-patch-verification: ON
1119 * eval: (c-set-style "gnu")