fab887addff3faf108a32d294cf6bcfbd5db38aa
[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 * format_vxlan_gpe_tunnel (u8 * s, va_list * args)
57 {
58   vxlan_gpe_tunnel_t * t = va_arg (*args, vxlan_gpe_tunnel_t *);
59   vxlan_gpe_main_t * ngm = &vxlan_gpe_main;
60
61   s = format (s, "[%d] local: %U remote: %U ",
62               t - ngm->tunnels,
63               format_ip46_address, &t->local, IP46_TYPE_ANY,
64               format_ip46_address, &t->remote, IP46_TYPE_ANY);
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
86   if (ip46_address_is_multicast (&t->remote))
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
111 static uword dummy_interface_tx (vlib_main_t * vm,
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 *
130 vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
131 {
132   u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
133     VNET_HW_INTERFACE_FLAG_LINK_UP : 0;
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
171 vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_t * t)
172 {
173     dpo_id_t dpo = DPO_INVALID;
174     u32 encap_index = vxlan_gpe_encap_node.index;
175     fib_forward_chain_type_t forw_type = ip46_address_is_ip4(&t->remote) ?
176         FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6;
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 *
184 vxlan_gpe_tunnel_from_fib_node (fib_node_t *node)
185 {
186 #if (CLIB_DEBUG > 0)
187     ASSERT(FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type);
188 #endif
189     return ((vxlan_gpe_tunnel_t*) (((char*)node) -
190                                STRUCT_OFFSET_OF(vxlan_gpe_tunnel_t, 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  */
197 static fib_node_back_walk_rc_t
198 vxlan_gpe_tunnel_back_walk (fib_node_t *node,
199                         fib_node_back_walk_ctx_t *ctx)
200 {
201     vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_from_fib_node(node));
202     return (FIB_NODE_BACK_WALK_CONTINUE);
203 }
204
205 /**
206  * Function definition to get a FIB node from its index
207  */
208 static fib_node_t*
209 vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index)
210 {
211     vxlan_gpe_tunnel_t * t;
212     vxlan_gpe_main_t * ngm = &vxlan_gpe_main;
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
223 vxlan_gpe_tunnel_last_lock_gone (fib_node_t *node)
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 = {
237     .fnv_get = vxlan_gpe_tunnel_fib_node_get,
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);
281   vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
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);
338   vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
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 {
433         ASSERT(ip46_address_is_multicast(ip));
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,
459                                   MFIB_SOURCE_VXLAN_GPE);
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  */
479 int vnet_vxlan_gpe_add_del_tunnel
480 (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp)
481 {
482   vxlan_gpe_main_t * ngm = &vxlan_gpe_main;
483   vxlan_gpe_tunnel_t *t = 0;
484   vnet_main_t * vnm = ngm->vnet_main;
485   vnet_hw_interface_t * hi;
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
522       pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
523       memset (t, 0, sizeof (*t));
524
525       /* copy from arg structure */
526 #define _(x) t->x = a->x;
527       foreach_gpe_copy_field;
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) {
535         rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
536       } else {
537         rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
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
561       if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
562         {
563               vnet_interface_main_t * im = &vnm->interface_main;
564           hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
565             [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices)-1];
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;
573           vnet_interface_counter_lock(im);
574           vlib_zero_combined_counter
575             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX], sw_if_index);
576           vlib_zero_combined_counter
577             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_RX], sw_if_index);
578           vlib_zero_simple_counter
579             (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
580           vnet_interface_counter_unlock(im);
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);
588           hi->output_node_index = vxlan_gpe_encap_node.index;
589         }
590
591       t->hw_if_index = hw_if_index;
592       t->sw_if_index = sw_if_index = hi->sw_if_index;
593       vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index, ~0);
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);
602       si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
603       vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
604                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
605       fib_node_init(&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
606       fib_prefix_t tun_remote_pfx;
607       u32 encap_index = vxlan_gpe_encap_node.index;
608       vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
609
610       fib_prefix_from_ip46_addr(&t->remote, &tun_remote_pfx);
611       if (!ip46_address_is_multicast(&t->remote))
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);
620           t->fib_entry_index = fib_table_entry_special_add
621             (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
622              FIB_ENTRY_FLAG_NONE);
623           t->sibling_index = fib_entry_child_add
624             (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, t - ngm->tunnels);
625           vxlan_gpe_tunnel_restack_dpo(t);
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                */
659               mfib_table_entry_path_update(t->encap_fib_index,
660                                            &mpfx,
661                                            MFIB_SOURCE_VXLAN_GPE,
662                                            &path,
663                                            MFIB_ITF_FLAG_FORWARD);
664
665               path.frp_sw_if_index = a->mcast_sw_if_index;
666               path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
667               mfei = mfib_table_entry_path_update(t->encap_fib_index,
668                                                   &mpfx,
669                                                   MFIB_SOURCE_VXLAN_GPE,
670                                                   &path,
671                                                   MFIB_ITF_FLAG_ACCEPT);
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 */
690           dpo_set (&dpo, DPO_ADJACENCY_MCAST,
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 */);
714       vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, t->sw_if_index);
715       si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
716       set_int_l2_mode(ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0);
717       vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
718
719       ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
720
721       if (!is_ip6)
722         hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
723       else
724         hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
725
726       if (!ip46_address_is_multicast(&t->remote))
727         {
728           vtep_addr_unref(&t->local);
729           fib_entry_child_remove(t->fib_entry_index, t->sibling_index);
730           fib_table_entry_delete_index(t->fib_entry_index, FIB_SOURCE_RR);
731         }
732       else if (vtep_addr_unref(&t->remote) == 0)
733         {
734           mcast_shared_remove(&t->remote);
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 *
749 vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
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;
769   vnet_vxlan_gpe_add_del_tunnel_args_t _a, * a = &_a;
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,
806                        unformat_vnet_sw_interface,
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,
814                        unformat_vnet_sw_interface,
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;
918   foreach_gpe_copy_field;
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",
981   .function = vxlan_gpe_add_del_tunnel_command_fn,
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 *
996 show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
997                                 unformat_input_t * input,
998                                 vlib_cli_command_t * cmd)
999 {
1000   vxlan_gpe_main_t * ngm = &vxlan_gpe_main;
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",
1026     .function = show_vxlan_gpe_tunnel_command_fn,
1027 };
1028 /* *INDENT-ON* */
1029
1030 void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index,
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 *
1044 set_ip_vxlan_gpe_bypass (u32 is_ip6,
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 *
1088 set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
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 *
1146 set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
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  */
1211 clib_error_t *vxlan_gpe_init (vlib_main_t *vm)
1212 {
1213   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1214
1215   ngm->vnet_main = vnet_get_main();
1216   ngm->vlib_main = vm;
1217
1218   ngm->vxlan4_gpe_tunnel_by_key
1219     = hash_create_mem (0, sizeof(vxlan4_gpe_tunnel_key_t), sizeof (uword));
1220
1221   ngm->vxlan6_gpe_tunnel_by_key
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
1242   fib_node_register_type(FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
1243
1244   return 0;
1245 }
1246
1247 VLIB_INIT_FUNCTION(vxlan_gpe_init);
1248