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