Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 17 | #include <vnet/vnet.h> |
| 18 | #include <vnet/api_errno.h> |
| 19 | #include <vnet/ip/ip.h> |
John Lo | 90430b6 | 2020-01-31 23:48:30 -0500 | [diff] [blame] | 20 | #include <vnet/l2/l2_input.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | |
| 22 | #include <vnet/ipsec/ipsec.h> |
| 23 | #include <vnet/ipsec/esp.h> |
Neale Ranns | 918c161 | 2019-02-21 23:34:59 -0800 | [diff] [blame] | 24 | #include <vnet/ipsec/ipsec_io.h> |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 25 | #include <vnet/ipsec/ipsec_tun.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | |
Neale Ranns | 119c0d7 | 2020-11-26 13:12:37 +0000 | [diff] [blame] | 27 | #include <vnet/gre/packet.h> |
Neale Ranns | 568acbb | 2019-12-18 05:54:40 +0000 | [diff] [blame] | 28 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 29 | #define foreach_esp_decrypt_next \ |
| 30 | _ (DROP, "error-drop") \ |
| 31 | _ (IP4_INPUT, "ip4-input-no-checksum") \ |
| 32 | _ (IP6_INPUT, "ip6-input") \ |
| 33 | _ (L2_INPUT, "l2-input") \ |
| 34 | _ (MPLS_INPUT, "mpls-input") \ |
| 35 | _ (HANDOFF, "handoff") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | |
| 37 | #define _(v, s) ESP_DECRYPT_NEXT_##v, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 38 | typedef enum |
| 39 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | foreach_esp_decrypt_next |
| 41 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 42 | ESP_DECRYPT_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | } esp_decrypt_next_t; |
| 44 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 45 | #define foreach_esp_decrypt_post_next \ |
| 46 | _ (DROP, "error-drop") \ |
| 47 | _ (IP4_INPUT, "ip4-input-no-checksum") \ |
| 48 | _ (IP6_INPUT, "ip6-input") \ |
| 49 | _ (MPLS_INPUT, "mpls-input") \ |
| 50 | _ (L2_INPUT, "l2-input") |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 51 | |
| 52 | #define _(v, s) ESP_DECRYPT_POST_NEXT_##v, |
| 53 | typedef enum |
| 54 | { |
| 55 | foreach_esp_decrypt_post_next |
| 56 | #undef _ |
| 57 | ESP_DECRYPT_POST_N_NEXT, |
| 58 | } esp_decrypt_post_next_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 60 | #define foreach_esp_decrypt_error \ |
| 61 | _ (RX_PKTS, "ESP pkts received") \ |
| 62 | _ (RX_POST_PKTS, "ESP-POST pkts received") \ |
| 63 | _ (HANDOFF, "hand-off") \ |
| 64 | _ (DECRYPTION_FAILED, "ESP decryption failed") \ |
| 65 | _ (INTEG_ERROR, "Integrity check failed") \ |
| 66 | _ (CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \ |
| 67 | _ (REPLAY, "SA replayed packet") \ |
| 68 | _ (RUNT, "undersized packet") \ |
| 69 | _ (NO_BUFFERS, "no buffers (packet dropped)") \ |
| 70 | _ (OVERSIZED_HEADER, "buffer with oversized header (dropped)") \ |
| 71 | _ (NO_TAIL_SPACE, "no enough buffer tail space (dropped)") \ |
| 72 | _ (TUN_NO_PROTO, "no tunnel protocol") \ |
| 73 | _ (UNSUP_PAYLOAD, "unsupported payload") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 74 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 75 | typedef enum |
| 76 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | #define _(sym,str) ESP_DECRYPT_ERROR_##sym, |
| 78 | foreach_esp_decrypt_error |
| 79 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 80 | ESP_DECRYPT_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | } esp_decrypt_error_t; |
| 82 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 83 | static char *esp_decrypt_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | #define _(sym,string) string, |
| 85 | foreach_esp_decrypt_error |
| 86 | #undef _ |
| 87 | }; |
| 88 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 89 | typedef struct |
| 90 | { |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 91 | u32 seq; |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 92 | u32 sa_seq; |
| 93 | u32 sa_seq_hi; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 94 | u32 pkt_seq_hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | ipsec_crypto_alg_t crypto_alg; |
| 96 | ipsec_integ_alg_t integ_alg; |
| 97 | } esp_decrypt_trace_t; |
| 98 | |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 99 | /* The number of byres in the hisequence number */ |
| 100 | #define N_HI_ESN_BYTES 4 |
| 101 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | /* packet trace format function */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 103 | static u8 * |
| 104 | format_esp_decrypt_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | { |
| 106 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 107 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 108 | esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 110 | s = format (s, |
| 111 | "esp: crypto %U integrity %U pkt-seq %d sa-seq %u sa-seq-hi %u " |
| 112 | "pkt-seq-hi %u", |
| 113 | format_ipsec_crypto_alg, t->crypto_alg, format_ipsec_integ_alg, |
| 114 | t->integ_alg, t->seq, t->sa_seq, t->sa_seq_hi, t->pkt_seq_hi); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | return s; |
| 116 | } |
| 117 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 118 | #define ESP_ENCRYPT_PD_F_FD_TRANSPORT (1 << 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 120 | static_always_inline void |
| 121 | esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 122 | vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts, |
| 123 | int e) |
| 124 | { |
| 125 | vnet_crypto_op_t *op = ops; |
| 126 | u32 n_fail, n_ops = vec_len (ops); |
| 127 | |
| 128 | if (n_ops == 0) |
| 129 | return; |
| 130 | |
| 131 | n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops); |
| 132 | |
| 133 | while (n_fail) |
| 134 | { |
| 135 | ASSERT (op - ops < n_ops); |
| 136 | if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED) |
| 137 | { |
| 138 | u32 err, bi = op->user_data; |
| 139 | if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC) |
| 140 | err = e; |
| 141 | else |
| 142 | err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR; |
| 143 | b[bi]->error = node->errors[err]; |
| 144 | nexts[bi] = ESP_DECRYPT_NEXT_DROP; |
| 145 | n_fail--; |
| 146 | } |
| 147 | op++; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | static_always_inline void |
| 152 | esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 153 | vnet_crypto_op_t * ops, vlib_buffer_t * b[], |
| 154 | u16 * nexts, vnet_crypto_op_chunk_t * chunks, int e) |
| 155 | { |
| 156 | |
| 157 | vnet_crypto_op_t *op = ops; |
| 158 | u32 n_fail, n_ops = vec_len (ops); |
| 159 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 160 | if (PREDICT_TRUE (n_ops == 0)) |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 161 | return; |
| 162 | |
| 163 | n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops); |
| 164 | |
| 165 | while (n_fail) |
| 166 | { |
| 167 | ASSERT (op - ops < n_ops); |
| 168 | if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED) |
| 169 | { |
| 170 | u32 err, bi = op->user_data; |
| 171 | if (op->status == VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC) |
| 172 | err = e; |
| 173 | else |
| 174 | err = ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR; |
| 175 | b[bi]->error = node->errors[err]; |
| 176 | nexts[bi] = ESP_DECRYPT_NEXT_DROP; |
| 177 | n_fail--; |
| 178 | } |
| 179 | op++; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | always_inline void |
| 184 | esp_remove_tail (vlib_main_t * vm, vlib_buffer_t * b, vlib_buffer_t * last, |
| 185 | u16 tail) |
| 186 | { |
| 187 | vlib_buffer_t *before_last = b; |
| 188 | |
| 189 | if (last->current_length > tail) |
| 190 | { |
| 191 | last->current_length -= tail; |
| 192 | return; |
| 193 | } |
| 194 | ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 195 | |
| 196 | while (b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 197 | { |
| 198 | before_last = b; |
| 199 | b = vlib_get_buffer (vm, b->next_buffer); |
| 200 | } |
| 201 | before_last->current_length -= tail - last->current_length; |
| 202 | vlib_buffer_free_one (vm, before_last->next_buffer); |
| 203 | before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 204 | } |
| 205 | |
| 206 | /* ICV is splitted in last two buffers so move it to the last buffer and |
| 207 | return pointer to it */ |
| 208 | static_always_inline u8 * |
| 209 | esp_move_icv (vlib_main_t * vm, vlib_buffer_t * first, |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 210 | esp_decrypt_packet_data_t * pd, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 211 | esp_decrypt_packet_data2_t * pd2, u16 icv_sz, u16 * dif) |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 212 | { |
| 213 | vlib_buffer_t *before_last, *bp; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 214 | u16 last_sz = pd2->lb->current_length; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 215 | u16 first_sz = icv_sz - last_sz; |
| 216 | |
| 217 | bp = before_last = first; |
| 218 | while (bp->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 219 | { |
| 220 | before_last = bp; |
| 221 | bp = vlib_get_buffer (vm, bp->next_buffer); |
| 222 | } |
| 223 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 224 | u8 *lb_curr = vlib_buffer_get_current (pd2->lb); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 225 | memmove (lb_curr + first_sz, lb_curr, last_sz); |
| 226 | clib_memcpy_fast (lb_curr, vlib_buffer_get_tail (before_last) - first_sz, |
| 227 | first_sz); |
| 228 | before_last->current_length -= first_sz; |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 229 | if (before_last == first) |
| 230 | pd->current_length -= first_sz; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 231 | clib_memset (vlib_buffer_get_tail (before_last), 0, first_sz); |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 232 | if (dif) |
| 233 | dif[0] = first_sz; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 234 | pd2->lb = before_last; |
| 235 | pd2->icv_removed = 1; |
| 236 | pd2->free_buffer_index = before_last->next_buffer; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 237 | before_last->flags &= ~VLIB_BUFFER_NEXT_PRESENT; |
| 238 | return lb_curr; |
| 239 | } |
| 240 | |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 241 | static_always_inline u16 |
| 242 | esp_insert_esn (vlib_main_t *vm, ipsec_sa_t *sa, esp_decrypt_packet_data_t *pd, |
| 243 | esp_decrypt_packet_data2_t *pd2, u32 *data_len, u8 **digest, |
| 244 | u16 *len, vlib_buffer_t *b, u8 *payload) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 245 | { |
| 246 | if (!ipsec_sa_is_set_USE_ESN (sa)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 247 | return 0; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 248 | /* shift ICV by 4 bytes to insert ESN */ |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 249 | u32 seq_hi = clib_host_to_net_u32 (pd->seq_hi); |
| 250 | u8 tmp[ESP_MAX_ICV_SIZE]; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 251 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 252 | if (pd2->icv_removed) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 253 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 254 | u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 255 | if (space_left >= N_HI_ESN_BYTES) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 256 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 257 | clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, |
| 258 | N_HI_ESN_BYTES); |
| 259 | *data_len += N_HI_ESN_BYTES; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 260 | } |
| 261 | else |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 262 | return N_HI_ESN_BYTES; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 263 | |
| 264 | len[0] = b->current_length; |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | clib_memcpy_fast (tmp, payload + len[0], ESP_MAX_ICV_SIZE); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 269 | clib_memcpy_fast (payload + len[0], &seq_hi, N_HI_ESN_BYTES); |
| 270 | clib_memcpy_fast (payload + len[0] + N_HI_ESN_BYTES, tmp, |
| 271 | ESP_MAX_ICV_SIZE); |
| 272 | *data_len += N_HI_ESN_BYTES; |
| 273 | *digest += N_HI_ESN_BYTES; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 274 | } |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 275 | return N_HI_ESN_BYTES; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static_always_inline u8 * |
| 279 | esp_move_icv_esn (vlib_main_t * vm, vlib_buffer_t * first, |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 280 | esp_decrypt_packet_data_t * pd, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 281 | esp_decrypt_packet_data2_t * pd2, u16 icv_sz, |
| 282 | ipsec_sa_t * sa, u8 * extra_esn, u32 * len) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 283 | { |
| 284 | u16 dif = 0; |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 285 | u8 *digest = esp_move_icv (vm, first, pd, pd2, icv_sz, &dif); |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 286 | if (dif) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 287 | *len -= dif; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 288 | |
| 289 | if (ipsec_sa_is_set_USE_ESN (sa)) |
| 290 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 291 | u32 seq_hi = clib_host_to_net_u32 (pd->seq_hi); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 292 | u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb); |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 293 | |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 294 | if (space_left >= N_HI_ESN_BYTES) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 295 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 296 | clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), &seq_hi, |
| 297 | N_HI_ESN_BYTES); |
| 298 | *len += N_HI_ESN_BYTES; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | { |
| 302 | /* no space for ESN at the tail, use the next buffer |
| 303 | * (with ICV data) */ |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 304 | ASSERT (pd2->icv_removed); |
| 305 | vlib_buffer_t *tmp = vlib_get_buffer (vm, pd2->free_buffer_index); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 306 | clib_memcpy_fast (vlib_buffer_get_current (tmp) - N_HI_ESN_BYTES, |
| 307 | &seq_hi, N_HI_ESN_BYTES); |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 308 | extra_esn[0] = 1; |
| 309 | } |
| 310 | } |
| 311 | return digest; |
| 312 | } |
| 313 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 314 | static_always_inline int |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 315 | esp_decrypt_chain_integ (vlib_main_t *vm, ipsec_per_thread_data_t *ptd, |
| 316 | const esp_decrypt_packet_data_t *pd, |
| 317 | esp_decrypt_packet_data2_t *pd2, ipsec_sa_t *sa0, |
| 318 | vlib_buffer_t *b, u8 icv_sz, u8 *start_src, |
| 319 | u32 start_len, u8 **digest, u16 *n_ch, |
| 320 | u32 *integ_total_len) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 321 | { |
| 322 | vnet_crypto_op_chunk_t *ch; |
| 323 | vlib_buffer_t *cb = vlib_get_buffer (vm, b->next_buffer); |
| 324 | u16 n_chunks = 1; |
| 325 | u32 total_len; |
| 326 | vec_add2 (ptd->chunks, ch, 1); |
| 327 | total_len = ch->len = start_len; |
| 328 | ch->src = start_src; |
| 329 | |
| 330 | while (1) |
| 331 | { |
| 332 | vec_add2 (ptd->chunks, ch, 1); |
| 333 | n_chunks += 1; |
| 334 | ch->src = vlib_buffer_get_current (cb); |
| 335 | if (pd2->lb == cb) |
| 336 | { |
| 337 | if (pd2->icv_removed) |
| 338 | ch->len = cb->current_length; |
| 339 | else |
| 340 | ch->len = cb->current_length - icv_sz; |
| 341 | if (ipsec_sa_is_set_USE_ESN (sa0)) |
| 342 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 343 | u32 seq_hi = clib_host_to_net_u32 (pd->seq_hi); |
| 344 | u8 tmp[ESP_MAX_ICV_SIZE]; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 345 | u8 *esn; |
| 346 | vlib_buffer_t *tmp_b; |
| 347 | u16 space_left = vlib_buffer_space_left_at_end (vm, pd2->lb); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 348 | if (space_left < N_HI_ESN_BYTES) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 349 | { |
| 350 | if (pd2->icv_removed) |
| 351 | { |
| 352 | /* use pre-data area from the last bufer |
| 353 | that was removed from the chain */ |
| 354 | tmp_b = vlib_get_buffer (vm, pd2->free_buffer_index); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 355 | esn = tmp_b->data - N_HI_ESN_BYTES; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 356 | } |
| 357 | else |
| 358 | { |
| 359 | /* no space, need to allocate new buffer */ |
| 360 | u32 tmp_bi = 0; |
| 361 | if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1) |
| 362 | return -1; |
| 363 | tmp_b = vlib_get_buffer (vm, tmp_bi); |
| 364 | esn = tmp_b->data; |
| 365 | pd2->free_buffer_index = tmp_bi; |
| 366 | } |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 367 | clib_memcpy_fast (esn, &seq_hi, N_HI_ESN_BYTES); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 368 | |
| 369 | vec_add2 (ptd->chunks, ch, 1); |
| 370 | n_chunks += 1; |
| 371 | ch->src = esn; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 372 | ch->len = N_HI_ESN_BYTES; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | { |
| 376 | if (pd2->icv_removed) |
| 377 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 378 | clib_memcpy_fast (vlib_buffer_get_tail (pd2->lb), |
| 379 | &seq_hi, N_HI_ESN_BYTES); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 380 | } |
| 381 | else |
| 382 | { |
| 383 | clib_memcpy_fast (tmp, *digest, ESP_MAX_ICV_SIZE); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 384 | clib_memcpy_fast (*digest, &seq_hi, N_HI_ESN_BYTES); |
| 385 | clib_memcpy_fast (*digest + N_HI_ESN_BYTES, tmp, |
| 386 | ESP_MAX_ICV_SIZE); |
| 387 | *digest += N_HI_ESN_BYTES; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 388 | } |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 389 | ch->len += N_HI_ESN_BYTES; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | total_len += ch->len; |
| 393 | break; |
| 394 | } |
| 395 | else |
| 396 | total_len += ch->len = cb->current_length; |
| 397 | |
| 398 | if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 399 | break; |
| 400 | |
| 401 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 402 | } |
| 403 | |
| 404 | if (n_ch) |
| 405 | *n_ch = n_chunks; |
| 406 | if (integ_total_len) |
| 407 | *integ_total_len = total_len; |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | static_always_inline u32 |
| 413 | esp_decrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd, |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 414 | esp_decrypt_packet_data_t * pd, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 415 | esp_decrypt_packet_data2_t * pd2, |
| 416 | ipsec_sa_t * sa0, vlib_buffer_t * b, u8 icv_sz, |
| 417 | u8 * start, u32 start_len, u8 ** tag, u16 * n_ch) |
| 418 | { |
| 419 | vnet_crypto_op_chunk_t *ch; |
| 420 | vlib_buffer_t *cb = b; |
| 421 | u16 n_chunks = 1; |
| 422 | u32 total_len; |
| 423 | vec_add2 (ptd->chunks, ch, 1); |
| 424 | total_len = ch->len = start_len; |
| 425 | ch->src = ch->dst = start; |
| 426 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 427 | n_chunks = 1; |
| 428 | |
| 429 | while (1) |
| 430 | { |
| 431 | vec_add2 (ptd->chunks, ch, 1); |
| 432 | n_chunks += 1; |
| 433 | ch->src = ch->dst = vlib_buffer_get_current (cb); |
| 434 | if (pd2->lb == cb) |
| 435 | { |
| 436 | if (ipsec_sa_is_set_IS_AEAD (sa0)) |
| 437 | { |
| 438 | if (pd2->lb->current_length < icv_sz) |
| 439 | { |
| 440 | u16 dif = 0; |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 441 | *tag = esp_move_icv (vm, b, pd, pd2, icv_sz, &dif); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 442 | |
| 443 | /* this chunk does not contain crypto data */ |
| 444 | n_chunks -= 1; |
| 445 | /* and fix previous chunk's length as it might have |
| 446 | been changed */ |
| 447 | ASSERT (n_chunks > 0); |
| 448 | if (pd2->lb == b) |
| 449 | { |
| 450 | total_len -= dif; |
| 451 | ch[-1].len -= dif; |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | total_len = total_len + pd2->lb->current_length - |
| 456 | ch[-1].len; |
| 457 | ch[-1].len = pd2->lb->current_length; |
| 458 | } |
| 459 | break; |
| 460 | } |
| 461 | else |
| 462 | *tag = vlib_buffer_get_tail (pd2->lb) - icv_sz; |
| 463 | } |
| 464 | |
| 465 | if (pd2->icv_removed) |
| 466 | total_len += ch->len = cb->current_length; |
| 467 | else |
| 468 | total_len += ch->len = cb->current_length - icv_sz; |
| 469 | } |
| 470 | else |
| 471 | total_len += ch->len = cb->current_length; |
| 472 | |
| 473 | if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 474 | break; |
| 475 | |
| 476 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 477 | } |
| 478 | |
| 479 | if (n_ch) |
| 480 | *n_ch = n_chunks; |
| 481 | |
| 482 | return total_len; |
| 483 | } |
| 484 | |
| 485 | static_always_inline void |
| 486 | esp_decrypt_prepare_sync_op (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 487 | ipsec_per_thread_data_t * ptd, |
| 488 | vnet_crypto_op_t *** crypto_ops, |
| 489 | vnet_crypto_op_t *** integ_ops, |
| 490 | vnet_crypto_op_t * op, |
| 491 | ipsec_sa_t * sa0, u8 * payload, |
| 492 | u16 len, u8 icv_sz, u8 iv_sz, |
| 493 | esp_decrypt_packet_data_t * pd, |
| 494 | esp_decrypt_packet_data2_t * pd2, |
| 495 | vlib_buffer_t * b, u16 * next, u32 index) |
| 496 | { |
| 497 | const u8 esp_sz = sizeof (esp_header_t); |
| 498 | |
| 499 | if (PREDICT_TRUE (sa0->integ_op_id != VNET_CRYPTO_OP_NONE)) |
| 500 | { |
| 501 | vnet_crypto_op_init (op, sa0->integ_op_id); |
| 502 | op->key_index = sa0->integ_key_index; |
| 503 | op->src = payload; |
| 504 | op->flags = VNET_CRYPTO_OP_FLAG_HMAC_CHECK; |
| 505 | op->user_data = index; |
| 506 | op->digest = payload + len; |
| 507 | op->digest_len = icv_sz; |
| 508 | op->len = len; |
| 509 | |
| 510 | if (pd->is_chain) |
| 511 | { |
| 512 | /* buffer is chained */ |
| 513 | op->len = pd->current_length; |
| 514 | |
| 515 | /* special case when ICV is splitted and needs to be reassembled |
| 516 | * first -> move it to the last buffer. Also take into account |
| 517 | * that ESN needs to be added after encrypted data and may or |
| 518 | * may not fit in the tail.*/ |
| 519 | if (pd2->lb->current_length < icv_sz) |
| 520 | { |
| 521 | u8 extra_esn = 0; |
| 522 | op->digest = |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 523 | esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 524 | &extra_esn, &op->len); |
| 525 | |
| 526 | if (extra_esn) |
| 527 | { |
| 528 | /* esn is in the last buffer, that was unlinked from |
| 529 | * the chain */ |
| 530 | op->len = b->current_length; |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | if (pd2->lb == b) |
| 535 | { |
| 536 | /* we now have a single buffer of crypto data, adjust |
| 537 | * the length (second buffer contains only ICV) */ |
| 538 | *integ_ops = &ptd->integ_ops; |
| 539 | *crypto_ops = &ptd->crypto_ops; |
| 540 | len = b->current_length; |
| 541 | goto out; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | else |
| 546 | op->digest = vlib_buffer_get_tail (pd2->lb) - icv_sz; |
| 547 | |
| 548 | op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 549 | op->chunk_index = vec_len (ptd->chunks); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 550 | if (esp_decrypt_chain_integ (vm, ptd, pd, pd2, sa0, b, icv_sz, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 551 | payload, pd->current_length, |
| 552 | &op->digest, &op->n_chunks, 0) < 0) |
| 553 | { |
| 554 | b->error = node->errors[ESP_DECRYPT_ERROR_NO_BUFFERS]; |
| 555 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 556 | return; |
| 557 | } |
| 558 | } |
| 559 | else |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 560 | esp_insert_esn (vm, sa0, pd, pd2, &op->len, &op->digest, &len, b, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 561 | payload); |
| 562 | out: |
| 563 | vec_add_aligned (*(integ_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES); |
| 564 | } |
| 565 | |
| 566 | payload += esp_sz; |
| 567 | len -= esp_sz; |
| 568 | |
| 569 | if (sa0->crypto_dec_op_id != VNET_CRYPTO_OP_NONE) |
| 570 | { |
| 571 | vnet_crypto_op_init (op, sa0->crypto_dec_op_id); |
| 572 | op->key_index = sa0->crypto_key_index; |
| 573 | op->iv = payload; |
| 574 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 575 | if (ipsec_sa_is_set_IS_CTR (sa0)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 576 | { |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 577 | /* construct nonce in a scratch space in front of the IP header */ |
| 578 | esp_ctr_nonce_t *nonce = |
| 579 | (esp_ctr_nonce_t *) (payload - esp_sz - pd->hdr_sz - |
| 580 | sizeof (*nonce)); |
| 581 | if (ipsec_sa_is_set_IS_AEAD (sa0)) |
| 582 | { |
| 583 | /* constuct aad in a scratch space in front of the nonce */ |
| 584 | esp_header_t *esp0 = (esp_header_t *) (payload - esp_sz); |
| 585 | op->aad = (u8 *) nonce - sizeof (esp_aead_t); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 586 | op->aad_len = esp_aad_fill (op->aad, esp0, sa0, pd->seq_hi); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 587 | op->tag = payload + len; |
| 588 | op->tag_len = 16; |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | nonce->ctr = clib_host_to_net_u32 (1); |
| 593 | } |
| 594 | nonce->salt = sa0->salt; |
| 595 | ASSERT (sizeof (u64) == iv_sz); |
| 596 | nonce->iv = *(u64 *) op->iv; |
| 597 | op->iv = (u8 *) nonce; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 598 | } |
| 599 | op->src = op->dst = payload += iv_sz; |
| 600 | op->len = len - iv_sz; |
| 601 | op->user_data = index; |
| 602 | |
| 603 | if (pd->is_chain && (pd2->lb != b)) |
| 604 | { |
| 605 | /* buffer is chained */ |
| 606 | op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 607 | op->chunk_index = vec_len (ptd->chunks); |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 608 | esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 609 | payload, len - pd->iv_sz + pd->icv_sz, |
| 610 | &op->tag, &op->n_chunks); |
| 611 | } |
| 612 | |
| 613 | vec_add_aligned (*(crypto_ops[0]), op, 1, CLIB_CACHE_LINE_BYTES); |
| 614 | } |
| 615 | } |
| 616 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 617 | static_always_inline esp_decrypt_error_t |
| 618 | esp_decrypt_prepare_async_frame (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 619 | ipsec_per_thread_data_t *ptd, |
| 620 | vnet_crypto_async_frame_t *f, ipsec_sa_t *sa0, |
| 621 | u8 *payload, u16 len, u8 icv_sz, u8 iv_sz, |
| 622 | esp_decrypt_packet_data_t *pd, |
| 623 | esp_decrypt_packet_data2_t *pd2, u32 bi, |
| 624 | vlib_buffer_t *b, u16 *next, u16 async_next) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 625 | { |
| 626 | const u8 esp_sz = sizeof (esp_header_t); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 627 | esp_decrypt_packet_data_t *async_pd = &(esp_post_data (b))->decrypt_data; |
| 628 | esp_decrypt_packet_data2_t *async_pd2 = esp_post_data2 (b); |
| 629 | u8 *tag = payload + len, *iv = payload + esp_sz, *aad = 0; |
| 630 | u32 key_index; |
| 631 | u32 crypto_len, integ_len = 0; |
| 632 | i16 crypto_start_offset, integ_start_offset = 0; |
| 633 | u8 flags = 0; |
| 634 | |
| 635 | if (!ipsec_sa_is_set_IS_AEAD (sa0)) |
| 636 | { |
| 637 | /* linked algs */ |
| 638 | key_index = sa0->linked_key_index; |
| 639 | integ_start_offset = payload - b->data; |
| 640 | integ_len = len; |
Benoît Ganne | 48524a9 | 2021-01-22 18:11:37 +0100 | [diff] [blame] | 641 | if (PREDICT_TRUE (sa0->integ_op_id != VNET_CRYPTO_OP_NONE)) |
| 642 | flags |= VNET_CRYPTO_OP_FLAG_HMAC_CHECK; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 643 | |
| 644 | if (pd->is_chain) |
| 645 | { |
| 646 | /* buffer is chained */ |
| 647 | integ_len = pd->current_length; |
| 648 | |
| 649 | /* special case when ICV is splitted and needs to be reassembled |
| 650 | * first -> move it to the last buffer. Also take into account |
| 651 | * that ESN needs to be added after encrypted data and may or |
| 652 | * may not fit in the tail.*/ |
| 653 | if (pd2->lb->current_length < icv_sz) |
| 654 | { |
| 655 | u8 extra_esn = 0; |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 656 | tag = esp_move_icv_esn (vm, b, pd, pd2, icv_sz, sa0, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 657 | &extra_esn, &integ_len); |
| 658 | |
| 659 | if (extra_esn) |
| 660 | { |
| 661 | /* esn is in the last buffer, that was unlinked from |
| 662 | * the chain */ |
| 663 | integ_len = b->current_length; |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | if (pd2->lb == b) |
| 668 | { |
| 669 | /* we now have a single buffer of crypto data, adjust |
| 670 | * the length (second buffer contains only ICV) */ |
| 671 | len = b->current_length; |
| 672 | goto out; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | else |
| 677 | tag = vlib_buffer_get_tail (pd2->lb) - icv_sz; |
| 678 | |
| 679 | flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 680 | if (esp_decrypt_chain_integ (vm, ptd, pd, pd2, sa0, b, icv_sz, |
| 681 | payload, pd->current_length, &tag, 0, |
| 682 | &integ_len) < 0) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 683 | { |
| 684 | /* allocate buffer failed, will not add to frame and drop */ |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 685 | return (ESP_DECRYPT_ERROR_NO_BUFFERS); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | else |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 689 | esp_insert_esn (vm, sa0, pd, pd2, &integ_len, &tag, &len, b, payload); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 690 | } |
| 691 | else |
| 692 | key_index = sa0->crypto_key_index; |
| 693 | |
| 694 | out: |
| 695 | /* crypto */ |
| 696 | payload += esp_sz; |
| 697 | len -= esp_sz; |
| 698 | iv = payload; |
| 699 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 700 | if (ipsec_sa_is_set_IS_CTR (sa0)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 701 | { |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 702 | /* construct nonce in a scratch space in front of the IP header */ |
| 703 | esp_ctr_nonce_t *nonce = |
| 704 | (esp_ctr_nonce_t *) (payload - esp_sz - pd->hdr_sz - sizeof (*nonce)); |
| 705 | if (ipsec_sa_is_set_IS_AEAD (sa0)) |
| 706 | { |
| 707 | /* constuct aad in a scratch space in front of the nonce */ |
| 708 | esp_header_t *esp0 = (esp_header_t *) (payload - esp_sz); |
| 709 | aad = (u8 *) nonce - sizeof (esp_aead_t); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 710 | esp_aad_fill (aad, esp0, sa0, pd->seq_hi); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 711 | tag = payload + len; |
| 712 | } |
| 713 | else |
| 714 | { |
| 715 | nonce->ctr = clib_host_to_net_u32 (1); |
| 716 | } |
| 717 | nonce->salt = sa0->salt; |
| 718 | ASSERT (sizeof (u64) == iv_sz); |
| 719 | nonce->iv = *(u64 *) iv; |
| 720 | iv = (u8 *) nonce; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | crypto_start_offset = (payload += iv_sz) - b->data; |
| 724 | crypto_len = len - iv_sz; |
| 725 | |
| 726 | if (pd->is_chain && (pd2->lb != b)) |
| 727 | { |
| 728 | /* buffer is chained */ |
| 729 | flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 730 | |
PiotrX Kleski | a9585fd | 2020-12-11 15:10:31 +0000 | [diff] [blame] | 731 | crypto_len = esp_decrypt_chain_crypto (vm, ptd, pd, pd2, sa0, b, icv_sz, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 732 | payload, |
| 733 | len - pd->iv_sz + pd->icv_sz, |
| 734 | &tag, 0); |
| 735 | } |
| 736 | |
| 737 | *async_pd = *pd; |
| 738 | *async_pd2 = *pd2; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 739 | |
| 740 | /* for AEAD integ_len - crypto_len will be negative, it is ok since it |
| 741 | * is ignored by the engine. */ |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 742 | vnet_crypto_async_add_to_frame ( |
| 743 | vm, f, key_index, crypto_len, integ_len - crypto_len, crypto_start_offset, |
| 744 | integ_start_offset, bi, async_next, iv, tag, aad, flags); |
| 745 | |
| 746 | return (ESP_DECRYPT_ERROR_RX_PKTS); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static_always_inline void |
Neale Ranns | e11203e | 2021-09-21 12:34:19 +0000 | [diff] [blame] | 750 | esp_decrypt_post_crypto (vlib_main_t *vm, const vlib_node_runtime_t *node, |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 751 | const u16 *next_by_next_header, |
Neale Ranns | e11203e | 2021-09-21 12:34:19 +0000 | [diff] [blame] | 752 | const esp_decrypt_packet_data_t *pd, |
| 753 | const esp_decrypt_packet_data2_t *pd2, |
| 754 | vlib_buffer_t *b, u16 *next, int is_ip6, int is_tun, |
| 755 | int is_async) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 756 | { |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 757 | ipsec_sa_t *sa0 = ipsec_sa_get (pd->sa_index); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 758 | vlib_buffer_t *lb = b; |
| 759 | const u8 esp_sz = sizeof (esp_header_t); |
| 760 | const u8 tun_flags = IPSEC_SA_FLAG_IS_TUNNEL | IPSEC_SA_FLAG_IS_TUNNEL_V6; |
| 761 | u8 pad_length = 0, next_header = 0; |
| 762 | u16 icv_sz; |
| 763 | |
| 764 | /* |
| 765 | * redo the anti-reply check |
| 766 | * in this frame say we have sequence numbers, s, s+1, s+1, s+1 |
| 767 | * and s and s+1 are in the window. When we did the anti-replay |
| 768 | * check above we did so against the state of the window (W), |
| 769 | * after packet s-1. So each of the packets in the sequence will be |
| 770 | * accepted. |
| 771 | * This time s will be cheked against Ws-1, s+1 chceked against Ws |
| 772 | * (i.e. the window state is updated/advnaced) |
| 773 | * so this time the successive s+! packet will be dropped. |
| 774 | * This is a consequence of batching the decrypts. If the |
| 775 | * check-dcrypt-advance process was done for each packet it would |
| 776 | * be fine. But we batch the decrypts because it's much more efficient |
| 777 | * to do so in SW and if we offload to HW and the process is async. |
| 778 | * |
| 779 | * You're probably thinking, but this means an attacker can send the |
| 780 | * above sequence and cause VPP to perform decrpyts that will fail, |
| 781 | * and that's true. But if the attacker can determine s (a valid |
| 782 | * sequence number in the window) which is non-trivial, it can generate |
| 783 | * a sequence s, s+1, s+2, s+3, ... s+n and nothing will prevent any |
| 784 | * implementation, sequential or batching, from decrypting these. |
| 785 | */ |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 786 | if (ipsec_sa_anti_replay_and_sn_advance (sa0, pd->seq, pd->seq_hi, true, |
| 787 | NULL)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 788 | { |
| 789 | b->error = node->errors[ESP_DECRYPT_ERROR_REPLAY]; |
| 790 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 791 | return; |
| 792 | } |
| 793 | |
Neale Ranns | e11203e | 2021-09-21 12:34:19 +0000 | [diff] [blame] | 794 | u64 n_lost = |
| 795 | ipsec_sa_anti_replay_advance (sa0, vm->thread_index, pd->seq, pd->seq_hi); |
| 796 | |
| 797 | vlib_prefetch_simple_counter (&ipsec_sa_lost_counters, vm->thread_index, |
| 798 | pd->sa_index); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 799 | |
| 800 | if (pd->is_chain) |
| 801 | { |
| 802 | lb = pd2->lb; |
| 803 | icv_sz = pd2->icv_removed ? 0 : pd->icv_sz; |
| 804 | if (pd2->free_buffer_index) |
| 805 | { |
| 806 | vlib_buffer_free_one (vm, pd2->free_buffer_index); |
| 807 | lb->next_buffer = 0; |
| 808 | } |
| 809 | if (lb->current_length < sizeof (esp_footer_t) + icv_sz) |
| 810 | { |
| 811 | /* esp footer is either splitted in two buffers or in the before |
| 812 | * last buffer */ |
| 813 | |
| 814 | vlib_buffer_t *before_last = b, *bp = b; |
| 815 | while (bp->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 816 | { |
| 817 | before_last = bp; |
| 818 | bp = vlib_get_buffer (vm, bp->next_buffer); |
| 819 | } |
| 820 | u8 *bt = vlib_buffer_get_tail (before_last); |
| 821 | |
| 822 | if (lb->current_length == icv_sz) |
| 823 | { |
| 824 | esp_footer_t *f = (esp_footer_t *) (bt - sizeof (*f)); |
| 825 | pad_length = f->pad_length; |
| 826 | next_header = f->next_header; |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | pad_length = (bt - 1)[0]; |
| 831 | next_header = ((u8 *) vlib_buffer_get_current (lb))[0]; |
| 832 | } |
| 833 | } |
| 834 | else |
| 835 | { |
| 836 | esp_footer_t *f = |
| 837 | (esp_footer_t *) (lb->data + lb->current_data + |
| 838 | lb->current_length - sizeof (esp_footer_t) - |
| 839 | icv_sz); |
| 840 | pad_length = f->pad_length; |
| 841 | next_header = f->next_header; |
| 842 | } |
| 843 | } |
| 844 | else |
| 845 | { |
| 846 | icv_sz = pd->icv_sz; |
| 847 | esp_footer_t *f = |
| 848 | (esp_footer_t *) (lb->data + lb->current_data + lb->current_length - |
| 849 | sizeof (esp_footer_t) - icv_sz); |
| 850 | pad_length = f->pad_length; |
| 851 | next_header = f->next_header; |
| 852 | } |
| 853 | |
| 854 | u16 adv = pd->iv_sz + esp_sz; |
| 855 | u16 tail = sizeof (esp_footer_t) + pad_length + icv_sz; |
| 856 | u16 tail_orig = sizeof (esp_footer_t) + pad_length + pd->icv_sz; |
| 857 | b->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; |
| 858 | |
| 859 | if ((pd->flags & tun_flags) == 0 && !is_tun) /* transport mode */ |
| 860 | { |
| 861 | u8 udp_sz = (is_ip6 == 0 && pd->flags & IPSEC_SA_FLAG_UDP_ENCAP) ? |
| 862 | sizeof (udp_header_t) : 0; |
| 863 | u16 ip_hdr_sz = pd->hdr_sz - udp_sz; |
| 864 | u8 *old_ip = b->data + pd->current_data - ip_hdr_sz - udp_sz; |
| 865 | u8 *ip = old_ip + adv + udp_sz; |
| 866 | |
| 867 | if (is_ip6 && ip_hdr_sz > 64) |
| 868 | memmove (ip, old_ip, ip_hdr_sz); |
| 869 | else |
| 870 | clib_memcpy_le64 (ip, old_ip, ip_hdr_sz); |
| 871 | |
| 872 | b->current_data = pd->current_data + adv - ip_hdr_sz; |
| 873 | b->current_length += ip_hdr_sz - adv; |
| 874 | esp_remove_tail (vm, b, lb, tail); |
| 875 | |
| 876 | if (is_ip6) |
| 877 | { |
| 878 | ip6_header_t *ip6 = (ip6_header_t *) ip; |
| 879 | u16 len = clib_net_to_host_u16 (ip6->payload_length); |
| 880 | len -= adv + tail_orig; |
| 881 | ip6->payload_length = clib_host_to_net_u16 (len); |
| 882 | ip6->protocol = next_header; |
| 883 | next[0] = ESP_DECRYPT_NEXT_IP6_INPUT; |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | ip4_header_t *ip4 = (ip4_header_t *) ip; |
| 888 | ip_csum_t sum = ip4->checksum; |
| 889 | u16 len = clib_net_to_host_u16 (ip4->length); |
| 890 | len = clib_host_to_net_u16 (len - adv - tail_orig - udp_sz); |
| 891 | sum = ip_csum_update (sum, ip4->protocol, next_header, |
| 892 | ip4_header_t, protocol); |
| 893 | sum = ip_csum_update (sum, ip4->length, len, ip4_header_t, length); |
| 894 | ip4->checksum = ip_csum_fold (sum); |
| 895 | ip4->protocol = next_header; |
| 896 | ip4->length = len; |
| 897 | next[0] = ESP_DECRYPT_NEXT_IP4_INPUT; |
| 898 | } |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP)) |
| 903 | { |
| 904 | next[0] = ESP_DECRYPT_NEXT_IP4_INPUT; |
| 905 | b->current_data = pd->current_data + adv; |
| 906 | b->current_length = pd->current_length - adv; |
| 907 | esp_remove_tail (vm, b, lb, tail); |
| 908 | } |
| 909 | else if (next_header == IP_PROTOCOL_IPV6) |
| 910 | { |
| 911 | next[0] = ESP_DECRYPT_NEXT_IP6_INPUT; |
| 912 | b->current_data = pd->current_data + adv; |
| 913 | b->current_length = pd->current_length - adv; |
| 914 | esp_remove_tail (vm, b, lb, tail); |
| 915 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 916 | else if (next_header == IP_PROTOCOL_MPLS_IN_IP) |
| 917 | { |
| 918 | next[0] = ESP_DECRYPT_NEXT_MPLS_INPUT; |
| 919 | b->current_data = pd->current_data + adv; |
| 920 | b->current_length = pd->current_length - adv; |
| 921 | esp_remove_tail (vm, b, lb, tail); |
| 922 | } |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 923 | else if (is_tun && next_header == IP_PROTOCOL_GRE) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 924 | { |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 925 | gre_header_t *gre; |
| 926 | |
| 927 | b->current_data = pd->current_data + adv; |
| 928 | b->current_length = pd->current_length - adv - tail; |
| 929 | |
| 930 | gre = vlib_buffer_get_current (b); |
| 931 | |
| 932 | vlib_buffer_advance (b, sizeof (*gre)); |
| 933 | |
| 934 | switch (clib_net_to_host_u16 (gre->protocol)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 935 | { |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 936 | case GRE_PROTOCOL_teb: |
| 937 | vnet_update_l2_len (b); |
| 938 | next[0] = ESP_DECRYPT_NEXT_L2_INPUT; |
| 939 | break; |
| 940 | case GRE_PROTOCOL_ip4: |
| 941 | next[0] = ESP_DECRYPT_NEXT_IP4_INPUT; |
| 942 | break; |
| 943 | case GRE_PROTOCOL_ip6: |
| 944 | next[0] = ESP_DECRYPT_NEXT_IP6_INPUT; |
| 945 | break; |
| 946 | default: |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 947 | b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD]; |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 948 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 949 | break; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 950 | } |
| 951 | } |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 952 | else if ((next[0] = vec_elt (next_by_next_header, next_header)) != |
| 953 | (u16) ~0) |
| 954 | { |
| 955 | b->current_data = pd->current_data + adv; |
| 956 | b->current_length = pd->current_length - adv; |
| 957 | esp_remove_tail (vm, b, lb, tail); |
| 958 | } |
| 959 | else |
| 960 | { |
| 961 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 962 | b->error = node->errors[ESP_DECRYPT_ERROR_UNSUP_PAYLOAD]; |
| 963 | return; |
| 964 | } |
| 965 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 966 | if (is_tun) |
| 967 | { |
| 968 | if (ipsec_sa_is_set_IS_PROTECT (sa0)) |
| 969 | { |
| 970 | /* |
| 971 | * There are two encap possibilities |
| 972 | * 1) the tunnel and ths SA are prodiving encap, i.e. it's |
| 973 | * MAC | SA-IP | TUN-IP | ESP | PAYLOAD |
| 974 | * implying the SA is in tunnel mode (on a tunnel interface) |
| 975 | * 2) only the tunnel provides encap |
| 976 | * MAC | TUN-IP | ESP | PAYLOAD |
| 977 | * implying the SA is in transport mode. |
| 978 | * |
| 979 | * For 2) we need only strip the tunnel encap and we're good. |
| 980 | * since the tunnel and crypto ecnap (int the tun=protect |
| 981 | * object) are the same and we verified above that these match |
| 982 | * for 1) we need to strip the SA-IP outer headers, to |
| 983 | * reveal the tunnel IP and then check that this matches |
| 984 | * the configured tunnel. |
| 985 | */ |
| 986 | const ipsec_tun_protect_t *itp; |
| 987 | |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 988 | itp = |
| 989 | ipsec_tun_protect_get (vnet_buffer (b)->ipsec.protect_index); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 990 | |
| 991 | if (PREDICT_TRUE (next_header == IP_PROTOCOL_IP_IN_IP)) |
| 992 | { |
| 993 | const ip4_header_t *ip4; |
| 994 | |
| 995 | ip4 = vlib_buffer_get_current (b); |
| 996 | |
| 997 | if (!ip46_address_is_equal_v4 (&itp->itp_tun.src, |
| 998 | &ip4->dst_address) || |
| 999 | !ip46_address_is_equal_v4 (&itp->itp_tun.dst, |
| 1000 | &ip4->src_address)) |
| 1001 | { |
| 1002 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 1003 | b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO]; |
| 1004 | } |
| 1005 | } |
| 1006 | else if (next_header == IP_PROTOCOL_IPV6) |
| 1007 | { |
| 1008 | const ip6_header_t *ip6; |
| 1009 | |
| 1010 | ip6 = vlib_buffer_get_current (b); |
| 1011 | |
| 1012 | if (!ip46_address_is_equal_v6 (&itp->itp_tun.src, |
| 1013 | &ip6->dst_address) || |
| 1014 | !ip46_address_is_equal_v6 (&itp->itp_tun.dst, |
| 1015 | &ip6->src_address)) |
| 1016 | { |
| 1017 | next[0] = ESP_DECRYPT_NEXT_DROP; |
| 1018 | b->error = node->errors[ESP_DECRYPT_ERROR_TUN_NO_PROTO]; |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
Neale Ranns | e11203e | 2021-09-21 12:34:19 +0000 | [diff] [blame] | 1024 | |
| 1025 | if (PREDICT_FALSE (n_lost)) |
| 1026 | vlib_increment_simple_counter (&ipsec_sa_lost_counters, vm->thread_index, |
| 1027 | pd->sa_index, n_lost); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1030 | always_inline uword |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1031 | esp_decrypt_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 1032 | vlib_frame_t *from_frame, int is_ip6, int is_tun, |
| 1033 | u16 async_next_node) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1034 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1035 | ipsec_main_t *im = &ipsec_main; |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 1036 | const u16 *next_by_next_header = im->next_header_registrations; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1037 | u32 thread_index = vm->thread_index; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1038 | u16 len; |
| 1039 | ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1040 | u32 *from = vlib_frame_vector_args (from_frame); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1041 | u32 n_left = from_frame->n_vectors; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1042 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1043 | vlib_buffer_t *sync_bufs[VLIB_FRAME_SIZE]; |
| 1044 | u16 sync_nexts[VLIB_FRAME_SIZE], *sync_next = sync_nexts, n_sync = 0; |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1045 | u16 async_nexts[VLIB_FRAME_SIZE], *async_next = async_nexts; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1046 | u16 noop_nexts[VLIB_FRAME_SIZE], *noop_next = noop_nexts, n_noop = 0; |
| 1047 | u32 sync_bi[VLIB_FRAME_SIZE]; |
| 1048 | u32 noop_bi[VLIB_FRAME_SIZE]; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1049 | esp_decrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1050 | esp_decrypt_packet_data2_t pkt_data2[VLIB_FRAME_SIZE], *pd2 = pkt_data2; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1051 | esp_decrypt_packet_data_t cpd = { }; |
| 1052 | u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0; |
| 1053 | const u8 esp_sz = sizeof (esp_header_t); |
| 1054 | ipsec_sa_t *sa0 = 0; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 1055 | vnet_crypto_op_t _op, *op = &_op; |
Benoît Ganne | e631ece | 2021-05-27 18:49:42 +0200 | [diff] [blame] | 1056 | vnet_crypto_op_t **crypto_ops; |
| 1057 | vnet_crypto_op_t **integ_ops; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1058 | int is_async = im->async_mode; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1059 | vnet_crypto_async_op_id_t async_op = ~0; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1060 | vnet_crypto_async_frame_t *async_frames[VNET_CRYPTO_ASYNC_OP_N_IDS]; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1061 | esp_decrypt_error_t err; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1062 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1063 | vlib_get_buffers (vm, from, b, n_left); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1064 | if (!is_async) |
| 1065 | { |
| 1066 | vec_reset_length (ptd->crypto_ops); |
| 1067 | vec_reset_length (ptd->integ_ops); |
| 1068 | vec_reset_length (ptd->chained_crypto_ops); |
| 1069 | vec_reset_length (ptd->chained_integ_ops); |
| 1070 | } |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1071 | vec_reset_length (ptd->async_frames); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1072 | vec_reset_length (ptd->chunks); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1073 | clib_memset (sync_nexts, -1, sizeof (sync_nexts)); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1074 | clib_memset (async_frames, 0, sizeof (async_frames)); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1075 | |
| 1076 | while (n_left > 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1077 | { |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1078 | u8 *payload; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1079 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1080 | err = ESP_DECRYPT_ERROR_RX_PKTS; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1081 | if (n_left > 2) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1082 | { |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1083 | u8 *p; |
| 1084 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 1085 | p = vlib_buffer_get_current (b[1]); |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 1086 | clib_prefetch_load (p); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1087 | p -= CLIB_CACHE_LINE_BYTES; |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 1088 | clib_prefetch_load (p); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1091 | u32 n_bufs = vlib_buffer_chain_linearize (vm, b[0]); |
| 1092 | if (n_bufs == 0) |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1093 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1094 | err = ESP_DECRYPT_ERROR_NO_BUFFERS; |
| 1095 | esp_set_next_index (b[0], node, err, n_noop, noop_nexts, |
| 1096 | ESP_DECRYPT_NEXT_DROP); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1097 | goto next; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1098 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1099 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1100 | if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1101 | { |
Damjan Marion | 867dfdd | 2019-06-05 15:42:54 +0200 | [diff] [blame] | 1102 | if (current_sa_pkts) |
| 1103 | vlib_increment_combined_counter (&ipsec_sa_counters, thread_index, |
| 1104 | current_sa_index, |
| 1105 | current_sa_pkts, |
| 1106 | current_sa_bytes); |
| 1107 | current_sa_bytes = current_sa_pkts = 0; |
| 1108 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1109 | current_sa_index = vnet_buffer (b[0])->ipsec.sad_index; |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 1110 | sa0 = ipsec_sa_get (current_sa_index); |
Neale Ranns | 123b5eb | 2020-10-16 14:03:55 +0000 | [diff] [blame] | 1111 | |
| 1112 | /* fetch the second cacheline ASAP */ |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 1113 | clib_prefetch_load (sa0->cacheline1); |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 1114 | cpd.icv_sz = sa0->integ_icv_size; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1115 | cpd.iv_sz = sa0->crypto_iv_size; |
| 1116 | cpd.flags = sa0->flags; |
| 1117 | cpd.sa_index = current_sa_index; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1118 | is_async = im->async_mode | ipsec_sa_is_set_IS_ASYNC (sa0); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1119 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1120 | |
Neale Ranns | 1a52d37 | 2021-02-04 11:33:32 +0000 | [diff] [blame] | 1121 | if (PREDICT_FALSE (~0 == sa0->thread_index)) |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 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 */ |
Neale Ranns | 1a52d37 | 2021-02-04 11:33:32 +0000 | [diff] [blame] | 1126 | clib_atomic_cmp_and_swap (&sa0->thread_index, ~0, |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1127 | ipsec_sa_assign_thread (thread_index)); |
| 1128 | } |
| 1129 | |
Neale Ranns | 1a52d37 | 2021-02-04 11:33:32 +0000 | [diff] [blame] | 1130 | if (PREDICT_FALSE (thread_index != sa0->thread_index)) |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1131 | { |
Neale Ranns | aa7d766 | 2021-02-10 08:42:49 +0000 | [diff] [blame] | 1132 | vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1133 | err = ESP_DECRYPT_ERROR_HANDOFF; |
| 1134 | esp_set_next_index (b[0], node, err, n_noop, noop_nexts, |
| 1135 | ESP_DECRYPT_NEXT_HANDOFF); |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1136 | goto next; |
| 1137 | } |
| 1138 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1139 | /* store packet data for next round for easier prefetch */ |
| 1140 | pd->sa_data = cpd.sa_data; |
| 1141 | pd->current_data = b[0]->current_data; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1142 | pd->hdr_sz = pd->current_data - vnet_buffer (b[0])->l3_hdr_offset; |
| 1143 | payload = b[0]->data + pd->current_data; |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 1144 | pd->seq = clib_host_to_net_u32 (((esp_header_t *) payload)->seq); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1145 | pd->is_chain = 0; |
| 1146 | pd2->lb = b[0]; |
| 1147 | pd2->free_buffer_index = 0; |
| 1148 | pd2->icv_removed = 0; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1149 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1150 | if (n_bufs > 1) |
| 1151 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1152 | pd->is_chain = 1; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1153 | /* find last buffer in the chain */ |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1154 | while (pd2->lb->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 1155 | pd2->lb = vlib_get_buffer (vm, pd2->lb->next_buffer); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1156 | |
| 1157 | crypto_ops = &ptd->chained_crypto_ops; |
| 1158 | integ_ops = &ptd->chained_integ_ops; |
| 1159 | } |
Benoît Ganne | e631ece | 2021-05-27 18:49:42 +0200 | [diff] [blame] | 1160 | else |
| 1161 | { |
| 1162 | crypto_ops = &ptd->crypto_ops; |
| 1163 | integ_ops = &ptd->integ_ops; |
| 1164 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1165 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1166 | pd->current_length = b[0]->current_length; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1167 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1168 | /* anti-reply check */ |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 1169 | if (ipsec_sa_anti_replay_and_sn_advance (sa0, pd->seq, ~0, false, |
| 1170 | &pd->seq_hi)) |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1171 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1172 | err = ESP_DECRYPT_ERROR_REPLAY; |
| 1173 | esp_set_next_index (b[0], node, err, n_noop, noop_nexts, |
| 1174 | ESP_DECRYPT_NEXT_DROP); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1175 | goto next; |
| 1176 | } |
| 1177 | |
Damjan Marion | a829b13 | 2019-04-24 23:39:16 +0200 | [diff] [blame] | 1178 | if (pd->current_length < cpd.icv_sz + esp_sz + cpd.iv_sz) |
| 1179 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1180 | err = ESP_DECRYPT_ERROR_RUNT; |
| 1181 | esp_set_next_index (b[0], node, err, n_noop, noop_nexts, |
| 1182 | ESP_DECRYPT_NEXT_DROP); |
Damjan Marion | a829b13 | 2019-04-24 23:39:16 +0200 | [diff] [blame] | 1183 | goto next; |
| 1184 | } |
| 1185 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1186 | len = pd->current_length - cpd.icv_sz; |
| 1187 | current_sa_pkts += 1; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1188 | current_sa_bytes += vlib_buffer_length_in_chain (vm, b[0]); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1189 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1190 | if (is_async) |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1191 | { |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1192 | async_op = sa0->crypto_async_dec_op_id; |
| 1193 | |
| 1194 | /* get a frame for this op if we don't yet have one or it's full |
| 1195 | */ |
| 1196 | if (NULL == async_frames[async_op] || |
| 1197 | vnet_crypto_async_frame_is_full (async_frames[async_op])) |
| 1198 | { |
| 1199 | async_frames[async_op] = |
| 1200 | vnet_crypto_async_get_frame (vm, async_op); |
| 1201 | /* Save the frame to the list we'll submit at the end */ |
| 1202 | vec_add1 (ptd->async_frames, async_frames[async_op]); |
| 1203 | } |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1204 | |
| 1205 | err = esp_decrypt_prepare_async_frame ( |
| 1206 | vm, node, ptd, async_frames[async_op], sa0, payload, len, |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1207 | cpd.icv_sz, cpd.iv_sz, pd, pd2, from[b - bufs], b[0], async_next, |
| 1208 | async_next_node); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1209 | if (ESP_DECRYPT_ERROR_RX_PKTS != err) |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1210 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1211 | esp_set_next_index (b[0], node, err, n_noop, noop_nexts, |
| 1212 | ESP_DECRYPT_NEXT_DROP); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1213 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1214 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1215 | else |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1216 | esp_decrypt_prepare_sync_op ( |
| 1217 | vm, node, ptd, &crypto_ops, &integ_ops, op, sa0, payload, len, |
| 1218 | cpd.icv_sz, cpd.iv_sz, pd, pd2, b[0], sync_next, b - bufs); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1219 | /* next */ |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1220 | next: |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1221 | if (ESP_DECRYPT_ERROR_RX_PKTS != err) |
| 1222 | { |
| 1223 | noop_bi[n_noop] = from[b - bufs]; |
| 1224 | n_noop++; |
| 1225 | noop_next++; |
| 1226 | } |
| 1227 | else if (!is_async) |
| 1228 | { |
| 1229 | sync_bi[n_sync] = from[b - bufs]; |
| 1230 | sync_bufs[n_sync] = b[0]; |
| 1231 | n_sync++; |
| 1232 | sync_next++; |
| 1233 | pd += 1; |
| 1234 | pd2 += 1; |
| 1235 | } |
| 1236 | else |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1237 | async_next++; |
| 1238 | |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1239 | n_left -= 1; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1240 | b += 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1241 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1242 | |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 1243 | if (PREDICT_TRUE (~0 != current_sa_index)) |
| 1244 | vlib_increment_combined_counter (&ipsec_sa_counters, thread_index, |
| 1245 | current_sa_index, current_sa_pkts, |
| 1246 | current_sa_bytes); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1247 | |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1248 | /* submit or free all of the open frames */ |
| 1249 | vnet_crypto_async_frame_t **async_frame; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1250 | |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1251 | vec_foreach (async_frame, ptd->async_frames) |
| 1252 | { |
| 1253 | /* free frame and move on if no ops were successfully added */ |
| 1254 | if (PREDICT_FALSE (!(*async_frame)->n_elts)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1255 | { |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1256 | vnet_crypto_async_free_frame (vm, *async_frame); |
| 1257 | continue; |
| 1258 | } |
| 1259 | if (vnet_crypto_async_submit_open_frame (vm, *async_frame) < 0) |
| 1260 | { |
| 1261 | n_noop += esp_async_recycle_failed_submit ( |
| 1262 | vm, *async_frame, node, ESP_DECRYPT_ERROR_CRYPTO_ENGINE_ERROR, |
Matthew Smith | c14b8cf | 2021-12-01 20:02:35 +0000 | [diff] [blame] | 1263 | n_noop, noop_bi, noop_nexts, ESP_DECRYPT_NEXT_DROP); |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1264 | vnet_crypto_async_reset_frame (*async_frame); |
| 1265 | vnet_crypto_async_free_frame (vm, *async_frame); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1266 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1267 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1268 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1269 | if (n_sync) |
| 1270 | { |
| 1271 | esp_process_ops (vm, node, ptd->integ_ops, sync_bufs, sync_nexts, |
| 1272 | ESP_DECRYPT_ERROR_INTEG_ERROR); |
| 1273 | esp_process_chained_ops (vm, node, ptd->chained_integ_ops, sync_bufs, |
| 1274 | sync_nexts, ptd->chunks, |
| 1275 | ESP_DECRYPT_ERROR_INTEG_ERROR); |
| 1276 | |
| 1277 | esp_process_ops (vm, node, ptd->crypto_ops, sync_bufs, sync_nexts, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1278 | ESP_DECRYPT_ERROR_DECRYPTION_FAILED); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1279 | esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, sync_bufs, |
| 1280 | sync_nexts, ptd->chunks, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1281 | ESP_DECRYPT_ERROR_DECRYPTION_FAILED); |
| 1282 | } |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1283 | |
| 1284 | /* Post decryption ronud - adjust packet data start and length and next |
| 1285 | node */ |
| 1286 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1287 | n_left = n_sync; |
| 1288 | sync_next = sync_nexts; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1289 | pd = pkt_data; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1290 | pd2 = pkt_data2; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1291 | b = sync_bufs; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1292 | |
| 1293 | while (n_left) |
| 1294 | { |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1295 | if (n_left >= 2) |
| 1296 | { |
| 1297 | void *data = b[1]->data + pd[1].current_data; |
| 1298 | |
| 1299 | /* buffer metadata */ |
| 1300 | vlib_prefetch_buffer_header (b[1], LOAD); |
| 1301 | |
| 1302 | /* esp_footer_t */ |
| 1303 | CLIB_PREFETCH (data + pd[1].current_length - pd[1].icv_sz - 2, |
| 1304 | CLIB_CACHE_LINE_BYTES, LOAD); |
| 1305 | |
| 1306 | /* packet headers */ |
| 1307 | CLIB_PREFETCH (data - CLIB_CACHE_LINE_BYTES, |
| 1308 | CLIB_CACHE_LINE_BYTES * 2, LOAD); |
| 1309 | } |
| 1310 | |
Christian Hopps | d570e53 | 2020-08-25 12:40:40 -0400 | [diff] [blame] | 1311 | /* save the sa_index as GRE_teb post_crypto changes L2 opaque */ |
| 1312 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 1313 | current_sa_index = vnet_buffer (b[0])->ipsec.sad_index; |
| 1314 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1315 | if (sync_next[0] >= ESP_DECRYPT_N_NEXT) |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 1316 | esp_decrypt_post_crypto (vm, node, next_by_next_header, pd, pd2, b[0], |
| 1317 | sync_next, is_ip6, is_tun, 0); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1318 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1319 | /* trace: */ |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1320 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 1321 | { |
| 1322 | esp_decrypt_trace_t *tr; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1323 | tr = vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 1324 | sa0 = ipsec_sa_get (current_sa_index); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1325 | tr->crypto_alg = sa0->crypto_alg; |
| 1326 | tr->integ_alg = sa0->integ_alg; |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 1327 | tr->seq = pd->seq; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 1328 | tr->sa_seq = sa0->seq; |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 1329 | tr->sa_seq_hi = sa0->seq_hi; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 1330 | tr->pkt_seq_hi = pd->seq_hi; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | /* next */ |
| 1334 | n_left -= 1; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1335 | sync_next += 1; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1336 | pd += 1; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1337 | pd2 += 1; |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1338 | b += 1; |
| 1339 | } |
| 1340 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1341 | vlib_node_increment_counter (vm, node->node_index, ESP_DECRYPT_ERROR_RX_PKTS, |
| 1342 | from_frame->n_vectors); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1343 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1344 | if (n_sync) |
| 1345 | vlib_buffer_enqueue_to_next (vm, node, sync_bi, sync_nexts, n_sync); |
Damjan Marion | b4fff3a | 2019-03-25 15:54:40 +0100 | [diff] [blame] | 1346 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1347 | if (n_noop) |
| 1348 | vlib_buffer_enqueue_to_next (vm, node, noop_bi, noop_nexts, n_noop); |
| 1349 | |
| 1350 | return (from_frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1353 | always_inline uword |
| 1354 | esp_decrypt_post_inline (vlib_main_t * vm, |
| 1355 | vlib_node_runtime_t * node, |
| 1356 | vlib_frame_t * from_frame, int is_ip6, int is_tun) |
| 1357 | { |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 1358 | const ipsec_main_t *im = &ipsec_main; |
| 1359 | const u16 *next_by_next_header = im->next_header_registrations; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1360 | u32 *from = vlib_frame_vector_args (from_frame); |
| 1361 | u32 n_left = from_frame->n_vectors; |
| 1362 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 1363 | u16 nexts[VLIB_FRAME_SIZE], *next = nexts; |
| 1364 | vlib_get_buffers (vm, from, b, n_left); |
| 1365 | |
| 1366 | while (n_left > 0) |
| 1367 | { |
| 1368 | esp_decrypt_packet_data_t *pd = &(esp_post_data (b[0]))->decrypt_data; |
| 1369 | |
| 1370 | if (n_left > 2) |
| 1371 | { |
| 1372 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 1373 | vlib_prefetch_buffer_header (b[1], LOAD); |
| 1374 | } |
| 1375 | |
| 1376 | if (!pd->is_chain) |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 1377 | esp_decrypt_post_crypto (vm, node, next_by_next_header, pd, 0, b[0], |
| 1378 | next, is_ip6, is_tun, 1); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1379 | else |
| 1380 | { |
| 1381 | esp_decrypt_packet_data2_t *pd2 = esp_post_data2 (b[0]); |
Benoît Ganne | 98ca76a | 2022-04-11 18:51:25 +0200 | [diff] [blame^] | 1382 | esp_decrypt_post_crypto (vm, node, next_by_next_header, pd, pd2, |
| 1383 | b[0], next, is_ip6, is_tun, 1); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /*trace: */ |
| 1387 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 1388 | { |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 1389 | ipsec_sa_t *sa0 = ipsec_sa_get (pd->sa_index); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1390 | esp_decrypt_trace_t *tr; |
| 1391 | esp_decrypt_packet_data_t *async_pd = |
| 1392 | &(esp_post_data (b[0]))->decrypt_data; |
| 1393 | tr = vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 1394 | sa0 = ipsec_sa_get (async_pd->sa_index); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1395 | |
| 1396 | tr->crypto_alg = sa0->crypto_alg; |
| 1397 | tr->integ_alg = sa0->integ_alg; |
| 1398 | tr->seq = pd->seq; |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 1399 | tr->sa_seq = sa0->seq; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1400 | tr->sa_seq_hi = sa0->seq_hi; |
| 1401 | } |
| 1402 | |
| 1403 | n_left--; |
| 1404 | next++; |
| 1405 | b++; |
| 1406 | } |
| 1407 | |
| 1408 | n_left = from_frame->n_vectors; |
| 1409 | vlib_node_increment_counter (vm, node->node_index, |
| 1410 | ESP_DECRYPT_ERROR_RX_POST_PKTS, n_left); |
| 1411 | |
| 1412 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left); |
| 1413 | |
| 1414 | return n_left; |
| 1415 | } |
| 1416 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 1417 | VLIB_NODE_FN (esp4_decrypt_node) (vlib_main_t * vm, |
| 1418 | vlib_node_runtime_t * node, |
| 1419 | vlib_frame_t * from_frame) |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1420 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1421 | return esp_decrypt_inline (vm, node, from_frame, 0, 0, |
| 1422 | esp_decrypt_async_next.esp4_post_next); |
| 1423 | } |
| 1424 | |
| 1425 | VLIB_NODE_FN (esp4_decrypt_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, 0, 0); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | VLIB_NODE_FN (esp4_decrypt_tun_node) (vlib_main_t * vm, |
| 1433 | vlib_node_runtime_t * node, |
| 1434 | vlib_frame_t * from_frame) |
| 1435 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1436 | return esp_decrypt_inline (vm, node, from_frame, 0, 1, |
| 1437 | esp_decrypt_async_next.esp4_tun_post_next); |
| 1438 | } |
| 1439 | |
| 1440 | VLIB_NODE_FN (esp4_decrypt_tun_post_node) (vlib_main_t * vm, |
| 1441 | vlib_node_runtime_t * node, |
| 1442 | vlib_frame_t * from_frame) |
| 1443 | { |
| 1444 | return esp_decrypt_post_inline (vm, node, from_frame, 0, 1); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | VLIB_NODE_FN (esp6_decrypt_node) (vlib_main_t * vm, |
| 1448 | vlib_node_runtime_t * node, |
| 1449 | vlib_frame_t * from_frame) |
| 1450 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1451 | return esp_decrypt_inline (vm, node, from_frame, 1, 0, |
| 1452 | esp_decrypt_async_next.esp6_post_next); |
| 1453 | } |
| 1454 | |
| 1455 | VLIB_NODE_FN (esp6_decrypt_post_node) (vlib_main_t * vm, |
| 1456 | vlib_node_runtime_t * node, |
| 1457 | vlib_frame_t * from_frame) |
| 1458 | { |
| 1459 | return esp_decrypt_post_inline (vm, node, from_frame, 1, 0); |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | VLIB_NODE_FN (esp6_decrypt_tun_node) (vlib_main_t * vm, |
| 1463 | vlib_node_runtime_t * node, |
| 1464 | vlib_frame_t * from_frame) |
| 1465 | { |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1466 | return esp_decrypt_inline (vm, node, from_frame, 1, 1, |
| 1467 | esp_decrypt_async_next.esp6_tun_post_next); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1468 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1469 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1470 | VLIB_NODE_FN (esp6_decrypt_tun_post_node) (vlib_main_t * vm, |
| 1471 | vlib_node_runtime_t * node, |
| 1472 | vlib_frame_t * from_frame) |
| 1473 | { |
| 1474 | return esp_decrypt_post_inline (vm, node, from_frame, 1, 1); |
| 1475 | } |
| 1476 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1477 | /* *INDENT-OFF* */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1478 | VLIB_REGISTER_NODE (esp4_decrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1479 | .name = "esp4-decrypt", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1480 | .vector_size = sizeof (u32), |
| 1481 | .format_trace = format_esp_decrypt_trace, |
| 1482 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1483 | |
| 1484 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1485 | .error_strings = esp_decrypt_error_strings, |
| 1486 | |
| 1487 | .n_next_nodes = ESP_DECRYPT_N_NEXT, |
| 1488 | .next_nodes = { |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1489 | [ESP_DECRYPT_NEXT_DROP] = "ip4-drop", |
| 1490 | [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum", |
| 1491 | [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1492 | [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop", |
Neale Ranns | 568acbb | 2019-12-18 05:54:40 +0000 | [diff] [blame] | 1493 | [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input", |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1494 | [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-handoff", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1495 | }, |
| 1496 | }; |
| 1497 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1498 | VLIB_REGISTER_NODE (esp4_decrypt_post_node) = { |
| 1499 | .name = "esp4-decrypt-post", |
| 1500 | .vector_size = sizeof (u32), |
| 1501 | .format_trace = format_esp_decrypt_trace, |
| 1502 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1503 | |
| 1504 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1505 | .error_strings = esp_decrypt_error_strings, |
| 1506 | |
| 1507 | .sibling_of = "esp4-decrypt", |
| 1508 | }; |
| 1509 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1510 | VLIB_REGISTER_NODE (esp6_decrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1511 | .name = "esp6-decrypt", |
| 1512 | .vector_size = sizeof (u32), |
| 1513 | .format_trace = format_esp_decrypt_trace, |
| 1514 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1515 | |
| 1516 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1517 | .error_strings = esp_decrypt_error_strings, |
| 1518 | |
| 1519 | .n_next_nodes = ESP_DECRYPT_N_NEXT, |
| 1520 | .next_nodes = { |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1521 | [ESP_DECRYPT_NEXT_DROP] = "ip6-drop", |
| 1522 | [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum", |
| 1523 | [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1524 | [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-drop", |
Neale Ranns | 568acbb | 2019-12-18 05:54:40 +0000 | [diff] [blame] | 1525 | [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input", |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1526 | [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-handoff", |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1527 | }, |
| 1528 | }; |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1529 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1530 | VLIB_REGISTER_NODE (esp6_decrypt_post_node) = { |
| 1531 | .name = "esp6-decrypt-post", |
| 1532 | .vector_size = sizeof (u32), |
| 1533 | .format_trace = format_esp_decrypt_trace, |
| 1534 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1535 | |
| 1536 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1537 | .error_strings = esp_decrypt_error_strings, |
| 1538 | |
| 1539 | .sibling_of = "esp6-decrypt", |
| 1540 | }; |
| 1541 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1542 | VLIB_REGISTER_NODE (esp4_decrypt_tun_node) = { |
| 1543 | .name = "esp4-decrypt-tun", |
| 1544 | .vector_size = sizeof (u32), |
| 1545 | .format_trace = format_esp_decrypt_trace, |
| 1546 | .type = VLIB_NODE_TYPE_INTERNAL, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1547 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1548 | .error_strings = esp_decrypt_error_strings, |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1549 | .n_next_nodes = ESP_DECRYPT_N_NEXT, |
| 1550 | .next_nodes = { |
| 1551 | [ESP_DECRYPT_NEXT_DROP] = "ip4-drop", |
| 1552 | [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum", |
| 1553 | [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1554 | [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input", |
Neale Ranns | 568acbb | 2019-12-18 05:54:40 +0000 | [diff] [blame] | 1555 | [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input", |
Neale Ranns | 4a56f4e | 2019-12-23 04:10:25 +0000 | [diff] [blame] | 1556 | [ESP_DECRYPT_NEXT_HANDOFF] = "esp4-decrypt-tun-handoff", |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1557 | }, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1558 | }; |
| 1559 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1560 | VLIB_REGISTER_NODE (esp4_decrypt_tun_post_node) = { |
| 1561 | .name = "esp4-decrypt-tun-post", |
| 1562 | .vector_size = sizeof (u32), |
| 1563 | .format_trace = format_esp_decrypt_trace, |
| 1564 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1565 | |
| 1566 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1567 | .error_strings = esp_decrypt_error_strings, |
| 1568 | |
| 1569 | .sibling_of = "esp4-decrypt-tun", |
| 1570 | }; |
| 1571 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1572 | VLIB_REGISTER_NODE (esp6_decrypt_tun_node) = { |
| 1573 | .name = "esp6-decrypt-tun", |
| 1574 | .vector_size = sizeof (u32), |
| 1575 | .format_trace = format_esp_decrypt_trace, |
| 1576 | .type = VLIB_NODE_TYPE_INTERNAL, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1577 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1578 | .error_strings = esp_decrypt_error_strings, |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1579 | .n_next_nodes = ESP_DECRYPT_N_NEXT, |
| 1580 | .next_nodes = { |
| 1581 | [ESP_DECRYPT_NEXT_DROP] = "ip6-drop", |
| 1582 | [ESP_DECRYPT_NEXT_IP4_INPUT] = "ip4-input-no-checksum", |
| 1583 | [ESP_DECRYPT_NEXT_IP6_INPUT] = "ip6-input", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1584 | [ESP_DECRYPT_NEXT_MPLS_INPUT] = "mpls-input", |
Neale Ranns | 568acbb | 2019-12-18 05:54:40 +0000 | [diff] [blame] | 1585 | [ESP_DECRYPT_NEXT_L2_INPUT] = "l2-input", |
Neale Ranns | 4a56f4e | 2019-12-23 04:10:25 +0000 | [diff] [blame] | 1586 | [ESP_DECRYPT_NEXT_HANDOFF]= "esp6-decrypt-tun-handoff", |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1587 | }, |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 1588 | }; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1589 | |
| 1590 | VLIB_REGISTER_NODE (esp6_decrypt_tun_post_node) = { |
| 1591 | .name = "esp6-decrypt-tun-post", |
| 1592 | .vector_size = sizeof (u32), |
| 1593 | .format_trace = format_esp_decrypt_trace, |
| 1594 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1595 | |
| 1596 | .n_errors = ARRAY_LEN(esp_decrypt_error_strings), |
| 1597 | .error_strings = esp_decrypt_error_strings, |
| 1598 | |
| 1599 | .sibling_of = "esp6-decrypt-tun", |
| 1600 | }; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1601 | /* *INDENT-ON* */ |
| 1602 | |
Neale Ranns | 2d49830 | 2021-02-25 08:38:58 +0000 | [diff] [blame] | 1603 | #ifndef CLIB_MARCH_VARIANT |
| 1604 | |
| 1605 | static clib_error_t * |
| 1606 | esp_decrypt_init (vlib_main_t *vm) |
| 1607 | { |
| 1608 | ipsec_main_t *im = &ipsec_main; |
| 1609 | |
| 1610 | im->esp4_dec_fq_index = |
| 1611 | vlib_frame_queue_main_init (esp4_decrypt_node.index, 0); |
| 1612 | im->esp6_dec_fq_index = |
| 1613 | vlib_frame_queue_main_init (esp6_decrypt_node.index, 0); |
| 1614 | im->esp4_dec_tun_fq_index = |
| 1615 | vlib_frame_queue_main_init (esp4_decrypt_tun_node.index, 0); |
| 1616 | im->esp6_dec_tun_fq_index = |
| 1617 | vlib_frame_queue_main_init (esp6_decrypt_tun_node.index, 0); |
| 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | VLIB_INIT_FUNCTION (esp_decrypt_init); |
| 1623 | |
| 1624 | #endif |
| 1625 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1626 | /* |
| 1627 | * fd.io coding-style-patch-verification: ON |
| 1628 | * |
| 1629 | * Local Variables: |
| 1630 | * eval: (c-set-style "gnu") |
| 1631 | * End: |
| 1632 | */ |