2 * esp_decrypt.c : IPSec ESP decrypt node
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/vnet.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/l2/l2_input.h>
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>
28 #include <vnet/gre/packet.h>
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") \
37 #define _(v, s) ESP_DECRYPT_NEXT_##v,
40 foreach_esp_decrypt_next
45 #define foreach_esp_decrypt_post_next \
46 _(DROP, "error-drop") \
47 _(IP4_INPUT, "ip4-input-no-checksum") \
48 _(IP6_INPUT, "ip6-input") \
49 _(L2_INPUT, "l2-input")
51 #define _(v, s) ESP_DECRYPT_POST_NEXT_##v,
54 foreach_esp_decrypt_post_next
56 ESP_DECRYPT_POST_N_NEXT,
57 } esp_decrypt_post_next_t;
59 #define foreach_esp_decrypt_error \
60 _(RX_PKTS, "ESP pkts received") \
61 _(RX_POST_PKTS, "ESP-POST pkts received") \
62 _(DECRYPTION_FAILED, "ESP decryption failed") \
63 _(INTEG_ERROR, "Integrity check failed") \
64 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
65 _(REPLAY, "SA replayed packet") \
66 _(RUNT, "undersized packet") \
67 _(NO_BUFFERS, "no buffers (packet dropped)") \
68 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \
69 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \
70 _(TUN_NO_PROTO, "no tunnel protocol") \
71 _(UNSUP_PAYLOAD, "unsupported payload") \
76 #define _(sym,str) ESP_DECRYPT_ERROR_##sym,
77 foreach_esp_decrypt_error
80 } esp_decrypt_error_t;
82 static char *esp_decrypt_error_strings[] = {
83 #define _(sym,string) string,
84 foreach_esp_decrypt_error
93 ipsec_crypto_alg_t crypto_alg;
94 ipsec_integ_alg_t integ_alg;
95 } esp_decrypt_trace_t;
97 /* packet trace format function */
99 format_esp_decrypt_trace (u8 * s, va_list * args)
101 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
102 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
103 esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
107 "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
108 format_ipsec_crypto_alg, t->crypto_alg, format_ipsec_integ_alg,
109 t->integ_alg, t->seq, t->sa_seq, t->sa_seq_hi);
113 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2)
115 static_always_inline void
116 esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
117 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts,
120 vnet_crypto_op_t *op = ops;
121 u32 n_fail, n_ops = vec_len (ops);
126 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
130 ASSERT (op - ops < n_ops);
131 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
133 u32 err, bi = op->user_data;
134 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
137 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
138 b[bi]->error = node->errors[err];
139 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
146 static_always_inline void
147 esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
148 vnet_crypto_op_t * ops, vlib_buffer_t * b[],
149 u16 * nexts, vnet_crypto_op_chunk_t * chunks, int e)
152 vnet_crypto_op_t *op = ops;
153 u32 n_fail, n_ops = vec_len (ops);
158 n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops);
162 ASSERT (op - ops < n_ops);
163 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
165 u32 err, bi = op->user_data;
166 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
169 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
170 b[bi]->error = node->errors[err];
171 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
179 esp_remove_tail (vlib_main_t * vm, vlib_buffer_t * b, vlib_buffer_t * last,
182 vlib_buffer_t *before_last = b;
184 if (last->current_length > tail)
186 last->current_length -= tail;
189 ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
191 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
194 b = vlib_get_buffer (vm, b->next_buffer);
196 before_last->current_length -= tail - last->current_length;
197 vlib_buffer_free_one (vm, before_last->next_buffer);
198 before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
201 /* ICV is splitted in last two buffers so move it to the last buffer and
202 return pointer to it */
203 static_always_inline u8 *
204 esp_move_icv (vlib_main_t * vm, vlib_buffer_t * first,
205 esp_decrypt_packet_data2_t * pd2, u16 icv_sz, u16 * dif)
207 vlib_buffer_t *before_last, *bp;
208 u16 last_sz = pd2->lb->current_length;
209 u16 first_sz = icv_sz - last_sz;
211 bp = before_last = first;
212 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
215 bp = vlib_get_buffer (vm, bp->next_buffer);
218 u8 *lb_curr = vlib_buffer_get_current (pd2->lb);
219 memmove (lb_curr + first_sz, lb_curr, last_sz);
220 clib_memcpy_fast (lb_curr, vlib_buffer_get_tail (before_last) - first_sz,
222 before_last->current_length -= first_sz;
223 clib_memset (vlib_buffer_get_tail (before_last), 0, first_sz);
226 pd2->lb = before_last;
227 pd2->icv_removed = 1;
228 pd2->free_buffer_index = before_last->next_buffer;
229 before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
233 static_always_inline i16
234 esp_insert_esn (vlib_main_t * vm, ipsec_sa_t * sa,
235 esp_decrypt_packet_data2_t * pd2, u32 * data_len,
236 u8 ** digest, u16 * len, vlib_buffer_t * b, u8 * payload)
238 if (!ipsec_sa_is_set_USE_ESN (sa))
241 /* shift ICV by 4 bytes to insert ESN */
242 u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
243 u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa->seq_hi);
245 if (pd2->icv_removed)
247 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
248 if (space_left >= sz)
250 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
256 len[0] = b->current_length;
260 clib_memcpy_fast (tmp, payload + len[0], ESP_MAX_ICV_SIZE);
261 clib_memcpy_fast (payload + len[0], &seq_hi, sz);
262 clib_memcpy_fast (payload + len[0] + sz, tmp, ESP_MAX_ICV_SIZE);
269 static_always_inline u8 *
270 esp_move_icv_esn (vlib_main_t * vm, vlib_buffer_t * first,
271 esp_decrypt_packet_data2_t * pd2, u16 icv_sz,
272 ipsec_sa_t * sa, u8 * extra_esn, u32 * len)
275 u8 *digest = esp_move_icv (vm, first, pd2, icv_sz, &dif);
279 if (ipsec_sa_is_set_USE_ESN (sa))
281 u8 sz = sizeof (sa->seq_hi);
282 u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
283 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
285 if (space_left >= sz)
287 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
292 /* no space for ESN at the tail, use the next buffer
294 ASSERT (pd2->icv_removed);
295 vlib_buffer_t *tmp = vlib_get_buffer (vm, pd2->free_buffer_index);
296 clib_memcpy_fast (vlib_buffer_get_current (tmp) - sz, &seq_hi, sz);
303 static_always_inline int
304 esp_decrypt_chain_integ (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
305 esp_decrypt_packet_data2_t * pd2,
306 ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
307 u8 * start_src, u32 start_len,
308 u8 ** digest, u16 * n_ch, u32 * integ_total_len)
310 vnet_crypto_op_chunk_t *ch;
311 vlib_buffer_t *cb = vlib_get_buffer (vm, b->next_buffer);
314 vec_add2 (ptd->chunks, ch, 1);
315 total_len = ch->len = start_len;
320 vec_add2 (ptd->chunks, ch, 1);
322 ch->src = vlib_buffer_get_current (cb);
325 if (pd2->icv_removed)
326 ch->len = cb->current_length;
328 ch->len = cb->current_length - icv_sz;
329 if (ipsec_sa_is_set_USE_ESN (sa0))
331 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
332 u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa0->seq_hi);
334 vlib_buffer_t *tmp_b;
335 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
338 if (pd2->icv_removed)
340 /* use pre-data area from the last bufer
341 that was removed from the chain */
342 tmp_b = vlib_get_buffer (vm, pd2->free_buffer_index);
343 esn = tmp_b->data - sz;
347 /* no space, need to allocate new buffer */
349 if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1)
351 tmp_b = vlib_get_buffer (vm, tmp_bi);
353 pd2->free_buffer_index = tmp_bi;
355 clib_memcpy_fast (esn, &seq_hi, sz);
357 vec_add2 (ptd->chunks, ch, 1);
364 if (pd2->icv_removed)
366 clib_memcpy_fast (vlib_buffer_get_tail
367 (pd2->lb), &seq_hi, sz);
371 clib_memcpy_fast (tmp, *digest, ESP_MAX_ICV_SIZE);
372 clib_memcpy_fast (*digest, &seq_hi, sz);
373 clib_memcpy_fast (*digest + sz, tmp, ESP_MAX_ICV_SIZE);
379 total_len += ch->len;
383 total_len += ch->len = cb->current_length;
385 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
388 cb = vlib_get_buffer (vm, cb->next_buffer);
394 *integ_total_len = total_len;
399 static_always_inline u32
400 esp_decrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
401 esp_decrypt_packet_data2_t * pd2,
402 ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
403 u8 * start, u32 start_len, u8 ** tag, u16 * n_ch)
405 vnet_crypto_op_chunk_t *ch;
406 vlib_buffer_t *cb = b;
409 vec_add2 (ptd->chunks, ch, 1);
410 total_len = ch->len = start_len;
411 ch->src = ch->dst = start;
412 cb = vlib_get_buffer (vm, cb->next_buffer);
417 vec_add2 (ptd->chunks, ch, 1);
419 ch->src = ch->dst = vlib_buffer_get_current (cb);
422 if (ipsec_sa_is_set_IS_AEAD (sa0))
424 if (pd2->lb->current_length < icv_sz)
427 *tag = esp_move_icv (vm, b, pd2, icv_sz, &dif);
429 /* this chunk does not contain crypto data */
431 /* and fix previous chunk's length as it might have
433 ASSERT (n_chunks > 0);
441 total_len = total_len + pd2->lb->current_length -
443 ch[-1].len = pd2->lb->current_length;
448 *tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
451 if (pd2->icv_removed)
452 total_len += ch->len = cb->current_length;
454 total_len += ch->len = cb->current_length - icv_sz;
457 total_len += ch->len = cb->current_length;
459 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
462 cb = vlib_get_buffer (vm, cb->next_buffer);
471 static_always_inline void
472 esp_decrypt_prepare_sync_op (vlib_main_t * vm, vlib_node_runtime_t * node,
473 ipsec_per_thread_data_t * ptd,
474 vnet_crypto_op_t *** crypto_ops,
475 vnet_crypto_op_t *** integ_ops,
476 vnet_crypto_op_t * op,
477 ipsec_sa_t * sa0, u8 * payload,
478 u16 len, u8 icv_sz, u8 iv_sz,
479 esp_decrypt_packet_data_t * pd,
480 esp_decrypt_packet_data2_t * pd2,
481 vlib_buffer_t * b, u16 * next, u32 index)
483 const u8 esp_sz = sizeof (esp_header_t);
485 if (PREDICT_TRUE (sa0->integ_op_id != VNET_CRYPTO_OP_NONE))
487 vnet_crypto_op_init (op, sa0->integ_op_id);
488 op->key_index = sa0->integ_key_index;
490 op->flags = VNET_CRYPTO_OP_FLAG_HMAC_CHECK;
491 op->user_data = index;
492 op->digest = payload + len;
493 op->digest_len = icv_sz;
498 /* buffer is chained */
499 op->len = pd->current_length;
501 /* special case when ICV is splitted and needs to be reassembled
502 * first -> move it to the last buffer. Also take into account
503 * that ESN needs to be added after encrypted data and may or
504 * may not fit in the tail.*/
505 if (pd2->lb->current_length < icv_sz)
509 esp_move_icv_esn (vm, b, pd2, icv_sz, sa0,
510 &extra_esn, &op->len);
514 /* esn is in the last buffer, that was unlinked from
516 op->len = b->current_length;
522 /* we now have a single buffer of crypto data, adjust
523 * the length (second buffer contains only ICV) */
524 *integ_ops = &ptd->integ_ops;
525 *crypto_ops = &ptd->crypto_ops;
526 len = b->current_length;
532 op->digest = vlib_buffer_get_tail (pd2->lb) - icv_sz;
534 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
535 op->chunk_index = vec_len (ptd->chunks);
536 if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz,
537 payload, pd->current_length,
538 &op->digest, &op->n_chunks, 0) < 0)
540 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
541 next[0] = ESP_DECRYPT_NEXT_DROP;
546 esp_insert_esn (vm, sa0, pd2, &op->len, &op->digest, &len, b,
549 vec_add_aligned (*(integ_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
555 if (sa0->crypto_dec_op_id != VNET_CRYPTO_OP_NONE)
557 vnet_crypto_op_init (op, sa0->crypto_dec_op_id);
558 op->key_index = sa0->crypto_key_index;
561 if (ipsec_sa_is_set_IS_AEAD (sa0))
568 * construct the AAD and the nonce (Salt || IV) in a scratch
569 * space in front of the IP header.
571 scratch = payload - esp_sz;
572 esp0 = (esp_header_t *) (scratch);
574 scratch -= (sizeof (*aad) + pd->hdr_sz);
577 op->aad_len = esp_aad_fill (op->aad, esp0, sa0);
580 * we don't need to refer to the ESP header anymore so we
581 * can overwrite it with the salt and use the IV where it is
582 * to form the nonce = (Salt + IV)
584 op->iv -= sizeof (sa0->salt);
585 clib_memcpy_fast (op->iv, &sa0->salt, sizeof (sa0->salt));
587 op->tag = payload + len;
590 op->src = op->dst = payload += iv_sz;
591 op->len = len - iv_sz;
592 op->user_data = index;
594 if (pd->is_chain && (pd2->lb != b))
596 /* buffer is chained */
597 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
598 op->chunk_index = vec_len (ptd->chunks);
599 esp_decrypt_chain_crypto (vm, ptd, pd2, sa0, b, icv_sz,
600 payload, len - pd->iv_sz + pd->icv_sz,
601 &op->tag, &op->n_chunks);
604 vec_add_aligned (*(crypto_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
608 static_always_inline int
609 esp_decrypt_prepare_async_frame (vlib_main_t * vm,
610 vlib_node_runtime_t * node,
611 ipsec_per_thread_data_t * ptd,
612 vnet_crypto_async_frame_t ** f,
613 ipsec_sa_t * sa0, u8 * payload, u16 len,
615 esp_decrypt_packet_data_t * pd,
616 esp_decrypt_packet_data2_t * pd2, u32 bi,
617 vlib_buffer_t * b, u16 * next,
620 const u8 esp_sz = sizeof (esp_header_t);
621 u32 current_protect_index = vnet_buffer (b)->ipsec.protect_index;
622 esp_decrypt_packet_data_t *async_pd = &(esp_post_data (b))->decrypt_data;
623 esp_decrypt_packet_data2_t *async_pd2 = esp_post_data2 (b);
624 u8 *tag = payload + len, *iv = payload + esp_sz, *aad = 0;
626 u32 crypto_len, integ_len = 0;
627 i16 crypto_start_offset, integ_start_offset = 0;
630 if (!ipsec_sa_is_set_IS_AEAD (sa0))
633 key_index = sa0->linked_key_index;
634 integ_start_offset = payload - b->data;
639 /* buffer is chained */
640 integ_len = pd->current_length;
642 /* special case when ICV is splitted and needs to be reassembled
643 * first -> move it to the last buffer. Also take into account
644 * that ESN needs to be added after encrypted data and may or
645 * may not fit in the tail.*/
646 if (pd2->lb->current_length < icv_sz)
649 tag = esp_move_icv_esn (vm, b, pd2, icv_sz, sa0,
650 &extra_esn, &integ_len);
654 /* esn is in the last buffer, that was unlinked from
656 integ_len = b->current_length;
662 /* we now have a single buffer of crypto data, adjust
663 * the length (second buffer contains only ICV) */
664 len = b->current_length;
670 tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
672 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
673 if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz, payload,
674 pd->current_length, &tag,
677 /* allocate buffer failed, will not add to frame and drop */
678 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
679 next[0] = ESP_DECRYPT_NEXT_DROP;
684 esp_insert_esn (vm, sa0, pd2, &integ_len, &tag, &len, b, payload);
687 key_index = sa0->crypto_key_index;
695 if (ipsec_sa_is_set_IS_AEAD (sa0))
701 * construct the AAD and the nonce (Salt || IV) in a scratch
702 * space in front of the IP header.
704 scratch = payload - esp_sz;
705 esp0 = (esp_header_t *) (scratch);
707 scratch -= (sizeof (esp_aead_t) + pd->hdr_sz);
710 esp_aad_fill (aad, esp0, sa0);
713 * we don't need to refer to the ESP header anymore so we
714 * can overwrite it with the salt and use the IV where it is
715 * to form the nonce = (Salt + IV)
717 iv -= sizeof (sa0->salt);
718 clib_memcpy_fast (iv, &sa0->salt, sizeof (sa0->salt));
723 crypto_start_offset = (payload += iv_sz) - b->data;
724 crypto_len = len - iv_sz;
726 if (pd->is_chain && (pd2->lb != b))
728 /* buffer is chained */
729 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
731 crypto_len = esp_decrypt_chain_crypto (vm, ptd, pd2, sa0, b, icv_sz,
733 len - pd->iv_sz + pd->icv_sz,
739 pd->protect_index = current_protect_index;
741 /* for AEAD integ_len - crypto_len will be negative, it is ok since it
742 * is ignored by the engine. */
743 return vnet_crypto_async_add_to_frame (vm, f, key_index, crypto_len,
744 integ_len - crypto_len,
747 bi, async_next, iv, tag, aad, flags);
750 static_always_inline void
751 esp_decrypt_post_crypto (vlib_main_t * vm, vlib_node_runtime_t * node,
752 esp_decrypt_packet_data_t * pd,
753 esp_decrypt_packet_data2_t * pd2, vlib_buffer_t * b,
754 u16 * next, int is_ip6, int is_tun, int is_async)
756 ipsec_main_t *im = &ipsec_main;
757 ipsec_sa_t *sa0 = vec_elt_at_index (im->sad, pd->sa_index);
758 vlib_buffer_t *lb = b;
759 const u8 esp_sz = sizeof (esp_header_t);
760 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL | IPSEC_SA_FLAG_IS_TUNNEL_V6;
761 u8 pad_length = 0, next_header = 0;
765 * redo the anti-reply check
766 * in this frame say we have sequence numbers, s, s+1, s+1, s+1
767 * and s and s+1 are in the window. When we did the anti-replay
768 * check above we did so against the state of the window (W),
769 * after packet s-1. So each of the packets in the sequence will be
771 * This time s will be cheked against Ws-1, s+1 chceked against Ws
772 * (i.e. the window state is updated/advnaced)
773 * so this time the successive s+! packet will be dropped.
774 * This is a consequence of batching the decrypts. If the
775 * check-dcrypt-advance process was done for each packet it would
776 * be fine. But we batch the decrypts because it's much more efficient
777 * to do so in SW and if we offload to HW and the process is async.
779 * You're probably thinking, but this means an attacker can send the
780 * above sequence and cause VPP to perform decrpyts that will fail,
781 * and that's true. But if the attacker can determine s (a valid
782 * sequence number in the window) which is non-trivial, it can generate
783 * a sequence s, s+1, s+2, s+3, ... s+n and nothing will prevent any
784 * implementation, sequential or batching, from decrypting these.
786 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
788 b->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
789 next[0] = ESP_DECRYPT_NEXT_DROP;
793 ipsec_sa_anti_replay_advance (sa0, pd->seq);
798 icv_sz = pd2->icv_removed ? 0 : pd->icv_sz;
799 if (pd2->free_buffer_index)
801 vlib_buffer_free_one (vm, pd2->free_buffer_index);
804 if (lb->current_length < sizeof (esp_footer_t) + icv_sz)
806 /* esp footer is either splitted in two buffers or in the before
809 vlib_buffer_t *before_last = b, *bp = b;
810 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
813 bp = vlib_get_buffer (vm, bp->next_buffer);
815 u8 *bt = vlib_buffer_get_tail (before_last);
817 if (lb->current_length == icv_sz)
819 esp_footer_t *f = (esp_footer_t *) (bt - sizeof (*f));
820 pad_length = f->pad_length;
821 next_header = f->next_header;
825 pad_length = (bt - 1)[0];
826 next_header = ((u8 *) vlib_buffer_get_current (lb))[0];
832 (esp_footer_t *) (lb->data + lb->current_data +
833 lb->current_length - sizeof (esp_footer_t) -
835 pad_length = f->pad_length;
836 next_header = f->next_header;
843 (esp_footer_t *) (lb->data + lb->current_data + lb->current_length -
844 sizeof (esp_footer_t) - icv_sz);
845 pad_length = f->pad_length;
846 next_header = f->next_header;
849 u16 adv = pd->iv_sz + esp_sz;
850 u16 tail = sizeof (esp_footer_t) + pad_length + icv_sz;
851 u16 tail_orig = sizeof (esp_footer_t) + pad_length + pd->icv_sz;
852 b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
854 if ((pd->flags & tun_flags) == 0 && !is_tun) /* transport mode */
856 u8 udp_sz = (is_ip6 == 0 && pd->flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
857 sizeof (udp_header_t) : 0;
858 u16 ip_hdr_sz = pd->hdr_sz - udp_sz;
859 u8 *old_ip = b->data + pd->current_data - ip_hdr_sz - udp_sz;
860 u8 *ip = old_ip + adv + udp_sz;
862 if (is_ip6 && ip_hdr_sz > 64)
863 memmove (ip, old_ip, ip_hdr_sz);
865 clib_memcpy_le64 (ip, old_ip, ip_hdr_sz);
867 b->current_data = pd->current_data + adv - ip_hdr_sz;
868 b->current_length += ip_hdr_sz - adv;
869 esp_remove_tail (vm, b, lb, tail);
873 ip6_header_t *ip6 = (ip6_header_t *) ip;
874 u16 len = clib_net_to_host_u16 (ip6->payload_length);
875 len -= adv + tail_orig;
876 ip6->payload_length = clib_host_to_net_u16 (len);
877 ip6->protocol = next_header;
878 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
882 ip4_header_t *ip4 = (ip4_header_t *) ip;
883 ip_csum_t sum = ip4->checksum;
884 u16 len = clib_net_to_host_u16 (ip4->length);
885 len = clib_host_to_net_u16 (len - adv - tail_orig - udp_sz);
886 sum = ip_csum_update (sum, ip4->protocol, next_header,
887 ip4_header_t, protocol);
888 sum = ip_csum_update (sum, ip4->length, len, ip4_header_t, length);
889 ip4->checksum = ip_csum_fold (sum);
890 ip4->protocol = next_header;
892 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
897 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
899 next[0] = ESP_DECRYPT_NEXT_IP4_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);
904 else if (next_header == IP_PROTOCOL_IPV6)
906 next[0] = ESP_DECRYPT_NEXT_IP6_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);
913 if (is_tun && next_header == IP_PROTOCOL_GRE)
917 b->current_data = pd->current_data + adv;
918 b->current_length = pd->current_length - adv - tail;
920 gre = vlib_buffer_get_current (b);
922 vlib_buffer_advance (b, sizeof (*gre));
924 switch (clib_net_to_host_u16 (gre->protocol))
926 case GRE_PROTOCOL_teb:
927 vnet_update_l2_len (b);
928 next[0] = ESP_DECRYPT_NEXT_L2_INPUT;
930 case GRE_PROTOCOL_ip4:
931 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
933 case GRE_PROTOCOL_ip6:
934 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
937 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
938 next[0] = ESP_DECRYPT_NEXT_DROP;
944 next[0] = ESP_DECRYPT_NEXT_DROP;
945 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
951 if (ipsec_sa_is_set_IS_PROTECT (sa0))
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.
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.
969 const ipsec_tun_protect_t *itp;
972 itp = ipsec_tun_protect_get (pd->protect_index);
975 ipsec_tun_protect_get (vnet_buffer (b)->
976 ipsec.protect_index);
978 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
980 const ip4_header_t *ip4;
982 ip4 = vlib_buffer_get_current (b);
984 if (!ip46_address_is_equal_v4 (&itp->itp_tun.src,
985 &ip4->dst_address) ||
986 !ip46_address_is_equal_v4 (&itp->itp_tun.dst,
989 next[0] = ESP_DECRYPT_NEXT_DROP;
990 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
993 else if (next_header == IP_PROTOCOL_IPV6)
995 const ip6_header_t *ip6;
997 ip6 = vlib_buffer_get_current (b);
999 if (!ip46_address_is_equal_v6 (&itp->itp_tun.src,
1000 &ip6->dst_address) ||
1001 !ip46_address_is_equal_v6 (&itp->itp_tun.dst,
1004 next[0] = ESP_DECRYPT_NEXT_DROP;
1005 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
1014 esp_decrypt_inline (vlib_main_t * vm,
1015 vlib_node_runtime_t * node, vlib_frame_t * from_frame,
1016 int is_ip6, int is_tun, u16 async_next)
1018 ipsec_main_t *im = &ipsec_main;
1019 u32 thread_index = vm->thread_index;
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;
1024 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1025 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1026 esp_decrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
1027 esp_decrypt_packet_data2_t pkt_data2[VLIB_FRAME_SIZE], *pd2 = pkt_data2;
1028 esp_decrypt_packet_data_t cpd = { };
1029 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
1030 const u8 esp_sz = sizeof (esp_header_t);
1031 ipsec_sa_t *sa0 = 0;
1032 vnet_crypto_op_t _op, *op = &_op;
1033 vnet_crypto_op_t **crypto_ops = &ptd->crypto_ops;
1034 vnet_crypto_op_t **integ_ops = &ptd->integ_ops;
1035 vnet_crypto_async_frame_t *async_frame = 0;
1036 int is_async = im->async_mode;
1037 vnet_crypto_async_op_id_t last_async_op = ~0;
1038 u16 n_async_drop = 0;
1040 vlib_get_buffers (vm, from, b, n_left);
1043 vec_reset_length (ptd->crypto_ops);
1044 vec_reset_length (ptd->integ_ops);
1045 vec_reset_length (ptd->chained_crypto_ops);
1046 vec_reset_length (ptd->chained_integ_ops);
1048 vec_reset_length (ptd->chunks);
1049 clib_memset_u16 (nexts, -1, n_left);
1058 vlib_prefetch_buffer_header (b[2], LOAD);
1059 p = vlib_buffer_get_current (b[1]);
1060 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1061 p -= CLIB_CACHE_LINE_BYTES;
1062 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1065 u32 n_bufs = vlib_buffer_chain_linearize (vm, b[0]);
1068 b[0]->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
1069 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1070 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1071 next[0] = ESP_DECRYPT_NEXT_DROP;
1075 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
1077 if (current_sa_pkts)
1078 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1082 current_sa_bytes = current_sa_pkts = 0;
1084 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1085 sa0 = pool_elt_at_index (im->sad, current_sa_index);
1087 /* fetch the second cacheline ASAP */
1088 CLIB_PREFETCH (sa0->cacheline1, CLIB_CACHE_LINE_BYTES, LOAD);
1089 cpd.icv_sz = sa0->integ_icv_size;
1090 cpd.iv_sz = sa0->crypto_iv_size;
1091 cpd.flags = sa0->flags;
1092 cpd.sa_index = current_sa_index;
1094 /* submit frame when op_id is different then the old one */
1095 if (is_async && last_async_op != sa0->crypto_async_dec_op_id)
1097 if (async_frame && async_frame->n_elts)
1099 if (vnet_crypto_async_submit_open_frame (vm, async_frame))
1100 esp_async_recycle_failed_submit (async_frame, b, from,
1101 nexts, &n_async_drop,
1102 ESP_DECRYPT_NEXT_DROP,
1103 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1106 vnet_crypto_async_get_frame (vm, sa0->crypto_async_dec_op_id);
1107 last_async_op = sa0->crypto_async_dec_op_id;
1111 if (PREDICT_FALSE (~0 == sa0->decrypt_thread_index))
1113 /* this is the first packet to use this SA, claim the SA
1114 * for this thread. this could happen simultaneously on
1116 clib_atomic_cmp_and_swap (&sa0->decrypt_thread_index, ~0,
1117 ipsec_sa_assign_thread (thread_index));
1120 if (PREDICT_FALSE (thread_index != sa0->decrypt_thread_index))
1122 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1123 &n_async_drop, ESP_DECRYPT_NEXT_HANDOFF, next);
1124 next[0] = ESP_DECRYPT_NEXT_HANDOFF;
1128 /* store packet data for next round for easier prefetch */
1129 pd->sa_data = cpd.sa_data;
1130 pd->current_data = b[0]->current_data;
1131 pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
1132 payload = b[0]->data + pd->current_data;
1133 pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq);
1136 pd2->free_buffer_index = 0;
1137 pd2->icv_removed = 0;
1142 /* find last buffer in the chain */
1143 while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT)
1144 pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer);
1146 crypto_ops = &ptd->chained_crypto_ops;
1147 integ_ops = &ptd->chained_integ_ops;
1150 pd->current_length = b[0]->current_length;
1152 /* anti-reply check */
1153 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
1155 b[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
1156 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1157 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1161 if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
1163 b[0]->error = node->errors[ESP_DECRYPT_ERROR_RUNT];
1164 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1165 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1169 len = pd->current_length - cpd.icv_sz;
1170 current_sa_pkts += 1;
1171 current_sa_bytes += vlib_buffer_length_in_chain (vm, b[0]);
1175 int ret = esp_decrypt_prepare_async_frame (vm, node, ptd,
1182 b[0], next, async_next);
1183 if (PREDICT_FALSE (ret < 0))
1185 b[0]->error = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
1186 esp_set_next_index (1, from, nexts, from[b - bufs],
1187 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1188 /* when next[0] is ESP_DECRYPT_NEXT_DROP we only have to drop
1189 * the current packet. Otherwise it is frame submission error
1190 * thus we have to drop the whole frame.
1192 if (next[0] != ESP_DECRYPT_NEXT_DROP && async_frame->n_elts)
1193 esp_async_recycle_failed_submit (async_frame, b, from,
1194 nexts, &n_async_drop,
1195 ESP_DECRYPT_NEXT_DROP,
1196 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1201 esp_decrypt_prepare_sync_op (vm, node, ptd, &crypto_ops, &integ_ops,
1202 op, sa0, payload, len, cpd.icv_sz,
1203 cpd.iv_sz, pd, pd2, b[0], next,
1214 if (PREDICT_TRUE (~0 != current_sa_index))
1215 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1216 current_sa_index, current_sa_pkts,
1221 if (async_frame && async_frame->n_elts)
1223 if (vnet_crypto_async_submit_open_frame (vm, async_frame) < 0)
1224 esp_async_recycle_failed_submit (async_frame, b, from, nexts,
1226 ESP_DECRYPT_NEXT_DROP,
1227 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1230 /* no post process in async */
1231 vlib_node_increment_counter (vm, node->node_index,
1232 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1234 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_async_drop);
1240 esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts,
1241 ESP_DECRYPT_ERROR_INTEG_ERROR);
1242 esp_process_chained_ops (vm, node, ptd->chained_integ_ops, bufs, nexts,
1243 ptd->chunks, ESP_DECRYPT_ERROR_INTEG_ERROR);
1245 esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts,
1246 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1247 esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, bufs, nexts,
1249 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1252 /* Post decryption ronud - adjust packet data start and length and next
1255 n_left = from_frame->n_vectors;
1265 void *data = b[1]->data + pd[1].current_data;
1267 /* buffer metadata */
1268 vlib_prefetch_buffer_header (b[1], LOAD);
1271 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
1272 CLIB_CACHE_LINE_BYTES, LOAD);
1274 /* packet headers */
1275 CLIB_PREFETCH (data - CLIB_CACHE_LINE_BYTES,
1276 CLIB_CACHE_LINE_BYTES * 2, LOAD);
1279 /* save the sa_index as GRE_teb post_crypto changes L2 opaque */
1280 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1281 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1283 if (next[0] >= ESP_DECRYPT_N_NEXT)
1284 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1288 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1290 esp_decrypt_trace_t *tr;
1291 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1292 sa0 = pool_elt_at_index (im->sad, current_sa_index);
1293 tr->crypto_alg = sa0->crypto_alg;
1294 tr->integ_alg = sa0->integ_alg;
1296 tr->sa_seq = sa0->last_seq;
1297 tr->sa_seq_hi = sa0->seq_hi;
1308 n_left = from_frame->n_vectors;
1309 vlib_node_increment_counter (vm, node->node_index,
1310 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1312 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1318 esp_decrypt_post_inline (vlib_main_t * vm,
1319 vlib_node_runtime_t * node,
1320 vlib_frame_t * from_frame, int is_ip6, int is_tun)
1322 ipsec_main_t *im = &ipsec_main;
1323 u32 *from = vlib_frame_vector_args (from_frame);
1324 u32 n_left = from_frame->n_vectors;
1325 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1326 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1327 vlib_get_buffers (vm, from, b, n_left);
1331 esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data;
1335 vlib_prefetch_buffer_header (b[2], LOAD);
1336 vlib_prefetch_buffer_header (b[1], LOAD);
1340 esp_decrypt_post_crypto (vm, node, pd, 0, b[0], next, is_ip6, is_tun,
1344 esp_decrypt_packet_data2_t *pd2 = esp_post_data2 (b[0]);
1345 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1350 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1352 ipsec_sa_t *sa0 = pool_elt_at_index (im->sad, pd->sa_index);
1353 esp_decrypt_trace_t *tr;
1354 esp_decrypt_packet_data_t *async_pd =
1355 &(esp_post_data (b[0]))->decrypt_data;
1356 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1357 sa0 = pool_elt_at_index (im->sad, async_pd->sa_index);
1359 tr->crypto_alg = sa0->crypto_alg;
1360 tr->integ_alg = sa0->integ_alg;
1362 tr->sa_seq = sa0->last_seq;
1363 tr->sa_seq_hi = sa0->seq_hi;
1371 n_left = from_frame->n_vectors;
1372 vlib_node_increment_counter (vm, node->node_index,
1373 ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left);
1375 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1380 VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm,
1381 vlib_node_runtime_t * node,
1382 vlib_frame_t * from_frame)
1384 return esp_decrypt_inline (vm, node, from_frame, 0, 0,
1385 esp_decrypt_async_next.esp4_post_next);
1388 VLIB_NODE_FN (esp4_decrypt_post_node) (vlib_main_t * vm,
1389 vlib_node_runtime_t * node,
1390 vlib_frame_t * from_frame)
1392 return esp_decrypt_post_inline (vm, node, from_frame, 0, 0);
1395 VLIB_NODE_FN (esp4_decrypt_tun_node) (vlib_main_t * vm,
1396 vlib_node_runtime_t * node,
1397 vlib_frame_t * from_frame)
1399 return esp_decrypt_inline (vm, node, from_frame, 0, 1,
1400 esp_decrypt_async_next.esp4_tun_post_next);
1403 VLIB_NODE_FN (esp4_decrypt_tun_post_node) (vlib_main_t * vm,
1404 vlib_node_runtime_t * node,
1405 vlib_frame_t * from_frame)
1407 return esp_decrypt_post_inline (vm, node, from_frame, 0, 1);
1410 VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm,
1411 vlib_node_runtime_t * node,
1412 vlib_frame_t * from_frame)
1414 return esp_decrypt_inline (vm, node, from_frame, 1, 0,
1415 esp_decrypt_async_next.esp6_post_next);
1418 VLIB_NODE_FN (esp6_decrypt_post_node) (vlib_main_t * vm,
1419 vlib_node_runtime_t * node,
1420 vlib_frame_t * from_frame)
1422 return esp_decrypt_post_inline (vm, node, from_frame, 1, 0);
1425 VLIB_NODE_FN (esp6_decrypt_tun_node) (vlib_main_t * vm,
1426 vlib_node_runtime_t * node,
1427 vlib_frame_t * from_frame)
1429 return esp_decrypt_inline (vm, node, from_frame, 1, 1,
1430 esp_decrypt_async_next.esp6_tun_post_next);
1433 VLIB_NODE_FN (esp6_decrypt_tun_post_node) (vlib_main_t * vm,
1434 vlib_node_runtime_t * node,
1435 vlib_frame_t * from_frame)
1437 return esp_decrypt_post_inline (vm, node, from_frame, 1, 1);
1441 VLIB_REGISTER_NODE (esp4_decrypt_node) = {
1442 .name = "esp4-decrypt",
1443 .vector_size = sizeof (u32),
1444 .format_trace = format_esp_decrypt_trace,
1445 .type = VLIB_NODE_TYPE_INTERNAL,
1447 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1448 .error_strings = esp_decrypt_error_strings,
1450 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1452 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1453 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1454 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1455 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1456 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff",
1460 VLIB_REGISTER_NODE (esp4_decrypt_post_node) = {
1461 .name = "esp4-decrypt-post",
1462 .vector_size = sizeof (u32),
1463 .format_trace = format_esp_decrypt_trace,
1464 .type = VLIB_NODE_TYPE_INTERNAL,
1466 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1467 .error_strings = esp_decrypt_error_strings,
1469 .sibling_of = "esp4-decrypt",
1472 VLIB_REGISTER_NODE (esp6_decrypt_node) = {
1473 .name = "esp6-decrypt",
1474 .vector_size = sizeof (u32),
1475 .format_trace = format_esp_decrypt_trace,
1476 .type = VLIB_NODE_TYPE_INTERNAL,
1478 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1479 .error_strings = esp_decrypt_error_strings,
1481 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1483 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1484 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1485 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1486 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1487 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff",
1491 VLIB_REGISTER_NODE (esp6_decrypt_post_node) = {
1492 .name = "esp6-decrypt-post",
1493 .vector_size = sizeof (u32),
1494 .format_trace = format_esp_decrypt_trace,
1495 .type = VLIB_NODE_TYPE_INTERNAL,
1497 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1498 .error_strings = esp_decrypt_error_strings,
1500 .sibling_of = "esp6-decrypt",
1503 VLIB_REGISTER_NODE (esp4_decrypt_tun_node) = {
1504 .name = "esp4-decrypt-tun",
1505 .vector_size = sizeof (u32),
1506 .format_trace = format_esp_decrypt_trace,
1507 .type = VLIB_NODE_TYPE_INTERNAL,
1508 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1509 .error_strings = esp_decrypt_error_strings,
1510 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1512 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1513 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1514 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1515 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1516 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff",
1520 VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node) = {
1521 .name = "esp4-decrypt-tun-post",
1522 .vector_size = sizeof (u32),
1523 .format_trace = format_esp_decrypt_trace,
1524 .type = VLIB_NODE_TYPE_INTERNAL,
1526 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1527 .error_strings = esp_decrypt_error_strings,
1529 .sibling_of = "esp4-decrypt-tun",
1532 VLIB_REGISTER_NODE (esp6_decrypt_tun_node) = {
1533 .name = "esp6-decrypt-tun",
1534 .vector_size = sizeof (u32),
1535 .format_trace = format_esp_decrypt_trace,
1536 .type = VLIB_NODE_TYPE_INTERNAL,
1537 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1538 .error_strings = esp_decrypt_error_strings,
1539 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1541 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1542 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1543 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1544 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1545 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff",
1549 VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node) = {
1550 .name = "esp6-decrypt-tun-post",
1551 .vector_size = sizeof (u32),
1552 .format_trace = format_esp_decrypt_trace,
1553 .type = VLIB_NODE_TYPE_INTERNAL,
1555 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1556 .error_strings = esp_decrypt_error_strings,
1558 .sibling_of = "esp6-decrypt-tun",
1563 * fd.io coding-style-patch-verification: ON
1566 * eval: (c-set-style "gnu")