FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
gtpu.c
Go to the documentation of this file.
1 /*
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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
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>
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>
35 
37 
38 /* *INDENT-OFF* */
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"),
43 };
44 
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"),
49 };
50 /* *INDENT-on* */
51 
52 u8 * format_gtpu_encap_trace (u8 * s, va_list * args)
53 {
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 *);
57  = va_arg (*args, gtpu_encap_trace_t *);
58 
59  s = format (s, "GTPU encap to gtpu_tunnel%d teid %d",
60  t->tunnel_index, t->teid);
61  return s;
62 }
63 
64 static u8 *
65 format_decap_next (u8 * s, va_list * args)
66 {
67  u32 next_index = va_arg (*args, u32);
68 
69  switch (next_index)
70  {
71  case GTPU_INPUT_NEXT_DROP:
72  return format (s, "drop");
73  case GTPU_INPUT_NEXT_L2_INPUT:
74  return format (s, "l2");
75  case GTPU_INPUT_NEXT_IP4_INPUT:
76  return format (s, "ip4");
77  case GTPU_INPUT_NEXT_IP6_INPUT:
78  return format (s, "ip6");
79  default:
80  return format (s, "index %d", next_index);
81  }
82  return s;
83 }
84 
85 u8 *
86 format_gtpu_tunnel (u8 * s, va_list * args)
87 {
88  gtpu_tunnel_t *t = va_arg (*args, gtpu_tunnel_t *);
89  gtpu_main_t *ngm = &gtpu_main;
90  ip4_main_t *im4 = &ip4_main;
91  ip6_main_t *im6 = &ip6_main;
93 
94  u32 encap_vrf_id =
95  is_ipv6 ? im6->fibs[t->encap_fib_index].ft_table_id :
97 
98  s = format (s, "[%d] src %U dst %U teid %d encap-vrf-id %d sw-if-idx %d ",
99  t - ngm->tunnels,
102  t->teid, encap_vrf_id, t->sw_if_index);
103 
104  s = format (s, "encap-dpo-idx %d ", t->next_dpo.dpoi_index);
105  s = format (s, "decap-next-%U ", format_decap_next, t->decap_next_index);
106 
108  s = format (s, "mcast-sw-if-idx %d ", t->mcast_sw_if_index);
109 
110  return s;
111 }
112 
113 static u8 *
114 format_gtpu_name (u8 * s, va_list * args)
115 {
116  u32 dev_instance = va_arg (*args, u32);
117  return format (s, "gtpu_tunnel%d", dev_instance);
118 }
119 
120 static clib_error_t *
122 {
123  u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
125  vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
126 
127  return /* no error */ 0;
128 }
129 
130 /* *INDENT-OFF* */
131 VNET_DEVICE_CLASS (gtpu_device_class,static) = {
132  .name = "GTPU",
133  .format_device_name = format_gtpu_name,
134  .format_tx_trace = format_gtpu_encap_trace,
135  .admin_up_down_function = gtpu_interface_admin_up_down,
136 };
137 /* *INDENT-ON* */
138 
139 static u8 *
140 format_gtpu_header_with_length (u8 * s, va_list * args)
141 {
142  u32 dev_instance = va_arg (*args, u32);
143  s = format (s, "unimplemented dev %u", dev_instance);
144  return s;
145 }
146 
147 /* *INDENT-OFF* */
148 VNET_HW_INTERFACE_CLASS (gtpu_hw_class) =
149 {
150  .name = "GTPU",
151  .format_header = format_gtpu_header_with_length,
152  .build_rewrite = default_build_rewrite,
154 };
155 /* *INDENT-ON* */
156 
157 static void
159 {
160  dpo_id_t dpo = DPO_INVALID;
161  u32 encap_index = ip46_address_is_ip4 (&t->dst) ?
162  gtpu4_encap_node.index : gtpu6_encap_node.index;
165 
166  fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
167  dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
168  dpo_reset (&dpo);
169 }
170 
171 static gtpu_tunnel_t *
173 {
174  return ((gtpu_tunnel_t *) (((char *) node) -
176 }
177 
178 /**
179  * Function definition to backwalk a FIB node -
180  * Here we will restack the new dpo of GTPU DIP to encap node.
181  */
184 {
187 }
188 
189 /**
190  * Function definition to get a FIB node from its index
191  */
192 static fib_node_t *
194 {
195  gtpu_tunnel_t *t;
196  gtpu_main_t *gtm = &gtpu_main;
197 
198  t = pool_elt_at_index (gtm->tunnels, index);
199 
200  return (&t->node);
201 }
202 
203 /**
204  * Function definition to inform the FIB node that its last lock has gone.
205  */
206 static void
208 {
209  /*
210  * The GTPU tunnel is a root of the graph. As such
211  * it never has children and thus is never locked.
212  */
213  ASSERT (0);
214 }
215 
216 /*
217  * Virtual function table registered by GTPU tunnels
218  * for participation in the FIB object graph.
219  */
220 const static fib_node_vft_t gtpu_vft = {
222  .fnv_last_lock = gtpu_tunnel_last_lock_gone,
223  .fnv_back_walk = gtpu_tunnel_back_walk,
224 };
225 
226 
227 #define foreach_copy_field \
228 _(teid) \
229 _(mcast_sw_if_index) \
230 _(encap_fib_index) \
231 _(decap_next_index) \
232 _(src) \
233 _(dst)
234 
235 static void
237 {
238  union
239  {
240  ip4_gtpu_header_t *h4;
241  ip6_gtpu_header_t *h6;
242  u8 *rw;
243  } r =
244  {
245  .rw = 0};
246  int len = is_ip6 ? sizeof *r.h6 : sizeof *r.h4;
247 
249 
250  udp_header_t *udp;
251  gtpu_header_t *gtpu;
252  /* Fixed portion of the (outer) ip header */
253  if (!is_ip6)
254  {
255  ip4_header_t *ip = &r.h4->ip4;
256  udp = &r.h4->udp;
257  gtpu = &r.h4->gtpu;
258  ip->ip_version_and_header_length = 0x45;
259  ip->ttl = 254;
260  ip->protocol = IP_PROTOCOL_UDP;
261 
262  ip->src_address = t->src.ip4;
263  ip->dst_address = t->dst.ip4;
264 
265  /* we fix up the ip4 header length and checksum after-the-fact */
266  ip->checksum = ip4_header_checksum (ip);
267  }
268  else
269  {
270  ip6_header_t *ip = &r.h6->ip6;
271  udp = &r.h6->udp;
272  gtpu = &r.h6->gtpu;
274  clib_host_to_net_u32 (6 << 28);
275  ip->hop_limit = 255;
276  ip->protocol = IP_PROTOCOL_UDP;
277 
278  ip->src_address = t->src.ip6;
279  ip->dst_address = t->dst.ip6;
280  }
281 
282  /* UDP header, randomize src port on something, maybe? */
283  udp->src_port = clib_host_to_net_u16 (2152);
284  udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_GTPU);
285 
286  /* GTPU header */
288  gtpu->type = GTPU_TYPE_GTPU;
289  gtpu->teid = clib_host_to_net_u32 (t->teid);
290 
291  t->rewrite = r.rw;
292  /* Now only support 8-byte gtpu header. TBD */
293  _vec_len (t->rewrite) = sizeof (ip4_gtpu_header_t) - 4;
294 
295  return;
296 }
297 
298 static bool
300 {
301  vlib_main_t *vm = gtm->vlib_main;
302  u32 input_idx = (!is_ip6) ? gtpu4_input_node.index : gtpu6_input_node.index;
303  vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
304 
305  return decap_next_index < r->n_next_nodes;
306 }
307 
308 typedef CLIB_PACKED (union
309  {
310  struct
311  {
312  fib_node_index_t mfib_entry_index;
313  adj_index_t mcast_adj_index;
314  }; u64 as_u64;
315  }) mcast_shared_t;
316 
317 static inline mcast_shared_t
318 mcast_shared_get (ip46_address_t * ip)
319 {
321  uword *p = hash_get_mem (gtpu_main.mcast_shared, ip);
322  ALWAYS_ASSERT (p);
323  return (mcast_shared_t)
324  {
325  .as_u64 = *p};
326 }
327 
328 static inline void
329 mcast_shared_add (ip46_address_t * dst, fib_node_index_t mfei, adj_index_t ai)
330 {
331  mcast_shared_t new_ep = {
332  .mcast_adj_index = ai,
333  .mfib_entry_index = mfei,
334  };
335 
336  hash_set_mem_alloc (&gtpu_main.mcast_shared, dst, new_ep.as_u64);
337 }
338 
339 static inline void
340 mcast_shared_remove (ip46_address_t * dst)
341 {
342  mcast_shared_t ep = mcast_shared_get (dst);
343 
344  adj_unlock (ep.mcast_adj_index);
345  mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_GTPU);
346 
347  hash_unset_mem_free (&gtpu_main.mcast_shared, dst);
348 }
349 
351  (vnet_gtpu_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
352 {
353  gtpu_main_t *gtm = &gtpu_main;
354  gtpu_tunnel_t *t = 0;
355  vnet_main_t *vnm = gtm->vnet_main;
356  uword *p;
357  u32 hw_if_index = ~0;
358  u32 sw_if_index = ~0;
359  gtpu4_tunnel_key_t key4;
360  gtpu6_tunnel_key_t key6;
361  bool is_ip6 = !ip46_address_is_ip4 (&a->dst);
362 
363  if (!is_ip6)
364  {
365  key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
366  key4.teid = clib_host_to_net_u32 (a->teid);
367  p = hash_get (gtm->gtpu4_tunnel_by_key, key4.as_u64);
368  }
369  else
370  {
371  key6.src = a->dst.ip6;
372  key6.teid = clib_host_to_net_u32 (a->teid);
373  p = hash_get_mem (gtm->gtpu6_tunnel_by_key, &key6);
374  }
375 
376  if (a->is_add)
377  {
378  l2input_main_t *l2im = &l2input_main;
379 
380  /* adding a tunnel: tunnel must not already exist */
381  if (p)
382  return VNET_API_ERROR_TUNNEL_EXIST;
383 
384  /*if not set explicitly, default to l2 */
385  if (a->decap_next_index == ~0)
386  a->decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
387  if (!gtpu_decap_next_is_valid (gtm, is_ip6, a->decap_next_index))
388  return VNET_API_ERROR_INVALID_DECAP_NEXT;
389 
391  clib_memset (t, 0, sizeof (*t));
392 
393  /* copy from arg structure */
394 #define _(x) t->x = a->x;
396 #undef _
397 
398  ip_udp_gtpu_rewrite (t, is_ip6);
399 
400  /* clear the flow index */
401  t->flow_index = ~0;
402 
403  /* copy the key */
404  if (is_ip6)
406  t - gtm->tunnels);
407  else
408  hash_set (gtm->gtpu4_tunnel_by_key, key4.as_u64, t - gtm->tunnels);
409 
412  {
414  hw_if_index = gtm->free_gtpu_tunnel_hw_if_indices
416  _vec_len (gtm->free_gtpu_tunnel_hw_if_indices) -= 1;
417 
418  hi = vnet_get_hw_interface (vnm, hw_if_index);
419  hi->dev_instance = t - gtm->tunnels;
420  hi->hw_instance = hi->dev_instance;
421 
422  /* clear old stats of freed tunnel before reuse */
423  sw_if_index = hi->sw_if_index;
427  sw_if_index);
430  sw_if_index);
433  sw_if_index);
435  }
436  else
437  {
438  hw_if_index = vnet_register_interface
439  (vnm, gtpu_device_class.index, t - gtm->tunnels,
440  gtpu_hw_class.index, t - gtm->tunnels);
441  hi = vnet_get_hw_interface (vnm, hw_if_index);
442  }
443 
444  /* Set gtpu tunnel output node */
445  u32 encap_index = !is_ip6 ?
446  gtpu4_encap_node.index : gtpu6_encap_node.index;
447  vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
448 
449  t->hw_if_index = hw_if_index;
450  t->sw_if_index = sw_if_index = hi->sw_if_index;
451 
453  ~0);
455 
456  /* setup l2 input config with l2 feature and bd 0 to drop packet */
457  vec_validate (l2im->configs, sw_if_index);
458  l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
459  l2im->configs[sw_if_index].bd_index = 0;
460 
461  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
463  vnet_sw_interface_set_flags (vnm, sw_if_index,
465 
466  fib_node_init (&t->node, gtm->fib_node_type);
467  fib_prefix_t tun_dst_pfx;
469 
470  fib_prefix_from_ip46_addr (&t->dst, &tun_dst_pfx);
471  if (!ip46_address_is_multicast (&t->dst))
472  {
473  /* Unicast tunnel -
474  * Track the FIB entry for the tunnel's destination.
475  * The tunnel will then get poked
476  * when the forwarding for the entry updates, and the tunnel can
477  * re-stack accordingly
478  */
479  vtep_addr_ref (&gtm->vtep_table, t->encap_fib_index, &t->src);
481  &tun_dst_pfx,
482  gtm->fib_node_type,
483  t - gtm->tunnels,
484  &t->sibling_index);
486  }
487  else
488  {
489  /* Multicast tunnel -
490  * as the same mcast group can be used for multiple mcast tunnels
491  * with different VNIs, create the output adjacency only if
492  * it does not already exist
493  */
494  fib_protocol_t fp = fib_ip_proto (is_ip6);
495 
496  if (vtep_addr_ref (&gtm->vtep_table,
497  t->encap_fib_index, &t->dst) == 1)
498  {
499  fib_node_index_t mfei;
500  adj_index_t ai;
502  .frp_proto = fib_proto_to_dpo (fp),
503  .frp_addr = zero_addr,
504  .frp_sw_if_index = 0xffffffff,
505  .frp_fib_index = ~0,
506  .frp_weight = 1,
507  .frp_flags = FIB_ROUTE_PATH_LOCAL,
508  .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
509  };
510  const mfib_prefix_t mpfx = {
511  .fp_proto = fp,
512  .fp_len = (is_ip6 ? 128 : 32),
513  .fp_grp_addr = tun_dst_pfx.fp_addr,
514  };
515 
516  /*
517  * Setup the (*,G) to receive traffic on the mcast group
518  * - the forwarding interface is for-us
519  * - the accepting interface is that from the API
520  */
522  &mpfx, MFIB_SOURCE_GTPU, &path);
523 
528  &mpfx,
529  MFIB_SOURCE_GTPU, &path);
530 
531  /*
532  * Create the mcast adjacency to send traffic to the group
533  */
534  ai = adj_mcast_add_or_lock (fp,
535  fib_proto_to_link (fp),
536  a->mcast_sw_if_index);
537 
538  /*
539  * create a new end-point
540  */
541  mcast_shared_add (&t->dst, mfei, ai);
542  }
543 
544  dpo_id_t dpo = DPO_INVALID;
545  mcast_shared_t ep = mcast_shared_get (&t->dst);
546 
547  /* Stack shared mcast dst mac addr rewrite on encap */
549  fib_proto_to_dpo (fp), ep.mcast_adj_index);
550 
551  dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
552 
553  dpo_reset (&dpo);
554  flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
555  }
556 
557  vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
558  flood_class;
559  }
560  else
561  {
562  /* deleting a tunnel: tunnel must exist */
563  if (!p)
564  return VNET_API_ERROR_NO_SUCH_ENTRY;
565 
566  t = pool_elt_at_index (gtm->tunnels, p[0]);
567  sw_if_index = t->sw_if_index;
568 
569  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
572 
573  /* make sure tunnel is removed from l2 bd or xconnect */
574  set_int_l2_mode (gtm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0,
575  L2_BD_PORT_TYPE_NORMAL, 0, 0);
577 
579 
580  if (!is_ip6)
581  hash_unset (gtm->gtpu4_tunnel_by_key, key4.as_u64);
582  else
584 
585  if (!ip46_address_is_multicast (&t->dst))
586  {
587  if (t->flow_index != ~0)
588  vnet_flow_del (vnm, t->flow_index);
589 
592  }
593  else if (vtep_addr_unref (&gtm->vtep_table,
594  t->encap_fib_index, &t->dst) == 0)
595  {
596  mcast_shared_remove (&t->dst);
597  }
598 
599  fib_node_deinit (&t->node);
600  vec_free (t->rewrite);
601  pool_put (gtm->tunnels, t);
602  }
603 
604  if (sw_if_indexp)
605  *sw_if_indexp = sw_if_index;
606 
607  if (a->is_add)
608  {
609  /* register udp ports */
610  if (!is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_GTPU, 1))
611  udp_register_dst_port (gtm->vlib_main, UDP_DST_PORT_GTPU,
612  gtpu4_input_node.index, /* is_ip4 */ 1);
613  if (is_ip6 && !udp_is_valid_dst_port (UDP_DST_PORT_GTPU6, 0))
614  udp_register_dst_port (gtm->vlib_main, UDP_DST_PORT_GTPU6,
615  gtpu6_input_node.index, /* is_ip4 */ 0);
616  }
617 
618  return 0;
619 }
620 
621 static uword
622 get_decap_next_for_node (u32 node_index, u32 ipv4_set)
623 {
624  gtpu_main_t *gtm = &gtpu_main;
625  vlib_main_t *vm = gtm->vlib_main;
626  uword input_node = (ipv4_set) ? gtpu4_input_node.index :
627  gtpu6_input_node.index;
628 
629  return vlib_node_add_next (vm, input_node, node_index);
630 }
631 
632 static uword
633 unformat_decap_next (unformat_input_t * input, va_list * args)
634 {
635  u32 *result = va_arg (*args, u32 *);
636  u32 ipv4_set = va_arg (*args, int);
637  gtpu_main_t *gtm = &gtpu_main;
638  vlib_main_t *vm = gtm->vlib_main;
639  u32 node_index;
640  u32 tmp;
641 
642  if (unformat (input, "l2"))
643  *result = GTPU_INPUT_NEXT_L2_INPUT;
644  else if (unformat (input, "ip4"))
645  *result = GTPU_INPUT_NEXT_IP4_INPUT;
646  else if (unformat (input, "ip6"))
647  *result = GTPU_INPUT_NEXT_IP6_INPUT;
648  else if (unformat (input, "node %U", unformat_vlib_node, vm, &node_index))
649  *result = get_decap_next_for_node (node_index, ipv4_set);
650  else if (unformat (input, "%d", &tmp))
651  *result = tmp;
652  else
653  return 0;
654 
655  return 1;
656 }
657 
658 static clib_error_t *
660  unformat_input_t * input,
661  vlib_cli_command_t * cmd)
662 {
663  unformat_input_t _line_input, *line_input = &_line_input;
664  ip46_address_t src, dst;
665  u8 is_add = 1;
666  u8 src_set = 0;
667  u8 dst_set = 0;
668  u8 grp_set = 0;
669  u8 ipv4_set = 0;
670  u8 ipv6_set = 0;
671  u32 encap_fib_index = 0;
672  u32 mcast_sw_if_index = ~0;
673  u32 decap_next_index = GTPU_INPUT_NEXT_L2_INPUT;
674  u32 teid = 0;
675  u32 tmp;
676  int rv;
677  vnet_gtpu_add_del_tunnel_args_t _a, *a = &_a;
678  u32 tunnel_sw_if_index;
679  clib_error_t *error = NULL;
680 
681  /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
682  clib_memset (&src, 0, sizeof src);
683  clib_memset (&dst, 0, sizeof dst);
684 
685  /* Get a line of input. */
686  if (!unformat_user (input, unformat_line_input, line_input))
687  return 0;
688 
689  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
690  {
691  if (unformat (line_input, "del"))
692  {
693  is_add = 0;
694  }
695  else if (unformat (line_input, "src %U",
696  unformat_ip4_address, &src.ip4))
697  {
698  src_set = 1;
699  ipv4_set = 1;
700  }
701  else if (unformat (line_input, "dst %U",
702  unformat_ip4_address, &dst.ip4))
703  {
704  dst_set = 1;
705  ipv4_set = 1;
706  }
707  else if (unformat (line_input, "src %U",
708  unformat_ip6_address, &src.ip6))
709  {
710  src_set = 1;
711  ipv6_set = 1;
712  }
713  else if (unformat (line_input, "dst %U",
714  unformat_ip6_address, &dst.ip6))
715  {
716  dst_set = 1;
717  ipv6_set = 1;
718  }
719  else if (unformat (line_input, "group %U %U",
720  unformat_ip4_address, &dst.ip4,
722  vnet_get_main (), &mcast_sw_if_index))
723  {
724  grp_set = dst_set = 1;
725  ipv4_set = 1;
726  }
727  else if (unformat (line_input, "group %U %U",
728  unformat_ip6_address, &dst.ip6,
730  vnet_get_main (), &mcast_sw_if_index))
731  {
732  grp_set = dst_set = 1;
733  ipv6_set = 1;
734  }
735  else if (unformat (line_input, "encap-vrf-id %d", &tmp))
736  {
737  encap_fib_index = fib_table_find (fib_ip_proto (ipv6_set), tmp);
738  if (encap_fib_index == ~0)
739  {
740  error =
741  clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
742  goto done;
743  }
744  }
745  else if (unformat (line_input, "decap-next %U", unformat_decap_next,
746  &decap_next_index, ipv4_set))
747  ;
748  else if (unformat (line_input, "teid %d", &teid))
749  ;
750  else
751  {
752  error = clib_error_return (0, "parse error: '%U'",
753  format_unformat_error, line_input);
754  goto done;
755  }
756  }
757 
758  if (src_set == 0)
759  {
760  error = clib_error_return (0, "tunnel src address not specified");
761  goto done;
762  }
763 
764  if (dst_set == 0)
765  {
766  error = clib_error_return (0, "tunnel dst address not specified");
767  goto done;
768  }
769 
770  if (grp_set && !ip46_address_is_multicast (&dst))
771  {
772  error = clib_error_return (0, "tunnel group address not multicast");
773  goto done;
774  }
775 
776  if (grp_set == 0 && ip46_address_is_multicast (&dst))
777  {
778  error = clib_error_return (0, "dst address must be unicast");
779  goto done;
780  }
781 
782  if (grp_set && mcast_sw_if_index == ~0)
783  {
784  error = clib_error_return (0, "tunnel nonexistent multicast device");
785  goto done;
786  }
787 
788  if (ipv4_set && ipv6_set)
789  {
790  error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
791  goto done;
792  }
793 
794  if (ip46_address_cmp (&src, &dst) == 0)
795  {
796  error = clib_error_return (0, "src and dst addresses are identical");
797  goto done;
798  }
799 
800  if (decap_next_index == ~0)
801  {
802  error = clib_error_return (0, "next node not found");
803  goto done;
804  }
805 
806  clib_memset (a, 0, sizeof (*a));
807 
808  a->is_add = is_add;
809 
810 #define _(x) a->x = x;
812 #undef _
813 
814  rv = vnet_gtpu_add_del_tunnel (a, &tunnel_sw_if_index);
815 
816  switch (rv)
817  {
818  case 0:
819  if (is_add)
821  vnet_get_main (), tunnel_sw_if_index);
822  break;
823 
824  case VNET_API_ERROR_TUNNEL_EXIST:
825  error = clib_error_return (0, "tunnel already exists...");
826  goto done;
827 
828  case VNET_API_ERROR_NO_SUCH_ENTRY:
829  error = clib_error_return (0, "tunnel does not exist...");
830  goto done;
831 
832  default:
833  error = clib_error_return
834  (0, "vnet_gtpu_add_del_tunnel returned %d", rv);
835  goto done;
836  }
837 
838 done:
839  unformat_free (line_input);
840 
841  return error;
842 }
843 
844 /*?
845  * Add or delete a GTPU Tunnel.
846  *
847  * GTPU provides the features needed to allow L2 bridge domains (BDs)
848  * to span multiple servers. This is done by building an L2 overlay on
849  * top of an L3 network underlay using GTPU tunnels.
850  *
851  * This makes it possible for servers to be co-located in the same data
852  * center or be separated geographically as long as they are reachable
853  * through the underlay L3 network.
854  *
855  * You can refer to this kind of L2 overlay bridge domain as a GTPU
856  * (Virtual eXtensible VLAN) segment.
857  *
858  * @cliexpar
859  * Example of how to create a GTPU Tunnel:
860  * @cliexcmd{create gtpu tunnel src 10.0.3.1 dst 10.0.3.3 teid 13 encap-vrf-id 7}
861  * Example of how to delete a GTPU Tunnel:
862  * @cliexcmd{create gtpu tunnel src 10.0.3.1 dst 10.0.3.3 teid 13 del}
863  ?*/
864 /* *INDENT-OFF* */
865 VLIB_CLI_COMMAND (create_gtpu_tunnel_command, static) = {
866  .path = "create gtpu tunnel",
867  .short_help =
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]",
871  .function = gtpu_add_del_tunnel_command_fn,
872 };
873 /* *INDENT-ON* */
874 
875 static clib_error_t *
877  unformat_input_t * input,
878  vlib_cli_command_t * cmd)
879 {
880  gtpu_main_t *gtm = &gtpu_main;
881  gtpu_tunnel_t *t;
882 
883  if (pool_elts (gtm->tunnels) == 0)
884  vlib_cli_output (vm, "No gtpu tunnels configured...");
885 
886  pool_foreach (t, gtm->tunnels, (
887  {
888  vlib_cli_output (vm, "%U",
889  format_gtpu_tunnel, t);
890  }
891  ));
892 
893  return 0;
894 }
895 
896 /*?
897  * Display all the GTPU Tunnel entries.
898  *
899  * @cliexpar
900  * Example of how to display the GTPU Tunnel entries:
901  * @cliexstart{show gtpu tunnel}
902  * [0] src 10.0.3.1 dst 10.0.3.3 teid 13 encap_fib_index 0 sw_if_index 5 decap_next l2
903  * @cliexend
904  ?*/
905 /* *INDENT-OFF* */
906 VLIB_CLI_COMMAND (show_gtpu_tunnel_command, static) = {
907  .path = "show gtpu tunnel",
908  .short_help = "show gtpu tunnel",
909  .function = show_gtpu_tunnel_command_fn,
910 };
911 /* *INDENT-ON* */
912 
913 void
915 {
916  if (is_ip6)
917  vnet_feature_enable_disable ("ip6-unicast", "ip6-gtpu-bypass",
918  sw_if_index, is_enable, 0, 0);
919  else
920  vnet_feature_enable_disable ("ip4-unicast", "ip4-gtpu-bypass",
921  sw_if_index, is_enable, 0, 0);
922 }
923 
924 static clib_error_t *
926  unformat_input_t * input, vlib_cli_command_t * cmd)
927 {
928  unformat_input_t _line_input, *line_input = &_line_input;
929  vnet_main_t *vnm = vnet_get_main ();
930  clib_error_t *error = 0;
931  u32 sw_if_index, is_enable;
932 
933  sw_if_index = ~0;
934  is_enable = 1;
935 
936  if (!unformat_user (input, unformat_line_input, line_input))
937  return 0;
938 
939  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
940  {
941  if (unformat_user
942  (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
943  ;
944  else if (unformat (line_input, "del"))
945  is_enable = 0;
946  else
947  {
948  error = unformat_parse_error (line_input);
949  goto done;
950  }
951  }
952 
953  if (~0 == sw_if_index)
954  {
955  error = clib_error_return (0, "unknown interface `%U'",
956  format_unformat_error, line_input);
957  goto done;
958  }
959 
960  vnet_int_gtpu_bypass_mode (sw_if_index, is_ip6, is_enable);
961 
962 done:
963  unformat_free (line_input);
964 
965  return error;
966 }
967 
968 static clib_error_t *
970  unformat_input_t * input, vlib_cli_command_t * cmd)
971 {
972  return set_ip_gtpu_bypass (0, input, cmd);
973 }
974 
975 /*?
976  * This command adds the 'ip4-gtpu-bypass' graph node for a given interface.
977  * By adding the IPv4 gtpu-bypass graph node to an interface, the node checks
978  * for and validate input gtpu packet and bypass ip4-lookup, ip4-local,
979  * ip4-udp-lookup nodes to speedup gtpu packet forwarding. This node will
980  * cause extra overhead to for non-gtpu packets which is kept at a minimum.
981  *
982  * @cliexpar
983  * @parblock
984  * Example of graph node before ip4-gtpu-bypass is enabled:
985  * @cliexstart{show vlib graph ip4-gtpu-bypass}
986  * Name Next Previous
987  * ip4-gtpu-bypass error-drop [0]
988  * gtpu4-input [1]
989  * ip4-lookup [2]
990  * @cliexend
991  *
992  * Example of how to enable ip4-gtpu-bypass on an interface:
993  * @cliexcmd{set interface ip gtpu-bypass GigabitEthernet2/0/0}
994  *
995  * Example of graph node after ip4-gtpu-bypass is enabled:
996  * @cliexstart{show vlib graph ip4-gtpu-bypass}
997  * Name Next Previous
998  * ip4-gtpu-bypass error-drop [0] ip4-input
999  * gtpu4-input [1] ip4-input-no-checksum
1000  * ip4-lookup [2]
1001  * @cliexend
1002  *
1003  * Example of how to display the feature enabled on an interface:
1004  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1005  * IP feature paths configured on GigabitEthernet2/0/0...
1006  * ...
1007  * ipv4 unicast:
1008  * ip4-gtpu-bypass
1009  * ip4-lookup
1010  * ...
1011  * @cliexend
1012  *
1013  * Example of how to disable ip4-gtpu-bypass on an interface:
1014  * @cliexcmd{set interface ip gtpu-bypass GigabitEthernet2/0/0 del}
1015  * @endparblock
1016 ?*/
1017 /* *INDENT-OFF* */
1018 VLIB_CLI_COMMAND (set_interface_ip_gtpu_bypass_command, static) = {
1019  .path = "set interface ip gtpu-bypass",
1020  .function = set_ip4_gtpu_bypass,
1021  .short_help = "set interface ip gtpu-bypass <interface> [del]",
1022 };
1023 /* *INDENT-ON* */
1024 
1025 static clib_error_t *
1027  unformat_input_t * input, vlib_cli_command_t * cmd)
1028 {
1029  return set_ip_gtpu_bypass (1, input, cmd);
1030 }
1031 
1032 /*?
1033  * This command adds the 'ip6-gtpu-bypass' graph node for a given interface.
1034  * By adding the IPv6 gtpu-bypass graph node to an interface, the node checks
1035  * for and validate input gtpu packet and bypass ip6-lookup, ip6-local,
1036  * ip6-udp-lookup nodes to speedup gtpu packet forwarding. This node will
1037  * cause extra overhead to for non-gtpu packets which is kept at a minimum.
1038  *
1039  * @cliexpar
1040  * @parblock
1041  * Example of graph node before ip6-gtpu-bypass is enabled:
1042  * @cliexstart{show vlib graph ip6-gtpu-bypass}
1043  * Name Next Previous
1044  * ip6-gtpu-bypass error-drop [0]
1045  * gtpu6-input [1]
1046  * ip6-lookup [2]
1047  * @cliexend
1048  *
1049  * Example of how to enable ip6-gtpu-bypass on an interface:
1050  * @cliexcmd{set interface ip6 gtpu-bypass GigabitEthernet2/0/0}
1051  *
1052  * Example of graph node after ip6-gtpu-bypass is enabled:
1053  * @cliexstart{show vlib graph ip6-gtpu-bypass}
1054  * Name Next Previous
1055  * ip6-gtpu-bypass error-drop [0] ip6-input
1056  * gtpu6-input [1] ip4-input-no-checksum
1057  * ip6-lookup [2]
1058  * @cliexend
1059  *
1060  * Example of how to display the feature enabled on an interface:
1061  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1062  * IP feature paths configured on GigabitEthernet2/0/0...
1063  * ...
1064  * ipv6 unicast:
1065  * ip6-gtpu-bypass
1066  * ip6-lookup
1067  * ...
1068  * @cliexend
1069  *
1070  * Example of how to disable ip6-gtpu-bypass on an interface:
1071  * @cliexcmd{set interface ip6 gtpu-bypass GigabitEthernet2/0/0 del}
1072  * @endparblock
1073 ?*/
1074 /* *INDENT-OFF* */
1075 VLIB_CLI_COMMAND (set_interface_ip6_gtpu_bypass_command, static) = {
1076  .path = "set interface ip6 gtpu-bypass",
1077  .function = set_ip6_gtpu_bypass,
1078  .short_help = "set interface ip6 gtpu-bypass <interface> [del]",
1079 };
1080 /* *INDENT-ON* */
1081 
1082 int
1083 vnet_gtpu_add_del_rx_flow (u32 hw_if_index, u32 t_index, int is_add)
1084 {
1085  gtpu_main_t *gtm = &gtpu_main;
1086  gtpu_tunnel_t *t = pool_elt_at_index (gtm->tunnels, t_index);
1087  vnet_main_t *vnm = vnet_get_main ();
1088  if (is_add)
1089  {
1090  if (t->flow_index == ~0)
1091  {
1092  vnet_flow_t flow = {
1093  .actions =
1094  VNET_FLOW_ACTION_REDIRECT_TO_NODE | VNET_FLOW_ACTION_MARK |
1095  VNET_FLOW_ACTION_BUFFER_ADVANCE,
1096  .mark_flow_id = t_index + gtm->flow_id_start,
1097  .redirect_node_index = gtpu4_flow_input_node.index,
1098  .buffer_advance = sizeof (ethernet_header_t)
1099  + sizeof (ip4_header_t) + sizeof (udp_header_t),
1100  .type = VNET_FLOW_TYPE_IP4_GTPU,
1101  .ip4_gtpu = {
1102  .protocol = IP_PROTOCOL_UDP,
1103  .src_addr.addr = t->dst.ip4,
1104  .src_addr.mask.as_u32 = ~0,
1105  .dst_addr.addr = t->src.ip4,
1106  .dst_addr.mask.as_u32 = ~0,
1107  .teid = t->teid,
1108  }
1109  ,
1110  };
1111  vnet_flow_add (vnm, &flow, &t->flow_index);
1112  }
1113 
1114  return vnet_flow_enable (vnm, t->flow_index, hw_if_index);
1115  }
1116 
1117  /* flow index is removed when the tunnel is deleted */
1118  return vnet_flow_disable (vnm, t->flow_index, hw_if_index);
1119 }
1120 
1121 u32
1123 {
1124  gtpu_main_t *gtm = &gtpu_main;
1125 
1126  if (sw_if_index >= vec_len (gtm->tunnel_index_by_sw_if_index))
1127  return ~0;
1129 }
1130 
1131 static clib_error_t *
1133  unformat_input_t * input, vlib_cli_command_t * cmd)
1134 {
1135  unformat_input_t _line_input, *line_input = &_line_input;
1136 
1137  /* Get a line of input. */
1138  if (!unformat_user (input, unformat_line_input, line_input))
1139  return 0;
1140 
1141  vnet_main_t *vnm = vnet_get_main ();
1142  u32 rx_sw_if_index = ~0;
1143  u32 hw_if_index = ~0;
1144  int is_add = 1;
1145 
1146  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1147  {
1148  if (unformat (line_input, "hw %U", unformat_vnet_hw_interface, vnm,
1149  &hw_if_index))
1150  continue;
1151  if (unformat (line_input, "rx %U", unformat_vnet_sw_interface, vnm,
1152  &rx_sw_if_index))
1153  continue;
1154  if (unformat (line_input, "del"))
1155  {
1156  is_add = 0;
1157  continue;
1158  }
1159  return clib_error_return (0, "unknown input `%U'",
1160  format_unformat_error, line_input);
1161  }
1162 
1163  if (rx_sw_if_index == ~0)
1164  return clib_error_return (0, "missing rx interface");
1165  if (hw_if_index == ~0)
1166  return clib_error_return (0, "missing hw interface");
1167 
1168  u32 t_index = vnet_gtpu_get_tunnel_index (rx_sw_if_index);;
1169  if (t_index == ~0)
1170  return clib_error_return (0, "%U is not a gtpu tunnel",
1172  rx_sw_if_index);
1173 
1174  gtpu_main_t *gtm = &gtpu_main;
1175  gtpu_tunnel_t *t = pool_elt_at_index (gtm->tunnels, t_index);
1176 
1177  /* first support ipv4 hw offload */
1178  if (!ip46_address_is_ip4 (&t->dst))
1179  return clib_error_return (0, "currently only IPV4 tunnels are supported");
1180 
1181  /* inner protocol should be IPv4/IPv6 */
1182  if ((t->decap_next_index != GTPU_INPUT_NEXT_IP4_INPUT) &&
1183  (t->decap_next_index != GTPU_INPUT_NEXT_IP6_INPUT))
1184  return clib_error_return (0,
1185  "currently only inner IPv4/IPv6 protocol is supported");
1186 
1187  vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1188  ip4_main_t *im = &ip4_main;
1189  u32 rx_fib_index =
1191 
1192  if (t->encap_fib_index != rx_fib_index)
1193  return clib_error_return (0, "interface/tunnel fib mismatch");
1194 
1195  if (vnet_gtpu_add_del_rx_flow (hw_if_index, t_index, is_add))
1196  return clib_error_return (0, "error %s flow",
1197  is_add ? "enabling" : "disabling");
1198 
1199  return 0;
1200 }
1201 
1202 
1203 /* *INDENT-OFF* */
1204 VLIB_CLI_COMMAND (gtpu_offload_command, static) = {
1205  .path = "set flow-offload gtpu",
1206  .short_help =
1207  "set flow-offload gtpu hw <inerface-name> rx <tunnel-name> [del]",
1208  .function = gtpu_offload_command_fn,
1209 };
1210 /* *INDENT-ON* */
1211 
1212 clib_error_t *
1214 {
1215  gtpu_main_t *gtm = &gtpu_main;
1216 
1217  gtm->vnet_main = vnet_get_main ();
1218  gtm->vlib_main = vm;
1219 
1220  vnet_flow_get_range (gtm->vnet_main, "gtpu", 1024 * 1024,
1221  &gtm->flow_id_start);
1222 
1223  /* initialize the ip6 hash */
1225  sizeof (gtpu6_tunnel_key_t),
1226  sizeof (uword));
1227  gtm->vtep_table = vtep_table_create ();
1228  gtm->mcast_shared = hash_create_mem (0,
1229  sizeof (ip46_address_t),
1230  sizeof (mcast_shared_t));
1231 
1232  gtm->fib_node_type = fib_node_register_new_type (&gtpu_vft);
1233 
1234  return 0;
1235 }
1236 
1238 
1239 /* *INDENT-OFF* */
1240 VLIB_PLUGIN_REGISTER () = {
1241  .version = VPP_BUILD_VER,
1242  .description = "GPRS Tunnelling Protocol, User Data (GTPv1-U)",
1243 };
1244 /* *INDENT-ON* */
1245 
1246 /*
1247  * fd.io coding-style-patch-verification: ON
1248  *
1249  * Local Variables:
1250  * eval: (c-set-style "gnu")
1251  * End:
1252  */
unformat_function_t unformat_vnet_hw_interface
vlib_main_t * vlib_main
Definition: gtpu.h:234
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:507
vlib_node_registration_t gtpu4_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu4_encap_node)
Definition: gtpu_encap.c:687
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.
Definition: dpo.c:531
clib_error_t * gtpu_init(vlib_main_t *vm)
Definition: gtpu.c:1213
fib_node_index_t fib_entry_track(u32 fib_index, const fib_prefix_t *prefix, fib_node_type_t child_type, index_t child_index, u32 *sibling)
Trackers are used on FIB entries by objects that which to track the changing state of the entry...
#define GTPU_PT_GTP
Definition: mobile.h:164
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:113
#define hash_set(h, key, value)
Definition: hash.h:255
l2_input_config_t * configs
Definition: l2_input.h:62
#define CLIB_UNUSED(x)
Definition: clib.h:86
uword vtep_addr_ref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:19
vnet_main_t * vnet_main
Definition: gtpu.h:235
static uword ip46_address_is_multicast(const ip46_address_t *a)
Definition: ip46_address.h:154
int vnet_flow_get_range(vnet_main_t *vnm, char *owner, u32 count, u32 *start)
Definition: flow.c:24
#define hash_unset(h, key)
Definition: hash.h:261
static uword get_decap_next_for_node(u32 node_index, u32 ipv4_set)
Definition: gtpu.c:622
A representation of a path as described by a route producer.
Definition: fib_types.h:490
ip4_address_t src_address
Definition: ip4_packet.h:170
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
u32 teid
Definition: mobile.h:95
u32 teid
Definition: gtpu.h:139
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define GTPU_TYPE_GTPU
Definition: mobile.h:104
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
u64 as_u64
Definition: bihash_doc.h:63
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)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:325
u32 frp_mitf_flags
MFIB interface flags.
Definition: fib_types.h:559
static mcast_shared_t mcast_shared_get(ip46_address_t *ip)
Definition: geneve.c:306
unsigned long u64
Definition: types.h:89
u32 * tunnel_index_by_sw_if_index
Definition: gtpu.h:223
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
fib_node_type_t fib_node_type
Node type for registering to fib changes.
Definition: gtpu.h:228
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
#define foreach_copy_field
Definition: gtpu.c:227
void fib_entry_contribute_forwarding(fib_node_index_t fib_entry_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_entry.c:437
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:590
vl_api_address_t src
Definition: gre.api:54
vlib_node_registration_t gtpu4_flow_input_node
(constructor) VLIB_REGISTER_NODE (gtpu4_flow_input_node)
Definition: gtpu_decap.c:1723
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:109
VNET_FEATURE_INIT(ip4_gtpu_bypass, static)
static void gtpu_tunnel_restack_dpo(gtpu_tunnel_t *t)
Definition: gtpu.c:158
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:69
void fib_node_deinit(fib_node_t *node)
Definition: fib_node.c:197
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:122
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unformat_function_t unformat_vnet_sw_interface
vl_api_fib_path_t path
Definition: mfib_types.api:34
u32 vnet_gtpu_get_tunnel_index(u32 sw_if_index)
Definition: gtpu.c:1122
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:518
typedef CLIB_PACKED(union { struct { fib_node_index_t mfib_entry_index;adj_index_t mcast_adj_index;};u64 as_u64;})
Definition: gtpu.c:308
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
int vnet_flow_disable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:135
ip6_address_t src_address
Definition: ip6_packet.h:310
format_function_t format_vnet_sw_if_index_name
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
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.
Definition: fib_node.c:80
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static u8 * format_decap_next(u8 *s, va_list *args)
Definition: gtpu.c:65
static fib_node_t * gtpu_tunnel_fib_node_get(fib_node_index_t index)
Function definition to get a FIB node from its index.
Definition: gtpu.c:193
u8 * format_gtpu_encap_trace(u8 *s, va_list *args)
Definition: gtpu.c:52
VNET_DEVICE_CLASS(gtpu_device_class, static)
static u8 * format_gtpu_name(u8 *s, va_list *args)
Definition: gtpu.c:114
vnet_flood_class_t flood_class
Definition: interface.h:749
VNET_HW_INTERFACE_CLASS(gtpu_hw_class)
static gtpu_tunnel_t * gtpu_tunnel_from_fib_node(fib_node_t *node)
Definition: gtpu.c:172
dpo_id_t next_dpo
Definition: gtpu.h:136
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
unformat_function_t unformat_ip4_address
Definition: format.h:68
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:530
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
int vnet_gtpu_add_del_tunnel(vnet_gtpu_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: gtpu.c:351
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
ip46_address_t src
Definition: gtpu.h:142
void mfib_table_entry_delete_index(fib_node_index_t mfib_entry_index, mfib_source_t source)
Delete a FIB entry.
Definition: mfib_table.c:517
ip4_address_t dst_address
Definition: ip4_packet.h:170
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:867
static int ip46_address_cmp(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:80
vl_api_interface_index_t mcast_sw_if_index
Definition: vxlan_gbp.api:41
Aggregate type for a prefix.
Definition: fib_types.h:203
static clib_error_t * show_gtpu_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:876
#define clib_error_return(e, args...)
Definition: error.h:99
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:325
#define ALWAYS_ASSERT(truth)
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1097
gtpu_main_t gtpu_main
Definition: gtpu.c:36
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:768
static u8 * format_gtpu_header_with_length(u8 *s, va_list *args)
Definition: gtpu.c:140
bool is_ip6
Definition: ip.api:43
u8 * format_gtpu_tunnel(u8 *s, va_list *args)
Definition: gtpu.c:86
unformat_function_t unformat_line_input
Definition: format.h:283
vl_api_fib_path_type_t type
Definition: fib_types.api:123
int vnet_flow_del(vnet_main_t *vnm, u32 flow_index)
Definition: flow.c:67
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
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.
Definition: counter.h:285
u32 decap_next_index
Definition: gtpu.h:149
uword vtep_addr_unref(vtep_table_t *t, u32 fib_index, ip46_address_t *ip)
Definition: vtep.c:34
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
u32 flow_id_start
Definition: gtpu.h:236
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
#define PREDICT_FALSE(x)
Definition: clib.h:118
vnet_sw_interface_flags_t flags
Definition: interface.h:724
ip6_main_t ip6_main
Definition: ip6_forward.c:2784
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:866
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...
Definition: gtpu.c:183
An node in the FIB graph.
Definition: fib_node.h:295
vl_api_address_t dst
Definition: gre.api:55
static clib_error_t * gtpu_add_del_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:659
vlib_main_t * vm
Definition: in2out_ed.c:1599
ip46_address_t dst
Definition: gtpu.h:143
u8 len
Definition: ip_types.api:92
format_function_t format_ip46_address
Definition: ip46_address.h:50
unformat_function_t unformat_ip6_address
Definition: format.h:89
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:246
static void ip_udp_gtpu_rewrite(gtpu_tunnel_t *t, bool is_ip6)
Definition: gtpu.c:236
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 flags
Definition: vhost_user.h:248
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
vnet_flood_class_t
Definition: interface.h:665
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:89
fib_node_get_t fnv_get
Definition: fib_node.h:283
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:897
static void mcast_shared_remove(ip46_address_t *dst)
Definition: gtpu.c:340
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 sw_if_index
Definition: gtpu.h:155
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void fib_prefix_from_ip46_addr(const ip46_address_t *addr, fib_prefix_t *pfx)
Host prefix from ip.
Definition: fib_types.c:81
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.
Definition: dpo.c:186
u32 sibling_index
The tunnel is a child of the FIB entry for its destination.
Definition: gtpu.h:176
Aggregate type for a prefix.
Definition: mfib_types.h:24
static bool gtpu_decap_next_is_valid(gtpu_main_t *gtm, u32 is_ip6, u32 decap_next_index)
Definition: gtpu.c:299
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
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.
Definition: interface.c:1635
Context passed between object during a back walk.
Definition: fib_node.h:208
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
u32 * free_gtpu_tunnel_hw_if_indices
Definition: gtpu.h:220
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:890
static clib_error_t * set_ip4_gtpu_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:969
#define ASSERT(truth)
fib_node_index_t fib_entry_index
Definition: gtpu.h:167
void fib_entry_untrack(fib_node_index_t fei, u32 sibling)
Stop tracking a FIB entry.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
fib_node_t node
Linkage into the FIB object graph.
Definition: gtpu.h:161
u32 hw_if_index
Definition: gtpu.h:156
IPv4 main type.
Definition: ip4.h:106
static void gtpu_tunnel_last_lock_gone(fib_node_t *node)
Function definition to inform the FIB node that its last lock has gone.
Definition: gtpu.c:207
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, l2_bd_port_type_t port_type, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:591
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
Definition: fib_types.h:600
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
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.
Definition: counter.h:139
void vnet_int_gtpu_bypass_mode(u32 sw_if_index, u8 is_ip6, u8 is_enable)
Definition: gtpu.c:914
u32 encap_fib_index
Definition: gtpu.h:152
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:324
#define GTPU_V1_VER
Definition: mobile.h:162
int vnet_flow_add(vnet_main_t *vnm, vnet_flow_t *flow, u32 *flow_index)
Definition: flow.c:43
#define VNET_FEATURES(...)
Definition: feature.h:470
vtep_table_t vtep_table
Definition: gtpu.h:214
static vtep_table_t vtep_table_create()
Definition: vtep.h:70
vl_api_ip4_address_t hi
Definition: arp.api:37
uword * gtpu4_tunnel_by_key
Definition: gtpu.h:209
#define vec_elt(v, i)
Get vector value at index i.
u32 tunnel_index
Definition: gtpu.h:264
#define unformat_parse_error(input)
Definition: format.h:269
vlib_node_registration_t gtpu6_input_node
(constructor) VLIB_REGISTER_NODE (gtpu6_input_node)
Definition: gtpu_decap.c:768
static void mcast_shared_add(ip46_address_t *dst, fib_node_index_t mfei, adj_index_t ai)
Definition: gtpu.c:329
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:297
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
l2input_main_t l2input_main
Definition: l2_input.c:128
uword * mcast_shared
Definition: gtpu.h:217
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:186
u32 flow_index
Definition: gtpu.h:178
A for-us/local path.
Definition: fib_types.h:338
bool udp_is_valid_dst_port(udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:529
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static fib_protocol_t fib_ip_proto(bool is_ip6)
Convert from boolean is_ip6 to FIB protocol.
Definition: fib_types.h:80
uword * gtpu6_tunnel_by_key
Definition: gtpu.h:210
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:498
u64 uword
Definition: types.h:112
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
static clib_error_t * set_ip6_gtpu_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:1026
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:197
vlib_node_registration_t gtpu6_encap_node
(constructor) VLIB_REGISTER_NODE (gtpu6_encap_node)
Definition: gtpu_encap.c:702
a point 2 point interface
Definition: interface.h:375
int vnet_flow_enable(vnet_main_t *vnm, u32 flow_index, u32 hw_if_index)
Definition: flow.c:91
unformat_function_t unformat_vlib_node
Definition: node_funcs.h:1147
Bits Octets 8 7 6 5 4 3 2 1 1 Version PT (*) E S PN 2 Message Type 3 Length (1st Octet) 4 Length...
Definition: mobile.h:90
#define hash_get_mem(h, key)
Definition: hash.h:269
static clib_error_t * set_ip_gtpu_bypass(u32 is_ip6, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:925
A FIB graph nodes virtual function table.
Definition: fib_node.h:282
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
gtpu_tunnel_t * tunnels
Definition: gtpu.h:206
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:507
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:111
adj_index_t adj_mcast_add_or_lock(fib_protocol_t proto, vnet_link_t link_type, u32 sw_if_index)
Mcast Adjacency.
Definition: adj_mcast.c:51
u8 * rewrite
Definition: gtpu.h:133
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:232
VLIB_PLUGIN_REGISTER()
u8 ver_flags
Definition: mobile.h:92
vnet_link_t fib_proto_to_link(fib_protocol_t proto)
Convert from a protocol to a link type.
Definition: fib_types.c:358
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279
bool is_ipv6
Definition: dhcp.api:202
int vnet_gtpu_add_del_rx_flow(u32 hw_if_index, u32 t_index, int is_add)
Definition: gtpu.c:1083
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
u8 si
Definition: lisp_types.api:47
u8 ip_version_and_header_length
Definition: ip4_packet.h:138
static clib_error_t * gtpu_offload_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: gtpu.c:1132
static clib_error_t * gtpu_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: gtpu.c:121
#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)
Definition: vec.h:554
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vlib_node_registration_t gtpu4_input_node
(constructor) VLIB_REGISTER_NODE (gtpu4_input_node)
Definition: gtpu_decap.c:748
struct fib_table_t_ * fibs
Definition: ip6.h:184
static uword unformat_decap_next(unformat_input_t *input, va_list *args)
Definition: gtpu.c:633
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
icmpr_flow_t * flow
Definition: main.c:123
const ip46_address_t zero_addr
Definition: lookup.c:181
u32 mcast_sw_if_index
Definition: gtpu.h:146
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
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)
Definition: feature.c:304
ip6_address_t dst_address
Definition: ip6_packet.h:310
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
#define MODE_L3
Definition: l2_input.h:220
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128