ipsec: fix sa counters in esp-encrypt
[vpp.git] / src / vnet / ipsec / esp_encrypt.c
1 /*
2  * esp_encrypt.c : IPSec ESP encrypt node
3  *
4  * Copyright (c) 2015 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <vnet/vnet.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/udp/udp.h>
22
23 #include <vnet/crypto/crypto.h>
24
25 #include <vnet/ipsec/ipsec.h>
26 #include <vnet/ipsec/esp.h>
27
28 #define foreach_esp_encrypt_next                   \
29 _(DROP, "error-drop")                              \
30 _(IP4_LOOKUP, "ip4-lookup")                        \
31 _(IP6_LOOKUP, "ip6-lookup")                        \
32 _(INTERFACE_OUTPUT, "interface-output")
33
34 #define _(v, s) ESP_ENCRYPT_NEXT_##v,
35 typedef enum
36 {
37   foreach_esp_encrypt_next
38 #undef _
39     ESP_ENCRYPT_N_NEXT,
40 } esp_encrypt_next_t;
41
42 #define foreach_esp_encrypt_error                               \
43  _(RX_PKTS, "ESP pkts received")                                \
44  _(SEQ_CYCLED, "sequence number cycled (packet dropped)")       \
45  _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
46  _(CHAINED_BUFFER, "chained buffers (packet dropped)")          \
47  _(NO_TRAILER_SPACE, "no trailer space (packet dropped)")
48
49 typedef enum
50 {
51 #define _(sym,str) ESP_ENCRYPT_ERROR_##sym,
52   foreach_esp_encrypt_error
53 #undef _
54     ESP_ENCRYPT_N_ERROR,
55 } esp_encrypt_error_t;
56
57 static char *esp_encrypt_error_strings[] = {
58 #define _(sym,string) string,
59   foreach_esp_encrypt_error
60 #undef _
61 };
62
63 typedef struct
64 {
65   u32 sa_index;
66   u32 spi;
67   u32 seq;
68   u8 udp_encap;
69   ipsec_crypto_alg_t crypto_alg;
70   ipsec_integ_alg_t integ_alg;
71 } esp_encrypt_trace_t;
72
73 /* packet trace format function */
74 static u8 *
75 format_esp_encrypt_trace (u8 * s, va_list * args)
76 {
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 *);
80
81   s = format (s, "esp: sa-index %d spi %u seq %u crypto %U integrity %U%s",
82               t->sa_index, t->spi, t->seq,
83               format_ipsec_crypto_alg, t->crypto_alg,
84               format_ipsec_integ_alg, t->integ_alg,
85               t->udp_encap ? " udp-encap-enabled" : "");
86   return s;
87 }
88
89 /* pad packet in input buffer */
90 static_always_inline u8 *
91 esp_add_footer_and_icv (vlib_buffer_t * b, u8 block_size, u8 icv_sz)
92 {
93   static const u8 pad_data[ESP_MAX_BLOCK_SIZE] = {
94     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
95     0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x00, 0x00,
96   };
97
98   u16 min_length = b->current_length + sizeof (esp_footer_t);
99   u16 new_length = round_pow2 (min_length, block_size);
100   u8 pad_bytes = new_length - min_length;
101   esp_footer_t *f = (esp_footer_t *) (vlib_buffer_get_current (b) +
102                                       new_length - sizeof (esp_footer_t));
103
104   if (pad_bytes)
105     clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, ESP_MAX_BLOCK_SIZE);
106
107   f->pad_length = pad_bytes;
108   b->current_length = new_length + icv_sz;
109   return &f->next_header;
110 }
111
112 static_always_inline void
113 esp_update_ip4_hdr (ip4_header_t * ip4, u16 len, int is_transport, int is_udp)
114 {
115   ip_csum_t sum;
116   u16 old_len;
117
118   len = clib_net_to_host_u16 (len);
119   old_len = ip4->length;
120
121   if (is_transport)
122     {
123       u8 prot = is_udp ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP;
124
125       sum = ip_csum_update (ip4->checksum, ip4->protocol,
126                             prot, ip4_header_t, protocol);
127       ip4->protocol = prot;
128
129       sum = ip_csum_update (sum, old_len, len, ip4_header_t, length);
130     }
131   else
132     sum = ip_csum_update (ip4->checksum, old_len, len, ip4_header_t, length);
133
134   ip4->length = len;
135   ip4->checksum = ip_csum_fold (sum);
136 }
137
138 static_always_inline void
139 esp_fill_udp_hdr (ipsec_sa_t * sa, udp_header_t * udp, u16 len)
140 {
141   clib_memcpy_fast (udp, &sa->udp_hdr, sizeof (udp_header_t));
142   udp->length = clib_net_to_host_u16 (len);
143 }
144
145 static_always_inline u8
146 ext_hdr_is_pre_esp (u8 nexthdr)
147 {
148 #ifdef CLIB_HAVE_VEC128
149   static const u8x16 ext_hdr_types = {
150     IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS,
151     IP_PROTOCOL_IPV6_ROUTE,
152     IP_PROTOCOL_IPV6_FRAGMENTATION,
153   };
154
155   return !u8x16_is_all_zero (ext_hdr_types == u8x16_splat (nexthdr));
156 #else
157   return ((nexthdr ^ IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) |
158           (nexthdr ^ IP_PROTOCOL_IPV6_ROUTE) |
159           (nexthdr ^ IP_PROTOCOL_IPV6_FRAGMENTATION) != 0);
160 #endif
161 }
162
163 static_always_inline u8
164 esp_get_ip6_hdr_len (ip6_header_t * ip6)
165 {
166   /* this code assumes that HbH, route and frag headers will be before
167      others, if that is not the case, they will end up encrypted */
168
169   u8 len = sizeof (ip6_header_t);
170   ip6_ext_header_t *p;
171
172   /* if next packet doesn't have ext header */
173   if (ext_hdr_is_pre_esp (ip6->protocol) == 0)
174     return len;
175
176   p = (void *) (ip6 + 1);
177   len += ip6_ext_header_len (p);
178
179   while (ext_hdr_is_pre_esp (p->next_hdr))
180     {
181       len += ip6_ext_header_len (p);
182       p = ip6_ext_next_header (p);
183     }
184
185   return len;
186 }
187
188 static_always_inline int
189 esp_trailer_icv_overflow (vlib_node_runtime_t * node, vlib_buffer_t * b,
190                           u16 * next, u16 buffer_data_size)
191 {
192   if (b->current_data + b->current_length <= buffer_data_size)
193     return 0;
194
195   b->current_length -= buffer_data_size - b->current_data;
196   b->error = node->errors[ESP_ENCRYPT_ERROR_NO_TRAILER_SPACE];
197   next[0] = ESP_ENCRYPT_NEXT_DROP;
198   return 1;
199 }
200
201 static_always_inline void
202 esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
203                  vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts)
204 {
205   u32 n_fail, n_ops = vec_len (ops);
206   vnet_crypto_op_t *op = ops;
207
208   if (n_ops == 0)
209     return;
210
211   n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
212
213   while (n_fail)
214     {
215       ASSERT (op - ops < n_ops);
216
217       if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
218         {
219           u32 bi = op->user_data;
220           b[bi]->error = node->errors[ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
221           nexts[bi] = ESP_ENCRYPT_NEXT_DROP;
222           n_fail--;
223         }
224       op++;
225     }
226 }
227
228 typedef struct
229 {
230   u32 salt;
231   u64 iv;
232 } __clib_packed esp_gcm_nonce_t;
233
234 STATIC_ASSERT_SIZEOF (esp_gcm_nonce_t, 12);
235
236 always_inline uword
237 esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
238                     vlib_frame_t * frame, int is_ip6, int is_tun)
239 {
240   ipsec_main_t *im = &ipsec_main;
241   ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, vm->thread_index);
242   u32 *from = vlib_frame_vector_args (frame);
243   u32 n_left = frame->n_vectors;
244   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
245   u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
246   esp_gcm_nonce_t nonces[VLIB_FRAME_SIZE], *nonce = nonces;
247   u32 thread_index = vm->thread_index;
248   u16 buffer_data_size = vlib_buffer_get_default_data_size (vm);
249   u32 current_sa_index = ~0, current_sa_packets = 0;
250   u32 current_sa_bytes = 0, spi = 0;
251   u8 block_sz = 0, iv_sz = 0, icv_sz = 0;
252   ipsec_sa_t *sa0 = 0;
253
254   vlib_get_buffers (vm, from, b, n_left);
255   vec_reset_length (ptd->crypto_ops);
256   vec_reset_length (ptd->integ_ops);
257
258   while (n_left > 0)
259     {
260       u32 sa_index0;
261       dpo_id_t *dpo;
262       esp_header_t *esp;
263       u8 *payload, *next_hdr_ptr;
264       u16 payload_len;
265       u32 hdr_len;
266
267       if (n_left > 2)
268         {
269           u8 *p;
270           vlib_prefetch_buffer_header (b[2], LOAD);
271           p = vlib_buffer_get_current (b[1]);
272           CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
273           p -= CLIB_CACHE_LINE_BYTES;
274           CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
275         }
276
277       if (is_tun)
278         {
279           /* we are on a ipsec tunnel's feature arc */
280           u32 next0;
281           sa_index0 = *(u32 *) vnet_feature_next_with_data (&next0, b[0],
282                                                             sizeof
283                                                             (sa_index0));
284           next[0] = next0;
285         }
286       else
287         sa_index0 = vnet_buffer (b[0])->ipsec.sad_index;
288
289       if (sa_index0 != current_sa_index)
290         {
291           if (current_sa_packets)
292             vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
293                                              current_sa_index,
294                                              current_sa_packets,
295                                              current_sa_bytes);
296           current_sa_packets = current_sa_bytes = 0;
297
298           sa0 = pool_elt_at_index (im->sad, sa_index0);
299           current_sa_index = sa_index0;
300           spi = clib_net_to_host_u32 (sa0->spi);
301           block_sz = sa0->crypto_block_size;
302           icv_sz = sa0->integ_icv_size;
303           iv_sz = sa0->crypto_iv_size;
304         }
305
306       if (vlib_buffer_chain_linearize (vm, b[0]) != 1)
307         {
308           b[0]->error = node->errors[ESP_ENCRYPT_ERROR_CHAINED_BUFFER];
309           next[0] = ESP_ENCRYPT_NEXT_DROP;
310           goto trace;
311         }
312
313       if (PREDICT_FALSE (esp_seq_advance (sa0)))
314         {
315           b[0]->error = node->errors[ESP_ENCRYPT_ERROR_SEQ_CYCLED];
316           next[0] = ESP_ENCRYPT_NEXT_DROP;
317           goto trace;
318         }
319
320       /* space for IV */
321       hdr_len = iv_sz;
322
323       if (ipsec_sa_is_set_IS_TUNNEL (sa0))
324         {
325           payload = vlib_buffer_get_current (b[0]);
326           next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz);
327           payload_len = b[0]->current_length;
328
329           if (esp_trailer_icv_overflow (node, b[0], next, buffer_data_size))
330             goto trace;
331
332           /* ESP header */
333           hdr_len += sizeof (*esp);
334           esp = (esp_header_t *) (payload - hdr_len);
335
336           /* optional UDP header */
337           if (ipsec_sa_is_set_UDP_ENCAP (sa0))
338             {
339               hdr_len += sizeof (udp_header_t);
340               esp_fill_udp_hdr (sa0, (udp_header_t *) (payload - hdr_len),
341                                 payload_len + hdr_len);
342             }
343
344           /* IP header */
345           if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
346             {
347               ip6_header_t *ip6;
348               u16 len = sizeof (ip6_header_t);
349               hdr_len += len;
350               ip6 = (ip6_header_t *) (payload - hdr_len);
351               clib_memcpy_fast (ip6, &sa0->ip6_hdr, len);
352               *next_hdr_ptr = (is_ip6 ?
353                                IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
354               len = payload_len + hdr_len - len;
355               ip6->payload_length = clib_net_to_host_u16 (len);
356             }
357           else
358             {
359               ip4_header_t *ip4;
360               u16 len = sizeof (ip4_header_t);
361               hdr_len += len;
362               ip4 = (ip4_header_t *) (payload - hdr_len);
363               clib_memcpy_fast (ip4, &sa0->ip4_hdr, len);
364               *next_hdr_ptr = (is_ip6 ?
365                                IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP);
366               len = payload_len + hdr_len;
367               esp_update_ip4_hdr (ip4, len, /* is_transport */ 0, 0);
368             }
369
370           dpo = sa0->dpo + IPSEC_PROTOCOL_ESP;
371           if (!is_tun)
372             {
373               next[0] = dpo->dpoi_next_node;
374               vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo->dpoi_index;
375             }
376         }
377       else                      /* transport mode */
378         {
379           u8 *l2_hdr, l2_len, *ip_hdr, ip_len;
380           udp_header_t *udp = 0;
381           u8 *old_ip_hdr = vlib_buffer_get_current (b[0]);
382
383           ip_len = is_ip6 ?
384             esp_get_ip6_hdr_len ((ip6_header_t *) old_ip_hdr) :
385             ip4_header_bytes ((ip4_header_t *) old_ip_hdr);
386
387           vlib_buffer_advance (b[0], ip_len);
388           payload = vlib_buffer_get_current (b[0]);
389           next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz);
390           payload_len = b[0]->current_length;
391
392           if (esp_trailer_icv_overflow (node, b[0], next, buffer_data_size))
393             goto trace;
394
395           /* ESP header */
396           hdr_len += sizeof (*esp);
397           esp = (esp_header_t *) (payload - hdr_len);
398
399           /* optional UDP header */
400           if (ipsec_sa_is_set_UDP_ENCAP (sa0))
401             {
402               hdr_len += sizeof (udp_header_t);
403               udp = (udp_header_t *) (payload - hdr_len);
404             }
405
406           /* IP header */
407           hdr_len += ip_len;
408           ip_hdr = payload - hdr_len;
409
410           /* L2 header */
411           l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
412           hdr_len += l2_len;
413           l2_hdr = payload - hdr_len;
414
415           /* copy l2 and ip header */
416           clib_memcpy_le32 (l2_hdr, old_ip_hdr - l2_len, l2_len);
417           clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len);
418
419           if (is_ip6)
420             {
421               ip6_header_t *ip6 = (ip6_header_t *) (ip_hdr);
422               *next_hdr_ptr = ip6->protocol;
423               ip6->protocol = IP_PROTOCOL_IPSEC_ESP;
424               ip6->payload_length =
425                 clib_host_to_net_u16 (payload_len + hdr_len - l2_len -
426                                       ip_len);
427             }
428           else
429             {
430               u16 len;
431               ip4_header_t *ip4 = (ip4_header_t *) (ip_hdr);
432               *next_hdr_ptr = ip4->protocol;
433               len = payload_len + hdr_len - l2_len;
434               if (udp)
435                 {
436                   esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 1);
437                   esp_fill_udp_hdr (sa0, udp, len - ip_len);
438                 }
439               else
440                 esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 0);
441             }
442
443           next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT;
444         }
445
446       esp->spi = spi;
447       esp->seq = clib_net_to_host_u32 (sa0->seq);
448
449       if (sa0->crypto_enc_op_id)
450         {
451           vnet_crypto_op_t *op;
452           vec_add2_aligned (ptd->crypto_ops, op, 1, CLIB_CACHE_LINE_BYTES);
453           vnet_crypto_op_init (op, sa0->crypto_enc_op_id);
454           op->src = op->dst = payload;
455           op->key_index = sa0->crypto_key_index;
456           op->len = payload_len - icv_sz;
457           op->user_data = b - bufs;
458
459           if (ipsec_sa_is_set_IS_AEAD (sa0))
460             {
461               /*
462                * construct the AAD in a scratch space in front
463                * of the IP header.
464                */
465               op->aad = payload - hdr_len - sizeof (esp_aead_t);
466
467               esp_aad_fill (op, esp, sa0);
468
469               op->tag = payload + op->len;
470               op->tag_len = 16;
471
472               u64 *iv = (u64 *) (payload - iv_sz);
473               nonce->salt = sa0->salt;
474               nonce->iv = *iv = clib_host_to_net_u64 (sa0->gcm_iv_counter++);
475               op->iv = (u8 *) nonce;
476               nonce++;
477             }
478           else
479             {
480               op->iv = payload - iv_sz;
481               op->flags = VNET_CRYPTO_OP_FLAG_INIT_IV;
482             }
483         }
484
485       if (sa0->integ_op_id)
486         {
487           vnet_crypto_op_t *op;
488           vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
489           vnet_crypto_op_init (op, sa0->integ_op_id);
490           op->src = payload - iv_sz - sizeof (esp_header_t);
491           op->digest = payload + payload_len - icv_sz;
492           op->key_index = sa0->integ_key_index;
493           op->digest_len = icv_sz;
494           op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t);
495           op->user_data = b - bufs;
496           if (ipsec_sa_is_set_USE_ESN (sa0))
497             {
498               u32 seq_hi = clib_net_to_host_u32 (sa0->seq_hi);
499               clib_memcpy_fast (op->digest, &seq_hi, sizeof (seq_hi));
500               op->len += sizeof (seq_hi);
501             }
502         }
503
504       vlib_buffer_advance (b[0], 0LL - hdr_len);
505
506       current_sa_packets += 1;
507       current_sa_bytes += payload_len;
508
509     trace:
510       if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
511         {
512           esp_encrypt_trace_t *tr = vlib_add_trace (vm, node, b[0],
513                                                     sizeof (*tr));
514           tr->sa_index = sa_index0;
515           tr->spi = sa0->spi;
516           tr->seq = sa0->seq - 1;
517           tr->udp_encap = ipsec_sa_is_set_UDP_ENCAP (sa0);
518           tr->crypto_alg = sa0->crypto_alg;
519           tr->integ_alg = sa0->integ_alg;
520         }
521       /* next */
522       n_left -= 1;
523       next += 1;
524       b += 1;
525     }
526
527   vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
528                                    current_sa_index, current_sa_packets,
529                                    current_sa_bytes);
530   esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts);
531   esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
532
533   vlib_node_increment_counter (vm, node->node_index,
534                                ESP_ENCRYPT_ERROR_RX_PKTS, frame->n_vectors);
535
536   vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
537   return frame->n_vectors;
538 }
539
540 VLIB_NODE_FN (esp4_encrypt_node) (vlib_main_t * vm,
541                                   vlib_node_runtime_t * node,
542                                   vlib_frame_t * from_frame)
543 {
544   return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 0);
545 }
546
547 /* *INDENT-OFF* */
548 VLIB_REGISTER_NODE (esp4_encrypt_node) = {
549   .name = "esp4-encrypt",
550   .vector_size = sizeof (u32),
551   .format_trace = format_esp_encrypt_trace,
552   .type = VLIB_NODE_TYPE_INTERNAL,
553
554   .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
555   .error_strings = esp_encrypt_error_strings,
556
557   .n_next_nodes = ESP_ENCRYPT_N_NEXT,
558   .next_nodes = {
559 #define _(s,n) [ESP_ENCRYPT_NEXT_##s] = n,
560     foreach_esp_encrypt_next
561 #undef _
562   },
563 };
564 /* *INDENT-ON* */
565
566 VLIB_NODE_FN (esp6_encrypt_node) (vlib_main_t * vm,
567                                   vlib_node_runtime_t * node,
568                                   vlib_frame_t * from_frame)
569 {
570   return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 0);
571 }
572
573 /* *INDENT-OFF* */
574 VLIB_REGISTER_NODE (esp6_encrypt_node) = {
575   .name = "esp6-encrypt",
576   .vector_size = sizeof (u32),
577   .format_trace = format_esp_encrypt_trace,
578   .type = VLIB_NODE_TYPE_INTERNAL,
579
580   .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
581   .error_strings = esp_encrypt_error_strings,
582
583   .n_next_nodes = ESP_ENCRYPT_N_NEXT,
584   .next_nodes = {
585 #define _(s,n) [ESP_ENCRYPT_NEXT_##s] = n,
586     foreach_esp_encrypt_next
587 #undef _
588   },
589 };
590 /* *INDENT-ON* */
591
592 VLIB_NODE_FN (esp4_encrypt_tun_node) (vlib_main_t * vm,
593                                       vlib_node_runtime_t * node,
594                                       vlib_frame_t * from_frame)
595 {
596   return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 1);
597 }
598
599 /* *INDENT-OFF* */
600 VLIB_REGISTER_NODE (esp4_encrypt_tun_node) = {
601   .name = "esp4-encrypt-tun",
602   .vector_size = sizeof (u32),
603   .format_trace = format_esp_encrypt_trace,
604   .type = VLIB_NODE_TYPE_INTERNAL,
605
606   .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
607   .error_strings = esp_encrypt_error_strings,
608
609   .n_next_nodes = 1,
610   .next_nodes = {
611     [ESP_ENCRYPT_NEXT_DROP] = "ip4-drop",
612   },
613 };
614
615 VNET_FEATURE_INIT (esp4_encrypt_tun_feat_node, static) =
616 {
617   .arc_name = "ip4-output",
618   .node_name = "esp4-encrypt-tun",
619   .runs_before = VNET_FEATURES ("adj-midchain-tx"),
620 };
621 /* *INDENT-ON* */
622
623 VLIB_NODE_FN (esp6_encrypt_tun_node) (vlib_main_t * vm,
624                                       vlib_node_runtime_t * node,
625                                       vlib_frame_t * from_frame)
626 {
627   return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 1);
628 }
629
630 /* *INDENT-OFF* */
631 VLIB_REGISTER_NODE (esp6_encrypt_tun_node) = {
632   .name = "esp6-encrypt-tun",
633   .vector_size = sizeof (u32),
634   .format_trace = format_esp_encrypt_trace,
635   .type = VLIB_NODE_TYPE_INTERNAL,
636
637   .n_errors = ARRAY_LEN(esp_encrypt_error_strings),
638   .error_strings = esp_encrypt_error_strings,
639
640   .n_next_nodes = 1,
641   .next_nodes = {
642     [ESP_ENCRYPT_NEXT_DROP] = "ip6-drop",
643   },
644 };
645
646 VNET_FEATURE_INIT (esp6_encrypt_tun_feat_node, static) =
647 {
648   .arc_name = "ip6-output",
649   .node_name = "esp6-encrypt-tun",
650   .runs_before = VNET_FEATURES ("adj-midchain-tx"),
651 };
652 /* *INDENT-ON* */
653
654 /*
655  * fd.io coding-style-patch-verification: ON
656  *
657  * Local Variables:
658  * eval: (c-set-style "gnu")
659  * End:
660  */