blob: 9aa5654c9da501c886afe02e897a1c4efdf4feb3 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * decap.c : IPSec tunnel decapsulation
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>
Damjan Marion8b3191e2016-11-09 19:54:20 +010021#include <vnet/feature/feature.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070022
23#include <vnet/ipsec/ipsec.h>
24#include <vnet/ipsec/esp.h>
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080025#include <vnet/ipsec/ah.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
Ed Warnickecb9cada2015-12-08 15:45:58 -070027#define foreach_ipsec_input_error \
28 _(RX_PKTS, "IPSEC pkts received") \
29 _(DECRYPTION_FAILED, "IPSEC decryption failed")
30
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070031typedef enum
32{
Ed Warnickecb9cada2015-12-08 15:45:58 -070033#define _(sym,str) IPSEC_INPUT_ERROR_##sym,
34 foreach_ipsec_input_error
35#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070036 IPSEC_INPUT_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -070037} ipsec_input_error_t;
38
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070039static char *ipsec_input_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#define _(sym,string) string,
41 foreach_ipsec_input_error
42#undef _
43};
44
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070045typedef struct
46{
Matus Fabian5539a072016-09-07 05:57:09 -070047 u32 sa_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070048 u32 spi;
49 u32 seq;
50} ipsec_input_trace_t;
51
52/* packet trace format function */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070053static u8 *
54format_ipsec_input_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070055{
56 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
57 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070058 ipsec_input_trace_t *t = va_arg (*args, ipsec_input_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
Matus Fabian5539a072016-09-07 05:57:09 -070060 if (t->spi == 0 && t->seq == 0)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070061 {
Matus Fabian5539a072016-09-07 05:57:09 -070062 s = format (s, "esp: no esp packet");
63 return s;
64 }
65
66 if (t->sa_id != 0)
67 {
68 s = format (s, "esp: sa_id %u spi %u seq %u", t->sa_id, t->spi, t->seq);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070069 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 else
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070071 {
Matus Fabian5539a072016-09-07 05:57:09 -070072 s = format (s, "esp: no sa spi %u seq %u", t->spi, t->seq);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070073 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070074 return s;
75}
76
77always_inline ipsec_policy_t *
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070078ipsec_input_protect_policy_match (ipsec_spd_t * spd, u32 sa, u32 da, u32 spi)
Ed Warnickecb9cada2015-12-08 15:45:58 -070079{
80 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070081 ipsec_policy_t *p;
82 ipsec_sa_t *s;
83 u32 *i;
Ed Warnickecb9cada2015-12-08 15:45:58 -070084
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070085 vec_foreach (i, spd->ipv4_inbound_protect_policy_indices)
86 {
87 p = pool_elt_at_index (spd->policies, *i);
88 s = pool_elt_at_index (im->sad, p->sa_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070089
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070090 if (spi != s->spi)
91 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070093 if (s->is_tunnel)
94 {
95 if (da != clib_net_to_host_u32 (s->tunnel_dst_addr.ip4.as_u32))
96 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070098 if (sa != clib_net_to_host_u32 (s->tunnel_src_addr.ip4.as_u32))
99 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700101 return p;
102 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700103
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700104 if (da < clib_net_to_host_u32 (p->laddr.start.ip4.as_u32))
105 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700107 if (da > clib_net_to_host_u32 (p->laddr.stop.ip4.as_u32))
108 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700110 if (sa < clib_net_to_host_u32 (p->raddr.start.ip4.as_u32))
111 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700113 if (sa > clib_net_to_host_u32 (p->raddr.stop.ip4.as_u32))
114 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700116 return p;
117 }
118 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119}
120
121always_inline uword
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700122ip6_addr_match_range (ip6_address_t * a, ip6_address_t * la,
123 ip6_address_t * ua)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700125 if ((memcmp (a->as_u64, la->as_u64, 2 * sizeof (u64)) >= 0) &&
126 (memcmp (a->as_u64, ua->as_u64, 2 * sizeof (u64)) <= 0))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127 return 1;
128 return 0;
129}
130
131always_inline ipsec_policy_t *
132ipsec_input_ip6_protect_policy_match (ipsec_spd_t * spd,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700133 ip6_address_t * sa,
134 ip6_address_t * da, u32 spi)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135{
136 ipsec_main_t *im = &ipsec_main;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700137 ipsec_policy_t *p;
138 ipsec_sa_t *s;
139 u32 *i;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700141 vec_foreach (i, spd->ipv6_inbound_protect_policy_indices)
142 {
143 p = pool_elt_at_index (spd->policies, *i);
144 s = pool_elt_at_index (im->sad, p->sa_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700146 if (spi != s->spi)
147 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700149 if (s->is_tunnel)
150 {
151 if (!ip6_address_is_equal (sa, &s->tunnel_src_addr.ip6))
152 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700154 if (!ip6_address_is_equal (da, &s->tunnel_dst_addr.ip6))
155 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700157 return p;
158 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700160 if (!ip6_addr_match_range (sa, &p->raddr.start.ip6, &p->raddr.stop.ip6))
161 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700163 if (!ip6_addr_match_range (da, &p->laddr.start.ip6, &p->laddr.stop.ip6))
164 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700166 return p;
167 }
168 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700169}
170
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100171static vlib_node_registration_t ipsec_input_ip4_node;
172
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173static uword
174ipsec_input_ip4_node_fn (vlib_main_t * vm,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700175 vlib_node_runtime_t * node,
176 vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 u32 n_left_from, *from, next_index, *to_next;
179 ipsec_main_t *im = &ipsec_main;
180
181 from = vlib_frame_vector_args (from_frame);
182 n_left_from = from_frame->n_vectors;
183
184 next_index = node->cached_next_index;
185
186 while (n_left_from > 0)
187 {
188 u32 n_left_to_next;
189
190 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
191
192 while (n_left_from > 0 && n_left_to_next > 0)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700193 {
194 u32 bi0, next0;
195 vlib_buffer_t *b0;
196 ip4_header_t *ip0;
197 esp_header_t *esp0;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800198 ah_header_t *ah0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700199 ip4_ipsec_config_t *c0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700200 ipsec_spd_t *spd0;
Matus Fabian5539a072016-09-07 05:57:09 -0700201 ipsec_policy_t *p0 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700203 bi0 = to_next[0] = from[0];
204 from += 1;
205 n_left_from -= 1;
206 to_next += 1;
207 n_left_to_next -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700208
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700209 b0 = vlib_get_buffer (vm, bi0);
Damjan Marion8b3191e2016-11-09 19:54:20 +0100210 c0 =
211 vnet_feature_next_with_data (vnet_buffer (b0)->sw_if_index
212 [VLIB_RX], &next0, b0,
213 sizeof (c0[0]));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700215 spd0 = pool_elt_at_index (im->spds, c0->spd_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700216
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700217 ip0 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700219 if (PREDICT_TRUE (ip0->protocol == IP_PROTOCOL_IPSEC_ESP))
220 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221#if 0
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700222 clib_warning
223 ("packet received from %U to %U spi %u size %u spd_id %u",
224 format_ip4_address, ip0->src_address.as_u8,
225 format_ip4_address, ip0->dst_address.as_u8,
226 clib_net_to_host_u32 (esp0->spi),
227 clib_net_to_host_u16 (ip0->length), spd0->id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228#endif
Matus Fabian5539a072016-09-07 05:57:09 -0700229
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800230 esp0 = (esp_header_t *) ((u8 *) ip0 + ip4_header_bytes (ip0));
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700231 p0 = ipsec_input_protect_policy_match (spd0,
232 clib_net_to_host_u32
Matus Fabian5539a072016-09-07 05:57:09 -0700233 (ip0->src_address.
234 as_u32),
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700235 clib_net_to_host_u32
Matus Fabian5539a072016-09-07 05:57:09 -0700236 (ip0->dst_address.
237 as_u32),
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700238 clib_net_to_host_u32
239 (esp0->spi));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700241 if (PREDICT_TRUE (p0 != 0))
242 {
243 p0->counter.packets++;
244 p0->counter.bytes += clib_net_to_host_u16 (ip0->length);
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100245 vnet_buffer (b0)->ipsec.sad_index = p0->sa_index;
246 vnet_buffer (b0)->ipsec.flags = 0;
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000247 next0 = im->esp_decrypt_next_index;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700248 vlib_buffer_advance (b0, ip4_header_bytes (ip0));
249 goto trace0;
250 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800251
252 /* FIXME bypass and discard */
253 trace0:
254 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
255 {
256 ipsec_input_trace_t *tr =
257 vlib_add_trace (vm, node, b0, sizeof (*tr));
258 if (ip0->protocol == IP_PROTOCOL_IPSEC_ESP)
259 {
260 if (p0)
261 tr->sa_id = p0->sa_id;
262 tr->spi = clib_host_to_net_u32 (esp0->spi);
263 tr->seq = clib_host_to_net_u32 (esp0->seq);
264 }
265 }
266
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700267 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800270 if (PREDICT_TRUE (ip0->protocol == IP_PROTOCOL_IPSEC_AH))
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700271 {
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800272 ah0 = (ah_header_t *) ((u8 *) ip0 + ip4_header_bytes (ip0));
273 p0 = ipsec_input_protect_policy_match (spd0,
274 clib_net_to_host_u32
275 (ip0->src_address.
276 as_u32),
277 clib_net_to_host_u32
278 (ip0->dst_address.
279 as_u32),
280 clib_net_to_host_u32
281 (ah0->spi));
282
283 if (PREDICT_TRUE (p0 != 0))
Matus Fabian5539a072016-09-07 05:57:09 -0700284 {
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800285 p0->counter.packets++;
286 p0->counter.bytes += clib_net_to_host_u16 (ip0->length);
287 vnet_buffer (b0)->ipsec.sad_index = p0->sa_index;
288 vnet_buffer (b0)->ipsec.flags = 0;
289 next0 = im->ah_decrypt_next_index;
290 goto trace1;
291 }
292 /* FIXME bypass and discard */
293 trace1:
294 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
295 {
296 ipsec_input_trace_t *tr =
297 vlib_add_trace (vm, node, b0, sizeof (*tr));
298 if (ip0->protocol == IP_PROTOCOL_IPSEC_ESP)
299 {
300 if (p0)
301 tr->sa_id = p0->sa_id;
302 tr->spi = clib_host_to_net_u32 (ah0->spi);
303 tr->seq = clib_host_to_net_u32 (ah0->seq_no);
304 }
Matus Fabian5539a072016-09-07 05:57:09 -0700305 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700306 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700308 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
309 to_next, n_left_to_next, bi0,
310 next0);
311 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700312 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
313 }
314 vlib_node_increment_counter (vm, ipsec_input_ip4_node.index,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700315 IPSEC_INPUT_ERROR_RX_PKTS,
316 from_frame->n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317
318 return from_frame->n_vectors;
319}
320
321
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700322/* *INDENT-OFF* */
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100323VLIB_REGISTER_NODE (ipsec_input_ip4_node,static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324 .function = ipsec_input_ip4_node_fn,
325 .name = "ipsec-input-ip4",
326 .vector_size = sizeof (u32),
327 .format_trace = format_ipsec_input_trace,
328 .type = VLIB_NODE_TYPE_INTERNAL,
329
330 .n_errors = ARRAY_LEN(ipsec_input_error_strings),
331 .error_strings = ipsec_input_error_strings,
332
333 .n_next_nodes = IPSEC_INPUT_N_NEXT,
334 .next_nodes = {
335#define _(s,n) [IPSEC_INPUT_NEXT_##s] = n,
336 foreach_ipsec_input_next
337#undef _
338 },
339};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700340/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700341
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700342VLIB_NODE_FUNCTION_MULTIARCH (ipsec_input_ip4_node, ipsec_input_ip4_node_fn)
343 static vlib_node_registration_t ipsec_input_ip6_node;
Damjan Marion1c80e832016-05-11 23:07:18 +0200344
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700345 static uword
346 ipsec_input_ip6_node_fn (vlib_main_t * vm,
347 vlib_node_runtime_t * node,
348 vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700349{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 u32 n_left_from, *from, next_index, *to_next;
351 ipsec_main_t *im = &ipsec_main;
352
353 from = vlib_frame_vector_args (from_frame);
354 n_left_from = from_frame->n_vectors;
355
356 next_index = node->cached_next_index;
357
358 while (n_left_from > 0)
359 {
360 u32 n_left_to_next;
361
362 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
363
364 while (n_left_from > 0 && n_left_to_next > 0)
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700365 {
366 u32 bi0, next0;
367 vlib_buffer_t *b0;
368 ip6_header_t *ip0;
369 esp_header_t *esp0;
370 ip4_ipsec_config_t *c0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700371 ipsec_spd_t *spd0;
Matus Fabian5539a072016-09-07 05:57:09 -0700372 ipsec_policy_t *p0 = 0;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700373 u32 header_size = sizeof (ip0[0]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700375 bi0 = to_next[0] = from[0];
376 from += 1;
377 n_left_from -= 1;
378 to_next += 1;
379 n_left_to_next -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700381 b0 = vlib_get_buffer (vm, bi0);
Damjan Marion8b3191e2016-11-09 19:54:20 +0100382 c0 =
383 vnet_feature_next_with_data (vnet_buffer (b0)->sw_if_index
384 [VLIB_RX], &next0, b0,
385 sizeof (c0[0]));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700387 spd0 = pool_elt_at_index (im->spds, c0->spd_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700388
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700389 ip0 = vlib_buffer_get_current (b0);
390 esp0 = (esp_header_t *) ((u8 *) ip0 + header_size);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700392 if (PREDICT_TRUE (ip0->protocol == IP_PROTOCOL_IPSEC_ESP))
393 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394#if 0
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700395 clib_warning
396 ("packet received from %U to %U spi %u size %u spd_id %u",
397 format_ip6_address, &ip0->src_address, format_ip6_address,
398 &ip0->dst_address, clib_net_to_host_u32 (esp0->spi),
399 clib_net_to_host_u16 (ip0->payload_length) + header_size,
400 spd0->id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401#endif
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700402 p0 = ipsec_input_ip6_protect_policy_match (spd0,
403 &ip0->src_address,
404 &ip0->dst_address,
405 clib_net_to_host_u32
406 (esp0->spi));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700407
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700408 if (PREDICT_TRUE (p0 != 0))
409 {
410 p0->counter.packets++;
411 p0->counter.bytes +=
412 clib_net_to_host_u16 (ip0->payload_length);
413 p0->counter.bytes += header_size;
Damjan Marion9c6ae5f2016-11-15 23:20:01 +0100414 vnet_buffer (b0)->ipsec.sad_index = p0->sa_index;
415 vnet_buffer (b0)->ipsec.flags = 0;
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000416 next0 = im->esp_decrypt_next_index;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700417 vlib_buffer_advance (b0, header_size);
418 goto trace0;
419 }
420 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700422 trace0:
423 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
424 {
425 ipsec_input_trace_t *tr =
426 vlib_add_trace (vm, node, b0, sizeof (*tr));
Matus Fabian5539a072016-09-07 05:57:09 -0700427 if (ip0->protocol == IP_PROTOCOL_IPSEC_ESP)
428 {
429 if (p0)
430 tr->sa_id = p0->sa_id;
431 tr->spi = clib_host_to_net_u32 (esp0->spi);
432 tr->seq = clib_host_to_net_u32 (esp0->seq);
433 }
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700434 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700435
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700436 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
437 n_left_to_next, bi0, next0);
438 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700439 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
440 }
441 vlib_node_increment_counter (vm, ipsec_input_ip6_node.index,
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700442 IPSEC_INPUT_ERROR_RX_PKTS,
443 from_frame->n_vectors);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700444
445 return from_frame->n_vectors;
446}
447
448
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700449/* *INDENT-OFF* */
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100450VLIB_REGISTER_NODE (ipsec_input_ip6_node,static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700451 .function = ipsec_input_ip6_node_fn,
452 .name = "ipsec-input-ip6",
453 .vector_size = sizeof (u32),
454 .format_trace = format_ipsec_input_trace,
455 .type = VLIB_NODE_TYPE_INTERNAL,
456
457 .n_errors = ARRAY_LEN(ipsec_input_error_strings),
458 .error_strings = ipsec_input_error_strings,
459
Radu Nicolau52a047a2017-02-16 13:43:41 +0000460 .sibling_of = "ipsec-input-ip4",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461};
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700462/* *INDENT-ON* */
Damjan Marion1c80e832016-05-11 23:07:18 +0200463
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700464VLIB_NODE_FUNCTION_MULTIARCH (ipsec_input_ip6_node, ipsec_input_ip6_node_fn)
465/*
466 * fd.io coding-style-patch-verification: ON
467 *
468 * Local Variables:
469 * eval: (c-set-style "gnu")
470 * End:
471 */