Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ipsec_if_in.c : IPSec interface input 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 | |
| 22 | #include <vnet/ipsec/ipsec.h> |
| 23 | #include <vnet/ipsec/esp.h> |
Neale Ranns | 918c161 | 2019-02-21 23:34:59 -0800 | [diff] [blame] | 24 | #include <vnet/ipsec/ipsec_io.h> |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 25 | #include <vnet/ipsec/ipsec_punt.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | |
| 27 | /* Statistics (not really errors) */ |
Matthew Smith | 831fd64 | 2018-05-15 22:03:05 -0500 | [diff] [blame] | 28 | #define foreach_ipsec_if_input_error \ |
| 29 | _(RX, "good packets received") \ |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 30 | _(DISABLED, "ipsec packets received on disabled interface") \ |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 31 | _(NO_TUNNEL, "no matching tunnel") \ |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 32 | _(NAT_KEEPALIVE, "NAT Keepalive") \ |
| 33 | _(TOO_SHORT, "Too Short") \ |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 34 | _(SPI_0, "SPI 0") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 36 | static char *ipsec_if_input_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | #define _(sym,string) string, |
| 38 | foreach_ipsec_if_input_error |
| 39 | #undef _ |
| 40 | }; |
| 41 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 42 | typedef enum |
| 43 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | #define _(sym,str) IPSEC_IF_INPUT_ERROR_##sym, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 45 | foreach_ipsec_if_input_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | #undef _ |
| 47 | IPSEC_IF_INPUT_N_ERROR, |
| 48 | } ipsec_if_input_error_t; |
| 49 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 51 | typedef struct |
| 52 | { |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 53 | union |
| 54 | { |
| 55 | ipsec4_tunnel_key_t key4; |
| 56 | ipsec6_tunnel_key_t key6; |
| 57 | }; |
| 58 | u8 is_ip6; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | u32 seq; |
| 60 | } ipsec_if_input_trace_t; |
| 61 | |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 62 | static u8 * |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 63 | format_ipsec_if_input_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | { |
| 65 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 66 | 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] | 67 | ipsec_if_input_trace_t *t = va_arg (*args, ipsec_if_input_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 69 | if (t->is_ip6) |
| 70 | s = format (s, "IPSec: %U seq %u", |
| 71 | format_ipsec6_tunnel_key, &t->key6, t->seq); |
| 72 | else |
| 73 | s = format (s, "IPSec: %U seq %u", |
| 74 | format_ipsec4_tunnel_key, &t->key4, t->seq); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | return s; |
| 76 | } |
| 77 | |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 78 | always_inline u16 |
| 79 | ipsec_ip4_if_no_tunnel (vlib_node_runtime_t * node, |
| 80 | vlib_buffer_t * b, |
| 81 | const esp_header_t * esp, |
| 82 | const ip4_header_t * ip4, u16 offset) |
| 83 | { |
| 84 | if (PREDICT_FALSE (0 == esp->spi)) |
| 85 | { |
| 86 | b->error = node->errors[IPSEC_IF_INPUT_ERROR_SPI_0]; |
| 87 | b->punt_reason = |
| 88 | ipsec_punt_reason[(ip4->protocol == IP_PROTOCOL_UDP ? |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 89 | IPSEC_PUNT_IP4_SPI_UDP_0 : |
| 90 | IPSEC_PUNT_IP4_NO_SUCH_TUNNEL)]; |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 91 | } |
| 92 | else |
| 93 | { |
| 94 | b->error = node->errors[IPSEC_IF_INPUT_ERROR_NO_TUNNEL]; |
| 95 | b->punt_reason = ipsec_punt_reason[IPSEC_PUNT_IP4_NO_SUCH_TUNNEL]; |
| 96 | } |
| 97 | vlib_buffer_advance (b, -offset); |
| 98 | return IPSEC_INPUT_NEXT_PUNT; |
| 99 | } |
| 100 | |
| 101 | always_inline u16 |
| 102 | ipsec_ip6_if_no_tunnel (vlib_node_runtime_t * node, |
| 103 | vlib_buffer_t * b, |
| 104 | const esp_header_t * esp, u16 offset) |
| 105 | { |
Neale Ranns | 719beb7 | 2019-07-10 07:10:25 +0000 | [diff] [blame] | 106 | b->error = node->errors[IPSEC_IF_INPUT_ERROR_NO_TUNNEL]; |
| 107 | b->punt_reason = ipsec_punt_reason[IPSEC_PUNT_IP6_NO_SUCH_TUNNEL]; |
| 108 | |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 109 | vlib_buffer_advance (b, -offset); |
| 110 | return (IPSEC_INPUT_NEXT_PUNT); |
| 111 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 112 | |
| 113 | always_inline uword |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 114 | ipsec_if_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 115 | vlib_frame_t * from_frame, int is_ip6) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | { |
| 117 | ipsec_main_t *im = &ipsec_main; |
Matthew Smith | 01034be | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 118 | vnet_main_t *vnm = im->vnet_main; |
| 119 | vnet_interface_main_t *vim = &vnm->interface_main; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 120 | |
| 121 | int is_trace = node->flags & VLIB_NODE_FLAG_TRACE; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 122 | u32 thread_index = vm->thread_index; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 123 | |
| 124 | u32 n_left_from, *from; |
| 125 | u16 nexts[VLIB_FRAME_SIZE], *next; |
| 126 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 127 | |
| 128 | from = vlib_frame_vector_args (from_frame); |
| 129 | n_left_from = from_frame->n_vectors; |
| 130 | |
| 131 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 132 | b = bufs; |
| 133 | next = nexts; |
| 134 | |
| 135 | clib_memset_u16 (nexts, im->esp4_decrypt_next_index, n_left_from); |
| 136 | |
Matthew Smith | 01034be | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 137 | u64 n_bytes = 0, n_packets = 0; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 138 | u32 n_disabled = 0, n_no_tunnel = 0; |
| 139 | |
| 140 | u32 last_sw_if_index = ~0; |
| 141 | u32 last_tunnel_id = ~0; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 142 | ipsec4_tunnel_key_t last_key4; |
| 143 | ipsec6_tunnel_key_t last_key6; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 144 | |
Matthew Smith | 831fd64 | 2018-05-15 22:03:05 -0500 | [diff] [blame] | 145 | vlib_combined_counter_main_t *rx_counter; |
| 146 | vlib_combined_counter_main_t *drop_counter; |
Matthew Smith | 831fd64 | 2018-05-15 22:03:05 -0500 | [diff] [blame] | 147 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 148 | if (is_ip6) |
| 149 | clib_memset (&last_key6, 0xff, sizeof (last_key6)); |
| 150 | else |
| 151 | last_key4.as_u64 = ~0; |
| 152 | |
Matthew Smith | 831fd64 | 2018-05-15 22:03:05 -0500 | [diff] [blame] | 153 | rx_counter = vim->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX; |
| 154 | drop_counter = vim->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 155 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 156 | while (n_left_from >= 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 158 | u32 sw_if_index0, sw_if_index1; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 159 | ip4_header_t *ip40, *ip41; |
| 160 | ip6_header_t *ip60, *ip61; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 161 | esp_header_t *esp0, *esp1; |
| 162 | u32 len0, len1; |
| 163 | u16 buf_adv0, buf_adv1; |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 164 | u16 buf_rewind0, buf_rewind1; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 165 | u32 tid0, tid1; |
| 166 | ipsec_tunnel_if_t *t0, *t1; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 167 | ipsec4_tunnel_key_t key40, key41; |
| 168 | ipsec6_tunnel_key_t key60, key61; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 170 | if (n_left_from >= 4) |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 171 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 172 | CLIB_PREFETCH (b[2], CLIB_CACHE_LINE_BYTES, STORE); |
| 173 | CLIB_PREFETCH (b[2]->data, CLIB_CACHE_LINE_BYTES, LOAD); |
| 174 | CLIB_PREFETCH (b[3], CLIB_CACHE_LINE_BYTES, STORE); |
| 175 | CLIB_PREFETCH (b[3]->data, CLIB_CACHE_LINE_BYTES, LOAD); |
| 176 | } |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 177 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 178 | ip40 = |
| 179 | (ip4_header_t *) (b[0]->data + vnet_buffer (b[0])->l3_hdr_offset); |
| 180 | ip41 = |
| 181 | (ip4_header_t *) (b[1]->data + vnet_buffer (b[1])->l3_hdr_offset); |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 182 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 183 | if (is_ip6) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 184 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 185 | ip60 = (ip6_header_t *) ip40; |
| 186 | ip61 = (ip6_header_t *) ip41; |
| 187 | esp0 = (esp_header_t *) ((u8 *) ip60 + sizeof (ip6_header_t)); |
| 188 | esp1 = (esp_header_t *) ((u8 *) ip61 + sizeof (ip6_header_t)); |
| 189 | buf_adv0 = sizeof (ip6_header_t); |
| 190 | buf_adv1 = sizeof (ip6_header_t); |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 191 | } |
| 192 | else |
| 193 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 194 | /* NAT UDP port 4500 case, don't advance any more */ |
| 195 | if (ip40->protocol == IP_PROTOCOL_UDP) |
| 196 | { |
| 197 | esp0 = |
| 198 | (esp_header_t *) ((u8 *) ip40 + ip4_header_bytes (ip40) + |
| 199 | sizeof (udp_header_t)); |
| 200 | buf_adv0 = 0; |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 201 | buf_rewind0 = ip4_header_bytes (ip40) + sizeof (udp_header_t); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 202 | } |
| 203 | else |
| 204 | { |
| 205 | esp0 = (esp_header_t *) ((u8 *) ip40 + ip4_header_bytes (ip40)); |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 206 | buf_rewind0 = buf_adv0 = ip4_header_bytes (ip40); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 207 | } |
| 208 | /* NAT UDP port 4500 case, don't advance any more */ |
| 209 | if (ip41->protocol == IP_PROTOCOL_UDP) |
| 210 | { |
| 211 | esp1 = |
| 212 | (esp_header_t *) ((u8 *) ip41 + ip4_header_bytes (ip41) + |
| 213 | sizeof (udp_header_t)); |
| 214 | buf_adv1 = 0; |
Neale Ranns | 37dab43 | 2019-07-16 00:53:22 -0700 | [diff] [blame] | 215 | buf_rewind1 = ip4_header_bytes (ip41) + sizeof (udp_header_t); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 216 | } |
| 217 | else |
| 218 | { |
| 219 | esp1 = (esp_header_t *) ((u8 *) ip41 + ip4_header_bytes (ip41)); |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 220 | buf_rewind1 = buf_adv1 = ip4_header_bytes (ip41); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 221 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 222 | } |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 223 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 224 | vlib_buffer_advance (b[0], buf_adv0); |
| 225 | vlib_buffer_advance (b[1], buf_adv1); |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 226 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 227 | len0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 228 | len1 = vlib_buffer_length_in_chain (vm, b[1]); |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 229 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 230 | /* If the packet is too short to contain an SPI, then maybe |
| 231 | * it's a keep alive */ |
| 232 | if (len0 < sizeof (esp_header_t)) |
| 233 | { |
| 234 | if (esp0->spi_bytes[0] == 0xff) |
| 235 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_NAT_KEEPALIVE]; |
| 236 | else |
| 237 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_TOO_SHORT]; |
| 238 | |
| 239 | next[0] = IPSEC_INPUT_NEXT_DROP; |
| 240 | goto pkt1; |
| 241 | } |
| 242 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 243 | if (is_ip6) |
| 244 | { |
| 245 | key60.remote_ip = ip60->src_address; |
| 246 | key60.spi = esp0->spi; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 247 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 248 | if (memcmp (&key60, &last_key6, sizeof (last_key6)) == 0) |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 249 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 250 | tid0 = last_tunnel_id; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 251 | } |
| 252 | else |
| 253 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 254 | uword *p = |
| 255 | hash_get_mem (im->ipsec6_if_pool_index_by_key, &key60); |
| 256 | if (p) |
| 257 | { |
| 258 | tid0 = p[0]; |
| 259 | last_tunnel_id = tid0; |
| 260 | clib_memcpy_fast (&last_key6, &key60, sizeof (key60)); |
| 261 | } |
| 262 | else |
| 263 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 264 | next[0] = |
| 265 | ipsec_ip6_if_no_tunnel (node, b[0], esp0, buf_adv0); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 266 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 267 | goto pkt1; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | else /* !is_ip6 */ |
| 272 | { |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 273 | key40.remote_ip = ip40->src_address; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 274 | key40.spi = esp0->spi; |
| 275 | |
| 276 | if (key40.as_u64 == last_key4.as_u64) |
| 277 | { |
| 278 | tid0 = last_tunnel_id; |
| 279 | } |
| 280 | else |
| 281 | { |
| 282 | uword *p = |
| 283 | hash_get (im->ipsec4_if_pool_index_by_key, key40.as_u64); |
| 284 | if (p) |
| 285 | { |
| 286 | tid0 = p[0]; |
| 287 | last_tunnel_id = tid0; |
| 288 | last_key4.as_u64 = key40.as_u64; |
| 289 | } |
| 290 | else |
| 291 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 292 | next[0] = |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 293 | ipsec_ip4_if_no_tunnel (node, b[0], esp0, ip40, |
| 294 | buf_rewind0); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 295 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 296 | goto pkt1; |
| 297 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | t0 = pool_elt_at_index (im->tunnel_interfaces, tid0); |
| 302 | vnet_buffer (b[0])->ipsec.sad_index = t0->input_sa_index; |
| 303 | |
| 304 | if (PREDICT_TRUE (t0->hw_if_index != ~0)) |
| 305 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 306 | sw_if_index0 = t0->sw_if_index; |
| 307 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0; |
| 308 | |
| 309 | if (PREDICT_FALSE (!(t0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))) |
| 310 | { |
| 311 | vlib_increment_combined_counter |
| 312 | (drop_counter, thread_index, sw_if_index0, 1, len0); |
| 313 | n_disabled++; |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 314 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_DISABLED]; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 315 | next[0] = IPSEC_INPUT_NEXT_DROP; |
| 316 | goto pkt1; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 319 | if (PREDICT_TRUE (sw_if_index0 == last_sw_if_index)) |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 320 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 321 | n_packets++; |
| 322 | n_bytes += len0; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 323 | } |
| 324 | else |
| 325 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 326 | if (n_packets) |
| 327 | { |
| 328 | vlib_increment_combined_counter |
| 329 | (rx_counter, thread_index, last_sw_if_index, |
| 330 | n_packets, n_bytes); |
| 331 | } |
| 332 | |
| 333 | last_sw_if_index = sw_if_index0; |
| 334 | n_packets = 1; |
| 335 | n_bytes = len0; |
| 336 | } |
| 337 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 338 | |
| 339 | pkt1: |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 340 | |
| 341 | if (len1 < sizeof (esp_header_t)) |
| 342 | { |
| 343 | if (esp0->spi_bytes[0] == 0xff) |
| 344 | b[1]->error = node->errors[IPSEC_IF_INPUT_ERROR_NAT_KEEPALIVE]; |
| 345 | else |
| 346 | b[1]->error = node->errors[IPSEC_IF_INPUT_ERROR_TOO_SHORT]; |
| 347 | |
| 348 | next[1] = IPSEC_INPUT_NEXT_DROP; |
| 349 | goto trace1; |
| 350 | } |
| 351 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 352 | if (is_ip6) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 353 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 354 | key61.remote_ip = ip61->src_address; |
| 355 | key61.spi = esp1->spi; |
| 356 | |
| 357 | if (memcmp (&key61, &last_key6, sizeof (last_key6)) == 0) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 358 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 359 | tid1 = last_tunnel_id; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 360 | } |
| 361 | else |
| 362 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 363 | uword *p = |
| 364 | hash_get_mem (im->ipsec6_if_pool_index_by_key, &key61); |
| 365 | if (p) |
| 366 | { |
| 367 | tid1 = p[0]; |
| 368 | last_tunnel_id = tid1; |
| 369 | clib_memcpy_fast (&last_key6, &key61, sizeof (key61)); |
| 370 | } |
| 371 | else |
| 372 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 373 | next[1] = |
| 374 | ipsec_ip6_if_no_tunnel (node, b[1], esp1, buf_adv1); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 375 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 376 | goto trace1; |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | else /* !is_ip6 */ |
| 381 | { |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 382 | key41.remote_ip = ip41->src_address; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 383 | key41.spi = esp1->spi; |
| 384 | |
| 385 | if (key41.as_u64 == last_key4.as_u64) |
| 386 | { |
| 387 | tid1 = last_tunnel_id; |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | uword *p = |
| 392 | hash_get (im->ipsec4_if_pool_index_by_key, key41.as_u64); |
| 393 | if (p) |
| 394 | { |
| 395 | tid1 = p[0]; |
| 396 | last_tunnel_id = tid1; |
| 397 | last_key4.as_u64 = key41.as_u64; |
| 398 | } |
| 399 | else |
| 400 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 401 | next[1] = |
Neale Ranns | 4b0b0d4 | 2019-07-15 01:04:11 -0700 | [diff] [blame] | 402 | ipsec_ip4_if_no_tunnel (node, b[1], esp1, ip41, |
| 403 | buf_rewind1); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 404 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 405 | goto trace1; |
| 406 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | t1 = pool_elt_at_index (im->tunnel_interfaces, tid1); |
| 411 | vnet_buffer (b[1])->ipsec.sad_index = t1->input_sa_index; |
| 412 | |
| 413 | if (PREDICT_TRUE (t1->hw_if_index != ~0)) |
| 414 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 415 | sw_if_index1 = t1->sw_if_index; |
| 416 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = sw_if_index1; |
| 417 | |
| 418 | if (PREDICT_FALSE (!(t1->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))) |
| 419 | { |
| 420 | vlib_increment_combined_counter |
| 421 | (drop_counter, thread_index, sw_if_index1, 1, len1); |
| 422 | n_disabled++; |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 423 | b[1]->error = node->errors[IPSEC_IF_INPUT_ERROR_DISABLED]; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 424 | next[1] = IPSEC_INPUT_NEXT_DROP; |
| 425 | goto trace1; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 428 | if (PREDICT_TRUE (sw_if_index1 == last_sw_if_index)) |
| 429 | { |
| 430 | n_packets++; |
| 431 | n_bytes += len1; |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | if (n_packets) |
| 436 | { |
| 437 | vlib_increment_combined_counter |
| 438 | (rx_counter, thread_index, last_sw_if_index, |
| 439 | n_packets, n_bytes); |
| 440 | } |
| 441 | |
| 442 | last_sw_if_index = sw_if_index1; |
| 443 | n_packets = 1; |
| 444 | n_bytes = len1; |
| 445 | } |
| 446 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 447 | |
| 448 | trace1: |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 449 | if (PREDICT_FALSE (is_trace)) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 450 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 451 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 452 | { |
| 453 | ipsec_if_input_trace_t *tr = |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 454 | vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 455 | if (is_ip6) |
| 456 | clib_memcpy (&tr->key6, &key60, sizeof (tr->key6)); |
| 457 | else |
| 458 | clib_memcpy (&tr->key4, &key40, sizeof (tr->key4)); |
| 459 | tr->is_ip6 = is_ip6; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 460 | tr->seq = clib_host_to_net_u32 (esp0->seq); |
| 461 | } |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 462 | if (b[1]->flags & VLIB_BUFFER_IS_TRACED) |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 463 | { |
| 464 | ipsec_if_input_trace_t *tr = |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 465 | vlib_add_trace (vm, node, b[1], sizeof (*tr)); |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 466 | if (is_ip6) |
| 467 | clib_memcpy (&tr->key6, &key61, sizeof (tr->key6)); |
| 468 | else |
| 469 | clib_memcpy (&tr->key4, &key41, sizeof (tr->key4)); |
| 470 | tr->is_ip6 = is_ip6; |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 471 | tr->seq = clib_host_to_net_u32 (esp1->seq); |
| 472 | } |
Neale Ranns | 77eb28f | 2019-03-04 14:13:14 +0000 | [diff] [blame] | 473 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 474 | |
| 475 | /* next */ |
| 476 | b += 2; |
| 477 | next += 2; |
| 478 | n_left_from -= 2; |
| 479 | } |
| 480 | while (n_left_from > 0) |
| 481 | { |
| 482 | u32 sw_if_index0; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 483 | ip4_header_t *ip40; |
| 484 | ip6_header_t *ip60; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 485 | esp_header_t *esp0; |
| 486 | u32 len0; |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 487 | u16 buf_adv0, buf_rewind0; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 488 | u32 tid0; |
| 489 | ipsec_tunnel_if_t *t0; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 490 | ipsec4_tunnel_key_t key40; |
| 491 | ipsec6_tunnel_key_t key60; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 492 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 493 | ip40 = |
| 494 | (ip4_header_t *) (b[0]->data + vnet_buffer (b[0])->l3_hdr_offset); |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 495 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 496 | if (is_ip6) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 497 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 498 | ip60 = (ip6_header_t *) ip40; |
| 499 | esp0 = (esp_header_t *) ((u8 *) ip60 + sizeof (ip6_header_t)); |
| 500 | buf_adv0 = sizeof (ip6_header_t); |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 501 | } |
| 502 | else |
| 503 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 504 | /* NAT UDP port 4500 case, don't advance any more */ |
| 505 | if (ip40->protocol == IP_PROTOCOL_UDP) |
| 506 | { |
| 507 | esp0 = |
| 508 | (esp_header_t *) ((u8 *) ip40 + ip4_header_bytes (ip40) + |
| 509 | sizeof (udp_header_t)); |
| 510 | buf_adv0 = 0; |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 511 | buf_rewind0 = ip4_header_bytes (ip40) + sizeof (udp_header_t); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 512 | } |
| 513 | else |
| 514 | { |
| 515 | esp0 = (esp_header_t *) ((u8 *) ip40 + ip4_header_bytes (ip40)); |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 516 | buf_rewind0 = buf_adv0 = ip4_header_bytes (ip40); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 517 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 518 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 519 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 520 | /* stats for the tunnel include all the data after the IP header |
| 521 | just like a norml IP-IP tunnel */ |
| 522 | vlib_buffer_advance (b[0], buf_adv0); |
| 523 | len0 = vlib_buffer_length_in_chain (vm, b[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 524 | |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 525 | if (len0 < sizeof (esp_header_t)) |
| 526 | { |
| 527 | if (esp0->spi_bytes[0] == 0xff) |
| 528 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_NAT_KEEPALIVE]; |
| 529 | else |
| 530 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_TOO_SHORT]; |
| 531 | |
| 532 | next[0] = IPSEC_INPUT_NEXT_DROP; |
| 533 | goto trace00; |
| 534 | } |
| 535 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 536 | if (is_ip6) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 537 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 538 | key60.remote_ip = ip60->src_address; |
| 539 | key60.spi = esp0->spi; |
| 540 | |
| 541 | if (memcmp (&key60, &last_key6, sizeof (last_key6)) == 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 542 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 543 | tid0 = last_tunnel_id; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 544 | } |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 545 | else |
| 546 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 547 | uword *p = |
| 548 | hash_get_mem (im->ipsec6_if_pool_index_by_key, &key60); |
| 549 | if (p) |
| 550 | { |
| 551 | tid0 = p[0]; |
| 552 | last_tunnel_id = tid0; |
| 553 | clib_memcpy_fast (&last_key6, &key60, sizeof (key60)); |
| 554 | } |
| 555 | else |
| 556 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 557 | next[0] = |
| 558 | ipsec_ip6_if_no_tunnel (node, b[0], esp0, buf_adv0); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 559 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 560 | goto trace00; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | else /* !is_ip6 */ |
| 565 | { |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 566 | key40.remote_ip = ip40->src_address; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 567 | key40.spi = esp0->spi; |
| 568 | |
| 569 | if (key40.as_u64 == last_key4.as_u64) |
| 570 | { |
| 571 | tid0 = last_tunnel_id; |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | uword *p = |
| 576 | hash_get (im->ipsec4_if_pool_index_by_key, key40.as_u64); |
| 577 | if (p) |
| 578 | { |
| 579 | tid0 = p[0]; |
| 580 | last_tunnel_id = tid0; |
| 581 | last_key4.as_u64 = key40.as_u64; |
| 582 | } |
| 583 | else |
| 584 | { |
Neale Ranns | b71fa75 | 2019-04-04 12:43:36 +0000 | [diff] [blame] | 585 | next[0] = |
Neale Ranns | a6bee0a | 2019-06-14 01:13:25 -0700 | [diff] [blame] | 586 | ipsec_ip4_if_no_tunnel (node, b[0], esp0, ip40, |
| 587 | buf_rewind0); |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 588 | n_no_tunnel++; |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 589 | goto trace00; |
| 590 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
| 594 | t0 = pool_elt_at_index (im->tunnel_interfaces, tid0); |
| 595 | vnet_buffer (b[0])->ipsec.sad_index = t0->input_sa_index; |
| 596 | |
| 597 | if (PREDICT_TRUE (t0->hw_if_index != ~0)) |
| 598 | { |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 599 | sw_if_index0 = t0->sw_if_index; |
| 600 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index0; |
| 601 | |
| 602 | if (PREDICT_FALSE (!(t0->flags & VNET_HW_INTERFACE_FLAG_LINK_UP))) |
| 603 | { |
| 604 | vlib_increment_combined_counter |
| 605 | (drop_counter, thread_index, sw_if_index0, 1, len0); |
| 606 | n_disabled++; |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 607 | b[0]->error = node->errors[IPSEC_IF_INPUT_ERROR_DISABLED]; |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 608 | next[0] = IPSEC_INPUT_NEXT_DROP; |
| 609 | goto trace00; |
Neale Ranns | 8d7c502 | 2019-02-06 01:41:05 -0800 | [diff] [blame] | 610 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 611 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 612 | if (PREDICT_TRUE (sw_if_index0 == last_sw_if_index)) |
| 613 | { |
| 614 | n_packets++; |
| 615 | n_bytes += len0; |
| 616 | } |
| 617 | else |
| 618 | { |
| 619 | if (n_packets) |
| 620 | { |
| 621 | vlib_increment_combined_counter |
| 622 | (rx_counter, thread_index, last_sw_if_index, |
| 623 | n_packets, n_bytes); |
| 624 | } |
| 625 | |
| 626 | last_sw_if_index = sw_if_index0; |
| 627 | n_packets = 1; |
| 628 | n_bytes = len0; |
| 629 | } |
| 630 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 631 | |
| 632 | trace00: |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 633 | if (PREDICT_FALSE (is_trace)) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 634 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 635 | if (b[0]->flags & VLIB_BUFFER_IS_TRACED) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 636 | { |
| 637 | ipsec_if_input_trace_t *tr = |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 638 | vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
Neale Ranns | 41afb33 | 2019-07-16 06:19:35 -0700 | [diff] [blame] | 639 | if (is_ip6) |
| 640 | clib_memcpy (&tr->key6, &key60, sizeof (tr->key6)); |
| 641 | else |
| 642 | clib_memcpy (&tr->key4, &key40, sizeof (tr->key4)); |
| 643 | tr->is_ip6 = is_ip6; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 644 | tr->seq = clib_host_to_net_u32 (esp0->seq); |
| 645 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 646 | } |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 647 | |
| 648 | /* next */ |
| 649 | b += 1; |
| 650 | next += 1; |
| 651 | n_left_from -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 654 | if (n_packets) |
Matthew Smith | 01034be | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 655 | { |
Matthew Smith | 831fd64 | 2018-05-15 22:03:05 -0500 | [diff] [blame] | 656 | vlib_increment_combined_counter (rx_counter, |
Matthew Smith | 01034be | 2017-05-16 11:51:18 -0500 | [diff] [blame] | 657 | thread_index, |
| 658 | last_sw_if_index, n_packets, n_bytes); |
| 659 | } |
| 660 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 661 | vlib_node_increment_counter (vm, node->node_index, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 662 | IPSEC_IF_INPUT_ERROR_RX, |
Neale Ranns | e524d45 | 2019-02-19 15:22:46 +0000 | [diff] [blame] | 663 | from_frame->n_vectors - (n_disabled + |
| 664 | n_no_tunnel)); |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 665 | |
| 666 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, from_frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | |
| 668 | return from_frame->n_vectors; |
| 669 | } |
| 670 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 671 | VLIB_NODE_FN (ipsec4_if_input_node) (vlib_main_t * vm, |
| 672 | vlib_node_runtime_t * node, |
| 673 | vlib_frame_t * from_frame) |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 674 | { |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 675 | return ipsec_if_input_inline (vm, node, from_frame, 0 /* is_ip6 */ ); |
Kingwel Xie | 00bff19 | 2019-03-07 01:25:32 -0500 | [diff] [blame] | 676 | } |
| 677 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 678 | /* *INDENT-OFF* */ |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 679 | VLIB_REGISTER_NODE (ipsec4_if_input_node) = { |
| 680 | .name = "ipsec4-if-input", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 681 | .vector_size = sizeof (u32), |
| 682 | .format_trace = format_ipsec_if_input_trace, |
| 683 | .type = VLIB_NODE_TYPE_INTERNAL, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 684 | .n_errors = ARRAY_LEN(ipsec_if_input_error_strings), |
| 685 | .error_strings = ipsec_if_input_error_strings, |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 686 | .sibling_of = "ipsec4-input-feature", |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 687 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 688 | /* *INDENT-ON* */ |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 689 | |
Kingwel Xie | 1ba5bc8 | 2019-03-20 07:21:58 -0400 | [diff] [blame] | 690 | VLIB_NODE_FN (ipsec6_if_input_node) (vlib_main_t * vm, |
| 691 | vlib_node_runtime_t * node, |
| 692 | vlib_frame_t * from_frame) |
| 693 | { |
| 694 | return ipsec_if_input_inline (vm, node, from_frame, 1 /* is_ip6 */ ); |
| 695 | } |
| 696 | |
| 697 | /* *INDENT-OFF* */ |
| 698 | VLIB_REGISTER_NODE (ipsec6_if_input_node) = { |
| 699 | .name = "ipsec6-if-input", |
| 700 | .vector_size = sizeof (u32), |
| 701 | .format_trace = format_ipsec_if_input_trace, |
| 702 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 703 | .n_errors = ARRAY_LEN(ipsec_if_input_error_strings), |
| 704 | .error_strings = ipsec_if_input_error_strings, |
| 705 | .sibling_of = "ipsec6-input-feature", |
| 706 | }; |
| 707 | /* *INDENT-ON* */ |
| 708 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 709 | /* |
| 710 | * fd.io coding-style-patch-verification: ON |
| 711 | * |
| 712 | * Local Variables: |
| 713 | * eval: (c-set-style "gnu") |
| 714 | * End: |
| 715 | */ |