FD.io VPP  v20.09-rc2-28-g3c5414029
Vector Packet Processing
ikev2_api.c
Go to the documentation of this file.
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 #include <vnet/api_errno.h>
23 #include <vpp/app/version.h>
24 #include <vnet/ip/ip_types_api.h>
25 #include <ikev2/ikev2.h>
26 #include <ikev2/ikev2_priv.h>
27 
28 /* define message IDs */
29 #include <vnet/format_fns.h>
30 #include <plugins/ikev2/ikev2.api_enum.h>
31 #include <plugins/ikev2/ikev2.api_types.h>
32 
33 
34 #define vl_endianfun /* define message structures */
35 #include <plugins/ikev2/ikev2.api.h>
36 #include <plugins/ikev2/ikev2_types.api.h>
37 #undef vl_endianfun
38 
40 
41 #define IKEV2_PLUGIN_VERSION_MAJOR 1
42 #define IKEV2_PLUGIN_VERSION_MINOR 0
43 #define REPLY_MSG_ID_BASE ikev2_main.msg_id_base
45 
46 static u32
48 {
49  return (ti << 16) | sai;
50 }
51 
52 static void
53 ikev2_decode_sa_index (u32 api_sai, u32 * sai, u32 * ti)
54 {
55  *sai = api_sai & 0xffff;
56  *ti = api_sai >> 16;
57 }
58 
59 static void
60 cp_ike_transforms (vl_api_ikev2_ike_transforms_t * vl_api_ts,
62 {
63  vl_api_ts->crypto_alg = ts->crypto_alg;
64  vl_api_ts->integ_alg = ts->integ_alg;
65  vl_api_ts->dh_group = ts->dh_type;
66  vl_api_ts->crypto_key_size = ts->crypto_key_size;
67 }
68 
69 static void
70 cp_esp_transforms (vl_api_ikev2_esp_transforms_t * vl_api_ts,
72 {
73  vl_api_ts->crypto_alg = ts->crypto_alg;
74  vl_api_ts->integ_alg = ts->integ_alg;
75  vl_api_ts->crypto_key_size = ts->crypto_key_size;
76 }
77 
78 static void
79 cp_id (vl_api_ikev2_id_t * vl_api_id, ikev2_id_t * id)
80 {
81  if (!id->data)
82  return;
83 
84  int size_data = 0;
85  vl_api_id->type = id->type;
86  size_data = sizeof (vl_api_id->data) - 1; // size without zero ending character
87  if (vec_len (id->data) < size_data)
88  size_data = vec_len (id->data);
89 
90  vl_api_id->data_len = size_data;
91  clib_memcpy (vl_api_id->data, id->data, size_data);
92 }
93 
94 static void
95 cp_ts (vl_api_ikev2_ts_t * vl_api_ts, ikev2_ts_t * ts, u8 is_local)
96 {
97  vl_api_ts->is_local = is_local;
98  vl_api_ts->protocol_id = ts->protocol_id;
99  vl_api_ts->start_port = ts->start_port;
100  vl_api_ts->end_port = ts->end_port;
101  ip4_address_encode (&ts->start_addr, vl_api_ts->start_addr);
102  ip4_address_encode (&ts->end_addr, vl_api_ts->end_addr);
103 }
104 
105 static void
106 cp_auth (vl_api_ikev2_auth_t * vl_api_auth, ikev2_auth_t * auth)
107 {
108  vl_api_auth->method = auth->method;
109  vl_api_auth->data_len = vec_len (auth->data);
110  vl_api_auth->hex = auth->hex;
111  clib_memcpy (&vl_api_auth->data, auth->data, vec_len (auth->data));
112 }
113 
114 static void
115 cp_responder (vl_api_ikev2_responder_t * vl_api_responder,
117 {
118  vl_api_responder->sw_if_index = responder->sw_if_index;
119  ip4_address_encode (&responder->ip4, vl_api_responder->ip4);
120 }
121 
122 void
123 cp_sa_transform (vl_api_ikev2_sa_transform_t * vl_tr,
125 {
126  vl_tr->transform_type = tr->type;
127  vl_tr->key_len = tr->key_len;
128  vl_tr->key_trunc = tr->key_trunc;
129  vl_tr->block_size = tr->block_size;
130  vl_tr->dh_group = tr->dh_group;
131  vl_tr->transform_id = tr->encr_type;
132 }
133 
134 static void
136  u32 context)
137 {
139 
140  rmp = vl_msg_api_alloc (sizeof (*rmp) + vec_len (profile->auth.data));
141  clib_memset (rmp, 0, sizeof (*rmp) + vec_len (profile->auth.data));
142  ikev2_main_t *im = &ikev2_main;
143  rmp->_vl_msg_id = ntohs (VL_API_IKEV2_PROFILE_DETAILS + im->msg_id_base);
144  rmp->context = context;
145 
146  int size_data = sizeof (rmp->profile.name) - 1;
147  if (vec_len (profile->name) < size_data)
148  size_data = vec_len (profile->name);
149  clib_memcpy (rmp->profile.name, profile->name, size_data);
150 
151  cp_ike_transforms (&rmp->profile.ike_ts, &profile->ike_ts);
152  cp_esp_transforms (&rmp->profile.esp_ts, &profile->esp_ts);
153 
154  cp_id (&rmp->profile.loc_id, &profile->loc_id);
155  cp_id (&rmp->profile.rem_id, &profile->rem_id);
156 
157  cp_ts (&rmp->profile.rem_ts, &profile->rem_ts, 0 /* is_local */ );
158  cp_ts (&rmp->profile.loc_ts, &profile->loc_ts, 1 /* is_local */ );
159 
160  cp_auth (&rmp->profile.auth, &profile->auth);
161 
162  cp_responder (&rmp->profile.responder, &profile->responder);
163 
164  rmp->profile.udp_encap = profile->udp_encap;
165  rmp->profile.tun_itf = profile->tun_itf;
166 
167  rmp->profile.ipsec_over_udp_port = profile->ipsec_over_udp_port;
168 
169  rmp->profile.lifetime = profile->lifetime;
170  rmp->profile.lifetime_maxdata = profile->lifetime_maxdata;
171  rmp->profile.lifetime_jitter = profile->lifetime_jitter;
172  rmp->profile.handover = profile->handover;
173 
174  vl_api_ikev2_profile_t_endian (&rmp->profile);
175 
176  vl_api_send_msg (reg, (u8 *) rmp);
177 }
178 
179 static void
181 {
182  ikev2_main_t *im = &ikev2_main;
183  ikev2_profile_t *profile;
186  if (!reg)
187  return;
188 
189  /* *INDENT-OFF* */
190  pool_foreach (profile, im->profiles,
191  ({
192  send_profile (profile, reg, mp->context);
193  }));
194  /* *INDENT-ON* */
195 }
196 
197 static void
198 send_sa (ikev2_sa_t * sa, vl_api_ikev2_sa_dump_t * mp, u32 api_sa_index)
199 {
200  vl_api_ikev2_sa_details_t *rmp = 0;
201  int rv = 0;
203 
204  /* *INDENT-OFF* */
205  REPLY_MACRO2_ZERO (VL_API_IKEV2_SA_DETAILS,
206  {
207  vl_api_ikev2_sa_t *rsa = &rmp->sa;
208  vl_api_ikev2_keys_t* k = &rsa->keys;
209  rsa->profile_index = rsa->profile_index;
210  rsa->sa_index = api_sa_index;
211  ip4_address_encode (&sa->iaddr, rsa->iaddr);
212  ip4_address_encode (&sa->raddr, rsa->raddr);
213  rsa->ispi = sa->ispi;
214  rsa->rspi = sa->rspi;
215  cp_id(&rsa->i_id, &sa->i_id);
216  cp_id(&rsa->r_id, &sa->r_id);
217 
218  tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_ENCR);
219  if (tr)
220  cp_sa_transform (&rsa->encryption, tr);
221 
222  tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_PRF);
223  if (tr)
224  cp_sa_transform (&rsa->prf, tr);
225 
227  IKEV2_TRANSFORM_TYPE_INTEG);
228  if (tr)
229  cp_sa_transform (&rsa->integrity, tr);
230 
231  tr = ikev2_sa_get_td_for_type (sa->r_proposals, IKEV2_TRANSFORM_TYPE_DH);
232  if (tr)
233  cp_sa_transform (&rsa->dh, tr);
234 
235  k->sk_d_len = vec_len (sa->sk_d);
236  clib_memcpy (&k->sk_d, sa->sk_d, k->sk_d_len);
237 
238  k->sk_ai_len = vec_len (sa->sk_ai);
239  clib_memcpy (&k->sk_ai, sa->sk_ai, k->sk_ai_len);
240 
241  k->sk_ar_len = vec_len (sa->sk_ar);
242  clib_memcpy (&k->sk_ar, sa->sk_ar, k->sk_ar_len);
243 
244  k->sk_ei_len = vec_len (sa->sk_ei);
245  clib_memcpy (&k->sk_ei, sa->sk_ei, k->sk_ei_len);
246 
247  k->sk_er_len = vec_len (sa->sk_er);
248  clib_memcpy (&k->sk_er, sa->sk_er, k->sk_er_len);
249 
250  k->sk_pi_len = vec_len (sa->sk_pi);
251  clib_memcpy (&k->sk_pi, sa->sk_pi, k->sk_pi_len);
252 
253  k->sk_pr_len = vec_len (sa->sk_pr);
254  clib_memcpy (&k->sk_pr, sa->sk_pr, k->sk_pr_len);
255 
256  vl_api_ikev2_sa_t_endian(rsa);
257  });
258  /* *INDENT-ON* */
259 }
260 
261 static void
263 {
264  ikev2_main_t *km = &ikev2_main;
266  ikev2_sa_t *sa;
267 
268  vec_foreach (tkm, km->per_thread_data)
269  {
270  /* *INDENT-OFF* */
271  pool_foreach (sa, tkm->sas,
272  ({
273  u32 api_sa_index = ikev2_encode_sa_index (sa - tkm->sas,
274  tkm - km->per_thread_data);
275  send_sa (sa, mp, api_sa_index);
276  }));
277  /* *INDENT-ON* */
278  }
279 }
280 
281 
282 static void
285  u32 sa_index)
286 {
288  int rv = 0;
290 
291  /* *INDENT-OFF* */
292  REPLY_MACRO2_ZERO (VL_API_IKEV2_CHILD_SA_DETAILS,
293  {
294  vl_api_ikev2_keys_t *k = &rmp->child_sa.keys;
295  rmp->child_sa.child_sa_index = child_sa_index;
296  rmp->child_sa.sa_index = sa_index;
297  rmp->child_sa.i_spi =
298  child->i_proposals ? child->i_proposals[0].spi : 0;
299  rmp->child_sa.r_spi =
300  child->r_proposals ? child->r_proposals[0].spi : 0;
301 
303  IKEV2_TRANSFORM_TYPE_ENCR);
304  if (tr)
305  cp_sa_transform (&rmp->child_sa.encryption, tr);
306 
308  IKEV2_TRANSFORM_TYPE_INTEG);
309  if (tr)
310  cp_sa_transform (&rmp->child_sa.integrity, tr);
311 
313  IKEV2_TRANSFORM_TYPE_ESN);
314  if (tr)
315  cp_sa_transform (&rmp->child_sa.esn, tr);
316 
317  k->sk_ei_len = vec_len (child->sk_ei);
318  clib_memcpy (&k->sk_ei, child->sk_ei, k->sk_ei_len);
319 
320  k->sk_er_len = vec_len (child->sk_er);
321  clib_memcpy (&k->sk_er, child->sk_er, k->sk_er_len);
322 
323  if (vec_len (child->sk_ai))
324  {
325  k->sk_ai_len = vec_len (child->sk_ai);
326  clib_memcpy (&k->sk_ai, child->sk_ai,
327  k->sk_ai_len);
328 
329  k->sk_ar_len = vec_len (child->sk_ar);
330  clib_memcpy (&k->sk_ar, child->sk_ar,
331  k->sk_ar_len);
332  }
333 
334  vl_api_ikev2_child_sa_t_endian (&rmp->child_sa);
335  });
336  /* *INDENT-ON* */
337 }
338 
339 static void
341 {
342  ikev2_main_t *im = &ikev2_main;
344  ikev2_sa_t *sa;
345  ikev2_child_sa_t *child;
346  u32 sai = ~0, ti = ~0;
347 
348  ikev2_decode_sa_index (clib_net_to_host_u32 (mp->sa_index), &sai, &ti);
349 
350  if (vec_len (im->per_thread_data) <= ti)
351  return;
352 
353  tkm = vec_elt_at_index (im->per_thread_data, ti);
354 
355  if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
356  return;
357 
358  sa = pool_elt_at_index (tkm->sas, sai);
359 
360  vec_foreach (child, sa->childs)
361  {
362  u32 child_sa_index = child - sa->childs;
363  send_child_sa (child, mp, child_sa_index, sai);
364  }
365 }
366 
367 static void
370 {
371  ikev2_main_t *im = &ikev2_main;
373  ikev2_sa_t *sa;
374  ikev2_child_sa_t *child;
375  ikev2_ts_t *ts;
376  u32 sai = ~0, ti = ~0;
377 
378  u32 api_sa_index = clib_net_to_host_u32 (mp->sa_index);
379  u32 child_sa_index = clib_net_to_host_u32 (mp->child_sa_index);
380  ikev2_decode_sa_index (api_sa_index, &sai, &ti);
381 
382  if (vec_len (im->per_thread_data) <= ti)
383  return;
384 
385  tkm = vec_elt_at_index (im->per_thread_data, ti);
386 
387  if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
388  return;
389 
390  sa = pool_elt_at_index (tkm->sas, sai);
391 
392  if (vec_len (sa->childs) <= child_sa_index)
393  return;
394 
395  child = vec_elt_at_index (sa->childs, child_sa_index);
396 
397  vec_foreach (ts, mp->is_initiator ? child->tsi : child->tsr)
398  {
400  int rv = 0;
401 
402  /* *INDENT-OFF* */
403  REPLY_MACRO2_ZERO (VL_API_IKEV2_TRAFFIC_SELECTOR_DETAILS,
404  {
405  rmp->ts.sa_index = api_sa_index;
406  rmp->ts.child_sa_index = child_sa_index;
407  cp_ts (&rmp->ts, ts, mp->is_initiator);
408  vl_api_ikev2_ts_t_endian (&rmp->ts);
409  });
410  /* *INDENT-ON* */
411  }
412 }
413 
414 static void
416 {
417  ikev2_main_t *im = &ikev2_main;
419  ikev2_sa_t *sa;
420  u32 sai = ~0, ti = ~0;
421 
422  ikev2_decode_sa_index (clib_net_to_host_u32 (mp->sa_index), &sai, &ti);
423 
424  if (vec_len (im->per_thread_data) <= ti)
425  return;
426 
427  tkm = vec_elt_at_index (im->per_thread_data, ti);
428 
429  if (pool_len (tkm->sas) <= sai || pool_is_free_index (tkm->sas, sai))
430  return;
431 
432  sa = pool_elt_at_index (tkm->sas, sai);
433 
434  u8 *nonce = mp->is_initiator ? sa->i_nonce : sa->r_nonce;
436  int data_len = vec_len (nonce);
437  int rv = 0;
438 
439  /* *INDENT-OFF* */
440  REPLY_MACRO3_ZERO (VL_API_IKEV2_NONCE_GET_REPLY, data_len,
441  {
442  rmp->data_len = clib_host_to_net_u32 (data_len);
443  clib_memcpy (rmp->nonce, nonce, data_len);
444  });
445  /* *INDENT-ON* */
446 }
447 
448 static void
450  mp)
451 {
452  ikev2_main_t *im = &ikev2_main;
454  int msg_size = sizeof (*rmp);
456 
458  if (!reg)
459  return;
460 
461  rmp = vl_msg_api_alloc (msg_size);
462  clib_memset (rmp, 0, msg_size);
463  rmp->_vl_msg_id =
464  ntohs (VL_API_IKEV2_PLUGIN_GET_VERSION_REPLY + im->msg_id_base);
465  rmp->context = mp->context;
466  rmp->major = htonl (IKEV2_PLUGIN_VERSION_MAJOR);
467  rmp->minor = htonl (IKEV2_PLUGIN_VERSION_MINOR);
468 
469  vl_api_send_msg (reg, (u8 *) rmp);
470 }
471 
472 static void
475 {
476  vl_api_ikev2_profile_set_liveness_reply_t *rmp;
477  int rv = 0;
478 
479 #if WITH_LIBSSL > 0
480  clib_error_t *error;
481  error = ikev2_set_liveness_params (clib_net_to_host_u32 (mp->period),
482  clib_net_to_host_u32 (mp->max_retries));
483  if (error)
484  rv = VNET_API_ERROR_UNSPECIFIED;
485 #else
486  rv = VNET_API_ERROR_UNIMPLEMENTED;
487 #endif
488 
489  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_LIVENESS_REPLY);
490 }
491 
492 static void
494 {
495  vl_api_ikev2_profile_add_del_reply_t *rmp;
496  int rv = 0;
497 
498 #if WITH_LIBSSL > 0
500  clib_error_t *error;
501  u8 *tmp = format (0, "%s", mp->name);
502  error = ikev2_add_del_profile (vm, tmp, mp->is_add);
503  vec_free (tmp);
504  if (error)
505  rv = VNET_API_ERROR_UNSPECIFIED;
506 #else
507  rv = VNET_API_ERROR_UNIMPLEMENTED;
508 #endif
509 
510  REPLY_MACRO (VL_API_IKEV2_PROFILE_ADD_DEL_REPLY);
511 }
512 
513 static void
516 {
517  vl_api_ikev2_profile_set_auth_reply_t *rmp;
518  int rv = 0;
519 
520 #if WITH_LIBSSL > 0
522  clib_error_t *error;
523  int data_len = ntohl (mp->data_len);
524  u8 *tmp = format (0, "%s", mp->name);
525  u8 *data = vec_new (u8, data_len);
526  clib_memcpy (data, mp->data, data_len);
527  error = ikev2_set_profile_auth (vm, tmp, mp->auth_method, data, mp->is_hex);
528  vec_free (tmp);
529  vec_free (data);
530  if (error)
531  rv = VNET_API_ERROR_UNSPECIFIED;
532 #else
533  rv = VNET_API_ERROR_UNIMPLEMENTED;
534 #endif
535 
536  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_AUTH_REPLY);
537 }
538 
539 static void
541 {
542  vl_api_ikev2_profile_set_id_reply_t *rmp;
543  int rv = 0;
544 
545 #if WITH_LIBSSL > 0
547  clib_error_t *error;
548  u8 *tmp = format (0, "%s", mp->name);
549  int data_len = ntohl (mp->data_len);
550  u8 *data = vec_new (u8, data_len);
551  clib_memcpy (data, mp->data, data_len);
552  error = ikev2_set_profile_id (vm, tmp, mp->id_type, data, mp->is_local);
553  vec_free (tmp);
554  vec_free (data);
555  if (error)
556  rv = VNET_API_ERROR_UNSPECIFIED;
557 #else
558  rv = VNET_API_ERROR_UNIMPLEMENTED;
559 #endif
560 
561  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_ID_REPLY);
562 }
563 
564 static void
567 {
568  vl_api_ikev2_profile_set_udp_encap_reply_t *rmp;
569  int rv = 0;
570 
571 #if WITH_LIBSSL > 0
573  clib_error_t *error;
574  u8 *tmp = format (0, "%s", mp->name);
575  error = ikev2_set_profile_udp_encap (vm, tmp);
576  vec_free (tmp);
577  if (error)
578  rv = VNET_API_ERROR_UNSPECIFIED;
579 #else
580  rv = VNET_API_ERROR_UNIMPLEMENTED;
581 #endif
582 
583  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_UDP_ENCAP_REPLY);
584 }
585 
586 static void
588 {
589  vl_api_ikev2_profile_set_ts_reply_t *rmp;
590  int rv = 0;
591 
592 #if WITH_LIBSSL > 0
594  clib_error_t *error;
595  u8 *tmp = format (0, "%s", mp->name);
597  ip4_address_decode (mp->ts.start_addr, &start_addr);
598  ip4_address_decode (mp->ts.end_addr, &end_addr);
599  error =
600  ikev2_set_profile_ts (vm, tmp, mp->ts.protocol_id,
601  clib_net_to_host_u16 (mp->ts.start_port),
602  clib_net_to_host_u16 (mp->ts.end_port),
603  start_addr, end_addr, mp->ts.is_local);
604  vec_free (tmp);
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_PROFILE_SET_TS_REPLY);
612 }
613 
614 static void
616 {
617  vl_api_ikev2_set_local_key_reply_t *rmp;
618  int rv = 0;
619 
620 #if WITH_LIBSSL > 0
622  clib_error_t *error;
623 
624  error = ikev2_set_local_key (vm, mp->key_file);
625  if (error)
626  rv = VNET_API_ERROR_UNSPECIFIED;
627 #else
628  rv = VNET_API_ERROR_UNIMPLEMENTED;
629 #endif
630 
631  REPLY_MACRO (VL_API_IKEV2_SET_LOCAL_KEY_REPLY);
632 }
633 
634 static void
636 {
637  vl_api_ikev2_set_responder_reply_t *rmp;
638  int rv = 0;
639 
640 #if WITH_LIBSSL > 0
642  clib_error_t *error;
643 
644  u8 *tmp = format (0, "%s", mp->name);
646  ip4_address_decode (mp->responder.ip4, &ip4);
647  u32 sw_if_index = clib_net_to_host_u32 (mp->responder.sw_if_index);
648 
649  error = ikev2_set_profile_responder (vm, tmp, sw_if_index, ip4);
650  vec_free (tmp);
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_SET_RESPONDER_REPLY);
658 }
659 
660 static void
662  mp)
663 {
664  vl_api_ikev2_set_ike_transforms_reply_t *rmp;
665  int rv = 0;
666 
667 #if WITH_LIBSSL > 0
669  clib_error_t *error;
670 
671  u8 *tmp = format (0, "%s", mp->name);
672 
673  error =
674  ikev2_set_profile_ike_transforms (vm, tmp, mp->tr.crypto_alg,
675  mp->tr.integ_alg,
676  mp->tr.dh_group,
677  ntohl (mp->tr.crypto_key_size));
678  vec_free (tmp);
679  if (error)
680  rv = VNET_API_ERROR_UNSPECIFIED;
681 #else
682  rv = VNET_API_ERROR_UNIMPLEMENTED;
683 #endif
684 
685  REPLY_MACRO (VL_API_IKEV2_SET_IKE_TRANSFORMS_REPLY);
686 }
687 
688 static void
690  mp)
691 {
692  vl_api_ikev2_set_esp_transforms_reply_t *rmp;
693  int rv = 0;
694 
695 #if WITH_LIBSSL > 0
697  clib_error_t *error;
698 
699  u8 *tmp = format (0, "%s", mp->name);
700 
701  error =
702  ikev2_set_profile_esp_transforms (vm, tmp, mp->tr.crypto_alg,
703  mp->tr.integ_alg,
704  ntohl (mp->tr.crypto_key_size));
705  vec_free (tmp);
706  if (error)
707  rv = VNET_API_ERROR_UNSPECIFIED;
708 #else
709  rv = VNET_API_ERROR_UNIMPLEMENTED;
710 #endif
711 
712  REPLY_MACRO (VL_API_IKEV2_SET_ESP_TRANSFORMS_REPLY);
713 }
714 
715 static void
717 {
718  vl_api_ikev2_set_sa_lifetime_reply_t *rmp;
719  int rv = 0;
720 
721 #if WITH_LIBSSL > 0
723  clib_error_t *error;
724 
725  u8 *tmp = format (0, "%s", mp->name);
726 
727  error =
729  clib_net_to_host_u64 (mp->lifetime),
730  ntohl (mp->lifetime_jitter),
731  ntohl (mp->handover),
732  clib_net_to_host_u64
733  (mp->lifetime_maxdata));
734  vec_free (tmp);
735  if (error)
736  rv = VNET_API_ERROR_UNSPECIFIED;
737 #else
738  rv = VNET_API_ERROR_UNIMPLEMENTED;
739 #endif
740 
741  REPLY_MACRO (VL_API_IKEV2_SET_SA_LIFETIME_REPLY);
742 }
743 
744 static void
747 {
748  vl_api_ikev2_profile_set_ipsec_udp_port_reply_t *rmp;
749  int rv = 0;
750 
751 #if WITH_LIBSSL > 0
753 
754  u8 *tmp = format (0, "%s", mp->name);
755 
756  rv =
758  clib_net_to_host_u16 (mp->port),
759  mp->is_set);
760  vec_free (tmp);
761 #else
762  rv = VNET_API_ERROR_UNIMPLEMENTED;
763 #endif
764 
765  REPLY_MACRO (VL_API_IKEV2_PROFILE_SET_IPSEC_UDP_PORT_REPLY);
766 }
767 
768 static void
771 {
772  vl_api_ikev2_set_tunnel_interface_reply_t *rmp;
773  int rv = 0;
774 
776 
777 #if WITH_LIBSSL > 0
778  u8 *tmp = format (0, "%s", mp->name);
779  clib_error_t *error;
780 
782  ntohl (mp->sw_if_index));
783 
784  if (error)
785  rv = VNET_API_ERROR_UNSPECIFIED;
786  vec_free (tmp);
787 #else
788  rv = VNET_API_ERROR_UNIMPLEMENTED;
789 #endif
790 
792  REPLY_MACRO (VL_API_IKEV2_SET_TUNNEL_INTERFACE_REPLY);
793 }
794 
795 static void
797 {
798  vl_api_ikev2_initiate_sa_init_reply_t *rmp;
799  int rv = 0;
800 
801 #if WITH_LIBSSL > 0
803  clib_error_t *error;
804 
805  u8 *tmp = format (0, "%s", mp->name);
806 
807  error = ikev2_initiate_sa_init (vm, tmp);
808  vec_free (tmp);
809  if (error)
810  rv = VNET_API_ERROR_UNSPECIFIED;
811 #else
812  rv = VNET_API_ERROR_UNIMPLEMENTED;
813 #endif
814 
815  REPLY_MACRO (VL_API_IKEV2_INITIATE_SA_INIT_REPLY);
816 }
817 
818 static void
820  * mp)
821 {
822  vl_api_ikev2_initiate_del_ike_sa_reply_t *rmp;
823  int rv = 0;
824 
825 #if WITH_LIBSSL > 0
827  clib_error_t *error;
828 
829  error = ikev2_initiate_delete_ike_sa (vm, mp->ispi);
830  if (error)
831  rv = VNET_API_ERROR_UNSPECIFIED;
832 #else
833  rv = VNET_API_ERROR_UNIMPLEMENTED;
834 #endif
835 
836  REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_IKE_SA_REPLY);
837 }
838 
839 static void
842 {
843  vl_api_ikev2_initiate_del_child_sa_reply_t *rmp;
844  int rv = 0;
845 
846 #if WITH_LIBSSL > 0
848  clib_error_t *error;
849 
850  error = ikev2_initiate_delete_child_sa (vm, mp->ispi);
851  if (error)
852  rv = VNET_API_ERROR_UNSPECIFIED;
853 #else
854  rv = VNET_API_ERROR_UNIMPLEMENTED;
855 #endif
856 
857  REPLY_MACRO (VL_API_IKEV2_INITIATE_DEL_CHILD_SA_REPLY);
858 }
859 
860 static void
863 {
864  vl_api_ikev2_initiate_rekey_child_sa_reply_t *rmp;
865  int rv = 0;
866 
867 #if WITH_LIBSSL > 0
869  clib_error_t *error;
870 
871  error = ikev2_initiate_rekey_child_sa (vm, mp->ispi);
872  if (error)
873  rv = VNET_API_ERROR_UNSPECIFIED;
874 #else
875  rv = VNET_API_ERROR_UNIMPLEMENTED;
876 #endif
877 
878  REPLY_MACRO (VL_API_IKEV2_INITIATE_REKEY_CHILD_SA_REPLY);
879 }
880 
881 #include <ikev2/ikev2.api.c>
882 static clib_error_t *
884 {
885  ikev2_main_t *im = &ikev2_main;
886 
887  /* Ask for a correctly-sized block of API message decode slots */
889 
890  return 0;
891 }
892 
894 
895 /*
896  * fd.io coding-style-patch-verification: ON
897  *
898  * Local Variables:
899  * eval: (c-set-style "gnu")
900  * End:
901  */
ikev2_main_per_thread_data_t * per_thread_data
Definition: ikev2_priv.h:489
vl_api_ikev2_sa_t sa
Definition: ikev2.api:89
ikev2_transform_type_t type
Definition: ikev2_priv.h:229
clib_error_t * ikev2_set_profile_responder(vlib_main_t *vm, u8 *name, u32 sw_if_index, ip4_address_t ip4)
Definition: ikev2.c:3520
ikev2_id_t r_id
Definition: ikev2_priv.h:404
details on specific traffic selector
Definition: ikev2.api:182
ikev2_transforms_set ike_ts
Definition: ikev2_priv.h:354
static void vl_api_ikev2_profile_set_ipsec_udp_port_t_handler(vl_api_ikev2_profile_set_ipsec_udp_port_t *mp)
Definition: ikev2_api.c:746
static void vl_api_ikev2_initiate_rekey_child_sa_t_handler(vl_api_ikev2_initiate_rekey_child_sa_t *mp)
Definition: ikev2_api.c:862
IKEv2: Set Child SA lifetime, limited by time and/or data.
Definition: ikev2.api:363
vl_api_ikev2_ike_transforms_t tr
Definition: ikev2.api:332
#define ntohs(x)
Definition: af_xdp.bpf.c:29
static void vl_api_ikev2_nonce_get_t_handler(vl_api_ikev2_nonce_get_t *mp)
Definition: ikev2_api.c:415
clib_error_t * ikev2_add_del_profile(vlib_main_t *vm, u8 *name, int is_add)
Definition: ikev2.c:3372
clib_error_t * ikev2_set_profile_udp_encap(vlib_main_t *vm, u8 *name)
Definition: ikev2.c:3642
static void cp_responder(vl_api_ikev2_responder_t *vl_api_responder, ikev2_responder_t *responder)
Definition: ikev2_api.c:115
IKEv2: Add/delete profile.
Definition: ikev2.api:197
ikev2_transform_dh_type_t dh_type
Definition: ikev2_priv.h:280
vl_api_ikev2_ts_t ts
Definition: ikev2.api:266
vl_api_ikev2_auth_t auth
Definition: ikev2_types.api:87
ikev2_profile_t * profiles
Definition: ikev2_priv.h:469
clib_error_t * ikev2_initiate_delete_ike_sa(vlib_main_t *vm, u64 ispi)
Definition: ikev2.c:3921
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
ikev2_transform_encr_type_t crypto_alg
Definition: ikev2_priv.h:278
clib_error_t * ikev2_set_profile_tunnel_interface(vlib_main_t *vm, u8 *name, u32 sw_if_index)
Definition: ikev2.c:3589
u8 * sk_pi
Definition: ikev2_priv.h:395
IKEv2: Set liveness parameters.
Definition: ikev2.api:475
ip4_address_t ip4
Definition: ikev2_priv.h:273
vlib_main_t * vm
Definition: in2out_ed.c:1582
clib_error_t * ikev2_set_profile_sa_lifetime(vlib_main_t *vm, u8 *name, u64 lifetime, u32 jitter, u32 handover, u64 maxdata)
Definition: ikev2.c:3658
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void vl_api_ikev2_initiate_sa_init_t_handler(vl_api_ikev2_initiate_sa_init_t *mp)
Definition: ikev2_api.c:796
clib_error_t * ikev2_set_liveness_params(u32 period, u32 max_retries)
Definition: ikev2.c:4207
#define REPLY_MACRO2_ZERO(t, body)
static u32 ikev2_encode_sa_index(u32 sai, u32 ti)
Definition: ikev2_api.c:47
static void ikev2_decode_sa_index(u32 api_sai, u32 *sai, u32 *ti)
Definition: ikev2_api.c:53
static void vl_api_ikev2_set_sa_lifetime_t_handler(vl_api_ikev2_set_sa_lifetime_t *mp)
Definition: ikev2_api.c:716
void * vl_msg_api_alloc(int nbytes)
u16 ipsec_over_udp_port
Definition: ikev2_priv.h:360
static void vl_api_ikev2_initiate_del_ike_sa_t_handler(vl_api_ikev2_initiate_del_ike_sa_t *mp)
Definition: ikev2_api.c:819
unsigned char u8
Definition: types.h:56
vnet_api_error_t ikev2_set_profile_ipsec_udp_port(vlib_main_t *vm, u8 *name, u16 port, u8 is_set)
Definition: ikev2.c:3609
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
u8 data[128]
Definition: ipsec_types.api:89
ikev2_sa_transform_t * ikev2_sa_get_td_for_type(ikev2_sa_proposal_t *p, ikev2_transform_type_t type)
Definition: ikev2.c:214
ikev2_auth_t auth
Definition: ikev2_priv.h:348
dump traffic selectors
Definition: ikev2.api:164
#define clib_memcpy(d, s, n)
Definition: string.h:180
ikev2_id_t rem_id
Definition: ikev2_priv.h:350
IKEv2: Set IKEv2 IKE transforms in SA_INIT proposal (RFC 7296)
Definition: ikev2.api:326
static void vl_api_ikev2_child_sa_dump_t_handler(vl_api_ikev2_child_sa_dump_t *mp)
Definition: ikev2_api.c:340
static void vl_api_ikev2_profile_dump_t_handler(vl_api_ikev2_profile_dump_t *mp)
Definition: ikev2_api.c:180
static void vl_api_ikev2_plugin_get_version_t_handler(vl_api_ikev2_plugin_get_version_t *mp)
Definition: ikev2_api.c:449
static void vl_api_ikev2_set_local_key_t_handler(vl_api_ikev2_set_local_key_t *mp)
Definition: ikev2_api.c:615
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:295
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
clib_error_t * ikev2_initiate_sa_init(vlib_main_t *vm, u8 *name)
Definition: ikev2.c:3681
static void send_sa(ikev2_sa_t *sa, vl_api_ikev2_sa_dump_t *mp, u32 api_sa_index)
Definition: ikev2_api.c:198
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:350
clib_error_t * ikev2_set_profile_auth(vlib_main_t *vm, u8 *name, u8 auth_method, u8 *auth_data, u8 data_hex_format)
Definition: ikev2.c:3408
static void vl_api_ikev2_set_tunnel_interface_t_handler(vl_api_ikev2_set_tunnel_interface_t *mp)
Definition: ikev2_api.c:770
ip4_address_t start_addr
Definition: ikev2_priv.h:266
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void cp_id(vl_api_ikev2_id_t *vl_api_id, ikev2_id_t *id)
Definition: ikev2_api.c:79
IKEv2: Initiate the delete Child SA exchange.
Definition: ikev2.api:412
ikev2_transform_integ_type_t integ_alg
Definition: ikev2_priv.h:279
unsigned int u32
Definition: types.h:88
IKEv2: Set IKEv2 profile local/remote identification.
Definition: ikev2.api:240
static void vl_api_ikev2_profile_set_ts_t_handler(vl_api_ikev2_profile_set_ts_t *mp)
Definition: ikev2_api.c:587
IKEv2: Set IKEv2 profile traffic selector parameters.
Definition: ikev2.api:260
static void cp_esp_transforms(vl_api_ikev2_esp_transforms_t *vl_api_ts, ikev2_transforms_set *ts)
Definition: ikev2_api.c:70
clib_error_t * ikev2_set_profile_esp_transforms(vlib_main_t *vm, u8 *name, ikev2_transform_encr_type_t crypto_alg, ikev2_transform_integ_type_t integ_alg, u32 crypto_key_size)
Definition: ikev2.c:3566
ikev2_id_t loc_id
Definition: ikev2_priv.h:349
u8 * sk_ar
Definition: ikev2_priv.h:392
static void vl_api_ikev2_set_ike_transforms_t_handler(vl_api_ikev2_set_ike_transforms_t *mp)
Definition: ikev2_api.c:661
ikev2_responder_t responder
Definition: ikev2_priv.h:353
static void cp_ike_transforms(vl_api_ikev2_ike_transforms_t *vl_api_ts, ikev2_transforms_set *ts)
Definition: ikev2_api.c:60
clib_error_t * ikev2_set_profile_id(vlib_main_t *vm, u8 *name, u8 id_type, u8 *data, int is_local)
Definition: ikev2.c:3442
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
vl_api_ikev2_esp_transforms_t tr
Definition: ikev2.api:349
IKEv2: Initiate the rekey Child SA exchange.
Definition: ikev2.api:427
ikev2_ts_t rem_ts
Definition: ikev2_priv.h:352
static void vl_api_ikev2_traffic_selector_dump_t_handler(vl_api_ikev2_traffic_selector_dump_t *mp)
Definition: ikev2_api.c:369
Dump all profiles.
Definition: ikev2.api:49
ikev2_sa_proposal_t * i_proposals
Definition: ikev2_priv.h:294
u8 data_len
Definition: ikev2_types.api:24
u8 * r_nonce
Definition: ikev2_priv.h:376
u16 end_port
Definition: ikev2_priv.h:265
clib_error_t * ikev2_initiate_delete_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:3881
vl_api_ikev2_profile_t profile
Definition: ikev2.api:63
#define REPLY_MACRO(t)
vl_api_ip4_address_t ip4
Definition: one.api:376
vl_api_interface_index_t sw_if_index
Definition: ikev2.api:299
ip4_address_t end_addr
Definition: ikev2_priv.h:267
ip4_address_t iaddr
Definition: ikev2_priv.h:371
static void vl_api_ikev2_set_responder_t_handler(vl_api_ikev2_set_responder_t *mp)
Definition: ikev2_api.c:635
u8 * i_nonce
Definition: ikev2_priv.h:375
clib_error_t * ikev2_set_local_key(vlib_main_t *vm, u8 *file)
Definition: ikev2.c:3204
clib_error_t * ikev2_set_profile_ts(vlib_main_t *vm, u8 *name, u8 protocol_id, u16 start_port, u16 end_port, ip4_address_t start_addr, ip4_address_t end_addr, int is_local)
Definition: ikev2.c:3481
Dump child SA of specific SA.
Definition: ikev2.api:98
u8 * sk_ei
Definition: ikev2_priv.h:393
bool is_local
Definition: ikev2_types.api:33
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
#define BAD_SW_IF_INDEX_LABEL
clib_error_t * ikev2_initiate_rekey_child_sa(vlib_main_t *vm, u32 ispi)
Definition: ikev2.c:3998
u32 child_sa_index
Definition: ikev2_types.api:31
ikev2_auth_method_t method
Definition: ikev2_priv.h:215
static void vl_api_ikev2_initiate_del_child_sa_t_handler(vl_api_ikev2_initiate_del_child_sa_t *mp)
Definition: ikev2_api.c:841
ikev2_ts_t * tsi
Definition: ikev2_priv.h:298
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static void cp_auth(vl_api_ikev2_auth_t *vl_api_auth, ikev2_auth_t *auth)
Definition: ikev2_api.c:106
ip4_address_t raddr
Definition: ikev2_priv.h:372
u8 * sk_er
Definition: ikev2_priv.h:394
vl_api_ikev2_responder_t responder
Definition: ikev2_types.api:77
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:299
IKEv2: Initiate the SA_INIT exchange.
Definition: ikev2.api:382
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
static void vl_api_ikev2_profile_set_liveness_t_handler(vl_api_ikev2_profile_set_liveness_t *mp)
Definition: ikev2_api.c:474
get specific nonce
Definition: ikev2.api:128
ikev2_ts_t loc_ts
Definition: ikev2_priv.h:351
ikev2_sa_proposal_t * r_proposals
Definition: ikev2_priv.h:387
u8 protocol_id
Definition: ikev2_priv.h:262
IKEv2: Set/unset custom ipsec-over-udp port.
Definition: ikev2.api:458
IKEv2: Set IKEv2 responder interface and IP address.
Definition: ikev2.api:309
IKEv2: Initiate the delete IKE SA exchange.
Definition: ikev2.api:397
vl_api_ikev2_responder_t responder
Definition: ikev2.api:315
Details about IKE SA.
Definition: ikev2.api:84
IKEv2: Set IKEv2 profile authentication method.
Definition: ikev2.api:217
u8 * sk_ai
Definition: ikev2_priv.h:391
Child SA details.
Definition: ikev2.api:113
static void vl_api_ikev2_profile_set_auth_t_handler(vl_api_ikev2_profile_set_auth_t *mp)
Definition: ikev2_api.c:515
Details about all profiles.
Definition: ikev2.api:60
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
ikev2_main_t ikev2_main
Definition: ikev2.c:36
Dump all SAs.
Definition: ikev2.api:71
#define IKEV2_PLUGIN_VERSION_MINOR
Definition: ikev2_api.c:42
ikev2_transform_encr_type_t encr_type
Definition: ikev2_priv.h:233
static void vl_api_ikev2_sa_dump_t_handler(vl_api_ikev2_sa_dump_t *mp)
Definition: ikev2_api.c:262
#define IKEV2_PLUGIN_VERSION_MAJOR
Definition: ikev2_api.c:41
vl_api_ip4_address_t start_addr
Definition: ikev2_types.api:37
IKEv2: Set IKEv2 local RSA private key.
Definition: ikev2.api:276
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u16 start_port
Definition: ikev2_priv.h:264
void cp_sa_transform(vl_api_ikev2_sa_transform_t *vl_tr, ikev2_sa_transform_t *tr)
Definition: ikev2_api.c:123
u8 * sk_pr
Definition: ikev2_priv.h:396
static void vl_api_ikev2_profile_set_id_t_handler(vl_api_ikev2_profile_set_id_t *mp)
Definition: ikev2_api.c:540
void ip4_address_decode(const vl_api_ip4_address_t in, ip4_address_t *out)
Definition: ip_types_api.c:129
clib_error_t * ikev2_set_profile_ike_transforms(vlib_main_t *vm, u8 *name, ikev2_transform_encr_type_t crypto_alg, ikev2_transform_integ_type_t integ_alg, ikev2_transform_dh_type_t dh_type, u32 crypto_key_size)
Definition: ikev2.c:3541
ikev2_id_t i_id
Definition: ikev2_priv.h:403
Get the plugin version.
Definition: ikev2.api:27
static void vl_api_ikev2_profile_set_udp_encap_t_handler(vl_api_ikev2_profile_set_udp_encap_t *mp)
Definition: ikev2_api.c:566
ikev2_ts_t * tsr
Definition: ikev2_priv.h:299
ikev2_child_sa_t * childs
Definition: ikev2_priv.h:434
IKEv2: Set IKEv2 ESP transforms in SA_INIT proposal (RFC 7296)
Definition: ikev2.api:343
static void send_profile(ikev2_profile_t *profile, vl_api_registration_t *reg, u32 context)
Definition: ikev2_api.c:135
static void vl_api_ikev2_set_esp_transforms_t_handler(vl_api_ikev2_set_esp_transforms_t *mp)
Definition: ikev2_api.c:689
vl_api_ip4_address_t end_addr
Definition: ikev2_types.api:38
void ip4_address_encode(const ip4_address_t *in, vl_api_ip4_address_t out)
Definition: ip_types_api.c:123
#define vec_foreach(var, vec)
Vector iterator.
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:2804
static void cp_ts(vl_api_ikev2_ts_t *vl_api_ts, ikev2_ts_t *ts, u8 is_local)
Definition: ikev2_api.c:95
static void vl_api_ikev2_profile_add_del_t_handler(vl_api_ikev2_profile_add_del_t *mp)
Definition: ikev2_api.c:493
Reply to get the plugin version.
Definition: ikev2.api:38
static void send_child_sa(ikev2_child_sa_t *child, vl_api_ikev2_child_sa_dump_t *mp, u32 child_sa_index, u32 sa_index)
Definition: ikev2_api.c:283
IKEv2: Set UDP encapsulation.
Definition: ikev2.api:442
ikev2_transforms_set esp_ts
Definition: ikev2_priv.h:355
#define REPLY_MACRO3_ZERO(t, n, body)
vl_api_ikev2_child_sa_t child_sa
Definition: ikev2.api:118
IKEv2: Set the tunnel interface which will be protected by IKE If this API is not called...
Definition: ikev2.api:293
static clib_error_t * ikev2_api_init(vlib_main_t *vm)
Definition: ikev2_api.c:883
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
reply on specific nonce
Definition: ikev2.api:146
#define VALIDATE_SW_IF_INDEX(mp)