FD.io VPP  v20.01-48-g3e0dafb74
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 
71 
72 typedef struct
73 {
76  u8 packet_data[64];
78 
79 /* packet trace format function */
80 static u8 *
81 format_esp_encrypt_trace (u8 * s, va_list * args)
82 {
83  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
84  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
85  esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *);
87  u32 indent = format_get_indent (s), offset;
88 
89  s = format (s, "cipher %U auth %U\n",
92 
93  if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
94  {
95  s = format (s, "%U%U", format_white_space, indent,
96  format_ip6_header, ih4);
97  offset = sizeof (ip6_header_t);
98  }
99  else
100  {
101  s = format (s, "%U%U", format_white_space, indent,
102  format_ip4_header, ih4);
103  offset = ip4_header_bytes (ih4);
104  }
105 
106  s = format (s, "\n%U%U", format_white_space, indent,
108 
109  return s;
110 }
111 
115  vlib_frame_t * from_frame, int is_ip6, int is_tun)
116 {
117  u32 n_left_from, *from, *to_next, next_index, thread_index;
118  ipsec_main_t *im = &ipsec_main;
119  vnet_main_t *vnm = im->vnet_main;
121  u32 thread_idx = vlib_get_thread_index ();
123  crypto_resource_t *res = 0;
124  ipsec_sa_t *sa0 = 0;
125  crypto_alg_t *cipher_alg = 0, *auth_alg = 0;
126  struct rte_cryptodev_sym_session *session = 0;
127  u32 ret, last_sa_index = ~0;
128  u8 numa = rte_socket_id ();
129  u8 is_aead = 0;
130  crypto_worker_main_t *cwm =
131  vec_elt_at_index (dcm->workers_main, thread_idx);
132  struct rte_crypto_op **ops = cwm->ops;
133 
134  from = vlib_frame_vector_args (from_frame);
135  n_left_from = from_frame->n_vectors;
136  thread_index = vm->thread_index;
137 
138  ret = crypto_alloc_ops (numa, ops, n_left_from);
139  if (ret)
140  {
141  if (is_ip6)
143  ESP_ENCRYPT_ERROR_DISCARD, 1);
144  else
146  ESP_ENCRYPT_ERROR_DISCARD, 1);
147  /* Discard whole frame */
148  return n_left_from;
149  }
150 
151  next_index = ESP_ENCRYPT_NEXT_DROP;
152 
153  while (n_left_from > 0)
154  {
155  u32 n_left_to_next;
156 
157  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
158 
159  while (n_left_from > 0 && n_left_to_next > 0)
160  {
161  clib_error_t *error;
162  u32 bi0, bi1;
163  vlib_buffer_t *b0, *b1;
164  u32 sa_index0;
165  ip4_and_esp_header_t *ih0, *oh0 = 0;
166  ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
167  ip4_and_udp_and_esp_header_t *ouh0 = 0;
168  esp_header_t *esp0;
169  esp_footer_t *f0;
170  u8 next_hdr_type;
171  u32 iv_size;
172  u16 orig_sz;
173  u8 trunc_size;
174  u16 rewrite_len;
175  u16 udp_encap_adv = 0;
176  struct rte_mbuf *mb0;
177  struct rte_crypto_op *op;
178  u16 res_idx;
179 
180  bi0 = from[0];
181  from += 1;
182  n_left_from -= 1;
183 
184  b0 = vlib_get_buffer (vm, bi0);
185  ih0 = vlib_buffer_get_current (b0);
186  mb0 = rte_mbuf_from_vlib_buffer (b0);
187 
188  /* ih0/ih6_0 */
189  CLIB_PREFETCH (ih0, sizeof (ih6_0[0]), LOAD);
190  /* f0 */
191  CLIB_PREFETCH (vlib_buffer_get_tail (b0), 20, STORE);
192  /* mb0 */
193  CLIB_PREFETCH (mb0, CLIB_CACHE_LINE_BYTES, STORE);
194 
195  if (n_left_from > 1)
196  {
197  bi1 = from[1];
198  b1 = vlib_get_buffer (vm, bi1);
199 
202  CLIB_CACHE_LINE_BYTES, STORE);
203  }
204 
205  op = ops[0];
206  ops += 1;
207  ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
208 
209  dpdk_op_priv_t *priv = crypto_op_get_priv (op);
210  /* store bi in op private */
211  priv->bi = bi0;
212  priv->encrypt = 1;
213 
214  u16 op_len =
215  sizeof (op[0]) + sizeof (op[0].sym[0]) + sizeof (priv[0]);
216  CLIB_PREFETCH (op, op_len, STORE);
217 
218  if (is_tun)
219  {
220  u32 tmp;
221  /* we are on a ipsec tunnel's feature arc */
222  sa_index0 = *(u32 *) vnet_feature_next_with_data (&tmp, b0,
223  sizeof
224  (sa_index0));
225  }
226  else
227  sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
228 
229  if (sa_index0 != last_sa_index)
230  {
231  sa0 = pool_elt_at_index (im->sad, sa_index0);
232 
233  cipher_alg =
235  auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
236 
237  is_aead = (cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD);
238 
239  if (is_aead)
240  auth_alg = cipher_alg;
241 
242  res_idx = get_resource (cwm, sa0);
243 
244  if (PREDICT_FALSE (res_idx == (u16) ~ 0))
245  {
246  clib_warning ("unsupported SA by thread index %u",
247  thread_idx);
248  if (is_ip6)
251  ESP_ENCRYPT_ERROR_NOSUP, 1);
252  else
255  ESP_ENCRYPT_ERROR_NOSUP, 1);
256  to_next[0] = bi0;
257  to_next += 1;
258  n_left_to_next -= 1;
259  goto trace;
260  }
261  res = vec_elt_at_index (dcm->resource, res_idx);
262 
263  error = crypto_get_session (&session, sa_index0, res, cwm, 1);
264  if (PREDICT_FALSE (error || !session))
265  {
266  clib_warning ("failed to get crypto session");
267  if (is_ip6)
270  ESP_ENCRYPT_ERROR_SESSION,
271  1);
272  else
275  ESP_ENCRYPT_ERROR_SESSION,
276  1);
277  to_next[0] = bi0;
278  to_next += 1;
279  n_left_to_next -= 1;
280  goto trace;
281  }
282 
283  last_sa_index = sa_index0;
284  }
285 
286  if (PREDICT_FALSE (esp_seq_advance (sa0)))
287  {
289  ("sequence number counter has cycled SPI %u (0x%08x)",
290  sa0->spi, sa0->spi);
291  if (is_ip6)
294  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
295  else
298  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
299  //TODO: rekey SA
300  to_next[0] = bi0;
301  to_next += 1;
302  n_left_to_next -= 1;
303  goto trace;
304  }
305 
306  orig_sz = b0->current_length;
307 
308  /* TODO multi-seg support - total_length_not_including_first_buffer */
310  (&ipsec_sa_counters, thread_index, sa_index0,
311  1, b0->current_length);
312 
313  /* Update tunnel interface tx counters */
314  if (is_tun)
317  thread_index, vnet_buffer (b0)->sw_if_index[VLIB_TX],
318  1, b0->current_length);
319 
320  res->ops[res->n_ops] = op;
321  res->bi[res->n_ops] = bi0;
322  res->n_ops += 1;
323 
324  dpdk_gcm_cnt_blk *icb = &priv->cb;
325 
326  crypto_set_icb (icb, sa0->salt, sa0->seq, sa0->seq_hi);
327 
328  iv_size = cipher_alg->iv_len;
329  trunc_size = auth_alg->trunc_size;
330 
331  /* if UDP encapsulation is used adjust the address of the IP header */
332  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && !is_ip6)
333  udp_encap_adv = sizeof (udp_header_t);
334 
335  if (ipsec_sa_is_set_IS_TUNNEL (sa0))
336  {
337  rewrite_len = 0;
338  if (!ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)) /* ip4 */
339  {
340  /* in tunnel mode send it back to FIB */
341  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP4_LOOKUP;
342  u8 adv = sizeof (ip4_header_t) + udp_encap_adv +
343  sizeof (esp_header_t) + iv_size;
344  vlib_buffer_advance (b0, -adv);
345  oh0 = vlib_buffer_get_current (b0);
346  ouh0 = vlib_buffer_get_current (b0);
347  next_hdr_type = (is_ip6 ?
348  IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
349  /*
350  * oh0->ip4.ip_version_and_header_length = 0x45;
351  * oh0->ip4.tos = ih0->ip4.tos;
352  * oh0->ip4.fragment_id = 0;
353  * oh0->ip4.flags_and_fragment_offset = 0;
354  */
355  oh0->ip4.checksum_data_64[0] =
356  clib_host_to_net_u64 (0x45ULL << 56);
357  /*
358  * oh0->ip4.ttl = 254;
359  * oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
360  */
361  oh0->ip4.checksum_data_32[2] =
362  clib_host_to_net_u32 (0xfe320000);
363 
364  oh0->ip4.src_address.as_u32 =
365  sa0->tunnel_src_addr.ip4.as_u32;
366  oh0->ip4.dst_address.as_u32 =
367  sa0->tunnel_dst_addr.ip4.as_u32;
368 
369  if (ipsec_sa_is_set_UDP_ENCAP (sa0))
370  {
371  oh0->ip4.protocol = IP_PROTOCOL_UDP;
372  esp0 = &ouh0->esp;
373  }
374  else
375  esp0 = &oh0->esp;
376  esp0->spi = clib_host_to_net_u32 (sa0->spi);
377  esp0->seq = clib_host_to_net_u32 (sa0->seq);
378  }
379  else
380  {
381  /* ip6 */
382  /* in tunnel mode send it back to FIB */
383  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP6_LOOKUP;
384 
385  u8 adv =
386  sizeof (ip6_header_t) + sizeof (esp_header_t) + iv_size;
387  vlib_buffer_advance (b0, -adv);
388  ih6_0 = (ip6_and_esp_header_t *) ih0;
389  oh6_0 = vlib_buffer_get_current (b0);
390 
391  next_hdr_type = (is_ip6 ?
392  IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
393 
394  oh6_0->ip6.ip_version_traffic_class_and_flow_label =
395  ih6_0->ip6.ip_version_traffic_class_and_flow_label;
396 
397  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
398  oh6_0->ip6.hop_limit = 254;
399  oh6_0->ip6.src_address.as_u64[0] =
400  sa0->tunnel_src_addr.ip6.as_u64[0];
401  oh6_0->ip6.src_address.as_u64[1] =
402  sa0->tunnel_src_addr.ip6.as_u64[1];
403  oh6_0->ip6.dst_address.as_u64[0] =
404  sa0->tunnel_dst_addr.ip6.as_u64[0];
405  oh6_0->ip6.dst_address.as_u64[1] =
406  sa0->tunnel_dst_addr.ip6.as_u64[1];
407  esp0 = &oh6_0->esp;
408  oh6_0->esp.spi = clib_host_to_net_u32 (sa0->spi);
409  oh6_0->esp.seq = clib_host_to_net_u32 (sa0->seq);
410  }
411 
412  vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
413  }
414  else /* transport mode */
415  {
416  if (is_tun)
417  {
418  rewrite_len = 0;
419  priv->next = DPDK_CRYPTO_INPUT_NEXT_MIDCHAIN;
420  }
421  else
422  {
423  priv->next = DPDK_CRYPTO_INPUT_NEXT_INTERFACE_OUTPUT;
424  rewrite_len = vnet_buffer (b0)->ip.save_rewrite_length;
425  }
426  u16 adv = sizeof (esp_header_t) + iv_size + udp_encap_adv;
427  vlib_buffer_advance (b0, -adv - rewrite_len);
428  u8 *src = ((u8 *) ih0) - rewrite_len;
430  oh0 = vlib_buffer_get_current (b0) + rewrite_len;
431 
432  if (is_ip6)
433  {
434  orig_sz -= sizeof (ip6_header_t);
435  ih6_0 = (ip6_and_esp_header_t *) ih0;
436  next_hdr_type = ih6_0->ip6.protocol;
437  memmove (dst, src, rewrite_len + sizeof (ip6_header_t));
438  oh6_0 = (ip6_and_esp_header_t *) oh0;
439  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
440  esp0 = &oh6_0->esp;
441  }
442  else /* ipv4 */
443  {
444  u16 ip_size = ip4_header_bytes (&ih0->ip4);
445  orig_sz -= ip_size;
446  next_hdr_type = ih0->ip4.protocol;
447  memmove (dst, src, rewrite_len + ip_size);
448  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
449  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
450  if (ipsec_sa_is_set_UDP_ENCAP (sa0))
451  {
452  oh0->ip4.protocol = IP_PROTOCOL_UDP;
453  esp0 = (esp_header_t *)
454  (((u8 *) oh0) + ip_size + udp_encap_adv);
455  }
456  else
457  {
458  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
459  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
460  }
461  }
462  esp0->spi = clib_host_to_net_u32 (sa0->spi);
463  esp0->seq = clib_host_to_net_u32 (sa0->seq);
464  }
465 
466  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
467  {
468  ouh0->udp.src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
469  ouh0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
470  ouh0->udp.checksum = 0;
471  }
472  ASSERT (is_pow2 (cipher_alg->boundary));
473  u16 mask = cipher_alg->boundary - 1;
474  u16 pad_payload_len = ((orig_sz + 2) + mask) & ~mask;
475  u8 pad_bytes = pad_payload_len - 2 - orig_sz;
476 
477  u8 *padding =
478  vlib_buffer_put_uninit (b0, pad_bytes + 2 + trunc_size);
479 
480  /* The extra pad bytes would be overwritten by the digest */
481  if (pad_bytes)
482  clib_memcpy_fast (padding, pad_data, 16);
483 
484  f0 = (esp_footer_t *) (padding + pad_bytes);
485  f0->pad_length = pad_bytes;
486  f0->next_header = next_hdr_type;
487 
488  if (oh6_0)
489  {
490  u16 len = b0->current_length - sizeof (ip6_header_t);
491  oh6_0->ip6.payload_length =
492  clib_host_to_net_u16 (len - rewrite_len);
493  }
494  else if (oh0)
495  {
496  oh0->ip4.length =
497  clib_host_to_net_u16 (b0->current_length - rewrite_len);
498  oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
499  if (ipsec_sa_is_set_UDP_ENCAP (sa0) && ouh0)
500  {
501  ouh0->udp.length =
502  clib_host_to_net_u16 (clib_net_to_host_u16
503  (ouh0->ip4.length) -
504  ip4_header_bytes (&ouh0->ip4));
505  }
506  }
507  else /* should never happen */
508  clib_warning ("No outer header found for ESP packet");
509 
510  b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
511 
512  /* mbuf packet starts at ESP header */
513  mb0->data_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
514  mb0->pkt_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
515  mb0->data_off = ((void *) esp0) - mb0->buf_addr;
516 
517  u32 cipher_off, cipher_len, auth_len = 0;
518  u32 *aad = NULL;
519 
520  u8 *digest = vlib_buffer_get_tail (b0) - trunc_size;
521  u64 digest_paddr =
522  mb0->buf_physaddr + digest - ((u8 *) mb0->buf_addr);
523 
524  if (!is_aead && (cipher_alg->alg == RTE_CRYPTO_CIPHER_AES_CBC ||
525  cipher_alg->alg == RTE_CRYPTO_CIPHER_NULL))
526  {
527  cipher_off = sizeof (esp_header_t);
528  cipher_len = iv_size + pad_payload_len;
529  }
530  else /* CTR/GCM */
531  {
532  u32 *esp_iv = (u32 *) (esp0 + 1);
533  esp_iv[0] = sa0->seq;
534  esp_iv[1] = sa0->seq_hi;
535 
536  cipher_off = sizeof (esp_header_t) + iv_size;
537  cipher_len = pad_payload_len;
538  }
539 
540  if (is_aead)
541  {
542  aad = (u32 *) priv->aad;
543  aad[0] = esp0->spi;
544 
545  /* aad[3] should always be 0 */
546  if (PREDICT_FALSE (ipsec_sa_is_set_USE_ESN (sa0)))
547  {
548  aad[1] = clib_host_to_net_u32 (sa0->seq_hi);
549  aad[2] = esp0->seq;
550  }
551  else
552  {
553  aad[1] = esp0->seq;
554  aad[2] = 0;
555  }
556  }
557  else
558  {
559  auth_len =
560  vlib_buffer_get_tail (b0) - ((u8 *) esp0) - trunc_size;
561  if (ipsec_sa_is_set_USE_ESN (sa0))
562  {
563  u32 *_digest = (u32 *) digest;
564  _digest[0] = clib_host_to_net_u32 (sa0->seq_hi);
565  auth_len += 4;
566  }
567  }
568 
569  crypto_op_setup (is_aead, mb0, op, session, cipher_off, cipher_len,
570  0, auth_len, (u8 *) aad, digest, digest_paddr);
571 
572  trace:
573  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
574  {
575  esp_encrypt_trace_t *tr =
576  vlib_add_trace (vm, node, b0, sizeof (*tr));
577  tr->crypto_alg = sa0->crypto_alg;
578  tr->integ_alg = sa0->integ_alg;
579  u8 *p = vlib_buffer_get_current (b0);
580  if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
581  p += vnet_buffer (b0)->ip.save_rewrite_length;
582  clib_memcpy_fast (tr->packet_data, p, sizeof (tr->packet_data));
583  }
584  }
585  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
586  }
587  if (is_ip6)
588  {
590  (is_tun ?
592  dpdk_esp6_encrypt_node.index),
593  ESP_ENCRYPT_ERROR_RX_PKTS,
594  from_frame->n_vectors);
595 
597  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa, 1 /* encrypt */ );
598  }
599  else
600  {
602  (is_tun ?
604  dpdk_esp4_encrypt_node.index),
605  ESP_ENCRYPT_ERROR_RX_PKTS,
606  from_frame->n_vectors);
607 
609  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa, 1 /* encrypt */ );
610  }
611 
612  crypto_free_ops (numa, ops, cwm->ops + from_frame->n_vectors - ops);
613 
614  return from_frame->n_vectors;
615 }
616 
619  vlib_frame_t * from_frame)
620 {
621  return dpdk_esp_encrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ , 0);
622 }
623 
624 /* *INDENT-OFF* */
626  .name = "dpdk-esp4-encrypt",
627  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
628  .vector_size = sizeof (u32),
629  .format_trace = format_esp_encrypt_trace,
630  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
631  .error_strings = esp_encrypt_error_strings,
632  .n_next_nodes = 1,
633  .next_nodes =
634  {
635  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
636  }
637 };
638 /* *INDENT-ON* */
639 
642  vlib_frame_t * from_frame)
643 {
644  return dpdk_esp_encrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ , 0);
645 }
646 
647 /* *INDENT-OFF* */
649  .name = "dpdk-esp6-encrypt",
650  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
651  .vector_size = sizeof (u32),
652  .format_trace = format_esp_encrypt_trace,
653  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
654  .error_strings = esp_encrypt_error_strings,
655  .n_next_nodes = 1,
656  .next_nodes =
657  {
658  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
659  }
660 };
661 /* *INDENT-ON* */
662 
665  vlib_frame_t * from_frame)
666 {
667  return dpdk_esp_encrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ , 1);
668 }
669 
670 /* *INDENT-OFF* */
672  .name = "dpdk-esp4-encrypt-tun",
673  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
674  .vector_size = sizeof (u32),
675  .format_trace = format_esp_encrypt_trace,
676  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
677  .error_strings = esp_encrypt_error_strings,
678  .n_next_nodes = 1,
679  .next_nodes =
680  {
681  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
682  }
683 };
684 
685 VNET_FEATURE_INIT (dpdk_esp4_encrypt_tun_feat_node, static) =
686 {
687  .arc_name = "ip4-output",
688  .node_name = "dpdk-esp4-encrypt-tun",
689  .runs_before = VNET_FEATURES ("adj-midchain-tx"),
690 };
691 /* *INDENT-ON* */
692 
695  vlib_frame_t * from_frame)
696 {
697  return dpdk_esp_encrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ , 1);
698 }
699 
700 /* *INDENT-OFF* */
702  .name = "dpdk-esp6-encrypt-tun",
703  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
704  .vector_size = sizeof (u32),
705  .format_trace = format_esp_encrypt_trace,
706  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
707  .error_strings = esp_encrypt_error_strings,
708  .n_next_nodes = 1,
709  .next_nodes =
710  {
711  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
712  }
713 };
714 
715 VNET_FEATURE_INIT (dpdk_esp6_encrypt_tun_feat_node, static) =
716 {
717  .arc_name = "ip6-output",
718  .node_name = "dpdk-esp6-encrypt-tun",
719  .runs_before = VNET_FEATURES ("adj-midchain-tx"),
720 };
721 /* *INDENT-ON* */
722 
723 /*
724  * fd.io coding-style-patch-verification: ON
725  *
726  * Local Variables:
727  * eval: (c-set-style "gnu")
728  * End:
729  */
u32 alg
Definition: ipsec.h:87
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
VNET_FEATURE_INIT(dpdk_esp4_encrypt_tun_feat_node, static)
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:110
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:357
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:898
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:625
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
vnet_interface_main_t interface_main
Definition: vnet.h:56
format_function_t format_ip4_header
Definition: format.h:81
ipsec_integ_alg_t
Definition: ipsec_sa.h:58
esp_encrypt_next_t
Definition: esp_encrypt.c:37
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:284
ipsec_integ_alg_t integ_alg
Definition: ipsec_sa.h:152
u32 thread_index
Definition: main.h:218
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:81
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
Definition: ipsec.h:349
u8 data[0]
Packet data.
Definition: buffer.h:181
vl_api_address_t src
Definition: gre.api:60
ipsec_integ_alg_t integ_alg
Definition: esp_encrypt.c:75
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:74
#define VLIB_NODE_FN(node)
Definition: node.h:202
unsigned char u8
Definition: types.h:56
u32 bi[VLIB_FRAME_SIZE]
Definition: ipsec.h:128
u32 seq_hi
Definition: ipsec_sa.h:121
static int esp_seq_advance(ipsec_sa_t *sa)
Definition: esp.h:84
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:238
static_always_inline void crypto_free_ops(u8 numa, struct rte_crypto_op **ops, u32 n)
Definition: ipsec.h:300
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.c:25
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
ipsec_main_t ipsec_main
Definition: ipsec.c:28
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:863
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
static_always_inline void crypto_enqueue_ops(vlib_main_t *vm, crypto_worker_main_t *cwm, u32 node_index, u32 error, u8 numa, u8 encrypt)
Definition: ipsec.h:312
#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:78
unsigned int u32
Definition: types.h:88
u32 padding
Definition: vhost_user.h:141
crypto_alg_t * auth_algs
Definition: ipsec.h:167
static const u8 pad_data[]
Definition: ipsec.h:176
bool is_ip6
Definition: ip.api:43
u32 next
Definition: ipsec.h:64
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
Definition: feature.h:289
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:519
vlib_node_registration_t dpdk_esp6_encrypt_tun_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_tun_node)
Definition: esp_encrypt.c:701
crypto_alg_t * cipher_algs
Definition: ipsec.h:166
u32 salt
Definition: ipsec_sa.h:165
vnet_main_t * vnet_main
Definition: ipsec.h:110
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
#define always_inline
Definition: ipsec.h:28
vl_api_address_t dst
Definition: gre.api:61
#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
vlib_main_t * vm
Definition: in2out_ed.c:1810
u8 encrypt
Definition: ipsec.h:66
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:91
ip46_address_t tunnel_dst_addr
Definition: ipsec_sa.h:157
u8 aad[16]
Definition: ipsec.h:69
#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:671
u16 n_vectors
Definition: node.h:397
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:218
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
dpdk_gcm_cnt_blk cb
Definition: ipsec.h:68
#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:648
#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
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:456
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1810
u8 * format_esp_header(u8 *s, va_list *args)
Definition: esp_format.c:23
u8 iv_len
Definition: ipsec.h:89
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
Definition: ipsec_sa.c:27
#define ASSERT(truth)
ipsec_sa_t * sad
Definition: ipsec.h:102
esp_encrypt_error_t
Definition: esp_encrypt.c:53
crypto_worker_main_t * workers_main
Definition: ipsec.h:163
u32 seq
Definition: esp.h:29
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:95
u32 spi
Definition: esp.h:26
u8 boundary
Definition: ipsec.h:91
#define VNET_FEATURES(...)
Definition: feature.h:442
crypto_resource_t * resource
Definition: ipsec.h:165
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:55
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:113
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:244
ipsec_crypto_alg_t
Definition: ipsec_sa.h:36
struct rte_crypto_op ** ops
Definition: ipsec.h:76
struct clib_bihash_value offset
template key/value backing page structure
enum rte_crypto_sym_xform_type type
Definition: ipsec.h:86
#define vnet_buffer(b)
Definition: buffer.h:408
static_always_inline u16 get_resource(crypto_worker_main_t *cwm, ipsec_sa_t *sa)
Definition: ipsec.h:259
ipsec_crypto_alg_t crypto_alg
Definition: ipsec_sa.h:148
#define VLIB_NODE_FLAG_IS_OUTPUT
Definition: node.h:296
#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
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
struct rte_crypto_op * ops[VLIB_FRAME_SIZE]
Definition: ipsec.h:127
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:208