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;
33 } vxlan_gbp_rx_trace_t;
36 format_vxlan_gbp_rx_trace (u8 * s, va_list * args)
38 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
39 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
40 vxlan_gbp_rx_trace_t *t = va_arg (*args, vxlan_gbp_rx_trace_t *);
42 if (t->tunnel_index == ~0)
44 "VXLAN_GBP decap error - tunnel for vni %d does not exist",
47 "VXLAN_GBP decap from vxlan_gbp_tunnel%d vni %d sclass %d"
48 " flags %U next %d error %d",
49 t->tunnel_index, t->vni, t->sclass,
50 format_vxlan_gbp_header_gpflags, t->flags,
51 t->next_index, t->error);
55 buf_fib_index (vlib_buffer_t * b, u32 is_ip4)
57 u32 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
58 if (sw_if_index != (u32) ~ 0)
61 u32 *fib_index_by_sw_if_index = is_ip4 ?
62 ip4_main.fib_index_by_sw_if_index : ip6_main.fib_index_by_sw_if_index;
63 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
65 return vec_elt (fib_index_by_sw_if_index, sw_if_index);
68 typedef vxlan4_gbp_tunnel_key_t last_tunnel_cache4;
70 always_inline vxlan_gbp_tunnel_t *
71 vxlan4_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache4 * cache,
72 u32 fib_index, ip4_header_t * ip4_0,
73 vxlan_gbp_header_t * vxlan_gbp0,
74 vxlan_gbp_tunnel_t ** stats_t0)
76 /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */
77 vxlan4_gbp_tunnel_key_t key4;
78 key4.key[1] = ((u64) fib_index << 32) | vxlan_gbp0->vni_reserved;
80 if (PREDICT_FALSE (key4.key[1] != cache->key[1] ||
81 ip4_0->src_address.as_u32 != (u32) cache->key[0]))
83 key4.key[0] = ip4_0->src_address.as_u32;
84 int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key,
86 if (PREDICT_FALSE (rv != 0))
91 vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
93 /* Validate VXLAN_GBP tunnel SIP against packet DIP */
94 if (PREDICT_TRUE (ip4_0->dst_address.as_u32 == t0->src.ip4.as_u32))
99 if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address)))
102 key4.key[0] = ip4_0->dst_address.as_u32;
103 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
104 int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key,
106 if (PREDICT_FALSE (rv != 0))
109 *stats_t0 = 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,
121 vxlan_gbp_tunnel_t ** stats_t0)
123 /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */
124 vxlan6_gbp_tunnel_key_t key6 = {
126 [0] = ip6_0->src_address.as_u64[0],
127 [1] = ip6_0->src_address.as_u64[1],
128 [2] = (((u64) fib_index) << 32) | vxlan_gbp0->vni_reserved,
133 (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0))
135 int rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
137 if (PREDICT_FALSE (rv != 0))
142 vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value);
144 /* Validate VXLAN_GBP tunnel SIP against packet DIP */
145 if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6)))
150 if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address)))
153 /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */
154 key6.key[0] = ip6_0->dst_address.as_u64[0];
155 key6.key[1] = ip6_0->dst_address.as_u64[1];
156 int rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key,
158 if (PREDICT_FALSE (rv != 0))
161 *stats_t0 = pool_elt_at_index (vxm->tunnels, key6.value);
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, *stats_t0 = 0;
273 vxlan_gbp_tunnel_t *t1, *stats_t1 = 0;
277 vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0,
280 vxlan4_gbp_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan_gbp1,
286 vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0,
289 vxlan6_gbp_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan_gbp1,
293 u32 len0 = vlib_buffer_length_in_chain (vm, b0);
294 u32 len1 = vlib_buffer_length_in_chain (vm, b1);
296 vxlan_gbp_input_next_t next0, next1;
297 u8 error0 = 0, error1 = 0;
298 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
299 u8 flags1 = vxlan_gbp_get_flags (vxlan_gbp1);
300 /* Required to make the l2 tag push / pop code work on l2 subifs */
302 vlib_buffer_advance (b0, sizeof *vxlan_gbp0);
303 vlib_buffer_advance (b1, sizeof *vxlan_gbp1);
305 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
307 (t0 == 0 || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
310 && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
312 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
313 vlib_increment_combined_counter
314 (drop_counter, thread_index, stats_t0->sw_if_index, 1,
316 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
320 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
321 next0 = VXLAN_GBP_INPUT_NEXT_NO_TUNNEL;
323 b0->error = node->errors[error0];
327 next0 = vxlan_gbp_tunnel_get_next (t0, b0);
329 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
330 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
331 vlib_increment_combined_counter
332 (rx_counter, thread_index, stats_t0->sw_if_index, 1, len0);
336 vnet_buffer2 (b0)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
337 vnet_buffer2 (b0)->gbp.src_epg = vxlan_gbp_get_sclass (vxlan_gbp0);
341 (t1 == 0 || flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
344 && flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
346 error1 = VXLAN_GBP_ERROR_BAD_FLAGS;
347 vlib_increment_combined_counter
348 (drop_counter, thread_index, stats_t1->sw_if_index, 1,
350 next1 = VXLAN_GBP_INPUT_NEXT_DROP;
354 error1 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
355 next1 = VXLAN_GBP_INPUT_NEXT_NO_TUNNEL;
357 b1->error = node->errors[error1];
361 next1 = vxlan_gbp_tunnel_get_next (t1, b1);
363 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
364 vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
367 vlib_increment_combined_counter
368 (rx_counter, thread_index, stats_t1->sw_if_index, 1, len1);
371 vnet_buffer2 (b1)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp1);
372 vnet_buffer2 (b1)->gbp.src_epg = vxlan_gbp_get_sclass (vxlan_gbp1);
374 vnet_update_l2_len (b0);
375 vnet_update_l2_len (b1);
377 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
379 vxlan_gbp_rx_trace_t *tr =
380 vlib_add_trace (vm, node, b0, sizeof (*tr));
381 tr->next_index = next0;
383 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
384 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
385 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
386 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
388 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
390 vxlan_gbp_rx_trace_t *tr =
391 vlib_add_trace (vm, node, b1, sizeof (*tr));
392 tr->next_index = next1;
394 tr->tunnel_index = t1 == 0 ? ~0 : t1 - vxm->tunnels;
395 tr->vni = vxlan_gbp_get_vni (vxlan_gbp1);
396 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp1);
397 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
400 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
401 to_next, n_left_to_next,
402 bi0, bi1, next0, next1);
405 while (n_left_from > 0 && n_left_to_next > 0)
407 u32 bi0 = to_next[0] = from[0];
413 vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
415 /* udp leaves current_data pointing at the vxlan_gbp header */
416 void *cur0 = vlib_buffer_get_current (b0);
417 vxlan_gbp_header_t *vxlan_gbp0 = cur0;
421 ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t);
423 ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t);
425 u32 fi0 = buf_fib_index (b0, is_ip4);
427 vxlan_gbp_tunnel_t *t0, *stats_t0 = 0;
430 vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0,
434 vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0,
437 uword len0 = vlib_buffer_length_in_chain (vm, b0);
439 vxlan_gbp_input_next_t next0;
441 u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0);
443 /* pop (ip, udp, vxlan_gbp) */
444 vlib_buffer_advance (b0, sizeof (*vxlan_gbp0));
445 /* Validate VXLAN_GBP tunnel encap-fib index against packet */
447 (t0 == 0 || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)))
450 && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))
452 error0 = VXLAN_GBP_ERROR_BAD_FLAGS;
453 vlib_increment_combined_counter
454 (drop_counter, thread_index, stats_t0->sw_if_index, 1,
456 next0 = VXLAN_GBP_INPUT_NEXT_DROP;
460 error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL;
461 next0 = VXLAN_GBP_INPUT_NEXT_NO_TUNNEL;
463 b0->error = node->errors[error0];
467 next0 = vxlan_gbp_tunnel_get_next (t0, b0);
468 /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */
469 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
472 vlib_increment_combined_counter
473 (rx_counter, thread_index, stats_t0->sw_if_index, 1, len0);
475 vnet_buffer2 (b0)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
476 vnet_buffer2 (b0)->gbp.src_epg = vxlan_gbp_get_sclass (vxlan_gbp0);
478 /* Required to make the l2 tag push / pop code work on l2 subifs */
479 vnet_update_l2_len (b0);
481 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
483 vxlan_gbp_rx_trace_t *tr
484 = vlib_add_trace (vm, node, b0, sizeof (*tr));
485 tr->next_index = next0;
487 tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels;
488 tr->vni = vxlan_gbp_get_vni (vxlan_gbp0);
489 tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0);
490 tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0);
492 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
493 to_next, n_left_to_next,
497 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
499 /* Do we still need this now that tunnel tx stats is kept? */
501 is_ip4 ? vxlan4_gbp_input_node.index : vxlan6_gbp_input_node.index;
502 vlib_node_increment_counter (vm, node_idx, VXLAN_GBP_ERROR_DECAPSULATED,
505 return from_frame->n_vectors;
509 vxlan4_gbp_input (vlib_main_t * vm,
510 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
512 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 1);
516 vxlan6_gbp_input (vlib_main_t * vm,
517 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
519 return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 0);
522 static char *vxlan_gbp_error_strings[] = {
523 #define vxlan_gbp_error(n,s) s,
524 #include <vnet/vxlan-gbp/vxlan_gbp_error.def>
525 #undef vxlan_gbp_error
530 VLIB_REGISTER_NODE (vxlan4_gbp_input_node) =
532 .function = vxlan4_gbp_input,
533 .name = "vxlan4-gbp-input",
534 .vector_size = sizeof (u32),
535 .n_errors = VXLAN_GBP_N_ERROR,
536 .error_strings = vxlan_gbp_error_strings,
537 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
538 .format_trace = format_vxlan_gbp_rx_trace,
540 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
541 foreach_vxlan_gbp_input_next
545 VLIB_NODE_FUNCTION_MULTIARCH (vxlan4_gbp_input_node, vxlan4_gbp_input)
547 VLIB_REGISTER_NODE (vxlan6_gbp_input_node) =
549 .function = vxlan6_gbp_input,
550 .name = "vxlan6-gbp-input",
551 .vector_size = sizeof (u32),
552 .n_errors = VXLAN_GBP_N_ERROR,
553 .error_strings = vxlan_gbp_error_strings,
554 .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT,
556 #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n,
557 foreach_vxlan_gbp_input_next
560 .format_trace = format_vxlan_gbp_rx_trace,
562 VLIB_NODE_FUNCTION_MULTIARCH (vxlan6_gbp_input_node, vxlan6_gbp_input)
567 IP_VXLAN_GBP_BYPASS_NEXT_DROP,
568 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP,
569 IP_VXLAN_GBP_BYPASS_N_NEXT,
570 } ip_vxan_gbp_bypass_next_t;
573 ip_vxlan_gbp_bypass_inline (vlib_main_t * vm,
574 vlib_node_runtime_t * node,
575 vlib_frame_t * frame, u32 is_ip4)
577 vxlan_gbp_main_t *vxm = &vxlan_gbp_main;
578 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
579 vlib_node_runtime_t *error_node =
580 vlib_node_get_runtime (vm, ip4_input_node.index);
581 ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */
582 ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */
584 from = vlib_frame_vector_args (frame);
585 n_left_from = frame->n_vectors;
586 next_index = node->cached_next_index;
588 if (node->flags & VLIB_NODE_FLAG_TRACE)
589 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
594 ip6_address_set_zero (&addr6);
596 while (n_left_from > 0)
598 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
600 while (n_left_from >= 4 && n_left_to_next >= 2)
602 vlib_buffer_t *b0, *b1;
603 ip4_header_t *ip40, *ip41;
604 ip6_header_t *ip60, *ip61;
605 udp_header_t *udp0, *udp1;
606 u32 bi0, ip_len0, udp_len0, flags0, next0;
607 u32 bi1, ip_len1, udp_len1, flags1, next1;
608 i32 len_diff0, len_diff1;
609 u8 error0, good_udp0, proto0;
610 u8 error1, good_udp1, proto1;
612 /* Prefetch next iteration. */
614 vlib_buffer_t *p2, *p3;
616 p2 = vlib_get_buffer (vm, from[2]);
617 p3 = vlib_get_buffer (vm, from[3]);
619 vlib_prefetch_buffer_header (p2, LOAD);
620 vlib_prefetch_buffer_header (p3, LOAD);
622 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
623 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
626 bi0 = to_next[0] = from[0];
627 bi1 = to_next[1] = from[1];
633 b0 = vlib_get_buffer (vm, bi0);
634 b1 = vlib_get_buffer (vm, bi1);
637 ip40 = vlib_buffer_get_current (b0);
638 ip41 = vlib_buffer_get_current (b1);
642 ip60 = vlib_buffer_get_current (b0);
643 ip61 = vlib_buffer_get_current (b1);
646 /* Setup packet for next IP feature */
647 vnet_feature_next (&next0, b0);
648 vnet_feature_next (&next1, b1);
652 /* Treat IP frag packets as "experimental" protocol for now
653 until support of IP frag reassembly is implemented */
654 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
655 proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol;
659 proto0 = ip60->protocol;
660 proto1 = ip61->protocol;
663 /* Process packet 0 */
664 if (proto0 != IP_PROTOCOL_UDP)
665 goto exit0; /* not UDP packet */
668 udp0 = ip4_next_header (ip40);
670 udp0 = ip6_next_header (ip60);
672 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
673 goto exit0; /* not VXLAN_GBP packet */
675 /* Validate DIP against VTEPs */
678 if (addr4.as_u32 != ip40->dst_address.as_u32)
680 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
681 goto exit0; /* no local VTEP for VXLAN_GBP packet */
682 addr4 = ip40->dst_address;
687 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
689 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
690 goto exit0; /* no local VTEP for VXLAN_GBP packet */
691 addr6 = ip60->dst_address;
696 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
698 /* Don't verify UDP checksum for packets with explicit zero checksum. */
699 good_udp0 |= udp0->checksum == 0;
701 /* Verify UDP length */
703 ip_len0 = clib_net_to_host_u16 (ip40->length);
705 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
706 udp_len0 = clib_net_to_host_u16 (udp0->length);
707 len_diff0 = ip_len0 - udp_len0;
709 /* Verify UDP checksum */
710 if (PREDICT_FALSE (!good_udp0))
712 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
715 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
717 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
719 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
725 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
726 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
730 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
731 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
735 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
736 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
737 b0->error = error0 ? error_node->errors[error0] : 0;
739 /* vxlan-gbp-input node expect current at VXLAN_GBP header */
741 vlib_buffer_advance (b0,
742 sizeof (ip4_header_t) +
743 sizeof (udp_header_t));
745 vlib_buffer_advance (b0,
746 sizeof (ip6_header_t) +
747 sizeof (udp_header_t));
750 /* Process packet 1 */
751 if (proto1 != IP_PROTOCOL_UDP)
752 goto exit1; /* not UDP packet */
755 udp1 = ip4_next_header (ip41);
757 udp1 = ip6_next_header (ip61);
759 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
760 goto exit1; /* not VXLAN_GBP packet */
762 /* Validate DIP against VTEPs */
765 if (addr4.as_u32 != ip41->dst_address.as_u32)
767 if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32))
768 goto exit1; /* no local VTEP for VXLAN_GBP packet */
769 addr4 = ip41->dst_address;
774 if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
776 if (!hash_get_mem (vxm->vtep6, &ip61->dst_address))
777 goto exit1; /* no local VTEP for VXLAN_GBP packet */
778 addr6 = ip61->dst_address;
783 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
785 /* Don't verify UDP checksum for packets with explicit zero checksum. */
786 good_udp1 |= udp1->checksum == 0;
788 /* Verify UDP length */
790 ip_len1 = clib_net_to_host_u16 (ip41->length);
792 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
793 udp_len1 = clib_net_to_host_u16 (udp1->length);
794 len_diff1 = ip_len1 - udp_len1;
796 /* Verify UDP checksum */
797 if (PREDICT_FALSE (!good_udp1))
799 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
802 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
804 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
806 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
812 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
813 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
817 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
818 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
822 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
823 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
824 b1->error = error1 ? error_node->errors[error1] : 0;
826 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
828 vlib_buffer_advance (b1,
829 sizeof (ip4_header_t) +
830 sizeof (udp_header_t));
832 vlib_buffer_advance (b1,
833 sizeof (ip6_header_t) +
834 sizeof (udp_header_t));
837 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
838 to_next, n_left_to_next,
839 bi0, bi1, next0, next1);
842 while (n_left_from > 0 && n_left_to_next > 0)
848 u32 bi0, ip_len0, udp_len0, flags0, next0;
850 u8 error0, good_udp0, proto0;
852 bi0 = to_next[0] = from[0];
858 b0 = vlib_get_buffer (vm, bi0);
860 ip40 = vlib_buffer_get_current (b0);
862 ip60 = vlib_buffer_get_current (b0);
864 /* Setup packet for next IP feature */
865 vnet_feature_next (&next0, b0);
868 /* Treat IP4 frag packets as "experimental" protocol for now
869 until support of IP frag reassembly is implemented */
870 proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol;
872 proto0 = ip60->protocol;
874 if (proto0 != IP_PROTOCOL_UDP)
875 goto exit; /* not UDP packet */
878 udp0 = ip4_next_header (ip40);
880 udp0 = ip6_next_header (ip60);
882 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp))
883 goto exit; /* not VXLAN_GBP packet */
885 /* Validate DIP against VTEPs */
888 if (addr4.as_u32 != ip40->dst_address.as_u32)
890 if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32))
891 goto exit; /* no local VTEP for VXLAN_GBP packet */
892 addr4 = ip40->dst_address;
897 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
899 if (!hash_get_mem (vxm->vtep6, &ip60->dst_address))
900 goto exit; /* no local VTEP for VXLAN_GBP packet */
901 addr6 = ip60->dst_address;
906 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
908 /* Don't verify UDP checksum for packets with explicit zero checksum. */
909 good_udp0 |= udp0->checksum == 0;
911 /* Verify UDP length */
913 ip_len0 = clib_net_to_host_u16 (ip40->length);
915 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
916 udp_len0 = clib_net_to_host_u16 (udp0->length);
917 len_diff0 = ip_len0 - udp_len0;
919 /* Verify UDP checksum */
920 if (PREDICT_FALSE (!good_udp0))
922 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
925 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
927 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
929 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
935 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
936 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
940 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
941 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
945 IP_VXLAN_GBP_BYPASS_NEXT_DROP :
946 IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP;
947 b0->error = error0 ? error_node->errors[error0] : 0;
949 /* vxlan_gbp-input node expect current at VXLAN_GBP header */
951 vlib_buffer_advance (b0,
952 sizeof (ip4_header_t) +
953 sizeof (udp_header_t));
955 vlib_buffer_advance (b0,
956 sizeof (ip6_header_t) +
957 sizeof (udp_header_t));
960 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
961 to_next, n_left_to_next,
965 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
968 return frame->n_vectors;
972 ip4_vxlan_gbp_bypass (vlib_main_t * vm,
973 vlib_node_runtime_t * node, vlib_frame_t * frame)
975 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
979 VLIB_REGISTER_NODE (ip4_vxlan_gbp_bypass_node) =
981 .function = ip4_vxlan_gbp_bypass,
982 .name = "ip4-vxlan-gbp-bypass",
983 .vector_size = sizeof (u32),
984 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
986 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
987 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan4-gbp-input",
989 .format_buffer = format_ip4_header,
990 .format_trace = format_ip4_forward_next_trace,
993 VLIB_NODE_FUNCTION_MULTIARCH (ip4_vxlan_gbp_bypass_node, ip4_vxlan_gbp_bypass)
996 /* Dummy init function to get us linked in. */
998 ip4_vxlan_gbp_bypass_init (vlib_main_t * vm)
1003 VLIB_INIT_FUNCTION (ip4_vxlan_gbp_bypass_init);
1006 ip6_vxlan_gbp_bypass (vlib_main_t * vm,
1007 vlib_node_runtime_t * node, vlib_frame_t * frame)
1009 return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
1013 VLIB_REGISTER_NODE (ip6_vxlan_gbp_bypass_node) =
1015 .function = ip6_vxlan_gbp_bypass,
1016 .name = "ip6-vxlan-gbp-bypass",
1017 .vector_size = sizeof (u32),
1018 .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT,
1020 [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop",
1021 [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan6-gbp-input",
1023 .format_buffer = format_ip6_header,
1024 .format_trace = format_ip6_forward_next_trace,
1027 VLIB_NODE_FUNCTION_MULTIARCH (ip6_vxlan_gbp_bypass_node, ip6_vxlan_gbp_bypass)
1030 /* Dummy init function to get us linked in. */
1032 ip6_vxlan_gbp_bypass_init (vlib_main_t * vm)
1037 VLIB_INIT_FUNCTION (ip6_vxlan_gbp_bypass_init);
1040 * fd.io coding-style-patch-verification: ON
1043 * eval: (c-set-style "gnu")