Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * esp_encrypt.c : IPSec ESP encrypt node |
| 3 | * |
| 4 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/vnet.h> |
| 19 | #include <vnet/api_errno.h> |
| 20 | #include <vnet/ip/ip.h> |
| 21 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 22 | #include <vnet/crypto/crypto.h> |
| 23 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | #include <vnet/ipsec/ipsec.h> |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [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 | #include <vnet/ipsec/esp.h> |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 28 | #include <vnet/tunnel/tunnel_dp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 30 | #define foreach_esp_encrypt_next \ |
| 31 | _ (DROP4, "ip4-drop") \ |
| 32 | _ (DROP6, "ip6-drop") \ |
| 33 | _ (DROP_MPLS, "mpls-drop") \ |
| 34 | _ (HANDOFF4, "handoff4") \ |
| 35 | _ (HANDOFF6, "handoff6") \ |
| 36 | _ (HANDOFF_MPLS, "handoff-mpls") \ |
| 37 | _ (INTERFACE_OUTPUT, "interface-output") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | |
| 39 | #define _(v, s) ESP_ENCRYPT_NEXT_##v, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 40 | typedef enum |
| 41 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | foreach_esp_encrypt_next |
| 43 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 44 | ESP_ENCRYPT_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | } esp_encrypt_next_t; |
| 46 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 47 | typedef struct |
| 48 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 49 | u32 sa_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | u32 spi; |
| 51 | u32 seq; |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 52 | u32 sa_seq_hi; |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 53 | u8 udp_encap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | ipsec_crypto_alg_t crypto_alg; |
| 55 | ipsec_integ_alg_t integ_alg; |
| 56 | } esp_encrypt_trace_t; |
| 57 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 58 | typedef struct |
| 59 | { |
| 60 | u32 next_index; |
| 61 | } esp_encrypt_post_trace_t; |
| 62 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 63 | typedef vl_counter_esp_encrypt_enum_t esp_encrypt_error_t; |
| 64 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | /* packet trace format function */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 66 | static u8 * |
| 67 | format_esp_encrypt_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | { |
| 69 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 70 | 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] | 71 | esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | |
Guillaume Solignac | 8f818cc | 2019-05-15 12:02:33 +0200 | [diff] [blame] | 73 | s = |
| 74 | format (s, |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 75 | "esp: sa-index %d spi %u (0x%08x) seq %u sa-seq-hi %u crypto %U integrity %U%s", |
| 76 | t->sa_index, t->spi, t->spi, t->seq, t->sa_seq_hi, |
| 77 | format_ipsec_crypto_alg, |
Guillaume Solignac | 8f818cc | 2019-05-15 12:02:33 +0200 | [diff] [blame] | 78 | t->crypto_alg, format_ipsec_integ_alg, t->integ_alg, |
| 79 | t->udp_encap ? " udp-encap-enabled" : ""); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | return s; |
| 81 | } |
| 82 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 83 | static u8 * |
| 84 | format_esp_post_encrypt_trace (u8 * s, va_list * args) |
| 85 | { |
| 86 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 87 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 88 | esp_encrypt_post_trace_t *t = va_arg (*args, esp_encrypt_post_trace_t *); |
| 89 | |
| 90 | s = format (s, "esp-post: next node index %u", t->next_index); |
| 91 | return s; |
| 92 | } |
| 93 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 94 | /* pad packet in input buffer */ |
| 95 | static_always_inline u8 * |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 96 | esp_add_footer_and_icv (vlib_main_t *vm, vlib_buffer_t **last, u8 esp_align, |
| 97 | u8 icv_sz, vlib_node_runtime_t *node, |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 98 | u16 buffer_data_size, uword total_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 100 | static const u8 pad_data[ESP_MAX_BLOCK_SIZE] = { |
| 101 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
Milan Lenco | 7885c74 | 2020-08-20 13:23:09 +0200 | [diff] [blame] | 102 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 103 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 105 | u16 min_length = total_len + sizeof (esp_footer_t); |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 106 | u16 new_length = round_pow2 (min_length, esp_align); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 107 | u8 pad_bytes = new_length - min_length; |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 108 | esp_footer_t *f = (esp_footer_t *) (vlib_buffer_get_current (last[0]) + |
| 109 | last[0]->current_length + pad_bytes); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 110 | u16 tail_sz = sizeof (esp_footer_t) + pad_bytes + icv_sz; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | |
Benoît Ganne | 217ba5a | 2021-06-14 17:23:56 +0200 | [diff] [blame] | 112 | if (last[0]->current_data + last[0]->current_length + tail_sz > |
| 113 | buffer_data_size) |
Filip Tehlar | 8cdb1a0 | 2019-11-18 22:21:37 +0000 | [diff] [blame] | 114 | { |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 115 | u32 tmp_bi = 0; |
| 116 | if (vlib_buffer_alloc (vm, &tmp_bi, 1) != 1) |
| 117 | return 0; |
Filip Tehlar | c2c1bfd | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 118 | |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 119 | vlib_buffer_t *tmp = vlib_get_buffer (vm, tmp_bi); |
| 120 | last[0]->next_buffer = tmp_bi; |
| 121 | last[0]->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 122 | f = (esp_footer_t *) (vlib_buffer_get_current (tmp) + pad_bytes); |
| 123 | tmp->current_length += tail_sz; |
| 124 | last[0] = tmp; |
| 125 | } |
| 126 | else |
| 127 | last[0]->current_length += tail_sz; |
| 128 | |
| 129 | f->pad_length = pad_bytes; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 130 | if (pad_bytes) |
Benoît Ganne | 4505f01 | 2019-12-07 09:14:27 -0700 | [diff] [blame] | 131 | { |
| 132 | ASSERT (pad_bytes <= ESP_MAX_BLOCK_SIZE); |
| 133 | pad_bytes = clib_min (ESP_MAX_BLOCK_SIZE, pad_bytes); |
| 134 | clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, pad_bytes); |
| 135 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 136 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 137 | return &f->next_header; |
| 138 | } |
| 139 | |
| 140 | static_always_inline void |
| 141 | esp_update_ip4_hdr (ip4_header_t * ip4, u16 len, int is_transport, int is_udp) |
| 142 | { |
Neale Ranns | 1b582b8 | 2019-04-18 19:49:13 -0700 | [diff] [blame] | 143 | ip_csum_t sum; |
| 144 | u16 old_len; |
| 145 | |
| 146 | len = clib_net_to_host_u16 (len); |
| 147 | old_len = ip4->length; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 148 | |
| 149 | if (is_transport) |
| 150 | { |
| 151 | u8 prot = is_udp ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 152 | |
Neale Ranns | 1b582b8 | 2019-04-18 19:49:13 -0700 | [diff] [blame] | 153 | sum = ip_csum_update (ip4->checksum, ip4->protocol, |
| 154 | prot, ip4_header_t, protocol); |
| 155 | ip4->protocol = prot; |
| 156 | |
| 157 | sum = ip_csum_update (sum, old_len, len, ip4_header_t, length); |
| 158 | } |
| 159 | else |
| 160 | sum = ip_csum_update (ip4->checksum, old_len, len, ip4_header_t, length); |
| 161 | |
| 162 | ip4->length = len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 163 | ip4->checksum = ip_csum_fold (sum); |
| 164 | } |
| 165 | |
| 166 | static_always_inline void |
| 167 | esp_fill_udp_hdr (ipsec_sa_t * sa, udp_header_t * udp, u16 len) |
| 168 | { |
| 169 | clib_memcpy_fast (udp, &sa->udp_hdr, sizeof (udp_header_t)); |
| 170 | udp->length = clib_net_to_host_u16 (len); |
| 171 | } |
| 172 | |
| 173 | static_always_inline u8 |
| 174 | ext_hdr_is_pre_esp (u8 nexthdr) |
| 175 | { |
| 176 | #ifdef CLIB_HAVE_VEC128 |
| 177 | static const u8x16 ext_hdr_types = { |
| 178 | IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS, |
| 179 | IP_PROTOCOL_IPV6_ROUTE, |
| 180 | IP_PROTOCOL_IPV6_FRAGMENTATION, |
| 181 | }; |
| 182 | |
| 183 | return !u8x16_is_all_zero (ext_hdr_types == u8x16_splat (nexthdr)); |
| 184 | #else |
Piotr Bronowski | 3a6bc6f | 2023-02-23 09:56:49 +0000 | [diff] [blame] | 185 | return (!(nexthdr ^ IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) || |
| 186 | !(nexthdr ^ IP_PROTOCOL_IPV6_ROUTE) || |
| 187 | !(nexthdr ^ IP_PROTOCOL_IPV6_FRAGMENTATION)); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 188 | #endif |
| 189 | } |
| 190 | |
| 191 | static_always_inline u8 |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 192 | esp_get_ip6_hdr_len (ip6_header_t * ip6, ip6_ext_header_t ** ext_hdr) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 193 | { |
| 194 | /* this code assumes that HbH, route and frag headers will be before |
| 195 | others, if that is not the case, they will end up encrypted */ |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 196 | u8 len = sizeof (ip6_header_t); |
| 197 | ip6_ext_header_t *p; |
| 198 | |
| 199 | /* if next packet doesn't have ext header */ |
| 200 | if (ext_hdr_is_pre_esp (ip6->protocol) == 0) |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 201 | { |
| 202 | *ext_hdr = NULL; |
| 203 | return len; |
| 204 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 205 | |
Ole Troan | 03092c1 | 2021-11-23 15:55:39 +0100 | [diff] [blame] | 206 | p = ip6_next_header (ip6); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 207 | len += ip6_ext_header_len (p); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 208 | while (ext_hdr_is_pre_esp (p->next_hdr)) |
| 209 | { |
| 210 | len += ip6_ext_header_len (p); |
| 211 | p = ip6_ext_next_header (p); |
| 212 | } |
| 213 | |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 214 | *ext_hdr = p; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 215 | return len; |
| 216 | } |
| 217 | |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 218 | /* IPsec IV generation: IVs requirements differ depending of the |
| 219 | * encryption mode: IVs must be unpredictable for AES-CBC whereas it can |
| 220 | * be predictable but should never be reused with the same key material |
| 221 | * for CTR and GCM. |
Benoît Ganne | 5527a78 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 222 | * To avoid reusing the same IVs between multiple VPP instances and between |
| 223 | * restarts, we use a properly chosen PRNG to generate IVs. To ensure the IV is |
| 224 | * unpredictable for CBC, it is then encrypted using the same key as the |
| 225 | * message. You can refer to NIST SP800-38a and NIST SP800-38d for more |
| 226 | * details. */ |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 227 | static_always_inline void * |
| 228 | esp_generate_iv (ipsec_sa_t *sa, void *payload, int iv_sz) |
| 229 | { |
| 230 | ASSERT (iv_sz >= sizeof (u64)); |
| 231 | u64 *iv = (u64 *) (payload - iv_sz); |
| 232 | clib_memset_u8 (iv, 0, iv_sz); |
Benoît Ganne | 5527a78 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 233 | *iv = clib_pcg64i_random_r (&sa->iv_prng); |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 234 | return iv; |
| 235 | } |
| 236 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 237 | static_always_inline void |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 238 | esp_process_chained_ops (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 239 | vnet_crypto_op_t * ops, vlib_buffer_t * b[], |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 240 | u16 * nexts, vnet_crypto_op_chunk_t * chunks, |
| 241 | u16 drop_next) |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 242 | { |
| 243 | u32 n_fail, n_ops = vec_len (ops); |
| 244 | vnet_crypto_op_t *op = ops; |
| 245 | |
| 246 | if (n_ops == 0) |
| 247 | return; |
| 248 | |
| 249 | n_fail = n_ops - vnet_crypto_process_chained_ops (vm, op, chunks, n_ops); |
| 250 | |
| 251 | while (n_fail) |
| 252 | { |
| 253 | ASSERT (op - ops < n_ops); |
| 254 | |
| 255 | if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED) |
| 256 | { |
| 257 | u32 bi = op->user_data; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 258 | esp_encrypt_set_next_index (b[bi], node, vm->thread_index, |
| 259 | ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR, |
| 260 | bi, nexts, drop_next, |
| 261 | vnet_buffer (b[bi])->ipsec.sad_index); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 262 | n_fail--; |
| 263 | } |
| 264 | op++; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | static_always_inline void |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 269 | esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node, |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 270 | vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts, |
| 271 | u16 drop_next) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 272 | { |
| 273 | u32 n_fail, n_ops = vec_len (ops); |
| 274 | vnet_crypto_op_t *op = ops; |
| 275 | |
| 276 | if (n_ops == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | return; |
| 278 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 279 | n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 281 | while (n_fail) |
| 282 | { |
| 283 | ASSERT (op - ops < n_ops); |
| 284 | |
| 285 | if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED) |
| 286 | { |
| 287 | u32 bi = op->user_data; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 288 | esp_encrypt_set_next_index (b[bi], node, vm->thread_index, |
| 289 | ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR, |
| 290 | bi, nexts, drop_next, |
| 291 | vnet_buffer (b[bi])->ipsec.sad_index); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 292 | n_fail--; |
| 293 | } |
| 294 | op++; |
| 295 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 298 | static_always_inline u32 |
| 299 | esp_encrypt_chain_crypto (vlib_main_t * vm, ipsec_per_thread_data_t * ptd, |
| 300 | ipsec_sa_t * sa0, vlib_buffer_t * b, |
| 301 | vlib_buffer_t * lb, u8 icv_sz, u8 * start, |
| 302 | u32 start_len, u16 * n_ch) |
| 303 | { |
| 304 | vnet_crypto_op_chunk_t *ch; |
| 305 | vlib_buffer_t *cb = b; |
| 306 | u32 n_chunks = 1; |
| 307 | u32 total_len; |
| 308 | vec_add2 (ptd->chunks, ch, 1); |
| 309 | total_len = ch->len = start_len; |
| 310 | ch->src = ch->dst = start; |
| 311 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 312 | |
| 313 | while (1) |
| 314 | { |
| 315 | vec_add2 (ptd->chunks, ch, 1); |
| 316 | n_chunks += 1; |
| 317 | if (lb == cb) |
| 318 | total_len += ch->len = cb->current_length - icv_sz; |
| 319 | else |
| 320 | total_len += ch->len = cb->current_length; |
| 321 | ch->src = ch->dst = vlib_buffer_get_current (cb); |
| 322 | |
| 323 | if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 324 | break; |
| 325 | |
| 326 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 327 | } |
| 328 | |
| 329 | if (n_ch) |
| 330 | *n_ch = n_chunks; |
| 331 | |
| 332 | return total_len; |
| 333 | } |
| 334 | |
| 335 | static_always_inline u32 |
| 336 | esp_encrypt_chain_integ (vlib_main_t * vm, ipsec_per_thread_data_t * ptd, |
| 337 | ipsec_sa_t * sa0, vlib_buffer_t * b, |
| 338 | vlib_buffer_t * lb, u8 icv_sz, u8 * start, |
| 339 | u32 start_len, u8 * digest, u16 * n_ch) |
| 340 | { |
| 341 | vnet_crypto_op_chunk_t *ch; |
| 342 | vlib_buffer_t *cb = b; |
| 343 | u32 n_chunks = 1; |
| 344 | u32 total_len; |
| 345 | vec_add2 (ptd->chunks, ch, 1); |
| 346 | total_len = ch->len = start_len; |
| 347 | ch->src = start; |
| 348 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 349 | |
| 350 | while (1) |
| 351 | { |
| 352 | vec_add2 (ptd->chunks, ch, 1); |
| 353 | n_chunks += 1; |
| 354 | if (lb == cb) |
| 355 | { |
| 356 | total_len += ch->len = cb->current_length - icv_sz; |
| 357 | if (ipsec_sa_is_set_USE_ESN (sa0)) |
| 358 | { |
| 359 | u32 seq_hi = clib_net_to_host_u32 (sa0->seq_hi); |
| 360 | clib_memcpy_fast (digest, &seq_hi, sizeof (seq_hi)); |
| 361 | ch->len += sizeof (seq_hi); |
| 362 | total_len += sizeof (seq_hi); |
| 363 | } |
| 364 | } |
| 365 | else |
| 366 | total_len += ch->len = cb->current_length; |
| 367 | ch->src = vlib_buffer_get_current (cb); |
| 368 | |
| 369 | if (!(cb->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 370 | break; |
| 371 | |
| 372 | cb = vlib_get_buffer (vm, cb->next_buffer); |
| 373 | } |
| 374 | |
| 375 | if (n_ch) |
| 376 | *n_ch = n_chunks; |
| 377 | |
| 378 | return total_len; |
| 379 | } |
| 380 | |
| 381 | always_inline void |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 382 | esp_prepare_sync_op (vlib_main_t *vm, ipsec_per_thread_data_t *ptd, |
| 383 | vnet_crypto_op_t **crypto_ops, |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 384 | vnet_crypto_op_t **integ_ops, ipsec_sa_t *sa0, u32 seq_hi, |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 385 | u8 *payload, u16 payload_len, u8 iv_sz, u8 icv_sz, u32 bi, |
| 386 | vlib_buffer_t **b, vlib_buffer_t *lb, u32 hdr_len, |
| 387 | esp_header_t *esp) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 388 | { |
| 389 | if (sa0->crypto_enc_op_id) |
| 390 | { |
| 391 | vnet_crypto_op_t *op; |
| 392 | vec_add2_aligned (crypto_ops[0], op, 1, CLIB_CACHE_LINE_BYTES); |
| 393 | vnet_crypto_op_init (op, sa0->crypto_enc_op_id); |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 394 | u8 *crypto_start = payload; |
| 395 | /* esp_add_footer_and_icv() in esp_encrypt_inline() makes sure we always |
| 396 | * have enough space for ESP header and footer which includes ICV */ |
| 397 | ASSERT (payload_len > icv_sz); |
| 398 | u16 crypto_len = payload_len - icv_sz; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 399 | |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 400 | /* generate the IV in front of the payload */ |
| 401 | void *pkt_iv = esp_generate_iv (sa0, payload, iv_sz); |
| 402 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 403 | op->key_index = sa0->crypto_key_index; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 404 | op->user_data = bi; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 405 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 406 | if (ipsec_sa_is_set_IS_CTR (sa0)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 407 | { |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 408 | /* construct nonce in a scratch space in front of the IP header */ |
| 409 | esp_ctr_nonce_t *nonce = |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 410 | (esp_ctr_nonce_t *) (pkt_iv - hdr_len - sizeof (*nonce)); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 411 | if (ipsec_sa_is_set_IS_AEAD (sa0)) |
| 412 | { |
| 413 | /* constuct aad in a scratch space in front of the nonce */ |
| 414 | op->aad = (u8 *) nonce - sizeof (esp_aead_t); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 415 | op->aad_len = esp_aad_fill (op->aad, esp, sa0, seq_hi); |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 416 | op->tag = payload + crypto_len; |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 417 | op->tag_len = 16; |
Benoît Ganne | 84e6658 | 2023-03-10 17:33:03 +0100 | [diff] [blame^] | 418 | if (PREDICT_FALSE (ipsec_sa_is_set_IS_NULL_GMAC (sa0))) |
| 419 | { |
| 420 | /* RFC-4543 ENCR_NULL_AUTH_AES_GMAC: IV is part of AAD */ |
| 421 | crypto_start -= iv_sz; |
| 422 | crypto_len += iv_sz; |
| 423 | } |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 424 | } |
| 425 | else |
| 426 | { |
| 427 | nonce->ctr = clib_host_to_net_u32 (1); |
| 428 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 429 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 430 | nonce->salt = sa0->salt; |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 431 | nonce->iv = *(u64 *) pkt_iv; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 432 | op->iv = (u8 *) nonce; |
| 433 | } |
| 434 | else |
| 435 | { |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 436 | /* construct zero iv in front of the IP header */ |
| 437 | op->iv = pkt_iv - hdr_len - iv_sz; |
| 438 | clib_memset_u8 (op->iv, 0, iv_sz); |
| 439 | /* include iv field in crypto */ |
| 440 | crypto_start -= iv_sz; |
| 441 | crypto_len += iv_sz; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Benoît Ganne | 5527a78 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 444 | if (PREDICT_FALSE (lb != b[0])) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 445 | { |
| 446 | /* is chained */ |
| 447 | op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 448 | op->chunk_index = vec_len (ptd->chunks); |
| 449 | op->tag = vlib_buffer_get_tail (lb) - icv_sz; |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 450 | esp_encrypt_chain_crypto (vm, ptd, sa0, b[0], lb, icv_sz, |
| 451 | crypto_start, crypto_len + icv_sz, |
| 452 | &op->n_chunks); |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | /* not chained */ |
| 457 | op->src = op->dst = crypto_start; |
| 458 | op->len = crypto_len; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | if (sa0->integ_op_id) |
| 463 | { |
| 464 | vnet_crypto_op_t *op; |
| 465 | vec_add2_aligned (integ_ops[0], op, 1, CLIB_CACHE_LINE_BYTES); |
| 466 | vnet_crypto_op_init (op, sa0->integ_op_id); |
| 467 | op->src = payload - iv_sz - sizeof (esp_header_t); |
| 468 | op->digest = payload + payload_len - icv_sz; |
| 469 | op->key_index = sa0->integ_key_index; |
| 470 | op->digest_len = icv_sz; |
| 471 | op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 472 | op->user_data = bi; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 473 | |
| 474 | if (lb != b[0]) |
| 475 | { |
| 476 | /* is chained */ |
| 477 | op->flags |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 478 | op->chunk_index = vec_len (ptd->chunks); |
| 479 | op->digest = vlib_buffer_get_tail (lb) - icv_sz; |
| 480 | |
| 481 | esp_encrypt_chain_integ (vm, ptd, sa0, b[0], lb, icv_sz, |
| 482 | payload - iv_sz - sizeof (esp_header_t), |
| 483 | payload_len + iv_sz + |
| 484 | sizeof (esp_header_t), op->digest, |
| 485 | &op->n_chunks); |
| 486 | } |
| 487 | else if (ipsec_sa_is_set_USE_ESN (sa0)) |
| 488 | { |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 489 | u32 tmp = clib_net_to_host_u32 (seq_hi); |
| 490 | clib_memcpy_fast (op->digest, &tmp, sizeof (seq_hi)); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 491 | op->len += sizeof (seq_hi); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 496 | static_always_inline void |
| 497 | esp_prepare_async_frame (vlib_main_t *vm, ipsec_per_thread_data_t *ptd, |
| 498 | vnet_crypto_async_frame_t *async_frame, |
| 499 | ipsec_sa_t *sa, vlib_buffer_t *b, esp_header_t *esp, |
| 500 | u8 *payload, u32 payload_len, u8 iv_sz, u8 icv_sz, |
| 501 | u32 bi, u16 next, u32 hdr_len, u16 async_next, |
| 502 | vlib_buffer_t *lb) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 503 | { |
| 504 | esp_post_data_t *post = esp_post_data (b); |
| 505 | u8 *tag, *iv, *aad = 0; |
| 506 | u8 flag = 0; |
Benoît Ganne | 5527a78 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 507 | const u32 key_index = sa->crypto_key_index; |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 508 | i16 crypto_start_offset, integ_start_offset; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 509 | u16 crypto_total_len, integ_total_len; |
| 510 | |
Fan Zhang | 18f0e31 | 2020-10-19 13:08:34 +0100 | [diff] [blame] | 511 | post->next_index = next; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 512 | |
| 513 | /* crypto */ |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 514 | crypto_start_offset = integ_start_offset = payload - b->data; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 515 | crypto_total_len = integ_total_len = payload_len - icv_sz; |
| 516 | tag = payload + crypto_total_len; |
| 517 | |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 518 | /* generate the IV in front of the payload */ |
| 519 | void *pkt_iv = esp_generate_iv (sa, payload, iv_sz); |
| 520 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 521 | if (ipsec_sa_is_set_IS_CTR (sa)) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 522 | { |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 523 | /* construct nonce in a scratch space in front of the IP header */ |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 524 | esp_ctr_nonce_t *nonce = |
| 525 | (esp_ctr_nonce_t *) (pkt_iv - hdr_len - sizeof (*nonce)); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 526 | if (ipsec_sa_is_set_IS_AEAD (sa)) |
| 527 | { |
| 528 | /* constuct aad in a scratch space in front of the nonce */ |
| 529 | aad = (u8 *) nonce - sizeof (esp_aead_t); |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 530 | esp_aad_fill (aad, esp, sa, sa->seq_hi); |
Benoît Ganne | 84e6658 | 2023-03-10 17:33:03 +0100 | [diff] [blame^] | 531 | if (PREDICT_FALSE (ipsec_sa_is_set_IS_NULL_GMAC (sa))) |
| 532 | { |
| 533 | /* RFC-4543 ENCR_NULL_AUTH_AES_GMAC: IV is part of AAD */ |
| 534 | crypto_start_offset -= iv_sz; |
| 535 | crypto_total_len += iv_sz; |
| 536 | } |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
| 540 | nonce->ctr = clib_host_to_net_u32 (1); |
| 541 | } |
| 542 | |
| 543 | nonce->salt = sa->salt; |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 544 | nonce->iv = *(u64 *) pkt_iv; |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 545 | iv = (u8 *) nonce; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 546 | } |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 547 | else |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 548 | { |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 549 | /* construct zero iv in front of the IP header */ |
| 550 | iv = pkt_iv - hdr_len - iv_sz; |
| 551 | clib_memset_u8 (iv, 0, iv_sz); |
| 552 | /* include iv field in crypto */ |
| 553 | crypto_start_offset -= iv_sz; |
| 554 | crypto_total_len += iv_sz; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 555 | } |
| 556 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 557 | if (lb != b) |
| 558 | { |
| 559 | /* chain */ |
| 560 | flag |= VNET_CRYPTO_OP_FLAG_CHAINED_BUFFERS; |
| 561 | tag = vlib_buffer_get_tail (lb) - icv_sz; |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 562 | crypto_total_len = esp_encrypt_chain_crypto ( |
| 563 | vm, ptd, sa, b, lb, icv_sz, b->data + crypto_start_offset, |
| 564 | crypto_total_len + icv_sz, 0); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | if (sa->integ_op_id) |
| 568 | { |
Benoît Ganne | 02dfd29 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 569 | integ_start_offset -= iv_sz + sizeof (esp_header_t); |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 570 | integ_total_len += iv_sz + sizeof (esp_header_t); |
| 571 | |
| 572 | if (b != lb) |
| 573 | { |
| 574 | integ_total_len = esp_encrypt_chain_integ ( |
| 575 | vm, ptd, sa, b, lb, icv_sz, |
| 576 | payload - iv_sz - sizeof (esp_header_t), |
| 577 | payload_len + iv_sz + sizeof (esp_header_t), tag, 0); |
| 578 | } |
| 579 | else if (ipsec_sa_is_set_USE_ESN (sa)) |
| 580 | { |
| 581 | u32 seq_hi = clib_net_to_host_u32 (sa->seq_hi); |
| 582 | clib_memcpy_fast (tag, &seq_hi, sizeof (seq_hi)); |
| 583 | integ_total_len += sizeof (seq_hi); |
| 584 | } |
| 585 | } |
| 586 | |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 587 | /* this always succeeds because we know the frame is not full */ |
| 588 | vnet_crypto_async_add_to_frame (vm, async_frame, key_index, crypto_total_len, |
| 589 | integ_total_len - crypto_total_len, |
| 590 | crypto_start_offset, integ_start_offset, bi, |
| 591 | async_next, iv, tag, aad, flag); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 594 | always_inline uword |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 595 | esp_encrypt_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 596 | vlib_frame_t *frame, vnet_link_t lt, int is_tun, |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 597 | u16 async_next_node) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 598 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | ipsec_main_t *im = &ipsec_main; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 600 | ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, vm->thread_index); |
| 601 | u32 *from = vlib_frame_vector_args (frame); |
| 602 | u32 n_left = frame->n_vectors; |
| 603 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 604 | u32 thread_index = vm->thread_index; |
| 605 | u16 buffer_data_size = vlib_buffer_get_default_data_size (vm); |
| 606 | u32 current_sa_index = ~0, current_sa_packets = 0; |
| 607 | u32 current_sa_bytes = 0, spi = 0; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 608 | u8 esp_align = 4, iv_sz = 0, icv_sz = 0; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 609 | ipsec_sa_t *sa0 = 0; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 610 | vlib_buffer_t *lb; |
| 611 | vnet_crypto_op_t **crypto_ops = &ptd->crypto_ops; |
| 612 | vnet_crypto_op_t **integ_ops = &ptd->integ_ops; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 613 | vnet_crypto_async_frame_t *async_frames[VNET_CRYPTO_ASYNC_OP_N_IDS]; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 614 | int is_async = im->async_mode; |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 615 | vnet_crypto_async_op_id_t async_op = ~0; |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 616 | u16 drop_next = |
| 617 | (lt == VNET_LINK_IP6 ? ESP_ENCRYPT_NEXT_DROP6 : |
| 618 | (lt == VNET_LINK_IP4 ? ESP_ENCRYPT_NEXT_DROP4 : |
| 619 | ESP_ENCRYPT_NEXT_DROP_MPLS)); |
| 620 | u16 handoff_next = (lt == VNET_LINK_IP6 ? |
| 621 | ESP_ENCRYPT_NEXT_HANDOFF6 : |
| 622 | (lt == VNET_LINK_IP4 ? ESP_ENCRYPT_NEXT_HANDOFF4 : |
| 623 | ESP_ENCRYPT_NEXT_HANDOFF_MPLS)); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 624 | vlib_buffer_t *sync_bufs[VLIB_FRAME_SIZE]; |
| 625 | u16 sync_nexts[VLIB_FRAME_SIZE], *sync_next = sync_nexts, n_sync = 0; |
Damjan Marion | dd298e8 | 2022-10-12 16:02:18 +0200 | [diff] [blame] | 626 | u16 n_async = 0; |
| 627 | u16 noop_nexts[VLIB_FRAME_SIZE], n_noop = 0; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 628 | u32 sync_bi[VLIB_FRAME_SIZE]; |
| 629 | u32 noop_bi[VLIB_FRAME_SIZE]; |
| 630 | esp_encrypt_error_t err; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 631 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 632 | vlib_get_buffers (vm, from, b, n_left); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 633 | |
| 634 | vec_reset_length (ptd->crypto_ops); |
| 635 | vec_reset_length (ptd->integ_ops); |
| 636 | vec_reset_length (ptd->chained_crypto_ops); |
| 637 | vec_reset_length (ptd->chained_integ_ops); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 638 | vec_reset_length (ptd->async_frames); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 639 | vec_reset_length (ptd->chunks); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 640 | clib_memset (async_frames, 0, sizeof (async_frames)); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 641 | |
| 642 | while (n_left > 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 643 | { |
Zhiyong Yang | 1cff643 | 2019-04-30 05:33:53 -0400 | [diff] [blame] | 644 | u32 sa_index0; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 645 | dpo_id_t *dpo; |
| 646 | esp_header_t *esp; |
| 647 | u8 *payload, *next_hdr_ptr; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 648 | u16 payload_len, payload_len_total, n_bufs; |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 649 | u32 hdr_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 650 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 651 | err = ESP_ENCRYPT_ERROR_RX_PKTS; |
| 652 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 653 | if (n_left > 2) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 654 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 655 | u8 *p; |
| 656 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 657 | p = vlib_buffer_get_current (b[1]); |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 658 | clib_prefetch_load (p); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 659 | p -= CLIB_CACHE_LINE_BYTES; |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 660 | clib_prefetch_load (p); |
Neale Ranns | 123b5eb | 2020-10-16 14:03:55 +0000 | [diff] [blame] | 661 | /* speculate that the trailer goes in the first buffer */ |
| 662 | CLIB_PREFETCH (vlib_buffer_get_tail (b[1]), |
| 663 | CLIB_CACHE_LINE_BYTES, LOAD); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 664 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 665 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 666 | if (is_tun) |
| 667 | { |
| 668 | /* we are on a ipsec tunnel's feature arc */ |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 669 | vnet_buffer (b[0])->ipsec.sad_index = |
| 670 | sa_index0 = ipsec_tun_protect_get_sa_out |
| 671 | (vnet_buffer (b[0])->ip.adj_index[VLIB_TX]); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 672 | |
| 673 | if (PREDICT_FALSE (INDEX_INVALID == sa_index0)) |
| 674 | { |
| 675 | err = ESP_ENCRYPT_ERROR_NO_PROTECTION; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 676 | noop_nexts[n_noop] = drop_next; |
| 677 | b[0]->error = node->errors[err]; |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 678 | goto trace; |
| 679 | } |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 680 | } |
| 681 | else |
| 682 | sa_index0 = vnet_buffer (b[0])->ipsec.sad_index; |
| 683 | |
| 684 | if (sa_index0 != current_sa_index) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 685 | { |
Damjan Marion | 21f265f | 2019-06-05 15:45:50 +0200 | [diff] [blame] | 686 | if (current_sa_packets) |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 687 | vlib_increment_combined_counter ( |
| 688 | &ipsec_sa_counters, thread_index, current_sa_index, |
| 689 | current_sa_packets, current_sa_bytes); |
Damjan Marion | 21f265f | 2019-06-05 15:45:50 +0200 | [diff] [blame] | 690 | current_sa_packets = current_sa_bytes = 0; |
| 691 | |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 692 | sa0 = ipsec_sa_get (sa_index0); |
Neale Ranns | 123b5eb | 2020-10-16 14:03:55 +0000 | [diff] [blame] | 693 | |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 694 | if (PREDICT_FALSE ((sa0->crypto_alg == IPSEC_CRYPTO_ALG_NONE && |
| 695 | sa0->integ_alg == IPSEC_INTEG_ALG_NONE) && |
| 696 | !ipsec_sa_is_set_NO_ALGO_NO_DROP (sa0))) |
| 697 | { |
| 698 | err = ESP_ENCRYPT_ERROR_NO_ENCRYPTION; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 699 | esp_encrypt_set_next_index (b[0], node, thread_index, err, |
| 700 | n_noop, noop_nexts, drop_next, |
| 701 | sa_index0); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 702 | goto trace; |
| 703 | } |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 704 | current_sa_index = sa_index0; |
| 705 | vlib_prefetch_combined_counter (&ipsec_sa_counters, thread_index, |
| 706 | current_sa_index); |
| 707 | |
Neale Ranns | 123b5eb | 2020-10-16 14:03:55 +0000 | [diff] [blame] | 708 | /* fetch the second cacheline ASAP */ |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 709 | clib_prefetch_load (sa0->cacheline1); |
Neale Ranns | 123b5eb | 2020-10-16 14:03:55 +0000 | [diff] [blame] | 710 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 711 | spi = clib_net_to_host_u32 (sa0->spi); |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 712 | esp_align = sa0->esp_block_align; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 713 | icv_sz = sa0->integ_icv_size; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 714 | iv_sz = sa0->crypto_iv_size; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 715 | is_async = im->async_mode | ipsec_sa_is_set_IS_ASYNC (sa0); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 716 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 717 | |
Benoît Ganne | 5527a78 | 2022-01-18 15:56:41 +0100 | [diff] [blame] | 718 | if (PREDICT_FALSE ((u16) ~0 == sa0->thread_index)) |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 719 | { |
| 720 | /* this is the first packet to use this SA, claim the SA |
| 721 | * for this thread. this could happen simultaneously on |
| 722 | * another thread */ |
Neale Ranns | 1a52d37 | 2021-02-04 11:33:32 +0000 | [diff] [blame] | 723 | clib_atomic_cmp_and_swap (&sa0->thread_index, ~0, |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 724 | ipsec_sa_assign_thread (thread_index)); |
| 725 | } |
| 726 | |
Neale Ranns | 1a52d37 | 2021-02-04 11:33:32 +0000 | [diff] [blame] | 727 | if (PREDICT_FALSE (thread_index != sa0->thread_index)) |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 728 | { |
Neale Ranns | aa7d766 | 2021-02-10 08:42:49 +0000 | [diff] [blame] | 729 | vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 730 | err = ESP_ENCRYPT_ERROR_HANDOFF; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 731 | esp_encrypt_set_next_index (b[0], node, thread_index, err, n_noop, |
| 732 | noop_nexts, handoff_next, |
| 733 | current_sa_index); |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 734 | goto trace; |
| 735 | } |
| 736 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 737 | lb = b[0]; |
| 738 | n_bufs = vlib_buffer_chain_linearize (vm, b[0]); |
| 739 | if (n_bufs == 0) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 740 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 741 | err = ESP_ENCRYPT_ERROR_NO_BUFFERS; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 742 | esp_encrypt_set_next_index (b[0], node, thread_index, err, n_noop, |
| 743 | noop_nexts, drop_next, current_sa_index); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 744 | goto trace; |
| 745 | } |
| 746 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 747 | if (n_bufs > 1) |
| 748 | { |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 749 | /* find last buffer in the chain */ |
| 750 | while (lb->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 751 | lb = vlib_get_buffer (vm, lb->next_buffer); |
| 752 | } |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 753 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 754 | if (PREDICT_FALSE (esp_seq_advance (sa0))) |
| 755 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 756 | err = ESP_ENCRYPT_ERROR_SEQ_CYCLED; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 757 | esp_encrypt_set_next_index (b[0], node, thread_index, err, n_noop, |
| 758 | noop_nexts, drop_next, current_sa_index); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 759 | goto trace; |
| 760 | } |
| 761 | |
| 762 | /* space for IV */ |
| 763 | hdr_len = iv_sz; |
| 764 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 765 | if (ipsec_sa_is_set_IS_TUNNEL (sa0)) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 766 | { |
| 767 | payload = vlib_buffer_get_current (b[0]); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 768 | next_hdr_ptr = esp_add_footer_and_icv ( |
| 769 | vm, &lb, esp_align, icv_sz, node, buffer_data_size, |
| 770 | vlib_buffer_length_in_chain (vm, b[0])); |
Filip Tehlar | 8cdb1a0 | 2019-11-18 22:21:37 +0000 | [diff] [blame] | 771 | if (!next_hdr_ptr) |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 772 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 773 | err = ESP_ENCRYPT_ERROR_NO_BUFFERS; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 774 | esp_encrypt_set_next_index (b[0], node, thread_index, err, |
| 775 | n_noop, noop_nexts, drop_next, |
| 776 | current_sa_index); |
Filip Tehlar | e4e8c6b | 2020-02-13 07:49:30 +0000 | [diff] [blame] | 777 | goto trace; |
| 778 | } |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 779 | b[0]->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; |
Filip Tehlar | 8cdb1a0 | 2019-11-18 22:21:37 +0000 | [diff] [blame] | 780 | payload_len = b[0]->current_length; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 781 | payload_len_total = vlib_buffer_length_in_chain (vm, b[0]); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 782 | |
| 783 | /* ESP header */ |
| 784 | hdr_len += sizeof (*esp); |
| 785 | esp = (esp_header_t *) (payload - hdr_len); |
| 786 | |
| 787 | /* optional UDP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 788 | if (ipsec_sa_is_set_UDP_ENCAP (sa0)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 789 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 790 | hdr_len += sizeof (udp_header_t); |
| 791 | esp_fill_udp_hdr (sa0, (udp_header_t *) (payload - hdr_len), |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 792 | payload_len_total + hdr_len); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /* IP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 796 | if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 797 | { |
| 798 | ip6_header_t *ip6; |
| 799 | u16 len = sizeof (ip6_header_t); |
| 800 | hdr_len += len; |
| 801 | ip6 = (ip6_header_t *) (payload - hdr_len); |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 802 | clib_memcpy_fast (ip6, &sa0->ip6_hdr, sizeof (ip6_header_t)); |
| 803 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 804 | if (VNET_LINK_IP6 == lt) |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 805 | { |
| 806 | *next_hdr_ptr = IP_PROTOCOL_IPV6; |
| 807 | tunnel_encap_fixup_6o6 (sa0->tunnel_flags, |
| 808 | (const ip6_header_t *) payload, |
| 809 | ip6); |
| 810 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 811 | else if (VNET_LINK_IP4 == lt) |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 812 | { |
| 813 | *next_hdr_ptr = IP_PROTOCOL_IP_IN_IP; |
Neale Ranns | a91cb45 | 2021-02-04 11:02:52 +0000 | [diff] [blame] | 814 | tunnel_encap_fixup_4o6 (sa0->tunnel_flags, b[0], |
| 815 | (const ip4_header_t *) payload, ip6); |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 816 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 817 | else if (VNET_LINK_MPLS == lt) |
| 818 | { |
| 819 | *next_hdr_ptr = IP_PROTOCOL_MPLS_IN_IP; |
| 820 | tunnel_encap_fixup_mplso6 ( |
Neale Ranns | a91cb45 | 2021-02-04 11:02:52 +0000 | [diff] [blame] | 821 | sa0->tunnel_flags, b[0], |
| 822 | (const mpls_unicast_header_t *) payload, ip6); |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 823 | } |
| 824 | else |
| 825 | ASSERT (0); |
| 826 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 827 | len = payload_len_total + hdr_len - len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 828 | ip6->payload_length = clib_net_to_host_u16 (len); |
Neale Ranns | 45d6d83 | 2021-01-19 13:38:47 +0000 | [diff] [blame] | 829 | b[0]->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 830 | } |
| 831 | else |
| 832 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 833 | ip4_header_t *ip4; |
| 834 | u16 len = sizeof (ip4_header_t); |
| 835 | hdr_len += len; |
| 836 | ip4 = (ip4_header_t *) (payload - hdr_len); |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 837 | clib_memcpy_fast (ip4, &sa0->ip4_hdr, sizeof (ip4_header_t)); |
| 838 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 839 | if (VNET_LINK_IP6 == lt) |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 840 | { |
| 841 | *next_hdr_ptr = IP_PROTOCOL_IPV6; |
| 842 | tunnel_encap_fixup_6o4_w_chksum (sa0->tunnel_flags, |
| 843 | (const ip6_header_t *) |
| 844 | payload, ip4); |
| 845 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 846 | else if (VNET_LINK_IP4 == lt) |
Neale Ranns | 041add7 | 2020-01-02 04:06:10 +0000 | [diff] [blame] | 847 | { |
| 848 | *next_hdr_ptr = IP_PROTOCOL_IP_IN_IP; |
| 849 | tunnel_encap_fixup_4o4_w_chksum (sa0->tunnel_flags, |
| 850 | (const ip4_header_t *) |
| 851 | payload, ip4); |
| 852 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 853 | else if (VNET_LINK_MPLS == lt) |
| 854 | { |
| 855 | *next_hdr_ptr = IP_PROTOCOL_MPLS_IN_IP; |
| 856 | tunnel_encap_fixup_mplso4_w_chksum ( |
| 857 | sa0->tunnel_flags, (const mpls_unicast_header_t *) payload, |
| 858 | ip4); |
| 859 | } |
| 860 | else |
| 861 | ASSERT (0); |
| 862 | |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 863 | len = payload_len_total + hdr_len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 864 | esp_update_ip4_hdr (ip4, len, /* is_transport */ 0, 0); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 865 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 866 | |
Neale Ranns | 72f2a3a | 2019-06-17 15:43:38 +0000 | [diff] [blame] | 867 | dpo = &sa0->dpo; |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 868 | if (!is_tun) |
| 869 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 870 | sync_next[0] = dpo->dpoi_next_node; |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 871 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo->dpoi_index; |
| 872 | } |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 873 | else |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 874 | sync_next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT; |
Neale Ranns | 9ec846c | 2021-02-09 14:04:02 +0000 | [diff] [blame] | 875 | b[0]->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 876 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 877 | else /* transport mode */ |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 878 | { |
Ole Troan | 03092c1 | 2021-11-23 15:55:39 +0100 | [diff] [blame] | 879 | u8 *l2_hdr, l2_len, *ip_hdr; |
| 880 | u16 ip_len; |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 881 | ip6_ext_header_t *ext_hdr; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 882 | udp_header_t *udp = 0; |
Alexander Chernavin | b0d2eda | 2020-03-25 10:56:52 -0400 | [diff] [blame] | 883 | u16 udp_len = 0; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 884 | u8 *old_ip_hdr = vlib_buffer_get_current (b[0]); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 885 | |
Ole Troan | 03092c1 | 2021-11-23 15:55:39 +0100 | [diff] [blame] | 886 | /* |
| 887 | * Get extension header chain length. It might be longer than the |
| 888 | * buffer's pre_data area. |
| 889 | */ |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 890 | ip_len = |
| 891 | (VNET_LINK_IP6 == lt ? |
| 892 | esp_get_ip6_hdr_len ((ip6_header_t *) old_ip_hdr, &ext_hdr) : |
| 893 | ip4_header_bytes ((ip4_header_t *) old_ip_hdr)); |
Ole Troan | 03092c1 | 2021-11-23 15:55:39 +0100 | [diff] [blame] | 894 | if ((old_ip_hdr - ip_len) < &b[0]->pre_data[0]) |
| 895 | { |
| 896 | err = ESP_ENCRYPT_ERROR_NO_BUFFERS; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 897 | esp_encrypt_set_next_index (b[0], node, thread_index, err, |
| 898 | n_noop, noop_nexts, drop_next, |
| 899 | current_sa_index); |
Ole Troan | 03092c1 | 2021-11-23 15:55:39 +0100 | [diff] [blame] | 900 | goto trace; |
| 901 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 902 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 903 | vlib_buffer_advance (b[0], ip_len); |
| 904 | payload = vlib_buffer_get_current (b[0]); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 905 | next_hdr_ptr = esp_add_footer_and_icv ( |
| 906 | vm, &lb, esp_align, icv_sz, node, buffer_data_size, |
| 907 | vlib_buffer_length_in_chain (vm, b[0])); |
Filip Tehlar | 8cdb1a0 | 2019-11-18 22:21:37 +0000 | [diff] [blame] | 908 | if (!next_hdr_ptr) |
Fan Zhang | 18f0e31 | 2020-10-19 13:08:34 +0100 | [diff] [blame] | 909 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 910 | err = ESP_ENCRYPT_ERROR_NO_BUFFERS; |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 911 | esp_encrypt_set_next_index (b[0], node, thread_index, err, |
| 912 | n_noop, noop_nexts, drop_next, |
| 913 | current_sa_index); |
Fan Zhang | 18f0e31 | 2020-10-19 13:08:34 +0100 | [diff] [blame] | 914 | goto trace; |
| 915 | } |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 916 | |
| 917 | b[0]->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID; |
Filip Tehlar | 8cdb1a0 | 2019-11-18 22:21:37 +0000 | [diff] [blame] | 918 | payload_len = b[0]->current_length; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 919 | payload_len_total = vlib_buffer_length_in_chain (vm, b[0]); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 920 | |
| 921 | /* ESP header */ |
| 922 | hdr_len += sizeof (*esp); |
| 923 | esp = (esp_header_t *) (payload - hdr_len); |
| 924 | |
| 925 | /* optional UDP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 926 | if (ipsec_sa_is_set_UDP_ENCAP (sa0)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 927 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 928 | hdr_len += sizeof (udp_header_t); |
| 929 | udp = (udp_header_t *) (payload - hdr_len); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 930 | } |
| 931 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 932 | /* IP header */ |
| 933 | hdr_len += ip_len; |
| 934 | ip_hdr = payload - hdr_len; |
| 935 | |
| 936 | /* L2 header */ |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 937 | if (!is_tun) |
| 938 | { |
| 939 | l2_len = vnet_buffer (b[0])->ip.save_rewrite_length; |
| 940 | hdr_len += l2_len; |
| 941 | l2_hdr = payload - hdr_len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 942 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 943 | /* copy l2 and ip header */ |
| 944 | clib_memcpy_le32 (l2_hdr, old_ip_hdr - l2_len, l2_len); |
| 945 | } |
| 946 | else |
| 947 | l2_len = 0; |
| 948 | |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 949 | u16 len; |
| 950 | len = payload_len_total + hdr_len - l2_len; |
| 951 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 952 | if (VNET_LINK_IP6 == lt) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 953 | { |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 954 | ip6_header_t *ip6 = (ip6_header_t *) (old_ip_hdr); |
| 955 | if (PREDICT_TRUE (NULL == ext_hdr)) |
| 956 | { |
| 957 | *next_hdr_ptr = ip6->protocol; |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 958 | ip6->protocol = |
| 959 | (udp) ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP; |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 960 | } |
| 961 | else |
| 962 | { |
| 963 | *next_hdr_ptr = ext_hdr->next_hdr; |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 964 | ext_hdr->next_hdr = |
| 965 | (udp) ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP; |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 966 | } |
Neale Ranns | d207fd7 | 2019-04-18 17:18:12 -0700 | [diff] [blame] | 967 | ip6->payload_length = |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 968 | clib_host_to_net_u16 (len - sizeof (ip6_header_t)); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 969 | } |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 970 | else if (VNET_LINK_IP4 == lt) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 971 | { |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 972 | ip4_header_t *ip4 = (ip4_header_t *) (old_ip_hdr); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 973 | *next_hdr_ptr = ip4->protocol; |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 974 | esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, |
| 975 | (udp != NULL)); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 976 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 977 | |
Neale Ranns | 0295040 | 2019-12-20 00:54:57 +0000 | [diff] [blame] | 978 | clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len); |
| 979 | |
Alexander Chernavin | b0d2eda | 2020-03-25 10:56:52 -0400 | [diff] [blame] | 980 | if (udp) |
| 981 | { |
Matthew Smith | 6f1eb48 | 2022-08-09 22:19:38 +0000 | [diff] [blame] | 982 | udp_len = len - ip_len; |
Alexander Chernavin | b0d2eda | 2020-03-25 10:56:52 -0400 | [diff] [blame] | 983 | esp_fill_udp_hdr (sa0, udp, udp_len); |
| 984 | } |
| 985 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 986 | sync_next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 987 | } |
| 988 | |
PiotrX Kleski | fdca4dd | 2020-05-05 14:14:22 +0200 | [diff] [blame] | 989 | if (lb != b[0]) |
| 990 | { |
| 991 | crypto_ops = &ptd->chained_crypto_ops; |
| 992 | integ_ops = &ptd->chained_integ_ops; |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | crypto_ops = &ptd->crypto_ops; |
| 997 | integ_ops = &ptd->integ_ops; |
| 998 | } |
| 999 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1000 | esp->spi = spi; |
| 1001 | esp->seq = clib_net_to_host_u32 (sa0->seq); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1002 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1003 | if (is_async) |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1004 | { |
| 1005 | async_op = sa0->crypto_async_enc_op_id; |
| 1006 | |
| 1007 | /* get a frame for this op if we don't yet have one or it's full |
| 1008 | */ |
| 1009 | if (NULL == async_frames[async_op] || |
| 1010 | vnet_crypto_async_frame_is_full (async_frames[async_op])) |
| 1011 | { |
| 1012 | async_frames[async_op] = |
| 1013 | vnet_crypto_async_get_frame (vm, async_op); |
gaoginskx | f441b5d | 2021-06-07 12:07:01 +0100 | [diff] [blame] | 1014 | |
| 1015 | if (PREDICT_FALSE (!async_frames[async_op])) |
| 1016 | { |
| 1017 | err = ESP_ENCRYPT_ERROR_NO_AVAIL_FRAME; |
| 1018 | esp_encrypt_set_next_index (b[0], node, thread_index, err, |
| 1019 | n_noop, noop_nexts, drop_next, |
| 1020 | current_sa_index); |
| 1021 | goto trace; |
| 1022 | } |
| 1023 | |
Matthew Smith | 51d56ba | 2021-06-04 09:18:37 -0500 | [diff] [blame] | 1024 | /* Save the frame to the list we'll submit at the end */ |
| 1025 | vec_add1 (ptd->async_frames, async_frames[async_op]); |
| 1026 | } |
| 1027 | |
| 1028 | esp_prepare_async_frame (vm, ptd, async_frames[async_op], sa0, b[0], |
| 1029 | esp, payload, payload_len, iv_sz, icv_sz, |
| 1030 | from[b - bufs], sync_next[0], hdr_len, |
| 1031 | async_next_node, lb); |
| 1032 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1033 | else |
Neale Ranns | 5b89110 | 2021-06-28 13:31:28 +0000 | [diff] [blame] | 1034 | esp_prepare_sync_op (vm, ptd, crypto_ops, integ_ops, sa0, sa0->seq_hi, |
| 1035 | payload, payload_len, iv_sz, icv_sz, n_sync, b, |
| 1036 | lb, hdr_len, esp); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1037 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1038 | vlib_buffer_advance (b[0], 0LL - hdr_len); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1039 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1040 | current_sa_packets += 1; |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1041 | current_sa_bytes += payload_len_total; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1042 | |
| 1043 | trace: |
| 1044 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1045 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1046 | esp_encrypt_trace_t *tr = vlib_add_trace (vm, node, b[0], |
| 1047 | sizeof (*tr)); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 1048 | if (INDEX_INVALID == sa_index0) |
| 1049 | clib_memset_u8 (tr, 0xff, sizeof (*tr)); |
| 1050 | else |
| 1051 | { |
| 1052 | tr->sa_index = sa_index0; |
| 1053 | tr->spi = sa0->spi; |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 1054 | tr->seq = sa0->seq; |
| 1055 | tr->sa_seq_hi = sa0->seq_hi; |
| 1056 | tr->udp_encap = ipsec_sa_is_set_UDP_ENCAP (sa0); |
| 1057 | tr->crypto_alg = sa0->crypto_alg; |
| 1058 | tr->integ_alg = sa0->integ_alg; |
| 1059 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1060 | } |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1061 | |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1062 | /* next */ |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1063 | if (ESP_ENCRYPT_ERROR_RX_PKTS != err) |
| 1064 | { |
| 1065 | noop_bi[n_noop] = from[b - bufs]; |
| 1066 | n_noop++; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1067 | } |
| 1068 | else if (!is_async) |
| 1069 | { |
| 1070 | sync_bi[n_sync] = from[b - bufs]; |
| 1071 | sync_bufs[n_sync] = b[0]; |
| 1072 | n_sync++; |
| 1073 | sync_next++; |
| 1074 | } |
| 1075 | else |
| 1076 | { |
| 1077 | n_async++; |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1078 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1079 | n_left -= 1; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1080 | b += 1; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 1083 | if (INDEX_INVALID != current_sa_index) |
| 1084 | vlib_increment_combined_counter (&ipsec_sa_counters, thread_index, |
| 1085 | current_sa_index, current_sa_packets, |
| 1086 | current_sa_bytes); |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1087 | if (n_sync) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1088 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1089 | esp_process_ops (vm, node, ptd->crypto_ops, sync_bufs, sync_nexts, |
| 1090 | drop_next); |
| 1091 | esp_process_chained_ops (vm, node, ptd->chained_crypto_ops, sync_bufs, |
| 1092 | sync_nexts, ptd->chunks, drop_next); |
Filip Tehlar | efcad1a | 2020-02-04 09:36:04 +0000 | [diff] [blame] | 1093 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1094 | esp_process_ops (vm, node, ptd->integ_ops, sync_bufs, sync_nexts, |
| 1095 | drop_next); |
| 1096 | esp_process_chained_ops (vm, node, ptd->chained_integ_ops, sync_bufs, |
| 1097 | sync_nexts, ptd->chunks, drop_next); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1098 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1099 | vlib_buffer_enqueue_to_next (vm, node, sync_bi, sync_nexts, n_sync); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1100 | } |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1101 | if (n_async) |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1102 | { |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1103 | /* submit all of the open frames */ |
| 1104 | vnet_crypto_async_frame_t **async_frame; |
| 1105 | |
| 1106 | vec_foreach (async_frame, ptd->async_frames) |
Fan Zhang | 18f0e31 | 2020-10-19 13:08:34 +0100 | [diff] [blame] | 1107 | { |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1108 | if (vnet_crypto_async_submit_open_frame (vm, *async_frame) < 0) |
| 1109 | { |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1110 | n_noop += esp_async_recycle_failed_submit ( |
| 1111 | vm, *async_frame, node, ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR, |
Arthur de Kerhor | ad95b06 | 2022-11-16 19:12:05 +0100 | [diff] [blame] | 1112 | IPSEC_SA_ERROR_CRYPTO_ENGINE_ERROR, n_noop, noop_bi, |
Xiaoming Jiang | 0c1454c | 2023-05-05 02:28:20 +0000 | [diff] [blame] | 1113 | noop_nexts, drop_next, true); |
Neale Ranns | fc81134 | 2021-02-26 10:35:33 +0000 | [diff] [blame] | 1114 | vnet_crypto_async_reset_frame (*async_frame); |
| 1115 | vnet_crypto_async_free_frame (vm, *async_frame); |
| 1116 | } |
Fan Zhang | 18f0e31 | 2020-10-19 13:08:34 +0100 | [diff] [blame] | 1117 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1118 | } |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 1119 | if (n_noop) |
| 1120 | vlib_buffer_enqueue_to_next (vm, node, noop_bi, noop_nexts, n_noop); |
| 1121 | |
| 1122 | vlib_node_increment_counter (vm, node->node_index, ESP_ENCRYPT_ERROR_RX_PKTS, |
| 1123 | frame->n_vectors); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1124 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 1125 | return frame->n_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1128 | always_inline uword |
| 1129 | esp_encrypt_post_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 1130 | vlib_frame_t * frame) |
| 1131 | { |
| 1132 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 1133 | u16 nexts[VLIB_FRAME_SIZE], *next = nexts; |
| 1134 | u32 *from = vlib_frame_vector_args (frame); |
| 1135 | u32 n_left = frame->n_vectors; |
| 1136 | |
| 1137 | vlib_get_buffers (vm, from, b, n_left); |
| 1138 | |
| 1139 | if (n_left >= 4) |
| 1140 | { |
| 1141 | vlib_prefetch_buffer_header (b[0], LOAD); |
| 1142 | vlib_prefetch_buffer_header (b[1], LOAD); |
| 1143 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 1144 | vlib_prefetch_buffer_header (b[3], LOAD); |
| 1145 | } |
| 1146 | |
| 1147 | while (n_left > 8) |
| 1148 | { |
| 1149 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 1150 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 1151 | vlib_prefetch_buffer_header (b[6], LOAD); |
| 1152 | vlib_prefetch_buffer_header (b[7], LOAD); |
| 1153 | |
| 1154 | next[0] = (esp_post_data (b[0]))->next_index; |
| 1155 | next[1] = (esp_post_data (b[1]))->next_index; |
| 1156 | next[2] = (esp_post_data (b[2]))->next_index; |
| 1157 | next[3] = (esp_post_data (b[3]))->next_index; |
| 1158 | |
| 1159 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) |
| 1160 | { |
| 1161 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 1162 | { |
| 1163 | esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[0], |
| 1164 | sizeof (*tr)); |
| 1165 | tr->next_index = next[0]; |
| 1166 | } |
| 1167 | if (b[1]->flags & VLIB_BUFFER_IS_TRACED) |
| 1168 | { |
| 1169 | esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[1], |
| 1170 | sizeof (*tr)); |
| 1171 | tr->next_index = next[1]; |
| 1172 | } |
| 1173 | if (b[2]->flags & VLIB_BUFFER_IS_TRACED) |
| 1174 | { |
| 1175 | esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[2], |
| 1176 | sizeof (*tr)); |
| 1177 | tr->next_index = next[2]; |
| 1178 | } |
| 1179 | if (b[3]->flags & VLIB_BUFFER_IS_TRACED) |
| 1180 | { |
| 1181 | esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[3], |
| 1182 | sizeof (*tr)); |
| 1183 | tr->next_index = next[3]; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | b += 4; |
| 1188 | next += 4; |
| 1189 | n_left -= 4; |
| 1190 | } |
| 1191 | |
| 1192 | while (n_left > 0) |
| 1193 | { |
| 1194 | next[0] = (esp_post_data (b[0]))->next_index; |
| 1195 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 1196 | { |
| 1197 | esp_encrypt_post_trace_t *tr = vlib_add_trace (vm, node, b[0], |
| 1198 | sizeof (*tr)); |
| 1199 | tr->next_index = next[0]; |
| 1200 | } |
| 1201 | |
| 1202 | b += 1; |
| 1203 | next += 1; |
| 1204 | n_left -= 1; |
| 1205 | } |
| 1206 | |
| 1207 | vlib_node_increment_counter (vm, node->node_index, |
| 1208 | ESP_ENCRYPT_ERROR_POST_RX_PKTS, |
| 1209 | frame->n_vectors); |
| 1210 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
| 1211 | return frame->n_vectors; |
| 1212 | } |
| 1213 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 1214 | VLIB_NODE_FN (esp4_encrypt_node) (vlib_main_t * vm, |
| 1215 | vlib_node_runtime_t * node, |
| 1216 | vlib_frame_t * from_frame) |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1217 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1218 | return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP4, 0, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1219 | esp_encrypt_async_next.esp4_post_next); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1220 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1221 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1222 | /* *INDENT-OFF* */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1223 | VLIB_REGISTER_NODE (esp4_encrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1224 | .name = "esp4-encrypt", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1225 | .vector_size = sizeof (u32), |
| 1226 | .format_trace = format_esp_encrypt_trace, |
| 1227 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1228 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1229 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1230 | .error_counters = esp_encrypt_error_counters, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1231 | |
| 1232 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1233 | .next_nodes = { [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop", |
| 1234 | [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop", |
| 1235 | [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop", |
| 1236 | [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-handoff", |
| 1237 | [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-handoff", |
| 1238 | [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "error-drop", |
| 1239 | [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output" }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1240 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1241 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1242 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1243 | VLIB_NODE_FN (esp4_encrypt_post_node) (vlib_main_t * vm, |
| 1244 | vlib_node_runtime_t * node, |
| 1245 | vlib_frame_t * from_frame) |
| 1246 | { |
| 1247 | return esp_encrypt_post_inline (vm, node, from_frame); |
| 1248 | } |
| 1249 | |
| 1250 | /* *INDENT-OFF* */ |
| 1251 | VLIB_REGISTER_NODE (esp4_encrypt_post_node) = { |
| 1252 | .name = "esp4-encrypt-post", |
| 1253 | .vector_size = sizeof (u32), |
| 1254 | .format_trace = format_esp_post_encrypt_trace, |
| 1255 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1256 | .sibling_of = "esp4-encrypt", |
| 1257 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1258 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1259 | .error_counters = esp_encrypt_error_counters, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1260 | }; |
| 1261 | /* *INDENT-ON* */ |
| 1262 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 1263 | VLIB_NODE_FN (esp6_encrypt_node) (vlib_main_t * vm, |
| 1264 | vlib_node_runtime_t * node, |
| 1265 | vlib_frame_t * from_frame) |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1266 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1267 | return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP6, 0, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1268 | esp_encrypt_async_next.esp6_post_next); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /* *INDENT-OFF* */ |
| 1272 | VLIB_REGISTER_NODE (esp6_encrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1273 | .name = "esp6-encrypt", |
| 1274 | .vector_size = sizeof (u32), |
| 1275 | .format_trace = format_esp_encrypt_trace, |
| 1276 | .type = VLIB_NODE_TYPE_INTERNAL, |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1277 | .sibling_of = "esp4-encrypt", |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1278 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1279 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1280 | .error_counters = esp_encrypt_error_counters, |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 1281 | }; |
| 1282 | /* *INDENT-ON* */ |
| 1283 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1284 | VLIB_NODE_FN (esp6_encrypt_post_node) (vlib_main_t * vm, |
| 1285 | vlib_node_runtime_t * node, |
| 1286 | vlib_frame_t * from_frame) |
| 1287 | { |
| 1288 | return esp_encrypt_post_inline (vm, node, from_frame); |
| 1289 | } |
| 1290 | |
| 1291 | /* *INDENT-OFF* */ |
| 1292 | VLIB_REGISTER_NODE (esp6_encrypt_post_node) = { |
| 1293 | .name = "esp6-encrypt-post", |
| 1294 | .vector_size = sizeof (u32), |
| 1295 | .format_trace = format_esp_post_encrypt_trace, |
| 1296 | .type = VLIB_NODE_TYPE_INTERNAL, |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1297 | .sibling_of = "esp4-encrypt", |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1298 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1299 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1300 | .error_counters = esp_encrypt_error_counters, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1301 | }; |
| 1302 | /* *INDENT-ON* */ |
| 1303 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1304 | VLIB_NODE_FN (esp4_encrypt_tun_node) (vlib_main_t * vm, |
| 1305 | vlib_node_runtime_t * node, |
| 1306 | vlib_frame_t * from_frame) |
| 1307 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1308 | return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP4, 1, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1309 | esp_encrypt_async_next.esp4_tun_post_next); |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | /* *INDENT-OFF* */ |
| 1313 | VLIB_REGISTER_NODE (esp4_encrypt_tun_node) = { |
| 1314 | .name = "esp4-encrypt-tun", |
| 1315 | .vector_size = sizeof (u32), |
| 1316 | .format_trace = format_esp_encrypt_trace, |
| 1317 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1318 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1319 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1320 | .error_counters = esp_encrypt_error_counters, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1321 | |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1322 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1323 | .next_nodes = { |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1324 | [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop", |
| 1325 | [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1326 | [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop", |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1327 | [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1328 | [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff", |
| 1329 | [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff", |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 1330 | [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx", |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1331 | }, |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1332 | }; |
| 1333 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1334 | VLIB_NODE_FN (esp4_encrypt_tun_post_node) (vlib_main_t * vm, |
| 1335 | vlib_node_runtime_t * node, |
| 1336 | vlib_frame_t * from_frame) |
| 1337 | { |
| 1338 | return esp_encrypt_post_inline (vm, node, from_frame); |
| 1339 | } |
| 1340 | |
| 1341 | /* *INDENT-OFF* */ |
| 1342 | VLIB_REGISTER_NODE (esp4_encrypt_tun_post_node) = { |
| 1343 | .name = "esp4-encrypt-tun-post", |
| 1344 | .vector_size = sizeof (u32), |
| 1345 | .format_trace = format_esp_post_encrypt_trace, |
| 1346 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1347 | .sibling_of = "esp4-encrypt-tun", |
| 1348 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1349 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1350 | .error_counters = esp_encrypt_error_counters, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1351 | }; |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1352 | /* *INDENT-ON* */ |
| 1353 | |
| 1354 | VLIB_NODE_FN (esp6_encrypt_tun_node) (vlib_main_t * vm, |
| 1355 | vlib_node_runtime_t * node, |
| 1356 | vlib_frame_t * from_frame) |
| 1357 | { |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1358 | return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_IP6, 1, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1359 | esp_encrypt_async_next.esp6_tun_post_next); |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | /* *INDENT-OFF* */ |
| 1363 | VLIB_REGISTER_NODE (esp6_encrypt_tun_node) = { |
| 1364 | .name = "esp6-encrypt-tun", |
| 1365 | .vector_size = sizeof (u32), |
| 1366 | .format_trace = format_esp_encrypt_trace, |
| 1367 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1368 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1369 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1370 | .error_counters = esp_encrypt_error_counters, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1371 | |
Neale Ranns | f62a8c0 | 2019-04-02 08:13:33 +0000 | [diff] [blame] | 1372 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1373 | .next_nodes = { |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1374 | [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop", |
| 1375 | [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1376 | [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop", |
| 1377 | [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff", |
Neale Ranns | b1fd80f | 2020-05-12 13:33:56 +0000 | [diff] [blame] | 1378 | [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff", |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1379 | [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff", |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 1380 | [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx", |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 1381 | }, |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1382 | }; |
| 1383 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 1384 | /* *INDENT-ON* */ |
| 1385 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1386 | VLIB_NODE_FN (esp6_encrypt_tun_post_node) (vlib_main_t * vm, |
| 1387 | vlib_node_runtime_t * node, |
| 1388 | vlib_frame_t * from_frame) |
| 1389 | { |
| 1390 | return esp_encrypt_post_inline (vm, node, from_frame); |
| 1391 | } |
| 1392 | |
| 1393 | /* *INDENT-OFF* */ |
| 1394 | VLIB_REGISTER_NODE (esp6_encrypt_tun_post_node) = { |
| 1395 | .name = "esp6-encrypt-tun-post", |
| 1396 | .vector_size = sizeof (u32), |
| 1397 | .format_trace = format_esp_post_encrypt_trace, |
| 1398 | .type = VLIB_NODE_TYPE_INTERNAL, |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1399 | .sibling_of = "esp-mpls-encrypt-tun", |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1400 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1401 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1402 | .error_counters = esp_encrypt_error_counters, |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 1403 | }; |
| 1404 | /* *INDENT-ON* */ |
| 1405 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1406 | VLIB_NODE_FN (esp_mpls_encrypt_tun_node) |
| 1407 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame) |
| 1408 | { |
| 1409 | return esp_encrypt_inline (vm, node, from_frame, VNET_LINK_MPLS, 1, |
| 1410 | esp_encrypt_async_next.esp_mpls_tun_post_next); |
| 1411 | } |
| 1412 | |
| 1413 | VLIB_REGISTER_NODE (esp_mpls_encrypt_tun_node) = { |
| 1414 | .name = "esp-mpls-encrypt-tun", |
| 1415 | .vector_size = sizeof (u32), |
| 1416 | .format_trace = format_esp_encrypt_trace, |
| 1417 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1418 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1419 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1420 | .error_counters = esp_encrypt_error_counters, |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1421 | |
| 1422 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
| 1423 | .next_nodes = { |
| 1424 | [ESP_ENCRYPT_NEXT_DROP4] = "ip4-drop", |
| 1425 | [ESP_ENCRYPT_NEXT_DROP6] = "ip6-drop", |
| 1426 | [ESP_ENCRYPT_NEXT_DROP_MPLS] = "mpls-drop", |
| 1427 | [ESP_ENCRYPT_NEXT_HANDOFF4] = "esp4-encrypt-tun-handoff", |
| 1428 | [ESP_ENCRYPT_NEXT_HANDOFF6] = "esp6-encrypt-tun-handoff", |
| 1429 | [ESP_ENCRYPT_NEXT_HANDOFF_MPLS] = "esp-mpls-encrypt-tun-handoff", |
| 1430 | [ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "adj-midchain-tx", |
| 1431 | }, |
| 1432 | }; |
| 1433 | |
| 1434 | VLIB_NODE_FN (esp_mpls_encrypt_tun_post_node) |
| 1435 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame) |
| 1436 | { |
| 1437 | return esp_encrypt_post_inline (vm, node, from_frame); |
| 1438 | } |
| 1439 | |
| 1440 | VLIB_REGISTER_NODE (esp_mpls_encrypt_tun_post_node) = { |
| 1441 | .name = "esp-mpls-encrypt-tun-post", |
| 1442 | .vector_size = sizeof (u32), |
| 1443 | .format_trace = format_esp_post_encrypt_trace, |
| 1444 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1445 | .sibling_of = "esp-mpls-encrypt-tun", |
| 1446 | |
Neale Ranns | 93688d7 | 2022-08-09 03:34:51 +0000 | [diff] [blame] | 1447 | .n_errors = ESP_ENCRYPT_N_ERROR, |
| 1448 | .error_counters = esp_encrypt_error_counters, |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 1449 | }; |
| 1450 | |
Neale Ranns | 2d49830 | 2021-02-25 08:38:58 +0000 | [diff] [blame] | 1451 | #ifndef CLIB_MARCH_VARIANT |
| 1452 | |
| 1453 | static clib_error_t * |
| 1454 | esp_encrypt_init (vlib_main_t *vm) |
| 1455 | { |
| 1456 | ipsec_main_t *im = &ipsec_main; |
| 1457 | |
| 1458 | im->esp4_enc_fq_index = |
| 1459 | vlib_frame_queue_main_init (esp4_encrypt_node.index, 0); |
| 1460 | im->esp6_enc_fq_index = |
| 1461 | vlib_frame_queue_main_init (esp6_encrypt_node.index, 0); |
| 1462 | im->esp4_enc_tun_fq_index = |
| 1463 | vlib_frame_queue_main_init (esp4_encrypt_tun_node.index, 0); |
| 1464 | im->esp6_enc_tun_fq_index = |
| 1465 | vlib_frame_queue_main_init (esp6_encrypt_tun_node.index, 0); |
| 1466 | im->esp_mpls_enc_tun_fq_index = |
| 1467 | vlib_frame_queue_main_init (esp_mpls_encrypt_tun_node.index, 0); |
| 1468 | |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | VLIB_INIT_FUNCTION (esp_encrypt_init); |
| 1473 | |
| 1474 | #endif |
| 1475 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 1476 | /* |
| 1477 | * fd.io coding-style-patch-verification: ON |
| 1478 | * |
| 1479 | * Local Variables: |
| 1480 | * eval: (c-set-style "gnu") |
| 1481 | * End: |
| 1482 | */ |