FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
vxlan_gpe.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file
17  * @brief Common utility functions for IPv4 and IPv6 VXLAN GPE tunnels
18  *
19 */
21 #include <vnet/fib/fib.h>
22 #include <vnet/ip/format.h>
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vnet/mfib/mfib_table.h>
26 #include <vnet/adj/adj_mcast.h>
27 #include <vnet/interface.h>
28 #include <vlib/vlib.h>
29 
30 /**
31  * @file
32  * @brief VXLAN-GPE.
33  *
34  * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
35  * to span multiple servers. This is done by building an L2 overlay on
36  * top of an L3 network underlay using VXLAN-GPE tunnels.
37  *
38  * This makes it possible for servers to be co-located in the same data
39  * center or be separated geographically as long as they are reachable
40  * through the underlay L3 network.
41  *
42  * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment.
43  */
44 
46 
47 /**
48  * @brief Tracing function for VXLAN GPE tunnel packets
49  *
50  * @param *s formatting string
51  * @param *args
52  *
53  * @return *s formatted string
54  *
55  */
56 u8 *
57 format_vxlan_gpe_tunnel (u8 * s, va_list * args)
58 {
59  vxlan_gpe_tunnel_t *t = va_arg (*args, vxlan_gpe_tunnel_t *);
61 
62  s = format (s, "[%d] local: %U remote: %U ",
63  t - ngm->tunnels,
66 
67  s = format (s, " vxlan VNI %d ", t->vni);
68 
69  switch (t->protocol)
70  {
71  case VXLAN_GPE_PROTOCOL_IP4:
72  s = format (s, "next-protocol ip4");
73  break;
74  case VXLAN_GPE_PROTOCOL_IP6:
75  s = format (s, "next-protocol ip6");
76  break;
77  case VXLAN_GPE_PROTOCOL_ETHERNET:
78  s = format (s, "next-protocol ethernet");
79  break;
80  case VXLAN_GPE_PROTOCOL_NSH:
81  s = format (s, "next-protocol nsh");
82  break;
83  default:
84  s = format (s, "next-protocol unknown %d", t->protocol);
85  }
86 
88  s = format (s, "mcast_sw_if_index %d ", t->mcast_sw_if_index);
89 
90  s = format (s, " fibs: (encap %d, decap %d)",
92 
93  return s;
94 }
95 
96 /**
97  * @brief Naming for VXLAN GPE tunnel
98  *
99  * @param *s formatting string
100  * @param *args
101  *
102  * @return *s formatted string
103  *
104  */
105 static u8 *
106 format_vxlan_gpe_name (u8 * s, va_list * args)
107 {
108  u32 dev_instance = va_arg (*args, u32);
109  return format (s, "vxlan_gpe_tunnel%d", dev_instance);
110 }
111 
112 /**
113  * @brief CLI function for VXLAN GPE admin up/down
114  *
115  * @param *vnm
116  * @param hw_if_index
117  * @param flag
118  *
119  * @return *rc
120  *
121  */
122 static clib_error_t *
124  u32 flags)
125 {
126  u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
128  vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
129 
130  return 0;
131 }
132 
133 /* *INDENT-OFF* */
134 VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = {
135  .name = "VXLAN_GPE",
136  .format_device_name = format_vxlan_gpe_name,
137  .format_tx_trace = format_vxlan_gpe_encap_trace,
138  .admin_up_down_function = vxlan_gpe_interface_admin_up_down,
139 };
140 /* *INDENT-ON* */
141 
142 
143 /**
144  * @brief Formatting function for tracing VXLAN GPE with length
145  *
146  * @param *s
147  * @param *args
148  *
149  * @return *s
150  *
151  */
152 static u8 *
154 {
155  u32 dev_instance = va_arg (*args, u32);
156  s = format (s, "unimplemented dev %u", dev_instance);
157  return s;
158 }
159 
160 /* *INDENT-OFF* */
161 VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = {
162  .name = "VXLAN_GPE",
163  .format_header = format_vxlan_gpe_header_with_length,
164  .build_rewrite = default_build_rewrite,
165 };
166 /* *INDENT-ON* */
167 
168 static void
170 {
171  dpo_id_t dpo = DPO_INVALID;
172  u32 encap_index = vxlan_gpe_encap_node.index;
175 
176  fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo);
177  dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
178  dpo_reset (&dpo);
179 }
180 
181 static vxlan_gpe_tunnel_t *
183 {
185  return ((vxlan_gpe_tunnel_t *) (((char *) node) -
187  node)));
188 }
189 
190 /**
191  * Function definition to backwalk a FIB node -
192  * Here we will restack the new dpo of VXLAN_GPE DIP to encap node.
193  */
196 {
199 }
200 
201 /**
202  * Function definition to get a FIB node from its index
203  */
204 static fib_node_t *
206 {
209 
210  t = pool_elt_at_index (ngm->tunnels, index);
211 
212  return (&t->node);
213 }
214 
215 /**
216  * Function definition to inform the FIB node that its last lock has gone.
217  */
218 static void
220 {
221  /*
222  * The VXLAN_GPE tunnel is a root of the graph. As such
223  * it never has children and thus is never locked.
224  */
225  ASSERT (0);
226 }
227 
228 /*
229  * Virtual function table registered by VXLAN_GPE tunnels
230  * for participation in the FIB object graph.
231  */
232 const static fib_node_vft_t vxlan_gpe_vft = {
234  .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone,
235  .fnv_back_walk = vxlan_gpe_tunnel_back_walk,
236 };
237 
238 #define foreach_gpe_copy_field \
239 _(vni) \
240 _(protocol) \
241 _(mcast_sw_if_index) \
242 _(encap_fib_index) \
243 _(decap_fib_index)
244 
245 #define foreach_copy_ipv4 { \
246  _(local.ip4.as_u32) \
247  _(remote.ip4.as_u32) \
248 }
249 
250 #define foreach_copy_ipv6 { \
251  _(local.ip6.as_u64[0]) \
252  _(local.ip6.as_u64[1]) \
253  _(remote.ip6.as_u64[0]) \
254  _(remote.ip6.as_u64[1]) \
255 }
256 
257 
258 /**
259  * @brief Calculate IPv4 VXLAN GPE rewrite header
260  *
261  * @param *t
262  *
263  * @return rc
264  *
265  */
266 int
268  u8 protocol_override, uword encap_next_node)
269 {
270  u8 *rw = 0;
271  ip4_header_t *ip0;
272  ip4_vxlan_gpe_header_t *h0;
273  int len;
274 
275  len = sizeof (*h0) + extension_size;
276 
277  vec_free (t->rewrite);
279 
280  h0 = (ip4_vxlan_gpe_header_t *) rw;
281 
282  /* Fixed portion of the (outer) ip4 header */
283  ip0 = &h0->ip4;
284  ip0->ip_version_and_header_length = 0x45;
285  ip0->ttl = 254;
286  ip0->protocol = IP_PROTOCOL_UDP;
287 
288  /* we fix up the ip4 header length and checksum after-the-fact */
289  ip0->src_address.as_u32 = t->local.ip4.as_u32;
290  ip0->dst_address.as_u32 = t->remote.ip4.as_u32;
291  ip0->checksum = ip4_header_checksum (ip0);
292 
293  /* UDP header, randomize src port on something, maybe? */
294  h0->udp.src_port = clib_host_to_net_u16 (4790);
295  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
296 
297  /* VXLAN header. Are we having fun yet? */
298  h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
299  h0->vxlan.ver_res = VXLAN_GPE_VERSION;
300  if (protocol_override)
301  {
302  h0->vxlan.protocol = protocol_override;
303  }
304  else
305  {
306  h0->vxlan.protocol = t->protocol;
307  }
308  t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
309  h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
310 
311  t->rewrite = rw;
312  t->encap_next_node = encap_next_node;
313  return (0);
314 }
315 
316 /**
317  * @brief Calculate IPv6 VXLAN GPE rewrite header
318  *
319  * @param *t
320  *
321  * @return rc
322  *
323  */
324 int
326  u8 protocol_override, uword encap_next_node)
327 {
328  u8 *rw = 0;
329  ip6_header_t *ip0;
330  ip6_vxlan_gpe_header_t *h0;
331  int len;
332 
333  len = sizeof (*h0) + extension_size;
334 
335  vec_free (t->rewrite);
337 
338  h0 = (ip6_vxlan_gpe_header_t *) rw;
339 
340  /* Fixed portion of the (outer) ip4 header */
341  ip0 = &h0->ip6;
343  clib_host_to_net_u32 (6 << 28);
344  ip0->hop_limit = 255;
345  ip0->protocol = IP_PROTOCOL_UDP;
346 
347  ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0];
348  ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1];
349  ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0];
350  ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1];
351 
352  /* UDP header, randomize src port on something, maybe? */
353  h0->udp.src_port = clib_host_to_net_u16 (4790);
354  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE);
355 
356  /* VXLAN header. Are we having fun yet? */
357  h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P;
358  h0->vxlan.ver_res = VXLAN_GPE_VERSION;
359  if (protocol_override)
360  {
361  h0->vxlan.protocol = t->protocol;
362  }
363  else
364  {
365  h0->vxlan.protocol = protocol_override;
366  }
367  t->rewrite_size = sizeof (ip4_vxlan_gpe_header_t) + extension_size;
368  h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni << 8);
369 
370  t->rewrite = rw;
371  t->encap_next_node = encap_next_node;
372  return (0);
373 }
374 
375 static uword
376 vtep_addr_ref (ip46_address_t * ip)
377 {
378  uword *vtep = ip46_address_is_ip4 (ip) ?
379  hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
380  hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
381  if (vtep)
382  return ++(*vtep);
383  ip46_address_is_ip4 (ip) ?
384  hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
385  hash_set_mem_alloc (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
386  return 1;
387 }
388 
389 static uword
390 vtep_addr_unref (ip46_address_t * ip)
391 {
392  uword *vtep = ip46_address_is_ip4 (ip) ?
393  hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
394  hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
395  ASSERT (vtep);
396  if (--(*vtep) != 0)
397  return *vtep;
398  ip46_address_is_ip4 (ip) ?
399  hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
400  hash_unset_mem_free (&vxlan_gpe_main.vtep6, &ip->ip6);
401  return 0;
402 }
403 
404 /* *INDENT-OFF* */
405 typedef CLIB_PACKED(union {
406  struct {
407  fib_node_index_t mfib_entry_index;
408  adj_index_t mcast_adj_index;
409  };
410  u64 as_u64;
411 }) mcast_shared_t;
412 /* *INDENT-ON* */
413 
414 static inline mcast_shared_t
415 mcast_shared_get (ip46_address_t * ip)
416 {
418  uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
419  ASSERT (p);
420  return (mcast_shared_t)
421  {
422  .as_u64 = *p};
423 }
424 
425 static inline void
426 mcast_shared_add (ip46_address_t * remote,
427  fib_node_index_t mfei, adj_index_t ai)
428 {
429  mcast_shared_t new_ep = {
430  .mcast_adj_index = ai,
431  .mfib_entry_index = mfei,
432  };
433 
434  hash_set_mem_alloc (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
435 }
436 
437 static inline void
438 mcast_shared_remove (ip46_address_t * remote)
439 {
440  mcast_shared_t ep = mcast_shared_get (remote);
441 
442  adj_unlock (ep.mcast_adj_index);
444 
445  hash_unset_mem_free (&vxlan_gpe_main.mcast_shared, remote);
446 }
447 
448 static inline fib_protocol_t
449 fib_ip_proto (bool is_ip6)
450 {
451  return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
452 }
453 
454 /**
455  * @brief Add or Del a VXLAN GPE tunnel
456  *
457  * @param *a
458  * @param *sw_if_index
459  *
460  * @return rc
461  *
462  */
465 {
467  vxlan_gpe_tunnel_t *t = 0;
468  vnet_main_t *vnm = ngm->vnet_main;
470  uword *p;
471  u32 hw_if_index = ~0;
472  u32 sw_if_index = ~0;
473  int rv;
474  vxlan4_gpe_tunnel_key_t key4, *key4_copy;
475  vxlan6_gpe_tunnel_key_t key6, *key6_copy;
476  u32 is_ip6 = a->is_ip6;
477 
478  if (!is_ip6)
479  {
480  key4.local = a->local.ip4.as_u32;
481  key4.remote = a->remote.ip4.as_u32;
482  key4.vni = clib_host_to_net_u32 (a->vni << 8);
483  key4.pad = 0;
484 
485  p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
486  }
487  else
488  {
489  key6.local.as_u64[0] = a->local.ip6.as_u64[0];
490  key6.local.as_u64[1] = a->local.ip6.as_u64[1];
491  key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
492  key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
493  key6.vni = clib_host_to_net_u32 (a->vni << 8);
494 
495  p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
496  }
497 
498  if (a->is_add)
499  {
500  l2input_main_t *l2im = &l2input_main;
501 
502  /* adding a tunnel: tunnel must not already exist */
503  if (p)
504  return VNET_API_ERROR_TUNNEL_EXIST;
505 
507  memset (t, 0, sizeof (*t));
508 
509  /* copy from arg structure */
510 /* *INDENT-OFF* */
511 #define _(x) t->x = a->x;
513  if (!a->is_ip6)
515  else
517 #undef _
518 /* *INDENT-ON* */
519 
520  if (!a->is_ip6)
522 
523  if (!a->is_ip6)
524  {
526  }
527  else
528  {
530  }
531 
532  if (rv)
533  {
534  pool_put (ngm->tunnels, t);
535  return rv;
536  }
537 
538  if (!is_ip6)
539  {
540  key4_copy = clib_mem_alloc (sizeof (*key4_copy));
541  clib_memcpy (key4_copy, &key4, sizeof (*key4_copy));
542  hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
543  t - ngm->tunnels);
544  }
545  else
546  {
547  key6_copy = clib_mem_alloc (sizeof (*key6_copy));
548  clib_memcpy (key6_copy, &key6, sizeof (*key6_copy));
549  hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
550  t - ngm->tunnels);
551  }
552 
554  {
556  hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
558  _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
559 
560  hi = vnet_get_hw_interface (vnm, hw_if_index);
561  hi->dev_instance = t - ngm->tunnels;
562  hi->hw_instance = hi->dev_instance;
563  /* clear old stats of freed tunnel before reuse */
564  sw_if_index = hi->sw_if_index;
568  sw_if_index);
571  sw_if_index);
574  sw_if_index);
576  }
577  else
578  {
579  hw_if_index = vnet_register_interface
580  (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
581  vxlan_gpe_hw_class.index, t - ngm->tunnels);
582  hi = vnet_get_hw_interface (vnm, hw_if_index);
583  }
584 
585  /* Set vxlan-gpe tunnel output node */
586  u32 encap_index = vxlan_gpe_encap_node.index;
587  vnet_set_interface_output_node (vnm, hw_if_index, encap_index);
588 
589  t->hw_if_index = hw_if_index;
590  t->sw_if_index = sw_if_index = hi->sw_if_index;
592  ~0);
593  ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
594 
595  /* setup l2 input config with l2 feature and bd 0 to drop packet */
596  vec_validate (l2im->configs, sw_if_index);
597  l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
598  l2im->configs[sw_if_index].bd_index = 0;
599 
600  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
605  fib_prefix_t tun_remote_pfx;
607 
608  fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
610  {
611  /* Unicast tunnel -
612  * source the FIB entry for the tunnel's destination
613  * and become a child thereof. The tunnel will then get poked
614  * when the forwarding for the entry updates, and the tunnel can
615  * re-stack accordingly
616  */
617  vtep_addr_ref (&t->local);
619  (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
623  t - ngm->tunnels);
625  }
626  else
627  {
628  /* Multicast tunnel -
629  * as the same mcast group can be used for mutiple mcast tunnels
630  * with different VNIs, create the output fib adjecency only if
631  * it does not already exist
632  */
633  fib_protocol_t fp = fib_ip_proto (is_ip6);
634 
635  if (vtep_addr_ref (&t->remote) == 1)
636  {
637  fib_node_index_t mfei;
638  adj_index_t ai;
639  fib_route_path_t path = {
640  .frp_proto = fib_proto_to_dpo (fp),
641  .frp_addr = zero_addr,
642  .frp_sw_if_index = 0xffffffff,
643  .frp_fib_index = ~0,
644  .frp_weight = 0,
645  .frp_flags = FIB_ROUTE_PATH_LOCAL,
646  };
647  const mfib_prefix_t mpfx = {
648  .fp_proto = fp,
649  .fp_len = (is_ip6 ? 128 : 32),
650  .fp_grp_addr = tun_remote_pfx.fp_addr,
651  };
652 
653  /*
654  * Setup the (*,G) to receive traffic on the mcast group
655  * - the forwarding interface is for-us
656  * - the accepting interface is that from the API
657  */
659  &mpfx,
661  &path, MFIB_ITF_FLAG_FORWARD);
662 
666  &mpfx,
668  &path,
670 
671  /*
672  * Create the mcast adjacency to send traffic to the group
673  */
674  ai = adj_mcast_add_or_lock (fp,
675  fib_proto_to_link (fp),
676  a->mcast_sw_if_index);
677 
678  /*
679  * create a new end-point
680  */
681  mcast_shared_add (&t->remote, mfei, ai);
682  }
683 
684  dpo_id_t dpo = DPO_INVALID;
685  mcast_shared_t ep = mcast_shared_get (&t->remote);
686 
687  /* Stack shared mcast remote mac addr rewrite on encap */
689  fib_proto_to_dpo (fp), ep.mcast_adj_index);
690 
691  dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
692  dpo_reset (&dpo);
693  flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
694  }
695 
696  vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
697  flood_class;
698  }
699  else
700  {
701  /* deleting a tunnel: tunnel must exist */
702  if (!p)
703  return VNET_API_ERROR_NO_SUCH_ENTRY;
704 
705  t = pool_elt_at_index (ngm->tunnels, p[0]);
706 
707  sw_if_index = t->sw_if_index;
708  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
711  set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
712  0);
714 
716 
717  if (!is_ip6)
718  hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
719  else
721 
723  {
724  vtep_addr_unref (&t->local);
727  }
728  else if (vtep_addr_unref (&t->remote) == 0)
729  {
731  }
732 
733  fib_node_deinit (&t->node);
734  vec_free (t->rewrite);
735  pool_put (ngm->tunnels, t);
736  }
737 
738  if (sw_if_indexp)
739  *sw_if_indexp = sw_if_index;
740 
741  return 0;
742 }
743 
744 static clib_error_t *
746  unformat_input_t * input,
747  vlib_cli_command_t * cmd)
748 {
749  unformat_input_t _line_input, *line_input = &_line_input;
750  u8 is_add = 1;
751  ip46_address_t local, remote;
752  u8 local_set = 0;
753  u8 remote_set = 0;
754  u8 grp_set = 0;
755  u8 ipv4_set = 0;
756  u8 ipv6_set = 0;
757  u32 mcast_sw_if_index = ~0;
758  u32 encap_fib_index = 0;
759  u32 decap_fib_index = 0;
760  u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
761  u32 vni;
762  u8 vni_set = 0;
763  int rv;
764  u32 tmp;
766  u32 sw_if_index;
767  clib_error_t *error = NULL;
768 
769  /* Get a line of input. */
770  if (!unformat_user (input, unformat_line_input, line_input))
771  return 0;
772 
773  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
774  {
775  if (unformat (line_input, "del"))
776  is_add = 0;
777  else if (unformat (line_input, "local %U",
778  unformat_ip4_address, &local.ip4))
779  {
780  local_set = 1;
781  ipv4_set = 1;
782  }
783  else if (unformat (line_input, "remote %U",
784  unformat_ip4_address, &remote.ip4))
785  {
786  remote_set = 1;
787  ipv4_set = 1;
788  }
789  else if (unformat (line_input, "local %U",
790  unformat_ip6_address, &local.ip6))
791  {
792  local_set = 1;
793  ipv6_set = 1;
794  }
795  else if (unformat (line_input, "remote %U",
796  unformat_ip6_address, &remote.ip6))
797  {
798  remote_set = 1;
799  ipv6_set = 1;
800  }
801  else if (unformat (line_input, "group %U %U",
802  unformat_ip4_address, &remote.ip4,
804  vnet_get_main (), &mcast_sw_if_index))
805  {
806  grp_set = remote_set = 1;
807  ipv4_set = 1;
808  }
809  else if (unformat (line_input, "group %U %U",
810  unformat_ip6_address, &remote.ip6,
812  vnet_get_main (), &mcast_sw_if_index))
813  {
814  grp_set = remote_set = 1;
815  ipv6_set = 1;
816  }
817  else if (unformat (line_input, "encap-vrf-id %d", &tmp))
818  {
819  if (ipv6_set)
820  encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
821  else
822  encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
823 
824  if (encap_fib_index == ~0)
825  {
826  error =
827  clib_error_return (0, "nonexistent encap fib id %d", tmp);
828  goto done;
829  }
830  }
831  else if (unformat (line_input, "decap-vrf-id %d", &tmp))
832  {
833  if (ipv6_set)
834  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
835  else
836  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
837 
838  if (decap_fib_index == ~0)
839  {
840  error =
841  clib_error_return (0, "nonexistent decap fib id %d", tmp);
842  goto done;
843  }
844  }
845  else if (unformat (line_input, "vni %d", &vni))
846  vni_set = 1;
847  else if (unformat (line_input, "next-ip4"))
848  protocol = VXLAN_GPE_PROTOCOL_IP4;
849  else if (unformat (line_input, "next-ip6"))
850  protocol = VXLAN_GPE_PROTOCOL_IP6;
851  else if (unformat (line_input, "next-ethernet"))
852  protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
853  else if (unformat (line_input, "next-nsh"))
854  protocol = VXLAN_GPE_PROTOCOL_NSH;
855  else
856  {
857  error = clib_error_return (0, "parse error: '%U'",
858  format_unformat_error, line_input);
859  goto done;
860  }
861  }
862 
863  if (local_set == 0)
864  {
865  error = clib_error_return (0, "tunnel local address not specified");
866  goto done;
867  }
868 
869  if (remote_set == 0)
870  {
871  error = clib_error_return (0, "tunnel remote address not specified");
872  goto done;
873  }
874 
875  if (grp_set && !ip46_address_is_multicast (&remote))
876  {
877  error = clib_error_return (0, "tunnel group address not multicast");
878  goto done;
879  }
880 
881  if (grp_set == 0 && ip46_address_is_multicast (&remote))
882  {
883  error = clib_error_return (0, "remote address must be unicast");
884  goto done;
885  }
886 
887  if (grp_set && mcast_sw_if_index == ~0)
888  {
889  error = clib_error_return (0, "tunnel nonexistent multicast device");
890  goto done;
891  }
892  if (ipv4_set && ipv6_set)
893  {
894  error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
895  goto done;
896  }
897 
898  if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
899  || (ipv6_set
900  && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
901  {
902  error = clib_error_return (0, "src and remote addresses are identical");
903  goto done;
904  }
905 
906  if (vni_set == 0)
907  {
908  error = clib_error_return (0, "vni not specified");
909  goto done;
910  }
911 
912  memset (a, 0, sizeof (*a));
913 
914  a->is_add = is_add;
915  a->is_ip6 = ipv6_set;
916 
917 /* *INDENT-OFF* */
918 #define _(x) a->x = x;
920  if (ipv4_set)
922  else
924 #undef _
925 /* *INDENT-ON* */
926 
927  rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
928 
929  switch (rv)
930  {
931  case 0:
933  vnet_get_main (), sw_if_index);
934  break;
935  case VNET_API_ERROR_INVALID_DECAP_NEXT:
936  error = clib_error_return (0, "invalid decap-next...");
937  goto done;
938 
939  case VNET_API_ERROR_TUNNEL_EXIST:
940  error = clib_error_return (0, "tunnel already exists...");
941  goto done;
942 
943  case VNET_API_ERROR_NO_SUCH_ENTRY:
944  error = clib_error_return (0, "tunnel does not exist...");
945  goto done;
946 
947  default:
948  error = clib_error_return
949  (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
950  goto done;
951  }
952 
953 done:
954  unformat_free (line_input);
955 
956  return error;
957 }
958 
959 /*?
960  * Add or delete a VXLAN-GPE Tunnel.
961  *
962  * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
963  * to span multiple servers. This is done by building an L2 overlay on
964  * top of an L3 network underlay using VXLAN-GPE tunnels.
965  *
966  * This makes it possible for servers to be co-located in the same data
967  * center or be separated geographically as long as they are reachable
968  * through the underlay L3 network.
969  *
970  * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment.
971  *
972  * @cliexpar
973  * Example of how to create a VXLAN-GPE Tunnel:
974  * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 local 10.0.3.3 vni 13 encap-vrf-id 7}
975  * Example of how to delete a VXLAN Tunnel:
976  * @cliexcmd{create vxlan tunnel src 10.0.3.1 remote 10.0.3.3 vni 13 del}
977  ?*/
978 /* *INDENT-OFF* */
979 VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
980  .path = "create vxlan-gpe tunnel",
981  .short_help =
982  "create vxlan-gpe tunnel local <local-addr> "
983  " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
984  " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
985  " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
987 };
988 /* *INDENT-ON* */
989 
990 /**
991  * @brief CLI function for showing VXLAN GPE tunnels
992  *
993  * @param *vm
994  * @param *input
995  * @param *cmd
996  *
997  * @return error
998  *
999  */
1000 static clib_error_t *
1002  unformat_input_t * input,
1003  vlib_cli_command_t * cmd)
1004 {
1006  vxlan_gpe_tunnel_t *t;
1007 
1008  if (pool_elts (ngm->tunnels) == 0)
1009  vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1010 
1011  /* *INDENT-OFF* */
1012  pool_foreach (t, ngm->tunnels,
1013  ({
1014  vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1015  }));
1016  /* *INDENT-ON* */
1017 
1018  return 0;
1019 }
1020 
1021 /*?
1022  * Display all the VXLAN-GPE Tunnel entries.
1023  *
1024  * @cliexpar
1025  * Example of how to display the VXLAN-GPE Tunnel entries:
1026  * @cliexstart{show vxlan-gpe tunnel}
1027  * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1028  * @cliexend
1029  ?*/
1030 /* *INDENT-OFF* */
1031 VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1032  .path = "show vxlan-gpe",
1034 };
1035 /* *INDENT-ON* */
1036 
1037 void
1038 vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
1039 {
1040  if (is_ip6)
1041  vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1042  sw_if_index, is_enable, 0, 0);
1043  else
1044  vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1045  sw_if_index, is_enable, 0, 0);
1046 }
1047 
1048 
1049 static clib_error_t *
1051  unformat_input_t * input, vlib_cli_command_t * cmd)
1052 {
1053  unformat_input_t _line_input, *line_input = &_line_input;
1054  vnet_main_t *vnm = vnet_get_main ();
1055  clib_error_t *error = 0;
1056  u32 sw_if_index, is_enable;
1057 
1058  sw_if_index = ~0;
1059  is_enable = 1;
1060 
1061  if (!unformat_user (input, unformat_line_input, line_input))
1062  return 0;
1063 
1064  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1065  {
1066  if (unformat_user
1067  (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1068  ;
1069  else if (unformat (line_input, "del"))
1070  is_enable = 0;
1071  else
1072  {
1073  error = unformat_parse_error (line_input);
1074  goto done;
1075  }
1076  }
1077 
1078  if (~0 == sw_if_index)
1079  {
1080  error = clib_error_return (0, "unknown interface `%U'",
1081  format_unformat_error, line_input);
1082  goto done;
1083  }
1084 
1085  vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1086 
1087 done:
1088  unformat_free (line_input);
1089 
1090  return error;
1091 }
1092 
1093 static clib_error_t *
1095  unformat_input_t * input, vlib_cli_command_t * cmd)
1096 {
1097  return set_ip_vxlan_gpe_bypass (0, input, cmd);
1098 }
1099 
1100 /*?
1101  * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1102  * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1103  * for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1104  * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1105  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1106  *
1107  * @cliexpar
1108  * @parblock
1109  * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1110  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1111  * Name Next Previous
1112  * ip4-vxlan-gpe-bypass error-drop [0]
1113  * vxlan4-gpe-input [1]
1114  * ip4-lookup [2]
1115  * @cliexend
1116  *
1117  * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1118  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1119  *
1120  * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1121  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1122  * Name Next Previous
1123  * ip4-vxlan-gpe-bypass error-drop [0] ip4-input
1124  * vxlan4-gpe-input [1] ip4-input-no-checksum
1125  * ip4-lookup [2]
1126  * @cliexend
1127  *
1128  * Example of how to display the feature enabed on an interface:
1129  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1130  * IP feature paths configured on GigabitEthernet2/0/0...
1131  * ...
1132  * ipv4 unicast:
1133  * ip4-vxlan-gpe-bypass
1134  * ip4-lookup
1135  * ...
1136  * @cliexend
1137  *
1138  * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1139  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1140  * @endparblock
1141 ?*/
1142 /* *INDENT-OFF* */
1143 VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1144  .path = "set interface ip vxlan-gpe-bypass",
1145  .function = set_ip4_vxlan_gpe_bypass,
1146  .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1147 };
1148 /* *INDENT-ON* */
1149 
1150 static clib_error_t *
1152  unformat_input_t * input, vlib_cli_command_t * cmd)
1153 {
1154  return set_ip_vxlan_gpe_bypass (1, input, cmd);
1155 }
1156 
1157 /*?
1158  * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1159  * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1160  * for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1161  * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1162  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1163  *
1164  * @cliexpar
1165  * @parblock
1166  * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1167  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1168  * Name Next Previous
1169  * ip6-vxlan-gpe-bypass error-drop [0]
1170  * vxlan6-gpe-input [1]
1171  * ip6-lookup [2]
1172  * @cliexend
1173  *
1174  * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1175  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1176  *
1177  * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1178  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1179  * Name Next Previous
1180  * ip6-vxlan-gpe-bypass error-drop [0] ip6-input
1181  * vxlan6-gpe-input [1] ip4-input-no-checksum
1182  * ip6-lookup [2]
1183  * @cliexend
1184  *
1185  * Example of how to display the feature enabed on an interface:
1186  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1187  * IP feature paths configured on GigabitEthernet2/0/0...
1188  * ...
1189  * ipv6 unicast:
1190  * ip6-vxlan-gpe-bypass
1191  * ip6-lookup
1192  * ...
1193  * @cliexend
1194  *
1195  * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1196  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1197  * @endparblock
1198 ?*/
1199 /* *INDENT-OFF* */
1200 VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1201  .path = "set interface ip6 vxlan-gpe-bypass",
1202  .function = set_ip6_vxlan_gpe_bypass,
1203  .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1204 };
1205 /* *INDENT-ON* */
1206 
1207 /* *INDENT-OFF* */
1209 {
1210  .arc_name = "ip4-unicast",
1211  .node_name = "ip4-vxlan-gpe-bypass",
1212  .runs_before = VNET_FEATURES ("ip4-lookup"),
1213 };
1214 
1216 {
1217  .arc_name = "ip6-unicast",
1218  .node_name = "ip6-vxlan-gpe-bypass",
1219  .runs_before = VNET_FEATURES ("ip6-lookup"),
1220 };
1221 /* *INDENT-ON* */
1222 
1223 /**
1224  * @brief Feature init function for VXLAN GPE
1225  *
1226  * @param *vm
1227  *
1228  * @return error
1229  *
1230  */
1231 clib_error_t *
1233 {
1235 
1236  ngm->vnet_main = vnet_get_main ();
1237  ngm->vlib_main = vm;
1238 
1240  = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
1241 
1243  = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
1244 
1245 
1246  ngm->mcast_shared = hash_create_mem (0,
1247  sizeof (ip46_address_t),
1248  sizeof (mcast_shared_t));
1249  ngm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
1250 
1251  udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE,
1252  vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
1253  udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE,
1254  vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
1255 
1256  /* Register the list of standard decap protocols supported */
1257  vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
1258  VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
1259  vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
1260  VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
1261  vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
1262  VXLAN_GPE_INPUT_NEXT_L2_INPUT);
1263 
1265 
1266  return 0;
1267 }
1268 
1270 
1271 
1272 /*
1273  * fd.io coding-style-patch-verification: ON
1274  *
1275  * Local Variables:
1276  * eval: (c-set-style "gnu")
1277  * End:
1278  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
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:485
uword * vxlan6_gpe_tunnel_by_key
lookup IPv6 VXLAN GPE tunnel by key
Definition: vxlan_gpe.h:201
vmrglw vmrglh hi
u32 sibling_index
The tunnel is a child of the FIB entry for its desintion.
Definition: vxlan_gpe.h:160
Recursive resolution source.
Definition: fib_entry.h:117
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:92
#define hash_set(h, key, value)
Definition: hash.h:254
l2_input_config_t * configs
Definition: l2_input.h:66
static fib_node_back_walk_rc_t vxlan_gpe_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 VXLAN_GPE DIP to enc...
Definition: vxlan_gpe.c:195
static void vxlan_gpe_tunnel_last_lock_gone(fib_node_t *node)
Function definition to inform the FIB node that its last lock has gone.
Definition: vxlan_gpe.c:219
u32 flags
flags
Definition: vxlan_gpe.h:134
clib_error_t * vxlan_gpe_init(vlib_main_t *vm)
Feature init function for VXLAN GPE.
Definition: vxlan_gpe.c:1232
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:538
#define hash_unset(h, key)
Definition: hash.h:260
static uword ip46_address_is_multicast(ip46_address_t *a)
Definition: ip6_packet.h:151
A representation of a path as described by a route producer.
Definition: fib_types.h:377
ip4_address_t src_address
Definition: ip4_packet.h:164
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
vlib_node_registration_t vxlan4_gpe_input_node
(constructor) VLIB_REGISTER_NODE (vxlan4_gpe_input_node)
Definition: decap.c:730
vnet_interface_main_t interface_main
Definition: vnet.h:56
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
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:503
u64 as_u64[2]
Definition: ip6_packet.h:51
#define foreach_copy_ipv4
Definition: vxlan_gpe.c:245
uword * mcast_shared
Definition: vxlan_gpe.h:208
#define NULL
Definition: clib.h:55
u32 * tunnel_index_by_sw_if_index
Mapping from sw_if_index to tunnel index.
Definition: vxlan_gpe.h:213
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
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:408
VXLAN GPE definitions.
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)
Definition: fib_entry.c:514
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:518
int vxlan6_gpe_rewrite(vxlan_gpe_tunnel_t *t, u32 extension_size, u8 protocol_override, uword encap_next_node)
Calculate IPv6 VXLAN GPE rewrite header.
Definition: vxlan_gpe.c:325
vlib_node_registration_t vxlan6_gpe_input_node
(constructor) VLIB_REGISTER_NODE (vxlan6_gpe_input_node)
Definition: decap.c:755
typedef CLIB_PACKED(union{struct{fib_node_index_t mfib_entry_index;adj_index_t mcast_adj_index;};u64 as_u64;})
Definition: vxlan_gpe.c:405
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
format_function_t format_ip46_address
Definition: format.h:61
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:88
#define hash_set_mem(h, key, value)
Definition: hash.h:274
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
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)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:382
unformat_function_t unformat_vnet_sw_interface
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:394
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:443
int vnet_vxlan_gpe_add_del_tunnel(vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Add or Del a VXLAN GPE tunnel.
Definition: vxlan_gpe.c:464
#define VXLAN_GPE_FLAGS_P
ip6_address_t src_address
Definition: ip6_packet.h:341
format_function_t format_vnet_sw_if_index_name
vnet_main_t * vnet_main
State convenience vnet_main_t.
Definition: vxlan_gpe.h:218
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
#define VXLAN_GPE_VERSION
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:60
#define VXLAN_GPE_FLAGS_I
#define foreach_gpe_copy_field
Definition: vxlan_gpe.c:238
vnet_flood_class_t flood_class
Definition: interface.h:618
static fib_node_t * vxlan_gpe_tunnel_fib_node_get(fib_node_index_t index)
Function definition to get a FIB node from its index.
Definition: vxlan_gpe.c:205
u8 * format_vxlan_gpe_tunnel(u8 *s, va_list *args)
Tracing function for VXLAN GPE tunnel packets.
Definition: vxlan_gpe.c:57
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
unformat_function_t unformat_ip4_address
Definition: format.h:76
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:412
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
ip46_address_t local
tunnel local address
Definition: vxlan_gpe.h:113
static u8 * format_vxlan_gpe_header_with_length(u8 *s, va_list *args)
Formatting function for tracing VXLAN GPE with length.
Definition: vxlan_gpe.c:153
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:380
ip4_address_t dst_address
Definition: ip4_packet.h:164
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:672
u8 * format_vxlan_gpe_encap_trace(u8 *s, va_list *args)
Trace of packets encapsulated in VXLAN GPE.
Definition: encap.c:69
static uword vtep_addr_unref(ip46_address_t *ip)
Definition: vxlan_gpe.c:390
Aggregrate type for a prefix.
Definition: fib_types.h:172
#define clib_error_return(e, args...)
Definition: error.h:99
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.
Definition: mfib_table.c:219
unsigned long u64
Definition: types.h:89
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:239
static fib_protocol_t fib_ip_proto(bool is_ip6)
Definition: vxlan_gpe.c:449
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:1028
void vxlan_gpe_register_decap_protocol(u8 protocol_id, uword next_node_index)
Definition: decap.c:685
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:689
fib_node_index_t fib_entry_index
Definition: vxlan_gpe.h:151
u8 * rewrite
Rewrite string.
Definition: vxlan_gpe.h:105
VNET_FEATURE_INIT(ip4_vxlan_gpe_bypass, static)
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, u32 bvi, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:565
static uword vtep_addr_ref(ip46_address_t *ip)
Definition: vxlan_gpe.c:376
Definition: fib_entry.h:238
unformat_function_t unformat_line_input
Definition: format.h:281
void vnet_int_vxlan_gpe_bypass_mode(u32 sw_if_index, u8 is_ip6, u8 is_enable)
Definition: vxlan_gpe.c:1038
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:660
#define hash_get(h, key)
Definition: hash.h:248
int vxlan4_gpe_rewrite(vxlan_gpe_tunnel_t *t, u32 extension_size, u8 protocol_override, uword encap_next_node)
Calculate IPv4 VXLAN GPE rewrite header.
Definition: vxlan_gpe.c:267
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
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:276
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:195
Struct for VXLAN GPE tunnel.
Definition: vxlan_gpe.h:102
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
static void mcast_shared_remove(ip46_address_t *remote)
Definition: vxlan_gpe.c:438
vxlan_gpe_main_t vxlan_gpe_main
Definition: vxlan_gpe.c:45
static vxlan_gpe_tunnel_t * vxlan_gpe_tunnel_from_fib_node(fib_node_t *node)
Definition: vxlan_gpe.c:182
vlib_main_t * vlib_main
State convenience vlib_main_t.
Definition: vxlan_gpe.h:216
u8 protocol
encapsulated protocol
Definition: vxlan_gpe.h:108
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:671
static clib_error_t * set_ip4_vxlan_gpe_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan_gpe.c:1094
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:290
An node in the FIB graph.
Definition: fib_node.h:286
ip46_address_t remote
tunnel remote address
Definition: vxlan_gpe.h:115
u32 vni
VXLAN GPE VNI in HOST byte order, shifted left 8 bits.
Definition: vxlan_gpe.h:126
#define ip46_address_is_ip4(ip46)
Definition: ip6_packet.h:76
unformat_function_t unformat_ip6_address
Definition: format.h:94
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
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 &#39;special&#39; entry to the FIB.
Definition: fib_table.c:371
static clib_error_t * set_ip6_vxlan_gpe_bypass(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan_gpe.c:1151
Struct for VXLAN GPE add/del args.
Definition: vxlan_gpe.h:233
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
vlib_main_t * vm
Definition: buffer.c:283
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:860
VNET_DEVICE_CLASS(vxlan_gpe_device_class, static)
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
vnet_flood_class_t
Definition: interface.h:557
fib_node_get_t fnv_get
Definition: fib_node.h:274
#define clib_memcpy(a, b, c)
Definition: string.h:75
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:697
fib_node_t node
Linkage into the FIB object graph.
Definition: vxlan_gpe.h:145
#define VNET_SW_INTERFACE_FLAG_HIDDEN
Definition: interface.h:588
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
static u8 * format_vxlan_gpe_name(u8 *s, va_list *args)
Naming for VXLAN GPE tunnel.
Definition: vxlan_gpe.c:106
void fib_prefix_from_ip46_addr(const ip46_address_t *addr, fib_prefix_t *pfx)
Host prefix from ip.
Definition: fib_types.c:54
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:182
Aggregrate type for a prefix.
Definition: mfib_types.h:24
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:1424
Context passed between object during a back walk.
Definition: fib_node.h:199
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:689
static clib_error_t * vxlan_gpe_add_del_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan_gpe.c:745
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:576
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
VNET_HW_INTERFACE_CLASS(vxlan_gpe_hw_class)
long ctx[MAX_CONNS]
Definition: main.c:122
static clib_error_t * vxlan_gpe_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
CLI function for VXLAN GPE admin up/down.
Definition: vxlan_gpe.c:123
u8 rewrite_size
rewrite size for dynamic plugins like iOAM
Definition: vxlan_gpe.h:137
Struct for VXLAN GPE node state.
Definition: vxlan_gpe.h:193
dpo_id_t next_dpo
Definition: vxlan_gpe.h:111
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:469
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:123
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:211
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
#define VNET_FEATURES(...)
Definition: feature.h:368
vxlan_gpe_tunnel_t * tunnels
vector of encap tunnel instances
Definition: vxlan_gpe.h:196
u64 uword
Definition: types.h:112
#define unformat_parse_error(input)
Definition: format.h:267
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:328
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
uword * vxlan4_gpe_tunnel_by_key
lookup IPv4 VXLAN GPE tunnel by key
Definition: vxlan_gpe.h:199
l2input_main_t l2input_main
Definition: l2_input.c:113
u32 decap_fib_index
FIB indices - inner IP packet lookup here.
Definition: vxlan_gpe.h:123
A for-us/local path.
Definition: fib_types.h:301
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
static clib_error_t * show_vxlan_gpe_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI function for showing VXLAN GPE tunnels.
Definition: vxlan_gpe.c:1001
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
static void hash_set_mem_alloc(uword **h, void *key, uword v)
Definition: hash.h:278
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:193
u32 hw_if_index
vnet intfc hw_if_index
Definition: vxlan_gpe.h:129
static void vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_t *t)
Definition: vxlan_gpe.c:169
#define hash_get_mem(h, key)
Definition: hash.h:268
static void hash_unset_mem_free(uword **h, void *key)
Definition: hash.h:294
A FIB graph nodes virtual function table.
Definition: fib_node.h:273
u32 encap_fib_index
FIB indices - tunnel partner lookup here.
Definition: vxlan_gpe.h:121
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
uword encap_next_node
Next node after VxLAN-GPE encap.
Definition: vxlan_gpe.h:140
u32 sw_if_index
vnet intfc sw_if_index
Definition: vxlan_gpe.h:131
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
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:228
vnet_link_t fib_proto_to_link(fib_protocol_t proto)
Convert from a protocol to a link type.
Definition: fib_types.c:245
static void mcast_shared_add(ip46_address_t *remote, fib_node_index_t mfei, adj_index_t ai)
Definition: vxlan_gpe.c:426
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:546
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:492
u8 ip_version_and_header_length
Definition: ip4_packet.h:132
vlib_node_registration_t vxlan_gpe_encap_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_encap_node)
Definition: encap.c:392
u32 flags
Definition: vhost-user.h:77
static uword ip6_vxlan_gpe_bypass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: decap.c:1214
#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:481
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
#define VXLAN_GPE_TUNNEL_IS_IPV4
Flags for vxlan_gpe_tunnel_t.
Definition: vxlan_gpe.h:165
static uword ip4_vxlan_gpe_bypass(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: decap.c:1181
static clib_error_t * set_ip_vxlan_gpe_bypass(u32 is_ip6, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan_gpe.c:1050
#define foreach_copy_ipv6
Definition: vxlan_gpe.c:250
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:239
const ip46_address_t zero_addr
Definition: lookup.c:359
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
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:229
ip6_address_t dst_address
Definition: ip6_packet.h:341
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u32 * free_vxlan_gpe_tunnel_hw_if_indices
Free vlib hw_if_indices.
Definition: vxlan_gpe.h:210
#define MODE_L3
Definition: l2_input.h:202
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128