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