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>
19 #include <vnet/pg/pg.h>
20 #include <vnet/vxlan-gbp/vxlan_gbp.h>
22 vlib_node_registration_t vxlan4_gbp_input_node;
23 vlib_node_registration_t vxlan6_gbp_input_node;
32 } vxlan_gbp_rx_trace_t;
35 format_vxlan_gbp_rx_trace (u8 * s, va_list * args)
37 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
38 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
39 vxlan_gbp_rx_trace_t *t = va_arg (*args, vxlan_gbp_rx_trace_t *);
41 if (t->tunnel_index == ~0)
43 "VXLAN_GBP decap error - tunnel for vni %d does not exist",
46 "VXLAN_GBP decap from vxlan_gbp_tunnel%d vni %d sclass %d"
48 t->tunnel_index, t->vni, t->sclass, 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,
71 vxlan_gbp_tunnel_t ** stats_t0)
73 /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */
74 vxlan4_gbp_tunnel_key_t key4;
75 key4.key[1] = ((u64) fib_index << 32) | vxlan_gbp0->vni_reserved;
77 if (PREDICT_FALSE (key4.key[1] != cache->key[1] ||
78 ip4_0->src_address.as_u32 != (u32) cache->key[0]))
80 key4.key[0] = ip4_0->src_address.as_u32;
81 int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key,
83 if (PREDICT_FALSE (rv != 0))
88 vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
90 /* Validate VXLAN_GBP tunnel SIP against packet DIP */
91 if (PREDICT_TRUE (ip4_0->dst_address.as_u32 == t0->src.ip4.as_u32))
96 if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address)))
99 key4.key[0] = ip4_0->dst_address.as_u32;
100 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
101 int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key,
103 if (PREDICT_FALSE (rv != 0))
106 *stats_t0 = pool_elt_at_index (vxm->tunnels, key4.value);
112 typedef vxlan6_gbp_tunnel_key_t last_tunnel_cache6;
114 always_inline vxlan_gbp_tunnel_t *
115 vxlan6_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache6 * cache,
116 u32 fib_index, ip6_header_t * ip6_0,
117 vxlan_gbp_header_t * vxlan_gbp0,
118 vxlan_gbp_tunnel_t ** stats_t0)
120 /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */
121 vxlan6_gbp_tunnel_key_t key6 = {
123 [0] = ip6_0->src_address.as_u64[0],
124 [1] = ip6_0->src_address.as_u64[1],
125 [2] = (((u64) fib_index) << 32) | vxlan_gbp0->vni_reserved,
130 (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0))
132 int rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
134 if (PREDICT_FALSE (rv != 0))
139 vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
141 /* Validate VXLAN_GBP tunnel SIP against packet DIP */
142 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6)))
147 if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address)))
150 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
151 key6.key[0] = ip6_0->dst_address.as_u64[0];
152 key6.key[1] = ip6_0->dst_address.as_u64[1];
153 int rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
155 if (PREDICT_FALSE (rv != 0))
158 *stats_t0 = pool_elt_at_index (vxm->tunnels, key6.value);
165 vxlan_gbp_input (vlib_main_t * vm,
166 vlib_node_runtime_t * node,
167 vlib_frame_t * from_frame, u32 is_ip4)
169 vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
170 vnet_main_t *vnm = vxm->vnet_main;
171 vnet_interface_main_t *im = &vnm->interface_main;
172 vlib_combined_counter_main_t *rx_counter =
173 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX;
174 vlib_combined_counter_main_t *drop_counter =
175 im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP;
176 last_tunnel_cache4 last4;
177 last_tunnel_cache6 last6;
178 u32 pkts_decapsulated = 0;
179 u32 thread_index = vlib_get_thread_index ();
182 clib_memset (&last4, 0xff, sizeof last4);
184 clib_memset (&last6, 0xff, sizeof last6);
186 u32 next_index = node->cached_next_index;
188 u32 *from = vlib_frame_vector_args (from_frame);
189 u32 n_left_from = from_frame->n_vectors;
191 while (n_left_from > 0)
193 u32 *to_next, n_left_to_next;
194 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
196 while (n_left_from >= 4 && n_left_to_next >= 2)
198 /* Prefetch next iteration. */
200 vlib_buffer_t *p2, *p3;
202 p2 = vlib_get_buffer (vm, from[2]);
203 p3 = vlib_get_buffer (vm, from[3]);
205 vlib_prefetch_buffer_header (p2, LOAD);
206 vlib_prefetch_buffer_header (p3, LOAD);
208 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
209 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
212 u32 bi0 = to_next[0] = from[0];
213 u32 bi1 = to_next[1] = from[1];
219 vlib_buffer_t *b0, *b1;
220 b0 = vlib_get_buffer (vm, bi0);
221 b1 = vlib_get_buffer (vm, bi1);
223 /* udp leaves current_data pointing at the vxlan_gbp header */
224 void *cur0 = vlib_buffer_get_current (b0);
225 void *cur1 = vlib_buffer_get_current (b1);
226 vxlan_gbp_header_t *vxlan_gbp0 = cur0;
227 vxlan_gbp_header_t *vxlan_gbp1 = cur1;
229 ip4_header_t *ip4_0, *ip4_1;
230 ip6_header_t *ip6_0, *ip6_1;
233 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
234 ip4_1 = cur1 - sizeof (udp_header_t) - sizeof (ip4_header_t);
238 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
239 ip6_1 = cur1 - sizeof (udp_header_t) - sizeof (ip6_header_t);
243 vlib_buffer_advance (b0, sizeof *vxlan_gbp0);
244 vlib_buffer_advance (b1, sizeof *vxlan_gbp1);
246 u32 fi0 = buf_fib_index (b0, is_ip4);
247 u32 fi1 = buf_fib_index (b1, is_ip4);
249 vxlan_gbp_tunnel_t *t0, *stats_t0 = 0;
250 vxlan_gbp_tunnel_t *t1, *stats_t1 = 0;
254 vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0,
257 vxlan4_gbp_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan_gbp1,
263 vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0,
266 vxlan6_gbp_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan_gbp1,
270 u32 len0 = vlib_buffer_length_in_chain (vm, b0);
271 u32 len1 = vlib_buffer_length_in_chain (vm, b1);
274 u8 error0 = 0, error1 = 0;
275 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
276 u8 flags1 = vxlan_gbp_get_flags (vxlan_gbp1);
277 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
279 (t0 == 0 || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
281 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
284 && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
286 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
287 vlib_increment_combined_counter
288 (drop_counter, thread_index, stats_t0->sw_if_index, 1,
292 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
293 b0->error = node->errors[error0];
297 next0 = t0->decap_next_index;
298 vnet_buffer2 (b0)->gbp.flags =
299 vxlan_gbp_get_gpflags (vxlan_gbp0);
300 vnet_buffer2 (b0)->gbp.src_epg =
301 vxlan_gbp_get_sclass (vxlan_gbp0);
303 /* Required to make the l2 tag push / pop code work on l2 subifs */
304 if (PREDICT_TRUE (next0 == VXLAN_GBP_INPUT_NEXT_L2_INPUT))
305 vnet_update_l2_len (b0);
307 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
308 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
309 vlib_increment_combined_counter
310 (rx_counter, thread_index, stats_t0->sw_if_index, 1, len0);
314 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
316 (t1 == 0 || flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
318 next1 = VXLAN_GBP_INPUT_NEXT_DROP;
321 && flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
323 error1 = VXLAN_GBP_ERROR_BAD_FLAGS;
324 vlib_increment_combined_counter
325 (drop_counter, thread_index, stats_t1->sw_if_index, 1,
329 error1 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
330 b1->error = node->errors[error1];
334 next1 = t1->decap_next_index;
335 vnet_buffer2 (b1)->gbp.flags =
336 vxlan_gbp_get_gpflags (vxlan_gbp1);
337 vnet_buffer2 (b1)->gbp.src_epg =
338 vxlan_gbp_get_sclass (vxlan_gbp1);
340 /* Required to make the l2 tag push / pop code work on l2 subifs */
341 if (PREDICT_TRUE (next1 == VXLAN_GBP_INPUT_NEXT_L2_INPUT))
342 vnet_update_l2_len (b1);
344 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
345 vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
348 vlib_increment_combined_counter
349 (rx_counter, thread_index, stats_t1->sw_if_index, 1, len1);
352 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
354 vxlan_gbp_rx_trace_t *tr =
355 vlib_add_trace (vm, node, b0, sizeof (*tr));
356 tr->next_index = next0;
358 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
359 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
360 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
362 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
364 vxlan_gbp_rx_trace_t *tr =
365 vlib_add_trace (vm, node, b1, sizeof (*tr));
366 tr->next_index = next1;
368 tr->tunnel_index = t1 == 0 ? ~0 : t1 - vxm->tunnels;
369 tr->vni = vxlan_gbp_get_vni (vxlan_gbp1);
370 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp1);
373 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
374 to_next, n_left_to_next,
375 bi0, bi1, next0, next1);
378 while (n_left_from > 0 && n_left_to_next > 0)
380 u32 bi0 = to_next[0] = from[0];
386 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
388 /* udp leaves current_data pointing at the vxlan_gbp header */
389 void *cur0 = vlib_buffer_get_current (b0);
390 vxlan_gbp_header_t *vxlan_gbp0 = cur0;
394 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
396 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
398 /* pop (ip, udp, vxlan_gbp) */
399 vlib_buffer_advance (b0, sizeof (*vxlan_gbp0));
401 u32 fi0 = buf_fib_index (b0, is_ip4);
403 vxlan_gbp_tunnel_t *t0, *stats_t0 = 0;
406 vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0,
410 vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0,
413 uword len0 = vlib_buffer_length_in_chain (vm, b0);
417 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
418 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
420 (t0 == 0 || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
422 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
425 && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
427 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
428 vlib_increment_combined_counter
429 (drop_counter, thread_index, stats_t0->sw_if_index, 1,
433 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
434 b0->error = node->errors[error0];
438 next0 = t0->decap_next_index;
439 vnet_buffer2 (b0)->gbp.flags =
440 vxlan_gbp_get_gpflags (vxlan_gbp0);
441 vnet_buffer2 (b0)->gbp.src_epg =
442 vxlan_gbp_get_sclass (vxlan_gbp0);
445 /* Required to make the l2 tag push / pop code work on l2 subifs */
446 if (PREDICT_TRUE (next0 == VXLAN_GBP_INPUT_NEXT_L2_INPUT))
447 vnet_update_l2_len (b0);
449 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
450 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
453 vlib_increment_combined_counter
454 (rx_counter, thread_index, stats_t0->sw_if_index, 1, len0);
457 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
459 vxlan_gbp_rx_trace_t *tr
460 = vlib_add_trace (vm, node, b0, sizeof (*tr));
461 tr->next_index = next0;
463 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
464 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
465 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
467 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
468 to_next, n_left_to_next,
472 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
474 /* Do we still need this now that tunnel tx stats is kept? */
476 is_ip4 ? vxlan4_gbp_input_node.index : vxlan6_gbp_input_node.index;
477 vlib_node_increment_counter (vm, node_idx, VXLAN_GBP_ERROR_DECAPSULATED,
480 return from_frame->n_vectors;
484 vxlan4_gbp_input (vlib_main_t * vm,
485 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
487 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 1);
491 vxlan6_gbp_input (vlib_main_t * vm,
492 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
494 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 0);
497 static char *vxlan_gbp_error_strings[] = {
498 #define vxlan_gbp_error(n,s) s,
499 #include <vnet/vxlan-gbp/vxlan_gbp_error.def>
500 #undef vxlan_gbp_error
505 VLIB_REGISTER_NODE (vxlan4_gbp_input_node) =
507 .function = vxlan4_gbp_input,
508 .name = "vxlan4-gbp-input",
509 .vector_size = sizeof (u32),
510 .n_errors = VXLAN_GBP_N_ERROR,
511 .error_strings = vxlan_gbp_error_strings,
512 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
513 .format_trace = format_vxlan_gbp_rx_trace,
515 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
516 foreach_vxlan_gbp_input_next
520 VLIB_NODE_FUNCTION_MULTIARCH (vxlan4_gbp_input_node, vxlan4_gbp_input)
522 VLIB_REGISTER_NODE (vxlan6_gbp_input_node) =
524 .function = vxlan6_gbp_input,
525 .name = "vxlan6-gbp-input",
526 .vector_size = sizeof (u32),
527 .n_errors = VXLAN_GBP_N_ERROR,
528 .error_strings = vxlan_gbp_error_strings,
529 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
531 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
532 foreach_vxlan_gbp_input_next
535 .format_trace = format_vxlan_gbp_rx_trace,
537 VLIB_NODE_FUNCTION_MULTIARCH (vxlan6_gbp_input_node, vxlan6_gbp_input)
542 IP_VXLAN_GBP_BYPASS_NEXT_DROP,
543 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP,
544 IP_VXLAN_GBP_BYPASS_N_NEXT,
545 } ip_vxan_gbp_bypass_next_t;
548 ip_vxlan_gbp_bypass_inline (vlib_main_t * vm,
549 vlib_node_runtime_t * node,
550 vlib_frame_t * frame, u32 is_ip4)
552 vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
553 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
554 vlib_node_runtime_t *error_node =
555 vlib_node_get_runtime (vm, ip4_input_node.index);
556 ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */
557 ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */
559 from = vlib_frame_vector_args (frame);
560 n_left_from = frame->n_vectors;
561 next_index = node->cached_next_index;
563 if (node->flags & VLIB_NODE_FLAG_TRACE)
564 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
569 ip6_address_set_zero (&addr6);
571 while (n_left_from > 0)
573 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
575 while (n_left_from >= 4 && n_left_to_next >= 2)
577 vlib_buffer_t *b0, *b1;
578 ip4_header_t *ip40, *ip41;
579 ip6_header_t *ip60, *ip61;
580 udp_header_t *udp0, *udp1;
581 u32 bi0, ip_len0, udp_len0, flags0, next0;
582 u32 bi1, ip_len1, udp_len1, flags1, next1;
583 i32 len_diff0, len_diff1;
584 u8 error0, good_udp0, proto0;
585 u8 error1, good_udp1, proto1;
587 /* Prefetch next iteration. */
589 vlib_buffer_t *p2, *p3;
591 p2 = vlib_get_buffer (vm, from[2]);
592 p3 = vlib_get_buffer (vm, from[3]);
594 vlib_prefetch_buffer_header (p2, LOAD);
595 vlib_prefetch_buffer_header (p3, LOAD);
597 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
598 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
601 bi0 = to_next[0] = from[0];
602 bi1 = to_next[1] = from[1];
608 b0 = vlib_get_buffer (vm, bi0);
609 b1 = vlib_get_buffer (vm, bi1);
612 ip40 = vlib_buffer_get_current (b0);
613 ip41 = vlib_buffer_get_current (b1);
617 ip60 = vlib_buffer_get_current (b0);
618 ip61 = vlib_buffer_get_current (b1);
621 /* Setup packet for next IP feature */
622 vnet_feature_next (&next0, b0);
623 vnet_feature_next (&next1, b1);
627 /* Treat IP frag packets as "experimental" protocol for now
628 until support of IP frag reassembly is implemented */
629 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
630 proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
634 proto0 = ip60->protocol;
635 proto1 = ip61->protocol;
638 /* Process packet 0 */
639 if (proto0 != IP_PROTOCOL_UDP)
640 goto exit0; /* not UDP packet */
643 udp0 = ip4_next_header (ip40);
645 udp0 = ip6_next_header (ip60);
647 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
648 goto exit0; /* not VXLAN_GBP packet */
650 /* Validate DIP against VTEPs */
653 if (addr4.as_u32 != ip40->dst_address.as_u32)
655 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
656 goto exit0; /* no local VTEP for VXLAN_GBP packet */
657 addr4 = ip40->dst_address;
662 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
664 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
665 goto exit0; /* no local VTEP for VXLAN_GBP packet */
666 addr6 = ip60->dst_address;
671 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
673 /* Don't verify UDP checksum for packets with explicit zero checksum. */
674 good_udp0 |= udp0->checksum == 0;
676 /* Verify UDP length */
678 ip_len0 = clib_net_to_host_u16 (ip40->length);
680 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
681 udp_len0 = clib_net_to_host_u16 (udp0->length);
682 len_diff0 = ip_len0 - udp_len0;
684 /* Verify UDP checksum */
685 if (PREDICT_FALSE (!good_udp0))
687 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
690 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
692 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
694 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
700 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
701 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
705 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
706 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
710 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
711 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
712 b0->error = error0 ? error_node->errors[error0] : 0;
714 /* vxlan-gbp-input node expect current at VXLAN_GBP header */
716 vlib_buffer_advance (b0,
717 sizeof (ip4_header_t) +
718 sizeof (udp_header_t));
720 vlib_buffer_advance (b0,
721 sizeof (ip6_header_t) +
722 sizeof (udp_header_t));
725 /* Process packet 1 */
726 if (proto1 != IP_PROTOCOL_UDP)
727 goto exit1; /* not UDP packet */
730 udp1 = ip4_next_header (ip41);
732 udp1 = ip6_next_header (ip61);
734 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
735 goto exit1; /* not VXLAN_GBP packet */
737 /* Validate DIP against VTEPs */
740 if (addr4.as_u32 != ip41->dst_address.as_u32)
742 if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32))
743 goto exit1; /* no local VTEP for VXLAN_GBP packet */
744 addr4 = ip41->dst_address;
749 if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
751 if (!hash_get_mem (vxm->vtep6, &ip61->dst_address))
752 goto exit1; /* no local VTEP for VXLAN_GBP packet */
753 addr6 = ip61->dst_address;
758 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
760 /* Don't verify UDP checksum for packets with explicit zero checksum. */
761 good_udp1 |= udp1->checksum == 0;
763 /* Verify UDP length */
765 ip_len1 = clib_net_to_host_u16 (ip41->length);
767 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
768 udp_len1 = clib_net_to_host_u16 (udp1->length);
769 len_diff1 = ip_len1 - udp_len1;
771 /* Verify UDP checksum */
772 if (PREDICT_FALSE (!good_udp1))
774 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
777 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
779 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
781 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
787 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
788 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
792 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
793 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
797 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
798 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
799 b1->error = error1 ? error_node->errors[error1] : 0;
801 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
803 vlib_buffer_advance (b1,
804 sizeof (ip4_header_t) +
805 sizeof (udp_header_t));
807 vlib_buffer_advance (b1,
808 sizeof (ip6_header_t) +
809 sizeof (udp_header_t));
812 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
813 to_next, n_left_to_next,
814 bi0, bi1, next0, next1);
817 while (n_left_from > 0 && n_left_to_next > 0)
823 u32 bi0, ip_len0, udp_len0, flags0, next0;
825 u8 error0, good_udp0, proto0;
827 bi0 = to_next[0] = from[0];
833 b0 = vlib_get_buffer (vm, bi0);
835 ip40 = vlib_buffer_get_current (b0);
837 ip60 = vlib_buffer_get_current (b0);
839 /* Setup packet for next IP feature */
840 vnet_feature_next (&next0, b0);
843 /* Treat IP4 frag packets as "experimental" protocol for now
844 until support of IP frag reassembly is implemented */
845 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
847 proto0 = ip60->protocol;
849 if (proto0 != IP_PROTOCOL_UDP)
850 goto exit; /* not UDP packet */
853 udp0 = ip4_next_header (ip40);
855 udp0 = ip6_next_header (ip60);
857 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
858 goto exit; /* not VXLAN_GBP packet */
860 /* Validate DIP against VTEPs */
863 if (addr4.as_u32 != ip40->dst_address.as_u32)
865 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
866 goto exit; /* no local VTEP for VXLAN_GBP packet */
867 addr4 = ip40->dst_address;
872 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
874 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
875 goto exit; /* no local VTEP for VXLAN_GBP packet */
876 addr6 = ip60->dst_address;
881 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
883 /* Don't verify UDP checksum for packets with explicit zero checksum. */
884 good_udp0 |= udp0->checksum == 0;
886 /* Verify UDP length */
888 ip_len0 = clib_net_to_host_u16 (ip40->length);
890 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
891 udp_len0 = clib_net_to_host_u16 (udp0->length);
892 len_diff0 = ip_len0 - udp_len0;
894 /* Verify UDP checksum */
895 if (PREDICT_FALSE (!good_udp0))
897 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
900 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
902 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
904 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
910 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
911 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
915 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
916 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
920 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
921 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
922 b0->error = error0 ? error_node->errors[error0] : 0;
924 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
926 vlib_buffer_advance (b0,
927 sizeof (ip4_header_t) +
928 sizeof (udp_header_t));
930 vlib_buffer_advance (b0,
931 sizeof (ip6_header_t) +
932 sizeof (udp_header_t));
935 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
936 to_next, n_left_to_next,
940 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
943 return frame->n_vectors;
947 ip4_vxlan_gbp_bypass (vlib_main_t * vm,
948 vlib_node_runtime_t * node, vlib_frame_t * frame)
950 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
954 VLIB_REGISTER_NODE (ip4_vxlan_gbp_bypass_node) =
956 .function = ip4_vxlan_gbp_bypass,
957 .name = "ip4-vxlan-gbp-bypass",
958 .vector_size = sizeof (u32),
959 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
961 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
962 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan4-gbp-input",
964 .format_buffer = format_ip4_header,
965 .format_trace = format_ip4_forward_next_trace,
968 VLIB_NODE_FUNCTION_MULTIARCH (ip4_vxlan_gbp_bypass_node, ip4_vxlan_gbp_bypass)
971 /* Dummy init function to get us linked in. */
973 ip4_vxlan_gbp_bypass_init (vlib_main_t * vm)
978 VLIB_INIT_FUNCTION (ip4_vxlan_gbp_bypass_init);
981 ip6_vxlan_gbp_bypass (vlib_main_t * vm,
982 vlib_node_runtime_t * node, vlib_frame_t * frame)
984 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
988 VLIB_REGISTER_NODE (ip6_vxlan_gbp_bypass_node) =
990 .function = ip6_vxlan_gbp_bypass,
991 .name = "ip6-vxlan-gbp-bypass",
992 .vector_size = sizeof (u32),
993 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
995 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
996 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan6-gbp-input",
998 .format_buffer = format_ip6_header,
999 .format_trace = format_ip6_forward_next_trace,
1002 VLIB_NODE_FUNCTION_MULTIARCH (ip6_vxlan_gbp_bypass_node, ip6_vxlan_gbp_bypass)
1005 /* Dummy init function to get us linked in. */
1007 ip6_vxlan_gbp_bypass_init (vlib_main_t * vm)
1012 VLIB_INIT_FUNCTION (ip6_vxlan_gbp_bypass_init);
1015 * fd.io coding-style-patch-verification: ON
1018 * eval: (c-set-style "gnu")