dpdk: be a plugin
[vpp.git] / src / vnet / ipsec / ipsec_api.c
1 /*
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
29 #if WITH_LIBSSL > 0
30 #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)                           \
61 _(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)
70
71 static void vl_api_ipsec_spd_add_del_t_handler
72   (vl_api_ipsec_spd_add_del_t * mp)
73 {
74 #if WITH_LIBSSL == 0
75   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   rv = ipsec_add_del_spd (vm, ntohl (mp->spd_id), mp->is_add);
83
84   REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_REPLY);
85 #endif
86 }
87
88 static void vl_api_ipsec_interface_add_del_spd_t_handler
89   (vl_api_ipsec_interface_add_del_spd_t * mp)
90 {
91   vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
92   vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
93   int rv;
94   u32 sw_if_index __attribute__ ((unused));
95   u32 spd_id __attribute__ ((unused));
96
97   sw_if_index = ntohl (mp->sw_if_index);
98   spd_id = ntohl (mp->spd_id);
99
100   VALIDATE_SW_IF_INDEX (mp);
101
102 #if WITH_LIBSSL > 0
103   rv = ipsec_set_interface_spd (vm, sw_if_index, spd_id, mp->is_add);
104 #else
105   rv = VNET_API_ERROR_UNIMPLEMENTED;
106 #endif
107
108   BAD_SW_IF_INDEX_LABEL;
109
110   REPLY_MACRO (VL_API_IPSEC_INTERFACE_ADD_DEL_SPD_REPLY);
111 }
112
113 static void vl_api_ipsec_spd_add_del_entry_t_handler
114   (vl_api_ipsec_spd_add_del_entry_t * mp)
115 {
116   vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
117   vl_api_ipsec_spd_add_del_entry_reply_t *rmp;
118   int rv;
119
120 #if WITH_LIBSSL > 0
121   ipsec_policy_t p;
122
123   memset (&p, 0, sizeof (p));
124
125   p.id = ntohl (mp->spd_id);
126   p.priority = ntohl (mp->priority);
127   p.is_outbound = mp->is_outbound;
128   p.is_ipv6 = mp->is_ipv6;
129
130   if (mp->is_ipv6 || mp->is_ip_any)
131     {
132       clib_memcpy (&p.raddr.start, mp->remote_address_start, 16);
133       clib_memcpy (&p.raddr.stop, mp->remote_address_stop, 16);
134       clib_memcpy (&p.laddr.start, mp->local_address_start, 16);
135       clib_memcpy (&p.laddr.stop, mp->local_address_stop, 16);
136     }
137   else
138     {
139       clib_memcpy (&p.raddr.start.ip4.data, mp->remote_address_start, 4);
140       clib_memcpy (&p.raddr.stop.ip4.data, mp->remote_address_stop, 4);
141       clib_memcpy (&p.laddr.start.ip4.data, mp->local_address_start, 4);
142       clib_memcpy (&p.laddr.stop.ip4.data, mp->local_address_stop, 4);
143     }
144   p.protocol = mp->protocol;
145   p.rport.start = ntohs (mp->remote_port_start);
146   p.rport.stop = ntohs (mp->remote_port_stop);
147   p.lport.start = ntohs (mp->local_port_start);
148   p.lport.stop = ntohs (mp->local_port_stop);
149   /* policy action resolve unsupported */
150   if (mp->policy == IPSEC_POLICY_ACTION_RESOLVE)
151     {
152       clib_warning ("unsupported action: 'resolve'");
153       rv = VNET_API_ERROR_UNIMPLEMENTED;
154       goto out;
155     }
156   p.policy = mp->policy;
157   p.sa_id = ntohl (mp->sa_id);
158
159   rv = ipsec_add_del_policy (vm, &p, mp->is_add);
160   if (rv)
161     goto out;
162
163   if (mp->is_ip_any)
164     {
165       p.is_ipv6 = 1;
166       rv = ipsec_add_del_policy (vm, &p, mp->is_add);
167     }
168 #else
169   rv = VNET_API_ERROR_UNIMPLEMENTED;
170   goto out;
171 #endif
172
173 out:
174   REPLY_MACRO (VL_API_IPSEC_SPD_ADD_DEL_ENTRY_REPLY);
175 }
176
177 static void vl_api_ipsec_sad_add_del_entry_t_handler
178   (vl_api_ipsec_sad_add_del_entry_t * mp)
179 {
180   vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
181   vl_api_ipsec_sad_add_del_entry_reply_t *rmp;
182   int rv;
183 #if WITH_LIBSSL > 0
184   ipsec_main_t *im = &ipsec_main;
185   ipsec_sa_t sa;
186
187   memset (&sa, 0, sizeof (sa));
188
189   sa.id = ntohl (mp->sad_id);
190   sa.spi = ntohl (mp->spi);
191   /* security protocol AH unsupported */
192   if (mp->protocol == IPSEC_PROTOCOL_AH)
193     {
194       clib_warning ("unsupported security protocol 'AH'");
195       rv = VNET_API_ERROR_UNIMPLEMENTED;
196       goto out;
197     }
198   sa.protocol = mp->protocol;
199   /* check for unsupported crypto-alg */
200   if (mp->crypto_algorithm < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
201       mp->crypto_algorithm >= IPSEC_CRYPTO_N_ALG)
202     {
203       clib_warning ("unsupported crypto-alg: '%U'", format_ipsec_crypto_alg,
204                     mp->crypto_algorithm);
205       rv = VNET_API_ERROR_UNIMPLEMENTED;
206       goto out;
207     }
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_ALG_NONE ||
213       mp->integrity_algorithm >= IPSEC_INTEG_N_ALG)
214     {
215       clib_warning ("unsupported integ-alg: '%U'", format_ipsec_integ_alg,
216                     mp->integrity_algorithm);
217       rv = VNET_API_ERROR_UNIMPLEMENTED;
218       goto out;
219     }
220
221   sa.integ_alg = mp->integrity_algorithm;
222   sa.integ_key_len = mp->integrity_key_length;
223   clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
224   sa.use_esn = mp->use_extended_sequence_number;
225   sa.is_tunnel = mp->is_tunnel;
226   sa.is_tunnel_ip6 = mp->is_tunnel_ipv6;
227   if (sa.is_tunnel_ip6)
228     {
229       clib_memcpy (&sa.tunnel_src_addr, mp->tunnel_src_address, 16);
230       clib_memcpy (&sa.tunnel_dst_addr, mp->tunnel_dst_address, 16);
231     }
232   else
233     {
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);
236     }
237
238   ASSERT (im->cb.check_support_cb);
239   clib_error_t *err = im->cb.check_support_cb (&sa);
240   if (err)
241     {
242       clib_warning ("%s", err->what);
243       rv = VNET_API_ERROR_UNIMPLEMENTED;
244       goto out;
245     }
246
247   rv = ipsec_add_del_sa (vm, &sa, mp->is_add);
248 #else
249   rv = VNET_API_ERROR_UNIMPLEMENTED;
250   goto out;
251 #endif
252
253 out:
254   REPLY_MACRO (VL_API_IPSEC_SAD_ADD_DEL_ENTRY_REPLY);
255 }
256
257 static void
258 send_ipsec_spd_details (ipsec_policy_t * p, unix_shared_memory_queue_t * q,
259                         u32 context)
260 {
261   vl_api_ipsec_spd_details_t *mp;
262
263   mp = vl_msg_api_alloc (sizeof (*mp));
264   memset (mp, 0, sizeof (*mp));
265   mp->_vl_msg_id = ntohs (VL_API_IPSEC_SPD_DETAILS);
266   mp->context = context;
267
268   mp->spd_id = htonl (p->id);
269   mp->priority = htonl (p->priority);
270   mp->is_outbound = p->is_outbound;
271   mp->is_ipv6 = p->is_ipv6;
272   if (p->is_ipv6)
273     {
274       memcpy (mp->local_start_addr, &p->laddr.start.ip6, 16);
275       memcpy (mp->local_stop_addr, &p->laddr.stop.ip6, 16);
276       memcpy (mp->remote_start_addr, &p->raddr.start.ip6, 16);
277       memcpy (mp->remote_stop_addr, &p->raddr.stop.ip6, 16);
278     }
279   else
280     {
281       memcpy (mp->local_start_addr, &p->laddr.start.ip4, 4);
282       memcpy (mp->local_stop_addr, &p->laddr.stop.ip4, 4);
283       memcpy (mp->remote_start_addr, &p->raddr.start.ip4, 4);
284       memcpy (mp->remote_stop_addr, &p->raddr.stop.ip4, 4);
285     }
286   mp->local_start_port = htons (p->lport.start);
287   mp->local_stop_port = htons (p->lport.stop);
288   mp->remote_start_port = htons (p->rport.start);
289   mp->remote_stop_port = htons (p->rport.stop);
290   mp->protocol = p->protocol;
291   mp->policy = p->policy;
292   mp->sa_id = htonl (p->sa_id);
293   mp->bytes = clib_host_to_net_u64 (p->counter.bytes);
294   mp->packets = clib_host_to_net_u64 (p->counter.packets);
295
296   vl_msg_api_send_shmem (q, (u8 *) & mp);
297 }
298
299 static void
300 vl_api_ipsec_spd_dump_t_handler (vl_api_ipsec_spd_dump_t * mp)
301 {
302   unix_shared_memory_queue_t *q;
303   ipsec_main_t *im = &ipsec_main;
304   ipsec_policy_t *policy;
305   ipsec_spd_t *spd;
306   uword *p;
307   u32 spd_index;
308 #if WITH_LIBSSL > 0
309   q = vl_api_client_index_to_input_queue (mp->client_index);
310   if (q == 0)
311     return;
312
313   p = hash_get (im->spd_index_by_spd_id, ntohl (mp->spd_id));
314   if (!p)
315     return;
316
317   spd_index = p[0];
318   spd = pool_elt_at_index (im->spds, spd_index);
319
320   /* *INDENT-OFF* */
321   pool_foreach (policy, spd->policies,
322   ({
323     if (mp->sa_id == ~(0) || ntohl (mp->sa_id) == policy->sa_id)
324       send_ipsec_spd_details (policy, q,
325                               mp->context);}
326     ));
327   /* *INDENT-ON* */
328 #else
329   clib_warning ("unimplemented");
330 #endif
331 }
332
333 static void
334 vl_api_ipsec_sa_set_key_t_handler (vl_api_ipsec_sa_set_key_t * mp)
335 {
336   vlib_main_t *vm __attribute__ ((unused)) = vlib_get_main ();
337   vl_api_ipsec_sa_set_key_reply_t *rmp;
338   int rv;
339 #if WITH_LIBSSL > 0
340   ipsec_sa_t sa;
341   sa.id = ntohl (mp->sa_id);
342   sa.crypto_key_len = mp->crypto_key_length;
343   clib_memcpy (&sa.crypto_key, mp->crypto_key, sizeof (sa.crypto_key));
344   sa.integ_key_len = mp->integrity_key_length;
345   clib_memcpy (&sa.integ_key, mp->integrity_key, sizeof (sa.integ_key));
346
347   rv = ipsec_set_sa_key (vm, &sa);
348 #else
349   rv = VNET_API_ERROR_UNIMPLEMENTED;
350 #endif
351
352   REPLY_MACRO (VL_API_IPSEC_SA_SET_KEY_REPLY);
353 }
354
355 static void
356 vl_api_ikev2_profile_add_del_t_handler (vl_api_ikev2_profile_add_del_t * mp)
357 {
358   vl_api_ikev2_profile_add_del_reply_t *rmp;
359   int rv = 0;
360
361 #if WITH_LIBSSL > 0
362   vlib_main_t *vm = vlib_get_main ();
363   clib_error_t *error;
364   u8 *tmp = format (0, "%s", mp->name);
365   error = ikev2_add_del_profile (vm, tmp, mp->is_add);
366   vec_free (tmp);
367   if (error)
368     rv = VNET_API_ERROR_UNSPECIFIED;
369 #else
370   rv = VNET_API_ERROR_UNIMPLEMENTED;
371 #endif
372
373   REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
374 }
375
376 static void
377   vl_api_ikev2_profile_set_auth_t_handler
378   (vl_api_ikev2_profile_set_auth_t * mp)
379 {
380   vl_api_ikev2_profile_set_auth_reply_t *rmp;
381   int rv = 0;
382
383 #if WITH_LIBSSL > 0
384   vlib_main_t *vm = vlib_get_main ();
385   clib_error_t *error;
386   u8 *tmp = format (0, "%s", mp->name);
387   u8 *data = vec_new (u8, mp->data_len);
388   clib_memcpy (data, mp->data, mp->data_len);
389   error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
390   vec_free (tmp);
391   vec_free (data);
392   if (error)
393     rv = VNET_API_ERROR_UNSPECIFIED;
394 #else
395   rv = VNET_API_ERROR_UNIMPLEMENTED;
396 #endif
397
398   REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
399 }
400
401 static void
402 vl_api_ikev2_profile_set_id_t_handler (vl_api_ikev2_profile_set_id_t * mp)
403 {
404   vl_api_ikev2_profile_add_del_reply_t *rmp;
405   int rv = 0;
406
407 #if WITH_LIBSSL > 0
408   vlib_main_t *vm = vlib_get_main ();
409   clib_error_t *error;
410   u8 *tmp = format (0, "%s", mp->name);
411   u8 *data = vec_new (u8, mp->data_len);
412   clib_memcpy (data, mp->data, mp->data_len);
413   error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
414   vec_free (tmp);
415   vec_free (data);
416   if (error)
417     rv = VNET_API_ERROR_UNSPECIFIED;
418 #else
419   rv = VNET_API_ERROR_UNIMPLEMENTED;
420 #endif
421
422   REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
423 }
424
425 static void
426 vl_api_ikev2_profile_set_ts_t_handler (vl_api_ikev2_profile_set_ts_t * mp)
427 {
428   vl_api_ikev2_profile_set_ts_reply_t *rmp;
429   int rv = 0;
430
431 #if WITH_LIBSSL > 0
432   vlib_main_t *vm = vlib_get_main ();
433   clib_error_t *error;
434   u8 *tmp = format (0, "%s", mp->name);
435   error = ikev2_set_profile_ts (vm, tmp, mp->proto, mp->start_port,
436                                 mp->end_port, (ip4_address_t) mp->start_addr,
437                                 (ip4_address_t) mp->end_addr, mp->is_local);
438   vec_free (tmp);
439   if (error)
440     rv = VNET_API_ERROR_UNSPECIFIED;
441 #else
442   rv = VNET_API_ERROR_UNIMPLEMENTED;
443 #endif
444
445   REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_TS_REPLY);
446 }
447
448 static void
449 vl_api_ikev2_set_local_key_t_handler (vl_api_ikev2_set_local_key_t * mp)
450 {
451   vl_api_ikev2_profile_set_ts_reply_t *rmp;
452   int rv = 0;
453
454 #if WITH_LIBSSL > 0
455   vlib_main_t *vm = vlib_get_main ();
456   clib_error_t *error;
457
458   error = ikev2_set_local_key (vm, mp->key_file);
459   if (error)
460     rv = VNET_API_ERROR_UNSPECIFIED;
461 #else
462   rv = VNET_API_ERROR_UNIMPLEMENTED;
463 #endif
464
465   REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
466 }
467
468 static void
469 vl_api_ikev2_set_responder_t_handler (vl_api_ikev2_set_responder_t * mp)
470 {
471   vl_api_ikev2_set_responder_reply_t *rmp;
472   int rv = 0;
473
474 #if WITH_LIBSSL > 0
475   vlib_main_t *vm = vlib_get_main ();
476   clib_error_t *error;
477
478   u8 *tmp = format (0, "%s", mp->name);
479   ip4_address_t ip4;
480   clib_memcpy (&ip4, mp->address, sizeof (ip4));
481
482   error = ikev2_set_profile_responder (vm, tmp, mp->sw_if_index, ip4);
483   vec_free (tmp);
484   if (error)
485     rv = VNET_API_ERROR_UNSPECIFIED;
486 #else
487   rv = VNET_API_ERROR_UNIMPLEMENTED;
488 #endif
489
490   REPLY_MACRO (VL_API_IKEV2_SET_RESPONDER_REPLY);
491 }
492
493 static void
494 vl_api_ikev2_set_ike_transforms_t_handler (vl_api_ikev2_set_ike_transforms_t *
495                                            mp)
496 {
497   vl_api_ikev2_set_ike_transforms_reply_t *rmp;
498   int rv = 0;
499
500 #if WITH_LIBSSL > 0
501   vlib_main_t *vm = vlib_get_main ();
502   clib_error_t *error;
503
504   u8 *tmp = format (0, "%s", mp->name);
505
506   error =
507     ikev2_set_profile_ike_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
508                                       mp->dh_group, mp->crypto_key_size);
509   vec_free (tmp);
510   if (error)
511     rv = VNET_API_ERROR_UNSPECIFIED;
512 #else
513   rv = VNET_API_ERROR_UNIMPLEMENTED;
514 #endif
515
516   REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
517 }
518
519 static void
520 vl_api_ikev2_set_esp_transforms_t_handler (vl_api_ikev2_set_esp_transforms_t *
521                                            mp)
522 {
523   vl_api_ikev2_set_esp_transforms_reply_t *rmp;
524   int rv = 0;
525
526 #if WITH_LIBSSL > 0
527   vlib_main_t *vm = vlib_get_main ();
528   clib_error_t *error;
529
530   u8 *tmp = format (0, "%s", mp->name);
531
532   error =
533     ikev2_set_profile_esp_transforms (vm, tmp, mp->crypto_alg, mp->integ_alg,
534                                       mp->dh_group, mp->crypto_key_size);
535   vec_free (tmp);
536   if (error)
537     rv = VNET_API_ERROR_UNSPECIFIED;
538 #else
539   rv = VNET_API_ERROR_UNIMPLEMENTED;
540 #endif
541
542   REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
543 }
544
545 static void
546 vl_api_ikev2_set_sa_lifetime_t_handler (vl_api_ikev2_set_sa_lifetime_t * mp)
547 {
548   vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
549   int rv = 0;
550
551 #if WITH_LIBSSL > 0
552   vlib_main_t *vm = vlib_get_main ();
553   clib_error_t *error;
554
555   u8 *tmp = format (0, "%s", mp->name);
556
557   error =
558     ikev2_set_profile_sa_lifetime (vm, tmp, mp->lifetime, mp->lifetime_jitter,
559                                    mp->handover, mp->lifetime_maxdata);
560   vec_free (tmp);
561   if (error)
562     rv = VNET_API_ERROR_UNSPECIFIED;
563 #else
564   rv = VNET_API_ERROR_UNIMPLEMENTED;
565 #endif
566
567   REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
568 }
569
570 static void
571 vl_api_ikev2_initiate_sa_init_t_handler (vl_api_ikev2_initiate_sa_init_t * mp)
572 {
573   vl_api_ikev2_initiate_sa_init_reply_t *rmp;
574   int rv = 0;
575
576 #if WITH_LIBSSL > 0
577   vlib_main_t *vm = vlib_get_main ();
578   clib_error_t *error;
579
580   u8 *tmp = format (0, "%s", mp->name);
581
582   error = ikev2_initiate_sa_init (vm, tmp);
583   vec_free (tmp);
584   if (error)
585     rv = VNET_API_ERROR_UNSPECIFIED;
586 #else
587   rv = VNET_API_ERROR_UNIMPLEMENTED;
588 #endif
589
590   REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
591 }
592
593 static void
594 vl_api_ikev2_initiate_del_ike_sa_t_handler (vl_api_ikev2_initiate_del_ike_sa_t
595                                             * mp)
596 {
597   vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
598   int rv = 0;
599
600 #if WITH_LIBSSL > 0
601   vlib_main_t *vm = vlib_get_main ();
602   clib_error_t *error;
603
604   error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
605   if (error)
606     rv = VNET_API_ERROR_UNSPECIFIED;
607 #else
608   rv = VNET_API_ERROR_UNIMPLEMENTED;
609 #endif
610
611   REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
612 }
613
614 static void
615   vl_api_ikev2_initiate_del_child_sa_t_handler
616   (vl_api_ikev2_initiate_del_child_sa_t * mp)
617 {
618   vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
619   int rv = 0;
620
621 #if WITH_LIBSSL > 0
622   vlib_main_t *vm = vlib_get_main ();
623   clib_error_t *error;
624
625   error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
626   if (error)
627     rv = VNET_API_ERROR_UNSPECIFIED;
628 #else
629   rv = VNET_API_ERROR_UNIMPLEMENTED;
630 #endif
631
632   REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
633 }
634
635 static void
636   vl_api_ikev2_initiate_rekey_child_sa_t_handler
637   (vl_api_ikev2_initiate_rekey_child_sa_t * mp)
638 {
639   vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
640   int rv = 0;
641
642 #if WITH_LIBSSL > 0
643   vlib_main_t *vm = vlib_get_main ();
644   clib_error_t *error;
645
646   error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
647   if (error)
648     rv = VNET_API_ERROR_UNSPECIFIED;
649 #else
650   rv = VNET_API_ERROR_UNIMPLEMENTED;
651 #endif
652
653   REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
654 }
655
656 /*
657  * ipsec_api_hookup
658  * Add vpe's API message handlers to the table.
659  * vlib has alread mapped shared memory and
660  * added the client registration handlers.
661  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
662  */
663 #define vl_msg_name_crc_list
664 #include <vnet/vnet_all_api_h.h>
665 #undef vl_msg_name_crc_list
666
667 static void
668 setup_message_id_table (api_main_t * am)
669 {
670 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
671   foreach_vl_msg_name_crc_ipsec;
672 #undef _
673 }
674
675 static clib_error_t *
676 ipsec_api_hookup (vlib_main_t * vm)
677 {
678   api_main_t *am = &api_main;
679
680 #define _(N,n)                                                  \
681     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
682                            vl_api_##n##_t_handler,              \
683                            vl_noop_handler,                     \
684                            vl_api_##n##_t_endian,               \
685                            vl_api_##n##_t_print,                \
686                            sizeof(vl_api_##n##_t), 1);
687   foreach_vpe_api_msg;
688 #undef _
689
690   /*
691    * Set up the (msg_name, crc, message-id) table
692    */
693   setup_message_id_table (am);
694
695   return 0;
696 }
697
698 VLIB_API_INIT_FUNCTION (ipsec_api_hookup);
699
700 /*
701  * fd.io coding-style-patch-verification: ON
702  *
703  * Local Variables:
704  * eval: (c-set-style "gnu")
705  * End:
706  */