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