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