2 * decap.c - decapsulate VXLAN GPE
4 * Copyright (c) 2013 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.
19 * @brief Functions for decapsulating VXLAN GPE tunnels
23 #include <vlib/vlib.h>
24 #include <vnet/udp/udp_local.h>
25 #include <vnet/vxlan-gpe/vxlan_gpe.h>
28 * @brief Struct for VXLAN GPE decap packet tracing
36 } vxlan_gpe_rx_trace_t;
39 * @brief Tracing function for VXLAN GPE packet decapsulation
48 format_vxlan_gpe_rx_trace (u8 * s, va_list * args)
50 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
51 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
52 vxlan_gpe_rx_trace_t *t = va_arg (*args, vxlan_gpe_rx_trace_t *);
54 if (t->tunnel_index != ~0)
56 s = format (s, "VXLAN-GPE: tunnel %d next %d error %d", t->tunnel_index,
57 t->next_index, t->error);
61 s = format (s, "VXLAN-GPE: no tunnel next %d error %d\n", t->next_index,
68 * @brief Tracing function for VXLAN GPE packet decapsulation including length
77 format_vxlan_gpe_with_length (u8 * s, va_list * args)
79 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
80 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
87 vxlan4_gpe_tunnel_key_t key;
88 vxlan_gpe_decap_info_t val;
89 } vxlan4_gpe_tunnel_cache_t;
91 static const vxlan_gpe_decap_info_t decap_not_found = {
93 .next_index = VXLAN_GPE_INPUT_NEXT_DROP,
94 .error = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL
97 always_inline vxlan_gpe_decap_info_t
98 vxlan4_gpe_find_tunnel (vxlan_gpe_main_t *nngm,
99 vxlan4_gpe_tunnel_cache_t *cache,
100 ip4_vxlan_gpe_header_t *iuvn4_0)
102 /* Make sure VXLAN GPE tunnel exist according to packet S/D IP, UDP port and
104 vxlan4_gpe_tunnel_key_t key4 = {
105 .local = iuvn4_0->ip4.dst_address.as_u32,
106 .remote = iuvn4_0->ip4.src_address.as_u32,
107 .vni = iuvn4_0->vxlan.vni_res,
108 .port = (u32) iuvn4_0->udp.dst_port,
111 if (PREDICT_TRUE (key4.as_u64[0] == cache->key.as_u64[0] &&
112 key4.as_u64[1] == cache->key.as_u64[1]))
118 uword *p = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4);
119 if (PREDICT_TRUE (p != 0))
121 u32 next = (iuvn4_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
122 nngm->decap_next_node_list[iuvn4_0->vxlan.protocol] :
123 VXLAN_GPE_INPUT_NEXT_DROP;
125 cache->key.as_u64[0] = key4.as_u64[0];
126 cache->key.as_u64[1] = key4.as_u64[1];
128 cache->val.error = 0;
129 cache->val.tunnel_index = p[0];
130 cache->val.next_index = next;
135 return decap_not_found;
140 vxlan6_gpe_tunnel_key_t key;
141 vxlan_gpe_decap_info_t val;
142 } vxlan6_gpe_tunnel_cache_t;
144 always_inline vxlan_gpe_decap_info_t
145 vxlan6_gpe_find_tunnel (vxlan_gpe_main_t *nngm,
146 vxlan6_gpe_tunnel_cache_t *cache,
147 ip6_vxlan_gpe_header_t *iuvn6_0)
149 /* Make sure VXLAN GPE tunnel exist according to packet S/D IP, UDP port and
151 vxlan6_gpe_tunnel_key_t key6;
153 ip6_address_copy (&key6.local, &iuvn6_0->ip6.dst_address);
154 ip6_address_copy (&key6.remote, &iuvn6_0->ip6.src_address);
155 key6.vni = iuvn6_0->vxlan.vni_res;
156 key6.port = iuvn6_0->udp.dst_port;
158 if (PREDICT_TRUE (memcmp (&key6, &cache->key, sizeof (cache->key)) == 0))
164 uword *p = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6);
165 if (PREDICT_TRUE (p != 0))
167 u32 next = (iuvn6_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
168 nngm->decap_next_node_list[iuvn6_0->vxlan.protocol] :
169 VXLAN_GPE_INPUT_NEXT_DROP;
171 clib_memcpy_fast (&cache->key, &key6, sizeof (key6));
172 cache->val.error = 0;
173 cache->val.tunnel_index = p[0];
174 cache->val.next_index = next;
179 return decap_not_found;
183 * @brief Common processing for IPv4 and IPv6 VXLAN GPE decap dispatch functions
185 * It is worth noting that other than trivial UDP forwarding (transit), VXLAN GPE
186 * tunnels are "terminate local". This means that there is no "TX" interface for this
187 * decap case, so that field in the buffer_metadata can be "used for something else".
188 * The something else in this case is, for the IPv4/IPv6 inner-packet type case, the
189 * FIB index used to look up the inner-packet's adjacency.
191 * vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
198 * @return from_frame->n_vectors
202 vxlan_gpe_input (vlib_main_t * vm,
203 vlib_node_runtime_t * node,
204 vlib_frame_t * from_frame, u8 is_ip4)
206 u32 n_left_from, next_index, *from, *to_next;
207 vxlan_gpe_main_t *nngm = &vxlan_gpe_main;
208 vnet_main_t *vnm = nngm->vnet_main;
209 vnet_interface_main_t *im = &vnm->interface_main;
210 vxlan4_gpe_tunnel_cache_t last4;
211 vxlan6_gpe_tunnel_cache_t last6;
212 u32 pkts_decapsulated = 0;
213 u32 thread_index = vm->thread_index;
214 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
217 clib_memset (&last4, 0xff, sizeof (last4));
219 clib_memset (&last6, 0xff, sizeof (last6));
221 from = vlib_frame_vector_args (from_frame);
222 n_left_from = from_frame->n_vectors;
224 next_index = node->cached_next_index;
225 stats_sw_if_index = node->runtime_data[0];
226 stats_n_packets = stats_n_bytes = 0;
228 while (n_left_from > 0)
232 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
234 while (n_left_from >= 4 && n_left_to_next >= 2)
237 vlib_buffer_t *b0, *b1;
239 ip4_vxlan_gpe_header_t *iuvn4_0, *iuvn4_1;
240 ip6_vxlan_gpe_header_t *iuvn6_0, *iuvn6_1;
241 vxlan_gpe_decap_info_t di0, di1;
242 vxlan_gpe_tunnel_t *t0, *t1;
244 u32 sw_if_index0, sw_if_index1, len0, len1;
246 /* Prefetch next iteration. */
248 vlib_buffer_t *p2, *p3;
250 p2 = vlib_get_buffer (vm, from[2]);
251 p3 = vlib_get_buffer (vm, from[3]);
253 vlib_prefetch_buffer_header (p2, LOAD);
254 vlib_prefetch_buffer_header (p3, LOAD);
256 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
257 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
269 b0 = vlib_get_buffer (vm, bi0);
270 b1 = vlib_get_buffer (vm, bi1);
274 /* udp leaves current_data pointing at the vxlan-gpe header */
275 vlib_buffer_advance (b0,
276 -(word) (sizeof (udp_header_t) +
277 sizeof (ip4_header_t)));
278 vlib_buffer_advance (b1,
279 -(word) (sizeof (udp_header_t) +
280 sizeof (ip4_header_t)));
282 iuvn4_0 = vlib_buffer_get_current (b0);
283 iuvn4_1 = vlib_buffer_get_current (b1);
285 /* pop (ip, udp, vxlan) */
286 vlib_buffer_advance (b0, sizeof (*iuvn4_0));
287 vlib_buffer_advance (b1, sizeof (*iuvn4_1));
289 di0 = vxlan4_gpe_find_tunnel (nngm, &last4, iuvn4_0);
290 di1 = vxlan4_gpe_find_tunnel (nngm, &last4, iuvn4_1);
294 /* udp leaves current_data pointing at the vxlan-gpe header */
295 vlib_buffer_advance (b0,
296 -(word) (sizeof (udp_header_t) +
297 sizeof (ip6_header_t)));
298 vlib_buffer_advance (b1,
299 -(word) (sizeof (udp_header_t) +
300 sizeof (ip6_header_t)));
302 iuvn6_0 = vlib_buffer_get_current (b0);
303 iuvn6_1 = vlib_buffer_get_current (b1);
305 /* pop (ip, udp, vxlan) */
306 vlib_buffer_advance (b0, sizeof (*iuvn6_0));
307 vlib_buffer_advance (b1, sizeof (*iuvn6_1));
309 di0 = vxlan6_gpe_find_tunnel (nngm, &last6, iuvn6_0);
310 di1 = vxlan6_gpe_find_tunnel (nngm, &last6, iuvn6_1);
313 /* Process packet 0 */
314 next0 = di0.next_index;
321 t0 = pool_elt_at_index (nngm->tunnels, di0.tunnel_index);
323 sw_if_index0 = t0->sw_if_index;
324 len0 = vlib_buffer_length_in_chain (vm, b0);
326 /* Required to make the l2 tag push / pop code work on l2 subifs */
327 vnet_update_l2_len (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;
333 * ip[46] lookup in the configured FIB
335 vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
338 stats_n_packets += 1;
339 stats_n_bytes += len0;
341 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
343 stats_n_packets -= 1;
344 stats_n_bytes -= len0;
346 vlib_increment_combined_counter (im->combined_sw_if_counters +
347 VNET_INTERFACE_COUNTER_RX,
353 stats_n_bytes = len0;
354 stats_sw_if_index = sw_if_index0;
357 trace0:b0->error = error0 ? node->errors[error0] : 0;
359 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
361 vxlan_gpe_rx_trace_t *tr =
362 vlib_add_trace (vm, node, b0, sizeof (*tr));
363 tr->next_index = next0;
365 tr->tunnel_index = di0.tunnel_index;
368 /* Process packet 1 */
369 next1 = di1.next_index;
376 t1 = pool_elt_at_index (nngm->tunnels, di1.tunnel_index);
378 sw_if_index1 = t1->sw_if_index;
379 len1 = vlib_buffer_length_in_chain (vm, b1);
381 /* Required to make the l2 tag push / pop code work on l2 subifs */
382 vnet_update_l2_len (b1);
384 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
385 vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
388 * ip[46] lookup in the configured FIB
390 vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index;
393 stats_n_packets += 1;
394 stats_n_bytes += len1;
396 /* Batch stats increment on the same vxlan tunnel so counter
397 is not incremented per packet */
398 if (PREDICT_FALSE (sw_if_index1 != stats_sw_if_index))
400 stats_n_packets -= 1;
401 stats_n_bytes -= len1;
403 vlib_increment_combined_counter (im->combined_sw_if_counters +
404 VNET_INTERFACE_COUNTER_RX,
410 stats_n_bytes = len1;
411 stats_sw_if_index = sw_if_index1;
413 vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index;
415 trace1:b1->error = error1 ? node->errors[error1] : 0;
417 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
419 vxlan_gpe_rx_trace_t *tr =
420 vlib_add_trace (vm, node, b1, sizeof (*tr));
421 tr->next_index = next1;
423 tr->tunnel_index = di1.tunnel_index;
426 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
427 n_left_to_next, bi0, bi1, next0,
431 while (n_left_from > 0 && n_left_to_next > 0)
436 ip4_vxlan_gpe_header_t *iuvn4_0;
437 ip6_vxlan_gpe_header_t *iuvn6_0;
438 vxlan_gpe_decap_info_t di0;
439 vxlan_gpe_tunnel_t *t0;
441 u32 sw_if_index0, len0;
450 b0 = vlib_get_buffer (vm, bi0);
454 /* udp leaves current_data pointing at the vxlan-gpe header */
455 vlib_buffer_advance (b0,
456 -(word) (sizeof (udp_header_t) +
457 sizeof (ip4_header_t)));
459 iuvn4_0 = vlib_buffer_get_current (b0);
461 /* pop (ip, udp, vxlan) */
462 vlib_buffer_advance (b0, sizeof (*iuvn4_0));
464 di0 = vxlan4_gpe_find_tunnel (nngm, &last4, iuvn4_0);
468 /* udp leaves current_data pointing at the vxlan-gpe header */
469 vlib_buffer_advance (b0,
470 -(word) (sizeof (udp_header_t) +
471 sizeof (ip6_header_t)));
473 iuvn6_0 = vlib_buffer_get_current (b0);
475 /* pop (ip, udp, vxlan) */
476 vlib_buffer_advance (b0, sizeof (*iuvn6_0));
478 di0 = vxlan6_gpe_find_tunnel (nngm, &last6, iuvn6_0);
481 next0 = di0.next_index;
488 t0 = pool_elt_at_index (nngm->tunnels, di0.tunnel_index);
490 sw_if_index0 = t0->sw_if_index;
491 len0 = vlib_buffer_length_in_chain (vm, b0);
493 /* Required to make the l2 tag push / pop code work on l2 subifs */
494 vnet_update_l2_len (b0);
496 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
497 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
500 * ip[46] lookup in the configured FIB
502 vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
505 stats_n_packets += 1;
506 stats_n_bytes += len0;
508 /* Batch stats increment on the same vxlan-gpe tunnel so counter
509 is not incremented per packet */
510 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
512 stats_n_packets -= 1;
513 stats_n_bytes -= len0;
515 vlib_increment_combined_counter (im->combined_sw_if_counters +
516 VNET_INTERFACE_COUNTER_RX,
522 stats_n_bytes = len0;
523 stats_sw_if_index = sw_if_index0;
526 trace00:b0->error = error0 ? node->errors[error0] : 0;
528 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
530 vxlan_gpe_rx_trace_t *tr =
531 vlib_add_trace (vm, node, b0, sizeof (*tr));
532 tr->next_index = next0;
534 tr->tunnel_index = di0.tunnel_index;
536 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
537 n_left_to_next, bi0, next0);
540 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
543 vlib_node_increment_counter (vm,
544 is_ip4 ? vxlan4_gpe_input_node.index :
545 vxlan6_gpe_input_node.index,
546 VXLAN_GPE_ERROR_DECAPSULATED,
549 /* Increment any remaining batch stats */
552 vlib_increment_combined_counter (im->combined_sw_if_counters +
553 VNET_INTERFACE_COUNTER_RX,
554 thread_index, stats_sw_if_index,
555 stats_n_packets, stats_n_bytes);
556 node->runtime_data[0] = stats_sw_if_index;
558 return from_frame->n_vectors;
562 * @brief Graph processing dispatch function for IPv4 VXLAN GPE
564 * @node vxlan4-gpe-input
569 * @return from_frame->n_vectors
572 VLIB_NODE_FN (vxlan4_gpe_input_node) (vlib_main_t * vm,
573 vlib_node_runtime_t * node,
574 vlib_frame_t * from_frame)
576 return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 1);
579 #ifndef CLIB_MARCH_VARIANT
581 vxlan_gpe_register_decap_protocol (u8 protocol_id, uword next_node_index)
583 vxlan_gpe_main_t *hm = &vxlan_gpe_main;
584 hm->decap_next_node_list[protocol_id] = next_node_index;
589 vxlan_gpe_unregister_decap_protocol (u8 protocol_id, uword next_node_index)
591 vxlan_gpe_main_t *hm = &vxlan_gpe_main;
592 hm->decap_next_node_list[protocol_id] = VXLAN_GPE_INPUT_NEXT_DROP;
595 #endif /* CLIB_MARCH_VARIANT */
598 * @brief Graph processing dispatch function for IPv6 VXLAN GPE
600 * @node vxlan6-gpe-input
605 * @return from_frame->n_vectors - uword
608 VLIB_NODE_FN (vxlan6_gpe_input_node) (vlib_main_t * vm,
609 vlib_node_runtime_t * node,
610 vlib_frame_t * from_frame)
612 return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 0);
616 * @brief VXLAN GPE error strings
618 static char *vxlan_gpe_error_strings[] = {
619 #define vxlan_gpe_error(n,s) s,
620 #include <vnet/vxlan-gpe/vxlan_gpe_error.def>
621 #undef vxlan_gpe_error
625 VLIB_REGISTER_NODE (vxlan4_gpe_input_node) = {
626 .name = "vxlan4-gpe-input",
627 /* Takes a vector of packets. */
628 .vector_size = sizeof (u32),
629 .type = VLIB_NODE_TYPE_INTERNAL,
630 .n_errors = ARRAY_LEN(vxlan_gpe_error_strings),
631 .error_strings = vxlan_gpe_error_strings,
633 .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT,
635 #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n,
636 foreach_vxlan_gpe_input_next
640 .format_buffer = format_vxlan_gpe_with_length,
641 .format_trace = format_vxlan_gpe_rx_trace,
642 // $$$$ .unformat_buffer = unformat_vxlan_gpe_header,
645 VLIB_REGISTER_NODE (vxlan6_gpe_input_node) = {
646 .name = "vxlan6-gpe-input",
647 /* Takes a vector of packets. */
648 .vector_size = sizeof (u32),
649 .type = VLIB_NODE_TYPE_INTERNAL,
650 .n_errors = ARRAY_LEN(vxlan_gpe_error_strings),
651 .error_strings = vxlan_gpe_error_strings,
653 .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT,
655 #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n,
656 foreach_vxlan_gpe_input_next
660 .format_buffer = format_vxlan_gpe_with_length,
661 .format_trace = format_vxlan_gpe_rx_trace,
662 // $$$$ .unformat_buffer = unformat_vxlan_gpe_header,
667 IP_VXLAN_BYPASS_NEXT_DROP,
668 IP_VXLAN_BYPASS_NEXT_VXLAN,
669 IP_VXLAN_BYPASS_N_NEXT,
670 } ip_vxlan_bypass_next_t;
673 ip_vxlan_gpe_bypass_inline (vlib_main_t * vm,
674 vlib_node_runtime_t * node,
675 vlib_frame_t * frame, u32 is_ip4)
677 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
678 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
679 vlib_node_runtime_t *error_node =
680 vlib_node_get_runtime (vm, ip4_input_node.index);
681 vtep4_key_t last_vtep4; /* last IPv4 address / fib index
682 matching a local VTEP address */
683 vtep6_key_t last_vtep6; /* last IPv6 address / fib index
684 matching a local VTEP address */
685 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
687 vxlan4_gpe_tunnel_cache_t last4;
688 vxlan6_gpe_tunnel_cache_t last6;
690 from = vlib_frame_vector_args (frame);
691 n_left_from = frame->n_vectors;
692 next_index = node->cached_next_index;
694 vlib_get_buffers (vm, from, bufs, n_left_from);
696 if (node->flags & VLIB_NODE_FLAG_TRACE)
697 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
701 vtep4_key_init (&last_vtep4);
702 clib_memset (&last4, 0xff, sizeof last4);
706 vtep6_key_init (&last_vtep6);
707 clib_memset (&last6, 0xff, sizeof last6);
710 while (n_left_from > 0)
712 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
714 while (n_left_from >= 4 && n_left_to_next >= 2)
716 vlib_buffer_t *b0, *b1;
717 ip4_header_t *ip40, *ip41;
718 ip6_header_t *ip60, *ip61;
719 udp_header_t *udp0, *udp1;
720 ip4_vxlan_gpe_header_t *iuvn4_0, *iuvn4_1;
721 ip6_vxlan_gpe_header_t *iuvn6_0, *iuvn6_1;
722 vxlan_gpe_decap_info_t di0, di1;
723 u32 bi0, ip_len0, udp_len0, flags0, next0;
724 u32 bi1, ip_len1, udp_len1, flags1, next1;
725 i32 len_diff0, len_diff1;
726 u8 error0, good_udp0, proto0;
727 u8 error1, good_udp1, proto1;
729 /* Prefetch next iteration. */
731 vlib_prefetch_buffer_header (b[2], LOAD);
732 vlib_prefetch_buffer_header (b[3], LOAD);
734 CLIB_PREFETCH (b[2]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
735 CLIB_PREFETCH (b[3]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
738 bi0 = to_next[0] = from[0];
739 bi1 = to_next[1] = from[1];
750 ip40 = vlib_buffer_get_current (b0);
751 ip41 = vlib_buffer_get_current (b1);
755 ip60 = vlib_buffer_get_current (b0);
756 ip61 = vlib_buffer_get_current (b1);
759 /* Setup packet for next IP feature */
760 vnet_feature_next (&next0, b0);
761 vnet_feature_next (&next1, b1);
765 proto0 = ip40->protocol;
766 proto1 = ip41->protocol;
770 proto0 = ip60->protocol;
771 proto1 = ip61->protocol;
774 /* Process packet 0 */
775 if (proto0 != IP_PROTOCOL_UDP)
776 goto exit0; /* not UDP packet */
780 udp0 = ip4_next_header (ip40);
781 iuvn4_0 = vlib_buffer_get_current (b0);
782 di0 = vxlan4_gpe_find_tunnel (ngm, &last4, iuvn4_0);
786 udp0 = ip6_next_header (ip60);
787 iuvn6_0 = vlib_buffer_get_current (b0);
788 di0 = vxlan6_gpe_find_tunnel (ngm, &last6, iuvn6_0);
791 if (PREDICT_FALSE (di0.tunnel_index == ~0))
792 goto exit0; /* unknown interface */
794 /* Validate DIP against VTEPs */
797 #ifdef CLIB_HAVE_VEC512
798 if (!vtep4_check_vector (&ngm->vtep_table, b0, ip40, &last_vtep4,
801 if (!vtep4_check (&ngm->vtep_table, b0, ip40, &last_vtep4))
803 goto exit0; /* no local VTEP for VXLAN packet */
807 if (!vtep6_check (&ngm->vtep_table, b0, ip60, &last_vtep6))
808 goto exit0; /* no local VTEP for VXLAN packet */
812 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
814 /* Don't verify UDP checksum for packets with explicit zero checksum. */
815 good_udp0 |= udp0->checksum == 0;
817 /* Verify UDP length */
819 ip_len0 = clib_net_to_host_u16 (ip40->length);
821 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
822 udp_len0 = clib_net_to_host_u16 (udp0->length);
823 len_diff0 = ip_len0 - udp_len0;
825 /* Verify UDP checksum */
826 if (PREDICT_FALSE (!good_udp0))
828 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
831 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
833 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
835 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
841 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
842 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
846 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
847 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
851 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
852 b0->error = error0 ? error_node->errors[error0] : 0;
854 /* vxlan_gpe-input node expect current at VXLAN header */
856 vlib_buffer_advance (b0,
857 sizeof (ip4_header_t) +
858 sizeof (udp_header_t));
860 vlib_buffer_advance (b0,
861 sizeof (ip6_header_t) +
862 sizeof (udp_header_t));
865 /* Process packet 1 */
866 if (proto1 != IP_PROTOCOL_UDP)
867 goto exit1; /* not UDP packet */
871 udp1 = ip4_next_header (ip41);
872 iuvn4_1 = vlib_buffer_get_current (b1);
873 di1 = vxlan4_gpe_find_tunnel (ngm, &last4, iuvn4_1);
877 udp1 = ip6_next_header (ip61);
878 iuvn6_1 = vlib_buffer_get_current (b1);
879 di1 = vxlan6_gpe_find_tunnel (ngm, &last6, iuvn6_1);
882 if (PREDICT_FALSE (di1.tunnel_index == ~0))
883 goto exit1; /* unknown interface */
885 /* Validate DIP against VTEPs */
888 #ifdef CLIB_HAVE_VEC512
889 if (!vtep4_check_vector (&ngm->vtep_table, b1, ip41, &last_vtep4,
892 if (!vtep4_check (&ngm->vtep_table, b1, ip41, &last_vtep4))
894 goto exit1; /* no local VTEP for VXLAN packet */
898 if (!vtep6_check (&ngm->vtep_table, b1, ip61, &last_vtep6))
899 goto exit1; /* no local VTEP for VXLAN packet */
903 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
905 /* Don't verify UDP checksum for packets with explicit zero checksum. */
906 good_udp1 |= udp1->checksum == 0;
908 /* Verify UDP length */
910 ip_len1 = clib_net_to_host_u16 (ip41->length);
912 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
913 udp_len1 = clib_net_to_host_u16 (udp1->length);
914 len_diff1 = ip_len1 - udp_len1;
916 /* Verify UDP checksum */
917 if (PREDICT_FALSE (!good_udp1))
919 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
922 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
924 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
926 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
932 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
933 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
937 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
938 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
942 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
943 b1->error = error1 ? error_node->errors[error1] : 0;
945 /* vxlan_gpe-input node expect current at VXLAN header */
947 vlib_buffer_advance (b1,
948 sizeof (ip4_header_t) +
949 sizeof (udp_header_t));
951 vlib_buffer_advance (b1,
952 sizeof (ip6_header_t) +
953 sizeof (udp_header_t));
956 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
957 to_next, n_left_to_next,
958 bi0, bi1, next0, next1);
961 while (n_left_from > 0 && n_left_to_next > 0)
967 ip4_vxlan_gpe_header_t *iuvn4_0;
968 ip6_vxlan_gpe_header_t *iuvn6_0;
969 vxlan_gpe_decap_info_t di0;
970 u32 bi0, ip_len0, udp_len0, flags0, next0;
972 u8 error0, good_udp0, proto0;
974 bi0 = to_next[0] = from[0];
983 ip40 = vlib_buffer_get_current (b0);
985 ip60 = vlib_buffer_get_current (b0);
987 /* Setup packet for next IP feature */
988 vnet_feature_next (&next0, b0);
991 proto0 = ip40->protocol;
993 proto0 = ip60->protocol;
995 if (proto0 != IP_PROTOCOL_UDP)
996 goto exit; /* not UDP packet */
1000 udp0 = ip4_next_header (ip40);
1001 iuvn4_0 = vlib_buffer_get_current (b0);
1002 di0 = vxlan4_gpe_find_tunnel (ngm, &last4, iuvn4_0);
1006 udp0 = ip6_next_header (ip60);
1007 iuvn6_0 = vlib_buffer_get_current (b0);
1008 di0 = vxlan6_gpe_find_tunnel (ngm, &last6, iuvn6_0);
1011 if (PREDICT_FALSE (di0.tunnel_index == ~0))
1012 goto exit; /* unknown interface */
1014 /* Validate DIP against VTEPs */
1018 #ifdef CLIB_HAVE_VEC512
1019 if (!vtep4_check_vector (&ngm->vtep_table, b0, ip40, &last_vtep4,
1022 if (!vtep4_check (&ngm->vtep_table, b0, ip40, &last_vtep4))
1024 goto exit; /* no local VTEP for VXLAN packet */
1028 if (!vtep6_check (&ngm->vtep_table, b0, ip60, &last_vtep6))
1029 goto exit; /* no local VTEP for VXLAN packet */
1033 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1035 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1036 good_udp0 |= udp0->checksum == 0;
1038 /* Verify UDP length */
1040 ip_len0 = clib_net_to_host_u16 (ip40->length);
1042 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
1043 udp_len0 = clib_net_to_host_u16 (udp0->length);
1044 len_diff0 = ip_len0 - udp_len0;
1046 /* Verify UDP checksum */
1047 if (PREDICT_FALSE (!good_udp0))
1049 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1052 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
1054 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
1056 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1062 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1063 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
1067 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1068 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
1072 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
1073 b0->error = error0 ? error_node->errors[error0] : 0;
1075 /* vxlan_gpe-input node expect current at VXLAN header */
1077 vlib_buffer_advance (b0,
1078 sizeof (ip4_header_t) +
1079 sizeof (udp_header_t));
1081 vlib_buffer_advance (b0,
1082 sizeof (ip6_header_t) +
1083 sizeof (udp_header_t));
1086 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1087 to_next, n_left_to_next,
1091 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1094 return frame->n_vectors;
1097 VLIB_NODE_FN (ip4_vxlan_gpe_bypass_node) (vlib_main_t * vm,
1098 vlib_node_runtime_t * node,
1099 vlib_frame_t * frame)
1101 return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
1104 VLIB_REGISTER_NODE (ip4_vxlan_gpe_bypass_node) = {
1105 .name = "ip4-vxlan-gpe-bypass",
1106 .vector_size = sizeof (u32),
1108 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
1110 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
1111 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan4-gpe-input",
1114 .format_buffer = format_ip4_header,
1115 .format_trace = format_ip4_forward_next_trace,
1118 #ifndef CLIB_MARCH_VARIANT
1119 /* Dummy init function to get us linked in. */
1121 ip4_vxlan_gpe_bypass_init (vlib_main_t * vm)
1126 VLIB_INIT_FUNCTION (ip4_vxlan_gpe_bypass_init);
1127 #endif /* CLIB_MARCH_VARIANT */
1129 VLIB_NODE_FN (ip6_vxlan_gpe_bypass_node) (vlib_main_t * vm,
1130 vlib_node_runtime_t * node,
1131 vlib_frame_t * frame)
1133 return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
1136 VLIB_REGISTER_NODE (ip6_vxlan_gpe_bypass_node) = {
1137 .name = "ip6-vxlan-gpe-bypass",
1138 .vector_size = sizeof (u32),
1140 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
1142 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
1143 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-gpe-input",
1146 .format_buffer = format_ip6_header,
1147 .format_trace = format_ip6_forward_next_trace,
1150 #ifndef CLIB_MARCH_VARIANT
1151 /* Dummy init function to get us linked in. */
1153 ip6_vxlan_gpe_bypass_init (vlib_main_t * vm)
1158 VLIB_INIT_FUNCTION (ip6_vxlan_gpe_bypass_init);
1159 #endif /* CLIB_MARCH_VARIANT */
1162 * fd.io coding-style-patch-verification: ON
1165 * eval: (c-set-style "gnu")