2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Intel and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/fib_entry.h>
26 #include <vnet/fib/fib_table.h>
27 #include <vnet/fib/fib_entry_track.h>
28 #include <vnet/mfib/mfib_table.h>
29 #include <vnet/adj/adj_mcast.h>
30 #include <vnet/dpo/dpo.h>
31 #include <vnet/plugin/plugin.h>
32 #include <vpp/app/version.h>
33 #include <gtpu/gtpu.h>
34 #include <vnet/flow/flow.h>
36 gtpu_main_t gtpu_main;
39 VNET_FEATURE_INIT (ip4_gtpu_bypass, static) = {
40 .arc_name = "ip4-unicast",
41 .node_name = "ip4-gtpu-bypass",
42 .runs_before = VNET_FEATURES ("ip4-lookup"),
45 VNET_FEATURE_INIT (ip6_gtpu_bypass, static) = {
46 .arc_name = "ip6-unicast",
47 .node_name = "ip6-gtpu-bypass",
48 .runs_before = VNET_FEATURES ("ip6-lookup"),
52 u8 * format_gtpu_encap_trace (u8 * s, va_list * args)
54 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
55 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
56 gtpu_encap_trace_t * t
57 = va_arg (*args, gtpu_encap_trace_t *);
59 s = format (s, "GTPU encap to gtpu_tunnel%d tteid %u ", t->tunnel_index,
63 s = format (s, "pdu-extension qfi %d ", t->qfi);
65 s = format (s, "no-pdu-extension ");
70 format_decap_next (u8 * s, va_list * args)
72 u32 next_index = va_arg (*args, u32);
76 case GTPU_INPUT_NEXT_DROP:
77 return format (s, "drop");
78 case GTPU_INPUT_NEXT_L2_INPUT:
79 return format (s, "l2");
80 case GTPU_INPUT_NEXT_IP4_INPUT:
81 return format (s, "ip4");
82 case GTPU_INPUT_NEXT_IP6_INPUT:
83 return format (s, "ip6");
85 return format (s, "index %d", next_index);
91 format_gtpu_tunnel (u8 * s, va_list * args)
93 gtpu_tunnel_t *t = va_arg (*args, gtpu_tunnel_t *);
94 gtpu_main_t *ngm = >pu_main;
95 ip4_main_t *im4 = &ip4_main;
96 ip6_main_t *im6 = &ip6_main;
97 u8 is_ipv6 = !ip46_address_is_ip4 (&t->dst);
100 is_ipv6 ? im6->fibs[t->encap_fib_index].ft_table_id :
101 im4->fibs[t->encap_fib_index].ft_table_id;
104 "[%d] src %U dst %U teid %u tteid %u "
105 "encap-vrf-id %d sw-if-idx %d ",
106 t - ngm->tunnels, format_ip46_address, &t->src, IP46_TYPE_ANY,
107 format_ip46_address, &t->dst, IP46_TYPE_ANY, t->teid, t->tteid,
108 encap_vrf_id, t->sw_if_index);
110 s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
111 s = format (s, "decap-next-%U ", format_decap_next, t->decap_next_index);
113 if (t->is_forwarding)
115 switch (t->forwarding_type)
117 case GTPU_FORWARD_BAD_HEADER:
118 s = format (s, "forwarding bad-header ");
120 case GTPU_FORWARD_UNKNOWN_TEID:
121 s = format (s, "forwarding unknown-teid ");
123 case GTPU_FORWARD_UNKNOWN_TYPE:
124 s = format (s, "forwarding unknown-type ");
129 if (t->pdu_extension != 0)
130 s = format (s, "pdu-enabled qfi %d ", t->qfi);
132 s = format (s, "pdu-disabled ");
134 if (PREDICT_FALSE (ip46_address_is_multicast (&t->dst)))
135 s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
141 format_gtpu_name (u8 * s, va_list * args)
143 u32 dev_instance = va_arg (*args, u32);
144 return format (s, "gtpu_tunnel%d", dev_instance);
147 static clib_error_t *
148 gtpu_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
150 u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
151 VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
152 vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
154 return /* no error */ 0;
158 VNET_DEVICE_CLASS (gtpu_device_class,static) = {
160 .format_device_name = format_gtpu_name,
161 .format_tx_trace = format_gtpu_encap_trace,
162 .admin_up_down_function = gtpu_interface_admin_up_down,
167 format_gtpu_header_with_length (u8 * s, va_list * args)
169 u32 dev_instance = va_arg (*args, u32);
170 s = format (s, "unimplemented dev %u", dev_instance);
175 VNET_HW_INTERFACE_CLASS (gtpu_hw_class) =
178 .format_header = format_gtpu_header_with_length,
179 .build_rewrite = default_build_rewrite,
180 .flags = VNET_HW_INTERFACE_CLASS_FLAG_P2P,
185 gtpu_tunnel_restack_dpo (gtpu_tunnel_t * t)
187 dpo_id_t dpo = DPO_INVALID;
188 u32 encap_index = ip46_address_is_ip4 (&t->dst) ?
189 gtpu4_encap_node.index : gtpu6_encap_node.index;
190 fib_forward_chain_type_t forw_type = ip46_address_is_ip4 (&t->dst) ?
191 FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
193 fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
194 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
198 static gtpu_tunnel_t *
199 gtpu_tunnel_from_fib_node (fib_node_t * node)
201 return ((gtpu_tunnel_t *) (((char *) node) -
202 STRUCT_OFFSET_OF (gtpu_tunnel_t, node)));
206 * Function definition to backwalk a FIB node -
207 * Here we will restack the new dpo of GTPU DIP to encap node.
209 static fib_node_back_walk_rc_t
210 gtpu_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
212 gtpu_tunnel_restack_dpo (gtpu_tunnel_from_fib_node (node));
213 return (FIB_NODE_BACK_WALK_CONTINUE);
217 * Function definition to get a FIB node from its index
220 gtpu_tunnel_fib_node_get (fib_node_index_t index)
223 gtpu_main_t *gtm = >pu_main;
225 t = pool_elt_at_index (gtm->tunnels, index);
231 * Function definition to inform the FIB node that its last lock has gone.
234 gtpu_tunnel_last_lock_gone (fib_node_t * node)
237 * The GTPU tunnel is a root of the graph. As such
238 * it never has children and thus is never locked.
244 * Virtual function table registered by GTPU tunnels
245 * for participation in the FIB object graph.
247 const static fib_node_vft_t gtpu_vft = {
248 .fnv_get = gtpu_tunnel_fib_node_get,
249 .fnv_last_lock = gtpu_tunnel_last_lock_gone,
250 .fnv_back_walk = gtpu_tunnel_back_walk,
253 #define foreach_copy_field \
256 _ (mcast_sw_if_index) \
257 _ (encap_fib_index) \
258 _ (decap_next_index) \
267 ip_udp_gtpu_rewrite (gtpu_tunnel_t * t, bool is_ip6)
271 ip4_gtpu_header_t *h4;
272 ip6_gtpu_header_t *h6;
277 int len = is_ip6 ? sizeof *r.h6 : sizeof *r.h4;
279 vec_validate_aligned (r.rw, len - 1, CLIB_CACHE_LINE_BYTES);
283 gtpu_ext_with_pdu_session_header_t *gtpu_ext_pdu;
284 i64 length_adjustment = 0;
285 /* Fixed portion of the (outer) ip header */
288 ip4_header_t *ip = &r.h4->ip4;
291 gtpu_ext_pdu = &r.h4->gtpu_ext;
292 ip->ip_version_and_header_length = 0x45;
294 ip->protocol = IP_PROTOCOL_UDP;
296 ip->src_address = t->src.ip4;
297 ip->dst_address = t->dst.ip4;
299 /* we fix up the ip4 header length and checksum after-the-fact */
300 ip->checksum = ip4_header_checksum (ip);
304 ip6_header_t *ip = &r.h6->ip6;
307 gtpu_ext_pdu = &r.h6->gtpu_ext;
308 ip->ip_version_traffic_class_and_flow_label =
309 clib_host_to_net_u32 (6 << 28);
311 ip->protocol = IP_PROTOCOL_UDP;
313 ip->src_address = t->src.ip6;
314 ip->dst_address = t->dst.ip6;
317 /* UDP header, randomize src port on something, maybe? */
318 udp->src_port = clib_host_to_net_u16 (2152);
319 udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU);
322 gtpu->ver_flags = GTPU_V1_VER | GTPU_PT_GTP;
323 gtpu->type = GTPU_TYPE_GTPU;
324 gtpu->teid = clib_host_to_net_u32 (t->tteid);
326 if (t->pdu_extension)
328 gtpu->ver_flags = GTPU_V1_VER | GTPU_PT_GTP | GTPU_E_BIT;
329 gtpu->next_ext_type = GTPU_EXT_HDR_PDU_SESSION_CONTAINER;
330 gtpu_ext_pdu->len = 1;
331 gtpu_ext_pdu->pdu.oct0 = GTPU_PDU_DL_SESSION_TYPE;
332 gtpu_ext_pdu->pdu.oct1 = t->qfi;
333 gtpu_ext_pdu->next_header = 0;
337 // Remove the size of the PDU session header and the optional fields
338 length_adjustment = -sizeof (gtpu_ext_with_pdu_session_header_t) - 4;
342 /* Now only support 8-byte gtpu header or 12+4-byte header. TBD */
344 vec_set_len (t->rewrite, sizeof (ip4_gtpu_header_t) + length_adjustment);
346 vec_set_len (t->rewrite, sizeof (ip6_gtpu_header_t) + length_adjustment);
352 gtpu_decap_next_is_valid (gtpu_main_t * gtm, u32 is_ip6, u32 decap_next_index)
354 vlib_main_t *vm = gtm->vlib_main;
355 u32 input_idx = (!is_ip6) ? gtpu4_input_node.index : gtpu6_input_node.index;
356 vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
358 return decap_next_index < r->n_next_nodes;
361 typedef CLIB_PACKED (union
365 fib_node_index_t mfib_entry_index;
366 adj_index_t mcast_adj_index;
370 static inline mcast_shared_t
371 mcast_shared_get (ip46_address_t * ip)
373 ASSERT (ip46_address_is_multicast (ip));
374 uword *p = hash_get_mem (gtpu_main.mcast_shared, ip);
376 return (mcast_shared_t)
382 mcast_shared_add (ip46_address_t * dst, fib_node_index_t mfei, adj_index_t ai)
384 mcast_shared_t new_ep = {
385 .mcast_adj_index = ai,
386 .mfib_entry_index = mfei,
389 hash_set_mem_alloc (>pu_main.mcast_shared, dst, new_ep.as_u64);
393 mcast_shared_remove (ip46_address_t * dst)
395 mcast_shared_t ep = mcast_shared_get (dst);
397 adj_unlock (ep.mcast_adj_index);
398 mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_GTPU);
400 hash_unset_mem_free (>pu_main.mcast_shared, dst);
404 vnet_gtpu_add_del_forwarding (vnet_gtpu_add_mod_del_tunnel_args_t *a,
407 gtpu_main_t *gtm = >pu_main;
409 u32 current_index_value, current_index_value_ipv6;
410 u32 address_tabel_ipv4;
411 ip6_address_t address_tabel_ipv6;
412 u32 sw_if_index = ~0;
413 bool is_ip6 = !ip46_address_is_ip4 (&a->dst);
415 /* Check for errors */
416 if (!a->is_forwarding)
418 return VNET_API_ERROR_INVALID_ARGUMENT;
423 case GTPU_ADD_TUNNEL:
426 case GTPU_DEL_TUNNEL:
430 return VNET_API_ERROR_INVALID_ARGUMENT;
433 /* Check if the operation is valid, and get the current state if it is.
434 * Handling multiple flags at once is not supported yet. */
435 switch (a->forwarding_type)
437 case GTPU_FORWARD_BAD_HEADER:
438 current_index_value = gtm->bad_header_forward_tunnel_index_ipv4;
439 current_index_value_ipv6 = gtm->bad_header_forward_tunnel_index_ipv6;
440 address_tabel_ipv4 = GTPU_FORWARD_BAD_HEADER_ADDRESS_IPV4;
442 ip6_address_t address_tabel_ipv6_ = GTPU_FORWARD_BAD_HEADER_ADDRESS_IPV6;
443 address_tabel_ipv6 = address_tabel_ipv6_;
445 case GTPU_FORWARD_UNKNOWN_TEID:
446 current_index_value = gtm->unknown_teid_forward_tunnel_index_ipv4;
447 current_index_value_ipv6 = gtm->unknown_teid_forward_tunnel_index_ipv6;
448 address_tabel_ipv4 = GTPU_FORWARD_UNKNOWN_TEID_ADDRESS_IPV4;
449 ip6_address_t address_tabel_ipv6__ =
450 GTPU_FORWARD_UNKNOWN_TEID_ADDRESS_IPV6;
451 address_tabel_ipv6 = address_tabel_ipv6__;
453 case GTPU_FORWARD_UNKNOWN_TYPE:
454 current_index_value = gtm->unknown_type_forward_tunnel_index_ipv4;
455 current_index_value_ipv6 = gtm->unknown_type_forward_tunnel_index_ipv6;
456 address_tabel_ipv4 = GTPU_FORWARD_UNKNOWN_TYPE_ADDRESS_IPV4;
457 ip6_address_t address_tabel_ipv6___ =
458 GTPU_FORWARD_UNKNOWN_TYPE_ADDRESS_IPV6;
459 address_tabel_ipv6 = address_tabel_ipv6___;
462 return VNET_API_ERROR_INVALID_ARGUMENT;
466 current_index_value = current_index_value_ipv6;
468 /* Check if the existing forwarding rule state conflicts with this operation
470 if ((is_add) && (current_index_value != ~0))
472 return VNET_API_ERROR_TUNNEL_EXIST;
476 if (current_index_value == ~0)
477 return VNET_API_ERROR_NO_SUCH_ENTRY;
478 /* Clear the tunnel index before deleting the tunnel itself */
479 switch (a->forwarding_type)
481 case GTPU_FORWARD_BAD_HEADER:
482 gtm->bad_header_forward_tunnel_index_ipv4 = ~0;
484 case GTPU_FORWARD_UNKNOWN_TEID:
485 gtm->unknown_teid_forward_tunnel_index_ipv4 = ~0;
487 case GTPU_FORWARD_UNKNOWN_TYPE:
488 gtm->unknown_type_forward_tunnel_index_ipv4 = ~0;
493 /* src is the tunnel lookup key, so it is fixed.
494 * dst is used for the new target */
497 a->dst.ip6 = address_tabel_ipv6;
499 a->dst.ip4.as_u32 = address_tabel_ipv4;
500 rv = vnet_gtpu_add_mod_del_tunnel (a, &sw_if_index);
502 // Forward only if not nil
504 *sw_if_indexp = sw_if_index;
509 /* Update the forwarding tunnel index */
510 u32 tunnel_index = is_add ? vnet_gtpu_get_tunnel_index (sw_if_index) : ~0;
511 switch (a->forwarding_type)
513 case GTPU_FORWARD_BAD_HEADER:
515 gtm->bad_header_forward_tunnel_index_ipv6 = tunnel_index;
517 gtm->bad_header_forward_tunnel_index_ipv4 = tunnel_index;
520 case GTPU_FORWARD_UNKNOWN_TEID:
522 gtm->unknown_teid_forward_tunnel_index_ipv6 = tunnel_index;
524 gtm->unknown_teid_forward_tunnel_index_ipv4 = tunnel_index;
526 case GTPU_FORWARD_UNKNOWN_TYPE:
528 gtm->unknown_type_forward_tunnel_index_ipv6 = tunnel_index;
530 gtm->unknown_type_forward_tunnel_index_ipv4 = tunnel_index;
536 int vnet_gtpu_add_mod_del_tunnel
537 (vnet_gtpu_add_mod_del_tunnel_args_t * a, u32 * sw_if_indexp)
539 gtpu_main_t *gtm = >pu_main;
540 gtpu_tunnel_t *t = 0;
541 vnet_main_t *vnm = gtm->vnet_main;
543 u32 hw_if_index = ~0;
544 u32 sw_if_index = ~0;
545 gtpu4_tunnel_key_t key4;
546 gtpu6_tunnel_key_t key6;
547 bool is_ip6 = !ip46_address_is_ip4 (&a->dst);
551 key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
552 key4.teid = clib_host_to_net_u32 (a->teid);
553 p = hash_get (gtm->gtpu4_tunnel_by_key, key4.as_u64);
557 key6.src = a->dst.ip6;
558 key6.teid = clib_host_to_net_u32 (a->teid);
559 p = hash_get_mem (gtm->gtpu6_tunnel_by_key, &key6);
562 if (a->opn == GTPU_ADD_TUNNEL)
564 l2input_main_t *l2im = &l2input_main;
566 /* adding a tunnel: tunnel must not already exist */
568 return VNET_API_ERROR_TUNNEL_EXIST;
570 /*if not set explicitly, default to l2 */
571 if (a->decap_next_index == ~0)
572 a->decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
573 if (!gtpu_decap_next_is_valid (gtm, is_ip6, a->decap_next_index))
574 return VNET_API_ERROR_INVALID_DECAP_NEXT;
576 pool_get_aligned (gtm->tunnels, t, CLIB_CACHE_LINE_BYTES);
577 clib_memset (t, 0, sizeof (*t));
579 /* copy from arg structure */
580 #define _(x) t->x = a->x;
584 /* default to same as local rx teid */
588 ip_udp_gtpu_rewrite (t, is_ip6);
590 /* clear the flow index */
595 hash_set_mem_alloc (>m->gtpu6_tunnel_by_key, &key6,
598 hash_set (gtm->gtpu4_tunnel_by_key, key4.as_u64, t - gtm->tunnels);
600 vnet_hw_interface_t *hi;
601 if (vec_len (gtm->free_gtpu_tunnel_hw_if_indices) > 0)
603 vnet_interface_main_t *im = &vnm->interface_main;
604 hw_if_index = gtm->free_gtpu_tunnel_hw_if_indices
605 [vec_len (gtm->free_gtpu_tunnel_hw_if_indices) - 1];
606 vec_dec_len (gtm->free_gtpu_tunnel_hw_if_indices, 1);
608 hi = vnet_get_hw_interface (vnm, hw_if_index);
609 hi->dev_instance = t - gtm->tunnels;
610 hi->hw_instance = hi->dev_instance;
612 /* clear old stats of freed tunnel before reuse */
613 sw_if_index = hi->sw_if_index;
614 vnet_interface_counter_lock (im);
615 vlib_zero_combined_counter
616 (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
618 vlib_zero_combined_counter (&im->combined_sw_if_counters
619 [VNET_INTERFACE_COUNTER_RX],
621 vlib_zero_simple_counter (&im->sw_if_counters
622 [VNET_INTERFACE_COUNTER_DROP],
624 vnet_interface_counter_unlock (im);
628 hw_if_index = vnet_register_interface
629 (vnm, gtpu_device_class.index, t - gtm->tunnels,
630 gtpu_hw_class.index, t - gtm->tunnels);
631 hi = vnet_get_hw_interface (vnm, hw_if_index);
634 /* Set gtpu tunnel output node */
635 u32 encap_index = !is_ip6 ?
636 gtpu4_encap_node.index : gtpu6_encap_node.index;
637 vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
639 t->hw_if_index = hw_if_index;
640 t->sw_if_index = sw_if_index = hi->sw_if_index;
642 vec_validate_init_empty (gtm->tunnel_index_by_sw_if_index, sw_if_index,
644 gtm->tunnel_index_by_sw_if_index[sw_if_index] = t - gtm->tunnels;
646 /* setup l2 input config with l2 feature and bd 0 to drop packet */
647 vec_validate (l2im->configs, sw_if_index);
648 l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
649 l2im->configs[sw_if_index].bd_index = 0;
651 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
652 si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
653 vnet_sw_interface_set_flags (vnm, sw_if_index,
654 VNET_SW_INTERFACE_FLAG_ADMIN_UP);
656 fib_node_init (&t->node, gtm->fib_node_type);
657 fib_prefix_t tun_dst_pfx;
658 vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
660 fib_protocol_t fp = fib_ip_proto (is_ip6);
661 fib_prefix_from_ip46_addr (fp, &t->dst, &tun_dst_pfx);
662 if (!ip46_address_is_multicast (&t->dst))
665 * Track the FIB entry for the tunnel's destination.
666 * The tunnel will then get poked
667 * when the forwarding for the entry updates, and the tunnel can
668 * re-stack accordingly
670 vtep_addr_ref (>m->vtep_table, t->encap_fib_index, &t->src);
671 t->fib_entry_index = fib_entry_track (t->encap_fib_index,
676 gtpu_tunnel_restack_dpo (t);
680 /* Multicast tunnel -
681 * as the same mcast group can be used for multiple mcast tunnels
682 * with different VNIs, create the output adjacency only if
683 * it does not already exist
685 if (vtep_addr_ref (>m->vtep_table,
686 t->encap_fib_index, &t->dst) == 1)
688 fib_node_index_t mfei;
690 fib_route_path_t path = {
691 .frp_proto = fib_proto_to_dpo (fp),
692 .frp_addr = zero_addr,
693 .frp_sw_if_index = 0xffffffff,
696 .frp_flags = FIB_ROUTE_PATH_LOCAL,
697 .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
699 const mfib_prefix_t mpfx = {
701 .fp_len = (is_ip6 ? 128 : 32),
702 .fp_grp_addr = tun_dst_pfx.fp_addr,
706 * Setup the (*,G) to receive traffic on the mcast group
707 * - the forwarding interface is for-us
708 * - the accepting interface is that from the API
710 mfib_table_entry_path_update (t->encap_fib_index, &mpfx,
712 MFIB_ENTRY_FLAG_NONE, &path);
714 path.frp_sw_if_index = a->mcast_sw_if_index;
715 path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
716 path.frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT;
717 mfei = mfib_table_entry_path_update (
718 t->encap_fib_index, &mpfx, MFIB_SOURCE_GTPU,
719 MFIB_ENTRY_FLAG_NONE, &path);
722 * Create the mcast adjacency to send traffic to the group
724 ai = adj_mcast_add_or_lock (fp,
725 fib_proto_to_link (fp),
726 a->mcast_sw_if_index);
729 * create a new end-point
731 mcast_shared_add (&t->dst, mfei, ai);
734 dpo_id_t dpo = DPO_INVALID;
735 mcast_shared_t ep = mcast_shared_get (&t->dst);
737 /* Stack shared mcast dst mac addr rewrite on encap */
738 dpo_set (&dpo, DPO_ADJACENCY_MCAST,
739 fib_proto_to_dpo (fp), ep.mcast_adj_index);
741 dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
744 flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
747 vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
752 /* mod-tteid or deleting a tunnel: tunnel must exist */
754 return VNET_API_ERROR_NO_SUCH_ENTRY;
756 t = pool_elt_at_index (gtm->tunnels, p[0]);
757 sw_if_index = t->sw_if_index;
759 if (a->opn == GTPU_UPD_TTEID)
762 return VNET_API_ERROR_INVALID_VALUE;
764 vec_free (t->rewrite);
765 ip_udp_gtpu_rewrite (t, is_ip6);
770 vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
771 vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
772 si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
774 /* make sure tunnel is removed from l2 bd or xconnect */
775 set_int_l2_mode (gtm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0,
776 L2_BD_PORT_TYPE_NORMAL, 0, 0);
777 vec_add1 (gtm->free_gtpu_tunnel_hw_if_indices, t->hw_if_index);
779 gtm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
782 hash_unset (gtm->gtpu4_tunnel_by_key, key4.as_u64);
784 hash_unset_mem_free (>m->gtpu6_tunnel_by_key, &key6);
786 if (!ip46_address_is_multicast (&t->dst))
788 if (t->flow_index != ~0)
789 vnet_flow_del (vnm, t->flow_index);
791 vtep_addr_unref (>m->vtep_table, t->encap_fib_index, &t->src);
792 fib_entry_untrack (t->fib_entry_index, t->sibling_index);
794 else if (vtep_addr_unref (>m->vtep_table,
795 t->encap_fib_index, &t->dst) == 0)
797 mcast_shared_remove (&t->dst);
800 fib_node_deinit (&t->node);
801 vec_free (t->rewrite);
802 pool_put (gtm->tunnels, t);
806 *sw_if_indexp = sw_if_index;
808 if (a->opn == GTPU_ADD_TUNNEL)
810 /* register udp ports */
811 if (!is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_GTPU, 1))
812 udp_register_dst_port (gtm->vlib_main, UDP_DST_PORT_GTPU,
813 gtpu4_input_node.index, /* is_ip4 */ 1);
814 if (is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_GTPU6, 0))
815 udp_register_dst_port (gtm->vlib_main, UDP_DST_PORT_GTPU6,
816 gtpu6_input_node.index, /* is_ip4 */ 0);
823 get_combined_counters (u32 sw_if_index, vlib_counter_t *result_rx,
824 vlib_counter_t *result_tx)
826 gtpu_main_t *gtm = >pu_main;
827 vnet_main_t *vnm = gtm->vnet_main;
828 vnet_interface_main_t *im = &vnm->interface_main;
829 vlib_get_combined_counter (im->combined_sw_if_counters +
830 VNET_INTERFACE_COUNTER_RX,
831 sw_if_index, result_rx);
832 vlib_get_combined_counter (im->combined_sw_if_counters +
833 VNET_INTERFACE_COUNTER_TX,
834 sw_if_index, result_tx);
839 get_decap_next_for_node (u32 node_index, u32 ipv4_set)
841 gtpu_main_t *gtm = >pu_main;
842 vlib_main_t *vm = gtm->vlib_main;
843 uword input_node = (ipv4_set) ? gtpu4_input_node.index :
844 gtpu6_input_node.index;
846 return vlib_node_add_next (vm, input_node, node_index);
850 unformat_decap_next (unformat_input_t * input, va_list * args)
852 u32 *result = va_arg (*args, u32 *);
853 u32 ipv4_set = va_arg (*args, int);
854 gtpu_main_t *gtm = >pu_main;
855 vlib_main_t *vm = gtm->vlib_main;
859 if (unformat (input, "l2"))
860 *result = GTPU_INPUT_NEXT_L2_INPUT;
861 else if (unformat (input, "ip4"))
862 *result = GTPU_INPUT_NEXT_IP4_INPUT;
863 else if (unformat (input, "ip6"))
864 *result = GTPU_INPUT_NEXT_IP6_INPUT;
865 else if (unformat (input, "node %U", unformat_vlib_node, vm, &node_index))
866 *result = get_decap_next_for_node (node_index, ipv4_set);
867 else if (unformat (input, "%d", &tmp))
875 static clib_error_t *
876 gtpu_add_del_tunnel_command_fn (vlib_main_t * vm,
877 unformat_input_t * input,
878 vlib_cli_command_t * cmd)
880 unformat_input_t _line_input, *line_input = &_line_input;
881 ip46_address_t src, dst;
882 u8 opn = GTPU_ADD_TUNNEL;
888 u32 encap_fib_index = 0;
889 u32 mcast_sw_if_index = ~0;
890 u32 decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
891 u32 teid = 0, tteid = 0;
893 /* PDU is disabled by default */
894 u8 pdu_extension = 0;
896 u8 is_forwarding = 0;
897 u8 forwarding_type = 0;
899 vnet_gtpu_add_mod_del_tunnel_args_t _a, *a = &_a;
900 u32 tunnel_sw_if_index;
901 clib_error_t *error = NULL;
903 /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
904 clib_memset (&src, 0, sizeof src);
905 clib_memset (&dst, 0, sizeof dst);
907 /* Get a line of input. */
908 if (!unformat_user (input, unformat_line_input, line_input))
911 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
913 if (unformat (line_input, "del"))
915 opn = GTPU_DEL_TUNNEL;
917 else if (unformat (line_input, "src %U",
918 unformat_ip4_address, &src.ip4))
923 else if (unformat (line_input, "dst %U",
924 unformat_ip4_address, &dst.ip4))
929 else if (unformat (line_input, "src %U",
930 unformat_ip6_address, &src.ip6))
935 else if (unformat (line_input, "dst %U",
936 unformat_ip6_address, &dst.ip6))
941 else if (unformat (line_input, "group %U %U",
942 unformat_ip4_address, &dst.ip4,
943 unformat_vnet_sw_interface,
944 vnet_get_main (), &mcast_sw_if_index))
946 grp_set = dst_set = 1;
949 else if (unformat (line_input, "group %U %U",
950 unformat_ip6_address, &dst.ip6,
951 unformat_vnet_sw_interface,
952 vnet_get_main (), &mcast_sw_if_index))
954 grp_set = dst_set = 1;
957 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
959 encap_fib_index = fib_table_find (fib_ip_proto (ipv6_set), tmp);
960 if (encap_fib_index == ~0)
963 clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
967 else if (unformat (line_input, "decap-next %U", unformat_decap_next,
968 &decap_next_index, ipv4_set))
970 else if (unformat (line_input, "teid %d", &teid))
972 else if (unformat (line_input, "tteid %d", &tteid))
974 else if (unformat (line_input, "upd-tteid %d", &tteid))
975 opn = GTPU_UPD_TTEID;
976 else if (unformat (line_input, "qfi %d", &qfi))
980 error = clib_error_return (0, "parse error: '%U'",
981 format_unformat_error, line_input);
988 error = clib_error_return (0, "tunnel teid specified");
992 if (src_set == 0 && opn == GTPU_ADD_TUNNEL)
994 error = clib_error_return (0, "tunnel src address not specified");
1000 error = clib_error_return (0, "tunnel dst address not specified");
1004 if (grp_set && !ip46_address_is_multicast (&dst))
1006 error = clib_error_return (0, "tunnel group address not multicast");
1010 if (grp_set == 0 && ip46_address_is_multicast (&dst))
1012 error = clib_error_return (0, "dst address must be unicast");
1016 if (grp_set && mcast_sw_if_index == ~0)
1018 error = clib_error_return (0, "tunnel nonexistent multicast device");
1022 if (ipv4_set && ipv6_set)
1024 error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
1028 if (ip46_address_cmp (&src, &dst) == 0)
1030 error = clib_error_return (0, "src and dst addresses are identical");
1034 if (decap_next_index == ~0)
1036 error = clib_error_return (0, "next node not found");
1039 if (pdu_extension == 1 && qfi > 31)
1041 error = clib_error_return (0, "qfi max value is 31");
1044 clib_memset (a, 0, sizeof (*a));
1048 #define _(x) a->x = x;
1052 rv = vnet_gtpu_add_mod_del_tunnel (a, &tunnel_sw_if_index);
1057 if (opn == GTPU_ADD_TUNNEL)
1058 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
1059 vnet_get_main (), tunnel_sw_if_index);
1062 case VNET_API_ERROR_TUNNEL_EXIST:
1063 error = clib_error_return (0, "tunnel already exists...");
1066 case VNET_API_ERROR_NO_SUCH_ENTRY:
1067 error = clib_error_return (0, "tunnel does not exist...");
1070 case VNET_API_ERROR_INVALID_VALUE:
1071 error = clib_error_return (0, "tx teid not specified...");
1075 error = clib_error_return
1076 (0, "vnet_gtpu_add_del_tunnel returned %d", rv);
1081 unformat_free (line_input);
1087 * Add or delete a GTPU Tunnel.
1089 * GTPU can be used to transport Ethernet packets as its PDU type to
1090 * provides allow L2 network or bridge domains (BDs)
1091 * to span multiple servers. This is done by building an L2 overlay on
1092 * top of an L3 network underlay using GTPU tunnels.
1094 * GTPU can also be used to transport IP packets as its PDU type to
1095 * allow IP forwarding over underlay network, e.g. between RAN and UPF
1096 * for mobility deployments.
1099 * Example of how to create a GTPU Tunnel:
1100 * @cliexcmd{create gtpu tunnel src 10.0.3.1 dst 10.0.3.3 teid 13 tteid 55
1102 * Example of how to delete a GTPU Tunnel:
1103 * @cliexcmd{create gtpu tunnel src 10.0.3.1 dst 10.0.3.3 teid 13 encap-vrf-id
1105 * Example of how to update tx TEID of a GTPU Tunnel:
1106 * @cliexcmd{create gtpu tunnel src 10.0.3.1 dst 10.0.3.3 encap-vrf-id 7
1110 VLIB_CLI_COMMAND (create_gtpu_tunnel_command, static) = {
1111 .path = "create gtpu tunnel",
1113 "create gtpu tunnel src <local-tep-addr>"
1114 " {dst <remote-tep-addr>|group <mcast-addr> <intf-name>}"
1115 " teid <nn> [tteid <nn>] [encap-vrf-id <nn>]"
1116 " [decap-next [l2|ip4|ip6|node <name>]] [qfi <nn>] [del | upd-tteid <nn>]",
1117 .function = gtpu_add_del_tunnel_command_fn,
1121 static clib_error_t *
1122 show_gtpu_tunnel_command_fn (vlib_main_t * vm,
1123 unformat_input_t * input,
1124 vlib_cli_command_t * cmd)
1126 gtpu_main_t *gtm = >pu_main;
1129 if (pool_elts (gtm->tunnels) == 0)
1130 vlib_cli_output (vm, "No gtpu tunnels configured...");
1132 pool_foreach (t, gtm->tunnels)
1134 vlib_cli_output (vm, "%U", format_gtpu_tunnel, t);
1141 * Display all the GTPU Tunnel entries.
1144 * Example of how to display the GTPU Tunnel entries:
1145 * @cliexstart{show gtpu tunnel}
1146 * [0] src 10.0.3.1 dst 10.0.3.3 teid 13 tx-teid 55 encap_fib_index 0
1147 sw_if_index 5 decap_next l2 pdu-disabled
1151 VLIB_CLI_COMMAND (show_gtpu_tunnel_command, static) = {
1152 .path = "show gtpu tunnel",
1153 .short_help = "show gtpu tunnel",
1154 .function = show_gtpu_tunnel_command_fn,
1159 vnet_int_gtpu_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
1162 vnet_feature_enable_disable ("ip6-unicast", "ip6-gtpu-bypass",
1163 sw_if_index, is_enable, 0, 0);
1165 vnet_feature_enable_disable ("ip4-unicast", "ip4-gtpu-bypass",
1166 sw_if_index, is_enable, 0, 0);
1169 static clib_error_t *
1170 set_ip_gtpu_bypass (u32 is_ip6,
1171 unformat_input_t * input, vlib_cli_command_t * cmd)
1173 unformat_input_t _line_input, *line_input = &_line_input;
1174 vnet_main_t *vnm = vnet_get_main ();
1175 clib_error_t *error = 0;
1176 u32 sw_if_index, is_enable;
1181 if (!unformat_user (input, unformat_line_input, line_input))
1184 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1187 (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1189 else if (unformat (line_input, "del"))
1193 error = unformat_parse_error (line_input);
1198 if (~0 == sw_if_index)
1200 error = clib_error_return (0, "unknown interface `%U'",
1201 format_unformat_error, line_input);
1205 vnet_int_gtpu_bypass_mode (sw_if_index, is_ip6, is_enable);
1208 unformat_free (line_input);
1213 static clib_error_t *
1214 set_ip4_gtpu_bypass (vlib_main_t * vm,
1215 unformat_input_t * input, vlib_cli_command_t * cmd)
1217 return set_ip_gtpu_bypass (0, input, cmd);
1221 * This command adds the 'ip4-gtpu-bypass' graph node for a given interface.
1222 * By adding the IPv4 gtpu-bypass graph node to an interface, the node checks
1223 * for and validate input gtpu packet and bypass ip4-lookup, ip4-local,
1224 * ip4-udp-lookup nodes to speedup gtpu packet forwarding. This node will
1225 * cause extra overhead to for non-gtpu packets which is kept at a minimum.
1229 * Example of graph node before ip4-gtpu-bypass is enabled:
1230 * @cliexstart{show vlib graph ip4-gtpu-bypass}
1231 * Name Next Previous
1232 * ip4-gtpu-bypass error-drop [0]
1237 * Example of how to enable ip4-gtpu-bypass on an interface:
1238 * @cliexcmd{set interface ip gtpu-bypass GigabitEthernet2/0/0}
1240 * Example of graph node after ip4-gtpu-bypass is enabled:
1241 * @cliexstart{show vlib graph ip4-gtpu-bypass}
1242 * Name Next Previous
1243 * ip4-gtpu-bypass error-drop [0] ip4-input
1244 * gtpu4-input [1] ip4-input-no-checksum
1248 * Example of how to display the feature enabled on an interface:
1249 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1250 * IP feature paths configured on GigabitEthernet2/0/0...
1258 * Example of how to disable ip4-gtpu-bypass on an interface:
1259 * @cliexcmd{set interface ip gtpu-bypass GigabitEthernet2/0/0 del}
1263 VLIB_CLI_COMMAND (set_interface_ip_gtpu_bypass_command, static) = {
1264 .path = "set interface ip gtpu-bypass",
1265 .function = set_ip4_gtpu_bypass,
1266 .short_help = "set interface ip gtpu-bypass <interface> [del]",
1270 static clib_error_t *
1271 set_ip6_gtpu_bypass (vlib_main_t * vm,
1272 unformat_input_t * input, vlib_cli_command_t * cmd)
1274 return set_ip_gtpu_bypass (1, input, cmd);
1278 * This command adds the 'ip6-gtpu-bypass' graph node for a given interface.
1279 * By adding the IPv6 gtpu-bypass graph node to an interface, the node checks
1280 * for and validate input gtpu packet and bypass ip6-lookup, ip6-local,
1281 * ip6-udp-lookup nodes to speedup gtpu packet forwarding. This node will
1282 * cause extra overhead to for non-gtpu packets which is kept at a minimum.
1286 * Example of graph node before ip6-gtpu-bypass is enabled:
1287 * @cliexstart{show vlib graph ip6-gtpu-bypass}
1288 * Name Next Previous
1289 * ip6-gtpu-bypass error-drop [0]
1294 * Example of how to enable ip6-gtpu-bypass on an interface:
1295 * @cliexcmd{set interface ip6 gtpu-bypass GigabitEthernet2/0/0}
1297 * Example of graph node after ip6-gtpu-bypass is enabled:
1298 * @cliexstart{show vlib graph ip6-gtpu-bypass}
1299 * Name Next Previous
1300 * ip6-gtpu-bypass error-drop [0] ip6-input
1301 * gtpu6-input [1] ip4-input-no-checksum
1305 * Example of how to display the feature enabled on an interface:
1306 * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1307 * IP feature paths configured on GigabitEthernet2/0/0...
1315 * Example of how to disable ip6-gtpu-bypass on an interface:
1316 * @cliexcmd{set interface ip6 gtpu-bypass GigabitEthernet2/0/0 del}
1320 VLIB_CLI_COMMAND (set_interface_ip6_gtpu_bypass_command, static) = {
1321 .path = "set interface ip6 gtpu-bypass",
1322 .function = set_ip6_gtpu_bypass,
1323 .short_help = "set interface ip6 gtpu-bypass <interface> [del]",
1328 vnet_gtpu_add_del_rx_flow (u32 hw_if_index, u32 t_index, int is_add)
1330 gtpu_main_t *gtm = >pu_main;
1331 gtpu_tunnel_t *t = pool_elt_at_index (gtm->tunnels, t_index);
1332 vnet_main_t *vnm = vnet_get_main ();
1335 if (t->flow_index == ~0)
1337 vnet_flow_t flow = {
1339 VNET_FLOW_ACTION_REDIRECT_TO_NODE | VNET_FLOW_ACTION_MARK |
1340 VNET_FLOW_ACTION_BUFFER_ADVANCE,
1341 .mark_flow_id = t_index + gtm->flow_id_start,
1342 .redirect_node_index = gtpu4_flow_input_node.index,
1343 .buffer_advance = sizeof (ethernet_header_t)
1344 + sizeof (ip4_header_t) + sizeof (udp_header_t),
1345 .type = VNET_FLOW_TYPE_IP4_GTPU,
1347 .protocol.prot = IP_PROTOCOL_UDP,
1348 .src_addr.addr = t->dst.ip4,
1349 .src_addr.mask.as_u32 = ~0,
1350 .dst_addr.addr = t->src.ip4,
1351 .dst_addr.mask.as_u32 = ~0,
1356 vnet_flow_add (vnm, &flow, &t->flow_index);
1359 return vnet_flow_enable (vnm, t->flow_index, hw_if_index);
1362 /* flow index is removed when the tunnel is deleted */
1363 return vnet_flow_disable (vnm, t->flow_index, hw_if_index);
1367 vnet_gtpu_get_tunnel_index (u32 sw_if_index)
1369 gtpu_main_t *gtm = >pu_main;
1371 if (sw_if_index >= vec_len (gtm->tunnel_index_by_sw_if_index))
1373 return gtm->tunnel_index_by_sw_if_index[sw_if_index];
1376 static clib_error_t *
1377 gtpu_offload_command_fn (vlib_main_t * vm,
1378 unformat_input_t * input, vlib_cli_command_t * cmd)
1380 unformat_input_t _line_input, *line_input = &_line_input;
1382 /* Get a line of input. */
1383 if (!unformat_user (input, unformat_line_input, line_input))
1386 vnet_main_t *vnm = vnet_get_main ();
1387 u32 rx_sw_if_index = ~0;
1388 u32 hw_if_index = ~0;
1391 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1393 if (unformat (line_input, "hw %U", unformat_vnet_hw_interface, vnm,
1396 if (unformat (line_input, "rx %U", unformat_vnet_sw_interface, vnm,
1399 if (unformat (line_input, "del"))
1404 return clib_error_return (0, "unknown input `%U'",
1405 format_unformat_error, line_input);
1408 if (rx_sw_if_index == ~0)
1409 return clib_error_return (0, "missing rx interface");
1410 if (hw_if_index == ~0)
1411 return clib_error_return (0, "missing hw interface");
1413 u32 t_index = vnet_gtpu_get_tunnel_index (rx_sw_if_index);;
1415 return clib_error_return (0, "%U is not a gtpu tunnel",
1416 format_vnet_sw_if_index_name, vnm,
1419 gtpu_main_t *gtm = >pu_main;
1420 gtpu_tunnel_t *t = pool_elt_at_index (gtm->tunnels, t_index);
1422 /* first support ipv4 hw offload */
1423 if (!ip46_address_is_ip4 (&t->dst))
1424 return clib_error_return (0, "currently only IPV4 tunnels are supported");
1426 /* inner protocol should be IPv4/IPv6 */
1427 if ((t->decap_next_index != GTPU_INPUT_NEXT_IP4_INPUT) &&
1428 (t->decap_next_index != GTPU_INPUT_NEXT_IP6_INPUT))
1429 return clib_error_return (0,
1430 "currently only inner IPv4/IPv6 protocol is supported");
1432 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1433 ip4_main_t *im = &ip4_main;
1435 vec_elt (im->fib_index_by_sw_if_index, hw_if->sw_if_index);
1437 if (t->encap_fib_index != rx_fib_index)
1438 return clib_error_return (0, "interface/tunnel fib mismatch");
1440 if (vnet_gtpu_add_del_rx_flow (hw_if_index, t_index, is_add))
1441 return clib_error_return (0, "error %s flow",
1442 is_add ? "enabling" : "disabling");
1449 VLIB_CLI_COMMAND (gtpu_offload_command, static) = {
1450 .path = "set flow-offload gtpu",
1452 "set flow-offload gtpu hw <inerface-name> rx <tunnel-name> [del]",
1453 .function = gtpu_offload_command_fn,
1457 static clib_error_t *
1458 gtpu_forward_command_fn (vlib_main_t *vm, unformat_input_t *input,
1459 vlib_cli_command_t *cmd)
1461 unformat_input_t _line_input, *line_input = &_line_input;
1463 /* Get a line of input. */
1464 if (!unformat_user (input, unformat_line_input, line_input))
1467 u32 tunnel_sw_if_index;
1468 clib_error_t *error = NULL;
1470 u32 decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
1476 ip46_address_t src, dst;
1477 u32 encap_fib_index = 0;
1478 u32 mcast_sw_if_index = ~0;
1479 u32 teid = 0, tteid = 0;
1481 /* PDU is disabled by default */
1482 u8 pdu_extension = 0;
1484 u8 is_forwarding = 1;
1485 u8 forwarding_type = 0;
1487 vnet_gtpu_add_mod_del_tunnel_args_t _a, *a = &_a;
1489 /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
1490 clib_memset (&src, 0, sizeof src);
1491 clib_memset (&dst, 0, sizeof dst);
1493 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1495 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
1500 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
1505 else if (unformat (line_input, "decap-next %U", unformat_decap_next,
1506 &decap_next_index, ipv4_set))
1508 else if (unformat (line_input, "encap-vrf-id %d", &tmp))
1510 encap_fib_index = fib_table_find (fib_ip_proto (ipv6_set), tmp);
1511 if (encap_fib_index == ~0)
1514 clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
1518 else if (unformat (line_input, "del"))
1520 else if (unformat (line_input, "bad-header"))
1521 forwarding_type |= GTPU_FORWARD_BAD_HEADER;
1522 else if (unformat (line_input, "unknown-teid"))
1523 forwarding_type |= GTPU_FORWARD_UNKNOWN_TEID;
1524 else if (unformat (line_input, "unknown-type"))
1525 forwarding_type |= GTPU_FORWARD_UNKNOWN_TYPE;
1528 error = clib_error_return (0, "unknown input `%U'",
1529 format_unformat_error, line_input);
1536 error = clib_error_return (0, "dst must be set to a valid IP address");
1540 a->opn = is_add ? GTPU_ADD_TUNNEL : GTPU_DEL_TUNNEL;
1541 #define _(x) a->x = x;
1545 rv = vnet_gtpu_add_del_forwarding (a, &tunnel_sw_if_index);
1551 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
1552 vnet_get_main (), tunnel_sw_if_index);
1555 case VNET_API_ERROR_TUNNEL_EXIST:
1556 error = clib_error_return (0, "tunnel already exists...");
1559 case VNET_API_ERROR_NO_SUCH_ENTRY:
1560 error = clib_error_return (0, "tunnel does not exist...");
1563 case VNET_API_ERROR_INVALID_ARGUMENT:
1565 clib_error_return (0, "one and only one of unknown-teid, unknown-type "
1566 "or bad-header must be specified");
1571 clib_error_return (0, "vnet_gtpu_add_del_tunnel returned %d", rv);
1576 unformat_free (line_input);
1581 VLIB_CLI_COMMAND (gtpu_forward_command, static) = {
1582 .path = "create gtpu forward",
1584 "create gtpu forward dst <local-tep-addr> "
1585 "{unknown-teid|unknown-type|bad-header} "
1586 "[decap-next [l2|ip4|ip6|node <name>]] [encap-vrf-id <nn>] [del]",
1587 .function = gtpu_forward_command_fn,
1591 gtpu_init (vlib_main_t * vm)
1593 gtpu_main_t *gtm = >pu_main;
1595 gtm->vnet_main = vnet_get_main ();
1596 gtm->vlib_main = vm;
1598 vnet_flow_get_range (gtm->vnet_main, "gtpu", 1024 * 1024,
1599 >m->flow_id_start);
1601 /* initialize the ip6 hash */
1602 gtm->gtpu6_tunnel_by_key = hash_create_mem (0,
1603 sizeof (gtpu6_tunnel_key_t),
1605 gtm->vtep_table = vtep_table_create ();
1606 gtm->mcast_shared = hash_create_mem (0,
1607 sizeof (ip46_address_t),
1608 sizeof (mcast_shared_t));
1610 gtm->fib_node_type = fib_node_register_new_type ("gtpu", >pu_vft);
1612 /* Clear forward tunnels */
1613 gtm->bad_header_forward_tunnel_index_ipv4 = ~0;
1614 gtm->unknown_teid_forward_tunnel_index_ipv4 = ~0;
1615 gtm->unknown_type_forward_tunnel_index_ipv4 = ~0;
1616 gtm->bad_header_forward_tunnel_index_ipv6 = ~0;
1617 gtm->unknown_teid_forward_tunnel_index_ipv6 = ~0;
1618 gtm->unknown_type_forward_tunnel_index_ipv6 = ~0;
1623 VLIB_INIT_FUNCTION (gtpu_init);
1626 VLIB_PLUGIN_REGISTER () = {
1627 .version = VPP_BUILD_VER,
1628 .description = "GPRS Tunnelling Protocol, User Data (GTPv1-U)",
1633 * fd.io coding-style-patch-verification: ON
1636 * eval: (c-set-style "gnu")