FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
esp_decrypt.c
Go to the documentation of this file.
1 /*
2  * esp_decrypt.c : IPSec ESP Decrypt node using DPDK Cryptodev
3  *
4  * Copyright (c) 2017 Intel 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 opy 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 
22 #include <vnet/ipsec/ipsec.h>
23 #include <vnet/ipsec/esp.h>
24 #include <dpdk/ipsec/ipsec.h>
25 #include <dpdk/device/dpdk.h>
26 #include <dpdk/device/dpdk_priv.h>
27 
28 #define foreach_esp_decrypt_next \
29 _(DROP, "error-drop") \
30 _(IP4_INPUT, "ip4-input-no-checksum") \
31 _(IP6_INPUT, "ip6-input")
32 
33 #define _(v, s) ESP_DECRYPT_NEXT_##v,
34 typedef enum
35 {
37 #undef _
40 
41 #define foreach_esp_decrypt_error \
42  _(RX_PKTS, "ESP pkts received") \
43  _(DECRYPTION_FAILED, "ESP decryption failed") \
44  _(REPLAY, "SA replayed packet") \
45  _(NOT_IP, "Not IP packet (dropped)") \
46  _(ENQ_FAIL, "Enqueue failed (buffer full)") \
47  _(DISCARD, "Not enough crypto operations, discarding frame") \
48  _(BAD_LEN, "Invalid ciphertext length") \
49  _(SESSION, "Failed to get crypto session") \
50  _(NOSUP, "Cipher/Auth not supported")
51 
52 
53 typedef enum
54 {
55 #define _(sym,str) ESP_DECRYPT_ERROR_##sym,
57 #undef _
60 
61 static char *esp_decrypt_error_strings[] = {
62 #define _(sym,string) string,
64 #undef _
65 };
66 
69 
70 typedef struct
71 {
72  ipsec_crypto_alg_t crypto_alg;
73  ipsec_integ_alg_t integ_alg;
74  u8 packet_data[64];
76 
77 /* packet trace format function */
78 static u8 *
79 format_esp_decrypt_trace (u8 * s, va_list * args)
80 {
81  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
82  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
83  esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
84  u32 indent = format_get_indent (s);
85 
86  s = format (s, "cipher %U auth %U\n",
89  s = format (s, "%U%U",
91  return s;
92 }
93 
96  vlib_node_runtime_t * node,
97  vlib_frame_t * from_frame, int is_ip6)
98 {
99  u32 n_left_from, *from, *to_next, next_index;
100  ipsec_main_t *im = &ipsec_main;
101  u32 thread_idx = vlib_get_thread_index ();
103  crypto_resource_t *res = 0;
104  ipsec_sa_t *sa0 = 0;
105  crypto_alg_t *cipher_alg = 0, *auth_alg = 0;
106  struct rte_cryptodev_sym_session *session = 0;
107  u32 ret, last_sa_index = ~0;
108  u8 numa = rte_socket_id ();
109  u8 is_aead = 0;
110  crypto_worker_main_t *cwm =
111  vec_elt_at_index (dcm->workers_main, thread_idx);
112  struct rte_crypto_op **ops = cwm->ops;
113 
114  from = vlib_frame_vector_args (from_frame);
115  n_left_from = from_frame->n_vectors;
116 
117  ret = crypto_alloc_ops (numa, ops, n_left_from);
118  if (ret)
119  {
120  if (is_ip6)
122  ESP_DECRYPT_ERROR_DISCARD, 1);
123  else
125  ESP_DECRYPT_ERROR_DISCARD, 1);
126  /* Discard whole frame */
127  return n_left_from;
128  }
129 
130  next_index = ESP_DECRYPT_NEXT_DROP;
131 
132  while (n_left_from > 0)
133  {
134  u32 n_left_to_next;
135 
136  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
137 
138  while (n_left_from > 0 && n_left_to_next > 0)
139  {
140  clib_error_t *error;
141  u32 bi0, sa_index0, seq, iv_size;
142  u8 trunc_size;
143  vlib_buffer_t *b0;
144  esp_header_t *esp0;
145  struct rte_mbuf *mb0;
146  struct rte_crypto_op *op;
147  u16 res_idx;
148 
149  bi0 = from[0];
150  from += 1;
151  n_left_from -= 1;
152 
153  b0 = vlib_get_buffer (vm, bi0);
154  mb0 = rte_mbuf_from_vlib_buffer (b0);
155  esp0 = vlib_buffer_get_current (b0);
156 
157  /* ih0/ih6_0 */
158  CLIB_PREFETCH (esp0, sizeof (esp0[0]) + 16, LOAD);
159  /* mb0 */
160  CLIB_PREFETCH (mb0, CLIB_CACHE_LINE_BYTES, STORE);
161 
162  op = ops[0];
163  ops += 1;
164  ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
165 
166  dpdk_op_priv_t *priv = crypto_op_get_priv (op);
167 
168  u16 op_len =
169  sizeof (op[0]) + sizeof (op[0].sym[0]) + sizeof (priv[0]);
170  CLIB_PREFETCH (op, op_len, STORE);
171 
172  sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
173 
174  if (sa_index0 != last_sa_index)
175  {
176  sa0 = pool_elt_at_index (im->sad, sa_index0);
177 
178  cipher_alg =
180  auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
181 
182  is_aead = (cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD);
183  if (is_aead)
184  auth_alg = cipher_alg;
185 
186  res_idx = get_resource (cwm, sa0);
187 
188  if (PREDICT_FALSE (res_idx == (u16) ~ 0))
189  {
190  clib_warning ("unsupported SA by thread index %u",
191  thread_idx);
192  if (is_ip6)
195  ESP_DECRYPT_ERROR_NOSUP, 1);
196  else
199  ESP_DECRYPT_ERROR_NOSUP, 1);
200  to_next[0] = bi0;
201  to_next += 1;
202  n_left_to_next -= 1;
203  goto trace;
204  }
205  res = vec_elt_at_index (dcm->resource, res_idx);
206 
207  error = crypto_get_session (&session, sa_index0, res, cwm, 0);
208  if (PREDICT_FALSE (error || !session))
209  {
210  clib_warning ("failed to get crypto session");
211  if (is_ip6)
214  ESP_DECRYPT_ERROR_SESSION,
215  1);
216  else
219  ESP_DECRYPT_ERROR_SESSION,
220  1);
221  to_next[0] = bi0;
222  to_next += 1;
223  n_left_to_next -= 1;
224  goto trace;
225  }
226 
227  last_sa_index = sa_index0;
228  }
229 
230  /* anti-replay check */
231  if (sa0->use_anti_replay)
232  {
233  int rv = 0;
234 
235  seq = clib_net_to_host_u32 (esp0->seq);
236 
237  if (PREDICT_TRUE (sa0->use_esn))
238  rv = esp_replay_check_esn (sa0, seq);
239  else
240  rv = esp_replay_check (sa0, seq);
241 
242  if (PREDICT_FALSE (rv))
243  {
244  clib_warning ("failed anti-replay check");
245  if (is_ip6)
248  ESP_DECRYPT_ERROR_REPLAY, 1);
249  else
252  ESP_DECRYPT_ERROR_REPLAY, 1);
253  to_next[0] = bi0;
254  to_next += 1;
255  n_left_to_next -= 1;
256  goto trace;
257  }
258  }
259 
260  if (is_ip6)
261  priv->next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT6_POST;
262  else
263  priv->next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT4_POST;
264 
265  /* FIXME multi-seg */
266  sa0->total_data_size += b0->current_length;
267 
268  res->ops[res->n_ops] = op;
269  res->bi[res->n_ops] = bi0;
270  res->n_ops += 1;
271 
272  /* Convert vlib buffer to mbuf */
273  mb0->data_len = b0->current_length;
274  mb0->pkt_len = b0->current_length;
275  mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->current_data;
276 
277  trunc_size = auth_alg->trunc_size;
278  iv_size = cipher_alg->iv_len;
279 
280  /* Outer IP header has already been stripped */
281  u16 payload_len =
282  b0->current_length - sizeof (esp_header_t) - iv_size - trunc_size;
283 
284  ASSERT (payload_len >= 4);
285 
286  if (payload_len & (cipher_alg->boundary - 1))
287  {
288  clib_warning ("payload %u not multiple of %d\n",
289  payload_len, cipher_alg->boundary);
290  if (is_ip6)
292  ESP_DECRYPT_ERROR_BAD_LEN, 1);
293  else
295  ESP_DECRYPT_ERROR_BAD_LEN, 1);
296  res->n_ops -= 1;
297  to_next[0] = bi0;
298  to_next += 1;
299  n_left_to_next -= 1;
300  goto trace;
301  }
302 
303  u32 cipher_off, cipher_len;
304  u32 auth_len = 0;
305  u8 *aad = NULL;
306 
307  u8 *iv = (u8 *) (esp0 + 1);
308 
309  dpdk_gcm_cnt_blk *icb = &priv->cb;
310 
311  cipher_off = sizeof (esp_header_t) + iv_size;
312  cipher_len = payload_len;
313 
314  u8 *digest = vlib_buffer_get_tail (b0) - trunc_size;
315  u64 digest_paddr =
316  mb0->buf_physaddr + digest - ((u8 *) mb0->buf_addr);
317 
318  if (!is_aead && cipher_alg->alg == RTE_CRYPTO_CIPHER_AES_CBC)
319  clib_memcpy_fast (icb, iv, 16);
320  else /* CTR/GCM */
321  {
322  u32 *_iv = (u32 *) iv;
323 
324  crypto_set_icb (icb, sa0->salt, _iv[0], _iv[1]);
325  }
326 
327  if (is_aead)
328  {
329  aad = priv->aad;
330  u32 *_aad = (u32 *) aad;
331  clib_memcpy_fast (aad, esp0, 8);
332 
333  /* _aad[3] should always be 0 */
334  if (PREDICT_FALSE (sa0->use_esn))
335  _aad[2] = clib_host_to_net_u32 (sa0->seq_hi);
336  else
337  _aad[2] = 0;
338  }
339  else
340  {
341  auth_len = sizeof (esp_header_t) + iv_size + payload_len;
342 
343  if (sa0->use_esn)
344  {
345  clib_memcpy_fast (priv->icv, digest, trunc_size);
346  u32 *_digest = (u32 *) digest;
347  _digest[0] = clib_host_to_net_u32 (sa0->seq_hi);
348  auth_len += sizeof (sa0->seq_hi);
349 
350  digest = priv->icv;
351  digest_paddr =
352  op->phys_addr + (uintptr_t) priv->icv - (uintptr_t) op;
353  }
354  }
355 
356  crypto_op_setup (is_aead, mb0, op, session, cipher_off, cipher_len,
357  0, auth_len, aad, digest, digest_paddr);
358  trace:
359  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
360  {
361  esp_decrypt_trace_t *tr =
362  vlib_add_trace (vm, node, b0, sizeof (*tr));
363  tr->crypto_alg = sa0->crypto_alg;
364  tr->integ_alg = sa0->integ_alg;
366  sizeof (esp_header_t));
367  }
368  }
369  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
370  }
371 
372  if (is_ip6)
373  {
375  ESP_DECRYPT_ERROR_RX_PKTS,
376  from_frame->n_vectors);
377 
378  crypto_enqueue_ops (vm, cwm, 0, dpdk_esp6_decrypt_node.index,
379  ESP_DECRYPT_ERROR_ENQ_FAIL, numa);
380  }
381  else
382  {
384  ESP_DECRYPT_ERROR_RX_PKTS,
385  from_frame->n_vectors);
386 
387  crypto_enqueue_ops (vm, cwm, 0, dpdk_esp4_decrypt_node.index,
388  ESP_DECRYPT_ERROR_ENQ_FAIL, numa);
389  }
390 
391  crypto_free_ops (numa, ops, cwm->ops + from_frame->n_vectors - ops);
392 
393  return from_frame->n_vectors;
394 }
395 
397  vlib_node_runtime_t * node,
398  vlib_frame_t * from_frame)
399 {
400  return dpdk_esp_decrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ );
401 }
402 
403 /* *INDENT-OFF* */
405  .name = "dpdk-esp4-decrypt",
406  .vector_size = sizeof (u32),
407  .format_trace = format_esp_decrypt_trace,
408  .type = VLIB_NODE_TYPE_INTERNAL,
409 
411  .error_strings = esp_decrypt_error_strings,
412 
413  .n_next_nodes = ESP_DECRYPT_N_NEXT,
414  .next_nodes = {
415 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
417 #undef _
418  },
419 };
420 /* *INDENT-ON* */
421 
423  vlib_node_runtime_t * node,
424  vlib_frame_t * from_frame)
425 {
426  return dpdk_esp_decrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ );
427 }
428 
429 /* *INDENT-OFF* */
431  .name = "dpdk-esp6-decrypt",
432  .vector_size = sizeof (u32),
433  .format_trace = format_esp_decrypt_trace,
434  .type = VLIB_NODE_TYPE_INTERNAL,
435 
437  .error_strings = esp_decrypt_error_strings,
438 
439  .n_next_nodes = ESP_DECRYPT_N_NEXT,
440  .next_nodes = {
441 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
443 #undef _
444  },
445 };
446 /* *INDENT-ON* */
447 
448 /*
449  * Decrypt Post Node
450  */
451 
452 #define foreach_esp_decrypt_post_error \
453  _(PKTS, "ESP post pkts")
454 
455 typedef enum
456 {
457 #define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym,
459 #undef _
462 
464 #define _(sym,string) string,
466 #undef _
467 };
468 
471 
472 static u8 *
473 format_esp_decrypt_post_trace (u8 * s, va_list * args)
474 {
475  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
476  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
477  esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
478  u32 indent = format_get_indent (s);
479 
480  s = format (s, "cipher %U auth %U\n",
483 
484  ip4_header_t *ih4 = (ip4_header_t *) t->packet_data;
485  if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
486  s =
487  format (s, "%U%U", format_white_space, indent, format_ip6_header, ih4);
488  else
489  s =
490  format (s, "%U%U", format_white_space, indent, format_ip4_header, ih4);
491 
492  return s;
493 }
494 
497  vlib_node_runtime_t * node,
498  vlib_frame_t * from_frame, int is_ip6)
499 {
500  u32 n_left_from, *from, *to_next = 0, next_index;
501  ipsec_sa_t *sa0;
502  u32 sa_index0 = ~0;
503  ipsec_main_t *im = &ipsec_main;
505 
506  from = vlib_frame_vector_args (from_frame);
507  n_left_from = from_frame->n_vectors;
508 
509  next_index = node->cached_next_index;
510 
511  while (n_left_from > 0)
512  {
513  u32 n_left_to_next;
514 
515  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
516 
517  while (n_left_from > 0 && n_left_to_next > 0)
518  {
519  esp_footer_t *f0;
520  u32 bi0, iv_size, next0;
521  vlib_buffer_t *b0 = 0;
522  ip4_header_t *ih4 = 0, *oh4 = 0;
523  ip6_header_t *ih6 = 0, *oh6 = 0;
524  crypto_alg_t *cipher_alg, *auth_alg;
525  esp_header_t *esp0;
526  u8 trunc_size, is_aead;
527  u16 udp_encap_adv = 0;
528 
529  next0 = ESP_DECRYPT_NEXT_DROP;
530 
531  bi0 = from[0];
532  from += 1;
533  n_left_from -= 1;
534  n_left_to_next -= 1;
535 
536  b0 = vlib_get_buffer (vm, bi0);
537  esp0 = vlib_buffer_get_current (b0);
538 
539  sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
540  sa0 = pool_elt_at_index (im->sad, sa_index0);
541 
542  to_next[0] = bi0;
543  to_next += 1;
544 
545  cipher_alg = vec_elt_at_index (dcm->cipher_algs, sa0->crypto_alg);
546  auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
547  is_aead = cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD;
548  if (is_aead)
549  auth_alg = cipher_alg;
550 
551  trunc_size = auth_alg->trunc_size;
552 
553  iv_size = cipher_alg->iv_len;
554 
555  if (sa0->use_anti_replay)
556  {
557  u32 seq;
558  seq = clib_host_to_net_u32 (esp0->seq);
559  if (PREDICT_TRUE (sa0->use_esn))
560  esp_replay_advance_esn (sa0, seq);
561  else
562  esp_replay_advance (sa0, seq);
563  }
564 
565  /* if UDP encapsulation is used adjust the address of the IP header */
566  if (sa0->udp_encap && (b0->flags & VNET_BUFFER_F_IS_IP4))
567  {
568  udp_encap_adv = sizeof (udp_header_t);
569  }
570 
571  if (b0->flags & VNET_BUFFER_F_IS_IP4)
572  ih4 = (ip4_header_t *)
573  ((u8 *) esp0 - udp_encap_adv - sizeof (ip4_header_t));
574  else
575  ih4 = (ip4_header_t *) ((u8 *) esp0 - sizeof (ip6_header_t));
576 
577  vlib_buffer_advance (b0, sizeof (esp_header_t) + iv_size);
578 
579  b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
580  f0 = (esp_footer_t *) (vlib_buffer_get_tail (b0) - trunc_size - 2);
581  b0->current_length -= (f0->pad_length + trunc_size + 2);
582 #if 0
583  /* check padding */
584  const u8 *padding = vlib_buffer_get_tail (b0);
585  if (PREDICT_FALSE (memcmp (padding, pad_data, f0->pad_length)))
586  {
587  clib_warning ("bad padding");
588  vlib_node_increment_counter (vm, dpdk_esp_decrypt_node.index,
589  ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
590  1);
591  goto trace;
592  }
593 #endif
594  if (sa0->is_tunnel)
595  {
596  if (f0->next_header == IP_PROTOCOL_IP_IN_IP)
597  next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
598  else if (sa0->is_tunnel_ip6
599  && f0->next_header == IP_PROTOCOL_IPV6)
600  next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
601  else
602  {
603  clib_warning ("next header: 0x%x", f0->next_header);
604  if (is_ip6)
607  ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
608  1);
609  else
612  ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
613  1);
614  goto trace;
615  }
616  }
617  else /* transport mode */
618  {
619  if ((ih4->ip_version_and_header_length & 0xF0) == 0x40)
620  {
621  u16 ih4_len = ip4_header_bytes (ih4);
622  vlib_buffer_advance (b0, -ih4_len - udp_encap_adv);
623  next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
624  if (!sa0->udp_encap)
625  {
626  oh4 = vlib_buffer_get_current (b0);
627  memmove (oh4, ih4, ih4_len);
628  oh4->protocol = f0->next_header;
629  oh4->length = clib_host_to_net_u16 (b0->current_length);
630  oh4->checksum = ip4_header_checksum (oh4);
631  }
632  }
633  else if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
634  {
635  ih6 = (ip6_header_t *) ih4;
636  vlib_buffer_advance (b0, -sizeof (ip6_header_t));
637  oh6 = vlib_buffer_get_current (b0);
638  memmove (oh6, ih6, sizeof (ip6_header_t));
639 
640  next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
641  oh6->protocol = f0->next_header;
642  u16 len = b0->current_length - sizeof (ip6_header_t);
643  oh6->payload_length = clib_host_to_net_u16 (len);
644  }
645  else
646  {
647  clib_warning ("next header: 0x%x", f0->next_header);
648  if (is_ip6)
651  ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
652  1);
653  else
656  ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
657  1);
658  goto trace;
659  }
660  }
661 
662  vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
663 
664  trace:
665  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
666  {
667  esp_decrypt_trace_t *tr =
668  vlib_add_trace (vm, node, b0, sizeof (*tr));
669  tr->crypto_alg = sa0->crypto_alg;
670  tr->integ_alg = sa0->integ_alg;
671  ih4 = vlib_buffer_get_current (b0);
672  clib_memcpy_fast (tr->packet_data, ih4, sizeof (ip6_header_t));
673  }
674 
675  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
676  to_next, n_left_to_next, bi0,
677  next0);
678  }
679  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
680  }
681 
682  if (is_ip6)
684  ESP_DECRYPT_POST_ERROR_PKTS,
685  from_frame->n_vectors);
686  else
688  ESP_DECRYPT_POST_ERROR_PKTS,
689  from_frame->n_vectors);
690 
691  return from_frame->n_vectors;
692 }
693 
695  vlib_node_runtime_t * node,
696  vlib_frame_t * from_frame)
697 {
698  return dpdk_esp_decrypt_post_inline (vm, node, from_frame, 0 /*is_ip6 */ );
699 }
700 
701 /* *INDENT-OFF* */
703  .name = "dpdk-esp4-decrypt-post",
704  .vector_size = sizeof (u32),
705  .format_trace = format_esp_decrypt_post_trace,
706  .type = VLIB_NODE_TYPE_INTERNAL,
707 
709  .error_strings = esp_decrypt_post_error_strings,
710 
711  .n_next_nodes = ESP_DECRYPT_N_NEXT,
712  .next_nodes = {
713 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
715 #undef _
716  },
717 };
718 /* *INDENT-ON* */
719 
721  vlib_node_runtime_t * node,
722  vlib_frame_t * from_frame)
723 {
724  return dpdk_esp_decrypt_post_inline (vm, node, from_frame, 0 /*is_ip6 */ );
725 }
726 
727 /* *INDENT-OFF* */
729  .name = "dpdk-esp6-decrypt-post",
730  .vector_size = sizeof (u32),
731  .format_trace = format_esp_decrypt_post_trace,
732  .type = VLIB_NODE_TYPE_INTERNAL,
733 
735  .error_strings = esp_decrypt_post_error_strings,
736 
737  .n_next_nodes = ESP_DECRYPT_N_NEXT,
738  .next_nodes = {
739 #define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
741 #undef _
742  },
743 };
744 /* *INDENT-ON* */
745 
746 /*
747  * fd.io coding-style-patch-verification: ON
748  *
749  * Local Variables:
750  * eval: (c-set-style "gnu")
751  * End:
752  */
u32 alg
Definition: ipsec.h:80
static_always_inline void crypto_op_setup(u8 is_aead, struct rte_mbuf *mb0, struct rte_crypto_op *op, void *session, u32 cipher_off, u32 cipher_len, u32 auth_off, u32 auth_len, u8 *aad, u8 *digest, u64 digest_paddr)
Definition: ipsec.h:346
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:862
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer&#39;s data.
Definition: buffer.h:295
#define CLIB_UNUSED(x)
Definition: clib.h:82
static char * esp_decrypt_post_error_strings[]
Definition: esp_decrypt.c:463
static u8 * format_esp_decrypt_post_trace(u8 *s, va_list *args)
Definition: esp_decrypt.c:473
format_function_t format_ip4_header
Definition: format.h:83
#define PREDICT_TRUE(x)
Definition: clib.h:112
unsigned long u64
Definition: types.h:89
static void esp_replay_advance(ipsec_sa_t *sa, u32 seq)
Definition: esp.h:124
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
static_always_inline i32 crypto_alloc_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
Definition: ipsec.h:276
ipsec_integ_alg_t integ_alg
Definition: ipsec.h:129
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
Definition: ipsec.h:338
ipsec_crypto_alg_t crypto_alg
Definition: esp_decrypt.c:65
u8 is_tunnel
Definition: ipsec.h:136
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define VLIB_NODE_FN(node)
Definition: node.h:201
static_always_inline void crypto_enqueue_ops(vlib_main_t *vm, crypto_worker_main_t *cwm, u8 outbound, u32 node_index, u32 error, u8 numa)
Definition: ipsec.h:304
esp_decrypt_next_t
Definition: esp_decrypt.c:32
unsigned char u8
Definition: types.h:56
static char * esp_decrypt_error_strings[]
Definition: esp_decrypt.c:61
u32 bi[VLIB_FRAME_SIZE]
Definition: ipsec.h:121
u32 seq_hi
Definition: ipsec.h:147
static_always_inline clib_error_t * crypto_get_session(struct rte_cryptodev_sym_session **session, u32 sa_idx, crypto_resource_t *res, crypto_worker_main_t *cwm, u8 is_outbound)
Definition: ipsec.h:230
static_always_inline void crypto_free_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
Definition: ipsec.h:292
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
vlib_node_registration_t dpdk_esp4_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_decrypt_post_node)
Definition: esp_decrypt.c:702
#define foreach_esp_decrypt_next
Definition: esp_decrypt.c:28
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.c:24
static void esp_replay_advance_esn(ipsec_sa_t *sa, u32 seq)
Definition: esp.h:145
ipsec_main_t ipsec_main
Definition: ipsec.c:30
#define always_inline
Definition: clib.h:98
#define foreach_esp_decrypt_post_error
Definition: esp_decrypt.c:452
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
u8 use_esn
Definition: ipsec.h:133
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned int u32
Definition: types.h:88
u32 padding
Definition: vhost_user.h:115
crypto_alg_t * auth_algs
Definition: ipsec.h:159
static const u8 pad_data[]
Definition: ipsec.h:168
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:58
u8 trunc_size
Definition: ipsec.h:83
u8 udp_encap
Definition: ipsec.h:138
u32 next
Definition: ipsec.h:60
#define rte_mbuf_from_vlib_buffer(x)
Definition: dpdk_priv.h:16
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
ipsec_integ_alg_t
Definition: ipsec.h:105
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:114
u8 is_tunnel_ip6
Definition: ipsec.h:137
crypto_alg_t * cipher_algs
Definition: ipsec.h:158
static int esp_replay_check_esn(ipsec_sa_t *sa, u32 seq)
Definition: esp.h:80
u32 salt
Definition: ipsec.h:143
unsigned short u16
Definition: types.h:57
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:214
#define PREDICT_FALSE(x)
Definition: clib.h:111
vlib_node_registration_t dpdk_esp4_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_decrypt_node)
Definition: esp_decrypt.c:404
vlib_node_registration_t dpdk_esp6_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_decrypt_post_node)
Definition: esp_decrypt.c:728
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
u8 len
Definition: ip_types.api:49
esp_decrypt_post_error_t
Definition: esp_decrypt.c:455
u8 aad[16]
Definition: ipsec.h:62
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:420
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:79
vlib_main_t * vm
Definition: buffer.c:301
dpdk_gcm_cnt_blk cb
Definition: ipsec.h:61
static uword dpdk_esp_decrypt_post_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6)
Definition: esp_decrypt.c:496
#define clib_warning(format, args...)
Definition: error.h:59
static uword dpdk_esp_decrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6)
Definition: esp_decrypt.c:95
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:452
u8 * format_esp_header(u8 *s, va_list *args)
Definition: esp_format.c:23
u8 iv_len
Definition: ipsec.h:82
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:537
#define ASSERT(truth)
static int esp_replay_check(ipsec_sa_t *sa, u32 seq)
Definition: esp.h:62
esp_decrypt_error_t
Definition: esp_decrypt.c:49
u8 icv[32]
Definition: ipsec.h:63
ipsec_sa_t * sad
Definition: ipsec.h:353
ipsec_crypto_alg_t
Definition: ipsec.h:88
crypto_worker_main_t * workers_main
Definition: ipsec.h:155
u64 total_data_size
Definition: ipsec.h:153
u32 seq
Definition: esp.h:24
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:233
format_function_t format_ip6_header
Definition: format.h:97
u8 boundary
Definition: ipsec.h:84
crypto_resource_t * resource
Definition: ipsec.h:157
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:90
struct _vlib_node_registration vlib_node_registration_t
Definition: defs.h:47
vlib_node_registration_t dpdk_esp6_decrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_decrypt_node)
Definition: esp_decrypt.c:430
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
struct rte_crypto_op ** ops
Definition: ipsec.h:69
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
Definition: esp_decrypt.c:79
enum rte_crypto_sym_xform_type type
Definition: ipsec.h:79
#define vnet_buffer(b)
Definition: buffer.h:368
static_always_inline u16 get_resource(crypto_worker_main_t *cwm, ipsec_sa_t *sa)
Definition: ipsec.h:251
ipsec_crypto_alg_t crypto_alg
Definition: ipsec.h:125
static int ip4_header_bytes(const ip4_header_t *i)
Definition: ip4_packet.h:235
u8 ip_version_and_header_length
Definition: ip4_packet.h:138
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:117
#define foreach_esp_decrypt_error
Definition: esp_decrypt.c:41
u8 use_anti_replay
Definition: ipsec.h:134
struct rte_crypto_op * ops[VLIB_FRAME_SIZE]
Definition: ipsec.h:120
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
ipsec_integ_alg_t integ_alg
Definition: esp_decrypt.c:66
static_always_inline dpdk_op_priv_t * crypto_op_get_priv(struct rte_crypto_op *op)
Definition: ipsec.h:200