blob: 75092cc9581763fa303bc9515d667500da822506 [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);
Damjan Marion7c22ff72019-04-04 12:25:44 +02001099 cpd.icv_sz = sa0->integ_icv_size;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001100 cpd.iv_sz = sa0->crypto_iv_size;
1101 cpd.flags = sa0->flags;
1102 cpd.sa_index = current_sa_index;
Fan Zhangf5395782020-04-29 14:00:03 +01001103
1104 /* submit frame when op_id is different then the old one */
1105 if (is_async && last_async_op != sa0->crypto_async_dec_op_id)
1106 {
1107 if (async_frame && async_frame->n_elts)
1108 {
1109 if (vnet_crypto_async_submit_open_frame (vm, async_frame))
1110 esp_async_recycle_failed_submit (async_frame, b, next);
1111 }
1112 async_frame =
1113 vnet_crypto_async_get_frame (vm, sa0->crypto_async_dec_op_id);
1114 last_async_op = sa0->crypto_async_dec_op_id;
1115 }
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001116 }
1117
Neale Rannsf62a8c02019-04-02 08:13:33 +00001118 if (PREDICT_FALSE (~0 == sa0->decrypt_thread_index))
1119 {
1120 /* this is the first packet to use this SA, claim the SA
1121 * for this thread. this could happen simultaneously on
1122 * another thread */
1123 clib_atomic_cmp_and_swap (&sa0->decrypt_thread_index, ~0,
1124 ipsec_sa_assign_thread (thread_index));
1125 }
1126
1127 if (PREDICT_TRUE (thread_index != sa0->decrypt_thread_index))
1128 {
1129 next[0] = ESP_DECRYPT_NEXT_HANDOFF;
1130 goto next;
1131 }
1132
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001133 /* store packet data for next round for easier prefetch */
1134 pd->sa_data = cpd.sa_data;
1135 pd->current_data = b[0]->current_data;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001136 pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset;
1137 payload = b[0]->data + pd->current_data;
Neale Ranns6afaae12019-07-17 15:07:14 +00001138 pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq);
Fan Zhangf5395782020-04-29 14:00:03 +01001139 pd->is_chain = 0;
1140 pd2->lb = b[0];
1141 pd2->free_buffer_index = 0;
1142 pd2->icv_removed = 0;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001143
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001144 if (n_bufs > 1)
1145 {
Fan Zhangf5395782020-04-29 14:00:03 +01001146 pd->is_chain = 1;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001147 /* find last buffer in the chain */
Fan Zhangf5395782020-04-29 14:00:03 +01001148 while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT)
1149 pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer);
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001150
1151 crypto_ops = &ptd->chained_crypto_ops;
1152 integ_ops = &ptd->chained_integ_ops;
1153 }
Fan Zhangf5395782020-04-29 14:00:03 +01001154
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001155 pd->current_length = b[0]->current_length;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001156
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001157 /* anti-reply check */
Neale Ranns6afaae12019-07-17 15:07:14 +00001158 if (ipsec_sa_anti_replay_check (sa0, pd->seq))
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001159 {
1160 b[0]->error = node->errors[ESP_DECRYPT_ERROR_REPLAY];
1161 next[0] = ESP_DECRYPT_NEXT_DROP;
1162 goto next;
1163 }
1164
Damjan Mariona829b132019-04-24 23:39:16 +02001165 if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz)
1166 {
1167 b[0]->error = node->errors[ESP_DECRYPT_ERROR_RUNT];
1168 next[0] = ESP_DECRYPT_NEXT_DROP;
1169 goto next;
1170 }
1171
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001172 len = pd->current_length - cpd.icv_sz;
1173 current_sa_pkts += 1;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001174 current_sa_bytes += vlib_buffer_length_in_chain (vm, b[0]);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001175
Fan Zhangf5395782020-04-29 14:00:03 +01001176 if (is_async)
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001177 {
Fan Zhangf5395782020-04-29 14:00:03 +01001178 int ret = esp_decrypt_prepare_async_frame (vm, node, ptd,
1179 &async_frame,
1180 sa0, payload, len,
1181 cpd.icv_sz,
1182 cpd.iv_sz,
1183 pd, pd2,
1184 from[b - bufs],
1185 b[0], next, async_next);
1186 if (PREDICT_FALSE (ret < 0))
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001187 {
Fan Zhangf5395782020-04-29 14:00:03 +01001188 esp_async_recycle_failed_submit (async_frame, b, next);
1189 goto next;
Filip Tehlarefcad1a2020-02-04 09:36:04 +00001190 }
Damjan Marionc98275f2019-03-06 14:05:01 +01001191 }
Fan Zhangf5395782020-04-29 14:00:03 +01001192 else
1193 esp_decrypt_prepare_sync_op (vm, node, ptd, &crypto_ops, &integ_ops,
1194 op, sa0, payload, len, cpd.icv_sz,
1195 cpd.iv_sz, pd, pd2, b[0], next,
1196 b - bufs);
Damjan Marionc98275f2019-03-06 14:05:01 +01001197 /* next */
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001198 next:
1199 n_left -= 1;
Damjan Marionc98275f2019-03-06 14:05:01 +01001200 next += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001201 pd += 1;
Fan Zhangf5395782020-04-29 14:00:03 +01001202 pd2 += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001203 b += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001204 }
Damjan Marionc98275f2019-03-06 14:05:01 +01001205
Neale Ranns02950402019-12-20 00:54:57 +00001206 if (PREDICT_TRUE (~0 != current_sa_index))
1207 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
1208 current_sa_index, current_sa_pkts,
1209 current_sa_bytes);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001210
Fan Zhangf5395782020-04-29 14:00:03 +01001211 if (is_async)
1212 {
1213 if (async_frame && async_frame->n_elts)
1214 {
1215 if (vnet_crypto_async_submit_open_frame (vm, async_frame) < 0)
1216 esp_async_recycle_failed_submit (async_frame, b, next);
1217 }
Neale Ranns92e93842019-04-08 07:36:50 +00001218
Fan Zhangf5395782020-04-29 14:00:03 +01001219 /* no post process in async */
1220 n_left = from_frame->n_vectors;
1221 vlib_node_increment_counter (vm, node->node_index,
1222 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1223 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1224
1225 return n_left;
1226 }
1227 else
1228 {
1229 esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts,
1230 ESP_DECRYPT_ERROR_INTEG_ERROR);
1231 esp_process_chained_ops (vm, node, ptd->chained_integ_ops, bufs, nexts,
1232 ptd->chunks, ESP_DECRYPT_ERROR_INTEG_ERROR);
1233
1234 esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts,
1235 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1236 esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, bufs, nexts,
1237 ptd->chunks,
1238 ESP_DECRYPT_ERROR_DECRYPTION_FAILED);
1239 }
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001240
1241 /* Post decryption ronud - adjust packet data start and length and next
1242 node */
1243
1244 n_left = from_frame->n_vectors;
1245 next = nexts;
1246 pd = pkt_data;
Fan Zhangf5395782020-04-29 14:00:03 +01001247 pd2 = pkt_data2;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001248 b = bufs;
1249
1250 while (n_left)
1251 {
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001252 if (n_left >= 2)
1253 {
1254 void *data = b[1]->data + pd[1].current_data;
1255
1256 /* buffer metadata */
1257 vlib_prefetch_buffer_header (b[1], LOAD);
1258
1259 /* esp_footer_t */
1260 CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2,
1261 CLIB_CACHE_LINE_BYTES, LOAD);
1262
1263 /* packet headers */
1264 CLIB_PREFETCH (data - CLIB_CACHE_LINE_BYTES,
1265 CLIB_CACHE_LINE_BYTES * 2, LOAD);
1266 }
1267
Christian Hoppsd570e532020-08-25 12:40:40 -04001268 /* save the sa_index as GRE_teb post_crypto changes L2 opaque */
1269 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1270 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
1271
Fan Zhangf5395782020-04-29 14:00:03 +01001272 if (next[0] >= ESP_DECRYPT_N_NEXT)
1273 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1274 is_tun, 0);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001275
Fan Zhangf5395782020-04-29 14:00:03 +01001276 /* trace: */
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001277 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1278 {
1279 esp_decrypt_trace_t *tr;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001280 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
Christian Hoppsd570e532020-08-25 12:40:40 -04001281 sa0 = pool_elt_at_index (im->sad, current_sa_index);
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001282 tr->crypto_alg = sa0->crypto_alg;
1283 tr->integ_alg = sa0->integ_alg;
Neale Ranns6afaae12019-07-17 15:07:14 +00001284 tr->seq = pd->seq;
1285 tr->sa_seq = sa0->last_seq;
1286 tr->sa_seq_hi = sa0->seq_hi;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001287 }
1288
1289 /* next */
1290 n_left -= 1;
1291 next += 1;
1292 pd += 1;
Fan Zhangf5395782020-04-29 14:00:03 +01001293 pd2 += 1;
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001294 b += 1;
1295 }
1296
1297 n_left = from_frame->n_vectors;
1298 vlib_node_increment_counter (vm, node->node_index,
1299 ESP_DECRYPT_ERROR_RX_PKTS, n_left);
1300
1301 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1302
Damjan Marionb4fff3a2019-03-25 15:54:40 +01001303 return n_left;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001304}
1305
Fan Zhangf5395782020-04-29 14:00:03 +01001306always_inline uword
1307esp_decrypt_post_inline (vlib_main_t * vm,
1308 vlib_node_runtime_t * node,
1309 vlib_frame_t * from_frame, int is_ip6, int is_tun)
1310{
1311 ipsec_main_t *im = &ipsec_main;
1312 u32 *from = vlib_frame_vector_args (from_frame);
1313 u32 n_left = from_frame->n_vectors;
1314 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1315 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1316 vlib_get_buffers (vm, from, b, n_left);
1317
1318 while (n_left > 0)
1319 {
1320 esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data;
1321
1322 if (n_left > 2)
1323 {
1324 vlib_prefetch_buffer_header (b[2], LOAD);
1325 vlib_prefetch_buffer_header (b[1], LOAD);
1326 }
1327
1328 if (!pd->is_chain)
1329 esp_decrypt_post_crypto (vm, node, pd, 0, b[0], next, is_ip6, is_tun,
1330 1);
1331 else
1332 {
1333 esp_decrypt_packet_data2_t *pd2 = esp_post_data2 (b[0]);
1334 esp_decrypt_post_crypto (vm, node, pd, pd2, b[0], next, is_ip6,
1335 is_tun, 1);
1336 }
1337
1338 /*trace: */
1339 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
1340 {
1341 ipsec_sa_t *sa0 = pool_elt_at_index (im->sad, pd->sa_index);
1342 esp_decrypt_trace_t *tr;
1343 esp_decrypt_packet_data_t *async_pd =
1344 &(esp_post_data (b[0]))->decrypt_data;
1345 tr = vlib_add_trace (vm, node, b[0], sizeof (*tr));
1346 sa0 = pool_elt_at_index (im->sad, async_pd->sa_index);
1347
1348 tr->crypto_alg = sa0->crypto_alg;
1349 tr->integ_alg = sa0->integ_alg;
1350 tr->seq = pd->seq;
1351 tr->sa_seq = sa0->last_seq;
1352 tr->sa_seq_hi = sa0->seq_hi;
1353 }
1354
1355 n_left--;
1356 next++;
1357 b++;
1358 }
1359
1360 n_left = from_frame->n_vectors;
1361 vlib_node_increment_counter (vm, node->node_index,
1362 ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left);
1363
1364 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
1365
1366 return n_left;
1367}
1368
Klement Sekerab8f35442018-10-29 13:38:19 +01001369VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm,
1370 vlib_node_runtime_t * node,
1371 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001372{
Fan Zhangf5395782020-04-29 14:00:03 +01001373 return esp_decrypt_inline (vm, node, from_frame, 0, 0,
1374 esp_decrypt_async_next.esp4_post_next);
1375}
1376
1377VLIB_NODE_FN (esp4_decrypt_post_node) (vlib_main_t * vm,
1378 vlib_node_runtime_t * node,
1379 vlib_frame_t * from_frame)
1380{
1381 return esp_decrypt_post_inline (vm, node, from_frame, 0, 0);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001382}
1383
1384VLIB_NODE_FN (esp4_decrypt_tun_node) (vlib_main_t * vm,
1385 vlib_node_runtime_t * node,
1386 vlib_frame_t * from_frame)
1387{
Fan Zhangf5395782020-04-29 14:00:03 +01001388 return esp_decrypt_inline (vm, node, from_frame, 0, 1,
1389 esp_decrypt_async_next.esp4_tun_post_next);
1390}
1391
1392VLIB_NODE_FN (esp4_decrypt_tun_post_node) (vlib_main_t * vm,
1393 vlib_node_runtime_t * node,
1394 vlib_frame_t * from_frame)
1395{
1396 return esp_decrypt_post_inline (vm, node, from_frame, 0, 1);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001397}
1398
1399VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm,
1400 vlib_node_runtime_t * node,
1401 vlib_frame_t * from_frame)
1402{
Fan Zhangf5395782020-04-29 14:00:03 +01001403 return esp_decrypt_inline (vm, node, from_frame, 1, 0,
1404 esp_decrypt_async_next.esp6_post_next);
1405}
1406
1407VLIB_NODE_FN (esp6_decrypt_post_node) (vlib_main_t * vm,
1408 vlib_node_runtime_t * node,
1409 vlib_frame_t * from_frame)
1410{
1411 return esp_decrypt_post_inline (vm, node, from_frame, 1, 0);
Neale Rannsc87b66c2019-02-07 07:26:12 -08001412}
1413
1414VLIB_NODE_FN (esp6_decrypt_tun_node) (vlib_main_t * vm,
1415 vlib_node_runtime_t * node,
1416 vlib_frame_t * from_frame)
1417{
Fan Zhangf5395782020-04-29 14:00:03 +01001418 return esp_decrypt_inline (vm, node, from_frame, 1, 1,
1419 esp_decrypt_async_next.esp6_tun_post_next);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001420}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001421
Fan Zhangf5395782020-04-29 14:00:03 +01001422VLIB_NODE_FN (esp6_decrypt_tun_post_node) (vlib_main_t * vm,
1423 vlib_node_runtime_t * node,
1424 vlib_frame_t * from_frame)
1425{
1426 return esp_decrypt_post_inline (vm, node, from_frame, 1, 1);
1427}
1428
1429VLIB_NODE_FN (esp_decrypt_pending_node) (vlib_main_t * vm,
1430 vlib_node_runtime_t * node,
1431 vlib_frame_t * from_frame)
1432{
1433 return from_frame->n_vectors;
1434}
1435
1436/* *INDENT-OFF* */
1437VLIB_REGISTER_NODE (esp_decrypt_pending_node) = {
1438 .name = "esp-decrypt-pending",
1439 .vector_size = sizeof (u32),
1440 .type = VLIB_NODE_TYPE_INTERNAL,
1441
1442 .n_next_nodes = 0
1443};
1444/* *INDENT-ON* */
1445
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001446/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001447VLIB_REGISTER_NODE (esp4_decrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001448 .name = "esp4-decrypt",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001449 .vector_size = sizeof (u32),
1450 .format_trace = format_esp_decrypt_trace,
1451 .type = VLIB_NODE_TYPE_INTERNAL,
1452
1453 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1454 .error_strings = esp_decrypt_error_strings,
1455
1456 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1457 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +00001458 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1459 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1460 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001461 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Rannsf62a8c02019-04-02 08:13:33 +00001462 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001463 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464 },
1465};
1466
Fan Zhangf5395782020-04-29 14:00:03 +01001467VLIB_REGISTER_NODE (esp4_decrypt_post_node) = {
1468 .name = "esp4-decrypt-post",
1469 .vector_size = sizeof (u32),
1470 .format_trace = format_esp_decrypt_trace,
1471 .type = VLIB_NODE_TYPE_INTERNAL,
1472
1473 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1474 .error_strings = esp_decrypt_error_strings,
1475
1476 .sibling_of = "esp4-decrypt",
1477};
1478
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001479VLIB_REGISTER_NODE (esp6_decrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001480 .name = "esp6-decrypt",
1481 .vector_size = sizeof (u32),
1482 .format_trace = format_esp_decrypt_trace,
1483 .type = VLIB_NODE_TYPE_INTERNAL,
1484
1485 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1486 .error_strings = esp_decrypt_error_strings,
1487
1488 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1489 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +00001490 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1491 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1492 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001493 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Rannsf62a8c02019-04-02 08:13:33 +00001494 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001495 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001496 },
1497};
Neale Rannsc87b66c2019-02-07 07:26:12 -08001498
Fan Zhangf5395782020-04-29 14:00:03 +01001499VLIB_REGISTER_NODE (esp6_decrypt_post_node) = {
1500 .name = "esp6-decrypt-post",
1501 .vector_size = sizeof (u32),
1502 .format_trace = format_esp_decrypt_trace,
1503 .type = VLIB_NODE_TYPE_INTERNAL,
1504
1505 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1506 .error_strings = esp_decrypt_error_strings,
1507
1508 .sibling_of = "esp6-decrypt",
1509};
1510
Neale Rannsc87b66c2019-02-07 07:26:12 -08001511VLIB_REGISTER_NODE (esp4_decrypt_tun_node) = {
1512 .name = "esp4-decrypt-tun",
1513 .vector_size = sizeof (u32),
1514 .format_trace = format_esp_decrypt_trace,
1515 .type = VLIB_NODE_TYPE_INTERNAL,
Neale Rannsc87b66c2019-02-07 07:26:12 -08001516 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1517 .error_strings = esp_decrypt_error_strings,
Neale Rannsf62a8c02019-04-02 08:13:33 +00001518 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1519 .next_nodes = {
1520 [ESP_DECRYPT_NEXT_DROP] = "ip4-drop",
1521 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1522 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001523 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Ranns4a56f4e2019-12-23 04:10:25 +00001524 [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001525 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Neale Rannsf62a8c02019-04-02 08:13:33 +00001526 },
Neale Rannsc87b66c2019-02-07 07:26:12 -08001527};
1528
Fan Zhangf5395782020-04-29 14:00:03 +01001529VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node) = {
1530 .name = "esp4-decrypt-tun-post",
1531 .vector_size = sizeof (u32),
1532 .format_trace = format_esp_decrypt_trace,
1533 .type = VLIB_NODE_TYPE_INTERNAL,
1534
1535 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1536 .error_strings = esp_decrypt_error_strings,
1537
1538 .sibling_of = "esp4-decrypt-tun",
1539};
1540
Neale Rannsc87b66c2019-02-07 07:26:12 -08001541VLIB_REGISTER_NODE (esp6_decrypt_tun_node) = {
1542 .name = "esp6-decrypt-tun",
1543 .vector_size = sizeof (u32),
1544 .format_trace = format_esp_decrypt_trace,
1545 .type = VLIB_NODE_TYPE_INTERNAL,
Neale Rannsc87b66c2019-02-07 07:26:12 -08001546 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1547 .error_strings = esp_decrypt_error_strings,
Neale Rannsf62a8c02019-04-02 08:13:33 +00001548 .n_next_nodes = ESP_DECRYPT_N_NEXT,
1549 .next_nodes = {
1550 [ESP_DECRYPT_NEXT_DROP] = "ip6-drop",
1551 [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
1552 [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input",
Neale Ranns568acbb2019-12-18 05:54:40 +00001553 [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input",
Neale Ranns4a56f4e2019-12-23 04:10:25 +00001554 [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff",
Fan Zhangf5395782020-04-29 14:00:03 +01001555 [ESP_DECRYPT_NEXT_PENDING] = "esp-decrypt-pending"
Neale Rannsf62a8c02019-04-02 08:13:33 +00001556 },
Neale Rannsc87b66c2019-02-07 07:26:12 -08001557};
Fan Zhangf5395782020-04-29 14:00:03 +01001558
1559VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node) = {
1560 .name = "esp6-decrypt-tun-post",
1561 .vector_size = sizeof (u32),
1562 .format_trace = format_esp_decrypt_trace,
1563 .type = VLIB_NODE_TYPE_INTERNAL,
1564
1565 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
1566 .error_strings = esp_decrypt_error_strings,
1567
1568 .sibling_of = "esp6-decrypt-tun",
1569};
Klement Sekerabe5a5dd2018-10-09 16:05:48 +02001570/* *INDENT-ON* */
1571
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -07001572/*
1573 * fd.io coding-style-patch-verification: ON
1574 *
1575 * Local Variables:
1576 * eval: (c-set-style "gnu")
1577 * End:
1578 */