FD.io VPP  v19.01.3-6-g70449b9b9
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/ipsec/ipsec.h>
26 #include <dpdk/device/dpdk.h>
27 #include <dpdk/device/dpdk_priv.h>
28 
29 #define foreach_esp_encrypt_next \
30 _(DROP, "error-drop") \
31 _(IP4_LOOKUP, "ip4-lookup") \
32 _(IP6_LOOKUP, "ip6-lookup") \
33 _(INTERFACE_OUTPUT, "interface-output")
34 
35 #define _(v, s) ESP_ENCRYPT_NEXT_##v,
36 typedef enum
37 {
39 #undef _
42 
43 #define foreach_esp_encrypt_error \
44  _(RX_PKTS, "ESP pkts received") \
45  _(SEQ_CYCLED, "Sequence number cycled") \
46  _(ENQ_FAIL, "Enqueue failed to crypto device") \
47  _(DISCARD, "Not enough crypto operations, discarding frame") \
48  _(SESSION, "Failed to get crypto session") \
49  _(NOSUP, "Cipher/Auth not supported")
50 
51 
52 typedef enum
53 {
54 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym,
56 #undef _
59 
60 static char *esp_encrypt_error_strings[] = {
61 #define _(sym,string) string,
63 #undef _
64 };
65 
68 
69 typedef struct
70 {
71  ipsec_crypto_alg_t crypto_alg;
72  ipsec_integ_alg_t integ_alg;
73  u8 packet_data[64];
75 
76 /* packet trace format function */
77 static u8 *
78 format_esp_encrypt_trace (u8 * s, va_list * args)
79 {
80  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
81  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
82  esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *);
84  u32 indent = format_get_indent (s), offset;
85 
86  s = format (s, "cipher %U auth %U\n",
89 
90  if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
91  {
92  s = format (s, "%U%U", format_white_space, indent,
93  format_ip6_header, ih4);
94  offset = sizeof (ip6_header_t);
95  }
96  else
97  {
98  s = format (s, "%U%U", format_white_space, indent,
99  format_ip4_header, ih4);
100  offset = ip4_header_bytes (ih4);
101  }
102 
103  s = format (s, "\n%U%U", format_white_space, indent,
105 
106  return s;
107 }
108 
111  vlib_node_runtime_t * node,
112  vlib_frame_t * from_frame, int is_ip6)
113 {
114  u32 n_left_from, *from, *to_next, next_index;
115  ipsec_main_t *im = &ipsec_main;
116  u32 thread_idx = vlib_get_thread_index ();
118  crypto_resource_t *res = 0;
119  ipsec_sa_t *sa0 = 0;
120  crypto_alg_t *cipher_alg = 0, *auth_alg = 0;
121  struct rte_cryptodev_sym_session *session = 0;
122  u32 ret, last_sa_index = ~0;
123  u8 numa = rte_socket_id ();
124  u8 is_aead = 0;
125  crypto_worker_main_t *cwm =
126  vec_elt_at_index (dcm->workers_main, thread_idx);
127  struct rte_crypto_op **ops = cwm->ops;
128 
129  from = vlib_frame_vector_args (from_frame);
130  n_left_from = from_frame->n_vectors;
131 
132  ret = crypto_alloc_ops (numa, ops, n_left_from);
133  if (ret)
134  {
135  if (is_ip6)
137  ESP_ENCRYPT_ERROR_DISCARD, 1);
138  else
140  ESP_ENCRYPT_ERROR_DISCARD, 1);
141  /* Discard whole frame */
142  return n_left_from;
143  }
144 
145  next_index = ESP_ENCRYPT_NEXT_DROP;
146 
147  while (n_left_from > 0)
148  {
149  u32 n_left_to_next;
150 
151  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
152 
153  while (n_left_from > 0 && n_left_to_next > 0)
154  {
155  clib_error_t *error;
156  u32 bi0;
157  vlib_buffer_t *b0 = 0;
158  u32 sa_index0;
159  ip4_and_esp_header_t *ih0, *oh0 = 0;
160  ip6_and_esp_header_t *ih6_0, *oh6_0 = 0;
161  ip4_and_udp_and_esp_header_t *ouh0 = 0;
162  esp_header_t *esp0;
163  esp_footer_t *f0;
164  u8 next_hdr_type;
165  u32 iv_size;
166  u16 orig_sz;
167  u8 trunc_size;
168  u16 rewrite_len;
169  u16 udp_encap_adv = 0;
170  struct rte_mbuf *mb0 = 0;
171  struct rte_crypto_op *op;
172  u16 res_idx;
173 
174  bi0 = from[0];
175  from += 1;
176  n_left_from -= 1;
177 
178  b0 = vlib_get_buffer (vm, bi0);
179  ih0 = vlib_buffer_get_current (b0);
180  mb0 = rte_mbuf_from_vlib_buffer (b0);
181 
182  /* ih0/ih6_0 */
183  CLIB_PREFETCH (ih0, sizeof (ih6_0[0]), LOAD);
184  /* f0 */
185  CLIB_PREFETCH (vlib_buffer_get_tail (b0), 20, STORE);
186  /* mb0 */
187  CLIB_PREFETCH (mb0, CLIB_CACHE_LINE_BYTES, STORE);
188 
189  op = ops[0];
190  ops += 1;
191  ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
192 
193  dpdk_op_priv_t *priv = crypto_op_get_priv (op);
194 
195  u16 op_len =
196  sizeof (op[0]) + sizeof (op[0].sym[0]) + sizeof (priv[0]);
197  CLIB_PREFETCH (op, op_len, STORE);
198 
199  sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
200 
201  if (sa_index0 != last_sa_index)
202  {
203  sa0 = pool_elt_at_index (im->sad, sa_index0);
204 
205  cipher_alg =
207  auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
208 
209  is_aead = (cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD);
210 
211  if (is_aead)
212  auth_alg = cipher_alg;
213 
214  res_idx = get_resource (cwm, sa0);
215 
216  if (PREDICT_FALSE (res_idx == (u16) ~ 0))
217  {
218  clib_warning ("unsupported SA by thread index %u",
219  thread_idx);
220  if (is_ip6)
223  ESP_ENCRYPT_ERROR_NOSUP, 1);
224  else
227  ESP_ENCRYPT_ERROR_NOSUP, 1);
228  to_next[0] = bi0;
229  to_next += 1;
230  n_left_to_next -= 1;
231  goto trace;
232  }
233  res = vec_elt_at_index (dcm->resource, res_idx);
234 
235  error = crypto_get_session (&session, sa_index0, res, cwm, 1);
236  if (PREDICT_FALSE (error || !session))
237  {
238  clib_warning ("failed to get crypto session");
239  if (is_ip6)
242  ESP_ENCRYPT_ERROR_SESSION,
243  1);
244  else
247  ESP_ENCRYPT_ERROR_SESSION,
248  1);
249  to_next[0] = bi0;
250  to_next += 1;
251  n_left_to_next -= 1;
252  goto trace;
253  }
254 
255  last_sa_index = sa_index0;
256  }
257 
258  if (PREDICT_FALSE (esp_seq_advance (sa0)))
259  {
260  clib_warning ("sequence number counter has cycled SPI %u",
261  sa0->spi);
262  if (is_ip6)
265  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
266  else
269  ESP_ENCRYPT_ERROR_SEQ_CYCLED, 1);
270  //TODO: rekey SA
271  to_next[0] = bi0;
272  to_next += 1;
273  n_left_to_next -= 1;
274  goto trace;
275  }
276 
277  orig_sz = b0->current_length;
278 
279  /* TODO multi-seg support - total_length_not_including_first_buffer */
280  sa0->total_data_size += b0->current_length;
281 
282  res->ops[res->n_ops] = op;
283  res->bi[res->n_ops] = bi0;
284  res->n_ops += 1;
285 
286  dpdk_gcm_cnt_blk *icb = &priv->cb;
287 
288  crypto_set_icb (icb, sa0->salt, sa0->seq, sa0->seq_hi);
289 
290  iv_size = cipher_alg->iv_len;
291  trunc_size = auth_alg->trunc_size;
292 
293  /* if UDP encapsulation is used adjust the address of the IP header */
294  if (sa0->udp_encap && !is_ip6)
295  udp_encap_adv = sizeof (udp_header_t);
296 
297  if (sa0->is_tunnel)
298  {
299  rewrite_len = 0;
300  if (!is_ip6 && !sa0->is_tunnel_ip6) /* ip4inip4 */
301  {
302  /* in tunnel mode send it back to FIB */
303  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP4_LOOKUP;
304  u8 adv = sizeof (ip4_header_t) + udp_encap_adv +
305  sizeof (esp_header_t) + iv_size;
306  vlib_buffer_advance (b0, -adv);
307  oh0 = vlib_buffer_get_current (b0);
308  ouh0 = vlib_buffer_get_current (b0);
309  next_hdr_type = IP_PROTOCOL_IP_IN_IP;
310  /*
311  * oh0->ip4.ip_version_and_header_length = 0x45;
312  * oh0->ip4.tos = ih0->ip4.tos;
313  * oh0->ip4.fragment_id = 0;
314  * oh0->ip4.flags_and_fragment_offset = 0;
315  */
316  oh0->ip4.checksum_data_64[0] =
317  clib_host_to_net_u64 (0x45ULL << 56);
318  /*
319  * oh0->ip4.ttl = 254;
320  * oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
321  */
322  oh0->ip4.checksum_data_32[2] =
323  clib_host_to_net_u32 (0xfe320000);
324 
325  oh0->ip4.src_address.as_u32 =
326  sa0->tunnel_src_addr.ip4.as_u32;
327  oh0->ip4.dst_address.as_u32 =
328  sa0->tunnel_dst_addr.ip4.as_u32;
329 
330  if (sa0->udp_encap)
331  {
332  oh0->ip4.protocol = IP_PROTOCOL_UDP;
333  esp0 = &ouh0->esp;
334  }
335  else
336  esp0 = &oh0->esp;
337  esp0->spi = clib_host_to_net_u32 (sa0->spi);
338  esp0->seq = clib_host_to_net_u32 (sa0->seq);
339  }
340  else if (is_ip6 && sa0->is_tunnel_ip6) /* ip6inip6 */
341  {
342  /* in tunnel mode send it back to FIB */
343  priv->next = DPDK_CRYPTO_INPUT_NEXT_IP6_LOOKUP;
344 
345  u8 adv =
346  sizeof (ip6_header_t) + sizeof (esp_header_t) + iv_size;
347  vlib_buffer_advance (b0, -adv);
348  ih6_0 = (ip6_and_esp_header_t *) ih0;
349  oh6_0 = vlib_buffer_get_current (b0);
350 
351  next_hdr_type = IP_PROTOCOL_IPV6;
352 
353  oh6_0->ip6.ip_version_traffic_class_and_flow_label =
354  ih6_0->ip6.ip_version_traffic_class_and_flow_label;
355 
356  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
357  oh6_0->ip6.hop_limit = 254;
358  oh6_0->ip6.src_address.as_u64[0] =
359  sa0->tunnel_src_addr.ip6.as_u64[0];
360  oh6_0->ip6.src_address.as_u64[1] =
361  sa0->tunnel_src_addr.ip6.as_u64[1];
362  oh6_0->ip6.dst_address.as_u64[0] =
363  sa0->tunnel_dst_addr.ip6.as_u64[0];
364  oh6_0->ip6.dst_address.as_u64[1] =
365  sa0->tunnel_dst_addr.ip6.as_u64[1];
366  esp0 = &oh6_0->esp;
367  oh6_0->esp.spi = clib_host_to_net_u32 (sa0->spi);
368  oh6_0->esp.seq = clib_host_to_net_u32 (sa0->seq);
369  }
370  else /* unsupported ip4inip6, ip6inip4 */
371  {
372  if (is_ip6)
375  ESP_ENCRYPT_ERROR_NOSUP, 1);
376  else
379  ESP_ENCRYPT_ERROR_NOSUP, 1);
380  to_next[0] = bi0;
381  to_next += 1;
382  n_left_to_next -= 1;
383  goto trace;
384  }
385  vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
386  }
387  else /* transport mode */
388  {
389  priv->next = DPDK_CRYPTO_INPUT_NEXT_INTERFACE_OUTPUT;
390  rewrite_len = vnet_buffer (b0)->ip.save_rewrite_length;
391  u16 adv = sizeof (esp_header_t) + iv_size + udp_encap_adv;
392  vlib_buffer_advance (b0, -adv - rewrite_len);
393  u8 *src = ((u8 *) ih0) - rewrite_len;
395  oh0 = vlib_buffer_get_current (b0) + rewrite_len;
396 
397  if (is_ip6)
398  {
399  orig_sz -= sizeof (ip6_header_t);
400  ih6_0 = (ip6_and_esp_header_t *) ih0;
401  next_hdr_type = ih6_0->ip6.protocol;
402  memmove (dst, src, rewrite_len + sizeof (ip6_header_t));
403  oh6_0 = (ip6_and_esp_header_t *) oh0;
404  oh6_0->ip6.protocol = IP_PROTOCOL_IPSEC_ESP;
405  esp0 = &oh6_0->esp;
406  }
407  else /* ipv4 */
408  {
409  u16 ip_size = ip4_header_bytes (&ih0->ip4);
410  orig_sz -= ip_size;
411  next_hdr_type = ih0->ip4.protocol;
412  memmove (dst, src, rewrite_len + ip_size);
413  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
414  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
415  if (sa0->udp_encap)
416  {
417  oh0->ip4.protocol = IP_PROTOCOL_UDP;
418  esp0 = (esp_header_t *)
419  (((u8 *) oh0) + ip_size + udp_encap_adv);
420  }
421  else
422  {
423  oh0->ip4.protocol = IP_PROTOCOL_IPSEC_ESP;
424  esp0 = (esp_header_t *) (((u8 *) oh0) + ip_size);
425  }
426  }
427  esp0->spi = clib_host_to_net_u32 (sa0->spi);
428  esp0->seq = clib_host_to_net_u32 (sa0->seq);
429  }
430 
431  if (sa0->udp_encap && ouh0)
432  {
433  ouh0->udp.src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
434  ouh0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipsec);
435  ouh0->udp.checksum = 0;
436  }
437  ASSERT (is_pow2 (cipher_alg->boundary));
438  u16 mask = cipher_alg->boundary - 1;
439  u16 pad_payload_len = ((orig_sz + 2) + mask) & ~mask;
440  u8 pad_bytes = pad_payload_len - 2 - orig_sz;
441 
442  u8 *padding =
443  vlib_buffer_put_uninit (b0, pad_bytes + 2 + trunc_size);
444 
445  /* The extra pad bytes would be overwritten by the digest */
446  if (pad_bytes)
447  clib_memcpy_fast (padding, pad_data, 16);
448 
449  f0 = (esp_footer_t *) (padding + pad_bytes);
450  f0->pad_length = pad_bytes;
451  f0->next_header = next_hdr_type;
452 
453  if (is_ip6)
454  {
455  u16 len = b0->current_length - sizeof (ip6_header_t);
456  oh6_0->ip6.payload_length =
457  clib_host_to_net_u16 (len - rewrite_len);
458  }
459  else
460  {
461  oh0->ip4.length =
462  clib_host_to_net_u16 (b0->current_length - rewrite_len);
463  oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
464  if (sa0->udp_encap && ouh0)
465  {
466  ouh0->udp.length =
467  clib_host_to_net_u16 (clib_net_to_host_u16
468  (ouh0->ip4.length) -
469  ip4_header_bytes (&ouh0->ip4));
470  }
471  }
472 
473  b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
474 
475  /* mbuf packet starts at ESP header */
476  mb0->data_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
477  mb0->pkt_len = vlib_buffer_get_tail (b0) - ((u8 *) esp0);
478  mb0->data_off = ((void *) esp0) - mb0->buf_addr;
479 
480  u32 cipher_off, cipher_len, auth_len = 0;
481  u32 *aad = NULL;
482 
483  u8 *digest = vlib_buffer_get_tail (b0) - trunc_size;
484  u64 digest_paddr =
485  mb0->buf_physaddr + digest - ((u8 *) mb0->buf_addr);
486 
487  if (!is_aead && cipher_alg->alg == RTE_CRYPTO_CIPHER_AES_CBC)
488  {
489  cipher_off = sizeof (esp_header_t);
490  cipher_len = iv_size + pad_payload_len;
491  }
492  else /* CTR/GCM */
493  {
494  u32 *esp_iv = (u32 *) (esp0 + 1);
495  esp_iv[0] = sa0->seq;
496  esp_iv[1] = sa0->seq_hi;
497 
498  cipher_off = sizeof (esp_header_t) + iv_size;
499  cipher_len = pad_payload_len;
500  }
501 
502  if (is_aead)
503  {
504  aad = (u32 *) priv->aad;
505  aad[0] = clib_host_to_net_u32 (sa0->spi);
506  aad[1] = clib_host_to_net_u32 (sa0->seq);
507 
508  /* aad[3] should always be 0 */
509  if (PREDICT_FALSE (sa0->use_esn))
510  aad[2] = clib_host_to_net_u32 (sa0->seq_hi);
511  else
512  aad[2] = 0;
513  }
514  else
515  {
516  auth_len =
517  vlib_buffer_get_tail (b0) - ((u8 *) esp0) - trunc_size;
518  if (sa0->use_esn)
519  {
520  u32 *_digest = (u32 *) digest;
521  _digest[0] = clib_host_to_net_u32 (sa0->seq_hi);
522  auth_len += 4;
523  }
524  }
525 
526  crypto_op_setup (is_aead, mb0, op, session, cipher_off, cipher_len,
527  0, auth_len, (u8 *) aad, digest, digest_paddr);
528 
529  trace:
530  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
531  {
532  esp_encrypt_trace_t *tr =
533  vlib_add_trace (vm, node, b0, sizeof (*tr));
534  tr->crypto_alg = sa0->crypto_alg;
535  tr->integ_alg = sa0->integ_alg;
536  u8 *p = vlib_buffer_get_current (b0);
537  if (!sa0->is_tunnel)
538  p += vnet_buffer (b0)->ip.save_rewrite_length;
539  clib_memcpy_fast (tr->packet_data, p, sizeof (tr->packet_data));
540  }
541  }
542  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
543  }
544  if (is_ip6)
545  {
547  ESP_ENCRYPT_ERROR_RX_PKTS,
548  from_frame->n_vectors);
549 
550  crypto_enqueue_ops (vm, cwm, 1, dpdk_esp6_encrypt_node.index,
551  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa);
552  }
553  else
554  {
556  ESP_ENCRYPT_ERROR_RX_PKTS,
557  from_frame->n_vectors);
558 
559  crypto_enqueue_ops (vm, cwm, 1, dpdk_esp4_encrypt_node.index,
560  ESP_ENCRYPT_ERROR_ENQ_FAIL, numa);
561  }
562 
563  crypto_free_ops (numa, ops, cwm->ops + from_frame->n_vectors - ops);
564 
565  return from_frame->n_vectors;
566 }
567 
569  vlib_node_runtime_t * node,
570  vlib_frame_t * from_frame)
571 {
572  return dpdk_esp_encrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ );
573 }
574 
575 /* *INDENT-OFF* */
577  .name = "dpdk-esp4-encrypt",
578  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
579  .vector_size = sizeof (u32),
580  .format_trace = format_esp_encrypt_trace,
581  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
582  .error_strings = esp_encrypt_error_strings,
583  .n_next_nodes = 1,
584  .next_nodes =
585  {
586  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
587  }
588 };
589 /* *INDENT-ON* */
590 
592  vlib_node_runtime_t * node,
593  vlib_frame_t * from_frame)
594 {
595  return dpdk_esp_encrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ );
596 }
597 
598 /* *INDENT-OFF* */
600  .name = "dpdk-esp6-encrypt",
601  .flags = VLIB_NODE_FLAG_IS_OUTPUT,
602  .vector_size = sizeof (u32),
603  .format_trace = format_esp_encrypt_trace,
604  .n_errors = ARRAY_LEN (esp_encrypt_error_strings),
605  .error_strings = esp_encrypt_error_strings,
606  .n_next_nodes = 1,
607  .next_nodes =
608  {
609  [ESP_ENCRYPT_NEXT_DROP] = "error-drop",
610  }
611 };
612 /* *INDENT-ON* */
613 
614 /*
615  * fd.io coding-style-patch-verification: ON
616  *
617  * Local Variables:
618  * eval: (c-set-style "gnu")
619  * End:
620  */
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
vl_api_address_t src
Definition: vxlan_gbp.api:32
#define CLIB_UNUSED(x)
Definition: clib.h:82
ip46_address_t tunnel_src_addr
Definition: ipsec.h:139
vlib_node_registration_t dpdk_esp4_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp4_encrypt_node)
Definition: esp_encrypt.c:576
format_function_t format_ip4_header
Definition: format.h:83
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:276
ipsec_integ_alg_t integ_alg
Definition: ipsec.h:129
static u8 * format_esp_encrypt_trace(u8 *s, va_list *args)
Definition: esp_encrypt.c:78
static_always_inline void crypto_set_icb(dpdk_gcm_cnt_blk *icb, u32 salt, u32 seq, u32 seq_hi)
Definition: ipsec.h:338
u8 is_tunnel
Definition: ipsec.h:136
ipsec_integ_alg_t integ_alg
Definition: esp_encrypt.c:69
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
ipsec_crypto_alg_t crypto_alg
Definition: esp_encrypt.c:68
#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
unsigned char u8
Definition: types.h:56
u32 spi
Definition: ipsec.h:122
u32 bi[VLIB_FRAME_SIZE]
Definition: ipsec.h:121
u32 seq_hi
Definition: ipsec.h:147
static int esp_seq_advance(ipsec_sa_t *sa)
Definition: esp.h:182
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
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.c:24
ipsec_main_t ipsec_main
Definition: ipsec.c:30
#define always_inline
Definition: clib.h:98
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 udp_encap
Definition: ipsec.h:138
u32 next
Definition: ipsec.h:60
esp_encrypt_error_t
Definition: esp_encrypt.c:49
#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
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
#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
ip46_address_t tunnel_dst_addr
Definition: ipsec.h:140
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
vl_api_address_t dst
Definition: vxlan_gbp.api:33
dpdk_gcm_cnt_blk cb
Definition: ipsec.h:61
#define foreach_esp_encrypt_error
Definition: esp_encrypt.c:43
vlib_node_registration_t dpdk_esp6_encrypt_node
(constructor) VLIB_REGISTER_NODE (dpdk_esp6_encrypt_node)
Definition: esp_encrypt.c:599
#define clib_warning(format, args...)
Definition: error.h:59
static char * esp_encrypt_error_strings[]
Definition: esp_encrypt.c:60
#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:452
u8 * format_esp_header(u8 *s, va_list *args)
Definition: esp_format.c:23
u8 iv_len
Definition: ipsec.h:82
#define ASSERT(truth)
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
u32 spi
Definition: esp.h:23
u8 boundary
Definition: ipsec.h:84
crypto_resource_t * resource
Definition: ipsec.h:157
static uword is_pow2(uword x)
Definition: clib.h:235
u32 seq
Definition: ipsec.h:146
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
static uword dpdk_esp_encrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6)
Definition: esp_encrypt.c:110
struct _vlib_node_registration vlib_node_registration_t
template key/value backing page structure
Definition: bihash_doc.h:44
Definition: defs.h:47
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
struct clib_bihash_value offset
template key/value backing page structure
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
#define VLIB_NODE_FLAG_IS_OUTPUT
Definition: node.h:320
#define foreach_esp_encrypt_next
Definition: esp_encrypt.c:29
static void * vlib_buffer_put_uninit(vlib_buffer_t *b, u16 size)
Append uninitialized data to buffer.
Definition: buffer.h:306
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
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
static_always_inline dpdk_op_priv_t * crypto_op_get_priv(struct rte_crypto_op *op)
Definition: ipsec.h:200