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