FD.io VPP  v21.06
Vector Packet Processing
esp_decrypt.c
Go to the documentation of this file.
1 /*
2  * esp_decrypt.c : IPSec ESP decrypt node
3  *
4  * Copyright (c) 2015 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/l2/l2_input.h>
22 
23 #include <vnet/ipsec/ipsec.h>
24 #include <vnet/ipsec/esp.h>
25 #include <vnet/ipsec/ipsec_io.h>
26 #include <vnet/ipsec/ipsec_tun.h>
27 
28 #include <vnet/gre/packet.h>
29 
30 #define foreach_esp_decrypt_next \
31  _ (DROP, "error-drop") \
32  _ (IP4_INPUT, "ip4-input-no-checksum") \
33  _ (IP6_INPUT, "ip6-input") \
34  _ (L2_INPUT, "l2-input") \
35  _ (MPLS_INPUT, "mpls-input") \
36  _ (HANDOFF, "handoff")
37 
38 #define _(v, s) ESP_DECRYPT_NEXT_##v,
39 typedef enum
40 {
42 #undef _
45 
46 #define foreach_esp_decrypt_post_next \
47  _ (DROP, "error-drop") \
48  _ (IP4_INPUT, "ip4-input-no-checksum") \
49  _ (IP6_INPUT, "ip6-input") \
50  _ (MPLS_INPUT, "mpls-input") \
51  _ (L2_INPUT, "l2-input")
52 
53 #define _(v, s) ESP_DECRYPT_POST_NEXT_##v,
54 typedef enum
55 {
57 #undef _
60 
61 #define foreach_esp_decrypt_error \
62  _ (RX_PKTS, "ESP pkts received") \
63  _ (RX_POST_PKTS, "ESP-POST pkts received") \
64  _ (HANDOFF, "hand-off") \
65  _ (DECRYPTION_FAILED, "ESP decryption failed") \
66  _ (INTEG_ERROR, "Integrity check failed") \
67  _ (CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
68  _ (REPLAY, "SA replayed packet") \
69  _ (RUNT, "undersized packet") \
70  _ (NO_BUFFERS, "no buffers (packet dropped)") \
71  _ (OVERSIZED_HEADER, "buffer with oversized header (dropped)") \
72  _ (NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \
73  _ (TUN_NO_PROTO, "no tunnel protocol") \
74  _ (UNSUP_PAYLOAD, "unsupported payload")
75 
76 typedef enum
77 {
78 #define _(sym,str) ESP_DECRYPT_ERROR_##sym,
80 #undef _
83 
84 static char *esp_decrypt_error_strings[] = {
85 #define _(sym,string) string,
87 #undef _
88 };
89 
90 typedef struct
91 {
95  ipsec_crypto_alg_t crypto_alg;
96  ipsec_integ_alg_t integ_alg;
98 
99 /* packet trace format function */
100 static u8 *
101 format_esp_decrypt_trace (u8 * s, va_list * args)
102 {
103  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
104  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
105  esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
106 
107  s =
108  format (s,
109  "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
111  t->integ_alg, t->seq, t->sa_seq, t->sa_seq_hi);
112  return s;
113 }
114 
115 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2)
116 
119  vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts,
120  int e)
121 {
122  vnet_crypto_op_t *op = ops;
123  u32 n_fail, n_ops = vec_len (ops);
124 
125  if (n_ops == 0)
126  return;
127 
128  n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
129 
130  while (n_fail)
131  {
132  ASSERT (op - ops < n_ops);
133  if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
134  {
135  u32 err, bi = op->user_data;
136  if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
137  err = e;
138  else
139  err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
140  b[bi]->error = node->errors[err];
141  nexts[bi] = ESP_DECRYPT_NEXT_DROP;
142  n_fail--;
143  }
144  op++;
145  }
146 }
147 
150  vnet_crypto_op_t * ops, vlib_buffer_t * b[],
151  u16 * nexts, vnet_crypto_op_chunk_t * chunks, int e)
152 {
153 
154  vnet_crypto_op_t *op = ops;
155  u32 n_fail, n_ops = vec_len (ops);
156 
157  if (PREDICT_TRUE (n_ops == 0))
158  return;
159 
160  n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops);
161 
162  while (n_fail)
163  {
164  ASSERT (op - ops < n_ops);
165  if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
166  {
167  u32 err, bi = op->user_data;
168  if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
169  err = e;
170  else
171  err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
172  b[bi]->error = node->errors[err];
173  nexts[bi] = ESP_DECRYPT_NEXT_DROP;
174  n_fail--;
175  }
176  op++;
177  }
178 }
179 
180 always_inline void
182  u16 tail)
183 {
184  vlib_buffer_t *before_last = b;
185 
186  if (last->current_length > tail)
187  {
188  last->current_length -= tail;
189  return;
190  }
191  ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
192 
193  while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
194  {
195  before_last = b;
196  b = vlib_get_buffer (vm, b->next_buffer);
197  }
198  before_last->current_length -= tail - last->current_length;
199  vlib_buffer_free_one (vm, before_last->next_buffer);
200  before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
201 }
202 
203 /* ICV is splitted in last two buffers so move it to the last buffer and
204  return pointer to it */
208  esp_decrypt_packet_data2_t * pd2, u16 icv_sz, u16 * dif)
209 {
210  vlib_buffer_t *before_last, *bp;
211  u16 last_sz = pd2->lb->current_length;
212  u16 first_sz = icv_sz - last_sz;
213 
214  bp = before_last = first;
215  while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
216  {
217  before_last = bp;
218  bp = vlib_get_buffer (vm, bp->next_buffer);
219  }
220 
221  u8 *lb_curr = vlib_buffer_get_current (pd2->lb);
222  memmove (lb_curr + first_sz, lb_curr, last_sz);
223  clib_memcpy_fast (lb_curr, vlib_buffer_get_tail (before_last) - first_sz,
224  first_sz);
225  before_last->current_length -= first_sz;
226  if (before_last == first)
227  pd->current_length -= first_sz;
228  clib_memset (vlib_buffer_get_tail (before_last), 0, first_sz);
229  if (dif)
230  dif[0] = first_sz;
231  pd2->lb = before_last;
232  pd2->icv_removed = 1;
233  pd2->free_buffer_index = before_last->next_buffer;
234  before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
235  return lb_curr;
236 }
237 
241  u8 ** digest, u16 * len, vlib_buffer_t * b, u8 * payload)
242 {
243  if (!ipsec_sa_is_set_USE_ESN (sa))
244  return 0;
245 
246  /* shift ICV by 4 bytes to insert ESN */
247  u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
248  u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa->seq_hi);
249 
250  if (pd2->icv_removed)
251  {
252  u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
253  if (space_left >= sz)
254  {
255  clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
256  *data_len += sz;
257  }
258  else
259  return sz;
260 
261  len[0] = b->current_length;
262  }
263  else
264  {
265  clib_memcpy_fast (tmp, payload + len[0], ESP_MAX_ICV_SIZE);
266  clib_memcpy_fast (payload + len[0], &seq_hi, sz);
267  clib_memcpy_fast (payload + len[0] + sz, tmp, ESP_MAX_ICV_SIZE);
268  *data_len += sz;
269  *digest += sz;
270  }
271  return sz;
272 }
273 
277  esp_decrypt_packet_data2_t * pd2, u16 icv_sz,
278  ipsec_sa_t * sa, u8 * extra_esn, u32 * len)
279 {
280  u16 dif = 0;
281  u8 *digest = esp_move_icv (vm, first, pd, pd2, icv_sz, &dif);
282  if (dif)
283  *len -= dif;
284 
285  if (ipsec_sa_is_set_USE_ESN (sa))
286  {
287  u8 sz = sizeof (sa->seq_hi);
288  u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
289  u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
290 
291  if (space_left >= sz)
292  {
293  clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
294  *len += sz;
295  }
296  else
297  {
298  /* no space for ESN at the tail, use the next buffer
299  * (with ICV data) */
300  ASSERT (pd2->icv_removed);
302  clib_memcpy_fast (vlib_buffer_get_current (tmp) - sz, &seq_hi, sz);
303  extra_esn[0] = 1;
304  }
305  }
306  return digest;
307 }
308 
312  ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
313  u8 * start_src, u32 start_len,
314  u8 ** digest, u16 * n_ch, u32 * integ_total_len)
315 {
318  u16 n_chunks = 1;
319  u32 total_len;
320  vec_add2 (ptd->chunks, ch, 1);
321  total_len = ch->len = start_len;
322  ch->src = start_src;
323 
324  while (1)
325  {
326  vec_add2 (ptd->chunks, ch, 1);
327  n_chunks += 1;
328  ch->src = vlib_buffer_get_current (cb);
329  if (pd2->lb == cb)
330  {
331  if (pd2->icv_removed)
332  ch->len = cb->current_length;
333  else
334  ch->len = cb->current_length - icv_sz;
335  if (ipsec_sa_is_set_USE_ESN (sa0))
336  {
337  u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
338  u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa0->seq_hi);
339  u8 *esn;
340  vlib_buffer_t *tmp_b;
341  u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
342  if (space_left < sz)
343  {
344  if (pd2->icv_removed)
345  {
346  /* use pre-data area from the last bufer
347  that was removed from the chain */
348  tmp_b = vlib_get_buffer (vm, pd2->free_buffer_index);
349  esn = tmp_b->data - sz;
350  }
351  else
352  {
353  /* no space, need to allocate new buffer */
354  u32 tmp_bi = 0;
355  if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1)
356  return -1;
357  tmp_b = vlib_get_buffer (vm, tmp_bi);
358  esn = tmp_b->data;
359  pd2->free_buffer_index = tmp_bi;
360  }
361  clib_memcpy_fast (esn, &seq_hi, sz);
362 
363  vec_add2 (ptd->chunks, ch, 1);
364  n_chunks += 1;
365  ch->src = esn;
366  ch->len = sz;
367  }
368  else
369  {
370  if (pd2->icv_removed)
371  {
373  (pd2->lb), &seq_hi, sz);
374  }
375  else
376  {
377  clib_memcpy_fast (tmp, *digest, ESP_MAX_ICV_SIZE);
378  clib_memcpy_fast (*digest, &seq_hi, sz);
379  clib_memcpy_fast (*digest + sz, tmp, ESP_MAX_ICV_SIZE);
380  *digest += sz;
381  }
382  ch->len += sz;
383  }
384  }
385  total_len += ch->len;
386  break;
387  }
388  else
389  total_len += ch->len = cb->current_length;
390 
391  if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
392  break;
393 
394  cb = vlib_get_buffer (vm, cb->next_buffer);
395  }
396 
397  if (n_ch)
398  *n_ch = n_chunks;
399  if (integ_total_len)
400  *integ_total_len = total_len;
401 
402  return 0;
403 }
404 
409  ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
410  u8 * start, u32 start_len, u8 ** tag, u16 * n_ch)
411 {
413  vlib_buffer_t *cb = b;
414  u16 n_chunks = 1;
415  u32 total_len;
416  vec_add2 (ptd->chunks, ch, 1);
417  total_len = ch->len = start_len;
418  ch->src = ch->dst = start;
419  cb = vlib_get_buffer (vm, cb->next_buffer);
420  n_chunks = 1;
421 
422  while (1)
423  {
424  vec_add2 (ptd->chunks, ch, 1);
425  n_chunks += 1;
426  ch->src = ch->dst = vlib_buffer_get_current (cb);
427  if (pd2->lb == cb)
428  {
429  if (ipsec_sa_is_set_IS_AEAD (sa0))
430  {
431  if (pd2->lb->current_length < icv_sz)
432  {
433  u16 dif = 0;
434  *tag = esp_move_icv (vm, b, pd, pd2, icv_sz, &dif);
435 
436  /* this chunk does not contain crypto data */
437  n_chunks -= 1;
438  /* and fix previous chunk's length as it might have
439  been changed */
440  ASSERT (n_chunks > 0);
441  if (pd2->lb == b)
442  {
443  total_len -= dif;
444  ch[-1].len -= dif;
445  }
446  else
447  {
448  total_len = total_len + pd2->lb->current_length -
449  ch[-1].len;
450  ch[-1].len = pd2->lb->current_length;
451  }
452  break;
453  }
454  else
455  *tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
456  }
457 
458  if (pd2->icv_removed)
459  total_len += ch->len = cb->current_length;
460  else
461  total_len += ch->len = cb->current_length - icv_sz;
462  }
463  else
464  total_len += ch->len = cb->current_length;
465 
466  if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
467  break;
468 
469  cb = vlib_get_buffer (vm, cb->next_buffer);
470  }
471 
472  if (n_ch)
473  *n_ch = n_chunks;
474 
475  return total_len;
476 }
477 
481  vnet_crypto_op_t *** crypto_ops,
482  vnet_crypto_op_t *** integ_ops,
483  vnet_crypto_op_t * op,
484  ipsec_sa_t * sa0, u8 * payload,
485  u16 len, u8 icv_sz, u8 iv_sz,
489 {
490  const u8 esp_sz = sizeof (esp_header_t);
491 
493  {
494  vnet_crypto_op_init (op, sa0->integ_op_id);
495  op->key_index = sa0->integ_key_index;
496  op->src = payload;
498  op->user_data = index;
499  op->digest = payload + len;
500  op->digest_len = icv_sz;
501  op->len = len;
502 
503  if (pd->is_chain)
504  {
505  /* buffer is chained */
506  op->len = pd->current_length;
507 
508  /* special case when ICV is splitted and needs to be reassembled
509  * first -> move it to the last buffer. Also take into account
510  * that ESN needs to be added after encrypted data and may or
511  * may not fit in the tail.*/
512  if (pd2->lb->current_length < icv_sz)
513  {
514  u8 extra_esn = 0;
515  op->digest =
516  esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0,
517  &extra_esn, &op->len);
518 
519  if (extra_esn)
520  {
521  /* esn is in the last buffer, that was unlinked from
522  * the chain */
523  op->len = b->current_length;
524  }
525  else
526  {
527  if (pd2->lb == b)
528  {
529  /* we now have a single buffer of crypto data, adjust
530  * the length (second buffer contains only ICV) */
531  *integ_ops = &ptd->integ_ops;
532  *crypto_ops = &ptd->crypto_ops;
533  len = b->current_length;
534  goto out;
535  }
536  }
537  }
538  else
539  op->digest = vlib_buffer_get_tail (pd2->lb) - icv_sz;
540 
542  op->chunk_index = vec_len (ptd->chunks);
543  if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz,
544  payload, pd->current_length,
545  &op->digest, &op->n_chunks, 0) < 0)
546  {
547  b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
548  next[0] = ESP_DECRYPT_NEXT_DROP;
549  return;
550  }
551  }
552  else
553  esp_insert_esn (vm, sa0, pd2, &op->len, &op->digest, &len, b,
554  payload);
555  out:
556  vec_add_aligned (*(integ_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
557  }
558 
559  payload += esp_sz;
560  len -= esp_sz;
561 
563  {
565  op->key_index = sa0->crypto_key_index;
566  op->iv = payload;
567 
568  if (ipsec_sa_is_set_IS_CTR (sa0))
569  {
570  /* construct nonce in a scratch space in front of the IP header */
571  esp_ctr_nonce_t *nonce =
572  (esp_ctr_nonce_t *) (payload - esp_sz - pd->hdr_sz -
573  sizeof (*nonce));
574  if (ipsec_sa_is_set_IS_AEAD (sa0))
575  {
576  /* constuct aad in a scratch space in front of the nonce */
577  esp_header_t *esp0 = (esp_header_t *) (payload - esp_sz);
578  op->aad = (u8 *) nonce - sizeof (esp_aead_t);
579  op->aad_len = esp_aad_fill (op->aad, esp0, sa0);
580  op->tag = payload + len;
581  op->tag_len = 16;
582  }
583  else
584  {
585  nonce->ctr = clib_host_to_net_u32 (1);
586  }
587  nonce->salt = sa0->salt;
588  ASSERT (sizeof (u64) == iv_sz);
589  nonce->iv = *(u64 *) op->iv;
590  op->iv = (u8 *) nonce;
591  }
592  op->src = op->dst = payload += iv_sz;
593  op->len = len - iv_sz;
594  op->user_data = index;
595 
596  if (pd->is_chain && (pd2->lb != b))
597  {
598  /* buffer is chained */
600  op->chunk_index = vec_len (ptd->chunks);
601  esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz,
602  payload, len - pd->iv_sz + pd->icv_sz,
603  &op->tag, &op->n_chunks);
604  }
605 
606  vec_add_aligned (*(crypto_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
607  }
608 }
609 
614  u8 *payload, u16 len, u8 icv_sz, u8 iv_sz,
617  vlib_buffer_t *b, u16 *next, u16 async_next)
618 {
619  const u8 esp_sz = sizeof (esp_header_t);
620  u32 current_protect_index = vnet_buffer (b)->ipsec.protect_index;
621  esp_decrypt_packet_data_t *async_pd = &(esp_post_data (b))->decrypt_data;
623  u8 *tag = payload + len, *iv = payload + esp_sz, *aad = 0;
624  u32 key_index;
625  u32 crypto_len, integ_len = 0;
626  i16 crypto_start_offset, integ_start_offset = 0;
627  u8 flags = 0;
628 
629  if (!ipsec_sa_is_set_IS_AEAD (sa0))
630  {
631  /* linked algs */
632  key_index = sa0->linked_key_index;
633  integ_start_offset = payload - b->data;
634  integ_len = len;
637 
638  if (pd->is_chain)
639  {
640  /* buffer is chained */
641  integ_len = pd->current_length;
642 
643  /* special case when ICV is splitted and needs to be reassembled
644  * first -> move it to the last buffer. Also take into account
645  * that ESN needs to be added after encrypted data and may or
646  * may not fit in the tail.*/
647  if (pd2->lb->current_length < icv_sz)
648  {
649  u8 extra_esn = 0;
650  tag = esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0,
651  &extra_esn, &integ_len);
652 
653  if (extra_esn)
654  {
655  /* esn is in the last buffer, that was unlinked from
656  * the chain */
657  integ_len = b->current_length;
658  }
659  else
660  {
661  if (pd2->lb == b)
662  {
663  /* we now have a single buffer of crypto data, adjust
664  * the length (second buffer contains only ICV) */
665  len = b->current_length;
666  goto out;
667  }
668  }
669  }
670  else
671  tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
672 
674  if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz, payload,
675  pd->current_length, &tag,
676  0, &integ_len) < 0)
677  {
678  /* allocate buffer failed, will not add to frame and drop */
679  return (ESP_DECRYPT_ERROR_NO_BUFFERS);
680  }
681  }
682  else
683  esp_insert_esn (vm, sa0, pd2, &integ_len, &tag, &len, b, payload);
684  }
685  else
686  key_index = sa0->crypto_key_index;
687 
688 out:
689  /* crypto */
690  payload += esp_sz;
691  len -= esp_sz;
692  iv = payload;
693 
694  if (ipsec_sa_is_set_IS_CTR (sa0))
695  {
696  /* construct nonce in a scratch space in front of the IP header */
697  esp_ctr_nonce_t *nonce =
698  (esp_ctr_nonce_t *) (payload - esp_sz - pd->hdr_sz - sizeof (*nonce));
699  if (ipsec_sa_is_set_IS_AEAD (sa0))
700  {
701  /* constuct aad in a scratch space in front of the nonce */
702  esp_header_t *esp0 = (esp_header_t *) (payload - esp_sz);
703  aad = (u8 *) nonce - sizeof (esp_aead_t);
704  esp_aad_fill (aad, esp0, sa0);
705  tag = payload + len;
706  }
707  else
708  {
709  nonce->ctr = clib_host_to_net_u32 (1);
710  }
711  nonce->salt = sa0->salt;
712  ASSERT (sizeof (u64) == iv_sz);
713  nonce->iv = *(u64 *) iv;
714  iv = (u8 *) nonce;
715  }
716 
717  crypto_start_offset = (payload += iv_sz) - b->data;
718  crypto_len = len - iv_sz;
719 
720  if (pd->is_chain && (pd2->lb != b))
721  {
722  /* buffer is chained */
724 
725  crypto_len = esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz,
726  payload,
727  len - pd->iv_sz + pd->icv_sz,
728  &tag, 0);
729  }
730 
731  *async_pd = *pd;
732  *async_pd2 = *pd2;
733  pd->protect_index = current_protect_index;
734 
735  /* for AEAD integ_len - crypto_len will be negative, it is ok since it
736  * is ignored by the engine. */
738  vm, f, key_index, crypto_len, integ_len - crypto_len, crypto_start_offset,
739  integ_start_offset, bi, async_next, iv, tag, aad, flags);
740 
741  return (ESP_DECRYPT_ERROR_RX_PKTS);
742 }
743 
748  u16 * next, int is_ip6, int is_tun, int is_async)
749 {
750  ipsec_sa_t *sa0 = ipsec_sa_get (pd->sa_index);
751  vlib_buffer_t *lb = b;
752  const u8 esp_sz = sizeof (esp_header_t);
753  const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL | IPSEC_SA_FLAG_IS_TUNNEL_V6;
754  u8 pad_length = 0, next_header = 0;
755  u16 icv_sz;
756 
757  /*
758  * redo the anti-reply check
759  * in this frame say we have sequence numbers, s, s+1, s+1, s+1
760  * and s and s+1 are in the window. When we did the anti-replay
761  * check above we did so against the state of the window (W),
762  * after packet s-1. So each of the packets in the sequence will be
763  * accepted.
764  * This time s will be cheked against Ws-1, s+1 chceked against Ws
765  * (i.e. the window state is updated/advnaced)
766  * so this time the successive s+! packet will be dropped.
767  * This is a consequence of batching the decrypts. If the
768  * check-dcrypt-advance process was done for each packet it would
769  * be fine. But we batch the decrypts because it's much more efficient
770  * to do so in SW and if we offload to HW and the process is async.
771  *
772  * You're probably thinking, but this means an attacker can send the
773  * above sequence and cause VPP to perform decrpyts that will fail,
774  * and that's true. But if the attacker can determine s (a valid
775  * sequence number in the window) which is non-trivial, it can generate
776  * a sequence s, s+1, s+2, s+3, ... s+n and nothing will prevent any
777  * implementation, sequential or batching, from decrypting these.
778  */
779  if (ipsec_sa_anti_replay_check (sa0, pd->seq))
780  {
781  b->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
782  next[0] = ESP_DECRYPT_NEXT_DROP;
783  return;
784  }
785 
787 
788  if (pd->is_chain)
789  {
790  lb = pd2->lb;
791  icv_sz = pd2->icv_removed ? 0 : pd->icv_sz;
792  if (pd2->free_buffer_index)
793  {
795  lb->next_buffer = 0;
796  }
797  if (lb->current_length < sizeof (esp_footer_t) + icv_sz)
798  {
799  /* esp footer is either splitted in two buffers or in the before
800  * last buffer */
801 
802  vlib_buffer_t *before_last = b, *bp = b;
803  while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
804  {
805  before_last = bp;
806  bp = vlib_get_buffer (vm, bp->next_buffer);
807  }
808  u8 *bt = vlib_buffer_get_tail (before_last);
809 
810  if (lb->current_length == icv_sz)
811  {
812  esp_footer_t *f = (esp_footer_t *) (bt - sizeof (*f));
813  pad_length = f->pad_length;
814  next_header = f->next_header;
815  }
816  else
817  {
818  pad_length = (bt - 1)[0];
819  next_header = ((u8 *) vlib_buffer_get_current (lb))[0];
820  }
821  }
822  else
823  {
824  esp_footer_t *f =
825  (esp_footer_t *) (lb->data + lb->current_data +
826  lb->current_length - sizeof (esp_footer_t) -
827  icv_sz);
828  pad_length = f->pad_length;
829  next_header = f->next_header;
830  }
831  }
832  else
833  {
834  icv_sz = pd->icv_sz;
835  esp_footer_t *f =
836  (esp_footer_t *) (lb->data + lb->current_data + lb->current_length -
837  sizeof (esp_footer_t) - icv_sz);
838  pad_length = f->pad_length;
839  next_header = f->next_header;
840  }
841 
842  u16 adv = pd->iv_sz + esp_sz;
843  u16 tail = sizeof (esp_footer_t) + pad_length + icv_sz;
844  u16 tail_orig = sizeof (esp_footer_t) + pad_length + pd->icv_sz;
845  b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
846 
847  if ((pd->flags & tun_flags) == 0 && !is_tun) /* transport mode */
848  {
849  u8 udp_sz = (is_ip6 == 0 && pd->flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
850  sizeof (udp_header_t) : 0;
851  u16 ip_hdr_sz = pd->hdr_sz - udp_sz;
852  u8 *old_ip = b->data + pd->current_data - ip_hdr_sz - udp_sz;
853  u8 *ip = old_ip + adv + udp_sz;
854 
855  if (is_ip6 && ip_hdr_sz > 64)
856  memmove (ip, old_ip, ip_hdr_sz);
857  else
858  clib_memcpy_le64 (ip, old_ip, ip_hdr_sz);
859 
860  b->current_data = pd->current_data + adv - ip_hdr_sz;
861  b->current_length += ip_hdr_sz - adv;
862  esp_remove_tail (vm, b, lb, tail);
863 
864  if (is_ip6)
865  {
866  ip6_header_t *ip6 = (ip6_header_t *) ip;
867  u16 len = clib_net_to_host_u16 (ip6->payload_length);
868  len -= adv + tail_orig;
869  ip6->payload_length = clib_host_to_net_u16 (len);
870  ip6->protocol = next_header;
871  next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
872  }
873  else
874  {
875  ip4_header_t *ip4 = (ip4_header_t *) ip;
876  ip_csum_t sum = ip4->checksum;
877  u16 len = clib_net_to_host_u16 (ip4->length);
878  len = clib_host_to_net_u16 (len - adv - tail_orig - udp_sz);
879  sum = ip_csum_update (sum, ip4->protocol, next_header,
881  sum = ip_csum_update (sum, ip4->length, len, ip4_header_t, length);
882  ip4->checksum = ip_csum_fold (sum);
883  ip4->protocol = next_header;
884  ip4->length = len;
885  next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
886  }
887  }
888  else
889  {
890  if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
891  {
892  next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
893  b->current_data = pd->current_data + adv;
894  b->current_length = pd->current_length - adv;
895  esp_remove_tail (vm, b, lb, tail);
896  }
897  else if (next_header == IP_PROTOCOL_IPV6)
898  {
899  next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
900  b->current_data = pd->current_data + adv;
901  b->current_length = pd->current_length - adv;
902  esp_remove_tail (vm, b, lb, tail);
903  }
904  else if (next_header == IP_PROTOCOL_MPLS_IN_IP)
905  {
906  next[0] = ESP_DECRYPT_NEXT_MPLS_INPUT;
907  b->current_data = pd->current_data + adv;
908  b->current_length = pd->current_length - adv;
909  esp_remove_tail (vm, b, lb, tail);
910  }
911  else
912  {
913  if (is_tun && next_header == IP_PROTOCOL_GRE)
914  {
915  gre_header_t *gre;
916 
917  b->current_data = pd->current_data + adv;
918  b->current_length = pd->current_length - adv - tail;
919 
920  gre = vlib_buffer_get_current (b);
921 
922  vlib_buffer_advance (b, sizeof (*gre));
923 
924  switch (clib_net_to_host_u16 (gre->protocol))
925  {
926  case GRE_PROTOCOL_teb:
927  vnet_update_l2_len (b);
928  next[0] = ESP_DECRYPT_NEXT_L2_INPUT;
929  break;
930  case GRE_PROTOCOL_ip4:
931  next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
932  break;
933  case GRE_PROTOCOL_ip6:
934  next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
935  break;
936  default:
937  b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
938  next[0] = ESP_DECRYPT_NEXT_DROP;
939  break;
940  }
941  }
942  else
943  {
944  next[0] = ESP_DECRYPT_NEXT_DROP;
945  b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
946  return;
947  }
948  }
949  if (is_tun)
950  {
951  if (ipsec_sa_is_set_IS_PROTECT (sa0))
952  {
953  /*
954  * There are two encap possibilities
955  * 1) the tunnel and ths SA are prodiving encap, i.e. it's
956  * MAC | SA-IP | TUN-IP | ESP | PAYLOAD
957  * implying the SA is in tunnel mode (on a tunnel interface)
958  * 2) only the tunnel provides encap
959  * MAC | TUN-IP | ESP | PAYLOAD
960  * implying the SA is in transport mode.
961  *
962  * For 2) we need only strip the tunnel encap and we're good.
963  * since the tunnel and crypto ecnap (int the tun=protect
964  * object) are the same and we verified above that these match
965  * for 1) we need to strip the SA-IP outer headers, to
966  * reveal the tunnel IP and then check that this matches
967  * the configured tunnel.
968  */
969  const ipsec_tun_protect_t *itp;
970 
971  if (is_async)
973  else
974  itp =
976  ipsec.protect_index);
977 
978  if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
979  {
980  const ip4_header_t *ip4;
981 
982  ip4 = vlib_buffer_get_current (b);
983 
985  &ip4->dst_address) ||
987  &ip4->src_address))
988  {
989  next[0] = ESP_DECRYPT_NEXT_DROP;
990  b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
991  }
992  }
993  else if (next_header == IP_PROTOCOL_IPV6)
994  {
995  const ip6_header_t *ip6;
996 
997  ip6 = vlib_buffer_get_current (b);
998 
1000  &ip6->dst_address) ||
1002  &ip6->src_address))
1003  {
1004  next[0] = ESP_DECRYPT_NEXT_DROP;
1005  b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
1006  }
1007  }
1008  }
1009  }
1010  }
1011 }
1012 
1015  vlib_frame_t *from_frame, int is_ip6, int is_tun,
1016  u16 async_next_node)
1017 {
1020  u16 len;
1021  ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
1022  u32 *from = vlib_frame_vector_args (from_frame);
1023  u32 n_left = from_frame->n_vectors;
1025  vlib_buffer_t *sync_bufs[VLIB_FRAME_SIZE];
1026  u16 sync_nexts[VLIB_FRAME_SIZE], *sync_next = sync_nexts, n_sync = 0;
1027  u16 async_nexts[VLIB_FRAME_SIZE], *async_next = async_nexts, n_async = 0;
1028  u16 noop_nexts[VLIB_FRAME_SIZE], *noop_next = noop_nexts, n_noop = 0;
1029  u32 sync_bi[VLIB_FRAME_SIZE];
1030  u32 noop_bi[VLIB_FRAME_SIZE];
1031  esp_decrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
1032  esp_decrypt_packet_data2_t pkt_data2[VLIB_FRAME_SIZE], *pd2 = pkt_data2;
1033  esp_decrypt_packet_data_t cpd = { };
1034  u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
1035  const u8 esp_sz = sizeof (esp_header_t);
1036  ipsec_sa_t *sa0 = 0;
1037  vnet_crypto_op_t _op, *op = &_op;
1038  vnet_crypto_op_t **crypto_ops;
1039  vnet_crypto_op_t **integ_ops;
1040  int is_async = im->async_mode;
1041  vnet_crypto_async_op_id_t async_op = ~0;
1043  esp_decrypt_error_t err;
1044 
1045  vlib_get_buffers (vm, from, b, n_left);
1046  if (!is_async)
1047  {
1049  vec_reset_length (ptd->integ_ops);
1052  }
1054  vec_reset_length (ptd->chunks);
1055  clib_memset (sync_nexts, -1, sizeof (sync_nexts));
1056  clib_memset (async_frames, 0, sizeof (async_frames));
1057 
1058  while (n_left > 0)
1059  {
1060  u8 *payload;
1061 
1062  err = ESP_DECRYPT_ERROR_RX_PKTS;
1063  if (n_left > 2)
1064  {
1065  u8 *p;
1066  vlib_prefetch_buffer_header (b[2], LOAD);
1067  p = vlib_buffer_get_current (b[1]);
1069  p -= CLIB_CACHE_LINE_BYTES;
1071  }
1072 
1073  u32 n_bufs = vlib_buffer_chain_linearize (vm, b[0]);
1074  if (n_bufs == 0)
1075  {
1076  err = ESP_DECRYPT_ERROR_NO_BUFFERS;
1077  esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
1078  ESP_DECRYPT_NEXT_DROP);
1079  goto next;
1080  }
1081 
1082  if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
1083  {
1084  if (current_sa_pkts)
1086  current_sa_index,
1087  current_sa_pkts,
1088  current_sa_bytes);
1089  current_sa_bytes = current_sa_pkts = 0;
1090 
1091  current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1092  sa0 = ipsec_sa_get (current_sa_index);
1093 
1094  /* fetch the second cacheline ASAP */
1095  CLIB_PREFETCH (sa0->cacheline1, CLIB_CACHE_LINE_BYTES, LOAD);
1096  cpd.icv_sz = sa0->integ_icv_size;
1097  cpd.iv_sz = sa0->crypto_iv_size;
1098  cpd.flags = sa0->flags;
1099  cpd.sa_index = current_sa_index;
1100  is_async = im->async_mode | ipsec_sa_is_set_IS_ASYNC (sa0);
1101  }
1102 
1103  if (is_async)
1104  {
1105  async_op = sa0->crypto_async_dec_op_id;
1106 
1107  /* get a frame for this op if we don't yet have one or it's full
1108  */
1109  if (NULL == async_frames[async_op] ||
1110  vnet_crypto_async_frame_is_full (async_frames[async_op]))
1111  {
1112  async_frames[async_op] =
1113  vnet_crypto_async_get_frame (vm, async_op);
1114  /* Save the frame to the list we'll submit at the end */
1115  vec_add1 (ptd->async_frames, async_frames[async_op]);
1116  }
1117  }
1118 
1119  if (PREDICT_FALSE (~0 == sa0->thread_index))
1120  {
1121  /* this is the first packet to use this SA, claim the SA
1122  * for this thread. this could happen simultaneously on
1123  * another thread */
1125  ipsec_sa_assign_thread (thread_index));
1126  }
1127 
1128  if (PREDICT_FALSE (thread_index != sa0->thread_index))
1129  {
1130  vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index;
1131  err = ESP_DECRYPT_ERROR_HANDOFF;
1132  esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
1133  ESP_DECRYPT_NEXT_HANDOFF);
1134  goto next;
1135  }
1136 
1137  /* store packet data for next round for easier prefetch */
1138  pd->sa_data = cpd.sa_data;
1139  pd->current_data = b[0]->current_data;
1140  pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
1141  payload = b[0]->data + pd->current_data;
1142  pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq);
1143  pd->is_chain = 0;
1144  pd2->lb = b[0];
1145  pd2->free_buffer_index = 0;
1146  pd2->icv_removed = 0;
1147 
1148  if (n_bufs > 1)
1149  {
1150  pd->is_chain = 1;
1151  /* find last buffer in the chain */
1152  while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT)
1153  pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer);
1154 
1155  crypto_ops = &ptd->chained_crypto_ops;
1156  integ_ops = &ptd->chained_integ_ops;
1157  }
1158  else
1159  {
1160  crypto_ops = &ptd->crypto_ops;
1161  integ_ops = &ptd->integ_ops;
1162  }
1163 
1164  pd->current_length = b[0]->current_length;
1165 
1166  /* anti-reply check */
1167  if (ipsec_sa_anti_replay_check (sa0, pd->seq))
1168  {
1169  err = ESP_DECRYPT_ERROR_REPLAY;
1170  esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
1171  ESP_DECRYPT_NEXT_DROP);
1172  goto next;
1173  }
1174 
1175  if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
1176  {
1177  err = ESP_DECRYPT_ERROR_RUNT;
1178  esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
1179  ESP_DECRYPT_NEXT_DROP);
1180  goto next;
1181  }
1182 
1183  len = pd->current_length - cpd.icv_sz;
1184  current_sa_pkts += 1;
1185  current_sa_bytes += vlib_buffer_length_in_chain (vm, b[0]);
1186 
1187  if (is_async)
1188  {
1189 
1191  vm, node, ptd, async_frames[async_op], sa0, payload, len,
1192  cpd.icv_sz, cpd.iv_sz, pd, pd2, from[b - bufs], b[0], async_next,
1193  async_next_node);
1194  if (ESP_DECRYPT_ERROR_RX_PKTS != err)
1195  {
1196  esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
1197  ESP_DECRYPT_NEXT_DROP);
1198  }
1199  }
1200  else
1202  vm, node, ptd, &crypto_ops, &integ_ops, op, sa0, payload, len,
1203  cpd.icv_sz, cpd.iv_sz, pd, pd2, b[0], sync_next, b - bufs);
1204  /* next */
1205  next:
1206  if (ESP_DECRYPT_ERROR_RX_PKTS != err)
1207  {
1208  noop_bi[n_noop] = from[b - bufs];
1209  n_noop++;
1210  noop_next++;
1211  }
1212  else if (!is_async)
1213  {
1214  sync_bi[n_sync] = from[b - bufs];
1215  sync_bufs[n_sync] = b[0];
1216  n_sync++;
1217  sync_next++;
1218  pd += 1;
1219  pd2 += 1;
1220  }
1221  else
1222  {
1223  n_async++;
1224  async_next++;
1225  }
1226  n_left -= 1;
1227  b += 1;
1228  }
1229 
1230  if (PREDICT_TRUE (~0 != current_sa_index))
1232  current_sa_index, current_sa_pkts,
1233  current_sa_bytes);
1234 
1235  if (n_async)
1236  {
1237  /* submit all of the open frames */
1238  vnet_crypto_async_frame_t **async_frame;
1239 
1240  vec_foreach (async_frame, ptd->async_frames)
1241  {
1242  if (vnet_crypto_async_submit_open_frame (vm, *async_frame) < 0)
1243  {
1245  vm, *async_frame, node, ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR,
1246  n_sync, noop_bi, noop_nexts, ESP_DECRYPT_NEXT_DROP);
1247  vnet_crypto_async_reset_frame (*async_frame);
1248  vnet_crypto_async_free_frame (vm, *async_frame);
1249  }
1250  }
1251  }
1252 
1253  if (n_sync)
1254  {
1255  esp_process_ops (vm, node, ptd->integ_ops, sync_bufs, sync_nexts,
1256  ESP_DECRYPT_ERROR_INTEG_ERROR);
1257  esp_process_chained_ops (vm, node, ptd->chained_integ_ops, sync_bufs,
1258  sync_nexts, ptd->chunks,
1259  ESP_DECRYPT_ERROR_INTEG_ERROR);
1260 
1261  esp_process_ops (vm, node, ptd->crypto_ops, sync_bufs, sync_nexts,
1262  ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1263  esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, sync_bufs,
1264  sync_nexts, ptd->chunks,
1265  ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1266  }
1267 
1268  /* Post decryption ronud - adjust packet data start and length and next
1269  node */
1270 
1271  n_left = n_sync;
1272  sync_next = sync_nexts;
1273  pd = pkt_data;
1274  pd2 = pkt_data2;
1275  b = sync_bufs;
1276 
1277  while (n_left)
1278  {
1279  if (n_left >= 2)
1280  {
1281  void *data = b[1]->data + pd[1].current_data;
1282 
1283  /* buffer metadata */
1284  vlib_prefetch_buffer_header (b[1], LOAD);
1285 
1286  /* esp_footer_t */
1287  CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
1288  CLIB_CACHE_LINE_BYTES, LOAD);
1289 
1290  /* packet headers */
1292  CLIB_CACHE_LINE_BYTES * 2, LOAD);
1293  }
1294 
1295  /* save the sa_index as GRE_teb post_crypto changes L2 opaque */
1296  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1297  current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1298 
1299  if (sync_next[0] >= ESP_DECRYPT_N_NEXT)
1300  esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], sync_next, is_ip6,
1301  is_tun, 0);
1302 
1303  /* trace: */
1304  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1305  {
1306  esp_decrypt_trace_t *tr;
1307  tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1308  sa0 = ipsec_sa_get (current_sa_index);
1309  tr->crypto_alg = sa0->crypto_alg;
1310  tr->integ_alg = sa0->integ_alg;
1311  tr->seq = pd->seq;
1312  tr->sa_seq = sa0->last_seq;
1313  tr->sa_seq_hi = sa0->seq_hi;
1314  }
1315 
1316  /* next */
1317  n_left -= 1;
1318  sync_next += 1;
1319  pd += 1;
1320  pd2 += 1;
1321  b += 1;
1322  }
1323 
1324  vlib_node_increment_counter (vm, node->node_index, ESP_DECRYPT_ERROR_RX_PKTS,
1325  from_frame->n_vectors);
1326 
1327  if (n_sync)
1328  vlib_buffer_enqueue_to_next (vm, node, sync_bi, sync_nexts, n_sync);
1329 
1330  if (n_noop)
1331  vlib_buffer_enqueue_to_next (vm, node, noop_bi, noop_nexts, n_noop);
1332 
1333  return (from_frame->n_vectors);
1334 }
1335 
1339  vlib_frame_t * from_frame, int is_ip6, int is_tun)
1340 {
1341  u32 *from = vlib_frame_vector_args (from_frame);
1342  u32 n_left = from_frame->n_vectors;
1345  vlib_get_buffers (vm, from, b, n_left);
1346 
1347  while (n_left > 0)
1348  {
1349  esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data;
1350 
1351  if (n_left > 2)
1352  {
1353  vlib_prefetch_buffer_header (b[2], LOAD);
1354  vlib_prefetch_buffer_header (b[1], LOAD);
1355  }
1356 
1357  if (!pd->is_chain)
1358  esp_decrypt_post_crypto (vm, node, pd, 0, b[0], next, is_ip6, is_tun,
1359  1);
1360  else
1361  {
1363  esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1364  is_tun, 1);
1365  }
1366 
1367  /*trace: */
1368  if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1369  {
1370  ipsec_sa_t *sa0 = ipsec_sa_get (pd->sa_index);
1371  esp_decrypt_trace_t *tr;
1372  esp_decrypt_packet_data_t *async_pd =
1373  &(esp_post_data (b[0]))->decrypt_data;
1374  tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1375  sa0 = ipsec_sa_get (async_pd->sa_index);
1376 
1377  tr->crypto_alg = sa0->crypto_alg;
1378  tr->integ_alg = sa0->integ_alg;
1379  tr->seq = pd->seq;
1380  tr->sa_seq = sa0->last_seq;
1381  tr->sa_seq_hi = sa0->seq_hi;
1382  }
1383 
1384  n_left--;
1385  next++;
1386  b++;
1387  }
1388 
1389  n_left = from_frame->n_vectors;
1391  ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left);
1392 
1393  vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1394 
1395  return n_left;
1396 }
1397 
1401 {
1402  return esp_decrypt_inline (vm, node, from_frame, 0, 0,
1404 }
1405 
1409 {
1410  return esp_decrypt_post_inline (vm, node, from_frame, 0, 0);
1411 }
1412 
1416 {
1417  return esp_decrypt_inline (vm, node, from_frame, 0, 1,
1419 }
1420 
1424 {
1425  return esp_decrypt_post_inline (vm, node, from_frame, 0, 1);
1426 }
1427 
1431 {
1432  return esp_decrypt_inline (vm, node, from_frame, 1, 0,
1434 }
1435 
1439 {
1440  return esp_decrypt_post_inline (vm, node, from_frame, 1, 0);
1441 }
1442 
1446 {
1447  return esp_decrypt_inline (vm, node, from_frame, 1, 1,
1449 }
1450 
1454 {
1455  return esp_decrypt_post_inline (vm, node, from_frame, 1, 1);
1456 }
1457 
1458 /* *INDENT-OFF* */
1460  .name = "esp4-decrypt",
1461  .vector_size = sizeof (u32),
1462  .format_trace = format_esp_decrypt_trace,
1464 
1465  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1466  .error_strings = esp_decrypt_error_strings,
1467 
1468  .n_next_nodes = ESP_DECRYPT_N_NEXT,
1469  .next_nodes = {
1470  [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1471  [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1472  [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1473  [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop",
1474  [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1475  [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff",
1476  },
1477 };
1478 
1480  .name = "esp4-decrypt-post",
1481  .vector_size = sizeof (u32),
1482  .format_trace = format_esp_decrypt_trace,
1484 
1485  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1486  .error_strings = esp_decrypt_error_strings,
1487 
1488  .sibling_of = "esp4-decrypt",
1489 };
1490 
1492  .name = "esp6-decrypt",
1493  .vector_size = sizeof (u32),
1494  .format_trace = format_esp_decrypt_trace,
1496 
1497  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1498  .error_strings = esp_decrypt_error_strings,
1499 
1500  .n_next_nodes = ESP_DECRYPT_N_NEXT,
1501  .next_nodes = {
1502  [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1503  [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1504  [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1505  [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop",
1506  [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1507  [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff",
1508  },
1509 };
1510 
1512  .name = "esp6-decrypt-post",
1513  .vector_size = sizeof (u32),
1514  .format_trace = format_esp_decrypt_trace,
1516 
1517  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1518  .error_strings = esp_decrypt_error_strings,
1519 
1520  .sibling_of = "esp6-decrypt",
1521 };
1522 
1524  .name = "esp4-decrypt-tun",
1525  .vector_size = sizeof (u32),
1526  .format_trace = format_esp_decrypt_trace,
1528  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1529  .error_strings = esp_decrypt_error_strings,
1530  .n_next_nodes = ESP_DECRYPT_N_NEXT,
1531  .next_nodes = {
1532  [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1533  [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1534  [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1535  [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input",
1536  [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1537  [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff",
1538  },
1539 };
1540 
1542  .name = "esp4-decrypt-tun-post",
1543  .vector_size = sizeof (u32),
1544  .format_trace = format_esp_decrypt_trace,
1546 
1547  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1548  .error_strings = esp_decrypt_error_strings,
1549 
1550  .sibling_of = "esp4-decrypt-tun",
1551 };
1552 
1554  .name = "esp6-decrypt-tun",
1555  .vector_size = sizeof (u32),
1556  .format_trace = format_esp_decrypt_trace,
1558  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1559  .error_strings = esp_decrypt_error_strings,
1560  .n_next_nodes = ESP_DECRYPT_N_NEXT,
1561  .next_nodes = {
1562  [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1563  [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1564  [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1565  [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input",
1566  [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1567  [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff",
1568  },
1569 };
1570 
1572  .name = "esp6-decrypt-tun-post",
1573  .vector_size = sizeof (u32),
1574  .format_trace = format_esp_decrypt_trace,
1576 
1577  .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1578  .error_strings = esp_decrypt_error_strings,
1579 
1580  .sibling_of = "esp6-decrypt-tun",
1581 };
1582 /* *INDENT-ON* */
1583 
1584 #ifndef CLIB_MARCH_VARIANT
1585 
1586 static clib_error_t *
1588 {
1590 
1591  im->esp4_dec_fq_index =
1593  im->esp6_dec_fq_index =
1595  im->esp4_dec_tun_fq_index =
1597  im->esp6_dec_tun_fq_index =
1599 
1600  return 0;
1601 }
1602 
1604 
1605 #endif
1606 
1607 /*
1608  * fd.io coding-style-patch-verification: ON
1609  *
1610  * Local Variables:
1611  * eval: (c-set-style "gnu")
1612  * End:
1613  */
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
Definition: crypto.c:99
static char * esp_decrypt_error_strings[]
Definition: esp_decrypt.c:84
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:133
esp_decrypt_next_t
Definition: esp_decrypt.c:39
vlib_node_registration_t esp6_decrypt_tun_post_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node)
Definition: esp_decrypt.c:1571
u8 * format_ipsec_integ_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:111
#define esp_post_data(b)
Definition: esp.h:227
vlib_node_registration_t esp6_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_node)
Definition: esp_decrypt.c:1491
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer&#39;s data.
Definition: buffer.h:338
#define foreach_esp_decrypt_post_next
Definition: esp_decrypt.c:46
The post data structure to for esp_encrypt/decrypt_inline to write to vib_buffer_t opaque unused fiel...
Definition: esp.h:183
#define CLIB_UNUSED(x)
Definition: clib.h:90
static_always_inline void vnet_crypto_async_reset_frame(vnet_crypto_async_frame_t *f)
Definition: crypto.h:650
ipsec_per_thread_data_t * ptd
Definition: ipsec.h:191
vnet_crypto_op_t * integ_ops
Definition: ipsec.h:101
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
ip4_address_t src_address
Definition: ip4_packet.h:125
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
static u16 esp_aad_fill(u8 *data, const esp_header_t *esp, const ipsec_sa_t *sa)
Definition: esp.h:121
esp_decrypt_error_t
Definition: esp_decrypt.c:76
u32 thread_index
#define PREDICT_TRUE(x)
Definition: clib.h:125
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
unsigned long u64
Definition: types.h:89
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
u16 nexts[VLIB_FRAME_SIZE]
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS
Definition: crypto.h:264
static u32 ipsec_sa_assign_thread(u32 thread_id)
Definition: ipsec_sa.h:512
u32 esp6_post_next
Definition: esp.h:243
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
Definition: threads.c:1572
ipsec_integ_alg_t integ_alg
Definition: ipsec_sa.h:218
static void esp_set_next_index(vlib_buffer_t *b, vlib_node_runtime_t *node, u32 err, u16 index, u16 *nexts, u16 drop_next)
Definition: esp.h:149
u32 thread_index
Definition: main.h:213
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
vnet_crypto_op_t * crypto_ops
Definition: ipsec.h:100
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:607
ipsec_crypto_alg_t crypto_alg
Definition: esp_decrypt.c:95
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
AES GCM Additional Authentication data.
Definition: esp.h:76
static_always_inline void esp_process_ops(vlib_main_t *vm, vlib_node_runtime_t *node, vnet_crypto_op_t *ops, vlib_buffer_t *b[], u16 *nexts, int e)
Definition: esp_decrypt.c:118
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:645
static_always_inline esp_decrypt_error_t esp_decrypt_prepare_async_frame(vlib_main_t *vm, vlib_node_runtime_t *node, ipsec_per_thread_data_t *ptd, vnet_crypto_async_frame_t *f, ipsec_sa_t *sa0, u8 *payload, u16 len, u8 icv_sz, u8 iv_sz, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, u32 bi, vlib_buffer_t *b, u16 *next, u16 async_next)
Definition: esp_decrypt.c:611
uword ip_csum_t
Definition: ip_packet.h:245
static_always_inline u8 * esp_move_icv_esn(vlib_main_t *vm, vlib_buffer_t *first, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, u16 icv_sz, ipsec_sa_t *sa, u8 *extra_esn, u32 *len)
Definition: esp_decrypt.c:275
vlib_node_registration_t esp4_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_post_node)
Definition: esp_decrypt.c:1479
static u16 vnet_update_l2_len(vlib_buffer_t *b)
Definition: l2_input.h:298
#define VLIB_NODE_FN(node)
Definition: node.h:202
esp_decrypt_post_next_t
Definition: esp_decrypt.c:54
vnet_crypto_op_chunk_t * chunks
Definition: ipsec.h:104
vlib_node_registration_t esp4_decrypt_tun_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_tun_node)
Definition: esp_decrypt.c:1523
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:461
vnet_crypto_op_id_t integ_op_id
Definition: ipsec_sa.h:150
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
static_always_inline int ip46_address_is_equal_v6(const ip46_address_t *ip46, const ip6_address_t *ip6)
Definition: ip46_address.h:115
ip6_address_t src_address
Definition: ip6_packet.h:310
unsigned char u8
Definition: types.h:56
vlib_buffer_t ** b
u8 data[128]
Definition: ipsec_types.api:92
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u32 seq_hi
Definition: ipsec_sa.h:133
unsigned int u32
Definition: types.h:88
vlib_node_registration_t esp6_decrypt_post_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_post_node)
Definition: esp_decrypt.c:1511
vnet_crypto_key_index_t linked_key_index
Definition: ipsec_sa.h:157
vlib_frame_t * f
vnet_crypto_key_index_t crypto_key_index
Definition: ipsec_sa.h:139
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
#define static_always_inline
Definition: clib.h:112
ip46_address_t src
Definition: ipsec_tun.h:101
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vlib_get_buffers(vm, from, b, n_left_from)
vl_api_ip6_address_t ip6
Definition: one.api:424
ip4_address_t dst_address
Definition: ip4_packet.h:125
u32 esp4_tun_post_next
Definition: esp.h:244
description fragment has unexpected format
Definition: map.api:433
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
Definition: crypto.h:528
u32 esp4_dec_tun_fq_index
Definition: ipsec.h:206
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
ipsec_ep_t itp_tun
Definition: ipsec_tun.h:124
u32 esp4_dec_fq_index
Definition: ipsec.h:200
u8 * format_ipsec_crypto_alg(u8 *s, va_list *args)
Definition: ipsec_format.c:79
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
ipsec_sa_flags_t flags
Definition: ipsec_sa.h:121
#define VLIB_FRAME_SIZE
Definition: node.h:369
bool is_ip6
Definition: ip.api:43
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:145
u32 last_seq
Definition: ipsec_sa.h:134
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
u16 * next
#define ESP_MAX_ICV_SIZE
Definition: esp.h:90
static u8 iv[]
Definition: aes_cbc.c:24
static_always_inline int esp_decrypt_chain_integ(vlib_main_t *vm, ipsec_per_thread_data_t *ptd, esp_decrypt_packet_data2_t *pd2, ipsec_sa_t *sa0, vlib_buffer_t *b, u8 icv_sz, u8 *start_src, u32 start_len, u8 **digest, u16 *n_ch, u32 *integ_total_len)
Definition: esp_decrypt.c:310
uword user_data
Definition: crypto.h:258
esp_async_post_next_t esp_decrypt_async_next
Definition: ipsec.c:30
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:708
u32 salt
Definition: ipsec_sa.h:174
#define foreach_esp_decrypt_error
Definition: esp_decrypt.c:61
static void ipsec_sa_anti_replay_advance(ipsec_sa_t *sa, u32 seq)
Definition: ipsec_sa.h:447
unsigned short u16
Definition: types.h:57
static u8 * format_esp_decrypt_trace(u8 *s, va_list *args)
Definition: esp_decrypt.c:101
u8 data_len
Definition: ikev2_types.api:24
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
u32 esp6_dec_tun_fq_index
Definition: ipsec.h:207
u32 * tmp
vnet_crypto_async_op_id_t crypto_async_dec_op_id
Definition: ipsec_sa.h:156
#define PREDICT_FALSE(x)
Definition: clib.h:124
static_always_inline void vnet_crypto_async_free_frame(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
Definition: crypto.h:580
vl_api_ip4_address_t ip4
Definition: one.api:376
static_always_inline u8 vnet_crypto_async_frame_is_full(const vnet_crypto_async_frame_t *f)
Definition: crypto.h:665
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
u32 node_index
Node index.
Definition: node.h:479
u32 n_left
#define VNET_CRYPTO_OP_FLAG_HMAC_CHECK
Definition: crypto.h:263
static_always_inline vnet_crypto_async_frame_t * vnet_crypto_async_get_frame(vlib_main_t *vm, vnet_crypto_async_op_id_t opt)
async crypto inline functions
Definition: crypto.h:563
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
static u32 esp_async_recycle_failed_submit(vlib_main_t *vm, vnet_crypto_async_frame_t *f, vlib_node_runtime_t *node, u32 err, u16 index, u32 *from, u16 *nexts, u16 drop_next_index)
Definition: esp.h:158
static uword esp_decrypt_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6, int is_tun, u16 async_next_node)
Definition: esp_decrypt.c:1014
u8 len
Definition: ip_types.api:103
vnet_crypto_op_t * chained_crypto_ops
Definition: ipsec.h:102
#define vec_add_aligned(V, E, N, A)
Add N elements to end of vector V (no header, specified alignment)
Definition: vec.h:699
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:388
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vnet_crypto_async_frame_t ** async_frames
Definition: ipsec.h:105
u32 index
Definition: flow_types.api:221
u16 protocol
Definition: packet.h:55
u8 data[]
Packet data.
Definition: buffer.h:204
vnet_interface_main_t * im
u32 thread_index
Definition: ipsec_sa.h:129
#define ARRAY_LEN(x)
Definition: clib.h:70
static u32 vlib_buffer_space_left_at_end(vlib_main_t *vm, vlib_buffer_t *b)
static void esp_remove_tail(vlib_main_t *vm, vlib_buffer_t *b, vlib_buffer_t *last, u16 tail)
Definition: esp_decrypt.c:181
static clib_error_t * esp_decrypt_init(vlib_main_t *vm)
Definition: esp_decrypt.c:1587
u32 esp4_post_next
Definition: esp.h:242
#define clib_atomic_cmp_and_swap(addr, old, new)
Definition: atomics.h:37
u32 esp6_tun_post_next
Definition: esp.h:245
ip46_address_t dst
Definition: ipsec_tun.h:102
static_always_inline u32 esp_decrypt_chain_crypto(vlib_main_t *vm, ipsec_per_thread_data_t *ptd, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, ipsec_sa_t *sa0, vlib_buffer_t *b, u8 icv_sz, u8 *start, u32 start_len, u8 **tag, u16 *n_ch)
Definition: esp_decrypt.c:406
vlib_combined_counter_main_t ipsec_sa_counters
SA packet & bytes counters.
Definition: ipsec_sa.c:27
#define ASSERT(truth)
u32 esp6_dec_fq_index
Definition: ipsec.h:202
static_always_inline u8 * esp_move_icv(vlib_main_t *vm, vlib_buffer_t *first, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, u16 icv_sz, u16 *dif)
Definition: esp_decrypt.c:206
u32 vnet_crypto_process_chained_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
Definition: crypto.c:105
#define always_inline
Definition: rdma_mlx5dv.h:23
static ipsec_tun_protect_t * ipsec_tun_protect_get(u32 index)
Definition: ipsec_tun.h:172
ipsec_sa_flags_t flags
Definition: esp.h:191
vlib_node_registration_t esp4_decrypt_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_node)
Definition: esp_decrypt.c:1459
static int ipsec_sa_anti_replay_check(ipsec_sa_t *sa, u32 seq)
Definition: ipsec_sa.h:320
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
char const int length
Definition: cJSON.h:163
static_always_inline void vnet_crypto_async_add_to_frame(vlib_main_t *vm, vnet_crypto_async_frame_t *f, u32 key_index, u32 crypto_len, i16 integ_len_adj, i16 crypto_start_offset, u16 integ_start_offset, u32 buffer_index, u16 next_node, u8 *iv, u8 *tag, u8 *aad, u8 flags)
Definition: crypto.h:621
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
vnet_crypto_async_op_id_t
Definition: crypto.h:182
vnet_crypto_key_index_t integ_key_index
Definition: ipsec_sa.h:140
vlib_node_registration_t esp6_decrypt_tun_node
(constructor) VLIB_REGISTER_NODE (esp6_decrypt_tun_node)
Definition: esp_decrypt.c:1553
static_always_inline int vnet_crypto_async_submit_open_frame(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
Definition: crypto.h:589
static_always_inline void clib_memcpy_le64(u8 *dst, u8 *src, u8 len)
Definition: string.h:300
u16 payload_length
Definition: ip6_packet.h:301
vl_api_address_t ip
Definition: l2.api:558
vlib_node_registration_t esp4_decrypt_tun_post_node
(constructor) VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node)
Definition: esp_decrypt.c:1541
static ipsec_sa_t * ipsec_sa_get(u32 sa_index)
Definition: ipsec_sa.h:519
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
ipsec_main_t ipsec_main
Definition: ipsec.c:28
VLIB buffer representation.
Definition: buffer.h:111
u64 uword
Definition: types.h:112
#define esp_post_data2(b)
Definition: esp.h:235
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:295
static_always_inline int ip46_address_is_equal_v4(const ip46_address_t *ip46, const ip4_address_t *ip4)
Definition: ip46_address.h:108
static uword esp_decrypt_post_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, int is_ip6, int is_tun)
Definition: esp_decrypt.c:1337
vnet_crypto_op_t * chained_integ_ops
Definition: ipsec.h:103
static_always_inline void esp_process_chained_ops(vlib_main_t *vm, vlib_node_runtime_t *node, vnet_crypto_op_t *ops, vlib_buffer_t *b[], u16 *nexts, vnet_crypto_op_chunk_t *chunks, int e)
Definition: esp_decrypt.c:149
vnet_crypto_op_status_t status
Definition: crypto.h:260
#define vnet_buffer(b)
Definition: buffer.h:437
static_always_inline void esp_decrypt_prepare_sync_op(vlib_main_t *vm, vlib_node_runtime_t *node, ipsec_per_thread_data_t *ptd, vnet_crypto_op_t ***crypto_ops, vnet_crypto_op_t ***integ_ops, vnet_crypto_op_t *op, ipsec_sa_t *sa0, u8 *payload, u16 len, u8 icv_sz, u8 iv_sz, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, vlib_buffer_t *b, u16 *next, u32 index)
Definition: esp_decrypt.c:479
ipsec_crypto_alg_t crypto_alg
Definition: ipsec_sa.h:217
#define vec_foreach(var, vec)
Vector iterator.
vlib_buffer_t * lb
Definition: esp.h:212
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
u8 crypto_iv_size
Definition: ipsec_sa.h:123
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vl_api_ikev2_sa_transform_t esn
u8 async_mode
Definition: ipsec.h:209
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
vnet_crypto_op_id_t crypto_dec_op_id
Definition: ipsec_sa.h:149
u8 integ_icv_size
Definition: ipsec_sa.h:125
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
static_always_inline i16 esp_insert_esn(vlib_main_t *vm, ipsec_sa_t *sa, esp_decrypt_packet_data2_t *pd2, u32 *data_len, u8 **digest, u16 *len, vlib_buffer_t *b, u8 *payload)
Definition: esp_decrypt.c:239
#define foreach_esp_decrypt_next
Definition: esp_decrypt.c:30
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:301
ipsec_integ_alg_t integ_alg
Definition: esp_decrypt.c:96
ip6_address_t dst_address
Definition: ip6_packet.h:310
signed short i16
Definition: types.h:46
static_always_inline void esp_decrypt_post_crypto(vlib_main_t *vm, vlib_node_runtime_t *node, esp_decrypt_packet_data_t *pd, esp_decrypt_packet_data2_t *pd2, vlib_buffer_t *b, u16 *next, int is_ip6, int is_tun, int is_async)
Definition: esp_decrypt.c:745