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>
21 #include <vnet/udp/udp.h>
23 #include <vnet/crypto/crypto.h>
25 #include <vnet/ipsec/ipsec.h>
26 #include <vnet/ipsec/esp.h>
28 #define foreach_esp_encrypt_next \
29 _(DROP, "error-drop") \
30 _(HANDOFF, "handoff") \
31 _(INTERFACE_OUTPUT, "interface-output")
33 #define _(v, s) ESP_ENCRYPT_NEXT_##v,
36 foreach_esp_encrypt_next
41 #define foreach_esp_encrypt_error \
42 _(RX_PKTS, "ESP pkts received") \
43 _(SEQ_CYCLED, "sequence number cycled (packet dropped)") \
44 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
45 _(CHAINED_BUFFER, "chained buffers (packet dropped)") \
46 _(NO_TRAILER_SPACE, "no trailer space (packet dropped)")
50 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym,
51 foreach_esp_encrypt_error
54 } esp_encrypt_error_t;
56 static char *esp_encrypt_error_strings[] = {
57 #define _(sym,string) string,
58 foreach_esp_encrypt_error
69 ipsec_crypto_alg_t crypto_alg;
70 ipsec_integ_alg_t integ_alg;
71 } esp_encrypt_trace_t;
73 /* packet trace format function */
75 format_esp_encrypt_trace (u8 * s, va_list * args)
77 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
78 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
79 esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *);
83 "esp: sa-index %d spi %u (0x%08x) seq %u sa-seq-hi %u crypto %U integrity %U%s",
84 t->sa_index, t->spi, t->spi, t->seq, t->sa_seq_hi,
85 format_ipsec_crypto_alg,
86 t->crypto_alg, format_ipsec_integ_alg, t->integ_alg,
87 t->udp_encap ? " udp-encap-enabled" : "");
91 /* pad packet in input buffer */
92 static_always_inline u8 *
93 esp_add_footer_and_icv (vlib_buffer_t * b, u8 block_size, u8 icv_sz,
94 u16 * next, vlib_node_runtime_t * node,
97 static const u8 pad_data[ESP_MAX_BLOCK_SIZE] = {
98 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
99 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x00, 0x00,
102 u16 min_length = b->current_length + sizeof (esp_footer_t);
103 u16 new_length = round_pow2 (min_length, block_size);
104 u8 pad_bytes = new_length - min_length;
105 esp_footer_t *f = (esp_footer_t *) (vlib_buffer_get_current (b) +
106 new_length - sizeof (esp_footer_t));
108 if (b->current_data + new_length + icv_sz > buffer_data_size)
110 b->error = node->errors[ESP_ENCRYPT_ERROR_NO_TRAILER_SPACE];
111 next[0] = ESP_ENCRYPT_NEXT_DROP;
117 ASSERT (pad_bytes <= ESP_MAX_BLOCK_SIZE);
118 pad_bytes = clib_min (ESP_MAX_BLOCK_SIZE, pad_bytes);
119 clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, pad_bytes);
122 f->pad_length = pad_bytes;
123 b->current_length = new_length + icv_sz;
124 return &f->next_header;
127 static_always_inline void
128 esp_update_ip4_hdr (ip4_header_t * ip4, u16 len, int is_transport, int is_udp)
133 len = clib_net_to_host_u16 (len);
134 old_len = ip4->length;
138 u8 prot = is_udp ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP;
140 sum = ip_csum_update (ip4->checksum, ip4->protocol,
141 prot, ip4_header_t, protocol);
142 ip4->protocol = prot;
144 sum = ip_csum_update (sum, old_len, len, ip4_header_t, length);
147 sum = ip_csum_update (ip4->checksum, old_len, len, ip4_header_t, length);
150 ip4->checksum = ip_csum_fold (sum);
153 static_always_inline void
154 esp_fill_udp_hdr (ipsec_sa_t * sa, udp_header_t * udp, u16 len)
156 clib_memcpy_fast (udp, &sa->udp_hdr, sizeof (udp_header_t));
157 udp->length = clib_net_to_host_u16 (len);
160 static_always_inline u8
161 ext_hdr_is_pre_esp (u8 nexthdr)
163 #ifdef CLIB_HAVE_VEC128
164 static const u8x16 ext_hdr_types = {
165 IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS,
166 IP_PROTOCOL_IPV6_ROUTE,
167 IP_PROTOCOL_IPV6_FRAGMENTATION,
170 return !u8x16_is_all_zero (ext_hdr_types == u8x16_splat (nexthdr));
172 return ((nexthdr ^ IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) |
173 (nexthdr ^ IP_PROTOCOL_IPV6_ROUTE) |
174 (nexthdr ^ IP_PROTOCOL_IPV6_FRAGMENTATION) != 0);
178 static_always_inline u8
179 esp_get_ip6_hdr_len (ip6_header_t * ip6, ip6_ext_header_t ** ext_hdr)
181 /* this code assumes that HbH, route and frag headers will be before
182 others, if that is not the case, they will end up encrypted */
183 u8 len = sizeof (ip6_header_t);
186 /* if next packet doesn't have ext header */
187 if (ext_hdr_is_pre_esp (ip6->protocol) == 0)
193 p = (void *) (ip6 + 1);
194 len += ip6_ext_header_len (p);
196 while (ext_hdr_is_pre_esp (p->next_hdr))
198 len += ip6_ext_header_len (p);
199 p = ip6_ext_next_header (p);
206 static_always_inline void
207 esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
208 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts)
210 u32 n_fail, n_ops = vec_len (ops);
211 vnet_crypto_op_t *op = ops;
216 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
220 ASSERT (op - ops < n_ops);
222 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
224 u32 bi = op->user_data;
225 b[bi]->error = node->errors[ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
226 nexts[bi] = ESP_ENCRYPT_NEXT_DROP;
237 } __clib_packed esp_gcm_nonce_t;
239 STATIC_ASSERT_SIZEOF (esp_gcm_nonce_t, 12);
242 esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
243 vlib_frame_t * frame, int is_ip6, int is_tun)
245 ipsec_main_t *im = &ipsec_main;
246 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, vm->thread_index);
247 u32 *from = vlib_frame_vector_args (frame);
248 u32 n_left = frame->n_vectors;
249 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
250 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
251 esp_gcm_nonce_t nonces[VLIB_FRAME_SIZE], *nonce = nonces;
252 u32 thread_index = vm->thread_index;
253 u16 buffer_data_size = vlib_buffer_get_default_data_size (vm);
254 u32 current_sa_index = ~0, current_sa_packets = 0;
255 u32 current_sa_bytes = 0, spi = 0;
256 u8 block_sz = 0, iv_sz = 0, icv_sz = 0;
259 vlib_get_buffers (vm, from, b, n_left);
260 vec_reset_length (ptd->crypto_ops);
261 vec_reset_length (ptd->integ_ops);
268 u8 *payload, *next_hdr_ptr;
270 u32 hdr_len, config_index;
275 vlib_prefetch_buffer_header (b[2], LOAD);
276 p = vlib_buffer_get_current (b[1]);
277 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
278 p -= CLIB_CACHE_LINE_BYTES;
279 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
284 /* we are on a ipsec tunnel's feature arc */
286 config_index = b[0]->current_config_index;
287 sa_index0 = *(u32 *) vnet_feature_next_with_data (&next0, b[0],
290 vnet_buffer (b[0])->ipsec.sad_index = sa_index0;
294 sa_index0 = vnet_buffer (b[0])->ipsec.sad_index;
296 if (sa_index0 != current_sa_index)
298 if (current_sa_packets)
299 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
303 current_sa_packets = current_sa_bytes = 0;
305 sa0 = pool_elt_at_index (im->sad, sa_index0);
306 current_sa_index = sa_index0;
307 spi = clib_net_to_host_u32 (sa0->spi);
308 block_sz = sa0->crypto_block_size;
309 icv_sz = sa0->integ_icv_size;
310 iv_sz = sa0->crypto_iv_size;
313 if (PREDICT_FALSE (~0 == sa0->encrypt_thread_index))
315 /* this is the first packet to use this SA, claim the SA
316 * for this thread. this could happen simultaneously on
318 clib_atomic_cmp_and_swap (&sa0->encrypt_thread_index, ~0,
319 ipsec_sa_assign_thread (thread_index));
322 if (PREDICT_TRUE (thread_index != sa0->encrypt_thread_index))
324 next[0] = ESP_ENCRYPT_NEXT_HANDOFF;
327 b[0]->current_config_index = config_index;
332 if (vlib_buffer_chain_linearize (vm, b[0]) != 1)
334 b[0]->error = node->errors[ESP_ENCRYPT_ERROR_CHAINED_BUFFER];
335 next[0] = ESP_ENCRYPT_NEXT_DROP;
339 if (PREDICT_FALSE (esp_seq_advance (sa0)))
341 b[0]->error = node->errors[ESP_ENCRYPT_ERROR_SEQ_CYCLED];
342 next[0] = ESP_ENCRYPT_NEXT_DROP;
349 if (ipsec_sa_is_set_IS_TUNNEL (sa0))
351 payload = vlib_buffer_get_current (b[0]);
352 next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz,
357 payload_len = b[0]->current_length;
360 hdr_len += sizeof (*esp);
361 esp = (esp_header_t *) (payload - hdr_len);
363 /* optional UDP header */
364 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
366 hdr_len += sizeof (udp_header_t);
367 esp_fill_udp_hdr (sa0, (udp_header_t *) (payload - hdr_len),
368 payload_len + hdr_len);
372 if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
375 u16 len = sizeof (ip6_header_t);
377 ip6 = (ip6_header_t *) (payload - hdr_len);
378 clib_memcpy_fast (ip6, &sa0->ip6_hdr, len);
379 *next_hdr_ptr = (is_ip6 ?
380 IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
381 len = payload_len + hdr_len - len;
382 ip6->payload_length = clib_net_to_host_u16 (len);
387 u16 len = sizeof (ip4_header_t);
389 ip4 = (ip4_header_t *) (payload - hdr_len);
390 clib_memcpy_fast (ip4, &sa0->ip4_hdr, len);
391 *next_hdr_ptr = (is_ip6 ?
392 IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
393 len = payload_len + hdr_len;
394 esp_update_ip4_hdr (ip4, len, /* is_transport */ 0, 0);
400 next[0] = dpo->dpoi_next_node;
401 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo->dpoi_index;
404 else /* transport mode */
406 u8 *l2_hdr, l2_len, *ip_hdr, ip_len;
407 ip6_ext_header_t *ext_hdr;
408 udp_header_t *udp = 0;
409 u8 *old_ip_hdr = vlib_buffer_get_current (b[0]);
412 esp_get_ip6_hdr_len ((ip6_header_t *) old_ip_hdr, &ext_hdr) :
413 ip4_header_bytes ((ip4_header_t *) old_ip_hdr);
415 vlib_buffer_advance (b[0], ip_len);
416 payload = vlib_buffer_get_current (b[0]);
417 next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz,
422 payload_len = b[0]->current_length;
425 hdr_len += sizeof (*esp);
426 esp = (esp_header_t *) (payload - hdr_len);
428 /* optional UDP header */
429 if (ipsec_sa_is_set_UDP_ENCAP (sa0))
431 hdr_len += sizeof (udp_header_t);
432 udp = (udp_header_t *) (payload - hdr_len);
437 ip_hdr = payload - hdr_len;
442 l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
444 l2_hdr = payload - hdr_len;
446 /* copy l2 and ip header */
447 clib_memcpy_le32 (l2_hdr, old_ip_hdr - l2_len, l2_len);
454 ip6_header_t *ip6 = (ip6_header_t *) (old_ip_hdr);
455 if (PREDICT_TRUE (NULL == ext_hdr))
457 *next_hdr_ptr = ip6->protocol;
458 ip6->protocol = IP_PROTOCOL_IPSEC_ESP;
462 *next_hdr_ptr = ext_hdr->next_hdr;
463 ext_hdr->next_hdr = IP_PROTOCOL_IPSEC_ESP;
465 ip6->payload_length =
466 clib_host_to_net_u16 (payload_len + hdr_len - l2_len -
467 sizeof (ip6_header_t));
472 ip4_header_t *ip4 = (ip4_header_t *) (old_ip_hdr);
473 *next_hdr_ptr = ip4->protocol;
474 len = payload_len + hdr_len - l2_len;
477 esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 1);
478 esp_fill_udp_hdr (sa0, udp, len - ip_len);
481 esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 0);
484 clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len);
487 next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
491 esp->seq = clib_net_to_host_u32 (sa0->seq);
493 if (sa0->crypto_enc_op_id)
495 vnet_crypto_op_t *op;
496 vec_add2_aligned (ptd->crypto_ops, op, 1, CLIB_CACHE_LINE_BYTES);
497 vnet_crypto_op_init (op, sa0->crypto_enc_op_id);
498 op->src = op->dst = payload;
499 op->key_index = sa0->crypto_key_index;
500 op->len = payload_len - icv_sz;
501 op->user_data = b - bufs;
503 if (ipsec_sa_is_set_IS_AEAD (sa0))
506 * construct the AAD in a scratch space in front
509 op->aad = payload - hdr_len - sizeof (esp_aead_t);
511 esp_aad_fill (op, esp, sa0);
513 op->tag = payload + op->len;
516 u64 *iv = (u64 *) (payload - iv_sz);
517 nonce->salt = sa0->salt;
518 nonce->iv = *iv = clib_host_to_net_u64 (sa0->gcm_iv_counter++);
519 op->iv = (u8 *) nonce;
524 op->iv = payload - iv_sz;
525 op->flags = VNET_CRYPTO_OP_FLAG_INIT_IV;
529 if (sa0->integ_op_id)
531 vnet_crypto_op_t *op;
532 vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
533 vnet_crypto_op_init (op, sa0->integ_op_id);
534 op->src = payload - iv_sz - sizeof (esp_header_t);
535 op->digest = payload + payload_len - icv_sz;
536 op->key_index = sa0->integ_key_index;
537 op->digest_len = icv_sz;
538 op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t);
539 op->user_data = b - bufs;
540 if (ipsec_sa_is_set_USE_ESN (sa0))
542 u32 seq_hi = clib_net_to_host_u32 (sa0->seq_hi);
543 clib_memcpy_fast (op->digest, &seq_hi, sizeof (seq_hi));
544 op->len += sizeof (seq_hi);
548 vlib_buffer_advance (b[0], 0LL - hdr_len);
550 current_sa_packets += 1;
551 current_sa_bytes += payload_len;
554 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
556 esp_encrypt_trace_t *tr = vlib_add_trace (vm, node, b[0],
558 tr->sa_index = sa_index0;
561 tr->sa_seq_hi = sa0->seq_hi;
562 tr->udp_encap = ipsec_sa_is_set_UDP_ENCAP (sa0);
563 tr->crypto_alg = sa0->crypto_alg;
564 tr->integ_alg = sa0->integ_alg;
572 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
573 current_sa_index, current_sa_packets,
575 esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts);
576 esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
578 vlib_node_increment_counter (vm, node->node_index,
579 ESP_ENCRYPT_ERROR_RX_PKTS, frame->n_vectors);
581 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
582 return frame->n_vectors;
585 VLIB_NODE_FN (esp4_encrypt_node) (vlib_main_t * vm,
586 vlib_node_runtime_t * node,
587 vlib_frame_t * from_frame)
589 return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 0);
593 VLIB_REGISTER_NODE (esp4_encrypt_node) = {
594 .name = "esp4-encrypt",
595 .vector_size = sizeof (u32),
596 .format_trace = format_esp_encrypt_trace,
597 .type = VLIB_NODE_TYPE_INTERNAL,
599 .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
600 .error_strings = esp_encrypt_error_strings,
602 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
604 [ESP_ENCRYPT_NEXT_DROP] = "ip4-drop",
605 [ESP_ENCRYPT_NEXT_HANDOFF] = "esp4-encrypt-handoff",
606 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
611 VLIB_NODE_FN (esp6_encrypt_node) (vlib_main_t * vm,
612 vlib_node_runtime_t * node,
613 vlib_frame_t * from_frame)
615 return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 0);
619 VLIB_REGISTER_NODE (esp6_encrypt_node) = {
620 .name = "esp6-encrypt",
621 .vector_size = sizeof (u32),
622 .format_trace = format_esp_encrypt_trace,
623 .type = VLIB_NODE_TYPE_INTERNAL,
625 .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
626 .error_strings = esp_encrypt_error_strings,
628 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
630 [ESP_ENCRYPT_NEXT_DROP] = "ip6-drop",
631 [ESP_ENCRYPT_NEXT_HANDOFF] = "esp6-encrypt-handoff",
632 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
637 VLIB_NODE_FN (esp4_encrypt_tun_node) (vlib_main_t * vm,
638 vlib_node_runtime_t * node,
639 vlib_frame_t * from_frame)
641 return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 1);
645 VLIB_REGISTER_NODE (esp4_encrypt_tun_node) = {
646 .name = "esp4-encrypt-tun",
647 .vector_size = sizeof (u32),
648 .format_trace = format_esp_encrypt_trace,
649 .type = VLIB_NODE_TYPE_INTERNAL,
651 .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
652 .error_strings = esp_encrypt_error_strings,
654 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
656 [ESP_ENCRYPT_NEXT_DROP] = "ip4-drop",
657 [ESP_ENCRYPT_NEXT_HANDOFF] = "esp4-encrypt-tun-handoff",
658 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "error-drop",
662 VNET_FEATURE_INIT (esp4_encrypt_tun_feat_node, static) =
664 .arc_name = "ip4-output",
665 .node_name = "esp4-encrypt-tun",
666 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
669 VNET_FEATURE_INIT (esp6o4_encrypt_tun_feat_node, static) =
671 .arc_name = "ip6-output",
672 .node_name = "esp4-encrypt-tun",
673 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
676 VNET_FEATURE_INIT (esp4_ethernet_encrypt_tun_feat_node, static) =
678 .arc_name = "ethernet-output",
679 .node_name = "esp4-encrypt-tun",
680 .runs_before = VNET_FEATURES ("adj-midchain-tx", "adj-midchain-tx-no-count"),
684 VLIB_NODE_FN (esp6_encrypt_tun_node) (vlib_main_t * vm,
685 vlib_node_runtime_t * node,
686 vlib_frame_t * from_frame)
688 return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 1);
692 VLIB_REGISTER_NODE (esp6_encrypt_tun_node) = {
693 .name = "esp6-encrypt-tun",
694 .vector_size = sizeof (u32),
695 .format_trace = format_esp_encrypt_trace,
696 .type = VLIB_NODE_TYPE_INTERNAL,
698 .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
699 .error_strings = esp_encrypt_error_strings,
701 .n_next_nodes = ESP_ENCRYPT_N_NEXT,
703 [ESP_ENCRYPT_NEXT_DROP] = "ip6-drop",
704 [ESP_ENCRYPT_NEXT_HANDOFF] = "esp6-encrypt-tun-handoff",
705 [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "error-drop",
709 VNET_FEATURE_INIT (esp6_encrypt_tun_feat_node, static) =
711 .arc_name = "ip6-output",
712 .node_name = "esp6-encrypt-tun",
713 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
716 VNET_FEATURE_INIT (esp4o6_encrypt_tun_feat_node, static) =
718 .arc_name = "ip4-output",
719 .node_name = "esp6-encrypt-tun",
720 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
728 } esp_no_crypto_trace_t;
731 format_esp_no_crypto_trace (u8 * s, va_list * args)
733 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
734 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
735 esp_no_crypto_trace_t *t = va_arg (*args, esp_no_crypto_trace_t *);
737 s = format (s, "esp-no-crypto: sa-index %u", t->sa_index);
744 ESP_NO_CRYPTO_NEXT_DROP,
745 ESP_NO_CRYPTO_N_NEXT,
750 ESP_NO_CRYPTO_ERROR_RX_PKTS,
753 static char *esp_no_crypto_error_strings[] = {
754 "Outbound ESP packets received",
758 esp_no_crypto_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
759 vlib_frame_t * frame)
761 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
762 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
763 u32 *from = vlib_frame_vector_args (frame);
764 u32 n_left = frame->n_vectors;
766 vlib_get_buffers (vm, from, b, n_left);
773 /* packets are always going to be dropped, but get the sa_index */
774 sa_index0 = *(u32 *) vnet_feature_next_with_data (&next0, b[0],
777 next[0] = ESP_NO_CRYPTO_NEXT_DROP;
779 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
781 esp_no_crypto_trace_t *tr = vlib_add_trace (vm, node, b[0],
783 tr->sa_index = sa_index0;
791 vlib_node_increment_counter (vm, node->node_index,
792 ESP_NO_CRYPTO_ERROR_RX_PKTS, frame->n_vectors);
794 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
796 return frame->n_vectors;
799 VLIB_NODE_FN (esp4_no_crypto_tun_node) (vlib_main_t * vm,
800 vlib_node_runtime_t * node,
801 vlib_frame_t * from_frame)
803 return esp_no_crypto_inline (vm, node, from_frame);
807 VLIB_REGISTER_NODE (esp4_no_crypto_tun_node) =
809 .name = "esp4-no-crypto",
810 .vector_size = sizeof (u32),
811 .format_trace = format_esp_no_crypto_trace,
812 .n_errors = ARRAY_LEN(esp_no_crypto_error_strings),
813 .error_strings = esp_no_crypto_error_strings,
814 .n_next_nodes = ESP_NO_CRYPTO_N_NEXT,
816 [ESP_NO_CRYPTO_NEXT_DROP] = "ip4-drop",
820 VNET_FEATURE_INIT (esp4_no_crypto_tun_feat_node, static) =
822 .arc_name = "ip4-output",
823 .node_name = "esp4-no-crypto",
824 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
827 VLIB_NODE_FN (esp6_no_crypto_tun_node) (vlib_main_t * vm,
828 vlib_node_runtime_t * node,
829 vlib_frame_t * from_frame)
831 return esp_no_crypto_inline (vm, node, from_frame);
835 VLIB_REGISTER_NODE (esp6_no_crypto_tun_node) =
837 .name = "esp6-no-crypto",
838 .vector_size = sizeof (u32),
839 .format_trace = format_esp_no_crypto_trace,
840 .n_errors = ARRAY_LEN(esp_no_crypto_error_strings),
841 .error_strings = esp_no_crypto_error_strings,
842 .n_next_nodes = ESP_NO_CRYPTO_N_NEXT,
844 [ESP_NO_CRYPTO_NEXT_DROP] = "ip6-drop",
848 VNET_FEATURE_INIT (esp6_no_crypto_tun_feat_node, static) =
850 .arc_name = "ip6-output",
851 .node_name = "esp6-no-crypto",
852 .runs_before = VNET_FEATURES ("adj-midchain-tx"),
857 * fd.io coding-style-patch-verification: ON
860 * eval: (c-set-style "gnu")