FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
esp_encrypt.c
Go to the documentation of this file.
1 /*
2  * esp_encrypt.c : IPSec ESP encrypt 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 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 
22 #include <vnet/ipsec/ipsec.h>
23 #include <vnet/ipsec/esp.h>
24 #include <vnet/udp/udp.h>
25 #include <dpdk/buffer.h>
26 #include <dpdk/ipsec/ipsec.h>
27 #include <dpdk/device/dpdk.h>
28 #include <dpdk/device/dpdk_priv.h>
29 
30 #define foreach_esp_encrypt_next \
31 _(DROP, "error-drop") \
32 _(IP4_LOOKUP, "ip4-lookup") \
33 _(IP6_LOOKUP, "ip6-lookup") \
34 _(INTERFACE_OUTPUT, "interface-output")
35 
36 #define _(v, s) ESP_ENCRYPT_NEXT_##v,
37 typedef enum
38 {
40 #undef _
43 
44 #define foreach_esp_encrypt_error \
45  _(RX_PKTS, "ESP pkts received") \
46  _(SEQ_CYCLED, "Sequence number cycled") \
47  _(ENQ_FAIL, "Enqueue failed to crypto device") \
48  _(DISCARD, "Not enough crypto operations, discarding frame") \
49  _(SESSION, "Failed to get crypto session") \
50  _(NOSUP, "Cipher/Auth not supported")
51 
52 
53 typedef enum
54 {
55 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym,
57 #undef _
60 
61 static char *esp_encrypt_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_encrypt_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_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *);
85  u32 indent = format_get_indent (s), offset;
86 
87  s = format (s, "cipher %U auth %U\n",
90 
91  if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
92  {
93  s = format (s, "%U%U", format_white_space, indent,
94  format_ip6_header, ih4);
95  offset = sizeof (ip6_header_t);
96  }
97  else
98  {
99  s = format (s, "%U%U", format_white_space, indent,
100  format_ip4_header, ih4);
101  offset = ip4_header_bytes (ih4);
102  }
103 
104  s = format (s, "\n%U%U", format_white_space, indent,
106 
107  return s;
108 }
109 
112  vlib_node_runtime_t * node,
113  vlib_frame_t * from_frame, int is_ip6, int is_tun)
114 {
115  u32 n_left_from, *from, *to_next, next_index, thread_index;
116  ipsec_main_t *im = &ipsec_main;
117  u32 thread_idx = vlib_get_thread_index ();
119  crypto_resource_t *res = 0;
120  ipsec_sa_t *sa0 = 0;
121  crypto_alg_t *cipher_alg = 0, *auth_alg = 0;
122  struct rte_cryptodev_sym_session *session = 0;
123  u32 ret, last_sa_index = ~0;
124  u8 numa = rte_socket_id ();
125  u8 is_aead = 0;
126  crypto_worker_main_t *cwm =
127  vec_elt_at_index (dcm->workers_main, thread_idx);
128  struct rte_crypto_op **ops = cwm->ops;
129 
130  from = vlib_frame_vector_args (from_frame);
131  n_left_from = from_frame->n_vectors;
132  thread_index = vm->thread_index;
133 
134  ret = crypto_alloc_ops (numa, ops, n_left_from);
135  if (ret)
136  {
137  if (is_ip6)
139  ESP_ENCRYPT_ERROR_DISCARD, 1);
140  else
142  ESP_ENCRYPT_ERROR_DISCARD, 1);
143  /* Discard whole frame */
144  return n_left_from;
145  }
146 
147  next_index = ESP_ENCRYPT_NEXT_DROP;
148 
149  while (n_left_from > 0)
150  {
151  u32 n_left_to_next;
152 
153  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
154 
155  while (n_left_from > 0 && n_left_to_next > 0)
156  {
157  clib_error_t *error;
158  u32 bi0;
159  vlib_buffer_t *b0 = 0;
160  u32 sa_index0;
161  ip4_and_esp_header_t *ih0, *oh0 = 0;
162  ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
163  ip4_and_udp_and_esp_header_t *ouh0 = 0;
164  esp_header_t *esp0;
165  esp_footer_t *f0;
166  u8 next_hdr_type;
167  u32 iv_size;
168  u16 orig_sz;
169  u8 trunc_size;
170  u16 rewrite_len;
171  u16 udp_encap_adv = 0;
172  struct rte_mbuf *mb0 = 0;
173  struct rte_crypto_op *op;
174  u16 res_idx;
175 
176  bi0 = from[0];
177  from += 1;
178  n_left_from -= 1;
179 
180  b0 = vlib_get_buffer (vm, bi0);
181  ih0 = vlib_buffer_get_current (b0);
182  mb0 = rte_mbuf_from_vlib_buffer (b0);
183 
184  /* ih0/ih6_0 */
185  CLIB_PREFETCH (ih0, sizeof (ih6_0[0]), LOAD);
186  /* f0 */
187  CLIB_PREFETCH (vlib_buffer_get_tail (b0), 20, STORE);
188  /* mb0 */
189  CLIB_PREFETCH (mb0, CLIB_CACHE_LINE_BYTES, STORE);
190 
191  op = ops[0];
192  ops += 1;
193  ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
194 
195  dpdk_op_priv_t *priv = crypto_op_get_priv (op);
196  /* store bi in op private */
197  priv->bi = bi0;
198 
199  u16 op_len =
200  sizeof (op[0]) + sizeof (op[0].sym[0]) + sizeof (priv[0]);
201  CLIB_PREFETCH (op, op_len, STORE);
202 
203  if (is_tun)
204  {
205  u32 tmp;
206  /* we are on a ipsec tunnel's feature arc */
207  sa_index0 = *(u32 *) vnet_feature_next_with_data (&tmp, b0,
208  sizeof
209  (sa_index0));
210  }
211  else
212  sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
213 
214  if (sa_index0 != last_sa_index)
215  {
216  sa0 = pool_elt_at_index (im->sad, sa_index0);
217 
218  cipher_alg =
220  auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
221 
222  is_aead = (cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD);
223 
224  if (is_aead)
225  auth_alg = cipher_alg;
226 
227  res_idx = get_resource (cwm, sa0);
228 
229  if (PREDICT_FALSE (res_idx == (u16) ~ 0))
230  {
231  clib_warning ("unsupported SA by thread index %u",
232  thread_idx);
233  if (is_ip6)
236  ESP_ENCRYPT_ERROR_NOSUP, 1);
237  else
240  ESP_ENCRYPT_ERROR_NOSUP, 1);
241  to_next[0] = bi0;
242  to_next += 1;
243  n_left_to_next -= 1;
244  goto trace;
245  }
246  res = vec_elt_at_index (dcm->resource, res_idx);
247 
248  error = crypto_get_session (&session, sa_index0, res, cwm, 1);
249  if (PREDICT_FALSE (error || !session))
250  {
251  clib_warning ("failed to get crypto session");
252  if (is_ip6)
255  ESP_ENCRYPT_ERROR_SESSION,
256  1);
257  else
260  ESP_ENCRYPT_ERROR_SESSION,
261  1);
262  to_next[0] = bi0;
263  to_next += 1;
264  n_left_to_next -= 1;
265  goto trace;
266  }
267 
268  last_sa_index = sa_index0;
269  }
270 
271  if (PREDICT_FALSE (esp_seq_advance (sa0)))
272  {
273  clib_warning ("sequence number counter has cycled SPI %u",
274  sa0->spi);
275  if (is_ip6)
278  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
279  else
282  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
283  //TODO: rekey SA
284  to_next[0] = bi0;
285  to_next += 1;
286  n_left_to_next -= 1;
287  goto trace;
288  }
289 
290  orig_sz = b0->current_length;
291 
292  /* TODO multi-seg support - total_length_not_including_first_buffer */
294  (&ipsec_sa_counters, thread_index, sa_index0,
295  1, b0->current_length);
296 
297  res->ops[res->n_ops] = op;
298  res->bi[res->n_ops] = bi0;
299  res->n_ops += 1;
300 
301  dpdk_gcm_cnt_blk *icb = &priv->cb;
302 
303  crypto_set_icb (icb, sa0->salt, sa0->seq, sa0->seq_hi);
304 
305  iv_size = cipher_alg->iv_len;
306  trunc_size = auth_alg->trunc_size;
307 
308  /* if UDP encapsulation is used adjust the address of the IP header */
309  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && !is_ip6)
310  udp_encap_adv = sizeof (udp_header_t);
311 
312  if (ipsec_sa_is_set_IS_TUNNEL (sa0))
313  {
314  rewrite_len = 0;
315  if (!is_ip6 && !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)) /* ip4inip4 */
316  {
317  /* in tunnel mode send it back to FIB */
318  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP4_LOOKUP;
319  u8 adv = sizeof (ip4_header_t) + udp_encap_adv +
320  sizeof (esp_header_t) + iv_size;
321  vlib_buffer_advance (b0, -adv);
322  oh0 = vlib_buffer_get_current (b0);
323  ouh0 = vlib_buffer_get_current (b0);
324  next_hdr_type = IP_PROTOCOL_IP_IN_IP;
325  /*
326  * oh0->ip4.ip_version_and_header_length = 0x45;
327  * oh0->ip4.tos = ih0->ip4.tos;
328  * oh0->ip4.fragment_id = 0;
329  * oh0->ip4.flags_and_fragment_offset = 0;
330  */
331  oh0->ip4.checksum_data_64[0] =
332  clib_host_to_net_u64 (0x45ULL << 56);
333  /*
334  * oh0->ip4.ttl = 254;
335  * oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
336  */
337  oh0->ip4.checksum_data_32[2] =
338  clib_host_to_net_u32 (0xfe320000);
339 
340  oh0->ip4.src_address.as_u32 =
341  sa0->tunnel_src_addr.ip4.as_u32;
342  oh0->ip4.dst_address.as_u32 =
343  sa0->tunnel_dst_addr.ip4.as_u32;
344 
345  if (ipsec_sa_is_set_UDP_ENCAP (sa0))
346  {
347  oh0->ip4.protocol = IP_PROTOCOL_UDP;
348  esp0 = &ouh0->esp;
349  }
350  else
351  esp0 = &oh0->esp;
352  esp0->spi = clib_host_to_net_u32 (sa0->spi);
353  esp0->seq = clib_host_to_net_u32 (sa0->seq);
354  }
355  else if (is_ip6 && ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
356  {
357  /* ip6inip6 */
358  /* in tunnel mode send it back to FIB */
359  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP6_LOOKUP;
360 
361  u8 adv =
362  sizeof (ip6_header_t) + sizeof (esp_header_t) + iv_size;
363  vlib_buffer_advance (b0, -adv);
364  ih6_0 = (ip6_and_esp_header_t *) ih0;
365  oh6_0 = vlib_buffer_get_current (b0);
366 
367  next_hdr_type = IP_PROTOCOL_IPV6;
368 
369  oh6_0->ip6.ip_version_traffic_class_and_flow_label =
370  ih6_0->ip6.ip_version_traffic_class_and_flow_label;
371 
372  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
373  oh6_0->ip6.hop_limit = 254;
374  oh6_0->ip6.src_address.as_u64[0] =
375  sa0->tunnel_src_addr.ip6.as_u64[0];
376  oh6_0->ip6.src_address.as_u64[1] =
377  sa0->tunnel_src_addr.ip6.as_u64[1];
378  oh6_0->ip6.dst_address.as_u64[0] =
379  sa0->tunnel_dst_addr.ip6.as_u64[0];
380  oh6_0->ip6.dst_address.as_u64[1] =
381  sa0->tunnel_dst_addr.ip6.as_u64[1];
382  esp0 = &oh6_0->esp;
383  oh6_0->esp.spi = clib_host_to_net_u32 (sa0->spi);
384  oh6_0->esp.seq = clib_host_to_net_u32 (sa0->seq);
385  }
386  else /* unsupported ip4inip6, ip6inip4 */
387  {
388  if (is_ip6)
391  ESP_ENCRYPT_ERROR_NOSUP, 1);
392  else
395  ESP_ENCRYPT_ERROR_NOSUP, 1);
396  to_next[0] = bi0;
397  to_next += 1;
398  n_left_to_next -= 1;
399  goto trace;
400  }
401  vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
402  }
403  else /* transport mode */
404  {
405  priv->next = DPDK_CRYPTO_INPUT_NEXT_INTERFACE_OUTPUT;
406  rewrite_len = vnet_buffer (b0)->ip.save_rewrite_length;
407  u16 adv = sizeof (esp_header_t) + iv_size + udp_encap_adv;
408  vlib_buffer_advance (b0, -adv - rewrite_len);
409  u8 *src = ((u8 *) ih0) - rewrite_len;
411  oh0 = vlib_buffer_get_current (b0) + rewrite_len;
412 
413  if (is_ip6)
414  {
415  orig_sz -= sizeof (ip6_header_t);
416  ih6_0 = (ip6_and_esp_header_t *) ih0;
417  next_hdr_type = ih6_0->ip6.protocol;
418  memmove (dst, src, rewrite_len + sizeof (ip6_header_t));
419  oh6_0 = (ip6_and_esp_header_t *) oh0;
420  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
421  esp0 = &oh6_0->esp;
422  }
423  else /* ipv4 */
424  {
425  u16 ip_size = ip4_header_bytes (&ih0->ip4);
426  orig_sz -= ip_size;
427  next_hdr_type = ih0->ip4.protocol;
428  memmove (dst, src, rewrite_len + ip_size);
429  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
430  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
431  if (ipsec_sa_is_set_UDP_ENCAP (sa0))
432  {
433  oh0->ip4.protocol = IP_PROTOCOL_UDP;
434  esp0 = (esp_header_t *)
435  (((u8 *) oh0) + ip_size + udp_encap_adv);
436  }
437  else
438  {
439  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
440  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
441  }
442  }
443  esp0->spi = clib_host_to_net_u32 (sa0->spi);
444  esp0->seq = clib_host_to_net_u32 (sa0->seq);
445  }
446 
447  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
448  {
449  ouh0->udp.src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
450  ouh0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
451  ouh0->udp.checksum = 0;
452  }
453  ASSERT (is_pow2 (cipher_alg->boundary));
454  u16 mask = cipher_alg->boundary - 1;
455  u16 pad_payload_len = ((orig_sz + 2) + mask) & ~mask;
456  u8 pad_bytes = pad_payload_len - 2 - orig_sz;
457 
458  u8 *padding =
459  vlib_buffer_put_uninit (b0, pad_bytes + 2 + trunc_size);
460 
461  /* The extra pad bytes would be overwritten by the digest */
462  if (pad_bytes)
463  clib_memcpy_fast (padding, pad_data, 16);
464 
465  f0 = (esp_footer_t *) (padding + pad_bytes);
466  f0->pad_length = pad_bytes;
467  f0->next_header = next_hdr_type;
468 
469  if (is_ip6)
470  {
471  u16 len = b0->current_length - sizeof (ip6_header_t);
472  oh6_0->ip6.payload_length =
473  clib_host_to_net_u16 (len - rewrite_len);
474  }
475  else
476  {
477  oh0->ip4.length =
478  clib_host_to_net_u16 (b0->current_length - rewrite_len);
479  oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
480  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
481  {
482  ouh0->udp.length =
483  clib_host_to_net_u16 (clib_net_to_host_u16
484  (ouh0->ip4.length) -
485  ip4_header_bytes (&ouh0->ip4));
486  }
487  }
488 
489  b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
490 
491  /* mbuf packet starts at ESP header */
492  mb0->data_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
493  mb0->pkt_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
494  mb0->data_off = ((void *) esp0) - mb0->buf_addr;
495 
496  u32 cipher_off, cipher_len, auth_len = 0;
497  u32 *aad = NULL;
498 
499  u8 *digest = vlib_buffer_get_tail (b0) - trunc_size;
500  u64 digest_paddr =
501  mb0->buf_physaddr + digest - ((u8 *) mb0->buf_addr);
502 
503  if (!is_aead && cipher_alg->alg == RTE_CRYPTO_CIPHER_AES_CBC)
504  {
505  cipher_off = sizeof (esp_header_t);
506  cipher_len = iv_size + pad_payload_len;
507  }
508  else /* CTR/GCM */
509  {
510  u32 *esp_iv = (u32 *) (esp0 + 1);
511  esp_iv[0] = sa0->seq;
512  esp_iv[1] = sa0->seq_hi;
513 
514  cipher_off = sizeof (esp_header_t) + iv_size;
515  cipher_len = pad_payload_len;
516  }
517 
518  if (is_aead)
519  {
520  aad = (u32 *) priv->aad;
521  aad[0] = clib_host_to_net_u32 (sa0->spi);
522  aad[1] = clib_host_to_net_u32 (sa0->seq);
523 
524  /* aad[3] should always be 0 */
525  if (PREDICT_FALSE (ipsec_sa_is_set_USE_ESN (sa0)))
526  aad[2] = clib_host_to_net_u32 (sa0->seq_hi);
527  else
528  aad[2] = 0;
529  }
530  else
531  {
532  auth_len =
533  vlib_buffer_get_tail (b0) - ((u8 *) esp0) - trunc_size;
534  if (ipsec_sa_is_set_USE_ESN (sa0))
535  {
536  u32 *_digest = (u32 *) digest;
537  _digest[0] = clib_host_to_net_u32 (sa0->seq_hi);
538  auth_len += 4;
539  }
540  }
541 
542  crypto_op_setup (is_aead, mb0, op, session, cipher_off, cipher_len,
543  0, auth_len, (u8 *) aad, digest, digest_paddr);
544 
545  trace:
546  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
547  {
548  esp_encrypt_trace_t *tr =
549  vlib_add_trace (vm, node, b0, sizeof (*tr));
550  tr->crypto_alg = sa0->crypto_alg;
551  tr->integ_alg = sa0->integ_alg;
552  u8 *p = vlib_buffer_get_current (b0);
553  if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
554  p += vnet_buffer (b0)->ip.save_rewrite_length;
555  clib_memcpy_fast (tr->packet_data, p, sizeof (tr->packet_data));
556  }
557  }
558  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
559  }
560  if (is_ip6)
561  {
563  ESP_ENCRYPT_ERROR_RX_PKTS,
564  from_frame->n_vectors);
565 
567  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa);
568  }
569  else
570  {
572  ESP_ENCRYPT_ERROR_RX_PKTS,
573  from_frame->n_vectors);
574 
576  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa);
577  }
578 
579  crypto_free_ops (numa, ops, cwm->ops + from_frame->n_vectors - ops);
580 
581  return from_frame->n_vectors;
582 }
583 
585  vlib_node_runtime_t * node,
586  vlib_frame_t * from_frame)
587 {
588  return dpdk_esp_encrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ , 0);
589 }
590 
591 /* *INDENT-OFF* */
593  .name = "dpdk-esp4-encrypt",
594  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
595  .vector_size = sizeof (u32),
596  .format_trace = format_esp_encrypt_trace,
597  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
598  .error_strings = esp_encrypt_error_strings,
599  .n_next_nodes = 1,
600  .next_nodes =
601  {
602  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
603  }
604 };
605 /* *INDENT-ON* */
606 
608  vlib_node_runtime_t * node,
609  vlib_frame_t * from_frame)
610 {
611  return dpdk_esp_encrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ , 0);
612 }
613 
614 /* *INDENT-OFF* */
616  .name = "dpdk-esp6-encrypt",
617  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
618  .vector_size = sizeof (u32),
619  .format_trace = format_esp_encrypt_trace,
620  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
621  .error_strings = esp_encrypt_error_strings,
622  .n_next_nodes = 1,
623  .next_nodes =
624  {
625  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
626  }
627 };
628 /* *INDENT-ON* */
629 
631  vlib_node_runtime_t * node,
632  vlib_frame_t * from_frame)
633 {
634  return dpdk_esp_encrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ , 1);
635 }
636 
637 /* *INDENT-OFF* */
639  .name = "dpdk-esp4-encrypt-tun",
640  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
641  .vector_size = sizeof (u32),
642  .format_trace = format_esp_encrypt_trace,
643  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
644  .error_strings = esp_encrypt_error_strings,
645  .n_next_nodes = 1,
646  .next_nodes =
647  {
648  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
649  }
650 };
651 
652 VNET_FEATURE_INIT (dpdk_esp4_encrypt_tun_feat_node, static) =
653 {
654  .arc_name = "ip4-output",
655  .node_name = "dpdk-esp4-encrypt-tun",
656  .runs_before = VNET_FEATURES ("adj-midchain-tx"),
657 };
658 /* *INDENT-ON* */
659 
661  vlib_node_runtime_t * node,
662  vlib_frame_t * from_frame)
663 {
664  return dpdk_esp_encrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ , 1);
665 }
666 
667 /* *INDENT-OFF* */
669  .name = "dpdk-esp6-encrypt-tun",
670  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
671  .vector_size = sizeof (u32),
672  .format_trace = format_esp_encrypt_trace,
673  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
674  .error_strings = esp_encrypt_error_strings,
675  .n_next_nodes = 1,
676  .next_nodes =
677  {
678  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
679  }
680 };
681 
682 VNET_FEATURE_INIT (dpdk_esp6_encrypt_tun_feat_node, static) =
683 {
684  .arc_name = "ip6-output",
685  .node_name = "dpdk-esp6-encrypt-tun",
686  .runs_before = VNET_FEATURES ("adj-midchain-tx"),
687 };
688 /* *INDENT-ON* */
689 
690 /*
691  * fd.io coding-style-patch-verification: ON
692  *
693  * Local Variables:
694  * eval: (c-set-style "gnu")
695  * End:
696  */
u32 alg
Definition: ipsec.h:81
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:124
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:109
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:347
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:310
#define CLIB_UNUSED(x)
Definition: clib.h:82
ip46_address_t tunnel_src_addr
Definition: ipsec_sa.h:156
vlib_node_registration_t dpdk_esp4_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_encrypt_node)
Definition: esp_encrypt.c:592
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:220
format_function_t format_ip4_header
Definition: format.h:83
ipsec_integ_alg_t
Definition: ipsec_sa.h:60
unsigned long u64
Definition: types.h:89
#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:277
ipsec_integ_alg_t integ_alg
Definition: ipsec_sa.h:153
u32 thread_index
Definition: main.h:197
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
static u8 * format_esp_encrypt_trace(u8 *s, va_list *args)
Definition: esp_encrypt.c:79
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
Definition: ipsec.h:339
ipsec_integ_alg_t integ_alg
Definition: esp_encrypt.c:70
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
ipsec_crypto_alg_t crypto_alg
Definition: esp_encrypt.c:69
vl_api_ip4_address_t dst
Definition: ipsec_gre.api:39
#define VLIB_NODE_FN(node)
Definition: node.h:201
unsigned char u8
Definition: types.h:56
static_always_inline void crypto_enqueue_ops(vlib_main_t *vm, crypto_worker_main_t *cwm, u32 node_index, u32 error, u8 numa)
Definition: ipsec.h:305
u32 bi[VLIB_FRAME_SIZE]
Definition: ipsec.h:122
u32 seq_hi
Definition: ipsec_sa.h:123
static int esp_seq_advance(ipsec_sa_t *sa)
Definition: esp.h:80
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:231
static_always_inline void crypto_free_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
Definition: ipsec.h:293
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.c:25
ipsec_main_t ipsec_main
Definition: ipsec.c:28
#define always_inline
Definition: clib.h:98
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:77
unsigned int u32
Definition: types.h:88
u32 padding
Definition: vhost_user.h:115
crypto_alg_t * auth_algs
Definition: ipsec.h:160
static const u8 pad_data[]
Definition: ipsec.h:169
u32 next
Definition: ipsec.h:60
esp_encrypt_error_t
Definition: esp_encrypt.c:49
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:282
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
vlib_node_registration_t dpdk_esp6_encrypt_tun_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_tun_node)
Definition: esp_encrypt.c:668
crypto_alg_t * cipher_algs
Definition: ipsec.h:159
u32 salt
Definition: ipsec_sa.h:163
unsigned short u16
Definition: types.h:57
#define rte_mbuf_from_vlib_buffer(x)
Definition: buffer.h:19
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:111
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
#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:368
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1180
u8 len
Definition: ip_types.api:49
ip46_address_t tunnel_dst_addr
Definition: ipsec_sa.h:157
u8 aad[16]
Definition: ipsec.h:63
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
vlib_node_registration_t dpdk_esp4_encrypt_tun_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_encrypt_tun_node)
Definition: esp_encrypt.c:638
u16 n_vectors
Definition: node.h:395
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:212
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:312
dpdk_gcm_cnt_blk cb
Definition: ipsec.h:62
#define foreach_esp_encrypt_error
Definition: esp_encrypt.c:44
vlib_node_registration_t dpdk_esp6_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_node)
Definition: esp_encrypt.c:615
#define clib_warning(format, args...)
Definition: error.h:59
static char * esp_encrypt_error_strings[]
Definition: esp_encrypt.c:61
#define ARRAY_LEN(x)
Definition: clib.h:62
esp_encrypt_next_t
Definition: esp_encrypt.c:35
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:465
u8 * format_esp_header(u8 *s, va_list *args)
Definition: esp_format.c:23
u8 iv_len
Definition: ipsec.h:83
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
Definition: ipsec_sa.c:25
#define ASSERT(truth)
ipsec_sa_t * sad
Definition: ipsec.h:95
crypto_worker_main_t * workers_main
Definition: ipsec.h:156
u32 seq
Definition: esp.h:25
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
format_function_t format_ip6_header
Definition: format.h:97
u32 spi
Definition: esp.h:24
u8 boundary
Definition: ipsec.h:85
#define VNET_FEATURES(...)
Definition: feature.h:435
crypto_resource_t * resource
Definition: ipsec.h:158
static uword is_pow2(uword x)
Definition: clib.h:235
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
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
Definition: bihash_doc.h:44
Definition: defs.h:47
static uword dpdk_esp_encrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6, int is_tun)
Definition: esp_encrypt.c:111
VLIB buffer representation.
Definition: buffer.h:102
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:274
ipsec_crypto_alg_t
Definition: ipsec_sa.h:38
struct rte_crypto_op ** ops
Definition: ipsec.h:70
struct clib_bihash_value offset
template key/value backing page structure
enum rte_crypto_sym_xform_type type
Definition: ipsec.h:80
#define vnet_buffer(b)
Definition: buffer.h:369
static_always_inline u16 get_resource(crypto_worker_main_t *cwm, ipsec_sa_t *sa)
Definition: ipsec.h:252
ipsec_crypto_alg_t crypto_alg
Definition: ipsec_sa.h:150
#define VLIB_NODE_FLAG_IS_OUTPUT
Definition: node.h:295
#define foreach_esp_encrypt_next
Definition: esp_encrypt.c:30
static void * vlib_buffer_put_uninit(vlib_buffer_t *b, u16 size)
Append uninitialized data to buffer.
Definition: buffer.h:321
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
VNET_FEATURE_INIT(esp4_encrypt_tun_feat_node, static)
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
struct rte_crypto_op * ops[VLIB_FRAME_SIZE]
Definition: ipsec.h:121
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
static_always_inline dpdk_op_priv_t * crypto_op_get_priv(struct rte_crypto_op *op)
Definition: ipsec.h:201