2 * esp_encrypt.c : IPSec ESP encrypt 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>
22 #include <vnet/crypto/crypto.h>
24 #include <vnet/ipsec/ipsec.h>
25 #include <vnet/ipsec/ipsec_tun.h>
26 #include <vnet/ipsec/ipsec.api_enum.h>
27 #include <vnet/ipsec/esp.h>
28 #include <vnet/tunnel/tunnel_dp.h>
30 #define foreach_esp_encrypt_next \
31 _ (DROP4, "ip4-drop") \
32 _ (DROP6, "ip6-drop") \
33 _ (DROP_MPLS, "mpls-drop") \
34 _ (HANDOFF4, "handoff4") \
35 _ (HANDOFF6, "handoff6") \
36 _ (HANDOFF_MPLS, "handoff-mpls") \
37 _ (INTERFACE_OUTPUT, "interface-output")
39 #define _(v, s) ESP_ENCRYPT_NEXT_##v,
42 foreach_esp_encrypt_next
54 ipsec_crypto_alg_t crypto_alg;
55 ipsec_integ_alg_t integ_alg;
56 } esp_encrypt_trace_t;
61 } esp_encrypt_post_trace_t;
63 typedef vl_counter_esp_encrypt_enum_t esp_encrypt_error_t;
65 /* packet trace format function */
67 format_esp_encrypt_trace (u8 * s, va_list * args)
69 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
70 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
71 esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *);
75 "esp: sa-index %d spi %u (0x%08x) seq %u sa-seq-hi %u crypto %U integrity %U%s",
76 t->sa_index, t->spi, t->spi, t->seq, t->sa_seq_hi,
77 format_ipsec_crypto_alg,
78 t->crypto_alg, format_ipsec_integ_alg, t->integ_alg,
79 t->udp_encap ? " udp-encap-enabled" : "");
84 format_esp_post_encrypt_trace (u8 * s, va_list * args)
86 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
87 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
88 esp_encrypt_post_trace_t *t = va_arg (*args, esp_encrypt_post_trace_t *);
90 s = format (s, "esp-post: next node index %u", t->next_index);
94 /* pad packet in input buffer */
95 static_always_inline u8 *
96 esp_add_footer_and_icv (vlib_main_t *vm, vlib_buffer_t **last, u8 esp_align,
97 u8 icv_sz, vlib_node_runtime_t *node,
98 u16 buffer_data_size, uword total_len)
100 static const u8 pad_data[ESP_MAX_BLOCK_SIZE] = {
101 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
102 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00,
105 u16 min_length = total_len + sizeof (esp_footer_t);
106 u16 new_length = round_pow2 (min_length, esp_align);
107 u8 pad_bytes = new_length - min_length;
108 esp_footer_t *f = (esp_footer_t *) (vlib_buffer_get_current (last[0]) +
109 last[0]->current_length + pad_bytes);
110 u16 tail_sz = sizeof (esp_footer_t) + pad_bytes + icv_sz;
112 if (last[0]->current_data + last[0]->current_length + tail_sz >
116 if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1)
119 vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi);
120 last[0]->next_buffer = tmp_bi;
121 last[0]->flags |= VLIB_BUFFER_NEXT_PRESENT;
122 f = (esp_footer_t *) (vlib_buffer_get_current (tmp) + pad_bytes);
123 tmp->current_length += tail_sz;
127 last[0]->current_length += tail_sz;
129 f->pad_length = pad_bytes;
132 ASSERT (pad_bytes <= ESP_MAX_BLOCK_SIZE);
133 pad_bytes = clib_min (ESP_MAX_BLOCK_SIZE, pad_bytes);
134 clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, pad_bytes);
137 return &f->next_header;
140 static_always_inline void
141 esp_update_ip4_hdr (ip4_header_t * ip4, u16 len, int is_transport, int is_udp)
146 len = clib_net_to_host_u16 (len);
147 old_len = ip4->length;
151 u8 prot = is_udp ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP;
153 sum = ip_csum_update (ip4->checksum, ip4->protocol,
154 prot, ip4_header_t, protocol);
155 ip4->protocol = prot;
157 sum = ip_csum_update (sum, old_len, len, ip4_header_t, length);
160 sum = ip_csum_update (ip4->checksum, old_len, len, ip4_header_t, length);
163 ip4->checksum = ip_csum_fold (sum);
166 static_always_inline void
167 esp_fill_udp_hdr (ipsec_sa_t * sa, udp_header_t * udp, u16 len)
169 clib_memcpy_fast (udp, &sa->udp_hdr, sizeof (udp_header_t));
170 udp->length = clib_net_to_host_u16 (len);
173 static_always_inline u8
174 ext_hdr_is_pre_esp (u8 nexthdr)
176 #ifdef CLIB_HAVE_VEC128
177 static const u8x16 ext_hdr_types = {
178 IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS,
179 IP_PROTOCOL_IPV6_ROUTE,
180 IP_PROTOCOL_IPV6_FRAGMENTATION,
183 return !u8x16_is_all_zero (ext_hdr_types == u8x16_splat (nexthdr));
185 return ((nexthdr ^ IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) |
186 (nexthdr ^ IP_PROTOCOL_IPV6_ROUTE) |
187 ((nexthdr ^ IP_PROTOCOL_IPV6_FRAGMENTATION) != 0));
191 static_always_inline u8
192 esp_get_ip6_hdr_len (ip6_header_t * ip6, ip6_ext_header_t ** ext_hdr)
194 /* this code assumes that HbH, route and frag headers will be before
195 others, if that is not the case, they will end up encrypted */
196 u8 len = sizeof (ip6_header_t);
199 /* if next packet doesn't have ext header */
200 if (ext_hdr_is_pre_esp (ip6->protocol) == 0)
206 p = ip6_next_header (ip6);
207 len += ip6_ext_header_len (p);
208 while (ext_hdr_is_pre_esp (p->next_hdr))
210 len += ip6_ext_header_len (p);
211 p = ip6_ext_next_header (p);
218 static_always_inline void
219 esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
220 vnet_crypto_op_t * ops, vlib_buffer_t * b[],
221 u16 * nexts, vnet_crypto_op_chunk_t * chunks,
224 u32 n_fail, n_ops = vec_len (ops);
225 vnet_crypto_op_t *op = ops;
230 n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops);
234 ASSERT (op - ops < n_ops);
236 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
238 u32 bi = op->user_data;
239 b[bi]->error = node->errors[ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
240 nexts[bi] = drop_next;
247 static_always_inline void
248 esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
249 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts,
252 u32 n_fail, n_ops = vec_len (ops);
253 vnet_crypto_op_t *op = ops;
258 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
262 ASSERT (op - ops < n_ops);
264 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
266 u32 bi = op->user_data;
267 b[bi]->error = node->errors[ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
268 nexts[bi] = drop_next;
275 static_always_inline u32
276 esp_encrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
277 ipsec_sa_t * sa0, vlib_buffer_t * b,
278 vlib_buffer_t * lb, u8 icv_sz, u8 * start,
279 u32 start_len, u16 * n_ch)
281 vnet_crypto_op_chunk_t *ch;
282 vlib_buffer_t *cb = b;
285 vec_add2 (ptd->chunks, ch, 1);
286 total_len = ch->len = start_len;
287 ch->src = ch->dst = start;
288 cb = vlib_get_buffer (vm, cb->next_buffer);
292 vec_add2 (ptd->chunks, ch, 1);
295 total_len += ch->len = cb->current_length - icv_sz;
297 total_len += ch->len = cb->current_length;
298 ch->src = ch->dst = vlib_buffer_get_current (cb);
300 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
303 cb = vlib_get_buffer (vm, cb->next_buffer);
312 static_always_inline u32
313 esp_encrypt_chain_integ (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
314 ipsec_sa_t * sa0, vlib_buffer_t * b,
315 vlib_buffer_t * lb, u8 icv_sz, u8 * start,
316 u32 start_len, u8 * digest, u16 * n_ch)
318 vnet_crypto_op_chunk_t *ch;
319 vlib_buffer_t *cb = b;
322 vec_add2 (ptd->chunks, ch, 1);
323 total_len = ch->len = start_len;
325 cb = vlib_get_buffer (vm, cb->next_buffer);
329 vec_add2 (ptd->chunks, ch, 1);
333 total_len += ch->len = cb->current_length - icv_sz;
334 if (ipsec_sa_is_set_USE_ESN (sa0))
336 u32 seq_hi = clib_net_to_host_u32 (sa0->seq_hi);
337 clib_memcpy_fast (digest, &seq_hi, sizeof (seq_hi));
338 ch->len += sizeof (seq_hi);
339 total_len += sizeof (seq_hi);
343 total_len += ch->len = cb->current_length;
344 ch->src = vlib_buffer_get_current (cb);
346 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
349 cb = vlib_get_buffer (vm, cb->next_buffer);
359 esp_prepare_sync_op (vlib_main_t *vm, ipsec_per_thread_data_t *ptd,
360 vnet_crypto_op_t **crypto_ops,
361 vnet_crypto_op_t **integ_ops, ipsec_sa_t *sa0, u32 seq_hi,
362 u8 *payload, u16 payload_len, u8 iv_sz, u8 icv_sz, u32 bi,
363 vlib_buffer_t **b, vlib_buffer_t *lb, u32 hdr_len,
366 if (sa0->crypto_enc_op_id)
368 vnet_crypto_op_t *op;
369 vec_add2_aligned (crypto_ops[0], op, 1, CLIB_CACHE_LINE_BYTES);
370 vnet_crypto_op_init (op, sa0->crypto_enc_op_id);
372 op->src = op->dst = payload;
373 op->key_index = sa0->crypto_key_index;
374 op->len = payload_len - icv_sz;
377 if (ipsec_sa_is_set_IS_CTR (sa0))
379 ASSERT (sizeof (u64) == iv_sz);
380 /* construct nonce in a scratch space in front of the IP header */
381 esp_ctr_nonce_t *nonce =
382 (esp_ctr_nonce_t *) (payload - sizeof (u64) - hdr_len -
384 u64 *pkt_iv = (u64 *) (payload - sizeof (u64));
386 if (ipsec_sa_is_set_IS_AEAD (sa0))
388 /* constuct aad in a scratch space in front of the nonce */
389 op->aad = (u8 *) nonce - sizeof (esp_aead_t);
390 op->aad_len = esp_aad_fill (op->aad, esp, sa0, seq_hi);
391 op->tag = payload + op->len;
396 nonce->ctr = clib_host_to_net_u32 (1);
399 nonce->salt = sa0->salt;
400 nonce->iv = *pkt_iv = clib_host_to_net_u64 (sa0->ctr_iv_counter++);
401 op->iv = (u8 *) nonce;
405 op->iv = payload - iv_sz;
406 op->flags = VNET_CRYPTO_OP_FLAG_INIT_IV;
412 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
413 op->chunk_index = vec_len (ptd->chunks);
414 op->tag = vlib_buffer_get_tail (lb) - icv_sz;
415 esp_encrypt_chain_crypto (vm, ptd, sa0, b[0], lb, icv_sz, payload,
416 payload_len, &op->n_chunks);
420 if (sa0->integ_op_id)
422 vnet_crypto_op_t *op;
423 vec_add2_aligned (integ_ops[0], op, 1, CLIB_CACHE_LINE_BYTES);
424 vnet_crypto_op_init (op, sa0->integ_op_id);
425 op->src = payload - iv_sz - sizeof (esp_header_t);
426 op->digest = payload + payload_len - icv_sz;
427 op->key_index = sa0->integ_key_index;
428 op->digest_len = icv_sz;
429 op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t);
435 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
436 op->chunk_index = vec_len (ptd->chunks);
437 op->digest = vlib_buffer_get_tail (lb) - icv_sz;
439 esp_encrypt_chain_integ (vm, ptd, sa0, b[0], lb, icv_sz,
440 payload - iv_sz - sizeof (esp_header_t),
441 payload_len + iv_sz +
442 sizeof (esp_header_t), op->digest,
445 else if (ipsec_sa_is_set_USE_ESN (sa0))
447 u32 tmp = clib_net_to_host_u32 (seq_hi);
448 clib_memcpy_fast (op->digest, &tmp, sizeof (seq_hi));
449 op->len += sizeof (seq_hi);
454 static_always_inline void
455 esp_prepare_async_frame (vlib_main_t *vm, ipsec_per_thread_data_t *ptd,
456 vnet_crypto_async_frame_t *async_frame,
457 ipsec_sa_t *sa, vlib_buffer_t *b, esp_header_t *esp,
458 u8 *payload, u32 payload_len, u8 iv_sz, u8 icv_sz,
459 u32 bi, u16 next, u32 hdr_len, u16 async_next,
462 esp_post_data_t *post = esp_post_data (b);
463 u8 *tag, *iv, *aad = 0;
466 i16 crypto_start_offset, integ_start_offset = 0;
467 u16 crypto_total_len, integ_total_len;
469 post->next_index = next;
472 crypto_start_offset = payload - b->data;
473 crypto_total_len = integ_total_len = payload_len - icv_sz;
474 tag = payload + crypto_total_len;
476 key_index = sa->linked_key_index;
478 if (ipsec_sa_is_set_IS_CTR (sa))
480 ASSERT (sizeof (u64) == iv_sz);
481 /* construct nonce in a scratch space in front of the IP header */
482 esp_ctr_nonce_t *nonce = (esp_ctr_nonce_t *) (payload - sizeof (u64) -
483 hdr_len - sizeof (*nonce));
484 u64 *pkt_iv = (u64 *) (payload - sizeof (u64));
486 if (ipsec_sa_is_set_IS_AEAD (sa))
488 /* constuct aad in a scratch space in front of the nonce */
489 aad = (u8 *) nonce - sizeof (esp_aead_t);
490 esp_aad_fill (aad, esp, sa, sa->seq_hi);
491 key_index = sa->crypto_key_index;
495 nonce->ctr = clib_host_to_net_u32 (1);
498 nonce->salt = sa->salt;
499 nonce->iv = *pkt_iv = clib_host_to_net_u64 (sa->ctr_iv_counter++);
504 iv = payload - iv_sz;
505 flag |= VNET_CRYPTO_OP_FLAG_INIT_IV;
511 flag |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
512 tag = vlib_buffer_get_tail (lb) - icv_sz;
513 crypto_total_len = esp_encrypt_chain_crypto (vm, ptd, sa, b, lb, icv_sz,
514 payload, payload_len, 0);
519 integ_start_offset = crypto_start_offset - iv_sz - sizeof (esp_header_t);
520 integ_total_len += iv_sz + sizeof (esp_header_t);
524 integ_total_len = esp_encrypt_chain_integ (
525 vm, ptd, sa, b, lb, icv_sz,
526 payload - iv_sz - sizeof (esp_header_t),
527 payload_len + iv_sz + sizeof (esp_header_t), tag, 0);
529 else if (ipsec_sa_is_set_USE_ESN (sa))
531 u32 seq_hi = clib_net_to_host_u32 (sa->seq_hi);
532 clib_memcpy_fast (tag, &seq_hi, sizeof (seq_hi));
533 integ_total_len += sizeof (seq_hi);
537 /* this always succeeds because we know the frame is not full */
538 vnet_crypto_async_add_to_frame (vm, async_frame, key_index, crypto_total_len,
539 integ_total_len - crypto_total_len,
540 crypto_start_offset, integ_start_offset, bi,
541 async_next, iv, tag, aad, flag);
545 esp_encrypt_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
546 vlib_frame_t *frame, vnet_link_t lt, int is_tun,
549 ipsec_main_t *im = &ipsec_main;
550 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, vm->thread_index);
551 u32 *from = vlib_frame_vector_args (frame);
552 u32 n_left = frame->n_vectors;
553 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
554 u32 thread_index = vm->thread_index;
555 u16 buffer_data_size = vlib_buffer_get_default_data_size (vm);
556 u32 current_sa_index = ~0, current_sa_packets = 0;
557 u32 current_sa_bytes = 0, spi = 0;
558 u8 esp_align = 4, iv_sz = 0, icv_sz = 0;
561 vnet_crypto_op_t **crypto_ops = &ptd->crypto_ops;
562 vnet_crypto_op_t **integ_ops = &ptd->integ_ops;
563 vnet_crypto_async_frame_t *async_frames[VNET_CRYPTO_ASYNC_OP_N_IDS];
564 int is_async = im->async_mode;
565 vnet_crypto_async_op_id_t async_op = ~0;
567 (lt == VNET_LINK_IP6 ? ESP_ENCRYPT_NEXT_DROP6 :
568 (lt == VNET_LINK_IP4 ? ESP_ENCRYPT_NEXT_DROP4 :
569 ESP_ENCRYPT_NEXT_DROP_MPLS));
570 u16 handoff_next = (lt == VNET_LINK_IP6 ?
571 ESP_ENCRYPT_NEXT_HANDOFF6 :
572 (lt == VNET_LINK_IP4 ? ESP_ENCRYPT_NEXT_HANDOFF4 :
573 ESP_ENCRYPT_NEXT_HANDOFF_MPLS));
574 vlib_buffer_t *sync_bufs[VLIB_FRAME_SIZE];
575 u16 sync_nexts[VLIB_FRAME_SIZE], *sync_next = sync_nexts, n_sync = 0;
576 u16 async_nexts[VLIB_FRAME_SIZE], *async_next = async_nexts, n_async = 0;
577 u16 noop_nexts[VLIB_FRAME_SIZE], *noop_next = noop_nexts, n_noop = 0;
578 u32 sync_bi[VLIB_FRAME_SIZE];
579 u32 noop_bi[VLIB_FRAME_SIZE];
580 esp_encrypt_error_t err;
582 vlib_get_buffers (vm, from, b, n_left);
584 vec_reset_length (ptd->crypto_ops);
585 vec_reset_length (ptd->integ_ops);
586 vec_reset_length (ptd->chained_crypto_ops);
587 vec_reset_length (ptd->chained_integ_ops);
588 vec_reset_length (ptd->async_frames);
589 vec_reset_length (ptd->chunks);
590 clib_memset (async_frames, 0, sizeof (async_frames));
597 u8 *payload, *next_hdr_ptr;
598 u16 payload_len, payload_len_total, n_bufs;
601 err = ESP_ENCRYPT_ERROR_RX_PKTS;
606 vlib_prefetch_buffer_header (b[2], LOAD);
607 p = vlib_buffer_get_current (b[1]);
608 clib_prefetch_load (p);
609 p -= CLIB_CACHE_LINE_BYTES;
610 clib_prefetch_load (p);
611 /* speculate that the trailer goes in the first buffer */
612 CLIB_PREFETCH (vlib_buffer_get_tail (b[1]),
613 CLIB_CACHE_LINE_BYTES, LOAD);
618 /* we are on a ipsec tunnel's feature arc */
619 vnet_buffer (b[0])->ipsec.sad_index =
620 sa_index0 = ipsec_tun_protect_get_sa_out
621 (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]);
623 if (PREDICT_FALSE (INDEX_INVALID == sa_index0))
625 err = ESP_ENCRYPT_ERROR_NO_PROTECTION;
626 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
632 sa_index0 = vnet_buffer (b[0])->ipsec.sad_index;
634 if (sa_index0 != current_sa_index)
636 if (current_sa_packets)
637 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
641 current_sa_packets = current_sa_bytes = 0;
643 sa0 = ipsec_sa_get (sa_index0);
645 if (PREDICT_FALSE ((sa0->crypto_alg == IPSEC_CRYPTO_ALG_NONE &&
646 sa0->integ_alg == IPSEC_INTEG_ALG_NONE) &&
647 !ipsec_sa_is_set_NO_ALGO_NO_DROP (sa0)))
649 err = ESP_ENCRYPT_ERROR_NO_ENCRYPTION;
650 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
654 /* fetch the second cacheline ASAP */
655 clib_prefetch_load (sa0->cacheline1);
657 current_sa_index = sa_index0;
658 spi = clib_net_to_host_u32 (sa0->spi);
659 esp_align = sa0->esp_block_align;
660 icv_sz = sa0->integ_icv_size;
661 iv_sz = sa0->crypto_iv_size;
662 is_async = im->async_mode | ipsec_sa_is_set_IS_ASYNC (sa0);
665 if (PREDICT_FALSE (~0 == sa0->thread_index))
667 /* this is the first packet to use this SA, claim the SA
668 * for this thread. this could happen simultaneously on
670 clib_atomic_cmp_and_swap (&sa0->thread_index, ~0,
671 ipsec_sa_assign_thread (thread_index));
674 if (PREDICT_FALSE (thread_index != sa0->thread_index))
676 vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index;
677 err = ESP_ENCRYPT_ERROR_HANDOFF;
678 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
684 n_bufs = vlib_buffer_chain_linearize (vm, b[0]);
687 err = ESP_ENCRYPT_ERROR_NO_BUFFERS;
688 esp_set_next_index (b[0], node, err, n_noop, noop_nexts, drop_next);
694 /* find last buffer in the chain */
695 while (lb->flags & VLIB_BUFFER_NEXT_PRESENT)
696 lb = vlib_get_buffer (vm, lb->next_buffer);
699 if (PREDICT_FALSE (esp_seq_advance (sa0)))
701 err = ESP_ENCRYPT_ERROR_SEQ_CYCLED;
702 esp_set_next_index (b[0], node, err, n_noop, noop_nexts, drop_next);
709 if (ipsec_sa_is_set_IS_TUNNEL (sa0))
711 payload = vlib_buffer_get_current (b[0]);
712 next_hdr_ptr = esp_add_footer_and_icv (
713 vm, &lb, esp_align, icv_sz, node, buffer_data_size,
714 vlib_buffer_length_in_chain (vm, b[0]));
717 err = ESP_ENCRYPT_ERROR_NO_BUFFERS;
718 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
722 b[0]->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
723 payload_len = b[0]->current_length;
724 payload_len_total = vlib_buffer_length_in_chain (vm, b[0]);
727 hdr_len += sizeof (*esp);
728 esp = (esp_header_t *) (payload - hdr_len);
730 /* optional UDP header */
731 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
733 hdr_len += sizeof (udp_header_t);
734 esp_fill_udp_hdr (sa0, (udp_header_t *) (payload - hdr_len),
735 payload_len_total + hdr_len);
739 if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
742 u16 len = sizeof (ip6_header_t);
744 ip6 = (ip6_header_t *) (payload - hdr_len);
745 clib_memcpy_fast (ip6, &sa0->ip6_hdr, sizeof (ip6_header_t));
747 if (VNET_LINK_IP6 == lt)
749 *next_hdr_ptr = IP_PROTOCOL_IPV6;
750 tunnel_encap_fixup_6o6 (sa0->tunnel_flags,
751 (const ip6_header_t *) payload,
754 else if (VNET_LINK_IP4 == lt)
756 *next_hdr_ptr = IP_PROTOCOL_IP_IN_IP;
757 tunnel_encap_fixup_4o6 (sa0->tunnel_flags, b[0],
758 (const ip4_header_t *) payload, ip6);
760 else if (VNET_LINK_MPLS == lt)
762 *next_hdr_ptr = IP_PROTOCOL_MPLS_IN_IP;
763 tunnel_encap_fixup_mplso6 (
764 sa0->tunnel_flags, b[0],
765 (const mpls_unicast_header_t *) payload, ip6);
770 len = payload_len_total + hdr_len - len;
771 ip6->payload_length = clib_net_to_host_u16 (len);
772 b[0]->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
777 u16 len = sizeof (ip4_header_t);
779 ip4 = (ip4_header_t *) (payload - hdr_len);
780 clib_memcpy_fast (ip4, &sa0->ip4_hdr, sizeof (ip4_header_t));
782 if (VNET_LINK_IP6 == lt)
784 *next_hdr_ptr = IP_PROTOCOL_IPV6;
785 tunnel_encap_fixup_6o4_w_chksum (sa0->tunnel_flags,
786 (const ip6_header_t *)
789 else if (VNET_LINK_IP4 == lt)
791 *next_hdr_ptr = IP_PROTOCOL_IP_IN_IP;
792 tunnel_encap_fixup_4o4_w_chksum (sa0->tunnel_flags,
793 (const ip4_header_t *)
796 else if (VNET_LINK_MPLS == lt)
798 *next_hdr_ptr = IP_PROTOCOL_MPLS_IN_IP;
799 tunnel_encap_fixup_mplso4_w_chksum (
800 sa0->tunnel_flags, (const mpls_unicast_header_t *) payload,
806 len = payload_len_total + hdr_len;
807 esp_update_ip4_hdr (ip4, len, /* is_transport */ 0, 0);
813 sync_next[0] = dpo->dpoi_next_node;
814 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo->dpoi_index;
817 sync_next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
818 b[0]->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
820 else /* transport mode */
822 u8 *l2_hdr, l2_len, *ip_hdr;
824 ip6_ext_header_t *ext_hdr;
825 udp_header_t *udp = 0;
827 u8 *old_ip_hdr = vlib_buffer_get_current (b[0]);
830 * Get extension header chain length. It might be longer than the
831 * buffer's pre_data area.
834 (VNET_LINK_IP6 == lt ?
835 esp_get_ip6_hdr_len ((ip6_header_t *) old_ip_hdr, &ext_hdr) :
836 ip4_header_bytes ((ip4_header_t *) old_ip_hdr));
837 if ((old_ip_hdr - ip_len) < &b[0]->pre_data[0])
839 err = ESP_ENCRYPT_ERROR_NO_BUFFERS;
840 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
845 vlib_buffer_advance (b[0], ip_len);
846 payload = vlib_buffer_get_current (b[0]);
847 next_hdr_ptr = esp_add_footer_and_icv (
848 vm, &lb, esp_align, icv_sz, node, buffer_data_size,
849 vlib_buffer_length_in_chain (vm, b[0]));
852 err = ESP_ENCRYPT_ERROR_NO_BUFFERS;
853 esp_set_next_index (b[0], node, err, n_noop, noop_nexts,
858 b[0]->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
859 payload_len = b[0]->current_length;
860 payload_len_total = vlib_buffer_length_in_chain (vm, b[0]);
863 hdr_len += sizeof (*esp);
864 esp = (esp_header_t *) (payload - hdr_len);
866 /* optional UDP header */
867 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
869 hdr_len += sizeof (udp_header_t);
870 udp = (udp_header_t *) (payload - hdr_len);
875 ip_hdr = payload - hdr_len;
880 l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
882 l2_hdr = payload - hdr_len;
884 /* copy l2 and ip header */
885 clib_memcpy_le32 (l2_hdr, old_ip_hdr - l2_len, l2_len);
891 len = payload_len_total + hdr_len - l2_len;
893 if (VNET_LINK_IP6 == lt)
895 ip6_header_t *ip6 = (ip6_header_t *) (old_ip_hdr);
896 if (PREDICT_TRUE (NULL == ext_hdr))
898 *next_hdr_ptr = ip6->protocol;
900 (udp) ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP;
904 *next_hdr_ptr = ext_hdr->next_hdr;
906 (udp) ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP;
908 ip6->payload_length =
909 clib_host_to_net_u16 (len - sizeof (ip6_header_t));
911 else if (VNET_LINK_IP4 == lt)
913 ip4_header_t *ip4 = (ip4_header_t *) (old_ip_hdr);
914 *next_hdr_ptr = ip4->protocol;
915 esp_update_ip4_hdr (ip4, len, /* is_transport */ 1,
919 clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len);
923 udp_len = len - ip_len;
924 esp_fill_udp_hdr (sa0, udp, udp_len);
927 sync_next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
932 crypto_ops = &ptd->chained_crypto_ops;
933 integ_ops = &ptd->chained_integ_ops;
937 crypto_ops = &ptd->crypto_ops;
938 integ_ops = &ptd->integ_ops;
942 esp->seq = clib_net_to_host_u32 (sa0->seq);
946 async_op = sa0->crypto_async_enc_op_id;
948 /* get a frame for this op if we don't yet have one or it's full
950 if (NULL == async_frames[async_op] ||
951 vnet_crypto_async_frame_is_full (async_frames[async_op]))
953 async_frames[async_op] =
954 vnet_crypto_async_get_frame (vm, async_op);
955 /* Save the frame to the list we'll submit at the end */
956 vec_add1 (ptd->async_frames, async_frames[async_op]);
959 esp_prepare_async_frame (vm, ptd, async_frames[async_op], sa0, b[0],
960 esp, payload, payload_len, iv_sz, icv_sz,
961 from[b - bufs], sync_next[0], hdr_len,
962 async_next_node, lb);
965 esp_prepare_sync_op (vm, ptd, crypto_ops, integ_ops, sa0, sa0->seq_hi,
966 payload, payload_len, iv_sz, icv_sz, n_sync, b,
969 vlib_buffer_advance (b[0], 0LL - hdr_len);
971 current_sa_packets += 1;
972 current_sa_bytes += payload_len_total;
975 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
977 esp_encrypt_trace_t *tr = vlib_add_trace (vm, node, b[0],
979 if (INDEX_INVALID == sa_index0)
980 clib_memset_u8 (tr, 0xff, sizeof (*tr));
983 tr->sa_index = sa_index0;
986 tr->sa_seq_hi = sa0->seq_hi;
987 tr->udp_encap = ipsec_sa_is_set_UDP_ENCAP (sa0);
988 tr->crypto_alg = sa0->crypto_alg;
989 tr->integ_alg = sa0->integ_alg;
994 if (ESP_ENCRYPT_ERROR_RX_PKTS != err)
996 noop_bi[n_noop] = from[b - bufs];
1002 sync_bi[n_sync] = from[b - bufs];
1003 sync_bufs[n_sync] = b[0];
1016 if (INDEX_INVALID != current_sa_index)
1017 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1018 current_sa_index, current_sa_packets,
1022 esp_process_ops (vm, node, ptd->crypto_ops, sync_bufs, sync_nexts,
1024 esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, sync_bufs,
1025 sync_nexts, ptd->chunks, drop_next);
1027 esp_process_ops (vm, node, ptd->integ_ops, sync_bufs, sync_nexts,
1029 esp_process_chained_ops (vm, node, ptd->chained_integ_ops, sync_bufs,
1030 sync_nexts, ptd->chunks, drop_next);
1032 vlib_buffer_enqueue_to_next (vm, node, sync_bi, sync_nexts, n_sync);
1036 /* submit all of the open frames */
1037 vnet_crypto_async_frame_t **async_frame;
1039 vec_foreach (async_frame, ptd->async_frames)
1041 if (vnet_crypto_async_submit_open_frame (vm, *async_frame) < 0)
1043 n_noop += esp_async_recycle_failed_submit (
1044 vm, *async_frame, node, ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR,
1045 n_noop, noop_bi, noop_nexts, drop_next);
1046 vnet_crypto_async_reset_frame (*async_frame);
1047 vnet_crypto_async_free_frame (vm, *async_frame);
1052 vlib_buffer_enqueue_to_next (vm, node, noop_bi, noop_nexts, n_noop);
1054 vlib_node_increment_counter (vm, node->node_index, ESP_ENCRYPT_ERROR_RX_PKTS,
1057 return frame->n_vectors;
1061 esp_encrypt_post_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
1062 vlib_frame_t * frame)
1064 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1065 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1066 u32 *from = vlib_frame_vector_args (frame);
1067 u32 n_left = frame->n_vectors;
1069 vlib_get_buffers (vm, from, b, n_left);
1073 vlib_prefetch_buffer_header (b[0], LOAD);
1074 vlib_prefetch_buffer_header (b[1], LOAD);
1075 vlib_prefetch_buffer_header (b[2], LOAD);
1076 vlib_prefetch_buffer_header (b[3], LOAD);
1081 vlib_prefetch_buffer_header (b[4], LOAD);
1082 vlib_prefetch_buffer_header (b[5], LOAD);
1083 vlib_prefetch_buffer_header (b[6], LOAD);
1084 vlib_prefetch_buffer_header (b[7], LOAD);
1086 next[0] = (esp_post_data (b[0]))->next_index;
1087 next[1] = (esp_post_data (b[1]))->next_index;
1088 next[2] = (esp_post_data (b[2]))->next_index;
1089 next[3] = (esp_post_data (b[3]))->next_index;
1091 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
1093 if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
1095 esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[0],
1097 tr->next_index = next[0];
1099 if (b[1]->flags & VLIB_BUFFER_IS_TRACED)
1101 esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[1],
1103 tr->next_index = next[1];
1105 if (b[2]->flags & VLIB_BUFFER_IS_TRACED)
1107 esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[2],
1109 tr->next_index = next[2];
1111 if (b[3]->flags & VLIB_BUFFER_IS_TRACED)
1113 esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[3],
1115 tr->next_index = next[3];
1126 next[0] = (esp_post_data (b[0]))->next_index;
1127 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1129 esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[0],
1131 tr->next_index = next[0];
1139 vlib_node_increment_counter (vm, node->node_index,
1140 ESP_ENCRYPT_ERROR_POST_RX_PKTS,
1142 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
1143 return frame->n_vectors;
1146 VLIB_NODE_FN (esp4_encrypt_node) (vlib_main_t * vm,
1147 vlib_node_runtime_t * node,
1148 vlib_frame_t * from_frame)
1150 return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP4, 0,
1151 esp_encrypt_async_next.esp4_post_next);
1155 VLIB_REGISTER_NODE (esp4_encrypt_node) = {
1156 .name = "esp4-encrypt",
1157 .vector_size = sizeof (u32),
1158 .format_trace = format_esp_encrypt_trace,
1159 .type = VLIB_NODE_TYPE_INTERNAL,
1161 .n_errors = ESP_ENCRYPT_N_ERROR,
1162 .error_counters = esp_encrypt_error_counters,
1164 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
1165 .next_nodes = { [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop",
1166 [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop",
1167 [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop",
1168 [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-handoff",
1169 [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-handoff",
1170 [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "error-drop",
1171 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output" },
1175 VLIB_NODE_FN (esp4_encrypt_post_node) (vlib_main_t * vm,
1176 vlib_node_runtime_t * node,
1177 vlib_frame_t * from_frame)
1179 return esp_encrypt_post_inline (vm, node, from_frame);
1183 VLIB_REGISTER_NODE (esp4_encrypt_post_node) = {
1184 .name = "esp4-encrypt-post",
1185 .vector_size = sizeof (u32),
1186 .format_trace = format_esp_post_encrypt_trace,
1187 .type = VLIB_NODE_TYPE_INTERNAL,
1188 .sibling_of = "esp4-encrypt",
1190 .n_errors = ESP_ENCRYPT_N_ERROR,
1191 .error_counters = esp_encrypt_error_counters,
1195 VLIB_NODE_FN (esp6_encrypt_node) (vlib_main_t * vm,
1196 vlib_node_runtime_t * node,
1197 vlib_frame_t * from_frame)
1199 return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP6, 0,
1200 esp_encrypt_async_next.esp6_post_next);
1204 VLIB_REGISTER_NODE (esp6_encrypt_node) = {
1205 .name = "esp6-encrypt",
1206 .vector_size = sizeof (u32),
1207 .format_trace = format_esp_encrypt_trace,
1208 .type = VLIB_NODE_TYPE_INTERNAL,
1209 .sibling_of = "esp4-encrypt",
1211 .n_errors = ESP_ENCRYPT_N_ERROR,
1212 .error_counters = esp_encrypt_error_counters,
1216 VLIB_NODE_FN (esp6_encrypt_post_node) (vlib_main_t * vm,
1217 vlib_node_runtime_t * node,
1218 vlib_frame_t * from_frame)
1220 return esp_encrypt_post_inline (vm, node, from_frame);
1224 VLIB_REGISTER_NODE (esp6_encrypt_post_node) = {
1225 .name = "esp6-encrypt-post",
1226 .vector_size = sizeof (u32),
1227 .format_trace = format_esp_post_encrypt_trace,
1228 .type = VLIB_NODE_TYPE_INTERNAL,
1229 .sibling_of = "esp4-encrypt",
1231 .n_errors = ESP_ENCRYPT_N_ERROR,
1232 .error_counters = esp_encrypt_error_counters,
1236 VLIB_NODE_FN (esp4_encrypt_tun_node) (vlib_main_t * vm,
1237 vlib_node_runtime_t * node,
1238 vlib_frame_t * from_frame)
1240 return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP4, 1,
1241 esp_encrypt_async_next.esp4_tun_post_next);
1245 VLIB_REGISTER_NODE (esp4_encrypt_tun_node) = {
1246 .name = "esp4-encrypt-tun",
1247 .vector_size = sizeof (u32),
1248 .format_trace = format_esp_encrypt_trace,
1249 .type = VLIB_NODE_TYPE_INTERNAL,
1251 .n_errors = ESP_ENCRYPT_N_ERROR,
1252 .error_counters = esp_encrypt_error_counters,
1254 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
1256 [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop",
1257 [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop",
1258 [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop",
1259 [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff",
1260 [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff",
1261 [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff",
1262 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx",
1266 VLIB_NODE_FN (esp4_encrypt_tun_post_node) (vlib_main_t * vm,
1267 vlib_node_runtime_t * node,
1268 vlib_frame_t * from_frame)
1270 return esp_encrypt_post_inline (vm, node, from_frame);
1274 VLIB_REGISTER_NODE (esp4_encrypt_tun_post_node) = {
1275 .name = "esp4-encrypt-tun-post",
1276 .vector_size = sizeof (u32),
1277 .format_trace = format_esp_post_encrypt_trace,
1278 .type = VLIB_NODE_TYPE_INTERNAL,
1279 .sibling_of = "esp4-encrypt-tun",
1281 .n_errors = ESP_ENCRYPT_N_ERROR,
1282 .error_counters = esp_encrypt_error_counters,
1286 VLIB_NODE_FN (esp6_encrypt_tun_node) (vlib_main_t * vm,
1287 vlib_node_runtime_t * node,
1288 vlib_frame_t * from_frame)
1290 return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP6, 1,
1291 esp_encrypt_async_next.esp6_tun_post_next);
1295 VLIB_REGISTER_NODE (esp6_encrypt_tun_node) = {
1296 .name = "esp6-encrypt-tun",
1297 .vector_size = sizeof (u32),
1298 .format_trace = format_esp_encrypt_trace,
1299 .type = VLIB_NODE_TYPE_INTERNAL,
1301 .n_errors = ESP_ENCRYPT_N_ERROR,
1302 .error_counters = esp_encrypt_error_counters,
1304 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
1306 [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop",
1307 [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop",
1308 [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop",
1309 [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff",
1310 [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff",
1311 [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff",
1312 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx",
1318 VLIB_NODE_FN (esp6_encrypt_tun_post_node) (vlib_main_t * vm,
1319 vlib_node_runtime_t * node,
1320 vlib_frame_t * from_frame)
1322 return esp_encrypt_post_inline (vm, node, from_frame);
1326 VLIB_REGISTER_NODE (esp6_encrypt_tun_post_node) = {
1327 .name = "esp6-encrypt-tun-post",
1328 .vector_size = sizeof (u32),
1329 .format_trace = format_esp_post_encrypt_trace,
1330 .type = VLIB_NODE_TYPE_INTERNAL,
1331 .sibling_of = "esp-mpls-encrypt-tun",
1333 .n_errors = ESP_ENCRYPT_N_ERROR,
1334 .error_counters = esp_encrypt_error_counters,
1338 VLIB_NODE_FN (esp_mpls_encrypt_tun_node)
1339 (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
1341 return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_MPLS, 1,
1342 esp_encrypt_async_next.esp_mpls_tun_post_next);
1345 VLIB_REGISTER_NODE (esp_mpls_encrypt_tun_node) = {
1346 .name = "esp-mpls-encrypt-tun",
1347 .vector_size = sizeof (u32),
1348 .format_trace = format_esp_encrypt_trace,
1349 .type = VLIB_NODE_TYPE_INTERNAL,
1351 .n_errors = ESP_ENCRYPT_N_ERROR,
1352 .error_counters = esp_encrypt_error_counters,
1354 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
1356 [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop",
1357 [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop",
1358 [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop",
1359 [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff",
1360 [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff",
1361 [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff",
1362 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx",
1366 VLIB_NODE_FN (esp_mpls_encrypt_tun_post_node)
1367 (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
1369 return esp_encrypt_post_inline (vm, node, from_frame);
1372 VLIB_REGISTER_NODE (esp_mpls_encrypt_tun_post_node) = {
1373 .name = "esp-mpls-encrypt-tun-post",
1374 .vector_size = sizeof (u32),
1375 .format_trace = format_esp_post_encrypt_trace,
1376 .type = VLIB_NODE_TYPE_INTERNAL,
1377 .sibling_of = "esp-mpls-encrypt-tun",
1379 .n_errors = ESP_ENCRYPT_N_ERROR,
1380 .error_counters = esp_encrypt_error_counters,
1383 #ifndef CLIB_MARCH_VARIANT
1385 static clib_error_t *
1386 esp_encrypt_init (vlib_main_t *vm)
1388 ipsec_main_t *im = &ipsec_main;
1390 im->esp4_enc_fq_index =
1391 vlib_frame_queue_main_init (esp4_encrypt_node.index, 0);
1392 im->esp6_enc_fq_index =
1393 vlib_frame_queue_main_init (esp6_encrypt_node.index, 0);
1394 im->esp4_enc_tun_fq_index =
1395 vlib_frame_queue_main_init (esp4_encrypt_tun_node.index, 0);
1396 im->esp6_enc_tun_fq_index =
1397 vlib_frame_queue_main_init (esp6_encrypt_tun_node.index, 0);
1398 im->esp_mpls_enc_tun_fq_index =
1399 vlib_frame_queue_main_init (esp_mpls_encrypt_tun_node.index, 0);
1404 VLIB_INIT_FUNCTION (esp_encrypt_init);
1409 * fd.io coding-style-patch-verification: ON
1412 * eval: (c-set-style "gnu")