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)
77 static void vl_api_ipsec_spd_add_del_t_handler
78 (vl_api_ipsec_spd_add_del_t * mp)
81 clib_warning ("unimplemented");
84 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
85 vl_api_ipsec_spd_add_del_reply_t *rmp;
88 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
90 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
94 static void vl_api_ipsec_interface_add_del_spd_t_handler
95 (vl_api_ipsec_interface_add_del_spd_t * mp)
97 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
98 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
100 u32 sw_if_index __attribute__ ((unused));
101 u32 spd_id __attribute__ ((unused));
103 sw_if_index = ntohl (mp->sw_if_index);
104 spd_id = ntohl (mp->spd_id);
106 VALIDATE_SW_IF_INDEX (mp);
109 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
111 rv = VNET_API_ERROR_UNIMPLEMENTED;
114 BAD_SW_IF_INDEX_LABEL;
116 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
119 static void vl_api_ipsec_spd_add_del_entry_t_handler
120 (vl_api_ipsec_spd_add_del_entry_t * mp)
122 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
123 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
129 clib_memset (&p, 0, sizeof (p));
131 p.id = ntohl (mp->spd_id);
132 p.priority = ntohl (mp->priority);
133 p.is_outbound = mp->is_outbound;
134 p.is_ipv6 = mp->is_ipv6;
136 if (mp->is_ipv6 || mp->is_ip_any)
138 clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
139 clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
140 clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
141 clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
145 clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
146 clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
147 clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
148 clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
150 p.protocol = mp->protocol;
151 p.rport.start = ntohs (mp->remote_port_start);
152 p.rport.stop = ntohs (mp->remote_port_stop);
153 p.lport.start = ntohs (mp->local_port_start);
154 p.lport.stop = ntohs (mp->local_port_stop);
155 /* policy action resolve unsupported */
156 if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
158 clib_warning ("unsupported action: 'resolve'");
159 rv = VNET_API_ERROR_UNIMPLEMENTED;
162 p.policy = mp->policy;
163 p.sa_id = ntohl (mp->sa_id);
165 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
172 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
175 rv = VNET_API_ERROR_UNIMPLEMENTED;
180 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
183 static void vl_api_ipsec_sad_add_del_entry_t_handler
184 (vl_api_ipsec_sad_add_del_entry_t * mp)
186 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
187 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
190 ipsec_main_t *im = &ipsec_main;
193 clib_memset (&sa, 0, sizeof (sa));
195 sa.id = ntohl (mp->sad_id);
196 sa.spi = ntohl (mp->spi);
197 sa.protocol = mp->protocol;
198 /* check for unsupported crypto-alg */
199 if (mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
201 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
202 mp->crypto_algorithm);
203 rv = VNET_API_ERROR_UNIMPLEMENTED;
206 sa.crypto_alg = mp->crypto_algorithm;
207 sa.crypto_key_len = mp->crypto_key_length;
208 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
209 /* check for unsupported integ-alg */
210 if (mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
212 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
213 mp->integrity_algorithm);
214 rv = VNET_API_ERROR_UNIMPLEMENTED;
218 sa.integ_alg = mp->integrity_algorithm;
219 sa.integ_key_len = mp->integrity_key_length;
220 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
221 sa.use_esn = mp->use_extended_sequence_number;
222 sa.is_tunnel = mp->is_tunnel;
223 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
224 sa.udp_encap = mp->udp_encap;
225 if (sa.is_tunnel_ip6)
227 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
228 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
232 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
233 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
235 sa.use_anti_replay = mp->use_anti_replay;
237 ASSERT (im->cb.check_support_cb);
238 clib_error_t *err = im->cb.check_support_cb (&sa);
241 clib_warning ("%s", err->what);
242 rv = VNET_API_ERROR_UNIMPLEMENTED;
246 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
248 rv = VNET_API_ERROR_UNIMPLEMENTED;
253 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
257 send_ipsec_spds_details (ipsec_spd_t * spd, vl_api_registration_t * reg,
260 vl_api_ipsec_spds_details_t *mp;
262 mp = vl_msg_api_alloc (sizeof (*mp));
263 clib_memset (mp, 0, sizeof (*mp));
264 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPDS_DETAILS);
265 mp->context = context;
267 mp->spd_id = htonl (spd->id);
268 mp->npolicies = htonl (pool_len (spd->policies));
270 vl_api_send_msg (reg, (u8 *) mp);
274 vl_api_ipsec_spds_dump_t_handler (vl_api_ipsec_spds_dump_t * mp)
276 vl_api_registration_t *reg;
277 ipsec_main_t *im = &ipsec_main;
280 reg = vl_api_client_index_to_registration (mp->client_index);
285 pool_foreach (spd, im->spds, ({
286 send_ipsec_spds_details (spd, reg, mp->context);
290 clib_warning ("unimplemented");
295 send_ipsec_spd_details (ipsec_policy_t * p, vl_api_registration_t * reg,
298 vl_api_ipsec_spd_details_t *mp;
300 mp = vl_msg_api_alloc (sizeof (*mp));
301 clib_memset (mp, 0, sizeof (*mp));
302 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
303 mp->context = context;
305 mp->spd_id = htonl (p->id);
306 mp->priority = htonl (p->priority);
307 mp->is_outbound = p->is_outbound;
308 mp->is_ipv6 = p->is_ipv6;
311 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
312 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
313 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
314 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
318 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
319 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
320 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
321 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
323 mp->local_start_port = htons (p->lport.start);
324 mp->local_stop_port = htons (p->lport.stop);
325 mp->remote_start_port = htons (p->rport.start);
326 mp->remote_stop_port = htons (p->rport.stop);
327 mp->protocol = p->protocol;
328 mp->policy = p->policy;
329 mp->sa_id = htonl (p->sa_id);
330 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
331 mp->packets = clib_host_to_net_u64 (p->counter.packets);
333 vl_api_send_msg (reg, (u8 *) mp);
337 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
339 vl_api_registration_t *reg;
340 ipsec_main_t *im = &ipsec_main;
341 ipsec_policy_t *policy;
346 reg = vl_api_client_index_to_registration (mp->client_index);
350 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
355 spd = pool_elt_at_index (im->spds, spd_index);
358 pool_foreach (policy, spd->policies,
360 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
361 send_ipsec_spd_details (policy, reg,
366 clib_warning ("unimplemented");
371 send_ipsec_spd_interface_details (vl_api_registration_t * reg, u32 spd_index,
372 u32 sw_if_index, u32 context)
374 vl_api_ipsec_spd_interface_details_t *mp;
376 mp = vl_msg_api_alloc (sizeof (*mp));
377 clib_memset (mp, 0, sizeof (*mp));
378 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_INTERFACE_DETAILS);
379 mp->context = context;
381 mp->spd_index = htonl (spd_index);
382 mp->sw_if_index = htonl (sw_if_index);
384 vl_api_send_msg (reg, (u8 *) mp);
388 vl_api_ipsec_spd_interface_dump_t_handler (vl_api_ipsec_spd_interface_dump_t *
391 ipsec_main_t *im = &ipsec_main;
392 vl_api_registration_t *reg;
396 reg = vl_api_client_index_to_registration (mp->client_index);
400 if (mp->spd_index_valid)
402 spd_index = ntohl (mp->spd_index);
404 hash_foreach(k, v, im->spd_index_by_sw_if_index, ({
406 send_ipsec_spd_interface_details(reg, v, k, mp->context);
413 hash_foreach(k, v, im->spd_index_by_sw_if_index, ({
414 send_ipsec_spd_interface_details(reg, v, k, mp->context);
420 clib_warning ("unimplemented");
425 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
427 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
428 vl_api_ipsec_sa_set_key_reply_t *rmp;
432 sa.id = ntohl (mp->sa_id);
433 sa.crypto_key_len = mp->crypto_key_length;
434 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
435 sa.integ_key_len = mp->integrity_key_length;
436 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
438 rv = ipsec_set_sa_key (vm, &sa);
440 rv = VNET_API_ERROR_UNIMPLEMENTED;
443 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
447 vl_api_ipsec_tunnel_if_add_del_t_handler (vl_api_ipsec_tunnel_if_add_del_t *
450 vl_api_ipsec_tunnel_if_add_del_reply_t *rmp;
451 ipsec_main_t *im = &ipsec_main;
452 vnet_main_t *vnm = im->vnet_main;
453 u32 sw_if_index = ~0;
457 ipsec_add_del_tunnel_args_t tun;
459 clib_memset (&tun, 0, sizeof (ipsec_add_del_tunnel_args_t));
461 tun.is_add = mp->is_add;
463 tun.anti_replay = mp->anti_replay;
464 tun.local_spi = ntohl (mp->local_spi);
465 tun.remote_spi = ntohl (mp->remote_spi);
466 tun.crypto_alg = mp->crypto_alg;
467 tun.local_crypto_key_len = mp->local_crypto_key_len;
468 tun.remote_crypto_key_len = mp->remote_crypto_key_len;
469 tun.integ_alg = mp->integ_alg;
470 tun.local_integ_key_len = mp->local_integ_key_len;
471 tun.remote_integ_key_len = mp->remote_integ_key_len;
472 memcpy (&tun.local_ip, mp->local_ip, 4);
473 memcpy (&tun.remote_ip, mp->remote_ip, 4);
474 memcpy (&tun.local_crypto_key, &mp->local_crypto_key,
475 mp->local_crypto_key_len);
476 memcpy (&tun.remote_crypto_key, &mp->remote_crypto_key,
477 mp->remote_crypto_key_len);
478 memcpy (&tun.local_integ_key, &mp->local_integ_key,
479 mp->local_integ_key_len);
480 memcpy (&tun.remote_integ_key, &mp->remote_integ_key,
481 mp->remote_integ_key_len);
482 tun.renumber = mp->renumber;
483 tun.show_instance = ntohl (mp->show_instance);
485 rv = ipsec_add_del_tunnel_if_internal (vnm, &tun, &sw_if_index);
488 rv = VNET_API_ERROR_UNIMPLEMENTED;
491 REPLY_MACRO2 (VL_API_IPSEC_TUNNEL_IF_ADD_DEL_REPLY, (
499 send_ipsec_sa_details (ipsec_sa_t * sa, vl_api_registration_t * reg,
500 u32 context, u32 sw_if_index)
502 vl_api_ipsec_sa_details_t *mp;
504 mp = vl_msg_api_alloc (sizeof (*mp));
505 clib_memset (mp, 0, sizeof (*mp));
506 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SA_DETAILS);
507 mp->context = context;
509 mp->sa_id = htonl (sa->id);
510 mp->sw_if_index = htonl (sw_if_index);
512 mp->spi = htonl (sa->spi);
513 mp->protocol = sa->protocol;
515 mp->crypto_alg = sa->crypto_alg;
516 mp->crypto_key_len = sa->crypto_key_len;
517 memcpy (mp->crypto_key, sa->crypto_key, sa->crypto_key_len);
519 mp->integ_alg = sa->integ_alg;
520 mp->integ_key_len = sa->integ_key_len;
521 memcpy (mp->integ_key, sa->integ_key, sa->integ_key_len);
523 mp->use_esn = sa->use_esn;
524 mp->use_anti_replay = sa->use_anti_replay;
526 mp->is_tunnel = sa->is_tunnel;
527 mp->is_tunnel_ip6 = sa->is_tunnel_ip6;
531 if (sa->is_tunnel_ip6)
533 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip6, 16);
534 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip6, 16);
538 memcpy (mp->tunnel_src_addr, &sa->tunnel_src_addr.ip4, 4);
539 memcpy (mp->tunnel_dst_addr, &sa->tunnel_dst_addr.ip4, 4);
543 mp->salt = clib_host_to_net_u32 (sa->salt);
544 mp->seq_outbound = clib_host_to_net_u64 (((u64) sa->seq));
545 mp->last_seq_inbound = clib_host_to_net_u64 (((u64) sa->last_seq));
548 mp->seq_outbound |= (u64) (clib_host_to_net_u32 (sa->seq_hi));
549 mp->last_seq_inbound |= (u64) (clib_host_to_net_u32 (sa->last_seq_hi));
551 if (sa->use_anti_replay)
552 mp->replay_window = clib_host_to_net_u64 (sa->replay_window);
553 mp->total_data_size = clib_host_to_net_u64 (sa->total_data_size);
554 mp->udp_encap = sa->udp_encap;
556 vl_api_send_msg (reg, (u8 *) mp);
561 vl_api_ipsec_sa_dump_t_handler (vl_api_ipsec_sa_dump_t * mp)
563 vl_api_registration_t *reg;
564 ipsec_main_t *im = &ipsec_main;
565 vnet_main_t *vnm = im->vnet_main;
567 ipsec_tunnel_if_t *t;
568 u32 *sa_index_to_tun_if_index = 0;
571 reg = vl_api_client_index_to_registration (mp->client_index);
572 if (!reg || pool_elts (im->sad) == 0)
575 vec_validate_init_empty (sa_index_to_tun_if_index, vec_len (im->sad) - 1,
579 pool_foreach (t, im->tunnel_interfaces,
581 vnet_hw_interface_t *hi;
582 u32 sw_if_index = ~0;
584 hi = vnet_get_hw_interface (vnm, t->hw_if_index);
585 sw_if_index = hi->sw_if_index;
586 sa_index_to_tun_if_index[t->input_sa_index] = sw_if_index;
587 sa_index_to_tun_if_index[t->output_sa_index] = sw_if_index;
590 pool_foreach (sa, im->sad,
592 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == sa->id)
593 send_ipsec_sa_details (sa, reg, mp->context,
594 sa_index_to_tun_if_index[sa - im->sad]);
598 vec_free (sa_index_to_tun_if_index);
600 clib_warning ("unimplemented");
606 vl_api_ipsec_tunnel_if_set_key_t_handler (vl_api_ipsec_tunnel_if_set_key_t *
609 vl_api_ipsec_tunnel_if_set_key_reply_t *rmp;
610 ipsec_main_t *im = &ipsec_main;
611 vnet_main_t *vnm = im->vnet_main;
612 vnet_sw_interface_t *sw;
617 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
619 switch (mp->key_type)
621 case IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO:
622 case IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO:
623 if (mp->alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
624 mp->alg >= IPSEC_CRYPTO_N_ALG)
626 rv = VNET_API_ERROR_UNIMPLEMENTED;
630 case IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG:
631 case IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG:
632 if (mp->alg >= IPSEC_INTEG_N_ALG)
634 rv = VNET_API_ERROR_UNIMPLEMENTED;
638 case IPSEC_IF_SET_KEY_TYPE_NONE:
640 rv = VNET_API_ERROR_UNIMPLEMENTED;
645 key = vec_new (u8, mp->key_len);
646 clib_memcpy (key, mp->key, mp->key_len);
648 rv = ipsec_set_interface_key (vnm, sw->hw_if_index, mp->key_type, mp->alg,
652 clib_warning ("unimplemented");
656 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_KEY_REPLY);
661 vl_api_ipsec_tunnel_if_set_sa_t_handler (vl_api_ipsec_tunnel_if_set_sa_t * mp)
663 vl_api_ipsec_tunnel_if_set_sa_reply_t *rmp;
664 ipsec_main_t *im = &ipsec_main;
665 vnet_main_t *vnm = im->vnet_main;
666 vnet_sw_interface_t *sw;
670 sw = vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index));
672 rv = ipsec_set_interface_sa (vnm, sw->hw_if_index, ntohl (mp->sa_id),
675 clib_warning ("unimplemented");
678 REPLY_MACRO (VL_API_IPSEC_TUNNEL_IF_SET_SA_REPLY);
683 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
685 vl_api_ikev2_profile_add_del_reply_t *rmp;
689 vlib_main_t *vm = vlib_get_main ();
691 u8 *tmp = format (0, "%s", mp->name);
692 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
695 rv = VNET_API_ERROR_UNSPECIFIED;
697 rv = VNET_API_ERROR_UNIMPLEMENTED;
700 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
704 vl_api_ikev2_profile_set_auth_t_handler
705 (vl_api_ikev2_profile_set_auth_t * mp)
707 vl_api_ikev2_profile_set_auth_reply_t *rmp;
711 vlib_main_t *vm = vlib_get_main ();
713 u8 *tmp = format (0, "%s", mp->name);
714 u8 *data = vec_new (u8, mp->data_len);
715 clib_memcpy (data, mp->data, mp->data_len);
716 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
720 rv = VNET_API_ERROR_UNSPECIFIED;
722 rv = VNET_API_ERROR_UNIMPLEMENTED;
725 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
729 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
731 vl_api_ikev2_profile_add_del_reply_t *rmp;
735 vlib_main_t *vm = vlib_get_main ();
737 u8 *tmp = format (0, "%s", mp->name);
738 u8 *data = vec_new (u8, mp->data_len);
739 clib_memcpy (data, mp->data, mp->data_len);
740 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
744 rv = VNET_API_ERROR_UNSPECIFIED;
746 rv = VNET_API_ERROR_UNIMPLEMENTED;
749 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
753 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
755 vl_api_ikev2_profile_set_ts_reply_t *rmp;
759 vlib_main_t *vm = vlib_get_main ();
761 u8 *tmp = format (0, "%s", mp->name);
762 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
763 mp->end_port, (ip4_address_t) mp->start_addr,
764 (ip4_address_t) mp->end_addr, mp->is_local);
767 rv = VNET_API_ERROR_UNSPECIFIED;
769 rv = VNET_API_ERROR_UNIMPLEMENTED;
772 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
776 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
778 vl_api_ikev2_profile_set_ts_reply_t *rmp;
782 vlib_main_t *vm = vlib_get_main ();
785 error = ikev2_set_local_key (vm, mp->key_file);
787 rv = VNET_API_ERROR_UNSPECIFIED;
789 rv = VNET_API_ERROR_UNIMPLEMENTED;
792 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
796 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
798 vl_api_ikev2_set_responder_reply_t *rmp;
802 vlib_main_t *vm = vlib_get_main ();
805 u8 *tmp = format (0, "%s", mp->name);
807 clib_memcpy (&ip4, mp->address, sizeof (ip4));
809 error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
812 rv = VNET_API_ERROR_UNSPECIFIED;
814 rv = VNET_API_ERROR_UNIMPLEMENTED;
817 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
821 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
824 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
828 vlib_main_t *vm = vlib_get_main ();
831 u8 *tmp = format (0, "%s", mp->name);
834 ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
835 mp->dh_group, mp->crypto_key_size);
838 rv = VNET_API_ERROR_UNSPECIFIED;
840 rv = VNET_API_ERROR_UNIMPLEMENTED;
843 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
847 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
850 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
854 vlib_main_t *vm = vlib_get_main ();
857 u8 *tmp = format (0, "%s", mp->name);
860 ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
861 mp->dh_group, mp->crypto_key_size);
864 rv = VNET_API_ERROR_UNSPECIFIED;
866 rv = VNET_API_ERROR_UNIMPLEMENTED;
869 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
873 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
875 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
879 vlib_main_t *vm = vlib_get_main ();
882 u8 *tmp = format (0, "%s", mp->name);
885 ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
886 mp->handover, mp->lifetime_maxdata);
889 rv = VNET_API_ERROR_UNSPECIFIED;
891 rv = VNET_API_ERROR_UNIMPLEMENTED;
894 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
898 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
900 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
904 vlib_main_t *vm = vlib_get_main ();
907 u8 *tmp = format (0, "%s", mp->name);
909 error = ikev2_initiate_sa_init (vm, tmp);
912 rv = VNET_API_ERROR_UNSPECIFIED;
914 rv = VNET_API_ERROR_UNIMPLEMENTED;
917 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
921 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
924 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
928 vlib_main_t *vm = vlib_get_main ();
931 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
933 rv = VNET_API_ERROR_UNSPECIFIED;
935 rv = VNET_API_ERROR_UNIMPLEMENTED;
938 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
942 vl_api_ikev2_initiate_del_child_sa_t_handler
943 (vl_api_ikev2_initiate_del_child_sa_t * mp)
945 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
949 vlib_main_t *vm = vlib_get_main ();
952 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
954 rv = VNET_API_ERROR_UNSPECIFIED;
956 rv = VNET_API_ERROR_UNIMPLEMENTED;
959 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
963 vl_api_ikev2_initiate_rekey_child_sa_t_handler
964 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
966 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
970 vlib_main_t *vm = vlib_get_main ();
973 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
975 rv = VNET_API_ERROR_UNSPECIFIED;
977 rv = VNET_API_ERROR_UNIMPLEMENTED;
980 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
985 * Add vpe's API message handlers to the table.
986 * vlib has already mapped shared memory and
987 * added the client registration handlers.
988 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
990 #define vl_msg_name_crc_list
991 #include <vnet/vnet_all_api_h.h>
992 #undef vl_msg_name_crc_list
995 setup_message_id_table (api_main_t * am)
997 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
998 foreach_vl_msg_name_crc_ipsec;
1002 static clib_error_t *
1003 ipsec_api_hookup (vlib_main_t * vm)
1005 api_main_t *am = &api_main;
1008 vl_msg_api_set_handlers(VL_API_##N, #n, \
1009 vl_api_##n##_t_handler, \
1011 vl_api_##n##_t_endian, \
1012 vl_api_##n##_t_print, \
1013 sizeof(vl_api_##n##_t), 1);
1014 foreach_vpe_api_msg;
1018 * Set up the (msg_name, crc, message-id) table
1020 setup_message_id_table (am);
1025 VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
1028 * fd.io coding-style-patch-verification: ON
1031 * eval: (c-set-style "gnu")