blob: 49b475cf3b698a7c08794694824ccae098c81558 [file] [log] [blame]
Pavel Kotucek9c7ef032016-12-21 07:46:45 +01001/*
2 *------------------------------------------------------------------
3 * ipsec_api.c - ipsec api
4 *
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:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
23#include <vnet/interface.h>
24#include <vnet/api_errno.h>
25#include <vnet/ip/ip.h>
26
27#include <vnet/vnet_msg_enum.h>
28
Damjan Mariona9a951f2017-01-16 22:06:10 +010029#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +010030#include <vnet/ipsec/ipsec.h>
31#include <vnet/ipsec/ikev2.h>
32#endif /* IPSEC */
33
34#define vl_typedefs /* define message structures */
35#include <vnet/vnet_all_api_h.h>
36#undef vl_typedefs
37
38#define vl_endianfun /* define message structures */
39#include <vnet/vnet_all_api_h.h>
40#undef vl_endianfun
41
42/* instantiate all the print functions we know about */
43#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
44#define vl_printfun
45#include <vnet/vnet_all_api_h.h>
46#undef vl_printfun
47
48#include <vlibapi/api_helper_macros.h>
49
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_SPD_DUMP, ipsec_spd_dump) \
57_(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del) \
58_(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth) \
59_(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id) \
60_(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts) \
Radu Nicolaucb33dc22017-02-16 16:49:46 +000061_(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key) \
62_(IKEV2_SET_RESPONDER, ikev2_set_responder) \
63_(IKEV2_SET_IKE_TRANSFORMS, ikev2_set_ike_transforms) \
64_(IKEV2_SET_ESP_TRANSFORMS, ikev2_set_esp_transforms) \
65_(IKEV2_SET_SA_LIFETIME, ikev2_set_sa_lifetime) \
66_(IKEV2_INITIATE_SA_INIT, ikev2_initiate_sa_init) \
67_(IKEV2_INITIATE_DEL_IKE_SA, ikev2_initiate_del_ike_sa) \
68_(IKEV2_INITIATE_DEL_CHILD_SA, ikev2_initiate_del_child_sa) \
69_(IKEV2_INITIATE_REKEY_CHILD_SA, ikev2_initiate_rekey_child_sa)
Pavel Kotucek9c7ef032016-12-21 07:46:45 +010070
71static void vl_api_ipsec_spd_add_del_t_handler
72 (vl_api_ipsec_spd_add_del_t * mp)
73{
Damjan Mariona9a951f2017-01-16 22:06:10 +010074#if WITH_LIBSSL == 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +010075 clib_warning ("unimplemented");
76#else
77
78 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
79 vl_api_ipsec_spd_add_del_reply_t *rmp;
80 int rv;
81
82#if DPDK > 0
83 rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
84#else
85 rv = VNET_API_ERROR_UNIMPLEMENTED;
86#endif
87
88 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
89#endif
90}
91
92static void vl_api_ipsec_interface_add_del_spd_t_handler
93 (vl_api_ipsec_interface_add_del_spd_t * mp)
94{
95 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
96 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
97 int rv;
98 u32 sw_if_index __attribute__ ((unused));
99 u32 spd_id __attribute__ ((unused));
100
101 sw_if_index = ntohl (mp->sw_if_index);
102 spd_id = ntohl (mp->spd_id);
103
104 VALIDATE_SW_IF_INDEX (mp);
105
Damjan Mariona9a951f2017-01-16 22:06:10 +0100106#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100107 rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
108#else
109 rv = VNET_API_ERROR_UNIMPLEMENTED;
110#endif
111
112 BAD_SW_IF_INDEX_LABEL;
113
114 REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
115}
116
117static void vl_api_ipsec_spd_add_del_entry_t_handler
118 (vl_api_ipsec_spd_add_del_entry_t * mp)
119{
120 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
121 vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
122 int rv;
123
Damjan Mariona9a951f2017-01-16 22:06:10 +0100124#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100125 ipsec_policy_t p;
126
127 memset (&p, 0, sizeof (p));
128
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;
133
134 if (mp->is_ipv6 || mp->is_ip_any)
135 {
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);
140 }
141 else
142 {
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);
147 }
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)
155 {
156 clib_warning ("unsupported action: 'resolve'");
157 rv = VNET_API_ERROR_UNIMPLEMENTED;
158 goto out;
159 }
160 p.policy = mp->policy;
161 p.sa_id = ntohl (mp->sa_id);
162
163 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
164 if (rv)
165 goto out;
166
167 if (mp->is_ip_any)
168 {
169 p.is_ipv6 = 1;
170 rv = ipsec_add_del_policy (vm, &p, mp->is_add);
171 }
172#else
173 rv = VNET_API_ERROR_UNIMPLEMENTED;
174 goto out;
175#endif
176
177out:
178 REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
179}
180
181static void vl_api_ipsec_sad_add_del_entry_t_handler
182 (vl_api_ipsec_sad_add_del_entry_t * mp)
183{
184 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
185 vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
186 int rv;
Damjan Mariona9a951f2017-01-16 22:06:10 +0100187#if WITH_LIBSSL > 0
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000188 ipsec_main_t *im = &ipsec_main;
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100189 ipsec_sa_t sa;
190
191 memset (&sa, 0, sizeof (sa));
192
193 sa.id = ntohl (mp->sad_id);
194 sa.spi = ntohl (mp->spi);
195 /* security protocol AH unsupported */
196 if (mp->protocol == IPSEC_PROTOCOL_AH)
197 {
198 clib_warning ("unsupported security protocol 'AH'");
199 rv = VNET_API_ERROR_UNIMPLEMENTED;
200 goto out;
201 }
202 sa.protocol = mp->protocol;
203 /* check for unsupported crypto-alg */
204 if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
205 mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
206 {
207 clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
208 mp->crypto_algorithm);
209 rv = VNET_API_ERROR_UNIMPLEMENTED;
210 goto out;
211 }
212 sa.crypto_alg = mp->crypto_algorithm;
213 sa.crypto_key_len = mp->crypto_key_length;
214 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
215 /* check for unsupported integ-alg */
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100216 if (mp->integrity_algorithm < IPSEC_INTEG_ALG_NONE ||
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100217 mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
218 {
219 clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
220 mp->integrity_algorithm);
221 rv = VNET_API_ERROR_UNIMPLEMENTED;
222 goto out;
223 }
224
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100225 sa.integ_alg = mp->integrity_algorithm;
226 sa.integ_key_len = mp->integrity_key_length;
227 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
228 sa.use_esn = mp->use_extended_sequence_number;
229 sa.is_tunnel = mp->is_tunnel;
230 sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
231 if (sa.is_tunnel_ip6)
232 {
233 clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
234 clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
235 }
236 else
237 {
238 clib_memcpy (&sa.tunnel_src_addr.ip4.data, mp->tunnel_src_address, 4);
239 clib_memcpy (&sa.tunnel_dst_addr.ip4.data, mp->tunnel_dst_address, 4);
240 }
241
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000242 ASSERT (im->cb.check_support_cb);
243 clib_error_t *err = im->cb.check_support_cb (&sa);
244 if (err)
245 {
246 clib_warning ("%s", err->what);
247 rv = VNET_API_ERROR_UNIMPLEMENTED;
248 goto out;
249 }
250
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100251 rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
252#else
253 rv = VNET_API_ERROR_UNIMPLEMENTED;
254 goto out;
255#endif
256
257out:
258 REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
259}
260
261static void
262send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
263 u32 context)
264{
265 vl_api_ipsec_spd_details_t *mp;
266
267 mp = vl_msg_api_alloc (sizeof (*mp));
268 memset (mp, 0, sizeof (*mp));
269 mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
270 mp->context = context;
271
272 mp->spd_id = htonl (p->id);
273 mp->priority = htonl (p->priority);
274 mp->is_outbound = p->is_outbound;
275 mp->is_ipv6 = p->is_ipv6;
276 if (p->is_ipv6)
277 {
278 memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
279 memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
280 memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
281 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
282 }
283 else
284 {
285 memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
286 memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
287 memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
288 memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
289 }
290 mp->local_start_port = htons (p->lport.start);
291 mp->local_stop_port = htons (p->lport.stop);
292 mp->remote_start_port = htons (p->rport.start);
293 mp->remote_stop_port = htons (p->rport.stop);
294 mp->protocol = p->protocol;
295 mp->policy = p->policy;
296 mp->sa_id = htonl (p->sa_id);
297 mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
298 mp->packets = clib_host_to_net_u64 (p->counter.packets);
299
300 vl_msg_api_send_shmem (q, (u8 *) & mp);
301}
302
303static void
304vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
305{
306 unix_shared_memory_queue_t *q;
307 ipsec_main_t *im = &ipsec_main;
308 ipsec_policy_t *policy;
309 ipsec_spd_t *spd;
310 uword *p;
311 u32 spd_index;
Damjan Mariona9a951f2017-01-16 22:06:10 +0100312#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100313 q = vl_api_client_index_to_input_queue (mp->client_index);
314 if (q == 0)
315 return;
316
317 p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
318 if (!p)
319 return;
320
321 spd_index = p[0];
322 spd = pool_elt_at_index (im->spds, spd_index);
323
324 /* *INDENT-OFF* */
325 pool_foreach (policy, spd->policies,
326 ({
327 if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
328 send_ipsec_spd_details (policy, q,
329 mp->context);}
330 ));
331 /* *INDENT-ON* */
332#else
333 clib_warning ("unimplemented");
334#endif
335}
336
337static void
338vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
339{
340 vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
341 vl_api_ipsec_sa_set_key_reply_t *rmp;
342 int rv;
Damjan Mariona9a951f2017-01-16 22:06:10 +0100343#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100344 ipsec_sa_t sa;
345 sa.id = ntohl (mp->sa_id);
346 sa.crypto_key_len = mp->crypto_key_length;
347 clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
348 sa.integ_key_len = mp->integrity_key_length;
349 clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
350
351 rv = ipsec_set_sa_key (vm, &sa);
352#else
353 rv = VNET_API_ERROR_UNIMPLEMENTED;
354#endif
355
356 REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
357}
358
359static void
360vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
361{
362 vl_api_ikev2_profile_add_del_reply_t *rmp;
363 int rv = 0;
364
Damjan Mariona9a951f2017-01-16 22:06:10 +0100365#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100366 vlib_main_t *vm = vlib_get_main ();
367 clib_error_t *error;
368 u8 *tmp = format (0, "%s", mp->name);
369 error = ikev2_add_del_profile (vm, tmp, mp->is_add);
370 vec_free (tmp);
371 if (error)
372 rv = VNET_API_ERROR_UNSPECIFIED;
373#else
374 rv = VNET_API_ERROR_UNIMPLEMENTED;
375#endif
376
377 REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
378}
379
380static void
381 vl_api_ikev2_profile_set_auth_t_handler
382 (vl_api_ikev2_profile_set_auth_t * mp)
383{
384 vl_api_ikev2_profile_set_auth_reply_t *rmp;
385 int rv = 0;
386
Damjan Mariona9a951f2017-01-16 22:06:10 +0100387#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100388 vlib_main_t *vm = vlib_get_main ();
389 clib_error_t *error;
390 u8 *tmp = format (0, "%s", mp->name);
391 u8 *data = vec_new (u8, mp->data_len);
392 clib_memcpy (data, mp->data, mp->data_len);
393 error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
394 vec_free (tmp);
395 vec_free (data);
396 if (error)
397 rv = VNET_API_ERROR_UNSPECIFIED;
398#else
399 rv = VNET_API_ERROR_UNIMPLEMENTED;
400#endif
401
402 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
403}
404
405static void
406vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
407{
408 vl_api_ikev2_profile_add_del_reply_t *rmp;
409 int rv = 0;
410
Damjan Mariona9a951f2017-01-16 22:06:10 +0100411#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100412 vlib_main_t *vm = vlib_get_main ();
413 clib_error_t *error;
414 u8 *tmp = format (0, "%s", mp->name);
415 u8 *data = vec_new (u8, mp->data_len);
416 clib_memcpy (data, mp->data, mp->data_len);
417 error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
418 vec_free (tmp);
419 vec_free (data);
420 if (error)
421 rv = VNET_API_ERROR_UNSPECIFIED;
422#else
423 rv = VNET_API_ERROR_UNIMPLEMENTED;
424#endif
425
426 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
427}
428
429static void
430vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
431{
432 vl_api_ikev2_profile_set_ts_reply_t *rmp;
433 int rv = 0;
434
Damjan Mariona9a951f2017-01-16 22:06:10 +0100435#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100436 vlib_main_t *vm = vlib_get_main ();
437 clib_error_t *error;
438 u8 *tmp = format (0, "%s", mp->name);
439 error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
440 mp->end_port, (ip4_address_t) mp->start_addr,
441 (ip4_address_t) mp->end_addr, mp->is_local);
442 vec_free (tmp);
443 if (error)
444 rv = VNET_API_ERROR_UNSPECIFIED;
445#else
446 rv = VNET_API_ERROR_UNIMPLEMENTED;
447#endif
448
449 REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
450}
451
452static void
453vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
454{
455 vl_api_ikev2_profile_set_ts_reply_t *rmp;
456 int rv = 0;
457
Damjan Mariona9a951f2017-01-16 22:06:10 +0100458#if WITH_LIBSSL > 0
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100459 vlib_main_t *vm = vlib_get_main ();
460 clib_error_t *error;
461
462 error = ikev2_set_local_key (vm, mp->key_file);
463 if (error)
464 rv = VNET_API_ERROR_UNSPECIFIED;
465#else
466 rv = VNET_API_ERROR_UNIMPLEMENTED;
467#endif
468
469 REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
470}
471
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000472static void
473vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
474{
475 vl_api_ikev2_set_responder_reply_t *rmp;
476 int rv = 0;
477
478#if WITH_LIBSSL > 0
479 vlib_main_t *vm = vlib_get_main ();
480 clib_error_t *error;
481
482 u8 *tmp = format (0, "%s", mp->name);
483 ip4_address_t ip4;
484 clib_memcpy (&ip4, mp->address, sizeof (ip4));
485
486 error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
487 vec_free (tmp);
488 if (error)
489 rv = VNET_API_ERROR_UNSPECIFIED;
490#else
491 rv = VNET_API_ERROR_UNIMPLEMENTED;
492#endif
493
494 REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
495}
496
497static void
498vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
499 mp)
500{
501 vl_api_ikev2_set_ike_transforms_reply_t *rmp;
502 int rv = 0;
503
504#if WITH_LIBSSL > 0
505 vlib_main_t *vm = vlib_get_main ();
506 clib_error_t *error;
507
508 u8 *tmp = format (0, "%s", mp->name);
509
510 error =
511 ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
512 mp->dh_group, mp->crypto_key_size);
513 vec_free (tmp);
514 if (error)
515 rv = VNET_API_ERROR_UNSPECIFIED;
516#else
517 rv = VNET_API_ERROR_UNIMPLEMENTED;
518#endif
519
520 REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
521}
522
523static void
524vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
525 mp)
526{
527 vl_api_ikev2_set_esp_transforms_reply_t *rmp;
528 int rv = 0;
529
530#if WITH_LIBSSL > 0
531 vlib_main_t *vm = vlib_get_main ();
532 clib_error_t *error;
533
534 u8 *tmp = format (0, "%s", mp->name);
535
536 error =
537 ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
538 mp->dh_group, mp->crypto_key_size);
539 vec_free (tmp);
540 if (error)
541 rv = VNET_API_ERROR_UNSPECIFIED;
542#else
543 rv = VNET_API_ERROR_UNIMPLEMENTED;
544#endif
545
546 REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
547}
548
549static void
550vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
551{
552 vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
553 int rv = 0;
554
555#if WITH_LIBSSL > 0
556 vlib_main_t *vm = vlib_get_main ();
557 clib_error_t *error;
558
559 u8 *tmp = format (0, "%s", mp->name);
560
561 error =
562 ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
563 mp->handover, mp->lifetime_maxdata);
564 vec_free (tmp);
565 if (error)
566 rv = VNET_API_ERROR_UNSPECIFIED;
567#else
568 rv = VNET_API_ERROR_UNIMPLEMENTED;
569#endif
570
571 REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
572}
573
574static void
575vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
576{
577 vl_api_ikev2_initiate_sa_init_reply_t *rmp;
578 int rv = 0;
579
580#if WITH_LIBSSL > 0
581 vlib_main_t *vm = vlib_get_main ();
582 clib_error_t *error;
583
584 u8 *tmp = format (0, "%s", mp->name);
585
586 error = ikev2_initiate_sa_init (vm, tmp);
587 vec_free (tmp);
588 if (error)
589 rv = VNET_API_ERROR_UNSPECIFIED;
590#else
591 rv = VNET_API_ERROR_UNIMPLEMENTED;
592#endif
593
594 REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
595}
596
597static void
598vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
599 * mp)
600{
601 vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
602 int rv = 0;
603
604#if WITH_LIBSSL > 0
605 vlib_main_t *vm = vlib_get_main ();
606 clib_error_t *error;
607
608 error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
609 if (error)
610 rv = VNET_API_ERROR_UNSPECIFIED;
611#else
612 rv = VNET_API_ERROR_UNIMPLEMENTED;
613#endif
614
615 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
616}
617
618static void
619 vl_api_ikev2_initiate_del_child_sa_t_handler
620 (vl_api_ikev2_initiate_del_child_sa_t * mp)
621{
622 vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
623 int rv = 0;
624
625#if WITH_LIBSSL > 0
626 vlib_main_t *vm = vlib_get_main ();
627 clib_error_t *error;
628
629 error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
630 if (error)
631 rv = VNET_API_ERROR_UNSPECIFIED;
632#else
633 rv = VNET_API_ERROR_UNIMPLEMENTED;
634#endif
635
636 REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
637}
638
639static void
640 vl_api_ikev2_initiate_rekey_child_sa_t_handler
641 (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
642{
643 vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
644 int rv = 0;
645
646#if WITH_LIBSSL > 0
647 vlib_main_t *vm = vlib_get_main ();
648 clib_error_t *error;
649
650 error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
651 if (error)
652 rv = VNET_API_ERROR_UNSPECIFIED;
653#else
654 rv = VNET_API_ERROR_UNIMPLEMENTED;
655#endif
656
657 REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
658}
659
Pavel Kotucek9c7ef032016-12-21 07:46:45 +0100660/*
661 * ipsec_api_hookup
662 * Add vpe's API message handlers to the table.
663 * vlib has alread mapped shared memory and
664 * added the client registration handlers.
665 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
666 */
667#define vl_msg_name_crc_list
668#include <vnet/vnet_all_api_h.h>
669#undef vl_msg_name_crc_list
670
671static void
672setup_message_id_table (api_main_t * am)
673{
674#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
675 foreach_vl_msg_name_crc_ipsec;
676#undef _
677}
678
679static clib_error_t *
680ipsec_api_hookup (vlib_main_t * vm)
681{
682 api_main_t *am = &api_main;
683
684#define _(N,n) \
685 vl_msg_api_set_handlers(VL_API_##N, #n, \
686 vl_api_##n##_t_handler, \
687 vl_noop_handler, \
688 vl_api_##n##_t_endian, \
689 vl_api_##n##_t_print, \
690 sizeof(vl_api_##n##_t), 1);
691 foreach_vpe_api_msg;
692#undef _
693
694 /*
695 * Set up the (msg_name, crc, message-id) table
696 */
697 setup_message_id_table (am);
698
699 return 0;
700}
701
702VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
703
704/*
705 * fd.io coding-style-patch-verification: ON
706 *
707 * Local Variables:
708 * eval: (c-set-style "gnu")
709 * End:
710 */