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