blob: db052145ce2ba942149d85a6abef0e7b45070e52 [file] [log] [blame]
Marco Varleseb598f1d2017-09-19 14:25:28 +02001/*
2 * Copyright (c) 2017 SUSE LLC.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vlib/vlib.h>
17#include <vnet/pg/pg.h>
18#include <vnet/geneve/geneve.h>
19
20vlib_node_registration_t geneve4_input_node;
21vlib_node_registration_t geneve6_input_node;
22
23typedef struct
24{
25 u32 next_index;
26 u32 tunnel_index;
27 u32 error;
28 u32 vni;
29} geneve_rx_trace_t;
30
31static u8 *
32format_geneve_rx_trace (u8 * s, va_list * args)
33{
34 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
35 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
36 geneve_rx_trace_t *t = va_arg (*args, geneve_rx_trace_t *);
37
38 if (t->tunnel_index != ~0)
39 {
40 s =
41 format (s,
42 "GENEVE decap from geneve_tunnel%d vni %d next %d error %d",
43 t->tunnel_index, t->vni, t->next_index, t->error);
44 }
45 else
46 {
47 s = format (s, "GENEVE decap error - tunnel for vni %d does not exist",
48 t->vni);
49 }
50 return s;
51}
52
53always_inline u32
54validate_geneve_fib (vlib_buffer_t * b, geneve_tunnel_t * t, u32 is_ip4)
55{
56 u32 fib_index, sw_if_index;
57
58 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
59
60 if (is_ip4)
61 fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
62 vec_elt (ip4_main.fib_index_by_sw_if_index, sw_if_index) :
63 vnet_buffer (b)->sw_if_index[VLIB_TX];
64 else
65 fib_index = (vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ?
66 vec_elt (ip6_main.fib_index_by_sw_if_index, sw_if_index) :
67 vnet_buffer (b)->sw_if_index[VLIB_TX];
68
69 return (fib_index == t->encap_fib_index);
70}
71
72always_inline uword
73geneve_input (vlib_main_t * vm,
74 vlib_node_runtime_t * node,
75 vlib_frame_t * from_frame, u32 is_ip4)
76{
77 u32 n_left_from, next_index, *from, *to_next;
78 geneve_main_t *vxm = &geneve_main;
79 vnet_main_t *vnm = vxm->vnet_main;
80 vnet_interface_main_t *im = &vnm->interface_main;
81 u32 last_tunnel_index = ~0;
82 geneve4_tunnel_key_t last_key4;
83 geneve6_tunnel_key_t last_key6;
84 u32 pkts_decapsulated = 0;
85 u32 thread_index = vlib_get_thread_index ();
86 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
87
88 if (is_ip4)
89 last_key4.as_u64 = ~0;
90 else
91 memset (&last_key6, 0xff, sizeof (last_key6));
92
93 from = vlib_frame_vector_args (from_frame);
94 n_left_from = from_frame->n_vectors;
95
96 next_index = node->cached_next_index;
97 stats_sw_if_index = node->runtime_data[0];
98 stats_n_packets = stats_n_bytes = 0;
99
100 while (n_left_from > 0)
101 {
102 u32 n_left_to_next;
103
104 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
105 while (n_left_from >= 4 && n_left_to_next >= 2)
106 {
107 u32 bi0, bi1;
108 vlib_buffer_t *b0, *b1;
109 u32 next0, next1;
110 ip4_header_t *ip4_0, *ip4_1;
111 ip6_header_t *ip6_0, *ip6_1;
112 geneve_header_t *geneve0, *geneve1;
113 uword *p0, *p1;
114 u32 tunnel_index0, tunnel_index1;
115 geneve_tunnel_t *t0, *t1, *mt0 = NULL, *mt1 = NULL;
116 geneve4_tunnel_key_t key4_0, key4_1;
117 geneve6_tunnel_key_t key6_0, key6_1;
118 u32 error0, error1;
119 u32 sw_if_index0, sw_if_index1, len0, len1;
120
121 /* Prefetch next iteration. */
122 {
123 vlib_buffer_t *p2, *p3;
124
125 p2 = vlib_get_buffer (vm, from[2]);
126 p3 = vlib_get_buffer (vm, from[3]);
127
128 vlib_prefetch_buffer_header (p2, LOAD);
129 vlib_prefetch_buffer_header (p3, LOAD);
130
131 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
132 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
133 }
134
135 bi0 = from[0];
136 bi1 = from[1];
137 to_next[0] = bi0;
138 to_next[1] = bi1;
139 from += 2;
140 to_next += 2;
141 n_left_to_next -= 2;
142 n_left_from -= 2;
143
144 b0 = vlib_get_buffer (vm, bi0);
145 b1 = vlib_get_buffer (vm, bi1);
146
147 /* udp leaves current_data pointing at the geneve header */
148 geneve0 = vlib_buffer_get_current (b0);
149 geneve1 = vlib_buffer_get_current (b1);
150 if (is_ip4)
151 {
152 vlib_buffer_advance
153 (b0, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
154 vlib_buffer_advance
155 (b1, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
156 ip4_0 = vlib_buffer_get_current (b0);
157 ip4_1 = vlib_buffer_get_current (b1);
158 }
159 else
160 {
161 vlib_buffer_advance
162 (b0, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
163 vlib_buffer_advance
164 (b1, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
165 ip6_0 = vlib_buffer_get_current (b0);
166 ip6_1 = vlib_buffer_get_current (b1);
167 }
168
169 /* pop (ip, udp, geneve) */
170 if (is_ip4)
171 {
172 vlib_buffer_advance
173 (b0,
174 sizeof (*ip4_0) + sizeof (udp_header_t) +
175 GENEVE_BASE_HEADER_LENGTH +
176 vnet_get_geneve_options_len (geneve0));
177 vlib_buffer_advance (b1,
178 sizeof (*ip4_1) + sizeof (udp_header_t) +
179 GENEVE_BASE_HEADER_LENGTH +
180 vnet_get_geneve_options_len (geneve1));
181 }
182 else
183 {
184 vlib_buffer_advance
185 (b0,
186 sizeof (*ip6_0) + sizeof (udp_header_t) +
187 GENEVE_BASE_HEADER_LENGTH +
188 vnet_get_geneve_options_len (geneve0));
189 vlib_buffer_advance (b0,
190 sizeof (*ip6_0) + sizeof (udp_header_t) +
191 GENEVE_BASE_HEADER_LENGTH +
192 vnet_get_geneve_options_len (geneve1));
193 }
194
195 tunnel_index0 = ~0;
196 error0 = 0;
197
198 tunnel_index1 = ~0;
199 error1 = 0;
200
201 if (PREDICT_FALSE (geneve0->ver != GENEVE_VERSION))
202 {
203 error0 = GENEVE_ERROR_BAD_FLAGS;
204 next0 = GENEVE_INPUT_NEXT_DROP;
205 goto trace0;
206 }
207#if SUPPORT_OPTIONS_HEADER==0
208 if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve0) == 1))
209 {
210 error0 = GENEVE_ERROR_BAD_FLAGS;
211 next0 = GENEVE_INPUT_NEXT_DROP;
212 goto trace0;
213 }
214#endif
215 if (is_ip4)
216 {
217 key4_0.remote = ip4_0->src_address.as_u32;
218 key4_0.vni = geneve0->vni;
219
220 /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
221 if (PREDICT_FALSE (key4_0.as_u64 != last_key4.as_u64))
222 {
223 p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
224 if (PREDICT_FALSE (p0 == NULL))
225 {
226 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
227 next0 = GENEVE_INPUT_NEXT_DROP;
228 goto trace0;
229 }
230 last_key4.as_u64 = key4_0.as_u64;
231 tunnel_index0 = last_tunnel_index = p0[0];
232 }
233 else
234 tunnel_index0 = last_tunnel_index;
235 t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);
236
237 /* Validate GENEVE tunnel encap-fib index agaist packet */
238 if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
239 {
240 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
241 next0 = GENEVE_INPUT_NEXT_DROP;
242 goto trace0;
243 }
244
245 /* Validate GENEVE tunnel SIP against packet DIP */
246 if (PREDICT_TRUE
247 (ip4_0->dst_address.as_u32 == t0->local.ip4.as_u32))
248 goto next0; /* valid packet */
249 if (PREDICT_FALSE
250 (ip4_address_is_multicast (&ip4_0->dst_address)))
251 {
252 key4_0.remote = ip4_0->dst_address.as_u32;
253 key4_0.vni = geneve0->vni;
254 /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
255 p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
256 if (PREDICT_TRUE (p0 != NULL))
257 {
258 mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
259 goto next0; /* valid packet */
260 }
261 }
262 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
263 next0 = GENEVE_INPUT_NEXT_DROP;
264 goto trace0;
265
266 }
267 else /* !is_ip4 */
268 {
269 key6_0.remote.as_u64[0] = ip6_0->src_address.as_u64[0];
270 key6_0.remote.as_u64[1] = ip6_0->src_address.as_u64[1];
271 key6_0.vni = geneve0->vni;
272
273 /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
274 if (PREDICT_FALSE
275 (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
276 {
277 p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
278 if (PREDICT_FALSE (p0 == NULL))
279 {
280 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
281 next0 = GENEVE_INPUT_NEXT_DROP;
282 goto trace0;
283 }
284 clib_memcpy (&last_key6, &key6_0, sizeof (key6_0));
285 tunnel_index0 = last_tunnel_index = p0[0];
286 }
287 else
288 tunnel_index0 = last_tunnel_index;
289 t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);
290
291 /* Validate GENEVE tunnel encap-fib index agaist packet */
292 if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
293 {
294 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
295 next0 = GENEVE_INPUT_NEXT_DROP;
296 goto trace0;
297 }
298
299 /* Validate GENEVE tunnel SIP against packet DIP */
300 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address,
301 &t0->local.ip6)))
302 goto next0; /* valid packet */
303 if (PREDICT_FALSE
304 (ip6_address_is_multicast (&ip6_0->dst_address)))
305 {
306 key6_0.remote.as_u64[0] = ip6_0->dst_address.as_u64[0];
307 key6_0.remote.as_u64[1] = ip6_0->dst_address.as_u64[1];
308 key6_0.vni = geneve0->vni;
309 p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
310 if (PREDICT_TRUE (p0 != NULL))
311 {
312 mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
313 goto next0; /* valid packet */
314 }
315 }
316 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
317 next0 = GENEVE_INPUT_NEXT_DROP;
318 goto trace0;
319 }
320
321 next0:
322 next0 = t0->decap_next_index;
323 sw_if_index0 = t0->sw_if_index;
324 len0 = vlib_buffer_length_in_chain (vm, b0);
325
326 /* Required to make the l2 tag push / pop code work on l2 subifs */
327 if (PREDICT_TRUE (next0 == GENEVE_INPUT_NEXT_L2_INPUT))
328 vnet_update_l2_len (b0);
329
330 /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
331 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
332 sw_if_index0 = (mt0) ? mt0->sw_if_index : sw_if_index0;
333
334 pkts_decapsulated++;
335 stats_n_packets += 1;
336 stats_n_bytes += len0;
337
338 /* Batch stats increment on the same geneve tunnel so counter
339 is not incremented per packet */
340 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
341 {
342 stats_n_packets -= 1;
343 stats_n_bytes -= len0;
344 if (stats_n_packets)
345 vlib_increment_combined_counter
346 (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
347 thread_index, stats_sw_if_index,
348 stats_n_packets, stats_n_bytes);
349 stats_n_packets = 1;
350 stats_n_bytes = len0;
351 stats_sw_if_index = sw_if_index0;
352 }
353
354 trace0:
355 b0->error = error0 ? node->errors[error0] : 0;
356
357 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
358 {
359 geneve_rx_trace_t *tr
360 = vlib_add_trace (vm, node, b0, sizeof (*tr));
361 tr->next_index = next0;
362 tr->error = error0;
363 tr->tunnel_index = tunnel_index0;
364 tr->vni = vnet_get_geneve_vni (geneve0);
365 }
366
367 if (PREDICT_FALSE (geneve1->ver != GENEVE_VERSION))
368 {
369 error1 = GENEVE_ERROR_BAD_FLAGS;
370 next1 = GENEVE_INPUT_NEXT_DROP;
371 goto trace1;
372 }
373#if SUPPORT_OPTIONS_HEADER==0
374 if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve1) == 1))
375 {
376 error1 = GENEVE_ERROR_BAD_FLAGS;
377 next1 = GENEVE_INPUT_NEXT_DROP;
378 goto trace1;
379 }
380#endif
381 if (is_ip4)
382 {
383 key4_1.remote = ip4_1->src_address.as_u32;
384 key4_1.vni = geneve1->vni;
385
386 /* Make sure unicast GENEVE tunnel exist by packet SIP and VNI */
387 if (PREDICT_FALSE (key4_1.as_u64 != last_key4.as_u64))
388 {
389 p1 = hash_get (vxm->geneve4_tunnel_by_key, key4_1.as_u64);
390 if (PREDICT_FALSE (p1 == NULL))
391 {
392 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
393 next1 = GENEVE_INPUT_NEXT_DROP;
394 goto trace1;
395 }
396 last_key4.as_u64 = key4_1.as_u64;
397 tunnel_index1 = last_tunnel_index = p1[0];
398 }
399 else
400 tunnel_index1 = last_tunnel_index;
401 t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1);
402
403 /* Validate GENEVE tunnel encap-fib index agaist packet */
404 if (PREDICT_FALSE (validate_geneve_fib (b1, t1, is_ip4) == 0))
405 {
406 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
407 next1 = GENEVE_INPUT_NEXT_DROP;
408 goto trace1;
409 }
410
411 /* Validate GENEVE tunnel SIP against packet DIP */
412 if (PREDICT_TRUE
413 (ip4_1->dst_address.as_u32 == t1->local.ip4.as_u32))
414 goto next1; /* valid packet */
415 if (PREDICT_FALSE
416 (ip4_address_is_multicast (&ip4_1->dst_address)))
417 {
418 key4_1.remote = ip4_1->dst_address.as_u32;
419 key4_1.vni = geneve1->vni;
420 /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
421 p1 = hash_get (vxm->geneve4_tunnel_by_key, key4_1.as_u64);
422 if (PREDICT_TRUE (p1 != NULL))
423 {
424 mt1 = pool_elt_at_index (vxm->tunnels, p1[0]);
425 goto next1; /* valid packet */
426 }
427 }
428 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
429 next1 = GENEVE_INPUT_NEXT_DROP;
430 goto trace1;
431
432 }
433 else /* !is_ip4 */
434 {
435 key6_1.remote.as_u64[0] = ip6_1->src_address.as_u64[0];
436 key6_1.remote.as_u64[1] = ip6_1->src_address.as_u64[1];
437 key6_1.vni = geneve1->vni;
438
439 /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
440 if (PREDICT_FALSE
441 (memcmp (&key6_1, &last_key6, sizeof (last_key6)) != 0))
442 {
443 p1 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_1);
444
445 if (PREDICT_FALSE (p1 == NULL))
446 {
447 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
448 next1 = GENEVE_INPUT_NEXT_DROP;
449 goto trace1;
450 }
451
452 clib_memcpy (&last_key6, &key6_1, sizeof (key6_1));
453 tunnel_index1 = last_tunnel_index = p1[0];
454 }
455 else
456 tunnel_index1 = last_tunnel_index;
457 t1 = pool_elt_at_index (vxm->tunnels, tunnel_index1);
458
459 /* Validate GENEVE tunnel encap-fib index agaist packet */
460 if (PREDICT_FALSE (validate_geneve_fib (b1, t1, is_ip4) == 0))
461 {
462 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
463 next1 = GENEVE_INPUT_NEXT_DROP;
464 goto trace1;
465 }
466
467 /* Validate GENEVE tunnel SIP against packet DIP */
468 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_1->dst_address,
469 &t1->local.ip6)))
470 goto next1; /* valid packet */
471 if (PREDICT_FALSE
472 (ip6_address_is_multicast (&ip6_1->dst_address)))
473 {
474 key6_1.remote.as_u64[0] = ip6_1->dst_address.as_u64[0];
475 key6_1.remote.as_u64[1] = ip6_1->dst_address.as_u64[1];
476 key6_1.vni = geneve1->vni;
477 p1 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_1);
478 if (PREDICT_TRUE (p1 != NULL))
479 {
480 mt1 = pool_elt_at_index (vxm->tunnels, p1[0]);
481 goto next1; /* valid packet */
482 }
483 }
484 error1 = GENEVE_ERROR_NO_SUCH_TUNNEL;
485 next1 = GENEVE_INPUT_NEXT_DROP;
486 goto trace1;
487 }
488
489 next1:
490 next1 = t1->decap_next_index;
491 sw_if_index1 = t1->sw_if_index;
492 len1 = vlib_buffer_length_in_chain (vm, b1);
493
494 /* Required to make the l2 tag push / pop code work on l2 subifs */
495 if (PREDICT_TRUE (next1 == GENEVE_INPUT_NEXT_L2_INPUT))
496 vnet_update_l2_len (b1);
497
498 /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
499 vnet_buffer (b1)->sw_if_index[VLIB_RX] = sw_if_index1;
500 sw_if_index1 = (mt1) ? mt1->sw_if_index : sw_if_index1;
501
502 pkts_decapsulated++;
503 stats_n_packets += 1;
504 stats_n_bytes += len1;
505
506 /* Batch stats increment on the same geneve tunnel so counter
507 is not incremented per packet */
508 if (PREDICT_FALSE (sw_if_index1 != stats_sw_if_index))
509 {
510 stats_n_packets -= 1;
511 stats_n_bytes -= len1;
512 if (stats_n_packets)
513 vlib_increment_combined_counter
514 (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
515 thread_index, stats_sw_if_index,
516 stats_n_packets, stats_n_bytes);
517 stats_n_packets = 1;
518 stats_n_bytes = len1;
519 stats_sw_if_index = sw_if_index1;
520 }
521
522 trace1:
523 b1->error = error1 ? node->errors[error1] : 0;
524
525 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
526 {
527 geneve_rx_trace_t *tr
528 = vlib_add_trace (vm, node, b1, sizeof (*tr));
529 tr->next_index = next1;
530 tr->error = error1;
531 tr->tunnel_index = tunnel_index1;
532 tr->vni = vnet_get_geneve_vni (geneve1);
533 }
534
535 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
536 to_next, n_left_to_next,
537 bi0, bi1, next0, next1);
538 }
539
540 while (n_left_from > 0 && n_left_to_next > 0)
541 {
542 u32 bi0;
543 vlib_buffer_t *b0;
544 u32 next0;
545 ip4_header_t *ip4_0;
546 ip6_header_t *ip6_0;
547 geneve_header_t *geneve0;
548 uword *p0;
549 u32 tunnel_index0;
550 geneve_tunnel_t *t0, *mt0 = NULL;
551 geneve4_tunnel_key_t key4_0;
552 geneve6_tunnel_key_t key6_0;
553 u32 error0;
554 u32 sw_if_index0, len0;
555
556 bi0 = from[0];
557 to_next[0] = bi0;
558 from += 1;
559 to_next += 1;
560 n_left_from -= 1;
561 n_left_to_next -= 1;
562
563 b0 = vlib_get_buffer (vm, bi0);
564
565 /* udp leaves current_data pointing at the geneve header */
566 geneve0 = vlib_buffer_get_current (b0);
567 if (is_ip4)
568 {
569 vlib_buffer_advance
570 (b0, -(word) (sizeof (udp_header_t) + sizeof (ip4_header_t)));
571 ip4_0 = vlib_buffer_get_current (b0);
572 }
573 else
574 {
575 vlib_buffer_advance
576 (b0, -(word) (sizeof (udp_header_t) + sizeof (ip6_header_t)));
577 ip6_0 = vlib_buffer_get_current (b0);
578 }
579
580 /* pop (ip, udp, geneve) */
581 if (is_ip4)
582 {
583 vlib_buffer_advance
584 (b0,
585 sizeof (*ip4_0) + sizeof (udp_header_t) +
586 GENEVE_BASE_HEADER_LENGTH +
587 vnet_get_geneve_options_len (geneve0));
588 }
589 else
590 {
591 vlib_buffer_advance
592 (b0,
593 sizeof (*ip6_0) + sizeof (udp_header_t) +
594 GENEVE_BASE_HEADER_LENGTH +
595 vnet_get_geneve_options_len (geneve0));
596 }
597
598 tunnel_index0 = ~0;
599 error0 = 0;
600
601 if (PREDICT_FALSE (geneve0->ver != GENEVE_VERSION))
602 {
603 error0 = GENEVE_ERROR_BAD_FLAGS;
604 next0 = GENEVE_INPUT_NEXT_DROP;
605 goto trace00;
606 }
607#if SUPPORT_OPTIONS_HEADER==0
608 if (PREDICT_FALSE (vnet_get_geneve_critical_bit (geneve0) == 1))
609 {
610 error0 = GENEVE_ERROR_BAD_FLAGS;
611 next0 = GENEVE_INPUT_NEXT_DROP;
612 goto trace00;
613 }
614#endif
615 if (is_ip4)
616 {
617 key4_0.remote = ip4_0->src_address.as_u32;
618 key4_0.vni = geneve0->vni;
619
620 /* Make sure unicast GENEVE tunnel exist by packet SIP and VNI */
621 if (PREDICT_FALSE (key4_0.as_u64 != last_key4.as_u64))
622 {
623 p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
624 if (PREDICT_FALSE (p0 == NULL))
625 {
626 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
627 next0 = GENEVE_INPUT_NEXT_DROP;
628 goto trace00;
629 }
630 last_key4.as_u64 = key4_0.as_u64;
631 tunnel_index0 = last_tunnel_index = p0[0];
632 }
633 else
634 tunnel_index0 = last_tunnel_index;
635 t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);
636
637 /* Validate GENEVE tunnel encap-fib index agaist packet */
638 if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
639 {
640 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
641 next0 = GENEVE_INPUT_NEXT_DROP;
642 goto trace00;
643 }
644
645 /* Validate GENEVE tunnel SIP against packet DIP */
646 if (PREDICT_TRUE
647 (ip4_0->dst_address.as_u32 == t0->local.ip4.as_u32))
648 goto next00; /* valid packet */
649 if (PREDICT_FALSE
650 (ip4_address_is_multicast (&ip4_0->dst_address)))
651 {
652 key4_0.remote = ip4_0->dst_address.as_u32;
653 key4_0.vni = geneve0->vni;
654 /* Make sure mcast GENEVE tunnel exist by packet DIP and VNI */
655 p0 = hash_get (vxm->geneve4_tunnel_by_key, key4_0.as_u64);
656 if (PREDICT_TRUE (p0 != NULL))
657 {
658 mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
659 goto next00; /* valid packet */
660 }
661 }
662 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
663 next0 = GENEVE_INPUT_NEXT_DROP;
664 goto trace00;
665
666 }
667 else /* !is_ip4 */
668 {
669 key6_0.remote.as_u64[0] = ip6_0->src_address.as_u64[0];
670 key6_0.remote.as_u64[1] = ip6_0->src_address.as_u64[1];
671 key6_0.vni = geneve0->vni;
672
673 /* Make sure GENEVE tunnel exist according to packet SIP and VNI */
674 if (PREDICT_FALSE
675 (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
676 {
677 p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
678 if (PREDICT_FALSE (p0 == NULL))
679 {
680 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
681 next0 = GENEVE_INPUT_NEXT_DROP;
682 goto trace00;
683 }
684 clib_memcpy (&last_key6, &key6_0, sizeof (key6_0));
685 tunnel_index0 = last_tunnel_index = p0[0];
686 }
687 else
688 tunnel_index0 = last_tunnel_index;
689 t0 = pool_elt_at_index (vxm->tunnels, tunnel_index0);
690
691 /* Validate GENEVE tunnel encap-fib index agaist packet */
692 if (PREDICT_FALSE (validate_geneve_fib (b0, t0, is_ip4) == 0))
693 {
694 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
695 next0 = GENEVE_INPUT_NEXT_DROP;
696 goto trace00;
697 }
698
699 /* Validate GENEVE tunnel SIP against packet DIP */
700 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address,
701 &t0->local.ip6)))
702 goto next00; /* valid packet */
703 if (PREDICT_FALSE
704 (ip6_address_is_multicast (&ip6_0->dst_address)))
705 {
706 key6_0.remote.as_u64[0] = ip6_0->dst_address.as_u64[0];
707 key6_0.remote.as_u64[1] = ip6_0->dst_address.as_u64[1];
708 key6_0.vni = geneve0->vni;
709 p0 = hash_get_mem (vxm->geneve6_tunnel_by_key, &key6_0);
710 if (PREDICT_TRUE (p0 != NULL))
711 {
712 mt0 = pool_elt_at_index (vxm->tunnels, p0[0]);
713 goto next00; /* valid packet */
714 }
715 }
716 error0 = GENEVE_ERROR_NO_SUCH_TUNNEL;
717 next0 = GENEVE_INPUT_NEXT_DROP;
718 goto trace00;
719 }
720
721 next00:
722 next0 = t0->decap_next_index;
723 sw_if_index0 = t0->sw_if_index;
724 len0 = vlib_buffer_length_in_chain (vm, b0);
725
726 /* Required to make the l2 tag push / pop code work on l2 subifs */
727 if (PREDICT_TRUE (next0 == GENEVE_INPUT_NEXT_L2_INPUT))
728 vnet_update_l2_len (b0);
729
730 /* Set packet input sw_if_index to unicast GENEVE tunnel for learning */
731 vnet_buffer (b0)->sw_if_index[VLIB_RX] = sw_if_index0;
732 sw_if_index0 = (mt0) ? mt0->sw_if_index : sw_if_index0;
733
734 pkts_decapsulated++;
735 stats_n_packets += 1;
736 stats_n_bytes += len0;
737
738 /* Batch stats increment on the same geneve tunnel so counter
739 is not incremented per packet */
740 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
741 {
742 stats_n_packets -= 1;
743 stats_n_bytes -= len0;
744 if (stats_n_packets)
745 vlib_increment_combined_counter
746 (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
747 thread_index, stats_sw_if_index,
748 stats_n_packets, stats_n_bytes);
749 stats_n_packets = 1;
750 stats_n_bytes = len0;
751 stats_sw_if_index = sw_if_index0;
752 }
753
754 trace00:
755 b0->error = error0 ? node->errors[error0] : 0;
756
757 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
758 {
759 geneve_rx_trace_t *tr
760 = vlib_add_trace (vm, node, b0, sizeof (*tr));
761 tr->next_index = next0;
762 tr->error = error0;
763 tr->tunnel_index = tunnel_index0;
764 tr->vni = vnet_get_geneve_vni (geneve0);
765 }
766 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
767 to_next, n_left_to_next,
768 bi0, next0);
769 }
770
771 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
772 }
773 /* Do we still need this now that tunnel tx stats is kept? */
774 vlib_node_increment_counter (vm, is_ip4 ?
775 geneve4_input_node.
776 index : geneve6_input_node.index,
777 GENEVE_ERROR_DECAPSULATED, pkts_decapsulated);
778
779 /* Increment any remaining batch stats */
780 if (stats_n_packets)
781 {
782 vlib_increment_combined_counter
783 (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX,
784 thread_index, stats_sw_if_index, stats_n_packets, stats_n_bytes);
785 node->runtime_data[0] = stats_sw_if_index;
786 }
787
788 return from_frame->n_vectors;
789}
790
791static uword
792geneve4_input (vlib_main_t * vm,
793 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
794{
795 return geneve_input (vm, node, from_frame, /* is_ip4 */ 1);
796}
797
798static uword
799geneve6_input (vlib_main_t * vm,
800 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
801{
802 return geneve_input (vm, node, from_frame, /* is_ip4 */ 0);
803}
804
805static char *geneve_error_strings[] = {
806#define geneve_error(n,s) s,
807#include <vnet/geneve/geneve_error.def>
808#undef geneve_error
809#undef _
810};
811
812/* *INDENT-OFF* */
813VLIB_REGISTER_NODE (geneve4_input_node) = {
814 .function = geneve4_input,
815 .name = "geneve4-input",
816 /* Takes a vector of packets. */
817 .vector_size = sizeof (u32),
818 .n_errors = GENEVE_N_ERROR,
819 .error_strings = geneve_error_strings,
820 .n_next_nodes = GENEVE_INPUT_N_NEXT,
821 .next_nodes = {
822#define _(s,n) [GENEVE_INPUT_NEXT_##s] = n,
823 foreach_geneve_input_next
824#undef _
825 },
826
827//temp .format_buffer = format_geneve_header,
828 .format_trace = format_geneve_rx_trace,
829 // $$$$ .unformat_buffer = unformat_geneve_header,
830};
831
832VLIB_NODE_FUNCTION_MULTIARCH (geneve4_input_node, geneve4_input)
833
834VLIB_REGISTER_NODE (geneve6_input_node) = {
835 .function = geneve6_input,
836 .name = "geneve6-input",
837 /* Takes a vector of packets. */
838 .vector_size = sizeof (u32),
839 .n_errors = GENEVE_N_ERROR,
840 .error_strings = geneve_error_strings,
841 .n_next_nodes = GENEVE_INPUT_N_NEXT,
842 .next_nodes = {
843#define _(s,n) [GENEVE_INPUT_NEXT_##s] = n,
844 foreach_geneve_input_next
845#undef _
846 },
847//temp .format_buffer = format_geneve_header,
848 .format_trace = format_geneve_rx_trace,
849 // $$$$ .unformat_buffer = unformat_geneve_header,
850};
851
852VLIB_NODE_FUNCTION_MULTIARCH (geneve6_input_node, geneve6_input)
853/* *INDENT-ON* */
854
855typedef enum
856{
857 IP_GENEVE_BYPASS_NEXT_DROP,
858 IP_GENEVE_BYPASS_NEXT_GENEVE,
859 IP_GENEVE_BYPASS_N_NEXT,
860} ip_vxan_bypass_next_t;
861
862always_inline uword
863ip_geneve_bypass_inline (vlib_main_t * vm,
864 vlib_node_runtime_t * node,
865 vlib_frame_t * frame, u32 is_ip4)
866{
867 geneve_main_t *vxm = &geneve_main;
868 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
869 vlib_node_runtime_t *error_node =
870 vlib_node_get_runtime (vm, ip4_input_node.index);
871 ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */
872 ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */
873
874 from = vlib_frame_vector_args (frame);
875 n_left_from = frame->n_vectors;
876 next_index = node->cached_next_index;
877
878 if (node->flags & VLIB_NODE_FLAG_TRACE)
879 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
880
881 if (is_ip4)
882 addr4.data_u32 = ~0;
883 else
884 ip6_address_set_zero (&addr6);
885
886 while (n_left_from > 0)
887 {
888 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
889
890 while (n_left_from >= 4 && n_left_to_next >= 2)
891 {
892 vlib_buffer_t *b0, *b1;
893 ip4_header_t *ip40, *ip41;
894 ip6_header_t *ip60, *ip61;
895 udp_header_t *udp0, *udp1;
896 u32 bi0, ip_len0, udp_len0, flags0, next0;
897 u32 bi1, ip_len1, udp_len1, flags1, next1;
898 i32 len_diff0, len_diff1;
899 u8 error0, good_udp0, proto0;
900 u8 error1, good_udp1, proto1;
901
902 /* Prefetch next iteration. */
903 {
904 vlib_buffer_t *p2, *p3;
905
906 p2 = vlib_get_buffer (vm, from[2]);
907 p3 = vlib_get_buffer (vm, from[3]);
908
909 vlib_prefetch_buffer_header (p2, LOAD);
910 vlib_prefetch_buffer_header (p3, LOAD);
911
912 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
913 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
914 }
915
916 bi0 = to_next[0] = from[0];
917 bi1 = to_next[1] = from[1];
918 from += 2;
919 n_left_from -= 2;
920 to_next += 2;
921 n_left_to_next -= 2;
922
923 b0 = vlib_get_buffer (vm, bi0);
924 b1 = vlib_get_buffer (vm, bi1);
925 if (is_ip4)
926 {
927 ip40 = vlib_buffer_get_current (b0);
928 ip41 = vlib_buffer_get_current (b1);
929 }
930 else
931 {
932 ip60 = vlib_buffer_get_current (b0);
933 ip61 = vlib_buffer_get_current (b1);
934 }
935
936 /* Setup packet for next IP feature */
937 vnet_feature_next (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0,
938 b0);
939 vnet_feature_next (vnet_buffer (b1)->sw_if_index[VLIB_RX], &next1,
940 b1);
941
942 if (is_ip4)
943 {
944 /* Treat IP frag packets as "experimental" protocol for now
945 until support of IP frag reassembly is implemented */
946 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
947 proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
948 }
949 else
950 {
951 proto0 = ip60->protocol;
952 proto1 = ip61->protocol;
953 }
954
955 /* Process packet 0 */
956 if (proto0 != IP_PROTOCOL_UDP)
957 goto exit0; /* not UDP packet */
958
959 if (is_ip4)
960 udp0 = ip4_next_header (ip40);
961 else
962 udp0 = ip6_next_header (ip60);
963
964 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
965 goto exit0; /* not GENEVE packet */
966
967 /* Validate DIP against VTEPs */
968 if (is_ip4)
969 {
970 if (addr4.as_u32 != ip40->dst_address.as_u32)
971 {
972 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
973 goto exit0; /* no local VTEP for GENEVE packet */
974 addr4 = ip40->dst_address;
975 }
976 }
977 else
978 {
979 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
980 {
981 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
982 goto exit0; /* no local VTEP for GENEVE packet */
983 addr6 = ip60->dst_address;
984 }
985 }
986
987 flags0 = b0->flags;
988 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
989
990 /* Don't verify UDP checksum for packets with explicit zero checksum. */
991 good_udp0 |= udp0->checksum == 0;
992
993 /* Verify UDP length */
994 if (is_ip4)
995 ip_len0 = clib_net_to_host_u16 (ip40->length);
996 else
997 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
998 udp_len0 = clib_net_to_host_u16 (udp0->length);
999 len_diff0 = ip_len0 - udp_len0;
1000
1001 /* Verify UDP checksum */
1002 if (PREDICT_FALSE (!good_udp0))
1003 {
1004 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1005 {
1006 if (is_ip4)
1007 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
1008 else
1009 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
1010 good_udp0 =
1011 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1012 }
1013 }
1014
1015 if (is_ip4)
1016 {
1017 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1018 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
1019 }
1020 else
1021 {
1022 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1023 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
1024 }
1025
1026 next0 = error0 ?
1027 IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
1028 b0->error = error0 ? error_node->errors[error0] : 0;
1029
1030 /* geneve-input node expect current at GENEVE header */
1031 if (is_ip4)
1032 vlib_buffer_advance (b0,
1033 sizeof (ip4_header_t) +
1034 sizeof (udp_header_t));
1035 else
1036 vlib_buffer_advance (b0,
1037 sizeof (ip6_header_t) +
1038 sizeof (udp_header_t));
1039
1040 exit0:
1041 /* Process packet 1 */
1042 if (proto1 != IP_PROTOCOL_UDP)
1043 goto exit1; /* not UDP packet */
1044
1045 if (is_ip4)
1046 udp1 = ip4_next_header (ip41);
1047 else
1048 udp1 = ip6_next_header (ip61);
1049
1050 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
1051 goto exit1; /* not GENEVE packet */
1052
1053 /* Validate DIP against VTEPs */
1054 if (is_ip4)
1055 {
1056 if (addr4.as_u32 != ip41->dst_address.as_u32)
1057 {
1058 if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32))
1059 goto exit1; /* no local VTEP for GENEVE packet */
1060 addr4 = ip41->dst_address;
1061 }
1062 }
1063 else
1064 {
1065 if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
1066 {
1067 if (!hash_get_mem (vxm->vtep6, &ip61->dst_address))
1068 goto exit1; /* no local VTEP for GENEVE packet */
1069 addr6 = ip61->dst_address;
1070 }
1071 }
1072
1073 flags1 = b1->flags;
1074 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1075
1076 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1077 good_udp1 |= udp1->checksum == 0;
1078
1079 /* Verify UDP length */
1080 if (is_ip4)
1081 ip_len1 = clib_net_to_host_u16 (ip41->length);
1082 else
1083 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
1084 udp_len1 = clib_net_to_host_u16 (udp1->length);
1085 len_diff1 = ip_len1 - udp_len1;
1086
1087 /* Verify UDP checksum */
1088 if (PREDICT_FALSE (!good_udp1))
1089 {
1090 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1091 {
1092 if (is_ip4)
1093 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
1094 else
1095 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
1096 good_udp1 =
1097 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1098 }
1099 }
1100
1101 if (is_ip4)
1102 {
1103 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1104 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
1105 }
1106 else
1107 {
1108 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1109 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
1110 }
1111
1112 next1 = error1 ?
1113 IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
1114 b1->error = error1 ? error_node->errors[error1] : 0;
1115
1116 /* geneve-input node expect current at GENEVE header */
1117 if (is_ip4)
1118 vlib_buffer_advance (b1,
1119 sizeof (ip4_header_t) +
1120 sizeof (udp_header_t));
1121 else
1122 vlib_buffer_advance (b1,
1123 sizeof (ip6_header_t) +
1124 sizeof (udp_header_t));
1125
1126 exit1:
1127 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1128 to_next, n_left_to_next,
1129 bi0, bi1, next0, next1);
1130 }
1131
1132 while (n_left_from > 0 && n_left_to_next > 0)
1133 {
1134 vlib_buffer_t *b0;
1135 ip4_header_t *ip40;
1136 ip6_header_t *ip60;
1137 udp_header_t *udp0;
1138 u32 bi0, ip_len0, udp_len0, flags0, next0;
1139 i32 len_diff0;
1140 u8 error0, good_udp0, proto0;
1141
1142 bi0 = to_next[0] = from[0];
1143 from += 1;
1144 n_left_from -= 1;
1145 to_next += 1;
1146 n_left_to_next -= 1;
1147
1148 b0 = vlib_get_buffer (vm, bi0);
1149 if (is_ip4)
1150 ip40 = vlib_buffer_get_current (b0);
1151 else
1152 ip60 = vlib_buffer_get_current (b0);
1153
1154 /* Setup packet for next IP feature */
1155 vnet_feature_next (vnet_buffer (b0)->sw_if_index[VLIB_RX], &next0,
1156 b0);
1157
1158 if (is_ip4)
1159 /* Treat IP4 frag packets as "experimental" protocol for now
1160 until support of IP frag reassembly is implemented */
1161 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
1162 else
1163 proto0 = ip60->protocol;
1164
1165 if (proto0 != IP_PROTOCOL_UDP)
1166 goto exit; /* not UDP packet */
1167
1168 if (is_ip4)
1169 udp0 = ip4_next_header (ip40);
1170 else
1171 udp0 = ip6_next_header (ip60);
1172
1173 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_geneve))
1174 goto exit; /* not GENEVE packet */
1175
1176 /* Validate DIP against VTEPs */
1177 if (is_ip4)
1178 {
1179 if (addr4.as_u32 != ip40->dst_address.as_u32)
1180 {
1181 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
1182 goto exit; /* no local VTEP for GENEVE packet */
1183 addr4 = ip40->dst_address;
1184 }
1185 }
1186 else
1187 {
1188 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
1189 {
1190 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
1191 goto exit; /* no local VTEP for GENEVE packet */
1192 addr6 = ip60->dst_address;
1193 }
1194 }
1195
1196 flags0 = b0->flags;
1197 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1198
1199 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1200 good_udp0 |= udp0->checksum == 0;
1201
1202 /* Verify UDP length */
1203 if (is_ip4)
1204 ip_len0 = clib_net_to_host_u16 (ip40->length);
1205 else
1206 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
1207 udp_len0 = clib_net_to_host_u16 (udp0->length);
1208 len_diff0 = ip_len0 - udp_len0;
1209
1210 /* Verify UDP checksum */
1211 if (PREDICT_FALSE (!good_udp0))
1212 {
1213 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1214 {
1215 if (is_ip4)
1216 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
1217 else
1218 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
1219 good_udp0 =
1220 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1221 }
1222 }
1223
1224 if (is_ip4)
1225 {
1226 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1227 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
1228 }
1229 else
1230 {
1231 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1232 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
1233 }
1234
1235 next0 = error0 ?
1236 IP_GENEVE_BYPASS_NEXT_DROP : IP_GENEVE_BYPASS_NEXT_GENEVE;
1237 b0->error = error0 ? error_node->errors[error0] : 0;
1238
1239 /* geneve-input node expect current at GENEVE header */
1240 if (is_ip4)
1241 vlib_buffer_advance (b0,
1242 sizeof (ip4_header_t) +
1243 sizeof (udp_header_t));
1244 else
1245 vlib_buffer_advance (b0,
1246 sizeof (ip6_header_t) +
1247 sizeof (udp_header_t));
1248
1249 exit:
1250 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1251 to_next, n_left_to_next,
1252 bi0, next0);
1253 }
1254
1255 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1256 }
1257
1258 return frame->n_vectors;
1259}
1260
1261static uword
1262ip4_geneve_bypass (vlib_main_t * vm,
1263 vlib_node_runtime_t * node, vlib_frame_t * frame)
1264{
1265 return ip_geneve_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
1266}
1267
1268/* *INDENT-OFF* */
1269VLIB_REGISTER_NODE (ip4_geneve_bypass_node) =
1270{
1271 .function = ip4_geneve_bypass,.name = "ip4-geneve-bypass",.vector_size =
1272 sizeof (u32),.n_next_nodes = IP_GENEVE_BYPASS_N_NEXT,.next_nodes =
1273 {
1274 [IP_GENEVE_BYPASS_NEXT_DROP] = "error-drop",
1275 [IP_GENEVE_BYPASS_NEXT_GENEVE] = "geneve4-input",}
1276,.format_buffer = format_ip4_header,.format_trace =
1277 format_ip4_forward_next_trace,};
1278
1279VLIB_NODE_FUNCTION_MULTIARCH (ip4_geneve_bypass_node, ip4_geneve_bypass)
1280/* Dummy init function to get us linked in. */
1281 clib_error_t *ip4_geneve_bypass_init (vlib_main_t * vm)
1282{
1283 return 0;
1284}
1285
1286VLIB_INIT_FUNCTION (ip4_geneve_bypass_init);
1287/* *INDENT-ON* */
1288
1289static uword
1290ip6_geneve_bypass (vlib_main_t * vm,
1291 vlib_node_runtime_t * node, vlib_frame_t * frame)
1292{
1293 return ip_geneve_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
1294}
1295
1296/* *INDENT-OFF* */
1297VLIB_REGISTER_NODE (ip6_geneve_bypass_node) =
1298{
1299 .function = ip6_geneve_bypass,.name = "ip6-geneve-bypass",.vector_size =
1300 sizeof (u32),.n_next_nodes = IP_GENEVE_BYPASS_N_NEXT,.next_nodes =
1301 {
1302 [IP_GENEVE_BYPASS_NEXT_DROP] = "error-drop",
1303 [IP_GENEVE_BYPASS_NEXT_GENEVE] = "geneve6-input",}
1304,.format_buffer = format_ip6_header,.format_trace =
1305 format_ip6_forward_next_trace,};
1306/* *INDENT-ON* */
1307
1308VLIB_NODE_FUNCTION_MULTIARCH (ip6_geneve_bypass_node, ip6_geneve_bypass)
1309/* Dummy init function to get us linked in. */
1310 clib_error_t *ip6_geneve_bypass_init (vlib_main_t * vm)
1311{
1312 return 0;
1313}
1314
1315VLIB_INIT_FUNCTION (ip6_geneve_bypass_init);
1316
1317/*
1318 * fd.io coding-style-patch-verification: ON
1319 *
1320 * Local Variables:
1321 * eval: (c-set-style "gnu")
1322 * End:
1323 */