FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ipsec.c
Go to the documentation of this file.
1 /*
2  * ipsec.c : IPSEC module functions
3  *
4  * Copyright (c) 2015 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/interface.h>
22 #include <vnet/udp/udp_local.h>
23 
24 #include <vnet/ipsec/ipsec.h>
25 #include <vnet/ipsec/esp.h>
26 #include <vnet/ipsec/ah.h>
27 #include <vnet/ipsec/ipsec_tun.h>
28 
32 
33 static clib_error_t *
35 {
37 
38  if (sa->integ_alg == IPSEC_INTEG_ALG_NONE)
39  return clib_error_return (0, "unsupported none integ-alg");
40 
41  if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
42  return clib_error_return (0, "No crypto engine support for %U",
44 
45  return 0;
46 }
47 
48 static clib_error_t *
50 {
52 
53  if (IPSEC_INTEG_ALG_NONE != sa->integ_alg)
54  {
55  if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
56  return clib_error_return (0, "No crypto engine support for %U",
58  }
59  if (IPSEC_CRYPTO_ALG_NONE != sa->crypto_alg)
60  {
61  if (!vnet_crypto_is_set_handler (im->crypto_algs[sa->crypto_alg].alg))
62  return clib_error_return (0, "No crypto engine support for %U",
64  }
65 
66  return (0);
67 }
68 
71 {
72  ipsec_ah_backend_t *ah =
73  pool_elt_at_index (im->ah_backends, im->ah_current_backend);
74  if (ah->add_del_sa_sess_cb)
75  {
76  clib_error_t *err = ah->add_del_sa_sess_cb (sa_index, is_add);
77  if (err)
78  return err;
79  }
80  ipsec_esp_backend_t *esp =
81  pool_elt_at_index (im->esp_backends, im->esp_current_backend);
82  if (esp->add_del_sa_sess_cb)
83  {
84  clib_error_t *err = esp->add_del_sa_sess_cb (sa_index, is_add);
85  if (err)
86  return err;
87  }
88  return 0;
89 }
90 
93 {
94  clib_error_t *error = 0;
95 
97  {
98  ipsec_ah_backend_t *ah =
99  pool_elt_at_index (im->ah_backends, im->ah_current_backend);
100  ASSERT (ah->check_support_cb);
101  error = ah->check_support_cb (sa);
102  }
103  else
104  {
105  ipsec_esp_backend_t *esp =
106  pool_elt_at_index (im->esp_backends, im->esp_current_backend);
107  ASSERT (esp->check_support_cb);
108  error = esp->check_support_cb (sa);
109  }
110  return error;
111 }
112 
113 
114 static void
115 ipsec_add_node (vlib_main_t * vm, const char *node_name,
116  const char *prev_node_name, u32 * out_node_index,
117  u32 * out_next_index)
118 {
119  vlib_node_t *prev_node, *node;
120  prev_node = vlib_get_node_by_name (vm, (u8 *) prev_node_name);
121  ASSERT (prev_node);
122  node = vlib_get_node_by_name (vm, (u8 *) node_name);
123  ASSERT (node);
124  *out_node_index = node->index;
125  *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index);
126 }
127 
128 void
130 {
132  u32 n_regs;
133  uword *p;
134 
135  p = hash_get (im->udp_port_registrations, port);
136 
137  ASSERT (p);
138 
139  n_regs = p[0];
140 
141  if (0 == --n_regs)
142  {
144  hash_unset (im->udp_port_registrations, port);
145  }
146  else
147  {
148  hash_unset (im->udp_port_registrations, port);
149  hash_set (im->udp_port_registrations, port, n_regs);
150  }
151 }
152 
153 void
155 {
157  u32 n_regs;
158  uword *p;
159 
160  p = hash_get (im->udp_port_registrations, port);
161 
162  n_regs = (p ? p[0] : 0);
163 
164  if (0 == n_regs++)
166  ipsec4_tun_input_node.index, 1);
167 
168  hash_unset (im->udp_port_registrations, port);
169  hash_set (im->udp_port_registrations, port, n_regs);
170 }
171 
172 u32
174  const char *name,
175  const char *ah4_encrypt_node_name,
176  const char *ah4_decrypt_node_name,
177  const char *ah6_encrypt_node_name,
178  const char *ah6_decrypt_node_name,
179  check_support_cb_t ah_check_support_cb,
180  add_del_sa_sess_cb_t ah_add_del_sa_sess_cb)
181 {
183  pool_get (im->ah_backends, b);
184  b->name = format (0, "%s%c", name, 0);
185 
186  ipsec_add_node (vm, ah4_encrypt_node_name, "ipsec4-output-feature",
187  &b->ah4_encrypt_node_index, &b->ah4_encrypt_next_index);
188  ipsec_add_node (vm, ah4_decrypt_node_name, "ipsec4-input-feature",
189  &b->ah4_decrypt_node_index, &b->ah4_decrypt_next_index);
190  ipsec_add_node (vm, ah6_encrypt_node_name, "ipsec6-output-feature",
191  &b->ah6_encrypt_node_index, &b->ah6_encrypt_next_index);
192  ipsec_add_node (vm, ah6_decrypt_node_name, "ipsec6-input-feature",
193  &b->ah6_decrypt_node_index, &b->ah6_decrypt_next_index);
194 
195  b->check_support_cb = ah_check_support_cb;
196  b->add_del_sa_sess_cb = ah_add_del_sa_sess_cb;
197  return b - im->ah_backends;
198 }
199 
200 u32
202  vlib_main_t *vm, ipsec_main_t *im, const char *name,
203  const char *esp4_encrypt_node_name, const char *esp4_encrypt_node_tun_name,
204  const char *esp4_decrypt_node_name, const char *esp4_decrypt_tun_node_name,
205  const char *esp6_encrypt_node_name, const char *esp6_encrypt_node_tun_name,
206  const char *esp6_decrypt_node_name, const char *esp6_decrypt_tun_node_name,
207  const char *esp_mpls_encrypt_node_tun_name,
208  check_support_cb_t esp_check_support_cb,
209  add_del_sa_sess_cb_t esp_add_del_sa_sess_cb,
210  enable_disable_cb_t enable_disable_cb)
211 {
213 
214  pool_get (im->esp_backends, b);
215  b->name = format (0, "%s%c", name, 0);
216 
217  ipsec_add_node (vm, esp4_encrypt_node_name, "ipsec4-output-feature",
218  &b->esp4_encrypt_node_index, &b->esp4_encrypt_next_index);
219  ipsec_add_node (vm, esp4_decrypt_node_name, "ipsec4-input-feature",
220  &b->esp4_decrypt_node_index, &b->esp4_decrypt_next_index);
221  ipsec_add_node (vm, esp6_encrypt_node_name, "ipsec6-output-feature",
222  &b->esp6_encrypt_node_index, &b->esp6_encrypt_next_index);
223  ipsec_add_node (vm, esp6_decrypt_node_name, "ipsec6-input-feature",
224  &b->esp6_decrypt_node_index, &b->esp6_decrypt_next_index);
225  ipsec_add_node (vm, esp4_decrypt_tun_node_name, "ipsec4-tun-input",
226  &b->esp4_decrypt_tun_node_index,
227  &b->esp4_decrypt_tun_next_index);
228  ipsec_add_node (vm, esp6_decrypt_tun_node_name, "ipsec6-tun-input",
229  &b->esp6_decrypt_tun_node_index,
230  &b->esp6_decrypt_tun_next_index);
231 
232  b->esp6_encrypt_tun_node_index =
233  vlib_get_node_by_name (vm, (u8 *) esp6_encrypt_node_tun_name)->index;
234  b->esp_mpls_encrypt_tun_node_index =
235  vlib_get_node_by_name (vm, (u8 *) esp_mpls_encrypt_node_tun_name)->index;
236  b->esp4_encrypt_tun_node_index =
237  vlib_get_node_by_name (vm, (u8 *) esp4_encrypt_node_tun_name)->index;
238 
239  b->check_support_cb = esp_check_support_cb;
240  b->add_del_sa_sess_cb = esp_add_del_sa_sess_cb;
241  b->enable_disable_cb = enable_disable_cb;
242 
243  return b - im->esp_backends;
244 }
245 
246 clib_error_t *
248 {
249  /* return an error is crypto resource are in use */
250  if (pool_elts (ipsec_sa_pool) > 0)
251  return clib_error_return (0, "%d SA entries configured",
253 
254  return (NULL);
255 }
256 
257 int
259 {
260  if (ipsec_rsc_in_use (im))
261  return VNET_API_ERROR_RSRC_IN_USE;
262 
263  if (pool_is_free_index (im->ah_backends, backend_idx))
264  return VNET_API_ERROR_INVALID_VALUE;
265 
266  ipsec_ah_backend_t *b = pool_elt_at_index (im->ah_backends, backend_idx);
267  im->ah_current_backend = backend_idx;
268  im->ah4_encrypt_node_index = b->ah4_encrypt_node_index;
269  im->ah4_decrypt_node_index = b->ah4_decrypt_node_index;
270  im->ah4_encrypt_next_index = b->ah4_encrypt_next_index;
271  im->ah4_decrypt_next_index = b->ah4_decrypt_next_index;
272  im->ah6_encrypt_node_index = b->ah6_encrypt_node_index;
273  im->ah6_decrypt_node_index = b->ah6_decrypt_node_index;
274  im->ah6_encrypt_next_index = b->ah6_encrypt_next_index;
275  im->ah6_decrypt_next_index = b->ah6_decrypt_next_index;
276 
277  return 0;
278 }
279 
280 int
282 {
283  if (ipsec_rsc_in_use (im))
284  return VNET_API_ERROR_RSRC_IN_USE;
285 
286  if (pool_is_free_index (im->esp_backends, backend_idx))
287  return VNET_API_ERROR_INVALID_VALUE;
288 
289  /* disable current backend */
290  if (im->esp_current_backend != ~0)
291  {
292  ipsec_esp_backend_t *cb = pool_elt_at_index (im->esp_backends,
293  im->esp_current_backend);
294  if (cb->enable_disable_cb)
295  {
296  if ((cb->enable_disable_cb) (0) != 0)
297  return -1;
298  }
299  }
300 
301  ipsec_esp_backend_t *b = pool_elt_at_index (im->esp_backends, backend_idx);
302  im->esp_current_backend = backend_idx;
303  im->esp4_encrypt_node_index = b->esp4_encrypt_node_index;
304  im->esp4_decrypt_node_index = b->esp4_decrypt_node_index;
305  im->esp4_encrypt_next_index = b->esp4_encrypt_next_index;
306  im->esp4_decrypt_next_index = b->esp4_decrypt_next_index;
307  im->esp6_encrypt_node_index = b->esp6_encrypt_node_index;
308  im->esp6_decrypt_node_index = b->esp6_decrypt_node_index;
309  im->esp6_encrypt_next_index = b->esp6_encrypt_next_index;
310  im->esp6_decrypt_next_index = b->esp6_decrypt_next_index;
311  im->esp4_decrypt_tun_node_index = b->esp4_decrypt_tun_node_index;
312  im->esp4_decrypt_tun_next_index = b->esp4_decrypt_tun_next_index;
313  im->esp6_decrypt_tun_node_index = b->esp6_decrypt_tun_node_index;
314  im->esp6_decrypt_tun_next_index = b->esp6_decrypt_tun_next_index;
315  im->esp4_encrypt_tun_node_index = b->esp4_encrypt_tun_node_index;
316  im->esp6_encrypt_tun_node_index = b->esp6_encrypt_tun_node_index;
317  im->esp_mpls_encrypt_tun_node_index = b->esp_mpls_encrypt_tun_node_index;
318 
319  if (b->enable_disable_cb)
320  {
321  if ((b->enable_disable_cb) (1) != 0)
322  return -1;
323  }
324  return 0;
325 }
326 
327 void
329 {
331  ipsec_sa_t *sa;
332 
333  vnet_crypto_request_async_mode (is_enabled);
334 
335  im->async_mode = is_enabled;
336 
337  /* change SA crypto op data */
339  {
340  sa->crypto_op_data =
341  (is_enabled ? sa->async_op_data.data : sa->sync_op_data.data);
342  }
343 }
344 
345 static void
347 {
350 
351  eit = &esp_encrypt_async_next;
352  eit->esp4_post_next =
353  vnet_crypto_register_post_node (vm, "esp4-encrypt-post");
354  eit->esp6_post_next =
355  vnet_crypto_register_post_node (vm, "esp6-encrypt-post");
356  eit->esp4_tun_post_next =
357  vnet_crypto_register_post_node (vm, "esp4-encrypt-tun-post");
358  eit->esp6_tun_post_next =
359  vnet_crypto_register_post_node (vm, "esp6-encrypt-tun-post");
361  vnet_crypto_register_post_node (vm, "esp-mpls-encrypt-tun-post");
362 
363  dit = &esp_decrypt_async_next;
364  dit->esp4_post_next =
365  vnet_crypto_register_post_node (vm, "esp4-decrypt-post");
366  dit->esp6_post_next =
367  vnet_crypto_register_post_node (vm, "esp6-decrypt-post");
368  dit->esp4_tun_post_next =
369  vnet_crypto_register_post_node (vm, "esp4-decrypt-tun-post");
370  dit->esp6_tun_post_next =
371  vnet_crypto_register_post_node (vm, "esp6-decrypt-tun-post");
372 }
373 
374 static clib_error_t *
376 {
380 
381  /* Backend registration requires the feature arcs to be set up */
383  return (error);
384 
385  im->vnet_main = vnet_get_main ();
386  im->vlib_main = vm;
387 
388  im->spd_index_by_spd_id = hash_create (0, sizeof (uword));
389  im->sa_index_by_sa_id = hash_create (0, sizeof (uword));
390  im->spd_index_by_sw_if_index = hash_create (0, sizeof (uword));
391 
392  vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
393  ASSERT (node);
394  im->error_drop_node_index = node->index;
395 
396  im->ah_current_backend = ~0;
397  im->esp_current_backend = ~0;
398 
399  u32 idx = ipsec_register_ah_backend (vm, im, "crypto engine backend",
400  "ah4-encrypt",
401  "ah4-decrypt",
402  "ah6-encrypt",
403  "ah6-decrypt",
405  NULL);
406 
407  im->ah_default_backend = idx;
408  int rv = ipsec_select_ah_backend (im, idx);
409  ASSERT (0 == rv);
410  (void) (rv); // avoid warning
411 
413  vm, im, "crypto engine backend", "esp4-encrypt", "esp4-encrypt-tun",
414  "esp4-decrypt", "esp4-decrypt-tun", "esp6-encrypt", "esp6-encrypt-tun",
415  "esp6-decrypt", "esp6-decrypt-tun", "esp-mpls-encrypt-tun",
417  im->esp_default_backend = idx;
418 
419  rv = ipsec_select_esp_backend (im, idx);
420  ASSERT (0 == rv);
421  (void) (rv); // avoid warning
422 
424  return error;
425 
426  vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1);
427 
428  a = im->crypto_algs + IPSEC_CRYPTO_ALG_NONE;
429  a->enc_op_id = VNET_CRYPTO_OP_NONE;
430  a->dec_op_id = VNET_CRYPTO_OP_NONE;
431  a->alg = VNET_CRYPTO_ALG_NONE;
432  a->iv_size = 0;
433  a->block_align = 1;
434 
435  a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC;
436  a->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC;
437  a->dec_op_id = VNET_CRYPTO_OP_DES_CBC_DEC;
438  a->alg = VNET_CRYPTO_ALG_DES_CBC;
439  a->iv_size = a->block_align = 8;
440 
441  a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC;
442  a->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC;
443  a->dec_op_id = VNET_CRYPTO_OP_3DES_CBC_DEC;
444  a->alg = VNET_CRYPTO_ALG_3DES_CBC;
445  a->iv_size = a->block_align = 8;
446 
447  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128;
448  a->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC;
449  a->dec_op_id = VNET_CRYPTO_OP_AES_128_CBC_DEC;
450  a->alg = VNET_CRYPTO_ALG_AES_128_CBC;
451  a->iv_size = a->block_align = 16;
452 
453  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192;
454  a->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC;
455  a->dec_op_id = VNET_CRYPTO_OP_AES_192_CBC_DEC;
456  a->alg = VNET_CRYPTO_ALG_AES_192_CBC;
457  a->iv_size = a->block_align = 16;
458 
459  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256;
460  a->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC;
461  a->dec_op_id = VNET_CRYPTO_OP_AES_256_CBC_DEC;
462  a->alg = VNET_CRYPTO_ALG_AES_256_CBC;
463  a->iv_size = a->block_align = 16;
464 
465  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_128;
466  a->enc_op_id = VNET_CRYPTO_OP_AES_128_CTR_ENC;
467  a->dec_op_id = VNET_CRYPTO_OP_AES_128_CTR_DEC;
468  a->alg = VNET_CRYPTO_ALG_AES_128_CTR;
469  a->iv_size = 8;
470  a->block_align = 1;
471 
472  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_192;
473  a->enc_op_id = VNET_CRYPTO_OP_AES_192_CTR_ENC;
474  a->dec_op_id = VNET_CRYPTO_OP_AES_192_CTR_DEC;
475  a->alg = VNET_CRYPTO_ALG_AES_192_CTR;
476  a->iv_size = 8;
477  a->block_align = 1;
478 
479  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_256;
480  a->enc_op_id = VNET_CRYPTO_OP_AES_256_CTR_ENC;
481  a->dec_op_id = VNET_CRYPTO_OP_AES_256_CTR_DEC;
482  a->alg = VNET_CRYPTO_ALG_AES_256_CTR;
483  a->iv_size = 8;
484  a->block_align = 1;
485 
486  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_128;
487  a->enc_op_id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
488  a->dec_op_id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
489  a->alg = VNET_CRYPTO_ALG_AES_128_GCM;
490  a->iv_size = 8;
491  a->block_align = 1;
492  a->icv_size = 16;
493 
494  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_192;
495  a->enc_op_id = VNET_CRYPTO_OP_AES_192_GCM_ENC;
496  a->dec_op_id = VNET_CRYPTO_OP_AES_192_GCM_DEC;
497  a->alg = VNET_CRYPTO_ALG_AES_192_GCM;
498  a->iv_size = 8;
499  a->block_align = 1;
500  a->icv_size = 16;
501 
502  a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_256;
503  a->enc_op_id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
504  a->dec_op_id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
505  a->alg = VNET_CRYPTO_ALG_AES_256_GCM;
506  a->iv_size = 8;
507  a->block_align = 1;
508  a->icv_size = 16;
509 
510  vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1);
512 
513  i = &im->integ_algs[IPSEC_INTEG_ALG_MD5_96];
514  i->op_id = VNET_CRYPTO_OP_MD5_HMAC;
515  i->alg = VNET_CRYPTO_ALG_HMAC_MD5;
516  i->icv_size = 12;
517 
518  i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96];
519  i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
520  i->alg = VNET_CRYPTO_ALG_HMAC_SHA1;
521  i->icv_size = 12;
522 
523  i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
524  i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
525  i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
526  i->icv_size = 12;
527 
528  i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
529  i->op_id = VNET_CRYPTO_OP_SHA256_HMAC;
530  i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
531  i->icv_size = 16;
532 
533  i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
534  i->op_id = VNET_CRYPTO_OP_SHA384_HMAC;
535  i->alg = VNET_CRYPTO_ALG_HMAC_SHA384;
536  i->icv_size = 24;
537 
538  i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
539  i->op_id = VNET_CRYPTO_OP_SHA512_HMAC;
540  i->alg = VNET_CRYPTO_ALG_HMAC_SHA512;
541  i->icv_size = 32;
542 
544 
545  im->async_mode = 0;
547 
548  return 0;
549 }
550 
552 
553 static clib_error_t *
555 {
556  unformat_input_t sub_input;
557 
559  {
560  if (unformat (input, "ip4 %U", unformat_vlib_cli_sub_input, &sub_input))
561  {
562  uword table_size = ~0;
563  u32 n_buckets = ~0;
564 
565  while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
566  {
567  if (unformat (&sub_input, "num-buckets %u", &n_buckets))
568  ;
569  else
570  return clib_error_return (0, "unknown input `%U'",
571  format_unformat_error, &sub_input);
572  }
573 
574  ipsec_tun_table_init (AF_IP4, table_size, n_buckets);
575  }
576  else if (unformat (input, "ip6 %U", unformat_vlib_cli_sub_input,
577  &sub_input))
578  {
579  uword table_size = ~0;
580  u32 n_buckets = ~0;
581 
582  while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
583  {
584  if (unformat (&sub_input, "num-buckets %u", &n_buckets))
585  ;
586  else
587  return clib_error_return (0, "unknown input `%U'",
588  format_unformat_error, &sub_input);
589  }
590 
591  ipsec_tun_table_init (AF_IP6, table_size, n_buckets);
592  }
593  else
594  return clib_error_return (0, "unknown input `%U'",
595  format_unformat_error, input);
596  }
597 
598  return 0;
599 }
600 
602 
603 /*
604  * fd.io coding-style-patch-verification: ON
605  *
606  * Local Variables:
607  * eval: (c-set-style "gnu")
608  * End:
609  */
ipsec.h
ipsec_register_esp_backend
u32 ipsec_register_esp_backend(vlib_main_t *vm, ipsec_main_t *im, const char *name, const char *esp4_encrypt_node_name, const char *esp4_encrypt_node_tun_name, const char *esp4_decrypt_node_name, const char *esp4_decrypt_tun_node_name, const char *esp6_encrypt_node_name, const char *esp6_encrypt_node_tun_name, const char *esp6_decrypt_node_name, const char *esp6_decrypt_tun_node_name, const char *esp_mpls_encrypt_node_tun_name, check_support_cb_t esp_check_support_cb, add_del_sa_sess_cb_t esp_add_del_sa_sess_cb, enable_disable_cb_t enable_disable_cb)
Definition: ipsec.c:201
im
vnet_interface_main_t * im
Definition: interface_output.c:415
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:333
ipsec_tun.h
ipsec_sa_t::protocol
ipsec_protocol_t protocol
Definition: ipsec_sa.h:174
ipsec_main_integ_alg_t
Definition: ipsec.h:90
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
vlib_node_add_next
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1177
format_ipsec_integ_alg
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:111
esp_async_post_next_t
Definition: esp.h:240
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
name
string name[64]
Definition: fib.api:25
VNET_CRYPTO_ALG_NONE
@ VNET_CRYPTO_ALG_NONE
Definition: crypto.h:147
esp_async_post_next_t::esp_mpls_tun_post_next
u32 esp_mpls_tun_post_next
Definition: esp.h:247
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
esp_encrypt_async_next
esp_async_post_next_t esp_encrypt_async_next
Definition: ipsec.c:30
ipsec_cli_init
clib_error_t * ipsec_cli_init(vlib_main_t *vm)
Definition: ipsec_cli.c:911
u16
unsigned short u16
Definition: types.h:57
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition: init.h:259
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
ipsec_add_node
static void ipsec_add_node(vlib_main_t *vm, const char *node_name, const char *prev_node_name, u32 *out_node_index, u32 *out_next_index)
Definition: ipsec.c:115
port
u16 port
Definition: lb_types.api:73
unformat_input_t
struct _unformat_input_t unformat_input_t
ipsec_ah_backend_t
Definition: ipsec.h:37
ipsec_esp_backend_t::check_support_cb
check_support_cb_t check_support_cb
Definition: ipsec.h:60
error
Definition: cJSON.c:88
hash_unset
#define hash_unset(h, key)
Definition: hash.h:261
ipsec_unregister_udp_port
void ipsec_unregister_udp_port(u16 port)
Definition: ipsec.c:129
ipsec_check_support_cb
clib_error_t * ipsec_check_support_cb(ipsec_main_t *im, ipsec_sa_t *sa)
Definition: ipsec.c:92
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
ipsec_rsc_in_use
clib_error_t * ipsec_rsc_in_use(ipsec_main_t *im)
Definition: ipsec.c:247
ipsec_ah_backend_t::check_support_cb
check_support_cb_t check_support_cb
Definition: ipsec.h:43
esp.h
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vlib_node_t::index
u32 index
Definition: node.h:269
check_support_cb_t
clib_error_t *(* check_support_cb_t)(ipsec_sa_t *sa)
Definition: ipsec.h:34
format_ipsec_crypto_alg
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:79
VNET_CRYPTO_OP_NONE
@ VNET_CRYPTO_OP_NONE
Definition: crypto.h:221
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
hash_get
#define hash_get(h, key)
Definition: hash.h:249
ipsec_main_t
Definition: ipsec.h:108
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vlib_config_function_runtime_t
Definition: init.h:68
esp_async_post_next_t::esp4_tun_post_next
u32 esp4_tun_post_next
Definition: esp.h:245
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
ipsec_main_crypto_alg_t
Definition: ipsec.h:80
udp_local.h
esp_async_post_next_t::esp6_tun_post_next
u32 esp6_tun_post_next
Definition: esp.h:246
uword
u64 uword
Definition: types.h:112
ipsec_main
ipsec_main_t ipsec_main
Definition: ipsec.c:29
udp_register_dst_port
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:431
interface.h
udp_unregister_dst_port
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:469
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
vnet_crypto_request_async_mode
void vnet_crypto_request_async_mode(int is_enable)
Definition: crypto.c:571
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
ipsec_register_udp_port
void ipsec_register_udp_port(u16 port)
Definition: ipsec.c:154
vnet_feature_init
static clib_error_t * vnet_feature_init(vlib_main_t *vm)
Definition: feature.c:50
ipsec_ah_backend_t::add_del_sa_sess_cb
add_del_sa_sess_cb_t add_del_sa_sess_cb
Definition: ipsec.h:41
IPSEC_CRYPTO_N_ALG
@ IPSEC_CRYPTO_N_ALG
Definition: ipsec_sa.h:43
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
unformat_vlib_cli_sub_input
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
Definition: cli.c:163
ipsec_sa_t::crypto_alg
ipsec_crypto_alg_t crypto_alg
Definition: ipsec_sa.h:215
ah.h
vnet_crypto_is_set_handler
int vnet_crypto_is_set_handler(vnet_crypto_alg_t alg)
Definition: crypto.c:189
ipsec_sa_t
Definition: ipsec_sa.h:116
ipsec_register_ah_backend
u32 ipsec_register_ah_backend(vlib_main_t *vm, ipsec_main_t *im, const char *name, const char *ah4_encrypt_node_name, const char *ah4_decrypt_node_name, const char *ah6_encrypt_node_name, const char *ah6_decrypt_node_name, check_support_cb_t ah_check_support_cb, add_del_sa_sess_cb_t ah_add_del_sa_sess_cb)
Definition: ipsec.c:173
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
ipsec4_tun_input_node
vlib_node_registration_t ipsec4_tun_input_node
(constructor) VLIB_REGISTER_NODE (ipsec4_tun_input_node)
Definition: ipsec_tun_in.c:388
esp_decrypt_async_next
esp_async_post_next_t esp_decrypt_async_next
Definition: ipsec.c:31
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
enable_disable_cb_t
clib_error_t *(* enable_disable_cb_t)(int is_enable)
Definition: ipsec.h:35
ipsec_esp_backend_t::add_del_sa_sess_cb
add_del_sa_sess_cb_t add_del_sa_sess_cb
Definition: ipsec.h:58
ip.h
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ipsec_esp_backend_t
Definition: ipsec.h:54
ipsec_set_async_mode
void ipsec_set_async_mode(u32 is_enabled)
Definition: ipsec.c:328
IPSEC_PROTOCOL_AH
@ IPSEC_PROTOCOL_AH
Definition: ipsec_sa.h:75
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
ipsec_check_esp_support
static clib_error_t * ipsec_check_esp_support(ipsec_sa_t *sa)
Definition: ipsec.c:49
crypto_dispatch_enable_disable
clib_error_t * crypto_dispatch_enable_disable(int is_enable)
Definition: crypto.c:459
ipsec_add_del_sa_sess_cb
clib_error_t * ipsec_add_del_sa_sess_cb(ipsec_main_t *im, u32 sa_index, u8 is_add)
Definition: ipsec.c:70
vlib_main_t
Definition: main.h:102
ipsec_tun_table_init
void ipsec_tun_table_init(ip_address_family_t af, uword table_size, u32 n_buckets)
Definition: ipsec_tun.c:929
vlib_node_t
Definition: node.h:247
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
esp_async_post_next_t::esp4_post_next
u32 esp4_post_next
Definition: esp.h:243
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
ipsec_config
static clib_error_t * ipsec_config(vlib_main_t *vm, unformat_input_t *input)
Definition: ipsec.c:554
vnet_crypto_register_post_node
u32 vnet_crypto_register_post_node(vlib_main_t *vm, char *post_node_name)
async crypto register functions
Definition: crypto.c:541
i
int i
Definition: flowhash_template.h:376
ipsec_select_esp_backend
int ipsec_select_esp_backend(ipsec_main_t *im, u32 backend_idx)
Definition: ipsec.c:281
ipsec_select_ah_backend
int ipsec_select_ah_backend(ipsec_main_t *im, u32 backend_idx)
Definition: ipsec.c:258
ipsec_sa_t::integ_alg
ipsec_integ_alg_t integ_alg
Definition: ipsec_sa.h:216
IPSEC_INTEG_N_ALG
@ IPSEC_INTEG_N_ALG
Definition: ipsec_sa.h:70
ipsec_sa_t::sync_op_data
union ipsec_sa_t::@451 sync_op_data
rv
int __clib_unused rv
Definition: application.c:491
ipsec_check_ah_support
static clib_error_t * ipsec_check_ah_support(ipsec_sa_t *sa)
Definition: ipsec.c:34
ipsec_sa_t::async_op_data
union ipsec_sa_t::@452 async_op_data
vnet.h
api_errno.h
ipsec_sa_t::data
u64 data
Definition: ipsec_sa.h:190
ipsec_esp_backend_t::enable_disable_cb
enable_disable_cb_t enable_disable_cb
Definition: ipsec.h:62
hash_create
#define hash_create(elts, value_bytes)
Definition: hash.h:695
crypto_engine_backend_register_post_node
static void crypto_engine_backend_register_post_node(vlib_main_t *vm)
Definition: ipsec.c:346
ipsec_sa_pool
ipsec_sa_t * ipsec_sa_pool
Pool of IPSec SAs.
Definition: ipsec_sa.c:32
esp_async_post_next_t::esp6_post_next
u32 esp6_post_next
Definition: esp.h:244
ipsec_init
static clib_error_t * ipsec_init(vlib_main_t *vm)
Definition: ipsec.c:375
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
add_del_sa_sess_cb_t
clib_error_t *(* add_del_sa_sess_cb_t)(u32 sa_index, u8 is_add)
Definition: ipsec.h:33
ipsec_sa_t::crypto_op_data
u64 crypto_op_data
Definition: ipsec_sa.h:159