19 #include <sys/ioctl.h> 31 #include <vpp/app/version.h> 39 .arc_name =
"ip4-unicast",
40 .node_name =
"ip4-gtpu-bypass",
45 .arc_name =
"ip6-unicast",
46 .node_name =
"ip6-gtpu-bypass",
54 u32 next_index = va_arg (*args,
u32);
58 case GTPU_INPUT_NEXT_DROP:
60 case GTPU_INPUT_NEXT_L2_INPUT:
62 case GTPU_INPUT_NEXT_IP4_INPUT:
64 case GTPU_INPUT_NEXT_IP6_INPUT:
67 return format (s,
"index %d", next_index);
78 s =
format (s,
"[%d] src %U dst %U teid %d sw_if_index %d ",
87 s =
format (s,
"encap_fib_index %d fib_entry_index %d decap_next %U\n",
96 u32 dev_instance = va_arg (*args,
u32);
97 return format (s,
"gtpu_tunnel%d", dev_instance);
122 u32 dev_instance = va_arg (*args,
u32);
123 s =
format (s,
"unimplemented dev %u", dev_instance);
207 #define foreach_copy_field \ 209 _(mcast_sw_if_index) \ 211 _(decap_next_index) \ 220 ip4_gtpu_header_t *h4;
221 ip6_gtpu_header_t *h6;
226 int len = is_ip6 ?
sizeof *r.h6 :
sizeof *r.h4;
254 clib_host_to_net_u32 (6 << 28);
263 udp->
src_port = clib_host_to_net_u16 (2152);
264 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU);
269 gtpu->
teid = clib_host_to_net_u32 (t->
teid);
273 _vec_len (t->
rewrite) =
sizeof (ip4_gtpu_header_t) - 4;
326 static inline mcast_shared_t
327 mcast_shared_get (ip46_address_t * ip)
332 return (mcast_shared_t)
340 mcast_shared_t new_ep = {
341 .mcast_adj_index = ai,
342 .mfib_entry_index = mfei,
351 mcast_shared_t ep = mcast_shared_get (dst);
372 u32 hw_if_index = ~0;
373 u32 sw_if_index = ~0;
374 gtpu4_tunnel_key_t key4;
375 gtpu6_tunnel_key_t key6;
380 key4.src = a->
dst.ip4.as_u32;
381 key4.teid = clib_host_to_net_u32 (a->
teid);
386 key6.src = a->
dst.ip6;
387 key6.teid = clib_host_to_net_u32 (a->
teid);
397 return VNET_API_ERROR_TUNNEL_EXIST;
403 return VNET_API_ERROR_INVALID_DECAP_NEXT;
406 memset (t, 0,
sizeof (*t));
409 #define _(x) t->x = a->x; 451 (vnm, gtpu_device_class.index, t - gtm->
tunnels,
452 gtpu_hw_class.index, t - gtm->
tunnels);
457 u32 encap_index = !is_ip6 ?
515 .frp_sw_if_index = 0xffffffff,
522 .fp_len = (is_ip6 ? 128 : 32),
523 .fp_grp_addr = tun_dst_pfx.
fp_addr,
558 mcast_shared_t ep = mcast_shared_get (&t->
dst);
577 return VNET_API_ERROR_NO_SUCH_ENTRY;
615 *sw_if_indexp = sw_if_index;
634 u32 *result = va_arg (*args,
u32 *);
635 u32 ipv4_set = va_arg (*args,
int);
642 *result = GTPU_INPUT_NEXT_L2_INPUT;
644 *result = GTPU_INPUT_NEXT_IP4_INPUT;
646 *result = GTPU_INPUT_NEXT_IP6_INPUT;
649 else if (
unformat (input,
"%d", &tmp))
663 ip46_address_t src, dst;
670 u32 encap_fib_index = 0;
671 u32 mcast_sw_if_index = ~0;
672 u32 decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
677 u32 tunnel_sw_if_index;
681 memset (&src, 0,
sizeof src);
682 memset (&dst, 0,
sizeof dst);
694 else if (
unformat (line_input,
"src %U",
700 else if (
unformat (line_input,
"dst %U",
706 else if (
unformat (line_input,
"src %U",
712 else if (
unformat (line_input,
"dst %U",
718 else if (
unformat (line_input,
"group %U %U",
723 grp_set = dst_set = 1;
726 else if (
unformat (line_input,
"group %U %U",
731 grp_set = dst_set = 1;
734 else if (
unformat (line_input,
"encap-vrf-id %d", &tmp))
737 if (encap_fib_index == ~0)
745 &decap_next_index, ipv4_set))
747 else if (
unformat (line_input,
"teid %d", &teid))
781 if (grp_set && mcast_sw_if_index == ~0)
787 if (ipv4_set && ipv6_set)
799 if (decap_next_index == ~0)
805 memset (a, 0,
sizeof (*a));
810 #define _(x) a->x = x; 824 case VNET_API_ERROR_TUNNEL_EXIST:
828 case VNET_API_ERROR_NO_SUCH_ENTRY:
834 (0,
"vnet_gtpu_add_del_tunnel returned %d", rv);
866 .path =
"create gtpu tunnel",
868 "create gtpu tunnel src <local-vtep-addr>" 869 " {dst <remote-vtep-addr>|group <mcast-vtep-addr> <intf-name>} teid <nn>" 870 " [encap-vrf-id <nn>] [decap-next [l2|ip4|ip6|node <name>]] [del]",
888 vlib_cli_output (vm,
"%U",
889 format_gtpu_tunnel, t);
907 .path =
"show gtpu tunnel",
908 .short_help =
"show gtpu tunnel",
918 sw_if_index, is_enable, 0, 0);
921 sw_if_index, is_enable, 0, 0);
931 u32 sw_if_index, is_enable;
944 else if (
unformat (line_input,
"del"))
953 if (~0 == sw_if_index)
1019 .path =
"set interface ip gtpu-bypass",
1021 .short_help =
"set interface ip gtpu-bypass <interface> [del]",
1076 .path =
"set interface ip6 gtpu-bypass",
1078 .short_help =
"set interface ip gtpu-bypass <interface> [del]",
1092 sizeof (gtpu6_tunnel_key_t),
1096 sizeof (ip46_address_t),
1097 sizeof (mcast_shared_t));
1113 .version = VPP_BUILD_VER,
1114 .description =
"GTPv1-U",
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
vlib_node_registration_t gtpu4_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu4_encap_node)
void vnet_set_interface_output_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Set interface output node - for interface registered without its output/tx nodes created because its ...
void dpo_stack_from_node(u32 child_node_index, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child parent relationship.
clib_error_t * gtpu_init(vlib_main_t *vm)
Recursive resolution source.
Contribute an object that is to be used to forward IP6 packets.
#define hash_set(h, key, value)
l2_input_config_t * configs
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
#define hash_unset(h, key)
static uword ip46_address_is_multicast(ip46_address_t *a)
static uword get_decap_next_for_node(u32 node_index, u32 ipv4_set)
A representation of a path as described by a route producer.
vnet_main_t * vnet_get_main(void)
typedef CLIB_PACKED(union{struct{fib_node_index_t mfib_entry_index;adj_index_t mcast_adj_index;};u64 as_u64;})
vnet_interface_main_t interface_main
void fib_node_init(fib_node_t *node, fib_node_type_t type)
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
u32 * tunnel_index_by_sw_if_index
fib_node_type_t fib_node_type
Node type for registering to fib changes.
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
#define foreach_copy_field
void fib_entry_contribute_forwarding(fib_node_index_t fib_entry_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
static uword vtep_addr_unref(ip46_address_t *ip)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Contribute an object that is to be used to forward IP4 packets.
VNET_FEATURE_INIT(ip4_gtpu_bypass, static)
static void gtpu_tunnel_restack_dpo(gtpu_tunnel_t *t)
#define STRUCT_OFFSET_OF(t, f)
void fib_node_deinit(fib_node_t *node)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
dpo_proto_t frp_proto
The protocol of the address below.
unformat_function_t unformat_vnet_sw_interface
static fib_protocol_t fib_ip_proto(bool is_ip6)
#define VNET_HW_INTERFACE_FLAG_LINK_UP
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
#define ip46_address_cmp(ip46_1, ip46_2)
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
fib_node_type_t fib_node_register_new_type(const fib_node_vft_t *vft)
Create a new FIB node type and Register the function table for it.
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static u8 * format_decap_next(u8 *s, va_list *args)
static fib_node_t * gtpu_tunnel_fib_node_get(fib_node_index_t index)
Function definition to get a FIB node from its index.
VNET_DEVICE_CLASS(gtpu_device_class, static)
static u8 * format_gtpu_name(u8 *s, va_list *args)
vnet_flood_class_t flood_class
VNET_HW_INTERFACE_CLASS(gtpu_hw_class)
static gtpu_tunnel_t * gtpu_tunnel_from_fib_node(fib_node_t *node)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
u32 frp_sw_if_index
The interface.
int vnet_gtpu_add_del_tunnel(vnet_gtpu_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
#define VLIB_INIT_FUNCTION(x)
void mfib_table_entry_delete_index(fib_node_index_t mfib_entry_index, mfib_source_t source)
Delete a FIB entry.
vlib_combined_counter_main_t * combined_sw_if_counters
Aggregrate type for a prefix.
static clib_error_t * show_gtpu_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define clib_error_return(e, args...)
fib_node_index_t mfib_table_entry_path_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath, mfib_itf_flags_t itf_flags)
Add n paths to an entry (aka route) in the FIB.
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
static u8 * format_gtpu_header_with_length(u8 *s, va_list *args)
u8 * format_gtpu_tunnel(u8 *s, va_list *args)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
#define hash_create_mem(elts, key_bytes, value_bytes)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
#define pool_put(P, E)
Free an object E in pool P.
static uword ip6_gtpu_bypass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vlib_simple_counter_main_t * sw_if_counters
static uword vtep_addr_ref(ip46_address_t *ip)
static fib_node_back_walk_rc_t gtpu_tunnel_back_walk(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Function definition to backwalk a FIB node - Here we will restack the new dpo of GTPU DIP to encap no...
An node in the FIB graph.
static clib_error_t * gtpu_add_del_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define ip46_address_is_ip4(ip46)
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
static void ip_udp_gtpu_rewrite(gtpu_tunnel_t *t, bool is_ip6)
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a 'special' entry to the FIB.
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
#define vec_free(V)
Free vector's memory (no header).
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
#define VNET_SW_INTERFACE_FLAG_HIDDEN
static void mcast_shared_remove(ip46_address_t *dst)
u32 fib_node_index_t
A typedef of a node index.
u32 adj_index_t
An index for adjacencies.
void fib_prefix_from_ip46_addr(const ip46_address_t *addr, fib_prefix_t *pfx)
Host prefix from ip.
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
u32 sibling_index
The tunnel is a child of the FIB entry for its destination.
Aggregrate type for a prefix.
static bool gtpu_decap_next_is_valid(gtpu_main_t *gtm, u32 is_ip6, u32 decap_next_index)
u8 * default_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
Return a complete, zero-length (aka dummy) rewrite.
Context passed between object during a back walk.
#define VLIB_CLI_COMMAND(x,...)
u32 * free_gtpu_tunnel_hw_if_indices
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
static clib_error_t * set_ip4_gtpu_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
fib_node_index_t fib_entry_index
u8 * format_gtpu_encap_trace(u8 *s, va_list *args)
fib_node_t node
Linkage into the FIB object graph.
static void gtpu_tunnel_last_lock_gone(fib_node_t *node)
Function definition to inform the FIB node that its last lock has gone.
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
fib_route_path_flags_t frp_flags
flags on the path
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
void vnet_int_gtpu_bypass_mode(u32 sw_if_index, u8 is_ip6, u8 is_enable)
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
#define VNET_FEATURES(...)
uword * gtpu4_tunnel_by_key
vlib_node_registration_t gtpu6_input_node
(constructor) VLIB_REGISTER_NODE (gtpu6_input_node)
static void mcast_shared_add(ip46_address_t *dst, fib_node_index_t mfei, adj_index_t ai)
fib_protocol_t fp_proto
protocol type
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
uword * gtpu6_tunnel_by_key
static void hash_set_mem_alloc(uword **h, void *key, uword v)
static clib_error_t * set_ip6_gtpu_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
vlib_node_registration_t gtpu6_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu6_encap_node)
a point 2 point interface
unformat_function_t unformat_vlib_node
#define hash_get_mem(h, key)
static void hash_unset_mem_free(uword **h, void *key)
static clib_error_t * set_ip_gtpu_bypass(u32 is_ip6, unformat_input_t *input, vlib_cli_command_t *cmd)
A FIB graph nodes virtual function table.
adj_index_t adj_mcast_add_or_lock(fib_protocol_t proto, vnet_link_t link_type, u32 sw_if_index)
Mcast Adjacency.
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
vnet_link_t fib_proto_to_link(fib_protocol_t proto)
Convert from a protocol to a link type.
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
static uword ip4_gtpu_bypass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
static clib_error_t * gtpu_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
#define CLIB_CACHE_LINE_BYTES
vlib_node_registration_t gtpu4_input_node
(constructor) VLIB_REGISTER_NODE (gtpu4_input_node)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static uword unformat_decap_next(unformat_input_t *input, va_list *args)
static u16 ip4_header_checksum(ip4_header_t *i)
const ip46_address_t zero_addr
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
static uword pool_elts(void *v)
Number of active elements in a pool.