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> |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 21 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 22 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 23 | #include <vnet/crypto/crypto.h> |
| 24 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | #include <vnet/ipsec/ipsec.h> |
| 26 | #include <vnet/ipsec/esp.h> |
| 27 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | #define foreach_esp_encrypt_next \ |
| 29 | _(DROP, "error-drop") \ |
Sergio Gonzalez Monroy | 1b6f902 | 2016-12-12 10:37:49 +0000 | [diff] [blame] | 30 | _(IP4_LOOKUP, "ip4-lookup") \ |
| 31 | _(IP6_LOOKUP, "ip6-lookup") \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | _(INTERFACE_OUTPUT, "interface-output") |
| 33 | |
| 34 | #define _(v, s) ESP_ENCRYPT_NEXT_##v, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 35 | typedef enum |
| 36 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | foreach_esp_encrypt_next |
| 38 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 39 | ESP_ENCRYPT_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | } esp_encrypt_next_t; |
| 41 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 42 | #define foreach_esp_encrypt_error \ |
| 43 | _(RX_PKTS, "ESP pkts received") \ |
| 44 | _(SEQ_CYCLED, "sequence number cycled (packet dropped)") \ |
| 45 | _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \ |
| 46 | _(CHAINED_BUFFER, "chained buffers (packet dropped)") \ |
| 47 | _(NO_TRAILER_SPACE, "no trailer space (packet dropped)") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 49 | typedef enum |
| 50 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | #define _(sym,str) ESP_ENCRYPT_ERROR_##sym, |
| 52 | foreach_esp_encrypt_error |
| 53 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 54 | ESP_ENCRYPT_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | } esp_encrypt_error_t; |
| 56 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 57 | static char *esp_encrypt_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | #define _(sym,string) string, |
| 59 | foreach_esp_encrypt_error |
| 60 | #undef _ |
| 61 | }; |
| 62 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 63 | typedef struct |
| 64 | { |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 65 | u32 sa_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | u32 spi; |
| 67 | u32 seq; |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 68 | u8 udp_encap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | ipsec_crypto_alg_t crypto_alg; |
| 70 | ipsec_integ_alg_t integ_alg; |
| 71 | } esp_encrypt_trace_t; |
| 72 | |
| 73 | /* packet trace format function */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 74 | static u8 * |
| 75 | format_esp_encrypt_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | { |
| 77 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 78 | 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] | 79 | esp_encrypt_trace_t *t = va_arg (*args, esp_encrypt_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 81 | s = format (s, "esp: sa-index %d spi %u seq %u crypto %U integrity %U%s", |
| 82 | t->sa_index, t->spi, t->seq, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 83 | format_ipsec_crypto_alg, t->crypto_alg, |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 84 | format_ipsec_integ_alg, t->integ_alg, |
| 85 | t->udp_encap ? " udp-encap-enabled" : ""); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | return s; |
| 87 | } |
| 88 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 89 | /* pad packet in input buffer */ |
| 90 | static_always_inline u8 * |
| 91 | esp_add_footer_and_icv (vlib_buffer_t * b, u8 block_size, u8 icv_sz) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 93 | static const u8 pad_data[ESP_MAX_BLOCK_SIZE] = { |
| 94 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 95 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x00, 0x00, |
| 96 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 98 | u16 min_length = b->current_length + sizeof (esp_footer_t); |
| 99 | u16 new_length = round_pow2 (min_length, block_size); |
| 100 | u8 pad_bytes = new_length - min_length; |
| 101 | esp_footer_t *f = (esp_footer_t *) (vlib_buffer_get_current (b) + |
| 102 | new_length - sizeof (esp_footer_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 104 | if (pad_bytes) |
| 105 | clib_memcpy_fast ((u8 *) f - pad_bytes, pad_data, ESP_MAX_BLOCK_SIZE); |
| 106 | |
| 107 | f->pad_length = pad_bytes; |
| 108 | b->current_length = new_length + icv_sz; |
| 109 | return &f->next_header; |
| 110 | } |
| 111 | |
| 112 | static_always_inline void |
| 113 | esp_update_ip4_hdr (ip4_header_t * ip4, u16 len, int is_transport, int is_udp) |
| 114 | { |
Neale Ranns | 1b582b8 | 2019-04-18 19:49:13 -0700 | [diff] [blame] | 115 | ip_csum_t sum; |
| 116 | u16 old_len; |
| 117 | |
| 118 | len = clib_net_to_host_u16 (len); |
| 119 | old_len = ip4->length; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 120 | |
| 121 | if (is_transport) |
| 122 | { |
| 123 | u8 prot = is_udp ? IP_PROTOCOL_UDP : IP_PROTOCOL_IPSEC_ESP; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 124 | |
Neale Ranns | 1b582b8 | 2019-04-18 19:49:13 -0700 | [diff] [blame] | 125 | sum = ip_csum_update (ip4->checksum, ip4->protocol, |
| 126 | prot, ip4_header_t, protocol); |
| 127 | ip4->protocol = prot; |
| 128 | |
| 129 | sum = ip_csum_update (sum, old_len, len, ip4_header_t, length); |
| 130 | } |
| 131 | else |
| 132 | sum = ip_csum_update (ip4->checksum, old_len, len, ip4_header_t, length); |
| 133 | |
| 134 | ip4->length = len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 135 | ip4->checksum = ip_csum_fold (sum); |
| 136 | } |
| 137 | |
| 138 | static_always_inline void |
| 139 | esp_fill_udp_hdr (ipsec_sa_t * sa, udp_header_t * udp, u16 len) |
| 140 | { |
| 141 | clib_memcpy_fast (udp, &sa->udp_hdr, sizeof (udp_header_t)); |
| 142 | udp->length = clib_net_to_host_u16 (len); |
| 143 | } |
| 144 | |
| 145 | static_always_inline u8 |
| 146 | ext_hdr_is_pre_esp (u8 nexthdr) |
| 147 | { |
| 148 | #ifdef CLIB_HAVE_VEC128 |
| 149 | static const u8x16 ext_hdr_types = { |
| 150 | IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS, |
| 151 | IP_PROTOCOL_IPV6_ROUTE, |
| 152 | IP_PROTOCOL_IPV6_FRAGMENTATION, |
| 153 | }; |
| 154 | |
| 155 | return !u8x16_is_all_zero (ext_hdr_types == u8x16_splat (nexthdr)); |
| 156 | #else |
| 157 | return ((nexthdr ^ IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS) | |
| 158 | (nexthdr ^ IP_PROTOCOL_IPV6_ROUTE) | |
| 159 | (nexthdr ^ IP_PROTOCOL_IPV6_FRAGMENTATION) != 0); |
| 160 | #endif |
| 161 | } |
| 162 | |
| 163 | static_always_inline u8 |
| 164 | esp_get_ip6_hdr_len (ip6_header_t * ip6) |
| 165 | { |
| 166 | /* this code assumes that HbH, route and frag headers will be before |
| 167 | others, if that is not the case, they will end up encrypted */ |
| 168 | |
| 169 | u8 len = sizeof (ip6_header_t); |
| 170 | ip6_ext_header_t *p; |
| 171 | |
| 172 | /* if next packet doesn't have ext header */ |
| 173 | if (ext_hdr_is_pre_esp (ip6->protocol) == 0) |
| 174 | return len; |
| 175 | |
| 176 | p = (void *) (ip6 + 1); |
| 177 | len += ip6_ext_header_len (p); |
| 178 | |
| 179 | while (ext_hdr_is_pre_esp (p->next_hdr)) |
| 180 | { |
| 181 | len += ip6_ext_header_len (p); |
| 182 | p = ip6_ext_next_header (p); |
| 183 | } |
| 184 | |
| 185 | return len; |
| 186 | } |
| 187 | |
| 188 | static_always_inline int |
| 189 | esp_trailer_icv_overflow (vlib_node_runtime_t * node, vlib_buffer_t * b, |
| 190 | u16 * next, u16 buffer_data_size) |
| 191 | { |
| 192 | if (b->current_data + b->current_length <= buffer_data_size) |
| 193 | return 0; |
| 194 | |
| 195 | b->current_length -= buffer_data_size - b->current_data; |
| 196 | b->error = node->errors[ESP_ENCRYPT_ERROR_NO_TRAILER_SPACE]; |
| 197 | next[0] = ESP_ENCRYPT_NEXT_DROP; |
| 198 | return 1; |
| 199 | } |
| 200 | |
| 201 | static_always_inline void |
| 202 | esp_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 203 | vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts) |
| 204 | { |
| 205 | u32 n_fail, n_ops = vec_len (ops); |
| 206 | vnet_crypto_op_t *op = ops; |
| 207 | |
| 208 | if (n_ops == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | return; |
| 210 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 211 | n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 213 | while (n_fail) |
| 214 | { |
| 215 | ASSERT (op - ops < n_ops); |
| 216 | |
| 217 | if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED) |
| 218 | { |
| 219 | u32 bi = op->user_data; |
| 220 | b[bi]->error = node->errors[ESP_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR]; |
| 221 | nexts[bi] = ESP_ENCRYPT_NEXT_DROP; |
| 222 | n_fail--; |
| 223 | } |
| 224 | op++; |
| 225 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Damjan Marion | d97918e | 2019-04-25 18:28:31 +0200 | [diff] [blame] | 228 | typedef struct |
| 229 | { |
| 230 | u32 salt; |
| 231 | u64 iv; |
| 232 | } __clib_packed esp_gcm_nonce_t; |
| 233 | |
| 234 | STATIC_ASSERT_SIZEOF (esp_gcm_nonce_t, 12); |
| 235 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 236 | always_inline uword |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 237 | esp_encrypt_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 238 | vlib_frame_t * frame, int is_ip6, int is_tun) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 239 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | ipsec_main_t *im = &ipsec_main; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 241 | ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, vm->thread_index); |
| 242 | u32 *from = vlib_frame_vector_args (frame); |
| 243 | u32 n_left = frame->n_vectors; |
| 244 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 245 | u16 nexts[VLIB_FRAME_SIZE], *next = nexts; |
Damjan Marion | d97918e | 2019-04-25 18:28:31 +0200 | [diff] [blame] | 246 | esp_gcm_nonce_t nonces[VLIB_FRAME_SIZE], *nonce = nonces; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 247 | u32 thread_index = vm->thread_index; |
| 248 | u16 buffer_data_size = vlib_buffer_get_default_data_size (vm); |
| 249 | u32 current_sa_index = ~0, current_sa_packets = 0; |
| 250 | u32 current_sa_bytes = 0, spi = 0; |
| 251 | u8 block_sz = 0, iv_sz = 0, icv_sz = 0; |
| 252 | ipsec_sa_t *sa0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 254 | vlib_get_buffers (vm, from, b, n_left); |
| 255 | vec_reset_length (ptd->crypto_ops); |
| 256 | vec_reset_length (ptd->integ_ops); |
| 257 | |
| 258 | while (n_left > 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 259 | { |
Zhiyong Yang | 1cff643 | 2019-04-30 05:33:53 -0400 | [diff] [blame] | 260 | u32 sa_index0; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 261 | dpo_id_t *dpo; |
| 262 | esp_header_t *esp; |
| 263 | u8 *payload, *next_hdr_ptr; |
| 264 | u16 payload_len; |
| 265 | u32 hdr_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 267 | if (n_left > 2) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 268 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 269 | u8 *p; |
| 270 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 271 | p = vlib_buffer_get_current (b[1]); |
| 272 | CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD); |
| 273 | p -= CLIB_CACHE_LINE_BYTES; |
| 274 | CLIB_PREFETCH (p, CLIB_CACHE_LINE_BYTES, LOAD); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 275 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 277 | if (is_tun) |
| 278 | { |
| 279 | /* we are on a ipsec tunnel's feature arc */ |
| 280 | u32 next0; |
| 281 | sa_index0 = *(u32 *) vnet_feature_next_with_data (&next0, b[0], |
| 282 | sizeof |
| 283 | (sa_index0)); |
| 284 | next[0] = next0; |
| 285 | } |
| 286 | else |
| 287 | sa_index0 = vnet_buffer (b[0])->ipsec.sad_index; |
| 288 | |
| 289 | if (sa_index0 != current_sa_index) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 290 | { |
| 291 | sa0 = pool_elt_at_index (im->sad, sa_index0); |
| 292 | current_sa_index = sa_index0; |
| 293 | vlib_increment_combined_counter (&ipsec_sa_counters, thread_index, |
| 294 | sa_index0, current_sa_packets, |
| 295 | current_sa_bytes); |
| 296 | current_sa_packets = current_sa_bytes = 0; |
| 297 | spi = clib_net_to_host_u32 (sa0->spi); |
| 298 | block_sz = sa0->crypto_block_size; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 299 | icv_sz = sa0->integ_icv_size; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 300 | iv_sz = sa0->crypto_iv_size; |
| 301 | } |
| 302 | |
| 303 | if (vlib_buffer_chain_linearize (vm, b[0]) != 1) |
| 304 | { |
| 305 | b[0]->error = node->errors[ESP_ENCRYPT_ERROR_CHAINED_BUFFER]; |
| 306 | next[0] = ESP_ENCRYPT_NEXT_DROP; |
| 307 | goto trace; |
| 308 | } |
| 309 | |
| 310 | if (PREDICT_FALSE (esp_seq_advance (sa0))) |
| 311 | { |
| 312 | b[0]->error = node->errors[ESP_ENCRYPT_ERROR_SEQ_CYCLED]; |
| 313 | next[0] = ESP_ENCRYPT_NEXT_DROP; |
| 314 | goto trace; |
| 315 | } |
| 316 | |
| 317 | /* space for IV */ |
| 318 | hdr_len = iv_sz; |
| 319 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 320 | if (ipsec_sa_is_set_IS_TUNNEL (sa0)) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 321 | { |
| 322 | payload = vlib_buffer_get_current (b[0]); |
| 323 | next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz); |
| 324 | payload_len = b[0]->current_length; |
| 325 | |
| 326 | if (esp_trailer_icv_overflow (node, b[0], next, buffer_data_size)) |
| 327 | goto trace; |
| 328 | |
| 329 | /* ESP header */ |
| 330 | hdr_len += sizeof (*esp); |
| 331 | esp = (esp_header_t *) (payload - hdr_len); |
| 332 | |
| 333 | /* optional UDP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 334 | if (ipsec_sa_is_set_UDP_ENCAP (sa0)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 335 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 336 | hdr_len += sizeof (udp_header_t); |
| 337 | esp_fill_udp_hdr (sa0, (udp_header_t *) (payload - hdr_len), |
| 338 | payload_len + hdr_len); |
| 339 | } |
| 340 | |
| 341 | /* IP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 342 | if (ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 343 | { |
| 344 | ip6_header_t *ip6; |
| 345 | u16 len = sizeof (ip6_header_t); |
| 346 | hdr_len += len; |
| 347 | ip6 = (ip6_header_t *) (payload - hdr_len); |
| 348 | clib_memcpy_fast (ip6, &sa0->ip6_hdr, len); |
Neale Ranns | 987aea8 | 2019-03-27 13:40:35 +0000 | [diff] [blame] | 349 | *next_hdr_ptr = (is_ip6 ? |
| 350 | IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 351 | len = payload_len + hdr_len - len; |
| 352 | ip6->payload_length = clib_net_to_host_u16 (len); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 353 | } |
| 354 | else |
| 355 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 356 | ip4_header_t *ip4; |
| 357 | u16 len = sizeof (ip4_header_t); |
| 358 | hdr_len += len; |
| 359 | ip4 = (ip4_header_t *) (payload - hdr_len); |
| 360 | clib_memcpy_fast (ip4, &sa0->ip4_hdr, len); |
Neale Ranns | 987aea8 | 2019-03-27 13:40:35 +0000 | [diff] [blame] | 361 | *next_hdr_ptr = (is_ip6 ? |
| 362 | IP_PROTOCOL_IPV6 : IP_PROTOCOL_IP_IN_IP); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 363 | len = payload_len + hdr_len; |
| 364 | esp_update_ip4_hdr (ip4, len, /* is_transport */ 0, 0); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 365 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 366 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 367 | dpo = sa0->dpo + IPSEC_PROTOCOL_ESP; |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 368 | if (!is_tun) |
| 369 | { |
| 370 | next[0] = dpo->dpoi_next_node; |
| 371 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpo->dpoi_index; |
| 372 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 373 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 374 | else /* transport mode */ |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 375 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 376 | u8 *l2_hdr, l2_len, *ip_hdr, ip_len; |
| 377 | udp_header_t *udp = 0; |
| 378 | u8 *old_ip_hdr = vlib_buffer_get_current (b[0]); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 379 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 380 | ip_len = is_ip6 ? |
| 381 | esp_get_ip6_hdr_len ((ip6_header_t *) old_ip_hdr) : |
| 382 | ip4_header_bytes ((ip4_header_t *) old_ip_hdr); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 383 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 384 | vlib_buffer_advance (b[0], ip_len); |
| 385 | payload = vlib_buffer_get_current (b[0]); |
| 386 | next_hdr_ptr = esp_add_footer_and_icv (b[0], block_sz, icv_sz); |
| 387 | payload_len = b[0]->current_length; |
| 388 | |
| 389 | if (esp_trailer_icv_overflow (node, b[0], next, buffer_data_size)) |
| 390 | goto trace; |
| 391 | |
| 392 | /* ESP header */ |
| 393 | hdr_len += sizeof (*esp); |
| 394 | esp = (esp_header_t *) (payload - hdr_len); |
| 395 | |
| 396 | /* optional UDP header */ |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 397 | if (ipsec_sa_is_set_UDP_ENCAP (sa0)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 398 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 399 | hdr_len += sizeof (udp_header_t); |
| 400 | udp = (udp_header_t *) (payload - hdr_len); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 403 | /* IP header */ |
| 404 | hdr_len += ip_len; |
| 405 | ip_hdr = payload - hdr_len; |
| 406 | |
| 407 | /* L2 header */ |
| 408 | l2_len = vnet_buffer (b[0])->ip.save_rewrite_length; |
| 409 | hdr_len += l2_len; |
| 410 | l2_hdr = payload - hdr_len; |
| 411 | |
| 412 | /* copy l2 and ip header */ |
| 413 | clib_memcpy_le32 (l2_hdr, old_ip_hdr - l2_len, l2_len); |
| 414 | clib_memcpy_le64 (ip_hdr, old_ip_hdr, ip_len); |
| 415 | |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 416 | if (is_ip6) |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 417 | { |
| 418 | ip6_header_t *ip6 = (ip6_header_t *) (ip_hdr); |
| 419 | *next_hdr_ptr = ip6->protocol; |
| 420 | ip6->protocol = IP_PROTOCOL_IPSEC_ESP; |
Neale Ranns | d207fd7 | 2019-04-18 17:18:12 -0700 | [diff] [blame] | 421 | ip6->payload_length = |
| 422 | clib_host_to_net_u16 (payload_len + hdr_len - l2_len - |
| 423 | ip_len); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 424 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 425 | else |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 426 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 427 | u16 len; |
| 428 | ip4_header_t *ip4 = (ip4_header_t *) (ip_hdr); |
| 429 | *next_hdr_ptr = ip4->protocol; |
Neale Ranns | 1b582b8 | 2019-04-18 19:49:13 -0700 | [diff] [blame] | 430 | len = payload_len + hdr_len - l2_len; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 431 | if (udp) |
| 432 | { |
| 433 | esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 1); |
| 434 | esp_fill_udp_hdr (sa0, udp, len - ip_len); |
| 435 | } |
| 436 | else |
| 437 | esp_update_ip4_hdr (ip4, len, /* is_transport */ 1, 0); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 438 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 439 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 440 | next[0] = ESP_ENCRYPT_NEXT_INTERFACE_OUTPUT; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 443 | esp->spi = spi; |
| 444 | esp->seq = clib_net_to_host_u32 (sa0->seq); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 445 | |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 446 | if (sa0->crypto_enc_op_id) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 447 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 448 | vnet_crypto_op_t *op; |
| 449 | vec_add2_aligned (ptd->crypto_ops, op, 1, CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 450 | vnet_crypto_op_init (op, sa0->crypto_enc_op_id); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 451 | op->src = op->dst = payload; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 452 | op->key_index = sa0->crypto_key_index; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 453 | op->len = payload_len - icv_sz; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 454 | op->user_data = b - bufs; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 455 | |
| 456 | if (ipsec_sa_is_set_IS_AEAD (sa0)) |
| 457 | { |
| 458 | /* |
| 459 | * construct the AAD in a scratch space in front |
| 460 | * of the IP header. |
| 461 | */ |
| 462 | op->aad = payload - hdr_len - sizeof (esp_aead_t); |
| 463 | |
| 464 | esp_aad_fill (op, esp, sa0); |
| 465 | |
| 466 | op->tag = payload + op->len; |
| 467 | op->tag_len = 16; |
Damjan Marion | d97918e | 2019-04-25 18:28:31 +0200 | [diff] [blame] | 468 | |
| 469 | u64 *iv = (u64 *) (payload - iv_sz); |
| 470 | nonce->salt = sa0->salt; |
| 471 | nonce->iv = *iv = clib_host_to_net_u64 (sa0->gcm_iv_counter++); |
| 472 | op->iv = (u8 *) nonce; |
| 473 | nonce++; |
| 474 | } |
| 475 | else |
| 476 | { |
| 477 | op->iv = payload - iv_sz; |
| 478 | op->flags = VNET_CRYPTO_OP_FLAG_INIT_IV; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 479 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 480 | } |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 481 | |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 482 | if (sa0->integ_op_id) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 483 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 484 | vnet_crypto_op_t *op; |
| 485 | vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 486 | vnet_crypto_op_init (op, sa0->integ_op_id); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 487 | op->src = payload - iv_sz - sizeof (esp_header_t); |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 488 | op->digest = payload + payload_len - icv_sz; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 489 | op->key_index = sa0->integ_key_index; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 490 | op->digest_len = icv_sz; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 491 | op->len = payload_len - icv_sz + iv_sz + sizeof (esp_header_t); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 492 | op->user_data = b - bufs; |
Damjan Marion | 1e3aa5e | 2019-03-28 10:58:59 +0100 | [diff] [blame] | 493 | if (ipsec_sa_is_set_USE_ESN (sa0)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 494 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 495 | u32 seq_hi = clib_net_to_host_u32 (sa0->seq_hi); |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 496 | clib_memcpy_fast (op->digest, &seq_hi, sizeof (seq_hi)); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 497 | op->len += sizeof (seq_hi); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 501 | vlib_buffer_advance (b[0], 0LL - hdr_len); |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 502 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 503 | current_sa_packets += 1; |
| 504 | current_sa_bytes += payload_len; |
| 505 | |
| 506 | trace: |
| 507 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 508 | { |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 509 | esp_encrypt_trace_t *tr = vlib_add_trace (vm, node, b[0], |
| 510 | sizeof (*tr)); |
| 511 | tr->sa_index = sa_index0; |
| 512 | tr->spi = sa0->spi; |
| 513 | tr->seq = sa0->seq - 1; |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 514 | tr->udp_encap = ipsec_sa_is_set_UDP_ENCAP (sa0); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 515 | tr->crypto_alg = sa0->crypto_alg; |
| 516 | tr->integ_alg = sa0->integ_alg; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 517 | } |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 518 | /* next */ |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 519 | n_left -= 1; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 520 | next += 1; |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 521 | b += 1; |
Damjan Marion | c98275f | 2019-03-06 14:05:01 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 524 | vlib_increment_combined_counter (&ipsec_sa_counters, thread_index, |
| 525 | current_sa_index, current_sa_packets, |
| 526 | current_sa_bytes); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 527 | esp_process_ops (vm, node, ptd->crypto_ops, bufs, nexts); |
| 528 | esp_process_ops (vm, node, ptd->integ_ops, bufs, nexts); |
| 529 | |
| 530 | vlib_node_increment_counter (vm, node->node_index, |
| 531 | ESP_ENCRYPT_ERROR_RX_PKTS, frame->n_vectors); |
| 532 | |
| 533 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
| 534 | return frame->n_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 537 | VLIB_NODE_FN (esp4_encrypt_node) (vlib_main_t * vm, |
| 538 | vlib_node_runtime_t * node, |
| 539 | vlib_frame_t * from_frame) |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 540 | { |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 541 | return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 0); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 542 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 543 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 544 | /* *INDENT-OFF* */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 545 | VLIB_REGISTER_NODE (esp4_encrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 546 | .name = "esp4-encrypt", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 547 | .vector_size = sizeof (u32), |
| 548 | .format_trace = format_esp_encrypt_trace, |
| 549 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 550 | |
| 551 | .n_errors = ARRAY_LEN(esp_encrypt_error_strings), |
| 552 | .error_strings = esp_encrypt_error_strings, |
| 553 | |
| 554 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
| 555 | .next_nodes = { |
| 556 | #define _(s,n) [ESP_ENCRYPT_NEXT_##s] = n, |
| 557 | foreach_esp_encrypt_next |
| 558 | #undef _ |
| 559 | }, |
| 560 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 561 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 563 | VLIB_NODE_FN (esp6_encrypt_node) (vlib_main_t * vm, |
| 564 | vlib_node_runtime_t * node, |
| 565 | vlib_frame_t * from_frame) |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 566 | { |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 567 | return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 0); |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* *INDENT-OFF* */ |
| 571 | VLIB_REGISTER_NODE (esp6_encrypt_node) = { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 572 | .name = "esp6-encrypt", |
| 573 | .vector_size = sizeof (u32), |
| 574 | .format_trace = format_esp_encrypt_trace, |
| 575 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 576 | |
| 577 | .n_errors = ARRAY_LEN(esp_encrypt_error_strings), |
| 578 | .error_strings = esp_encrypt_error_strings, |
| 579 | |
| 580 | .n_next_nodes = ESP_ENCRYPT_N_NEXT, |
| 581 | .next_nodes = { |
| 582 | #define _(s,n) [ESP_ENCRYPT_NEXT_##s] = n, |
| 583 | foreach_esp_encrypt_next |
| 584 | #undef _ |
| 585 | }, |
| 586 | }; |
| 587 | /* *INDENT-ON* */ |
| 588 | |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 589 | VLIB_NODE_FN (esp4_encrypt_tun_node) (vlib_main_t * vm, |
| 590 | vlib_node_runtime_t * node, |
| 591 | vlib_frame_t * from_frame) |
| 592 | { |
| 593 | return esp_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ , 1); |
| 594 | } |
| 595 | |
| 596 | /* *INDENT-OFF* */ |
| 597 | VLIB_REGISTER_NODE (esp4_encrypt_tun_node) = { |
| 598 | .name = "esp4-encrypt-tun", |
| 599 | .vector_size = sizeof (u32), |
| 600 | .format_trace = format_esp_encrypt_trace, |
| 601 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 602 | |
| 603 | .n_errors = ARRAY_LEN(esp_encrypt_error_strings), |
| 604 | .error_strings = esp_encrypt_error_strings, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 605 | |
| 606 | .n_next_nodes = 1, |
| 607 | .next_nodes = { |
| 608 | [ESP_ENCRYPT_NEXT_DROP] = "ip4-drop", |
| 609 | }, |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 610 | }; |
| 611 | |
| 612 | VNET_FEATURE_INIT (esp4_encrypt_tun_feat_node, static) = |
| 613 | { |
| 614 | .arc_name = "ip4-output", |
| 615 | .node_name = "esp4-encrypt-tun", |
Neale Ranns | ea5bb77 | 2019-04-02 05:43:34 -0700 | [diff] [blame] | 616 | .runs_before = VNET_FEATURES ("adj-midchain-tx"), |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 617 | }; |
| 618 | /* *INDENT-ON* */ |
| 619 | |
| 620 | VLIB_NODE_FN (esp6_encrypt_tun_node) (vlib_main_t * vm, |
| 621 | vlib_node_runtime_t * node, |
| 622 | vlib_frame_t * from_frame) |
| 623 | { |
| 624 | return esp_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ , 1); |
| 625 | } |
| 626 | |
| 627 | /* *INDENT-OFF* */ |
| 628 | VLIB_REGISTER_NODE (esp6_encrypt_tun_node) = { |
| 629 | .name = "esp6-encrypt-tun", |
| 630 | .vector_size = sizeof (u32), |
| 631 | .format_trace = format_esp_encrypt_trace, |
| 632 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 633 | |
| 634 | .n_errors = ARRAY_LEN(esp_encrypt_error_strings), |
| 635 | .error_strings = esp_encrypt_error_strings, |
Neale Ranns | d7603d9 | 2019-03-28 08:56:10 +0000 | [diff] [blame] | 636 | |
| 637 | .n_next_nodes = 1, |
| 638 | .next_nodes = { |
| 639 | [ESP_ENCRYPT_NEXT_DROP] = "ip6-drop", |
| 640 | }, |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 641 | }; |
| 642 | |
| 643 | VNET_FEATURE_INIT (esp6_encrypt_tun_feat_node, static) = |
| 644 | { |
| 645 | .arc_name = "ip6-output", |
| 646 | .node_name = "esp6-encrypt-tun", |
Neale Ranns | ea5bb77 | 2019-04-02 05:43:34 -0700 | [diff] [blame] | 647 | .runs_before = VNET_FEATURES ("adj-midchain-tx"), |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 648 | }; |
| 649 | /* *INDENT-ON* */ |
| 650 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 651 | /* |
| 652 | * fd.io coding-style-patch-verification: ON |
| 653 | * |
| 654 | * Local Variables: |
| 655 | * eval: (c-set-style "gnu") |
| 656 | * End: |
| 657 | */ |