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") \
35 _ (MPLS_INPUT, "mpls-input") \
36 _ (HANDOFF, "handoff")
38 #define _(v, s) ESP_DECRYPT_NEXT_##v,
41 foreach_esp_decrypt_next
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")
53 #define _(v, s) ESP_DECRYPT_POST_NEXT_##v,
56 foreach_esp_decrypt_post_next
58 ESP_DECRYPT_POST_N_NEXT,
59 } esp_decrypt_post_next_t;
61 #define foreach_esp_decrypt_error \
62 _(RX_PKTS, "ESP pkts received") \
63 _(RX_POST_PKTS, "ESP-POST pkts received") \
64 _(DECRYPTION_FAILED, "ESP decryption failed") \
65 _(INTEG_ERROR, "Integrity check failed") \
66 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
67 _(REPLAY, "SA replayed packet") \
68 _(RUNT, "undersized packet") \
69 _(NO_BUFFERS, "no buffers (packet dropped)") \
70 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \
71 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \
72 _(TUN_NO_PROTO, "no tunnel protocol") \
73 _(UNSUP_PAYLOAD, "unsupported payload") \
78 #define _(sym,str) ESP_DECRYPT_ERROR_##sym,
79 foreach_esp_decrypt_error
82 } esp_decrypt_error_t;
84 static char *esp_decrypt_error_strings[] = {
85 #define _(sym,string) string,
86 foreach_esp_decrypt_error
95 ipsec_crypto_alg_t crypto_alg;
96 ipsec_integ_alg_t integ_alg;
97 } esp_decrypt_trace_t;
99 /* packet trace format function */
101 format_esp_decrypt_trace (u8 * s, va_list * args)
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 *);
109 "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
110 format_ipsec_crypto_alg, t->crypto_alg, format_ipsec_integ_alg,
111 t->integ_alg, t->seq, t->sa_seq, t->sa_seq_hi);
115 #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2)
117 static_always_inline void
118 esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
119 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts,
122 vnet_crypto_op_t *op = ops;
123 u32 n_fail, n_ops = vec_len (ops);
128 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
132 ASSERT (op - ops < n_ops);
133 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
135 u32 err, bi = op->user_data;
136 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
139 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
140 b[bi]->error = node->errors[err];
141 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
148 static_always_inline void
149 esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
150 vnet_crypto_op_t * ops, vlib_buffer_t * b[],
151 u16 * nexts, vnet_crypto_op_chunk_t * chunks, int e)
154 vnet_crypto_op_t *op = ops;
155 u32 n_fail, n_ops = vec_len (ops);
160 n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops);
164 ASSERT (op - ops < n_ops);
165 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
167 u32 err, bi = op->user_data;
168 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
171 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
172 b[bi]->error = node->errors[err];
173 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
181 esp_remove_tail (vlib_main_t * vm, vlib_buffer_t * b, vlib_buffer_t * last,
184 vlib_buffer_t *before_last = b;
186 if (last->current_length > tail)
188 last->current_length -= tail;
191 ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
193 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
196 b = vlib_get_buffer (vm, b->next_buffer);
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;
203 /* ICV is splitted in last two buffers so move it to the last buffer and
204 return pointer to it */
205 static_always_inline u8 *
206 esp_move_icv (vlib_main_t * vm, vlib_buffer_t * first,
207 esp_decrypt_packet_data_t * pd,
208 esp_decrypt_packet_data2_t * pd2, u16 icv_sz, u16 * dif)
210 vlib_buffer_t *before_last, *bp;
211 u16 last_sz = pd2->lb->current_length;
212 u16 first_sz = icv_sz - last_sz;
214 bp = before_last = first;
215 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
218 bp = vlib_get_buffer (vm, bp->next_buffer);
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,
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);
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;
238 static_always_inline i16
239 esp_insert_esn (vlib_main_t * vm, ipsec_sa_t * sa,
240 esp_decrypt_packet_data2_t * pd2, u32 * data_len,
241 u8 ** digest, u16 * len, vlib_buffer_t * b, u8 * payload)
243 if (!ipsec_sa_is_set_USE_ESN (sa))
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);
250 if (pd2->icv_removed)
252 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
253 if (space_left >= sz)
255 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
261 len[0] = b->current_length;
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);
274 static_always_inline u8 *
275 esp_move_icv_esn (vlib_main_t * vm, vlib_buffer_t * first,
276 esp_decrypt_packet_data_t * pd,
277 esp_decrypt_packet_data2_t * pd2, u16 icv_sz,
278 ipsec_sa_t * sa, u8 * extra_esn, u32 * len)
281 u8 *digest = esp_move_icv (vm, first, pd, pd2, icv_sz, &dif);
285 if (ipsec_sa_is_set_USE_ESN (sa))
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);
291 if (space_left >= sz)
293 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
298 /* no space for ESN at the tail, use the next buffer
300 ASSERT (pd2->icv_removed);
301 vlib_buffer_t *tmp = vlib_get_buffer (vm, pd2->free_buffer_index);
302 clib_memcpy_fast (vlib_buffer_get_current (tmp) - sz, &seq_hi, sz);
309 static_always_inline int
310 esp_decrypt_chain_integ (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
311 esp_decrypt_packet_data2_t * pd2,
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)
316 vnet_crypto_op_chunk_t *ch;
317 vlib_buffer_t *cb = vlib_get_buffer (vm, b->next_buffer);
320 vec_add2 (ptd->chunks, ch, 1);
321 total_len = ch->len = start_len;
326 vec_add2 (ptd->chunks, ch, 1);
328 ch->src = vlib_buffer_get_current (cb);
331 if (pd2->icv_removed)
332 ch->len = cb->current_length;
334 ch->len = cb->current_length - icv_sz;
335 if (ipsec_sa_is_set_USE_ESN (sa0))
337 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
338 u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa0->seq_hi);
340 vlib_buffer_t *tmp_b;
341 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
344 if (pd2->icv_removed)
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;
353 /* no space, need to allocate new buffer */
355 if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1)
357 tmp_b = vlib_get_buffer (vm, tmp_bi);
359 pd2->free_buffer_index = tmp_bi;
361 clib_memcpy_fast (esn, &seq_hi, sz);
363 vec_add2 (ptd->chunks, ch, 1);
370 if (pd2->icv_removed)
372 clib_memcpy_fast (vlib_buffer_get_tail
373 (pd2->lb), &seq_hi, sz);
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);
385 total_len += ch->len;
389 total_len += ch->len = cb->current_length;
391 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
394 cb = vlib_get_buffer (vm, cb->next_buffer);
400 *integ_total_len = total_len;
405 static_always_inline u32
406 esp_decrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
407 esp_decrypt_packet_data_t * pd,
408 esp_decrypt_packet_data2_t * pd2,
409 ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
410 u8 * start, u32 start_len, u8 ** tag, u16 * n_ch)
412 vnet_crypto_op_chunk_t *ch;
413 vlib_buffer_t *cb = b;
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);
424 vec_add2 (ptd->chunks, ch, 1);
426 ch->src = ch->dst = vlib_buffer_get_current (cb);
429 if (ipsec_sa_is_set_IS_AEAD (sa0))
431 if (pd2->lb->current_length < icv_sz)
434 *tag = esp_move_icv (vm, b, pd, pd2, icv_sz, &dif);
436 /* this chunk does not contain crypto data */
438 /* and fix previous chunk's length as it might have
440 ASSERT (n_chunks > 0);
448 total_len = total_len + pd2->lb->current_length -
450 ch[-1].len = pd2->lb->current_length;
455 *tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
458 if (pd2->icv_removed)
459 total_len += ch->len = cb->current_length;
461 total_len += ch->len = cb->current_length - icv_sz;
464 total_len += ch->len = cb->current_length;
466 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
469 cb = vlib_get_buffer (vm, cb->next_buffer);
478 static_always_inline void
479 esp_decrypt_prepare_sync_op (vlib_main_t * vm, vlib_node_runtime_t * node,
480 ipsec_per_thread_data_t * ptd,
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,
486 esp_decrypt_packet_data_t * pd,
487 esp_decrypt_packet_data2_t * pd2,
488 vlib_buffer_t * b, u16 * next, u32 index)
490 const u8 esp_sz = sizeof (esp_header_t);
492 if (PREDICT_TRUE (sa0->integ_op_id != VNET_CRYPTO_OP_NONE))
494 vnet_crypto_op_init (op, sa0->integ_op_id);
495 op->key_index = sa0->integ_key_index;
497 op->flags = VNET_CRYPTO_OP_FLAG_HMAC_CHECK;
498 op->user_data = index;
499 op->digest = payload + len;
500 op->digest_len = icv_sz;
505 /* buffer is chained */
506 op->len = pd->current_length;
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)
516 esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0,
517 &extra_esn, &op->len);
521 /* esn is in the last buffer, that was unlinked from
523 op->len = b->current_length;
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;
539 op->digest = vlib_buffer_get_tail (pd2->lb) - icv_sz;
541 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
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)
547 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
548 next[0] = ESP_DECRYPT_NEXT_DROP;
553 esp_insert_esn (vm, sa0, pd2, &op->len, &op->digest, &len, b,
556 vec_add_aligned (*(integ_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
562 if (sa0->crypto_dec_op_id != VNET_CRYPTO_OP_NONE)
564 vnet_crypto_op_init (op, sa0->crypto_dec_op_id);
565 op->key_index = sa0->crypto_key_index;
568 if (ipsec_sa_is_set_IS_AEAD (sa0))
575 * construct the AAD and the nonce (Salt || IV) in a scratch
576 * space in front of the IP header.
578 scratch = payload - esp_sz;
579 esp0 = (esp_header_t *) (scratch);
581 scratch -= (sizeof (*aad) + pd->hdr_sz);
584 op->aad_len = esp_aad_fill (op->aad, esp0, sa0);
587 * we don't need to refer to the ESP header anymore so we
588 * can overwrite it with the salt and use the IV where it is
589 * to form the nonce = (Salt + IV)
591 op->iv -= sizeof (sa0->salt);
592 clib_memcpy_fast (op->iv, &sa0->salt, sizeof (sa0->salt));
594 op->tag = payload + len;
597 op->src = op->dst = payload += iv_sz;
598 op->len = len - iv_sz;
599 op->user_data = index;
601 if (pd->is_chain && (pd2->lb != b))
603 /* buffer is chained */
604 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
605 op->chunk_index = vec_len (ptd->chunks);
606 esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz,
607 payload, len - pd->iv_sz + pd->icv_sz,
608 &op->tag, &op->n_chunks);
611 vec_add_aligned (*(crypto_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
615 static_always_inline int
616 esp_decrypt_prepare_async_frame (vlib_main_t * vm,
617 vlib_node_runtime_t * node,
618 ipsec_per_thread_data_t * ptd,
619 vnet_crypto_async_frame_t ** f,
620 ipsec_sa_t * sa0, u8 * payload, u16 len,
622 esp_decrypt_packet_data_t * pd,
623 esp_decrypt_packet_data2_t * pd2, u32 bi,
624 vlib_buffer_t * b, u16 * next,
627 const u8 esp_sz = sizeof (esp_header_t);
628 u32 current_protect_index = vnet_buffer (b)->ipsec.protect_index;
629 esp_decrypt_packet_data_t *async_pd = &(esp_post_data (b))->decrypt_data;
630 esp_decrypt_packet_data2_t *async_pd2 = esp_post_data2 (b);
631 u8 *tag = payload + len, *iv = payload + esp_sz, *aad = 0;
633 u32 crypto_len, integ_len = 0;
634 i16 crypto_start_offset, integ_start_offset = 0;
637 if (!ipsec_sa_is_set_IS_AEAD (sa0))
640 key_index = sa0->linked_key_index;
641 integ_start_offset = payload - b->data;
646 /* buffer is chained */
647 integ_len = pd->current_length;
649 /* special case when ICV is splitted and needs to be reassembled
650 * first -> move it to the last buffer. Also take into account
651 * that ESN needs to be added after encrypted data and may or
652 * may not fit in the tail.*/
653 if (pd2->lb->current_length < icv_sz)
656 tag = esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0,
657 &extra_esn, &integ_len);
661 /* esn is in the last buffer, that was unlinked from
663 integ_len = b->current_length;
669 /* we now have a single buffer of crypto data, adjust
670 * the length (second buffer contains only ICV) */
671 len = b->current_length;
677 tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
679 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
680 if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz, payload,
681 pd->current_length, &tag,
684 /* allocate buffer failed, will not add to frame and drop */
685 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
686 next[0] = ESP_DECRYPT_NEXT_DROP;
691 esp_insert_esn (vm, sa0, pd2, &integ_len, &tag, &len, b, payload);
694 key_index = sa0->crypto_key_index;
702 if (ipsec_sa_is_set_IS_AEAD (sa0))
708 * construct the AAD and the nonce (Salt || IV) in a scratch
709 * space in front of the IP header.
711 scratch = payload - esp_sz;
712 esp0 = (esp_header_t *) (scratch);
714 scratch -= (sizeof (esp_aead_t) + pd->hdr_sz);
717 esp_aad_fill (aad, esp0, sa0);
720 * we don't need to refer to the ESP header anymore so we
721 * can overwrite it with the salt and use the IV where it is
722 * to form the nonce = (Salt + IV)
724 iv -= sizeof (sa0->salt);
725 clib_memcpy_fast (iv, &sa0->salt, sizeof (sa0->salt));
730 crypto_start_offset = (payload += iv_sz) - b->data;
731 crypto_len = len - iv_sz;
733 if (pd->is_chain && (pd2->lb != b))
735 /* buffer is chained */
736 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
738 crypto_len = esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz,
740 len - pd->iv_sz + pd->icv_sz,
746 pd->protect_index = current_protect_index;
748 /* for AEAD integ_len - crypto_len will be negative, it is ok since it
749 * is ignored by the engine. */
750 return vnet_crypto_async_add_to_frame (vm, f, key_index, crypto_len,
751 integ_len - crypto_len,
754 bi, async_next, iv, tag, aad, flags);
757 static_always_inline void
758 esp_decrypt_post_crypto (vlib_main_t * vm, vlib_node_runtime_t * node,
759 esp_decrypt_packet_data_t * pd,
760 esp_decrypt_packet_data2_t * pd2, vlib_buffer_t * b,
761 u16 * next, int is_ip6, int is_tun, int is_async)
763 ipsec_main_t *im = &ipsec_main;
764 ipsec_sa_t *sa0 = vec_elt_at_index (im->sad, pd->sa_index);
765 vlib_buffer_t *lb = b;
766 const u8 esp_sz = sizeof (esp_header_t);
767 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL | IPSEC_SA_FLAG_IS_TUNNEL_V6;
768 u8 pad_length = 0, next_header = 0;
772 * redo the anti-reply check
773 * in this frame say we have sequence numbers, s, s+1, s+1, s+1
774 * and s and s+1 are in the window. When we did the anti-replay
775 * check above we did so against the state of the window (W),
776 * after packet s-1. So each of the packets in the sequence will be
778 * This time s will be cheked against Ws-1, s+1 chceked against Ws
779 * (i.e. the window state is updated/advnaced)
780 * so this time the successive s+! packet will be dropped.
781 * This is a consequence of batching the decrypts. If the
782 * check-dcrypt-advance process was done for each packet it would
783 * be fine. But we batch the decrypts because it's much more efficient
784 * to do so in SW and if we offload to HW and the process is async.
786 * You're probably thinking, but this means an attacker can send the
787 * above sequence and cause VPP to perform decrpyts that will fail,
788 * and that's true. But if the attacker can determine s (a valid
789 * sequence number in the window) which is non-trivial, it can generate
790 * a sequence s, s+1, s+2, s+3, ... s+n and nothing will prevent any
791 * implementation, sequential or batching, from decrypting these.
793 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
795 b->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
796 next[0] = ESP_DECRYPT_NEXT_DROP;
800 ipsec_sa_anti_replay_advance (sa0, pd->seq);
805 icv_sz = pd2->icv_removed ? 0 : pd->icv_sz;
806 if (pd2->free_buffer_index)
808 vlib_buffer_free_one (vm, pd2->free_buffer_index);
811 if (lb->current_length < sizeof (esp_footer_t) + icv_sz)
813 /* esp footer is either splitted in two buffers or in the before
816 vlib_buffer_t *before_last = b, *bp = b;
817 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
820 bp = vlib_get_buffer (vm, bp->next_buffer);
822 u8 *bt = vlib_buffer_get_tail (before_last);
824 if (lb->current_length == icv_sz)
826 esp_footer_t *f = (esp_footer_t *) (bt - sizeof (*f));
827 pad_length = f->pad_length;
828 next_header = f->next_header;
832 pad_length = (bt - 1)[0];
833 next_header = ((u8 *) vlib_buffer_get_current (lb))[0];
839 (esp_footer_t *) (lb->data + lb->current_data +
840 lb->current_length - sizeof (esp_footer_t) -
842 pad_length = f->pad_length;
843 next_header = f->next_header;
850 (esp_footer_t *) (lb->data + lb->current_data + lb->current_length -
851 sizeof (esp_footer_t) - icv_sz);
852 pad_length = f->pad_length;
853 next_header = f->next_header;
856 u16 adv = pd->iv_sz + esp_sz;
857 u16 tail = sizeof (esp_footer_t) + pad_length + icv_sz;
858 u16 tail_orig = sizeof (esp_footer_t) + pad_length + pd->icv_sz;
859 b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
861 if ((pd->flags & tun_flags) == 0 && !is_tun) /* transport mode */
863 u8 udp_sz = (is_ip6 == 0 && pd->flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
864 sizeof (udp_header_t) : 0;
865 u16 ip_hdr_sz = pd->hdr_sz - udp_sz;
866 u8 *old_ip = b->data + pd->current_data - ip_hdr_sz - udp_sz;
867 u8 *ip = old_ip + adv + udp_sz;
869 if (is_ip6 && ip_hdr_sz > 64)
870 memmove (ip, old_ip, ip_hdr_sz);
872 clib_memcpy_le64 (ip, old_ip, ip_hdr_sz);
874 b->current_data = pd->current_data + adv - ip_hdr_sz;
875 b->current_length += ip_hdr_sz - adv;
876 esp_remove_tail (vm, b, lb, tail);
880 ip6_header_t *ip6 = (ip6_header_t *) ip;
881 u16 len = clib_net_to_host_u16 (ip6->payload_length);
882 len -= adv + tail_orig;
883 ip6->payload_length = clib_host_to_net_u16 (len);
884 ip6->protocol = next_header;
885 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
889 ip4_header_t *ip4 = (ip4_header_t *) ip;
890 ip_csum_t sum = ip4->checksum;
891 u16 len = clib_net_to_host_u16 (ip4->length);
892 len = clib_host_to_net_u16 (len - adv - tail_orig - udp_sz);
893 sum = ip_csum_update (sum, ip4->protocol, next_header,
894 ip4_header_t, protocol);
895 sum = ip_csum_update (sum, ip4->length, len, ip4_header_t, length);
896 ip4->checksum = ip_csum_fold (sum);
897 ip4->protocol = next_header;
899 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
904 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
906 next[0] = ESP_DECRYPT_NEXT_IP4_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);
911 else if (next_header == IP_PROTOCOL_IPV6)
913 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
914 b->current_data = pd->current_data + adv;
915 b->current_length = pd->current_length - adv;
916 esp_remove_tail (vm, b, lb, tail);
918 else if (next_header == IP_PROTOCOL_MPLS_IN_IP)
920 next[0] = ESP_DECRYPT_NEXT_MPLS_INPUT;
921 b->current_data = pd->current_data + adv;
922 b->current_length = pd->current_length - adv;
923 esp_remove_tail (vm, b, lb, tail);
927 if (is_tun && next_header == IP_PROTOCOL_GRE)
931 b->current_data = pd->current_data + adv;
932 b->current_length = pd->current_length - adv - tail;
934 gre = vlib_buffer_get_current (b);
936 vlib_buffer_advance (b, sizeof (*gre));
938 switch (clib_net_to_host_u16 (gre->protocol))
940 case GRE_PROTOCOL_teb:
941 vnet_update_l2_len (b);
942 next[0] = ESP_DECRYPT_NEXT_L2_INPUT;
944 case GRE_PROTOCOL_ip4:
945 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
947 case GRE_PROTOCOL_ip6:
948 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
951 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
952 next[0] = ESP_DECRYPT_NEXT_DROP;
958 next[0] = ESP_DECRYPT_NEXT_DROP;
959 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
965 if (ipsec_sa_is_set_IS_PROTECT (sa0))
968 * There are two encap possibilities
969 * 1) the tunnel and ths SA are prodiving encap, i.e. it's
970 * MAC | SA-IP | TUN-IP | ESP | PAYLOAD
971 * implying the SA is in tunnel mode (on a tunnel interface)
972 * 2) only the tunnel provides encap
973 * MAC | TUN-IP | ESP | PAYLOAD
974 * implying the SA is in transport mode.
976 * For 2) we need only strip the tunnel encap and we're good.
977 * since the tunnel and crypto ecnap (int the tun=protect
978 * object) are the same and we verified above that these match
979 * for 1) we need to strip the SA-IP outer headers, to
980 * reveal the tunnel IP and then check that this matches
981 * the configured tunnel.
983 const ipsec_tun_protect_t *itp;
986 itp = ipsec_tun_protect_get (pd->protect_index);
989 ipsec_tun_protect_get (vnet_buffer (b)->
990 ipsec.protect_index);
992 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
994 const ip4_header_t *ip4;
996 ip4 = vlib_buffer_get_current (b);
998 if (!ip46_address_is_equal_v4 (&itp->itp_tun.src,
999 &ip4->dst_address) ||
1000 !ip46_address_is_equal_v4 (&itp->itp_tun.dst,
1003 next[0] = ESP_DECRYPT_NEXT_DROP;
1004 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
1007 else if (next_header == IP_PROTOCOL_IPV6)
1009 const ip6_header_t *ip6;
1011 ip6 = vlib_buffer_get_current (b);
1013 if (!ip46_address_is_equal_v6 (&itp->itp_tun.src,
1014 &ip6->dst_address) ||
1015 !ip46_address_is_equal_v6 (&itp->itp_tun.dst,
1018 next[0] = ESP_DECRYPT_NEXT_DROP;
1019 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
1028 esp_decrypt_inline (vlib_main_t * vm,
1029 vlib_node_runtime_t * node, vlib_frame_t * from_frame,
1030 int is_ip6, int is_tun, u16 async_next)
1032 ipsec_main_t *im = &ipsec_main;
1033 u32 thread_index = vm->thread_index;
1035 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
1036 u32 *from = vlib_frame_vector_args (from_frame);
1037 u32 n_left = from_frame->n_vectors;
1038 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1039 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1040 esp_decrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
1041 esp_decrypt_packet_data2_t pkt_data2[VLIB_FRAME_SIZE], *pd2 = pkt_data2;
1042 esp_decrypt_packet_data_t cpd = { };
1043 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
1044 const u8 esp_sz = sizeof (esp_header_t);
1045 ipsec_sa_t *sa0 = 0;
1046 vnet_crypto_op_t _op, *op = &_op;
1047 vnet_crypto_op_t **crypto_ops = &ptd->crypto_ops;
1048 vnet_crypto_op_t **integ_ops = &ptd->integ_ops;
1049 vnet_crypto_async_frame_t *async_frame = 0;
1050 int is_async = im->async_mode;
1051 vnet_crypto_async_op_id_t last_async_op = ~0;
1052 u16 n_async_drop = 0;
1054 vlib_get_buffers (vm, from, b, n_left);
1057 vec_reset_length (ptd->crypto_ops);
1058 vec_reset_length (ptd->integ_ops);
1059 vec_reset_length (ptd->chained_crypto_ops);
1060 vec_reset_length (ptd->chained_integ_ops);
1062 vec_reset_length (ptd->chunks);
1063 clib_memset_u16 (nexts, -1, n_left);
1072 vlib_prefetch_buffer_header (b[2], LOAD);
1073 p = vlib_buffer_get_current (b[1]);
1074 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1075 p -= CLIB_CACHE_LINE_BYTES;
1076 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1079 u32 n_bufs = vlib_buffer_chain_linearize (vm, b[0]);
1082 b[0]->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
1083 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1084 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1085 next[0] = ESP_DECRYPT_NEXT_DROP;
1089 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
1091 if (current_sa_pkts)
1092 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1096 current_sa_bytes = current_sa_pkts = 0;
1098 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1099 sa0 = pool_elt_at_index (im->sad, current_sa_index);
1101 /* fetch the second cacheline ASAP */
1102 CLIB_PREFETCH (sa0->cacheline1, CLIB_CACHE_LINE_BYTES, LOAD);
1103 cpd.icv_sz = sa0->integ_icv_size;
1104 cpd.iv_sz = sa0->crypto_iv_size;
1105 cpd.flags = sa0->flags;
1106 cpd.sa_index = current_sa_index;
1108 /* submit frame when op_id is different then the old one */
1109 if (is_async && last_async_op != sa0->crypto_async_dec_op_id)
1111 if (async_frame && async_frame->n_elts)
1113 if (vnet_crypto_async_submit_open_frame (vm, async_frame))
1114 esp_async_recycle_failed_submit (async_frame, b, from,
1115 nexts, &n_async_drop,
1116 ESP_DECRYPT_NEXT_DROP,
1117 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1120 vnet_crypto_async_get_frame (vm, sa0->crypto_async_dec_op_id);
1121 last_async_op = sa0->crypto_async_dec_op_id;
1125 if (PREDICT_FALSE (~0 == sa0->decrypt_thread_index))
1127 /* this is the first packet to use this SA, claim the SA
1128 * for this thread. this could happen simultaneously on
1130 clib_atomic_cmp_and_swap (&sa0->decrypt_thread_index, ~0,
1131 ipsec_sa_assign_thread (thread_index));
1134 if (PREDICT_FALSE (thread_index != sa0->decrypt_thread_index))
1136 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1137 &n_async_drop, ESP_DECRYPT_NEXT_HANDOFF, next);
1138 next[0] = ESP_DECRYPT_NEXT_HANDOFF;
1142 /* store packet data for next round for easier prefetch */
1143 pd->sa_data = cpd.sa_data;
1144 pd->current_data = b[0]->current_data;
1145 pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
1146 payload = b[0]->data + pd->current_data;
1147 pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq);
1150 pd2->free_buffer_index = 0;
1151 pd2->icv_removed = 0;
1156 /* find last buffer in the chain */
1157 while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT)
1158 pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer);
1160 crypto_ops = &ptd->chained_crypto_ops;
1161 integ_ops = &ptd->chained_integ_ops;
1164 pd->current_length = b[0]->current_length;
1166 /* anti-reply check */
1167 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
1169 b[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
1170 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1171 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1175 if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
1177 b[0]->error = node->errors[ESP_DECRYPT_ERROR_RUNT];
1178 esp_set_next_index (is_async, from, nexts, from[b - bufs],
1179 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
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]);
1189 int ret = esp_decrypt_prepare_async_frame (vm, node, ptd,
1196 b[0], next, async_next);
1197 if (PREDICT_FALSE (ret < 0))
1199 b[0]->error = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
1200 esp_set_next_index (1, from, nexts, from[b - bufs],
1201 &n_async_drop, ESP_DECRYPT_NEXT_DROP, next);
1202 /* when next[0] is ESP_DECRYPT_NEXT_DROP we only have to drop
1203 * the current packet. Otherwise it is frame submission error
1204 * thus we have to drop the whole frame.
1206 if (next[0] != ESP_DECRYPT_NEXT_DROP && async_frame->n_elts)
1207 esp_async_recycle_failed_submit (async_frame, b, from,
1208 nexts, &n_async_drop,
1209 ESP_DECRYPT_NEXT_DROP,
1210 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1215 esp_decrypt_prepare_sync_op (vm, node, ptd, &crypto_ops, &integ_ops,
1216 op, sa0, payload, len, cpd.icv_sz,
1217 cpd.iv_sz, pd, pd2, b[0], next,
1228 if (PREDICT_TRUE (~0 != current_sa_index))
1229 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1230 current_sa_index, current_sa_pkts,
1235 if (async_frame && async_frame->n_elts)
1237 if (vnet_crypto_async_submit_open_frame (vm, async_frame) < 0)
1238 esp_async_recycle_failed_submit (async_frame, b, from, nexts,
1240 ESP_DECRYPT_NEXT_DROP,
1241 ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR);
1244 /* no post process in async */
1245 vlib_node_increment_counter (vm, node->node_index,
1246 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1248 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_async_drop);
1254 esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts,
1255 ESP_DECRYPT_ERROR_INTEG_ERROR);
1256 esp_process_chained_ops (vm, node, ptd->chained_integ_ops, bufs, nexts,
1257 ptd->chunks, ESP_DECRYPT_ERROR_INTEG_ERROR);
1259 esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts,
1260 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1261 esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, bufs, nexts,
1263 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1266 /* Post decryption ronud - adjust packet data start and length and next
1269 n_left = from_frame->n_vectors;
1279 void *data = b[1]->data + pd[1].current_data;
1281 /* buffer metadata */
1282 vlib_prefetch_buffer_header (b[1], LOAD);
1285 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
1286 CLIB_CACHE_LINE_BYTES, LOAD);
1288 /* packet headers */
1289 CLIB_PREFETCH (data - CLIB_CACHE_LINE_BYTES,
1290 CLIB_CACHE_LINE_BYTES * 2, LOAD);
1293 /* save the sa_index as GRE_teb post_crypto changes L2 opaque */
1294 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1295 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1297 if (next[0] >= ESP_DECRYPT_N_NEXT)
1298 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1302 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1304 esp_decrypt_trace_t *tr;
1305 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1306 sa0 = pool_elt_at_index (im->sad, current_sa_index);
1307 tr->crypto_alg = sa0->crypto_alg;
1308 tr->integ_alg = sa0->integ_alg;
1310 tr->sa_seq = sa0->last_seq;
1311 tr->sa_seq_hi = sa0->seq_hi;
1322 n_left = from_frame->n_vectors;
1323 vlib_node_increment_counter (vm, node->node_index,
1324 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1326 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1332 esp_decrypt_post_inline (vlib_main_t * vm,
1333 vlib_node_runtime_t * node,
1334 vlib_frame_t * from_frame, int is_ip6, int is_tun)
1336 ipsec_main_t *im = &ipsec_main;
1337 u32 *from = vlib_frame_vector_args (from_frame);
1338 u32 n_left = from_frame->n_vectors;
1339 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1340 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1341 vlib_get_buffers (vm, from, b, n_left);
1345 esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data;
1349 vlib_prefetch_buffer_header (b[2], LOAD);
1350 vlib_prefetch_buffer_header (b[1], LOAD);
1354 esp_decrypt_post_crypto (vm, node, pd, 0, b[0], next, is_ip6, is_tun,
1358 esp_decrypt_packet_data2_t *pd2 = esp_post_data2 (b[0]);
1359 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1364 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1366 ipsec_sa_t *sa0 = pool_elt_at_index (im->sad, pd->sa_index);
1367 esp_decrypt_trace_t *tr;
1368 esp_decrypt_packet_data_t *async_pd =
1369 &(esp_post_data (b[0]))->decrypt_data;
1370 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1371 sa0 = pool_elt_at_index (im->sad, async_pd->sa_index);
1373 tr->crypto_alg = sa0->crypto_alg;
1374 tr->integ_alg = sa0->integ_alg;
1376 tr->sa_seq = sa0->last_seq;
1377 tr->sa_seq_hi = sa0->seq_hi;
1385 n_left = from_frame->n_vectors;
1386 vlib_node_increment_counter (vm, node->node_index,
1387 ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left);
1389 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1394 VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm,
1395 vlib_node_runtime_t * node,
1396 vlib_frame_t * from_frame)
1398 return esp_decrypt_inline (vm, node, from_frame, 0, 0,
1399 esp_decrypt_async_next.esp4_post_next);
1402 VLIB_NODE_FN (esp4_decrypt_post_node) (vlib_main_t * vm,
1403 vlib_node_runtime_t * node,
1404 vlib_frame_t * from_frame)
1406 return esp_decrypt_post_inline (vm, node, from_frame, 0, 0);
1409 VLIB_NODE_FN (esp4_decrypt_tun_node) (vlib_main_t * vm,
1410 vlib_node_runtime_t * node,
1411 vlib_frame_t * from_frame)
1413 return esp_decrypt_inline (vm, node, from_frame, 0, 1,
1414 esp_decrypt_async_next.esp4_tun_post_next);
1417 VLIB_NODE_FN (esp4_decrypt_tun_post_node) (vlib_main_t * vm,
1418 vlib_node_runtime_t * node,
1419 vlib_frame_t * from_frame)
1421 return esp_decrypt_post_inline (vm, node, from_frame, 0, 1);
1424 VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm,
1425 vlib_node_runtime_t * node,
1426 vlib_frame_t * from_frame)
1428 return esp_decrypt_inline (vm, node, from_frame, 1, 0,
1429 esp_decrypt_async_next.esp6_post_next);
1432 VLIB_NODE_FN (esp6_decrypt_post_node) (vlib_main_t * vm,
1433 vlib_node_runtime_t * node,
1434 vlib_frame_t * from_frame)
1436 return esp_decrypt_post_inline (vm, node, from_frame, 1, 0);
1439 VLIB_NODE_FN (esp6_decrypt_tun_node) (vlib_main_t * vm,
1440 vlib_node_runtime_t * node,
1441 vlib_frame_t * from_frame)
1443 return esp_decrypt_inline (vm, node, from_frame, 1, 1,
1444 esp_decrypt_async_next.esp6_tun_post_next);
1447 VLIB_NODE_FN (esp6_decrypt_tun_post_node) (vlib_main_t * vm,
1448 vlib_node_runtime_t * node,
1449 vlib_frame_t * from_frame)
1451 return esp_decrypt_post_inline (vm, node, from_frame, 1, 1);
1455 VLIB_REGISTER_NODE (esp4_decrypt_node) = {
1456 .name = "esp4-decrypt",
1457 .vector_size = sizeof (u32),
1458 .format_trace = format_esp_decrypt_trace,
1459 .type = VLIB_NODE_TYPE_INTERNAL,
1461 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1462 .error_strings = esp_decrypt_error_strings,
1464 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1466 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1467 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1468 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1469 [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop",
1470 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1471 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff",
1475 VLIB_REGISTER_NODE (esp4_decrypt_post_node) = {
1476 .name = "esp4-decrypt-post",
1477 .vector_size = sizeof (u32),
1478 .format_trace = format_esp_decrypt_trace,
1479 .type = VLIB_NODE_TYPE_INTERNAL,
1481 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1482 .error_strings = esp_decrypt_error_strings,
1484 .sibling_of = "esp4-decrypt",
1487 VLIB_REGISTER_NODE (esp6_decrypt_node) = {
1488 .name = "esp6-decrypt",
1489 .vector_size = sizeof (u32),
1490 .format_trace = format_esp_decrypt_trace,
1491 .type = VLIB_NODE_TYPE_INTERNAL,
1493 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1494 .error_strings = esp_decrypt_error_strings,
1496 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1498 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1499 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1500 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1501 [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop",
1502 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1503 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff",
1507 VLIB_REGISTER_NODE (esp6_decrypt_post_node) = {
1508 .name = "esp6-decrypt-post",
1509 .vector_size = sizeof (u32),
1510 .format_trace = format_esp_decrypt_trace,
1511 .type = VLIB_NODE_TYPE_INTERNAL,
1513 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1514 .error_strings = esp_decrypt_error_strings,
1516 .sibling_of = "esp6-decrypt",
1519 VLIB_REGISTER_NODE (esp4_decrypt_tun_node) = {
1520 .name = "esp4-decrypt-tun",
1521 .vector_size = sizeof (u32),
1522 .format_trace = format_esp_decrypt_trace,
1523 .type = VLIB_NODE_TYPE_INTERNAL,
1524 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1525 .error_strings = esp_decrypt_error_strings,
1526 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1528 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1529 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1530 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1531 [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input",
1532 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1533 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff",
1537 VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node) = {
1538 .name = "esp4-decrypt-tun-post",
1539 .vector_size = sizeof (u32),
1540 .format_trace = format_esp_decrypt_trace,
1541 .type = VLIB_NODE_TYPE_INTERNAL,
1543 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1544 .error_strings = esp_decrypt_error_strings,
1546 .sibling_of = "esp4-decrypt-tun",
1549 VLIB_REGISTER_NODE (esp6_decrypt_tun_node) = {
1550 .name = "esp6-decrypt-tun",
1551 .vector_size = sizeof (u32),
1552 .format_trace = format_esp_decrypt_trace,
1553 .type = VLIB_NODE_TYPE_INTERNAL,
1554 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1555 .error_strings = esp_decrypt_error_strings,
1556 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1558 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1559 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1560 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
1561 [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input",
1562 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
1563 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff",
1567 VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node) = {
1568 .name = "esp6-decrypt-tun-post",
1569 .vector_size = sizeof (u32),
1570 .format_trace = format_esp_decrypt_trace,
1571 .type = VLIB_NODE_TYPE_INTERNAL,
1573 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1574 .error_strings = esp_decrypt_error_strings,
1576 .sibling_of = "esp6-decrypt-tun",
1581 * fd.io coding-style-patch-verification: ON
1584 * eval: (c-set-style "gnu")