2 * decap.c: vxlan gbp tunnel decap packet processing
4 * Copyright (c) 2018 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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vlib/vlib.h>
20 #include <vnet/vxlan-gbp/vxlan_gbp.h>
30 } vxlan_gbp_rx_trace_t;
33 format_vxlan_gbp_rx_trace (u8 * s, va_list * args)
35 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
36 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
37 vxlan_gbp_rx_trace_t *t = va_arg (*args, vxlan_gbp_rx_trace_t *);
39 if (t->tunnel_index == ~0)
41 "VXLAN_GBP decap error - tunnel for vni %d does not exist",
44 "VXLAN_GBP decap from vxlan_gbp_tunnel%d vni %d sclass %d"
45 " flags %U next %d error %d",
46 t->tunnel_index, t->vni, t->sclass,
47 format_vxlan_gbp_header_gpflags, t->flags,
48 t->next_index, t->error);
52 buf_fib_index (vlib_buffer_t * b, u32 is_ip4)
54 u32 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
55 if (sw_if_index != (u32) ~ 0)
58 u32 *fib_index_by_sw_if_index = is_ip4 ?
59 ip4_main.fib_index_by_sw_if_index : ip6_main.fib_index_by_sw_if_index;
60 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
62 return vec_elt (fib_index_by_sw_if_index, sw_if_index);
65 typedef vxlan4_gbp_tunnel_key_t last_tunnel_cache4;
67 always_inline vxlan_gbp_tunnel_t *
68 vxlan4_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache4 * cache,
69 u32 fib_index, ip4_header_t * ip4_0,
70 vxlan_gbp_header_t * vxlan_gbp0)
73 * Check unicast first since that's where most of the traffic comes from
74 * Make sure VXLAN_GBP tunnel exist according to packet SIP, DIP and VNI
76 vxlan4_gbp_tunnel_key_t key4;
79 key4.key[1] = (((u64) fib_index << 32) |
80 (vxlan_gbp0->vni_reserved &
81 clib_host_to_net_u32 (0xffffff00)));
83 (((u64) ip4_0->dst_address.as_u32 << 32) | ip4_0->src_address.as_u32);
85 if (PREDICT_FALSE (key4.key[0] != cache->key[0] ||
86 key4.key[1] != cache->key[1]))
88 rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key,
90 if (PREDICT_FALSE (rv == 0))
93 return (pool_elt_at_index (vxm->tunnels, cache->value));
98 return (pool_elt_at_index (vxm->tunnels, cache->value));
101 /* No unicast match - try multicast */
102 if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address)))
105 key4.key[0] = ip4_0->dst_address.as_u32;
106 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
107 rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key, &key4);
109 if (PREDICT_FALSE (rv != 0))
112 return (pool_elt_at_index (vxm->tunnels, key4.value));
115 typedef vxlan6_gbp_tunnel_key_t last_tunnel_cache6;
117 always_inline vxlan_gbp_tunnel_t *
118 vxlan6_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache6 * cache,
119 u32 fib_index, ip6_header_t * ip6_0,
120 vxlan_gbp_header_t * vxlan_gbp0)
122 /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */
123 vxlan6_gbp_tunnel_key_t key6 = {
125 [0] = ip6_0->src_address.as_u64[0],
126 [1] = ip6_0->src_address.as_u64[1],
127 [2] = ((((u64) fib_index) << 32) |
128 (vxlan_gbp0->vni_reserved &
129 clib_host_to_net_u32 (0xffffff00))),
135 (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0))
137 rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
139 if (PREDICT_FALSE (rv != 0))
144 vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
146 /* Validate VXLAN_GBP tunnel SIP against packet DIP */
148 (!ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6)))
151 if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address)))
154 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
155 key6.key[0] = ip6_0->dst_address.as_u64[0];
156 key6.key[1] = ip6_0->dst_address.as_u64[1];
157 rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
159 if (PREDICT_FALSE (rv != 0))
167 always_inline vxlan_gbp_input_next_t
168 vxlan_gbp_tunnel_get_next (const vxlan_gbp_tunnel_t * t, vlib_buffer_t * b0)
170 if (VXLAN_GBP_TUNNEL_MODE_L2 == t->mode)
171 return (VXLAN_GBP_INPUT_NEXT_L2_INPUT);
174 ethernet_header_t *e0;
177 e0 = vlib_buffer_get_current (b0);
178 vlib_buffer_advance (b0, sizeof (*e0));
179 type0 = clib_net_to_host_u16 (e0->type);
182 case ETHERNET_TYPE_IP4:
183 return (VXLAN_GBP_INPUT_NEXT_IP4_INPUT);
184 case ETHERNET_TYPE_IP6:
185 return (VXLAN_GBP_INPUT_NEXT_IP6_INPUT);
188 return (VXLAN_GBP_INPUT_NEXT_DROP);
192 vxlan_gbp_input (vlib_main_t * vm,
193 vlib_node_runtime_t * node,
194 vlib_frame_t * from_frame, u8 is_ip4)
196 vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
197 vnet_main_t *vnm = vxm->vnet_main;
198 vnet_interface_main_t *im = &vnm->interface_main;
199 vlib_combined_counter_main_t *rx_counter =
200 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX;
201 vlib_combined_counter_main_t *drop_counter =
202 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP;
203 last_tunnel_cache4 last4;
204 last_tunnel_cache6 last6;
205 u32 pkts_decapsulated = 0;
206 u32 thread_index = vlib_get_thread_index ();
209 clib_memset (&last4, 0xff, sizeof last4);
211 clib_memset (&last6, 0xff, sizeof last6);
213 u32 next_index = node->cached_next_index;
215 u32 *from = vlib_frame_vector_args (from_frame);
216 u32 n_left_from = from_frame->n_vectors;
218 while (n_left_from > 0)
220 u32 *to_next, n_left_to_next;
221 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
223 while (n_left_from >= 4 && n_left_to_next >= 2)
225 /* Prefetch next iteration. */
227 vlib_buffer_t *p2, *p3;
229 p2 = vlib_get_buffer (vm, from[2]);
230 p3 = vlib_get_buffer (vm, from[3]);
232 vlib_prefetch_buffer_header (p2, LOAD);
233 vlib_prefetch_buffer_header (p3, LOAD);
235 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
236 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
239 u32 bi0 = to_next[0] = from[0];
240 u32 bi1 = to_next[1] = from[1];
246 vlib_buffer_t *b0, *b1;
247 b0 = vlib_get_buffer (vm, bi0);
248 b1 = vlib_get_buffer (vm, bi1);
250 /* udp leaves current_data pointing at the vxlan_gbp header */
251 void *cur0 = vlib_buffer_get_current (b0);
252 void *cur1 = vlib_buffer_get_current (b1);
253 vxlan_gbp_header_t *vxlan_gbp0 = cur0;
254 vxlan_gbp_header_t *vxlan_gbp1 = cur1;
256 ip4_header_t *ip4_0, *ip4_1;
257 ip6_header_t *ip6_0, *ip6_1;
260 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
261 ip4_1 = cur1 - sizeof (udp_header_t) - sizeof (ip4_header_t);
265 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
266 ip6_1 = cur1 - sizeof (udp_header_t) - sizeof (ip6_header_t);
269 u32 fi0 = buf_fib_index (b0, is_ip4);
270 u32 fi1 = buf_fib_index (b1, is_ip4);
272 vxlan_gbp_tunnel_t *t0, *t1;
276 vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0);
278 vxlan4_gbp_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan_gbp1);
283 vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0);
285 vxlan6_gbp_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan_gbp1);
288 u32 len0 = vlib_buffer_length_in_chain (vm, b0);
289 u32 len1 = vlib_buffer_length_in_chain (vm, b1);
291 vxlan_gbp_input_next_t next0, next1;
292 u8 error0 = 0, error1 = 0;
293 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
294 u8 flags1 = vxlan_gbp_get_flags (vxlan_gbp1);
295 /* Required to make the l2 tag push / pop code work on l2 subifs */
297 vlib_buffer_advance (b0, sizeof *vxlan_gbp0);
298 vlib_buffer_advance (b1, sizeof *vxlan_gbp1);
300 u8 i_and_g0 = ((flags0 & VXLAN_GBP_FLAGS_GI) == VXLAN_GBP_FLAGS_GI);
301 u8 i_and_g1 = ((flags1 & VXLAN_GBP_FLAGS_GI) == VXLAN_GBP_FLAGS_GI);
303 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
304 if (PREDICT_FALSE (t0 == NULL || !i_and_g0))
306 if (t0 != NULL && !i_and_g0)
308 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
309 vlib_increment_combined_counter
310 (drop_counter, thread_index, t0->sw_if_index, 1, len0);
311 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
315 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
316 next0 = VXLAN_GBP_INPUT_NEXT_PUNT;
319 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4];
322 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6];
324 b0->error = node->errors[error0];
328 next0 = vxlan_gbp_tunnel_get_next (t0, b0);
330 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
331 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
332 vlib_increment_combined_counter
333 (rx_counter, thread_index, t0->sw_if_index, 1, len0);
337 vnet_buffer2 (b0)->gbp.flags = (vxlan_gbp_get_gpflags (vxlan_gbp0) |
338 VXLAN_GBP_GPFLAGS_R);
339 vnet_buffer2 (b0)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
342 if (PREDICT_FALSE (t1 == NULL || !i_and_g1))
344 if (t1 != NULL && !i_and_g1)
346 error1 = VXLAN_GBP_ERROR_BAD_FLAGS;
347 vlib_increment_combined_counter
348 (drop_counter, thread_index, t1->sw_if_index, 1, len1);
349 next1 = VXLAN_GBP_INPUT_NEXT_DROP;
353 error1 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
354 next1 = VXLAN_GBP_INPUT_NEXT_PUNT;
357 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4];
360 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6];
362 b1->error = node->errors[error1];
366 next1 = vxlan_gbp_tunnel_get_next (t1, b1);
368 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
369 vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
372 vlib_increment_combined_counter
373 (rx_counter, thread_index, t1->sw_if_index, 1, len1);
376 vnet_buffer2 (b1)->gbp.flags = (vxlan_gbp_get_gpflags (vxlan_gbp1) |
377 VXLAN_GBP_GPFLAGS_R);
379 vnet_buffer2 (b1)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp1);
381 vnet_update_l2_len (b0);
382 vnet_update_l2_len (b1);
384 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
386 vxlan_gbp_rx_trace_t *tr =
387 vlib_add_trace (vm, node, b0, sizeof (*tr));
388 tr->next_index = next0;
390 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
391 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
392 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
393 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
395 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
397 vxlan_gbp_rx_trace_t *tr =
398 vlib_add_trace (vm, node, b1, sizeof (*tr));
399 tr->next_index = next1;
401 tr->tunnel_index = t1 == 0 ? ~0 : t1 - vxm->tunnels;
402 tr->vni = vxlan_gbp_get_vni (vxlan_gbp1);
403 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp1);
404 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp1);
407 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
408 to_next, n_left_to_next,
409 bi0, bi1, next0, next1);
412 while (n_left_from > 0 && n_left_to_next > 0)
414 u32 bi0 = to_next[0] = from[0];
420 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
422 /* udp leaves current_data pointing at the vxlan_gbp header */
423 void *cur0 = vlib_buffer_get_current (b0);
424 vxlan_gbp_header_t *vxlan_gbp0 = cur0;
428 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
430 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
432 u32 fi0 = buf_fib_index (b0, is_ip4);
434 vxlan_gbp_tunnel_t *t0;
436 t0 = vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0);
438 t0 = vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0);
440 uword len0 = vlib_buffer_length_in_chain (vm, b0);
442 vxlan_gbp_input_next_t next0;
444 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
446 /* pop (ip, udp, vxlan_gbp) */
447 vlib_buffer_advance (b0, sizeof (*vxlan_gbp0));
449 u8 i_and_g0 = ((flags0 & VXLAN_GBP_FLAGS_GI) == VXLAN_GBP_FLAGS_GI);
451 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
452 if (PREDICT_FALSE (t0 == NULL || !i_and_g0))
454 if (t0 != NULL && !i_and_g0)
456 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
457 vlib_increment_combined_counter
458 (drop_counter, thread_index, t0->sw_if_index, 1, len0);
459 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
463 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
464 next0 = VXLAN_GBP_INPUT_NEXT_PUNT;
467 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4];
470 vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6];
472 b0->error = node->errors[error0];
476 next0 = vxlan_gbp_tunnel_get_next (t0, b0);
477 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
478 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
481 vlib_increment_combined_counter
482 (rx_counter, thread_index, t0->sw_if_index, 1, len0);
484 vnet_buffer2 (b0)->gbp.flags = (vxlan_gbp_get_gpflags (vxlan_gbp0) |
485 VXLAN_GBP_GPFLAGS_R);
487 vnet_buffer2 (b0)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
489 /* Required to make the l2 tag push / pop code work on l2 subifs */
490 vnet_update_l2_len (b0);
492 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
494 vxlan_gbp_rx_trace_t *tr
495 = vlib_add_trace (vm, node, b0, sizeof (*tr));
496 tr->next_index = next0;
498 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
499 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
500 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
501 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
503 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
504 to_next, n_left_to_next,
508 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
510 /* Do we still need this now that tunnel tx stats is kept? */
512 is_ip4 ? vxlan4_gbp_input_node.index : vxlan6_gbp_input_node.index;
513 vlib_node_increment_counter (vm, node_idx, VXLAN_GBP_ERROR_DECAPSULATED,
516 return from_frame->n_vectors;
519 VLIB_NODE_FN (vxlan4_gbp_input_node) (vlib_main_t * vm,
520 vlib_node_runtime_t * node,
521 vlib_frame_t * from_frame)
523 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 1);
526 VLIB_NODE_FN (vxlan6_gbp_input_node) (vlib_main_t * vm,
527 vlib_node_runtime_t * node,
528 vlib_frame_t * from_frame)
530 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 0);
533 static char *vxlan_gbp_error_strings[] = {
534 #define vxlan_gbp_error(n,s) s,
535 #include <vnet/vxlan-gbp/vxlan_gbp_error.def>
536 #undef vxlan_gbp_error
541 VLIB_REGISTER_NODE (vxlan4_gbp_input_node) =
543 .name = "vxlan4-gbp-input",
544 .vector_size = sizeof (u32),
545 .n_errors = VXLAN_GBP_N_ERROR,
546 .error_strings = vxlan_gbp_error_strings,
547 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
548 .format_trace = format_vxlan_gbp_rx_trace,
550 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
551 foreach_vxlan_gbp_input_next
556 VLIB_REGISTER_NODE (vxlan6_gbp_input_node) =
558 .name = "vxlan6-gbp-input",
559 .vector_size = sizeof (u32),
560 .n_errors = VXLAN_GBP_N_ERROR,
561 .error_strings = vxlan_gbp_error_strings,
562 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
564 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
565 foreach_vxlan_gbp_input_next
568 .format_trace = format_vxlan_gbp_rx_trace,
574 IP_VXLAN_GBP_BYPASS_NEXT_DROP,
575 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP,
576 IP_VXLAN_GBP_BYPASS_N_NEXT,
577 } ip_vxlan_gbp_bypass_next_t;
580 ip_vxlan_gbp_bypass_inline (vlib_main_t * vm,
581 vlib_node_runtime_t * node,
582 vlib_frame_t * frame, u32 is_ip4)
584 vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
585 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
586 vlib_node_runtime_t *error_node =
587 vlib_node_get_runtime (vm, ip4_input_node.index);
588 ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */
589 ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */
591 from = vlib_frame_vector_args (frame);
592 n_left_from = frame->n_vectors;
593 next_index = node->cached_next_index;
595 if (node->flags & VLIB_NODE_FLAG_TRACE)
596 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
601 ip6_address_set_zero (&addr6);
603 while (n_left_from > 0)
605 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
607 while (n_left_from >= 4 && n_left_to_next >= 2)
609 vlib_buffer_t *b0, *b1;
610 ip4_header_t *ip40, *ip41;
611 ip6_header_t *ip60, *ip61;
612 udp_header_t *udp0, *udp1;
613 u32 bi0, ip_len0, udp_len0, flags0, next0;
614 u32 bi1, ip_len1, udp_len1, flags1, next1;
615 i32 len_diff0, len_diff1;
616 u8 error0, good_udp0, proto0;
617 u8 error1, good_udp1, proto1;
619 /* Prefetch next iteration. */
621 vlib_buffer_t *p2, *p3;
623 p2 = vlib_get_buffer (vm, from[2]);
624 p3 = vlib_get_buffer (vm, from[3]);
626 vlib_prefetch_buffer_header (p2, LOAD);
627 vlib_prefetch_buffer_header (p3, LOAD);
629 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
630 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
633 bi0 = to_next[0] = from[0];
634 bi1 = to_next[1] = from[1];
640 b0 = vlib_get_buffer (vm, bi0);
641 b1 = vlib_get_buffer (vm, bi1);
644 ip40 = vlib_buffer_get_current (b0);
645 ip41 = vlib_buffer_get_current (b1);
649 ip60 = vlib_buffer_get_current (b0);
650 ip61 = vlib_buffer_get_current (b1);
653 /* Setup packet for next IP feature */
654 vnet_feature_next (&next0, b0);
655 vnet_feature_next (&next1, b1);
659 /* Treat IP frag packets as "experimental" protocol for now
660 until support of IP frag reassembly is implemented */
661 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
662 proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
666 proto0 = ip60->protocol;
667 proto1 = ip61->protocol;
670 /* Process packet 0 */
671 if (proto0 != IP_PROTOCOL_UDP)
672 goto exit0; /* not UDP packet */
675 udp0 = ip4_next_header (ip40);
677 udp0 = ip6_next_header (ip60);
679 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
680 goto exit0; /* not VXLAN_GBP packet */
682 /* Validate DIP against VTEPs */
685 if (addr4.as_u32 != ip40->dst_address.as_u32)
687 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
688 goto exit0; /* no local VTEP for VXLAN_GBP packet */
689 addr4 = ip40->dst_address;
694 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
696 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
697 goto exit0; /* no local VTEP for VXLAN_GBP packet */
698 addr6 = ip60->dst_address;
703 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
705 /* Don't verify UDP checksum for packets with explicit zero checksum. */
706 good_udp0 |= udp0->checksum == 0;
708 /* Verify UDP length */
710 ip_len0 = clib_net_to_host_u16 (ip40->length);
712 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
713 udp_len0 = clib_net_to_host_u16 (udp0->length);
714 len_diff0 = ip_len0 - udp_len0;
716 /* Verify UDP checksum */
717 if (PREDICT_FALSE (!good_udp0))
719 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
722 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
724 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
726 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
732 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
733 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
737 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
738 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
742 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
743 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
744 b0->error = error0 ? error_node->errors[error0] : 0;
746 /* vxlan-gbp-input node expect current at VXLAN_GBP header */
748 vlib_buffer_advance (b0,
749 sizeof (ip4_header_t) +
750 sizeof (udp_header_t));
752 vlib_buffer_advance (b0,
753 sizeof (ip6_header_t) +
754 sizeof (udp_header_t));
757 /* Process packet 1 */
758 if (proto1 != IP_PROTOCOL_UDP)
759 goto exit1; /* not UDP packet */
762 udp1 = ip4_next_header (ip41);
764 udp1 = ip6_next_header (ip61);
766 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
767 goto exit1; /* not VXLAN_GBP packet */
769 /* Validate DIP against VTEPs */
772 if (addr4.as_u32 != ip41->dst_address.as_u32)
774 if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32))
775 goto exit1; /* no local VTEP for VXLAN_GBP packet */
776 addr4 = ip41->dst_address;
781 if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
783 if (!hash_get_mem (vxm->vtep6, &ip61->dst_address))
784 goto exit1; /* no local VTEP for VXLAN_GBP packet */
785 addr6 = ip61->dst_address;
790 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
792 /* Don't verify UDP checksum for packets with explicit zero checksum. */
793 good_udp1 |= udp1->checksum == 0;
795 /* Verify UDP length */
797 ip_len1 = clib_net_to_host_u16 (ip41->length);
799 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
800 udp_len1 = clib_net_to_host_u16 (udp1->length);
801 len_diff1 = ip_len1 - udp_len1;
803 /* Verify UDP checksum */
804 if (PREDICT_FALSE (!good_udp1))
806 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
809 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
811 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
813 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
819 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
820 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
824 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
825 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
829 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
830 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
831 b1->error = error1 ? error_node->errors[error1] : 0;
833 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
835 vlib_buffer_advance (b1,
836 sizeof (ip4_header_t) +
837 sizeof (udp_header_t));
839 vlib_buffer_advance (b1,
840 sizeof (ip6_header_t) +
841 sizeof (udp_header_t));
844 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
845 to_next, n_left_to_next,
846 bi0, bi1, next0, next1);
849 while (n_left_from > 0 && n_left_to_next > 0)
855 u32 bi0, ip_len0, udp_len0, flags0, next0;
857 u8 error0, good_udp0, proto0;
859 bi0 = to_next[0] = from[0];
865 b0 = vlib_get_buffer (vm, bi0);
867 ip40 = vlib_buffer_get_current (b0);
869 ip60 = vlib_buffer_get_current (b0);
871 /* Setup packet for next IP feature */
872 vnet_feature_next (&next0, b0);
875 /* Treat IP4 frag packets as "experimental" protocol for now
876 until support of IP frag reassembly is implemented */
877 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
879 proto0 = ip60->protocol;
881 if (proto0 != IP_PROTOCOL_UDP)
882 goto exit; /* not UDP packet */
885 udp0 = ip4_next_header (ip40);
887 udp0 = ip6_next_header (ip60);
889 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
890 goto exit; /* not VXLAN_GBP packet */
892 /* Validate DIP against VTEPs */
895 if (addr4.as_u32 != ip40->dst_address.as_u32)
897 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
898 goto exit; /* no local VTEP for VXLAN_GBP packet */
899 addr4 = ip40->dst_address;
904 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
906 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
907 goto exit; /* no local VTEP for VXLAN_GBP packet */
908 addr6 = ip60->dst_address;
913 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
915 /* Don't verify UDP checksum for packets with explicit zero checksum. */
916 good_udp0 |= udp0->checksum == 0;
918 /* Verify UDP length */
920 ip_len0 = clib_net_to_host_u16 (ip40->length);
922 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
923 udp_len0 = clib_net_to_host_u16 (udp0->length);
924 len_diff0 = ip_len0 - udp_len0;
926 /* Verify UDP checksum */
927 if (PREDICT_FALSE (!good_udp0))
929 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
932 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
934 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
936 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
942 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
943 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
947 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
948 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
952 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
953 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
954 b0->error = error0 ? error_node->errors[error0] : 0;
956 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
958 vlib_buffer_advance (b0,
959 sizeof (ip4_header_t) +
960 sizeof (udp_header_t));
962 vlib_buffer_advance (b0,
963 sizeof (ip6_header_t) +
964 sizeof (udp_header_t));
967 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
968 to_next, n_left_to_next,
972 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
975 return frame->n_vectors;
978 VLIB_NODE_FN (ip4_vxlan_gbp_bypass_node) (vlib_main_t * vm,
979 vlib_node_runtime_t * node,
980 vlib_frame_t * frame)
982 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
986 VLIB_REGISTER_NODE (ip4_vxlan_gbp_bypass_node) =
988 .name = "ip4-vxlan-gbp-bypass",
989 .vector_size = sizeof (u32),
990 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
992 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
993 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan4-gbp-input",
995 .format_buffer = format_ip4_header,
996 .format_trace = format_ip4_forward_next_trace,
1000 #ifndef CLIB_MARCH_VARIANT
1001 /* Dummy init function to get us linked in. */
1003 ip4_vxlan_gbp_bypass_init (vlib_main_t * vm)
1008 VLIB_INIT_FUNCTION (ip4_vxlan_gbp_bypass_init);
1009 #endif /* CLIB_MARCH_VARIANT */
1011 VLIB_NODE_FN (ip6_vxlan_gbp_bypass_node) (vlib_main_t * vm,
1012 vlib_node_runtime_t * node,
1013 vlib_frame_t * frame)
1015 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
1019 VLIB_REGISTER_NODE (ip6_vxlan_gbp_bypass_node) =
1021 .name = "ip6-vxlan-gbp-bypass",
1022 .vector_size = sizeof (u32),
1023 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
1025 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
1026 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan6-gbp-input",
1028 .format_buffer = format_ip6_header,
1029 .format_trace = format_ip6_forward_next_trace,
1033 #ifndef CLIB_MARCH_VARIANT
1034 /* Dummy init function to get us linked in. */
1036 ip6_vxlan_gbp_bypass_init (vlib_main_t * vm)
1041 VLIB_INIT_FUNCTION (ip6_vxlan_gbp_bypass_init);
1042 #endif /* CLIB_MARCH_VARIANT */
1045 * fd.io coding-style-patch-verification: ON
1048 * eval: (c-set-style "gnu")