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/pg/pg.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 * @brief Common processing for IPv4 and IPv6 VXLAN GPE decap dispatch functions
89 * It is worth noting that other than trivial UDP forwarding (transit), VXLAN GPE
90 * tunnels are "terminate local". This means that there is no "TX" interface for this
91 * decap case, so that field in the buffer_metadata can be "used for something else".
92 * The something else in this case is, for the IPv4/IPv6 inner-packet type case, the
93 * FIB index used to look up the inner-packet's adjacency.
95 * vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
102 * @return from_frame->n_vectors
106 vxlan_gpe_input (vlib_main_t * vm,
107 vlib_node_runtime_t * node,
108 vlib_frame_t * from_frame, u8 is_ip4)
110 u32 n_left_from, next_index, *from, *to_next;
111 vxlan_gpe_main_t *nngm = &vxlan_gpe_main;
112 vnet_main_t *vnm = nngm->vnet_main;
113 vnet_interface_main_t *im = &vnm->interface_main;
114 u32 last_tunnel_index = ~0;
115 vxlan4_gpe_tunnel_key_t last_key4;
116 vxlan6_gpe_tunnel_key_t last_key6;
117 u32 pkts_decapsulated = 0;
118 u32 thread_index = vm->thread_index;
119 u32 stats_sw_if_index, stats_n_packets, stats_n_bytes;
122 clib_memset (&last_key4, 0xff, sizeof (last_key4));
124 clib_memset (&last_key6, 0xff, sizeof (last_key6));
126 from = vlib_frame_vector_args (from_frame);
127 n_left_from = from_frame->n_vectors;
129 next_index = node->cached_next_index;
130 stats_sw_if_index = node->runtime_data[0];
131 stats_n_packets = stats_n_bytes = 0;
133 while (n_left_from > 0)
137 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
139 while (n_left_from >= 4 && n_left_to_next >= 2)
142 vlib_buffer_t *b0, *b1;
144 ip4_vxlan_gpe_header_t *iuvn4_0, *iuvn4_1;
145 ip6_vxlan_gpe_header_t *iuvn6_0, *iuvn6_1;
147 u32 tunnel_index0, tunnel_index1;
148 vxlan_gpe_tunnel_t *t0, *t1;
149 vxlan4_gpe_tunnel_key_t key4_0, key4_1;
150 vxlan6_gpe_tunnel_key_t key6_0, key6_1;
152 u32 sw_if_index0, sw_if_index1, len0, len1;
154 /* Prefetch next iteration. */
156 vlib_buffer_t *p2, *p3;
158 p2 = vlib_get_buffer (vm, from[2]);
159 p3 = vlib_get_buffer (vm, from[3]);
161 vlib_prefetch_buffer_header (p2, LOAD);
162 vlib_prefetch_buffer_header (p3, LOAD);
164 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
165 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
177 b0 = vlib_get_buffer (vm, bi0);
178 b1 = vlib_get_buffer (vm, bi1);
182 /* udp leaves current_data pointing at the vxlan-gpe header */
183 vlib_buffer_advance (b0,
184 -(word) (sizeof (udp_header_t) +
185 sizeof (ip4_header_t)));
186 vlib_buffer_advance (b1,
187 -(word) (sizeof (udp_header_t) +
188 sizeof (ip4_header_t)));
190 iuvn4_0 = vlib_buffer_get_current (b0);
191 iuvn4_1 = vlib_buffer_get_current (b1);
193 /* pop (ip, udp, vxlan) */
194 vlib_buffer_advance (b0, sizeof (*iuvn4_0));
195 vlib_buffer_advance (b1, sizeof (*iuvn4_1));
199 /* udp leaves current_data pointing at the vxlan-gpe header */
200 vlib_buffer_advance (b0,
201 -(word) (sizeof (udp_header_t) +
202 sizeof (ip6_header_t)));
203 vlib_buffer_advance (b1,
204 -(word) (sizeof (udp_header_t) +
205 sizeof (ip6_header_t)));
207 iuvn6_0 = vlib_buffer_get_current (b0);
208 iuvn6_1 = vlib_buffer_get_current (b1);
210 /* pop (ip, udp, vxlan) */
211 vlib_buffer_advance (b0, sizeof (*iuvn6_0));
212 vlib_buffer_advance (b1, sizeof (*iuvn6_1));
223 (iuvn4_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
224 nngm->decap_next_node_list[iuvn4_0->vxlan.protocol] :
225 VXLAN_GPE_INPUT_NEXT_DROP;
227 (iuvn4_1->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
228 nngm->decap_next_node_list[iuvn4_1->vxlan.protocol] :
229 VXLAN_GPE_INPUT_NEXT_DROP;
231 key4_0.local = iuvn4_0->ip4.dst_address.as_u32;
232 key4_1.local = iuvn4_1->ip4.dst_address.as_u32;
234 key4_0.remote = iuvn4_0->ip4.src_address.as_u32;
235 key4_1.remote = iuvn4_1->ip4.src_address.as_u32;
237 key4_0.vni = iuvn4_0->vxlan.vni_res;
238 key4_1.vni = iuvn4_1->vxlan.vni_res;
245 next0 = (iuvn6_0->vxlan.protocol < node->n_next_nodes) ?
246 iuvn6_0->vxlan.protocol : VXLAN_GPE_INPUT_NEXT_DROP;
247 next1 = (iuvn6_1->vxlan.protocol < node->n_next_nodes) ?
248 iuvn6_1->vxlan.protocol : VXLAN_GPE_INPUT_NEXT_DROP;
250 key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0];
251 key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1];
252 key6_1.local.as_u64[0] = iuvn6_1->ip6.dst_address.as_u64[0];
253 key6_1.local.as_u64[1] = iuvn6_1->ip6.dst_address.as_u64[1];
255 key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0];
256 key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1];
257 key6_1.remote.as_u64[0] = iuvn6_1->ip6.src_address.as_u64[0];
258 key6_1.remote.as_u64[1] = iuvn6_1->ip6.src_address.as_u64[1];
260 key6_0.vni = iuvn6_0->vxlan.vni_res;
261 key6_1.vni = iuvn6_1->vxlan.vni_res;
264 /* Processing packet 0 */
267 /* Processing for key4_0 */
268 if (PREDICT_FALSE ((key4_0.as_u64[0] != last_key4.as_u64[0])
269 || (key4_0.as_u64[1] !=
270 last_key4.as_u64[1])))
272 p0 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_0);
276 error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
280 last_key4.as_u64[0] = key4_0.as_u64[0];
281 last_key4.as_u64[1] = key4_0.as_u64[1];
282 tunnel_index0 = last_tunnel_index = p0[0];
285 tunnel_index0 = last_tunnel_index;
290 (iuvn6_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
291 nngm->decap_next_node_list[iuvn6_0->vxlan.protocol] :
292 VXLAN_GPE_INPUT_NEXT_DROP;
294 (iuvn6_1->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
295 nngm->decap_next_node_list[iuvn6_1->vxlan.protocol] :
296 VXLAN_GPE_INPUT_NEXT_DROP;
298 key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0];
299 key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1];
300 key6_1.local.as_u64[0] = iuvn6_1->ip6.dst_address.as_u64[0];
301 key6_1.local.as_u64[1] = iuvn6_1->ip6.dst_address.as_u64[1];
303 key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0];
304 key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1];
305 key6_1.remote.as_u64[0] = iuvn6_1->ip6.src_address.as_u64[0];
306 key6_1.remote.as_u64[1] = iuvn6_1->ip6.src_address.as_u64[1];
308 key6_0.vni = iuvn6_0->vxlan.vni_res;
309 key6_1.vni = iuvn6_1->vxlan.vni_res;
311 /* Processing for key6_0 */
313 (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
315 p0 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_0);
319 error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
323 memcpy (&last_key6, &key6_0, sizeof (key6_0));
324 tunnel_index0 = last_tunnel_index = p0[0];
327 tunnel_index0 = last_tunnel_index;
330 t0 = pool_elt_at_index (nngm->tunnels, tunnel_index0);
333 sw_if_index0 = t0->sw_if_index;
334 len0 = vlib_buffer_length_in_chain (vm, b0);
336 /* Required to make the l2 tag push / pop code work on l2 subifs */
337 vnet_update_l2_len (b0);
339 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
340 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
343 * ip[46] lookup in the configured FIB
345 vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
348 stats_n_packets += 1;
349 stats_n_bytes += len0;
351 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
353 stats_n_packets -= 1;
354 stats_n_bytes -= len0;
356 vlib_increment_combined_counter (im->combined_sw_if_counters +
357 VNET_INTERFACE_COUNTER_RX,
363 stats_n_bytes = len0;
364 stats_sw_if_index = sw_if_index0;
367 trace0:b0->error = error0 ? node->errors[error0] : 0;
369 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
371 vxlan_gpe_rx_trace_t *tr =
372 vlib_add_trace (vm, node, b0, sizeof (*tr));
373 tr->next_index = next0;
375 tr->tunnel_index = tunnel_index0;
378 /* Process packet 1 */
381 /* Processing for key4_1 */
382 if (PREDICT_FALSE ((key4_1.as_u64[0] != last_key4.as_u64[0])
383 || (key4_1.as_u64[1] !=
384 last_key4.as_u64[1])))
386 p1 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_1);
390 error1 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
394 last_key4.as_u64[0] = key4_1.as_u64[0];
395 last_key4.as_u64[1] = key4_1.as_u64[1];
396 tunnel_index1 = last_tunnel_index = p1[0];
399 tunnel_index1 = last_tunnel_index;
403 /* Processing for key6_1 */
405 (memcmp (&key6_1, &last_key6, sizeof (last_key6)) != 0))
407 p1 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_1);
411 error1 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
415 memcpy (&last_key6, &key6_1, sizeof (key6_1));
416 tunnel_index1 = last_tunnel_index = p1[0];
419 tunnel_index1 = last_tunnel_index;
422 t1 = pool_elt_at_index (nngm->tunnels, tunnel_index1);
424 sw_if_index1 = t1->sw_if_index;
425 len1 = vlib_buffer_length_in_chain (vm, b1);
427 /* Required to make the l2 tag push / pop code work on l2 subifs */
428 vnet_update_l2_len (b1);
430 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
431 vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index;
434 * ip[46] lookup in the configured FIB
436 vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index;
439 stats_n_packets += 1;
440 stats_n_bytes += len1;
442 /* Batch stats increment on the same vxlan tunnel so counter
443 is not incremented per packet */
444 if (PREDICT_FALSE (sw_if_index1 != stats_sw_if_index))
446 stats_n_packets -= 1;
447 stats_n_bytes -= len1;
449 vlib_increment_combined_counter (im->combined_sw_if_counters +
450 VNET_INTERFACE_COUNTER_RX,
456 stats_n_bytes = len1;
457 stats_sw_if_index = sw_if_index1;
459 vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index;
461 trace1:b1->error = error1 ? node->errors[error1] : 0;
463 if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
465 vxlan_gpe_rx_trace_t *tr =
466 vlib_add_trace (vm, node, b1, sizeof (*tr));
467 tr->next_index = next1;
469 tr->tunnel_index = tunnel_index1;
472 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
473 n_left_to_next, bi0, bi1, next0,
477 while (n_left_from > 0 && n_left_to_next > 0)
482 ip4_vxlan_gpe_header_t *iuvn4_0;
483 ip6_vxlan_gpe_header_t *iuvn6_0;
486 vxlan_gpe_tunnel_t *t0;
487 vxlan4_gpe_tunnel_key_t key4_0;
488 vxlan6_gpe_tunnel_key_t key6_0;
490 u32 sw_if_index0, len0;
499 b0 = vlib_get_buffer (vm, bi0);
503 /* udp leaves current_data pointing at the vxlan-gpe header */
504 vlib_buffer_advance (b0,
505 -(word) (sizeof (udp_header_t) +
506 sizeof (ip4_header_t)));
508 iuvn4_0 = vlib_buffer_get_current (b0);
510 /* pop (ip, udp, vxlan) */
511 vlib_buffer_advance (b0, sizeof (*iuvn4_0));
515 /* udp leaves current_data pointing at the vxlan-gpe header */
516 vlib_buffer_advance (b0,
517 -(word) (sizeof (udp_header_t) +
518 sizeof (ip6_header_t)));
520 iuvn6_0 = vlib_buffer_get_current (b0);
522 /* pop (ip, udp, vxlan) */
523 vlib_buffer_advance (b0, sizeof (*iuvn6_0));
532 (iuvn4_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
533 nngm->decap_next_node_list[iuvn4_0->vxlan.protocol] :
534 VXLAN_GPE_INPUT_NEXT_DROP;
536 key4_0.local = iuvn4_0->ip4.dst_address.as_u32;
537 key4_0.remote = iuvn4_0->ip4.src_address.as_u32;
538 key4_0.vni = iuvn4_0->vxlan.vni_res;
541 /* Processing for key4_0 */
542 if (PREDICT_FALSE ((key4_0.as_u64[0] != last_key4.as_u64[0])
543 || (key4_0.as_u64[1] !=
544 last_key4.as_u64[1])))
546 p0 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_0);
550 error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
554 last_key4.as_u64[0] = key4_0.as_u64[0];
555 last_key4.as_u64[1] = key4_0.as_u64[1];
556 tunnel_index0 = last_tunnel_index = p0[0];
559 tunnel_index0 = last_tunnel_index;
564 (iuvn6_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ?
565 nngm->decap_next_node_list[iuvn6_0->vxlan.protocol] :
566 VXLAN_GPE_INPUT_NEXT_DROP;
568 key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0];
569 key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1];
570 key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0];
571 key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1];
572 key6_0.vni = iuvn6_0->vxlan.vni_res;
574 /* Processing for key6_0 */
576 (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0))
578 p0 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_0);
582 error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL;
586 memcpy (&last_key6, &key6_0, sizeof (key6_0));
587 tunnel_index0 = last_tunnel_index = p0[0];
590 tunnel_index0 = last_tunnel_index;
593 t0 = pool_elt_at_index (nngm->tunnels, tunnel_index0);
596 sw_if_index0 = t0->sw_if_index;
597 len0 = vlib_buffer_length_in_chain (vm, b0);
599 /* Required to make the l2 tag push / pop code work on l2 subifs */
600 vnet_update_l2_len (b0);
602 /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */
603 vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index;
606 * ip[46] lookup in the configured FIB
608 vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index;
611 stats_n_packets += 1;
612 stats_n_bytes += len0;
614 /* Batch stats increment on the same vxlan-gpe tunnel so counter
615 is not incremented per packet */
616 if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index))
618 stats_n_packets -= 1;
619 stats_n_bytes -= len0;
621 vlib_increment_combined_counter (im->combined_sw_if_counters +
622 VNET_INTERFACE_COUNTER_RX,
628 stats_n_bytes = len0;
629 stats_sw_if_index = sw_if_index0;
632 trace00:b0->error = error0 ? node->errors[error0] : 0;
634 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
636 vxlan_gpe_rx_trace_t *tr =
637 vlib_add_trace (vm, node, b0, sizeof (*tr));
638 tr->next_index = next0;
640 tr->tunnel_index = tunnel_index0;
642 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
643 n_left_to_next, bi0, next0);
646 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
649 vlib_node_increment_counter (vm,
650 is_ip4 ? vxlan4_gpe_input_node.index :
651 vxlan6_gpe_input_node.index,
652 VXLAN_GPE_ERROR_DECAPSULATED,
655 /* Increment any remaining batch stats */
658 vlib_increment_combined_counter (im->combined_sw_if_counters +
659 VNET_INTERFACE_COUNTER_RX,
660 thread_index, stats_sw_if_index,
661 stats_n_packets, stats_n_bytes);
662 node->runtime_data[0] = stats_sw_if_index;
664 return from_frame->n_vectors;
668 * @brief Graph processing dispatch function for IPv4 VXLAN GPE
670 * @node vxlan4-gpe-input
675 * @return from_frame->n_vectors
678 VLIB_NODE_FN (vxlan4_gpe_input_node) (vlib_main_t * vm,
679 vlib_node_runtime_t * node,
680 vlib_frame_t * from_frame)
682 return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 1);
685 #ifndef CLIB_MARCH_VARIANT
687 vxlan_gpe_register_decap_protocol (u8 protocol_id, uword next_node_index)
689 vxlan_gpe_main_t *hm = &vxlan_gpe_main;
690 hm->decap_next_node_list[protocol_id] = next_node_index;
695 vxlan_gpe_unregister_decap_protocol (u8 protocol_id, uword next_node_index)
697 vxlan_gpe_main_t *hm = &vxlan_gpe_main;
698 hm->decap_next_node_list[protocol_id] = VXLAN_GPE_INPUT_NEXT_DROP;
701 #endif /* CLIB_MARCH_VARIANT */
704 * @brief Graph processing dispatch function for IPv6 VXLAN GPE
706 * @node vxlan6-gpe-input
711 * @return from_frame->n_vectors - uword
714 VLIB_NODE_FN (vxlan6_gpe_input_node) (vlib_main_t * vm,
715 vlib_node_runtime_t * node,
716 vlib_frame_t * from_frame)
718 return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 0);
722 * @brief VXLAN GPE error strings
724 static char *vxlan_gpe_error_strings[] = {
725 #define vxlan_gpe_error(n,s) s,
726 #include <vnet/vxlan-gpe/vxlan_gpe_error.def>
727 #undef vxlan_gpe_error
732 VLIB_REGISTER_NODE (vxlan4_gpe_input_node) = {
733 .name = "vxlan4-gpe-input",
734 /* Takes a vector of packets. */
735 .vector_size = sizeof (u32),
736 .type = VLIB_NODE_TYPE_INTERNAL,
737 .n_errors = ARRAY_LEN(vxlan_gpe_error_strings),
738 .error_strings = vxlan_gpe_error_strings,
740 .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT,
742 #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n,
743 foreach_vxlan_gpe_input_next
747 .format_buffer = format_vxlan_gpe_with_length,
748 .format_trace = format_vxlan_gpe_rx_trace,
749 // $$$$ .unformat_buffer = unformat_vxlan_gpe_header,
754 VLIB_REGISTER_NODE (vxlan6_gpe_input_node) = {
755 .name = "vxlan6-gpe-input",
756 /* Takes a vector of packets. */
757 .vector_size = sizeof (u32),
758 .type = VLIB_NODE_TYPE_INTERNAL,
759 .n_errors = ARRAY_LEN(vxlan_gpe_error_strings),
760 .error_strings = vxlan_gpe_error_strings,
762 .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT,
764 #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n,
765 foreach_vxlan_gpe_input_next
769 .format_buffer = format_vxlan_gpe_with_length,
770 .format_trace = format_vxlan_gpe_rx_trace,
771 // $$$$ .unformat_buffer = unformat_vxlan_gpe_header,
777 IP_VXLAN_BYPASS_NEXT_DROP,
778 IP_VXLAN_BYPASS_NEXT_VXLAN,
779 IP_VXLAN_BYPASS_N_NEXT,
780 } ip_vxlan_bypass_next_t;
783 ip_vxlan_gpe_bypass_inline (vlib_main_t * vm,
784 vlib_node_runtime_t * node,
785 vlib_frame_t * frame, u32 is_ip4)
787 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
788 u32 *from, *to_next, n_left_from, n_left_to_next, next_index;
789 vlib_node_runtime_t *error_node =
790 vlib_node_get_runtime (vm, ip4_input_node.index);
791 ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */
792 ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */
794 from = vlib_frame_vector_args (frame);
795 n_left_from = frame->n_vectors;
796 next_index = node->cached_next_index;
798 if (node->flags & VLIB_NODE_FLAG_TRACE)
799 ip4_forward_next_trace (vm, node, frame, VLIB_TX);
804 ip6_address_set_zero (&addr6);
806 while (n_left_from > 0)
808 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
810 while (n_left_from >= 4 && n_left_to_next >= 2)
812 vlib_buffer_t *b0, *b1;
813 ip4_header_t *ip40, *ip41;
814 ip6_header_t *ip60, *ip61;
815 udp_header_t *udp0, *udp1;
816 u32 bi0, ip_len0, udp_len0, flags0, next0;
817 u32 bi1, ip_len1, udp_len1, flags1, next1;
818 i32 len_diff0, len_diff1;
819 u8 error0, good_udp0, proto0;
820 u8 error1, good_udp1, proto1;
822 /* Prefetch next iteration. */
824 vlib_buffer_t *p2, *p3;
826 p2 = vlib_get_buffer (vm, from[2]);
827 p3 = vlib_get_buffer (vm, from[3]);
829 vlib_prefetch_buffer_header (p2, LOAD);
830 vlib_prefetch_buffer_header (p3, LOAD);
832 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
833 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
836 bi0 = to_next[0] = from[0];
837 bi1 = to_next[1] = from[1];
843 b0 = vlib_get_buffer (vm, bi0);
844 b1 = vlib_get_buffer (vm, bi1);
847 ip40 = vlib_buffer_get_current (b0);
848 ip41 = vlib_buffer_get_current (b1);
852 ip60 = vlib_buffer_get_current (b0);
853 ip61 = vlib_buffer_get_current (b1);
856 /* Setup packet for next IP feature */
857 vnet_feature_next (&next0, b0);
858 vnet_feature_next (&next1, b1);
862 proto0 = ip40->protocol;
863 proto1 = ip41->protocol;
867 proto0 = ip60->protocol;
868 proto1 = ip61->protocol;
871 /* Process packet 0 */
872 if (proto0 != IP_PROTOCOL_UDP)
873 goto exit0; /* not UDP packet */
876 udp0 = ip4_next_header (ip40);
878 udp0 = ip6_next_header (ip60);
880 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE))
881 goto exit0; /* not VXLAN packet */
883 /* Validate DIP against VTEPs */
886 if (addr4.as_u32 != ip40->dst_address.as_u32)
888 if (!hash_get (ngm->vtep4, ip40->dst_address.as_u32))
889 goto exit0; /* no local VTEP for VXLAN packet */
890 addr4 = ip40->dst_address;
895 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
897 if (!hash_get_mem (ngm->vtep6, &ip60->dst_address))
898 goto exit0; /* no local VTEP for VXLAN packet */
899 addr6 = ip60->dst_address;
904 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
906 /* Don't verify UDP checksum for packets with explicit zero checksum. */
907 good_udp0 |= udp0->checksum == 0;
909 /* Verify UDP length */
911 ip_len0 = clib_net_to_host_u16 (ip40->length);
913 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
914 udp_len0 = clib_net_to_host_u16 (udp0->length);
915 len_diff0 = ip_len0 - udp_len0;
917 /* Verify UDP checksum */
918 if (PREDICT_FALSE (!good_udp0))
920 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
923 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
925 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
927 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
933 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
934 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
938 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
939 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
943 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
944 b0->error = error0 ? error_node->errors[error0] : 0;
946 /* vxlan_gpe-input node expect current at VXLAN header */
948 vlib_buffer_advance (b0,
949 sizeof (ip4_header_t) +
950 sizeof (udp_header_t));
952 vlib_buffer_advance (b0,
953 sizeof (ip6_header_t) +
954 sizeof (udp_header_t));
957 /* Process packet 1 */
958 if (proto1 != IP_PROTOCOL_UDP)
959 goto exit1; /* not UDP packet */
962 udp1 = ip4_next_header (ip41);
964 udp1 = ip6_next_header (ip61);
966 if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE))
967 goto exit1; /* not VXLAN packet */
969 /* Validate DIP against VTEPs */
972 if (addr4.as_u32 != ip41->dst_address.as_u32)
974 if (!hash_get (ngm->vtep4, ip41->dst_address.as_u32))
975 goto exit1; /* no local VTEP for VXLAN packet */
976 addr4 = ip41->dst_address;
981 if (!ip6_address_is_equal (&addr6, &ip61->dst_address))
983 if (!hash_get_mem (ngm->vtep6, &ip61->dst_address))
984 goto exit1; /* no local VTEP for VXLAN packet */
985 addr6 = ip61->dst_address;
990 good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
992 /* Don't verify UDP checksum for packets with explicit zero checksum. */
993 good_udp1 |= udp1->checksum == 0;
995 /* Verify UDP length */
997 ip_len1 = clib_net_to_host_u16 (ip41->length);
999 ip_len1 = clib_net_to_host_u16 (ip61->payload_length);
1000 udp_len1 = clib_net_to_host_u16 (udp1->length);
1001 len_diff1 = ip_len1 - udp_len1;
1003 /* Verify UDP checksum */
1004 if (PREDICT_FALSE (!good_udp1))
1006 if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1009 flags1 = ip4_tcp_udp_validate_checksum (vm, b1);
1011 flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1);
1013 (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1019 error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1020 error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH;
1024 error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1025 error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH;
1029 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
1030 b1->error = error1 ? error_node->errors[error1] : 0;
1032 /* vxlan_gpe-input node expect current at VXLAN header */
1034 vlib_buffer_advance (b1,
1035 sizeof (ip4_header_t) +
1036 sizeof (udp_header_t));
1038 vlib_buffer_advance (b1,
1039 sizeof (ip6_header_t) +
1040 sizeof (udp_header_t));
1043 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
1044 to_next, n_left_to_next,
1045 bi0, bi1, next0, next1);
1048 while (n_left_from > 0 && n_left_to_next > 0)
1054 u32 bi0, ip_len0, udp_len0, flags0, next0;
1056 u8 error0, good_udp0, proto0;
1058 bi0 = to_next[0] = from[0];
1062 n_left_to_next -= 1;
1064 b0 = vlib_get_buffer (vm, bi0);
1066 ip40 = vlib_buffer_get_current (b0);
1068 ip60 = vlib_buffer_get_current (b0);
1070 /* Setup packet for next IP feature */
1071 vnet_feature_next (&next0, b0);
1074 proto0 = ip40->protocol;
1076 proto0 = ip60->protocol;
1078 if (proto0 != IP_PROTOCOL_UDP)
1079 goto exit; /* not UDP packet */
1082 udp0 = ip4_next_header (ip40);
1084 udp0 = ip6_next_header (ip60);
1086 if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE))
1087 goto exit; /* not VXLAN packet */
1089 /* Validate DIP against VTEPs */
1092 if (addr4.as_u32 != ip40->dst_address.as_u32)
1094 if (!hash_get (ngm->vtep4, ip40->dst_address.as_u32))
1095 goto exit; /* no local VTEP for VXLAN packet */
1096 addr4 = ip40->dst_address;
1101 if (!ip6_address_is_equal (&addr6, &ip60->dst_address))
1103 if (!hash_get_mem (ngm->vtep6, &ip60->dst_address))
1104 goto exit; /* no local VTEP for VXLAN packet */
1105 addr6 = ip60->dst_address;
1110 good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1112 /* Don't verify UDP checksum for packets with explicit zero checksum. */
1113 good_udp0 |= udp0->checksum == 0;
1115 /* Verify UDP length */
1117 ip_len0 = clib_net_to_host_u16 (ip40->length);
1119 ip_len0 = clib_net_to_host_u16 (ip60->payload_length);
1120 udp_len0 = clib_net_to_host_u16 (udp0->length);
1121 len_diff0 = ip_len0 - udp_len0;
1123 /* Verify UDP checksum */
1124 if (PREDICT_FALSE (!good_udp0))
1126 if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0)
1129 flags0 = ip4_tcp_udp_validate_checksum (vm, b0);
1131 flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0);
1133 (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0;
1139 error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM;
1140 error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH;
1144 error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM;
1145 error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH;
1149 IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN;
1150 b0->error = error0 ? error_node->errors[error0] : 0;
1152 /* vxlan_gpe-input node expect current at VXLAN header */
1154 vlib_buffer_advance (b0,
1155 sizeof (ip4_header_t) +
1156 sizeof (udp_header_t));
1158 vlib_buffer_advance (b0,
1159 sizeof (ip6_header_t) +
1160 sizeof (udp_header_t));
1163 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1164 to_next, n_left_to_next,
1168 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1171 return frame->n_vectors;
1174 VLIB_NODE_FN (ip4_vxlan_gpe_bypass_node) (vlib_main_t * vm,
1175 vlib_node_runtime_t * node,
1176 vlib_frame_t * frame)
1178 return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 1);
1182 VLIB_REGISTER_NODE (ip4_vxlan_gpe_bypass_node) = {
1183 .name = "ip4-vxlan-gpe-bypass",
1184 .vector_size = sizeof (u32),
1186 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
1188 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
1189 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan4-gpe-input",
1192 .format_buffer = format_ip4_header,
1193 .format_trace = format_ip4_forward_next_trace,
1197 #ifndef CLIB_MARCH_VARIANT
1198 /* Dummy init function to get us linked in. */
1200 ip4_vxlan_gpe_bypass_init (vlib_main_t * vm)
1205 VLIB_INIT_FUNCTION (ip4_vxlan_gpe_bypass_init);
1206 #endif /* CLIB_MARCH_VARIANT */
1208 VLIB_NODE_FN (ip6_vxlan_gpe_bypass_node) (vlib_main_t * vm,
1209 vlib_node_runtime_t * node,
1210 vlib_frame_t * frame)
1212 return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 0);
1216 VLIB_REGISTER_NODE (ip6_vxlan_gpe_bypass_node) = {
1217 .name = "ip6-vxlan-gpe-bypass",
1218 .vector_size = sizeof (u32),
1220 .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT,
1222 [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop",
1223 [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-gpe-input",
1226 .format_buffer = format_ip6_header,
1227 .format_trace = format_ip6_forward_next_trace,
1231 #ifndef CLIB_MARCH_VARIANT
1232 /* Dummy init function to get us linked in. */
1234 ip6_vxlan_gpe_bypass_init (vlib_main_t * vm)
1239 VLIB_INIT_FUNCTION (ip6_vxlan_gpe_bypass_init);
1240 #endif /* CLIB_MARCH_VARIANT */
1243 * fd.io coding-style-patch-verification: ON
1246 * eval: (c-set-style "gnu")