blob: ff9fc0c2d374af6b606740533382d4317b2a60ec [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * esp_decrypt.c : IPSec ESP decrypt 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>
John Lo90430b62020-01-31 23:48:30 -050021#include <vnet/l2/l2_input.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070022
23#include <vnet/ipsec/ipsec.h>
24#include <vnet/ipsec/esp.h>
Neale Ranns918c1612019-02-21 23:34:59 -080025#include <vnet/ipsec/ipsec_io.h>
Neale Rannsc87b66c2019-02-07 07:26:12 -080026#include <vnet/ipsec/ipsec_tun.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027
Neale Ranns568acbb2019-12-18 05:54:40 +000028#include <vnet/gre/gre.h>
29
Ed Warnickecb9cada2015-12-08 15:45:58 -070030#define foreach_esp_decrypt_next \
31_(DROP, "error-drop") \
Kingwel Xie561d1ca2019-03-05 22:56:17 -050032_(IP4_INPUT, "ip4-input-no-checksum") \
Neale Rannsf62a8c02019-04-02 08:13:33 +000033_(IP6_INPUT, "ip6-input") \
Neale Ranns568acbb2019-12-18 05:54:40 +000034_(L2_INPUT, "l2-input") \
Fan Zhangf5395782020-04-29 14:00:03 +010035_(HANDOFF, "handoff") \
36_(PENDING, "pending")
Ed Warnickecb9cada2015-12-08 15:45:58 -070037
38#define _(v, s) ESP_DECRYPT_NEXT_##v,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070039typedef enum
40{
Ed Warnickecb9cada2015-12-08 15:45:58 -070041 foreach_esp_decrypt_next
42#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070043 ESP_DECRYPT_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -070044} esp_decrypt_next_t;
45
Fan Zhangf5395782020-04-29 14:00:03 +010046#define foreach_esp_decrypt_post_next \
47_(DROP, "error-drop") \
48_(IP4_INPUT, "ip4-input-no-checksum") \
49_(IP6_INPUT, "ip6-input") \
50_(L2_INPUT, "l2-input")
51
52#define _(v, s) ESP_DECRYPT_POST_NEXT_##v,
53typedef enum
54{
55 foreach_esp_decrypt_post_next
56#undef _
57 ESP_DECRYPT_POST_N_NEXT,
58} esp_decrypt_post_next_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
Damjan Marionb4fff3a2019-03-25 15:54:40 +010060#define foreach_esp_decrypt_error \
61 _(RX_PKTS, "ESP pkts received") \
Fan Zhangf5395782020-04-29 14:00:03 +010062 _(RX_POST_PKTS, "ESP-POST pkts received") \
Damjan Marionb4fff3a2019-03-25 15:54:40 +010063 _(DECRYPTION_FAILED, "ESP decryption failed") \
64 _(INTEG_ERROR, "Integrity check failed") \
65 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
66 _(REPLAY, "SA replayed packet") \
Damjan Mariona829b132019-04-24 23:39:16 +020067 _(RUNT, "undersized packet") \
Filip Tehlarefcad1a2020-02-04 09:36:04 +000068 _(NO_BUFFERS, "no buffers (packet dropped)") \
Damjan Marionb4fff3a2019-03-25 15:54:40 +010069 _(OVERSIZED_HEADER, "buffer with oversized header (dropped)") \
Neale Ranns12989b52019-09-26 16:20:19 +000070 _(NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \
71 _(TUN_NO_PROTO, "no tunnel protocol") \
Neale Ranns02950402019-12-20 00:54:57 +000072 _(UNSUP_PAYLOAD, "unsupported payload") \
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
74
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070075typedef enum
76{
Ed Warnickecb9cada2015-12-08 15:45:58 -070077#define _(sym,str) ESP_DECRYPT_ERROR_##sym,
78 foreach_esp_decrypt_error
79#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070080 ESP_DECRYPT_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -070081} esp_decrypt_error_t;
82
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070083static char *esp_decrypt_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070084#define _(sym,string) string,
85 foreach_esp_decrypt_error
86#undef _
87};
88
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070089typedef struct
90{
Damjan Marionb4fff3a2019-03-25 15:54:40 +010091 u32 seq;
Neale Ranns6afaae12019-07-17 15:07:14 +000092 u32 sa_seq;
93 u32 sa_seq_hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 ipsec_crypto_alg_t crypto_alg;
95 ipsec_integ_alg_t integ_alg;
96} esp_decrypt_trace_t;
97
98/* packet trace format function */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070099static u8 *
100format_esp_decrypt_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101{
102 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
103 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700104 esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105
Neale Ranns6afaae12019-07-17 15:07:14 +0000106 s =
107 format (s,
108 "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u",
109 format_ipsec_crypto_alg, t->crypto_alg, format_ipsec_integ_alg,
110 t->integ_alg, t->seq, t->sa_seq, t->sa_seq_hi);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111 return s;
112}
113
Damjan Marionb4fff3a2019-03-25 15:54:40 +0100114#define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000116static_always_inline void
117esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
118 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts,
119 int e)
120{
121 vnet_crypto_op_t *op = ops;
122 u32 n_fail, n_ops = vec_len (ops);
123
124 if (n_ops == 0)
125 return;
126
127 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
128
129 while (n_fail)
130 {
131 ASSERT (op - ops < n_ops);
132 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
133 {
134 u32 err, bi = op->user_data;
135 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
136 err = e;
137 else
138 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
139 b[bi]->error = node->errors[err];
140 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
141 n_fail--;
142 }
143 op++;
144 }
145}
146
147static_always_inline void
148esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
149 vnet_crypto_op_t * ops, vlib_buffer_t * b[],
150 u16 * nexts, vnet_crypto_op_chunk_t * chunks, int e)
151{
152
153 vnet_crypto_op_t *op = ops;
154 u32 n_fail, n_ops = vec_len (ops);
155
156 if (n_ops == 0)
157 return;
158
159 n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops);
160
161 while (n_fail)
162 {
163 ASSERT (op - ops < n_ops);
164 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
165 {
166 u32 err, bi = op->user_data;
167 if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC)
168 err = e;
169 else
170 err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
171 b[bi]->error = node->errors[err];
172 nexts[bi] = ESP_DECRYPT_NEXT_DROP;
173 n_fail--;
174 }
175 op++;
176 }
177}
178
179always_inline void
180esp_remove_tail (vlib_main_t * vm, vlib_buffer_t * b, vlib_buffer_t * last,
181 u16 tail)
182{
183 vlib_buffer_t *before_last = b;
184
185 if (last->current_length > tail)
186 {
187 last->current_length -= tail;
188 return;
189 }
190 ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
191
192 while (b->flags & VLIB_BUFFER_NEXT_PRESENT)
193 {
194 before_last = b;
195 b = vlib_get_buffer (vm, b->next_buffer);
196 }
197 before_last->current_length -= tail - last->current_length;
198 vlib_buffer_free_one (vm, before_last->next_buffer);
199 before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
200}
201
202/* ICV is splitted in last two buffers so move it to the last buffer and
203 return pointer to it */
204static_always_inline u8 *
205esp_move_icv (vlib_main_t * vm, vlib_buffer_t * first,
Fan Zhangf5395782020-04-29 14:00:03 +0100206 esp_decrypt_packet_data2_t * pd2, u16 icv_sz, u16 * dif)
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000207{
208 vlib_buffer_t *before_last, *bp;
Fan Zhangf5395782020-04-29 14:00:03 +0100209 u16 last_sz = pd2->lb->current_length;
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000210 u16 first_sz = icv_sz - last_sz;
211
212 bp = before_last = first;
213 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
214 {
215 before_last = bp;
216 bp = vlib_get_buffer (vm, bp->next_buffer);
217 }
218
Fan Zhangf5395782020-04-29 14:00:03 +0100219 u8 *lb_curr = vlib_buffer_get_current (pd2->lb);
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000220 memmove (lb_curr + first_sz, lb_curr, last_sz);
221 clib_memcpy_fast (lb_curr, vlib_buffer_get_tail (before_last) - first_sz,
222 first_sz);
223 before_last->current_length -= first_sz;
Fan Zhangf5395782020-04-29 14:00:03 +0100224 clib_memset (vlib_buffer_get_tail (before_last), 0, first_sz);
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000225 if (dif)
226 dif[0] = first_sz;
Fan Zhangf5395782020-04-29 14:00:03 +0100227 pd2->lb = before_last;
228 pd2->icv_removed = 1;
229 pd2->free_buffer_index = before_last->next_buffer;
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000230 before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
231 return lb_curr;
232}
233
Fan Zhangf5395782020-04-29 14:00:03 +0100234static_always_inline i16
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000235esp_insert_esn (vlib_main_t * vm, ipsec_sa_t * sa,
Fan Zhangf5395782020-04-29 14:00:03 +0100236 esp_decrypt_packet_data2_t * pd2, u32 * data_len,
237 u8 ** digest, u16 * len, vlib_buffer_t * b, u8 * payload)
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000238{
239 if (!ipsec_sa_is_set_USE_ESN (sa))
Fan Zhangf5395782020-04-29 14:00:03 +0100240 return 0;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000241
242 /* shift ICV by 4 bytes to insert ESN */
243 u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
244 u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa->seq_hi);
245
Fan Zhangf5395782020-04-29 14:00:03 +0100246 if (pd2->icv_removed)
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000247 {
Fan Zhangf5395782020-04-29 14:00:03 +0100248 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000249 if (space_left >= sz)
250 {
Fan Zhangf5395782020-04-29 14:00:03 +0100251 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
252 *data_len += sz;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000253 }
254 else
Fan Zhangf5395782020-04-29 14:00:03 +0100255 return sz;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000256
257 len[0] = b->current_length;
258 }
259 else
260 {
261 clib_memcpy_fast (tmp, payload + len[0], ESP_MAX_ICV_SIZE);
262 clib_memcpy_fast (payload + len[0], &seq_hi, sz);
263 clib_memcpy_fast (payload + len[0] + sz, tmp, ESP_MAX_ICV_SIZE);
Fan Zhangf5395782020-04-29 14:00:03 +0100264 *data_len += sz;
265 *digest += sz;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000266 }
Fan Zhangf5395782020-04-29 14:00:03 +0100267 return sz;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000268}
269
270static_always_inline u8 *
271esp_move_icv_esn (vlib_main_t * vm, vlib_buffer_t * first,
Fan Zhangf5395782020-04-29 14:00:03 +0100272 esp_decrypt_packet_data2_t * pd2, u16 icv_sz,
273 ipsec_sa_t * sa, u8 * extra_esn, u32 * len)
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000274{
275 u16 dif = 0;
Fan Zhangf5395782020-04-29 14:00:03 +0100276 u8 *digest = esp_move_icv (vm, first, pd2, icv_sz, &dif);
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000277 if (dif)
Fan Zhangf5395782020-04-29 14:00:03 +0100278 *len -= dif;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000279
280 if (ipsec_sa_is_set_USE_ESN (sa))
281 {
282 u8 sz = sizeof (sa->seq_hi);
283 u32 seq_hi = clib_host_to_net_u32 (sa->seq_hi);
Fan Zhangf5395782020-04-29 14:00:03 +0100284 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000285
286 if (space_left >= sz)
287 {
Fan Zhangf5395782020-04-29 14:00:03 +0100288 clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, sz);
289 *len += sz;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000290 }
291 else
292 {
293 /* no space for ESN at the tail, use the next buffer
294 * (with ICV data) */
Fan Zhangf5395782020-04-29 14:00:03 +0100295 ASSERT (pd2->icv_removed);
296 vlib_buffer_t *tmp = vlib_get_buffer (vm, pd2->free_buffer_index);
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000297 clib_memcpy_fast (vlib_buffer_get_current (tmp) - sz, &seq_hi, sz);
298 extra_esn[0] = 1;
299 }
300 }
301 return digest;
302}
303
Fan Zhangf5395782020-04-29 14:00:03 +0100304static_always_inline int
305esp_decrypt_chain_integ (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
306 esp_decrypt_packet_data2_t * pd2,
307 ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
308 u8 * start_src, u32 start_len,
309 u8 ** digest, u16 * n_ch, u32 * integ_total_len)
310{
311 vnet_crypto_op_chunk_t *ch;
312 vlib_buffer_t *cb = vlib_get_buffer (vm, b->next_buffer);
313 u16 n_chunks = 1;
314 u32 total_len;
315 vec_add2 (ptd->chunks, ch, 1);
316 total_len = ch->len = start_len;
317 ch->src = start_src;
318
319 while (1)
320 {
321 vec_add2 (ptd->chunks, ch, 1);
322 n_chunks += 1;
323 ch->src = vlib_buffer_get_current (cb);
324 if (pd2->lb == cb)
325 {
326 if (pd2->icv_removed)
327 ch->len = cb->current_length;
328 else
329 ch->len = cb->current_length - icv_sz;
330 if (ipsec_sa_is_set_USE_ESN (sa0))
331 {
332 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
333 u8 tmp[ESP_MAX_ICV_SIZE], sz = sizeof (sa0->seq_hi);
334 u8 *esn;
335 vlib_buffer_t *tmp_b;
336 u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb);
337 if (space_left < sz)
338 {
339 if (pd2->icv_removed)
340 {
341 /* use pre-data area from the last bufer
342 that was removed from the chain */
343 tmp_b = vlib_get_buffer (vm, pd2->free_buffer_index);
344 esn = tmp_b->data - sz;
345 }
346 else
347 {
348 /* no space, need to allocate new buffer */
349 u32 tmp_bi = 0;
350 if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1)
351 return -1;
352 tmp_b = vlib_get_buffer (vm, tmp_bi);
353 esn = tmp_b->data;
354 pd2->free_buffer_index = tmp_bi;
355 }
356 clib_memcpy_fast (esn, &seq_hi, sz);
357
358 vec_add2 (ptd->chunks, ch, 1);
359 n_chunks += 1;
360 ch->src = esn;
361 ch->len = sz;
362 }
363 else
364 {
365 if (pd2->icv_removed)
366 {
367 clib_memcpy_fast (vlib_buffer_get_tail
368 (pd2->lb), &seq_hi, sz);
369 }
370 else
371 {
372 clib_memcpy_fast (tmp, *digest, ESP_MAX_ICV_SIZE);
373 clib_memcpy_fast (*digest, &seq_hi, sz);
374 clib_memcpy_fast (*digest + sz, tmp, ESP_MAX_ICV_SIZE);
375 *digest += sz;
376 }
377 ch->len += sz;
378 }
379 }
380 total_len += ch->len;
381 break;
382 }
383 else
384 total_len += ch->len = cb->current_length;
385
386 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
387 break;
388
389 cb = vlib_get_buffer (vm, cb->next_buffer);
390 }
391
392 if (n_ch)
393 *n_ch = n_chunks;
394 if (integ_total_len)
395 *integ_total_len = total_len;
396
397 return 0;
398}
399
400static_always_inline u32
401esp_decrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd,
402 esp_decrypt_packet_data2_t * pd2,
403 ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz,
404 u8 * start, u32 start_len, u8 ** tag, u16 * n_ch)
405{
406 vnet_crypto_op_chunk_t *ch;
407 vlib_buffer_t *cb = b;
408 u16 n_chunks = 1;
409 u32 total_len;
410 vec_add2 (ptd->chunks, ch, 1);
411 total_len = ch->len = start_len;
412 ch->src = ch->dst = start;
413 cb = vlib_get_buffer (vm, cb->next_buffer);
414 n_chunks = 1;
415
416 while (1)
417 {
418 vec_add2 (ptd->chunks, ch, 1);
419 n_chunks += 1;
420 ch->src = ch->dst = vlib_buffer_get_current (cb);
421 if (pd2->lb == cb)
422 {
423 if (ipsec_sa_is_set_IS_AEAD (sa0))
424 {
425 if (pd2->lb->current_length < icv_sz)
426 {
427 u16 dif = 0;
428 *tag = esp_move_icv (vm, b, pd2, icv_sz, &dif);
429
430 /* this chunk does not contain crypto data */
431 n_chunks -= 1;
432 /* and fix previous chunk's length as it might have
433 been changed */
434 ASSERT (n_chunks > 0);
435 if (pd2->lb == b)
436 {
437 total_len -= dif;
438 ch[-1].len -= dif;
439 }
440 else
441 {
442 total_len = total_len + pd2->lb->current_length -
443 ch[-1].len;
444 ch[-1].len = pd2->lb->current_length;
445 }
446 break;
447 }
448 else
449 *tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
450 }
451
452 if (pd2->icv_removed)
453 total_len += ch->len = cb->current_length;
454 else
455 total_len += ch->len = cb->current_length - icv_sz;
456 }
457 else
458 total_len += ch->len = cb->current_length;
459
460 if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT))
461 break;
462
463 cb = vlib_get_buffer (vm, cb->next_buffer);
464 }
465
466 if (n_ch)
467 *n_ch = n_chunks;
468
469 return total_len;
470}
471
472static_always_inline void
473esp_decrypt_prepare_sync_op (vlib_main_t * vm, vlib_node_runtime_t * node,
474 ipsec_per_thread_data_t * ptd,
475 vnet_crypto_op_t *** crypto_ops,
476 vnet_crypto_op_t *** integ_ops,
477 vnet_crypto_op_t * op,
478 ipsec_sa_t * sa0, u8 * payload,
479 u16 len, u8 icv_sz, u8 iv_sz,
480 esp_decrypt_packet_data_t * pd,
481 esp_decrypt_packet_data2_t * pd2,
482 vlib_buffer_t * b, u16 * next, u32 index)
483{
484 const u8 esp_sz = sizeof (esp_header_t);
485
486 if (PREDICT_TRUE (sa0->integ_op_id != VNET_CRYPTO_OP_NONE))
487 {
488 vnet_crypto_op_init (op, sa0->integ_op_id);
489 op->key_index = sa0->integ_key_index;
490 op->src = payload;
491 op->flags = VNET_CRYPTO_OP_FLAG_HMAC_CHECK;
492 op->user_data = index;
493 op->digest = payload + len;
494 op->digest_len = icv_sz;
495 op->len = len;
496
497 if (pd->is_chain)
498 {
499 /* buffer is chained */
500 op->len = pd->current_length;
501
502 /* special case when ICV is splitted and needs to be reassembled
503 * first -> move it to the last buffer. Also take into account
504 * that ESN needs to be added after encrypted data and may or
505 * may not fit in the tail.*/
506 if (pd2->lb->current_length < icv_sz)
507 {
508 u8 extra_esn = 0;
509 op->digest =
510 esp_move_icv_esn (vm, b, pd2, icv_sz, sa0,
511 &extra_esn, &op->len);
512
513 if (extra_esn)
514 {
515 /* esn is in the last buffer, that was unlinked from
516 * the chain */
517 op->len = b->current_length;
518 }
519 else
520 {
521 if (pd2->lb == b)
522 {
523 /* we now have a single buffer of crypto data, adjust
524 * the length (second buffer contains only ICV) */
525 *integ_ops = &ptd->integ_ops;
526 *crypto_ops = &ptd->crypto_ops;
527 len = b->current_length;
528 goto out;
529 }
530 }
531 }
532 else
533 op->digest = vlib_buffer_get_tail (pd2->lb) - icv_sz;
534
535 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
536 op->chunk_index = vec_len (ptd->chunks);
537 if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz,
538 payload, pd->current_length,
539 &op->digest, &op->n_chunks, 0) < 0)
540 {
541 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
542 next[0] = ESP_DECRYPT_NEXT_DROP;
543 return;
544 }
545 }
546 else
547 esp_insert_esn (vm, sa0, pd2, &op->len, &op->digest, &len, b,
548 payload);
549 out:
550 vec_add_aligned (*(integ_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
551 }
552
553 payload += esp_sz;
554 len -= esp_sz;
555
556 if (sa0->crypto_dec_op_id != VNET_CRYPTO_OP_NONE)
557 {
558 vnet_crypto_op_init (op, sa0->crypto_dec_op_id);
559 op->key_index = sa0->crypto_key_index;
560 op->iv = payload;
561
562 if (ipsec_sa_is_set_IS_AEAD (sa0))
563 {
564 esp_header_t *esp0;
565 esp_aead_t *aad;
566 u8 *scratch;
567
568 /*
569 * construct the AAD and the nonce (Salt || IV) in a scratch
570 * space in front of the IP header.
571 */
572 scratch = payload - esp_sz;
573 esp0 = (esp_header_t *) (scratch);
574
575 scratch -= (sizeof (*aad) + pd->hdr_sz);
576 op->aad = scratch;
577
578 op->aad_len = esp_aad_fill (op->aad, esp0, sa0);
579
580 /*
581 * we don't need to refer to the ESP header anymore so we
582 * can overwrite it with the salt and use the IV where it is
583 * to form the nonce = (Salt + IV)
584 */
585 op->iv -= sizeof (sa0->salt);
586 clib_memcpy_fast (op->iv, &sa0->salt, sizeof (sa0->salt));
587
588 op->tag = payload + len;
589 op->tag_len = 16;
590 }
591 op->src = op->dst = payload += iv_sz;
592 op->len = len - iv_sz;
593 op->user_data = index;
594
595 if (pd->is_chain && (pd2->lb != b))
596 {
597 /* buffer is chained */
598 op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
599 op->chunk_index = vec_len (ptd->chunks);
600 esp_decrypt_chain_crypto (vm, ptd, pd2, sa0, b, icv_sz,
601 payload, len - pd->iv_sz + pd->icv_sz,
602 &op->tag, &op->n_chunks);
603 }
604
605 vec_add_aligned (*(crypto_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES);
606 }
607}
608
609static_always_inline int
610esp_decrypt_prepare_async_frame (vlib_main_t * vm,
611 vlib_node_runtime_t * node,
612 ipsec_per_thread_data_t * ptd,
613 vnet_crypto_async_frame_t ** f,
614 ipsec_sa_t * sa0, u8 * payload, u16 len,
615 u8 icv_sz, u8 iv_sz,
616 esp_decrypt_packet_data_t * pd,
617 esp_decrypt_packet_data2_t * pd2, u32 bi,
618 vlib_buffer_t * b, u16 * next,
619 u16 async_next)
620{
621 const u8 esp_sz = sizeof (esp_header_t);
622 u32 current_protect_index = vnet_buffer (b)->ipsec.protect_index;
623 esp_decrypt_packet_data_t *async_pd = &(esp_post_data (b))->decrypt_data;
624 esp_decrypt_packet_data2_t *async_pd2 = esp_post_data2 (b);
625 u8 *tag = payload + len, *iv = payload + esp_sz, *aad = 0;
626 u32 key_index;
627 u32 crypto_len, integ_len = 0;
628 i16 crypto_start_offset, integ_start_offset = 0;
629 u8 flags = 0;
630
631 if (!ipsec_sa_is_set_IS_AEAD (sa0))
632 {
633 /* linked algs */
634 key_index = sa0->linked_key_index;
635 integ_start_offset = payload - b->data;
636 integ_len = len;
637
638 if (pd->is_chain)
639 {
640 /* buffer is chained */
641 integ_len = pd->current_length;
642
643 /* special case when ICV is splitted and needs to be reassembled
644 * first -> move it to the last buffer. Also take into account
645 * that ESN needs to be added after encrypted data and may or
646 * may not fit in the tail.*/
647 if (pd2->lb->current_length < icv_sz)
648 {
649 u8 extra_esn = 0;
650 tag = esp_move_icv_esn (vm, b, pd2, icv_sz, sa0,
651 &extra_esn, &integ_len);
652
653 if (extra_esn)
654 {
655 /* esn is in the last buffer, that was unlinked from
656 * the chain */
657 integ_len = b->current_length;
658 }
659 else
660 {
661 if (pd2->lb == b)
662 {
663 /* we now have a single buffer of crypto data, adjust
664 * the length (second buffer contains only ICV) */
665 len = b->current_length;
666 goto out;
667 }
668 }
669 }
670 else
671 tag = vlib_buffer_get_tail (pd2->lb) - icv_sz;
672
673 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
674 if (esp_decrypt_chain_integ (vm, ptd, pd2, sa0, b, icv_sz, payload,
675 pd->current_length, &tag,
676 0, &integ_len) < 0)
677 {
678 /* allocate buffer failed, will not add to frame and drop */
679 b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
680 next[0] = ESP_DECRYPT_NEXT_DROP;
681 return 0;
682 }
683 }
684 else
685 esp_insert_esn (vm, sa0, pd2, &integ_len, &tag, &len, b, payload);
686 }
687 else
688 key_index = sa0->crypto_key_index;
689
690out:
691 /* crypto */
692 payload += esp_sz;
693 len -= esp_sz;
694 iv = payload;
695
696 if (ipsec_sa_is_set_IS_AEAD (sa0))
697 {
698 esp_header_t *esp0;
699 u8 *scratch;
700
701 /*
702 * construct the AAD and the nonce (Salt || IV) in a scratch
703 * space in front of the IP header.
704 */
705 scratch = payload - esp_sz;
706 esp0 = (esp_header_t *) (scratch);
707
708 scratch -= (sizeof (esp_aead_t) + pd->hdr_sz);
709 aad = scratch;
710
711 esp_aad_fill (aad, esp0, sa0);
712
713 /*
714 * we don't need to refer to the ESP header anymore so we
715 * can overwrite it with the salt and use the IV where it is
716 * to form the nonce = (Salt + IV)
717 */
718 iv -= sizeof (sa0->salt);
719 clib_memcpy_fast (iv, &sa0->salt, sizeof (sa0->salt));
720
721 tag = payload + len;
722 }
723
724 crypto_start_offset = (payload += iv_sz) - b->data;
725 crypto_len = len - iv_sz;
726
727 if (pd->is_chain && (pd2->lb != b))
728 {
729 /* buffer is chained */
730 flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS;
731
732 crypto_len = esp_decrypt_chain_crypto (vm, ptd, pd2, sa0, b, icv_sz,
733 payload,
734 len - pd->iv_sz + pd->icv_sz,
735 &tag, 0);
736 }
737
738 *async_pd = *pd;
739 *async_pd2 = *pd2;
740 pd->protect_index = current_protect_index;
741 next[0] = ESP_DECRYPT_NEXT_PENDING;
742
743 /* for AEAD integ_len - crypto_len will be negative, it is ok since it
744 * is ignored by the engine. */
745 return vnet_crypto_async_add_to_frame (vm, f, key_index, crypto_len,
746 integ_len - crypto_len,
747 crypto_start_offset,
748 integ_start_offset,
749 bi, async_next, iv, tag, aad, flags);
750}
751
752static_always_inline void
753esp_decrypt_post_crypto (vlib_main_t * vm, vlib_node_runtime_t * node,
754 esp_decrypt_packet_data_t * pd,
755 esp_decrypt_packet_data2_t * pd2, vlib_buffer_t * b,
756 u16 * next, int is_ip6, int is_tun, int is_async)
757{
758 ipsec_main_t *im = &ipsec_main;
759 ipsec_sa_t *sa0 = vec_elt_at_index (im->sad, pd->sa_index);
760 vlib_buffer_t *lb = b;
761 const u8 esp_sz = sizeof (esp_header_t);
762 const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL | IPSEC_SA_FLAG_IS_TUNNEL_V6;
763 u8 pad_length = 0, next_header = 0;
764 u16 icv_sz;
765
766 /*
767 * redo the anti-reply check
768 * in this frame say we have sequence numbers, s, s+1, s+1, s+1
769 * and s and s+1 are in the window. When we did the anti-replay
770 * check above we did so against the state of the window (W),
771 * after packet s-1. So each of the packets in the sequence will be
772 * accepted.
773 * This time s will be cheked against Ws-1, s+1 chceked against Ws
774 * (i.e. the window state is updated/advnaced)
775 * so this time the successive s+! packet will be dropped.
776 * This is a consequence of batching the decrypts. If the
777 * check-dcrypt-advance process was done for each packet it would
778 * be fine. But we batch the decrypts because it's much more efficient
779 * to do so in SW and if we offload to HW and the process is async.
780 *
781 * You're probably thinking, but this means an attacker can send the
782 * above sequence and cause VPP to perform decrpyts that will fail,
783 * and that's true. But if the attacker can determine s (a valid
784 * sequence number in the window) which is non-trivial, it can generate
785 * a sequence s, s+1, s+2, s+3, ... s+n and nothing will prevent any
786 * implementation, sequential or batching, from decrypting these.
787 */
788 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
789 {
790 b->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
791 next[0] = ESP_DECRYPT_NEXT_DROP;
792 return;
793 }
794
795 ipsec_sa_anti_replay_advance (sa0, pd->seq);
796
797 if (pd->is_chain)
798 {
799 lb = pd2->lb;
800 icv_sz = pd2->icv_removed ? 0 : pd->icv_sz;
801 if (pd2->free_buffer_index)
802 {
803 vlib_buffer_free_one (vm, pd2->free_buffer_index);
804 lb->next_buffer = 0;
805 }
806 if (lb->current_length < sizeof (esp_footer_t) + icv_sz)
807 {
808 /* esp footer is either splitted in two buffers or in the before
809 * last buffer */
810
811 vlib_buffer_t *before_last = b, *bp = b;
812 while (bp->flags & VLIB_BUFFER_NEXT_PRESENT)
813 {
814 before_last = bp;
815 bp = vlib_get_buffer (vm, bp->next_buffer);
816 }
817 u8 *bt = vlib_buffer_get_tail (before_last);
818
819 if (lb->current_length == icv_sz)
820 {
821 esp_footer_t *f = (esp_footer_t *) (bt - sizeof (*f));
822 pad_length = f->pad_length;
823 next_header = f->next_header;
824 }
825 else
826 {
827 pad_length = (bt - 1)[0];
828 next_header = ((u8 *) vlib_buffer_get_current (lb))[0];
829 }
830 }
831 else
832 {
833 esp_footer_t *f =
834 (esp_footer_t *) (lb->data + lb->current_data +
835 lb->current_length - sizeof (esp_footer_t) -
836 icv_sz);
837 pad_length = f->pad_length;
838 next_header = f->next_header;
839 }
840 }
841 else
842 {
843 icv_sz = pd->icv_sz;
844 esp_footer_t *f =
845 (esp_footer_t *) (lb->data + lb->current_data + lb->current_length -
846 sizeof (esp_footer_t) - icv_sz);
847 pad_length = f->pad_length;
848 next_header = f->next_header;
849 }
850
851 u16 adv = pd->iv_sz + esp_sz;
852 u16 tail = sizeof (esp_footer_t) + pad_length + icv_sz;
853 u16 tail_orig = sizeof (esp_footer_t) + pad_length + pd->icv_sz;
854 b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
855
856 if ((pd->flags & tun_flags) == 0 && !is_tun) /* transport mode */
857 {
858 u8 udp_sz = (is_ip6 == 0 && pd->flags & IPSEC_SA_FLAG_UDP_ENCAP) ?
859 sizeof (udp_header_t) : 0;
860 u16 ip_hdr_sz = pd->hdr_sz - udp_sz;
861 u8 *old_ip = b->data + pd->current_data - ip_hdr_sz - udp_sz;
862 u8 *ip = old_ip + adv + udp_sz;
863
864 if (is_ip6 && ip_hdr_sz > 64)
865 memmove (ip, old_ip, ip_hdr_sz);
866 else
867 clib_memcpy_le64 (ip, old_ip, ip_hdr_sz);
868
869 b->current_data = pd->current_data + adv - ip_hdr_sz;
870 b->current_length += ip_hdr_sz - adv;
871 esp_remove_tail (vm, b, lb, tail);
872
873 if (is_ip6)
874 {
875 ip6_header_t *ip6 = (ip6_header_t *) ip;
876 u16 len = clib_net_to_host_u16 (ip6->payload_length);
877 len -= adv + tail_orig;
878 ip6->payload_length = clib_host_to_net_u16 (len);
879 ip6->protocol = next_header;
880 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
881 }
882 else
883 {
884 ip4_header_t *ip4 = (ip4_header_t *) ip;
885 ip_csum_t sum = ip4->checksum;
886 u16 len = clib_net_to_host_u16 (ip4->length);
887 len = clib_host_to_net_u16 (len - adv - tail_orig - udp_sz);
888 sum = ip_csum_update (sum, ip4->protocol, next_header,
889 ip4_header_t, protocol);
890 sum = ip_csum_update (sum, ip4->length, len, ip4_header_t, length);
891 ip4->checksum = ip_csum_fold (sum);
892 ip4->protocol = next_header;
893 ip4->length = len;
894 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
895 }
896 }
897 else
898 {
899 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
900 {
901 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
902 b->current_data = pd->current_data + adv;
903 b->current_length = pd->current_length - adv;
904 esp_remove_tail (vm, b, lb, tail);
905 }
906 else if (next_header == IP_PROTOCOL_IPV6)
907 {
908 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
909 b->current_data = pd->current_data + adv;
910 b->current_length = pd->current_length - adv;
911 esp_remove_tail (vm, b, lb, tail);
912 }
913 else
914 {
915 if (is_tun && next_header == IP_PROTOCOL_GRE)
916 {
917 gre_header_t *gre;
918
919 b->current_data = pd->current_data + adv;
920 b->current_length = pd->current_length - adv - tail;
921
922 gre = vlib_buffer_get_current (b);
923
924 vlib_buffer_advance (b, sizeof (*gre));
925
926 switch (clib_net_to_host_u16 (gre->protocol))
927 {
928 case GRE_PROTOCOL_teb:
929 vnet_update_l2_len (b);
930 next[0] = ESP_DECRYPT_NEXT_L2_INPUT;
931 break;
932 case GRE_PROTOCOL_ip4:
933 next[0] = ESP_DECRYPT_NEXT_IP4_INPUT;
934 break;
935 case GRE_PROTOCOL_ip6:
936 next[0] = ESP_DECRYPT_NEXT_IP6_INPUT;
937 break;
938 default:
939 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
940 next[0] = ESP_DECRYPT_NEXT_DROP;
941 break;
942 }
943 }
944 else
945 {
946 next[0] = ESP_DECRYPT_NEXT_DROP;
947 b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD];
948 return;
949 }
950 }
951 if (is_tun)
952 {
953 if (ipsec_sa_is_set_IS_PROTECT (sa0))
954 {
955 /*
956 * There are two encap possibilities
957 * 1) the tunnel and ths SA are prodiving encap, i.e. it's
958 * MAC | SA-IP | TUN-IP | ESP | PAYLOAD
959 * implying the SA is in tunnel mode (on a tunnel interface)
960 * 2) only the tunnel provides encap
961 * MAC | TUN-IP | ESP | PAYLOAD
962 * implying the SA is in transport mode.
963 *
964 * For 2) we need only strip the tunnel encap and we're good.
965 * since the tunnel and crypto ecnap (int the tun=protect
966 * object) are the same and we verified above that these match
967 * for 1) we need to strip the SA-IP outer headers, to
968 * reveal the tunnel IP and then check that this matches
969 * the configured tunnel.
970 */
971 const ipsec_tun_protect_t *itp;
972
973 if (is_async)
974 itp = ipsec_tun_protect_get (pd->protect_index);
975 else
976 itp =
977 ipsec_tun_protect_get (vnet_buffer (b)->
978 ipsec.protect_index);
979
980 if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP))
981 {
982 const ip4_header_t *ip4;
983
984 ip4 = vlib_buffer_get_current (b);
985
986 if (!ip46_address_is_equal_v4 (&itp->itp_tun.src,
987 &ip4->dst_address) ||
988 !ip46_address_is_equal_v4 (&itp->itp_tun.dst,
989 &ip4->src_address))
990 {
991 next[0] = ESP_DECRYPT_NEXT_DROP;
992 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
993 }
994 }
995 else if (next_header == IP_PROTOCOL_IPV6)
996 {
997 const ip6_header_t *ip6;
998
999 ip6 = vlib_buffer_get_current (b);
1000
1001 if (!ip46_address_is_equal_v6 (&itp->itp_tun.src,
1002 &ip6->dst_address) ||
1003 !ip46_address_is_equal_v6 (&itp->itp_tun.dst,
1004 &ip6->src_address))
1005 {
1006 next[0] = ESP_DECRYPT_NEXT_DROP;
1007 b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO];
1008 }
1009 }
1010 }
1011 }
1012 }
1013}
1014
1015/* when submitting a frame is failed, drop all buffers in the frame */
1016static_always_inline void
1017esp_async_recycle_failed_submit (vnet_crypto_async_frame_t * f,
1018 vlib_buffer_t ** b, u16 * next)
1019{
1020 u32 n_drop = f->n_elts;
1021 while (--n_drop)
1022 {
1023 (b - n_drop)[0]->error = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR;
1024 (next - n_drop)[0] = ESP_DECRYPT_NEXT_DROP;
1025 }
1026 vnet_crypto_async_reset_frame (f);
1027}
1028
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001029always_inline uword
1030esp_decrypt_inline (vlib_main_t * vm,
1031 vlib_node_runtime_t * node, vlib_frame_t * from_frame,
Fan Zhangf5395782020-04-29 14:00:03 +01001032 int is_ip6, int is_tun, u16 async_next)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001033{
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034 ipsec_main_t *im = &ipsec_main;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001035 u32 thread_index = vm->thread_index;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001036 u16 len;
1037 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
Damjan Marionc98275f2019-03-06 14:05:01 +01001038 u32 *from = vlib_frame_vector_args (from_frame);
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001039 u32 n_left = from_frame->n_vectors;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001040 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
Damjan Marionc98275f2019-03-06 14:05:01 +01001041 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001042 esp_decrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
Fan Zhangf5395782020-04-29 14:00:03 +01001043 esp_decrypt_packet_data2_t pkt_data2[VLIB_FRAME_SIZE], *pd2 = pkt_data2;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001044 esp_decrypt_packet_data_t cpd = { };
1045 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
1046 const u8 esp_sz = sizeof (esp_header_t);
1047 ipsec_sa_t *sa0 = 0;
Filip Tehlare4e8c6b2020-02-13 07:49:30 +00001048 vnet_crypto_op_t _op, *op = &_op;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001049 vnet_crypto_op_t **crypto_ops = &ptd->crypto_ops;
1050 vnet_crypto_op_t **integ_ops = &ptd->integ_ops;
Fan Zhangf5395782020-04-29 14:00:03 +01001051 vnet_crypto_async_frame_t *async_frame = 0;
1052 int is_async = im->async_mode;
1053 vnet_crypto_async_op_id_t last_async_op = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001054
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001055 vlib_get_buffers (vm, from, b, n_left);
Fan Zhangf5395782020-04-29 14:00:03 +01001056 if (!is_async)
1057 {
1058 vec_reset_length (ptd->crypto_ops);
1059 vec_reset_length (ptd->integ_ops);
1060 vec_reset_length (ptd->chained_crypto_ops);
1061 vec_reset_length (ptd->chained_integ_ops);
1062 }
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001063 vec_reset_length (ptd->chunks);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001064 clib_memset_u16 (nexts, -1, n_left);
1065
1066 while (n_left > 0)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001067 {
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001068 u8 *payload;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001070 if (n_left > 2)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001071 {
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001072 u8 *p;
1073 vlib_prefetch_buffer_header (b[2], LOAD);
1074 p = vlib_buffer_get_current (b[1]);
1075 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1076 p -= CLIB_CACHE_LINE_BYTES;
1077 CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD);
1078 }
1079
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001080 u32 n_bufs = vlib_buffer_chain_linearize (vm, b[0]);
1081 if (n_bufs == 0)
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001082 {
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001083 b[0]->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS];
Damjan Marion1f4e1cb2019-03-28 19:19:31 +01001084 next[0] = ESP_DECRYPT_NEXT_DROP;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001085 goto next;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001086 }
Damjan Marionc98275f2019-03-06 14:05:01 +01001087
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001088 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
Damjan Marionc98275f2019-03-06 14:05:01 +01001089 {
Damjan Marion867dfdd2019-06-05 15:42:54 +02001090 if (current_sa_pkts)
1091 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1092 current_sa_index,
1093 current_sa_pkts,
1094 current_sa_bytes);
1095 current_sa_bytes = current_sa_pkts = 0;
1096
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001097 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1098 sa0 = pool_elt_at_index (im->sad, current_sa_index);
Neale Ranns123b5eb2020-10-16 14:03:55 +00001099
1100 /* fetch the second cacheline ASAP */
1101 CLIB_PREFETCH (sa0->cacheline1, CLIB_CACHE_LINE_BYTES, LOAD);
Damjan Marion7c22ff72019-04-04 12:25:44 +02001102 cpd.icv_sz = sa0->integ_icv_size;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001103 cpd.iv_sz = sa0->crypto_iv_size;
1104 cpd.flags = sa0->flags;
1105 cpd.sa_index = current_sa_index;
Fan Zhangf5395782020-04-29 14:00:03 +01001106
1107 /* submit frame when op_id is different then the old one */
1108 if (is_async && last_async_op != sa0->crypto_async_dec_op_id)
1109 {
1110 if (async_frame && async_frame->n_elts)
1111 {
1112 if (vnet_crypto_async_submit_open_frame (vm, async_frame))
1113 esp_async_recycle_failed_submit (async_frame, b, next);
1114 }
1115 async_frame =
1116 vnet_crypto_async_get_frame (vm, sa0->crypto_async_dec_op_id);
1117 last_async_op = sa0->crypto_async_dec_op_id;
1118 }
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001119 }
1120
Neale Rannsf62a8c02019-04-02 08:13:33 +00001121 if (PREDICT_FALSE (~0 == sa0->decrypt_thread_index))
1122 {
1123 /* this is the first packet to use this SA, claim the SA
1124 * for this thread. this could happen simultaneously on
1125 * another thread */
1126 clib_atomic_cmp_and_swap (&sa0->decrypt_thread_index, ~0,
1127 ipsec_sa_assign_thread (thread_index));
1128 }
1129
1130 if (PREDICT_TRUE (thread_index != sa0->decrypt_thread_index))
1131 {
1132 next[0] = ESP_DECRYPT_NEXT_HANDOFF;
1133 goto next;
1134 }
1135
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001136 /* store packet data for next round for easier prefetch */
1137 pd->sa_data = cpd.sa_data;
1138 pd->current_data = b[0]->current_data;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001139 pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
1140 payload = b[0]->data + pd->current_data;
Neale Ranns6afaae12019-07-17 15:07:14 +00001141 pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq);
Fan Zhangf5395782020-04-29 14:00:03 +01001142 pd->is_chain = 0;
1143 pd2->lb = b[0];
1144 pd2->free_buffer_index = 0;
1145 pd2->icv_removed = 0;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001146
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001147 if (n_bufs > 1)
1148 {
Fan Zhangf5395782020-04-29 14:00:03 +01001149 pd->is_chain = 1;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001150 /* find last buffer in the chain */
Fan Zhangf5395782020-04-29 14:00:03 +01001151 while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT)
1152 pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer);
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001153
1154 crypto_ops = &ptd->chained_crypto_ops;
1155 integ_ops = &ptd->chained_integ_ops;
1156 }
Fan Zhangf5395782020-04-29 14:00:03 +01001157
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001158 pd->current_length = b[0]->current_length;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001159
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001160 /* anti-reply check */
Neale Ranns6afaae12019-07-17 15:07:14 +00001161 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001162 {
1163 b[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
1164 next[0] = ESP_DECRYPT_NEXT_DROP;
1165 goto next;
1166 }
1167
Damjan Mariona829b132019-04-24 23:39:16 +02001168 if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
1169 {
1170 b[0]->error = node->errors[ESP_DECRYPT_ERROR_RUNT];
1171 next[0] = ESP_DECRYPT_NEXT_DROP;
1172 goto next;
1173 }
1174
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001175 len = pd->current_length - cpd.icv_sz;
1176 current_sa_pkts += 1;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001177 current_sa_bytes += vlib_buffer_length_in_chain (vm, b[0]);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001178
Fan Zhangf5395782020-04-29 14:00:03 +01001179 if (is_async)
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001180 {
Fan Zhangf5395782020-04-29 14:00:03 +01001181 int ret = esp_decrypt_prepare_async_frame (vm, node, ptd,
1182 &async_frame,
1183 sa0, payload, len,
1184 cpd.icv_sz,
1185 cpd.iv_sz,
1186 pd, pd2,
1187 from[b - bufs],
1188 b[0], next, async_next);
1189 if (PREDICT_FALSE (ret < 0))
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001190 {
Fan Zhangf5395782020-04-29 14:00:03 +01001191 esp_async_recycle_failed_submit (async_frame, b, next);
1192 goto next;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001193 }
Damjan Marionc98275f2019-03-06 14:05:01 +01001194 }
Fan Zhangf5395782020-04-29 14:00:03 +01001195 else
1196 esp_decrypt_prepare_sync_op (vm, node, ptd, &crypto_ops, &integ_ops,
1197 op, sa0, payload, len, cpd.icv_sz,
1198 cpd.iv_sz, pd, pd2, b[0], next,
1199 b - bufs);
Damjan Marionc98275f2019-03-06 14:05:01 +01001200 /* next */
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001201 next:
1202 n_left -= 1;
Damjan Marionc98275f2019-03-06 14:05:01 +01001203 next += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001204 pd += 1;
Fan Zhangf5395782020-04-29 14:00:03 +01001205 pd2 += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001206 b += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001207 }
Damjan Marionc98275f2019-03-06 14:05:01 +01001208
Neale Ranns02950402019-12-20 00:54:57 +00001209 if (PREDICT_TRUE (~0 != current_sa_index))
1210 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1211 current_sa_index, current_sa_pkts,
1212 current_sa_bytes);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001213
Fan Zhangf5395782020-04-29 14:00:03 +01001214 if (is_async)
1215 {
1216 if (async_frame && async_frame->n_elts)
1217 {
1218 if (vnet_crypto_async_submit_open_frame (vm, async_frame) < 0)
1219 esp_async_recycle_failed_submit (async_frame, b, next);
1220 }
Neale Ranns92e93842019-04-08 07:36:50 +00001221
Fan Zhangf5395782020-04-29 14:00:03 +01001222 /* no post process in async */
1223 n_left = from_frame->n_vectors;
1224 vlib_node_increment_counter (vm, node->node_index,
1225 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1226 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1227
1228 return n_left;
1229 }
1230 else
1231 {
1232 esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts,
1233 ESP_DECRYPT_ERROR_INTEG_ERROR);
1234 esp_process_chained_ops (vm, node, ptd->chained_integ_ops, bufs, nexts,
1235 ptd->chunks, ESP_DECRYPT_ERROR_INTEG_ERROR);
1236
1237 esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts,
1238 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1239 esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, bufs, nexts,
1240 ptd->chunks,
1241 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1242 }
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001243
1244 /* Post decryption ronud - adjust packet data start and length and next
1245 node */
1246
1247 n_left = from_frame->n_vectors;
1248 next = nexts;
1249 pd = pkt_data;
Fan Zhangf5395782020-04-29 14:00:03 +01001250 pd2 = pkt_data2;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001251 b = bufs;
1252
1253 while (n_left)
1254 {
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001255 if (n_left >= 2)
1256 {
1257 void *data = b[1]->data + pd[1].current_data;
1258
1259 /* buffer metadata */
1260 vlib_prefetch_buffer_header (b[1], LOAD);
1261
1262 /* esp_footer_t */
1263 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
1264 CLIB_CACHE_LINE_BYTES, LOAD);
1265
1266 /* packet headers */
1267 CLIB_PREFETCH (data - CLIB_CACHE_LINE_BYTES,
1268 CLIB_CACHE_LINE_BYTES * 2, LOAD);
1269 }
1270
Christian Hoppsd570e532020-08-25 12:40:40 -04001271 /* save the sa_index as GRE_teb post_crypto changes L2 opaque */
1272 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1273 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1274
Fan Zhangf5395782020-04-29 14:00:03 +01001275 if (next[0] >= ESP_DECRYPT_N_NEXT)
1276 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1277 is_tun, 0);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001278
Fan Zhangf5395782020-04-29 14:00:03 +01001279 /* trace: */
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001280 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1281 {
1282 esp_decrypt_trace_t *tr;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001283 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
Christian Hoppsd570e532020-08-25 12:40:40 -04001284 sa0 = pool_elt_at_index (im->sad, current_sa_index);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001285 tr->crypto_alg = sa0->crypto_alg;
1286 tr->integ_alg = sa0->integ_alg;
Neale Ranns6afaae12019-07-17 15:07:14 +00001287 tr->seq = pd->seq;
1288 tr->sa_seq = sa0->last_seq;
1289 tr->sa_seq_hi = sa0->seq_hi;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001290 }
1291
1292 /* next */
1293 n_left -= 1;
1294 next += 1;
1295 pd += 1;
Fan Zhangf5395782020-04-29 14:00:03 +01001296 pd2 += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001297 b += 1;
1298 }
1299
1300 n_left = from_frame->n_vectors;
1301 vlib_node_increment_counter (vm, node->node_index,
1302 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1303
1304 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1305
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001306 return n_left;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001307}
1308
Fan Zhangf5395782020-04-29 14:00:03 +01001309always_inline uword
1310esp_decrypt_post_inline (vlib_main_t * vm,
1311 vlib_node_runtime_t * node,
1312 vlib_frame_t * from_frame, int is_ip6, int is_tun)
1313{
1314 ipsec_main_t *im = &ipsec_main;
1315 u32 *from = vlib_frame_vector_args (from_frame);
1316 u32 n_left = from_frame->n_vectors;
1317 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1318 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1319 vlib_get_buffers (vm, from, b, n_left);
1320
1321 while (n_left > 0)
1322 {
1323 esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data;
1324
1325 if (n_left > 2)
1326 {
1327 vlib_prefetch_buffer_header (b[2], LOAD);
1328 vlib_prefetch_buffer_header (b[1], LOAD);
1329 }
1330
1331 if (!pd->is_chain)
1332 esp_decrypt_post_crypto (vm, node, pd, 0, b[0], next, is_ip6, is_tun,
1333 1);
1334 else
1335 {
1336 esp_decrypt_packet_data2_t *pd2 = esp_post_data2 (b[0]);
1337 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1338 is_tun, 1);
1339 }
1340
1341 /*trace: */
1342 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1343 {
1344 ipsec_sa_t *sa0 = pool_elt_at_index (im->sad, pd->sa_index);
1345 esp_decrypt_trace_t *tr;
1346 esp_decrypt_packet_data_t *async_pd =
1347 &(esp_post_data (b[0]))->decrypt_data;
1348 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1349 sa0 = pool_elt_at_index (im->sad, async_pd->sa_index);
1350
1351 tr->crypto_alg = sa0->crypto_alg;
1352 tr->integ_alg = sa0->integ_alg;
1353 tr->seq = pd->seq;
1354 tr->sa_seq = sa0->last_seq;
1355 tr->sa_seq_hi = sa0->seq_hi;
1356 }
1357
1358 n_left--;
1359 next++;
1360 b++;
1361 }
1362
1363 n_left = from_frame->n_vectors;
1364 vlib_node_increment_counter (vm, node->node_index,
1365 ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left);
1366
1367 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1368
1369 return n_left;
1370}
1371
Klement Sekerab8f35442018-10-29 13:38:19 +01001372VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm,
1373 vlib_node_runtime_t * node,
1374 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001375{
Fan Zhangf5395782020-04-29 14:00:03 +01001376 return esp_decrypt_inline (vm, node, from_frame, 0, 0,
1377 esp_decrypt_async_next.esp4_post_next);
1378}
1379
1380VLIB_NODE_FN (esp4_decrypt_post_node) (vlib_main_t * vm,
1381 vlib_node_runtime_t * node,
1382 vlib_frame_t * from_frame)
1383{
1384 return esp_decrypt_post_inline (vm, node, from_frame, 0, 0);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001385}
1386
1387VLIB_NODE_FN (esp4_decrypt_tun_node) (vlib_main_t * vm,
1388 vlib_node_runtime_t * node,
1389 vlib_frame_t * from_frame)
1390{
Fan Zhangf5395782020-04-29 14:00:03 +01001391 return esp_decrypt_inline (vm, node, from_frame, 0, 1,
1392 esp_decrypt_async_next.esp4_tun_post_next);
1393}
1394
1395VLIB_NODE_FN (esp4_decrypt_tun_post_node) (vlib_main_t * vm,
1396 vlib_node_runtime_t * node,
1397 vlib_frame_t * from_frame)
1398{
1399 return esp_decrypt_post_inline (vm, node, from_frame, 0, 1);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001400}
1401
1402VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm,
1403 vlib_node_runtime_t * node,
1404 vlib_frame_t * from_frame)
1405{
Fan Zhangf5395782020-04-29 14:00:03 +01001406 return esp_decrypt_inline (vm, node, from_frame, 1, 0,
1407 esp_decrypt_async_next.esp6_post_next);
1408}
1409
1410VLIB_NODE_FN (esp6_decrypt_post_node) (vlib_main_t * vm,
1411 vlib_node_runtime_t * node,
1412 vlib_frame_t * from_frame)
1413{
1414 return esp_decrypt_post_inline (vm, node, from_frame, 1, 0);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001415}
1416
1417VLIB_NODE_FN (esp6_decrypt_tun_node) (vlib_main_t * vm,
1418 vlib_node_runtime_t * node,
1419 vlib_frame_t * from_frame)
1420{
Fan Zhangf5395782020-04-29 14:00:03 +01001421 return esp_decrypt_inline (vm, node, from_frame, 1, 1,
1422 esp_decrypt_async_next.esp6_tun_post_next);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001423}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424
Fan Zhangf5395782020-04-29 14:00:03 +01001425VLIB_NODE_FN (esp6_decrypt_tun_post_node) (vlib_main_t * vm,
1426 vlib_node_runtime_t * node,
1427 vlib_frame_t * from_frame)
1428{
1429 return esp_decrypt_post_inline (vm, node, from_frame, 1, 1);
1430}
1431
1432VLIB_NODE_FN (esp_decrypt_pending_node) (vlib_main_t * vm,
1433 vlib_node_runtime_t * node,
1434 vlib_frame_t * from_frame)
1435{
1436 return from_frame->n_vectors;
1437}
1438
1439/* *INDENT-OFF* */
1440VLIB_REGISTER_NODE (esp_decrypt_pending_node) = {
1441 .name = "esp-decrypt-pending",
1442 .vector_size = sizeof (u32),
1443 .type = VLIB_NODE_TYPE_INTERNAL,
1444
1445 .n_next_nodes = 0
1446};
1447/* *INDENT-ON* */
1448
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001449/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001450VLIB_REGISTER_NODE (esp4_decrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001451 .name = "esp4-decrypt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001452 .vector_size = sizeof (u32),
1453 .format_trace = format_esp_decrypt_trace,
1454 .type = VLIB_NODE_TYPE_INTERNAL,
1455
1456 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1457 .error_strings = esp_decrypt_error_strings,
1458
1459 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1460 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +00001461 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1462 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1463 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001464 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Rannsf62a8c02019-04-02 08:13:33 +00001465 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001466 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Ed Warnickecb9cada2015-12-08 15:45:58 -07001467 },
1468};
1469
Fan Zhangf5395782020-04-29 14:00:03 +01001470VLIB_REGISTER_NODE (esp4_decrypt_post_node) = {
1471 .name = "esp4-decrypt-post",
1472 .vector_size = sizeof (u32),
1473 .format_trace = format_esp_decrypt_trace,
1474 .type = VLIB_NODE_TYPE_INTERNAL,
1475
1476 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1477 .error_strings = esp_decrypt_error_strings,
1478
1479 .sibling_of = "esp4-decrypt",
1480};
1481
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001482VLIB_REGISTER_NODE (esp6_decrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001483 .name = "esp6-decrypt",
1484 .vector_size = sizeof (u32),
1485 .format_trace = format_esp_decrypt_trace,
1486 .type = VLIB_NODE_TYPE_INTERNAL,
1487
1488 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1489 .error_strings = esp_decrypt_error_strings,
1490
1491 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1492 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +00001493 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1494 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1495 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001496 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Rannsf62a8c02019-04-02 08:13:33 +00001497 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001498 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001499 },
1500};
Neale Rannsc87b66c2019-02-07 07:26:12 -08001501
Fan Zhangf5395782020-04-29 14:00:03 +01001502VLIB_REGISTER_NODE (esp6_decrypt_post_node) = {
1503 .name = "esp6-decrypt-post",
1504 .vector_size = sizeof (u32),
1505 .format_trace = format_esp_decrypt_trace,
1506 .type = VLIB_NODE_TYPE_INTERNAL,
1507
1508 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1509 .error_strings = esp_decrypt_error_strings,
1510
1511 .sibling_of = "esp6-decrypt",
1512};
1513
Neale Rannsc87b66c2019-02-07 07:26:12 -08001514VLIB_REGISTER_NODE (esp4_decrypt_tun_node) = {
1515 .name = "esp4-decrypt-tun",
1516 .vector_size = sizeof (u32),
1517 .format_trace = format_esp_decrypt_trace,
1518 .type = VLIB_NODE_TYPE_INTERNAL,
Neale Rannsc87b66c2019-02-07 07:26:12 -08001519 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1520 .error_strings = esp_decrypt_error_strings,
Neale Rannsf62a8c02019-04-02 08:13:33 +00001521 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1522 .next_nodes = {
1523 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1524 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1525 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001526 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Ranns4a56f4e2019-12-23 04:10:25 +00001527 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001528 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Neale Rannsf62a8c02019-04-02 08:13:33 +00001529 },
Neale Rannsc87b66c2019-02-07 07:26:12 -08001530};
1531
Fan Zhangf5395782020-04-29 14:00:03 +01001532VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node) = {
1533 .name = "esp4-decrypt-tun-post",
1534 .vector_size = sizeof (u32),
1535 .format_trace = format_esp_decrypt_trace,
1536 .type = VLIB_NODE_TYPE_INTERNAL,
1537
1538 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1539 .error_strings = esp_decrypt_error_strings,
1540
1541 .sibling_of = "esp4-decrypt-tun",
1542};
1543
Neale Rannsc87b66c2019-02-07 07:26:12 -08001544VLIB_REGISTER_NODE (esp6_decrypt_tun_node) = {
1545 .name = "esp6-decrypt-tun",
1546 .vector_size = sizeof (u32),
1547 .format_trace = format_esp_decrypt_trace,
1548 .type = VLIB_NODE_TYPE_INTERNAL,
Neale Rannsc87b66c2019-02-07 07:26:12 -08001549 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1550 .error_strings = esp_decrypt_error_strings,
Neale Rannsf62a8c02019-04-02 08:13:33 +00001551 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1552 .next_nodes = {
1553 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1554 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1555 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001556 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Ranns4a56f4e2019-12-23 04:10:25 +00001557 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001558 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Neale Rannsf62a8c02019-04-02 08:13:33 +00001559 },
Neale Rannsc87b66c2019-02-07 07:26:12 -08001560};
Fan Zhangf5395782020-04-29 14:00:03 +01001561
1562VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node) = {
1563 .name = "esp6-decrypt-tun-post",
1564 .vector_size = sizeof (u32),
1565 .format_trace = format_esp_decrypt_trace,
1566 .type = VLIB_NODE_TYPE_INTERNAL,
1567
1568 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1569 .error_strings = esp_decrypt_error_strings,
1570
1571 .sibling_of = "esp6-decrypt-tun",
1572};
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001573/* *INDENT-ON* */
1574
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001575/*
1576 * fd.io coding-style-patch-verification: ON
1577 *
1578 * Local Variables:
1579 * eval: (c-set-style "gnu")
1580 * End:
1581 */