make "test-all" target pass again
[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 void
385 hash_set_key_copy (uword ** h, void *key, uword v)
386 {
387   size_t ksz = hash_header (*h)->user;
388   void *copy = clib_mem_alloc (ksz);
389   clib_memcpy (copy, key, ksz);
390   hash_set_mem (*h, copy, v);
391 }
392
393 static void
394 hash_unset_key_free (uword ** h, void *key)
395 {
396   hash_pair_t *hp = hash_get_pair_mem (*h, key);
397   ASSERT (hp);
398   key = uword_to_pointer (hp->key, void *);
399   hash_unset_mem (*h, key);
400   clib_mem_free (key);
401 }
402
403 static uword
404 vtep_addr_ref (ip46_address_t * ip)
405 {
406   uword *vtep = ip46_address_is_ip4 (ip) ?
407     hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
408     hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
409   if (vtep)
410     return ++(*vtep);
411   ip46_address_is_ip4 (ip) ?
412     hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) :
413     hash_set_key_copy (&vxlan_gpe_main.vtep6, &ip->ip6, 1);
414   return 1;
415 }
416
417 static uword
418 vtep_addr_unref (ip46_address_t * ip)
419 {
420   uword *vtep = ip46_address_is_ip4 (ip) ?
421     hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
422     hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6);
423   ASSERT (vtep);
424   if (--(*vtep) != 0)
425     return *vtep;
426   ip46_address_is_ip4 (ip) ?
427     hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) :
428     hash_unset_key_free (&vxlan_gpe_main.vtep6, &ip->ip6);
429   return 0;
430 }
431
432 /* *INDENT-OFF* */
433 typedef CLIB_PACKED(union {
434   struct {
435     fib_node_index_t mfib_entry_index;
436     adj_index_t mcast_adj_index;
437   };
438   u64 as_u64;
439 }) mcast_shared_t;
440 /* *INDENT-ON* */
441
442 static inline mcast_shared_t
443 mcast_shared_get (ip46_address_t * ip)
444 {
445   ASSERT (ip46_address_is_multicast (ip));
446   uword *p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip);
447   ASSERT (p);
448   return (mcast_shared_t)
449   {
450   .as_u64 = *p};
451 }
452
453 static inline void
454 mcast_shared_add (ip46_address_t * remote,
455                   fib_node_index_t mfei, adj_index_t ai)
456 {
457   mcast_shared_t new_ep = {
458     .mcast_adj_index = ai,
459     .mfib_entry_index = mfei,
460   };
461
462   hash_set_key_copy (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64);
463 }
464
465 static inline void
466 mcast_shared_remove (ip46_address_t * remote)
467 {
468   mcast_shared_t ep = mcast_shared_get (remote);
469
470   adj_unlock (ep.mcast_adj_index);
471   mfib_table_entry_delete_index (ep.mfib_entry_index, MFIB_SOURCE_VXLAN_GPE);
472
473   hash_unset_key_free (&vxlan_gpe_main.mcast_shared, remote);
474 }
475
476 static inline fib_protocol_t
477 fib_ip_proto (bool is_ip6)
478 {
479   return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4;
480 }
481
482 /**
483  * @brief Add or Del a VXLAN GPE tunnel
484  *
485  * @param *a
486  * @param *sw_if_index
487  *
488  * @return rc
489  *
490  */
491 int vnet_vxlan_gpe_add_del_tunnel
492   (vnet_vxlan_gpe_add_del_tunnel_args_t * a, u32 * sw_if_indexp)
493 {
494   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
495   vxlan_gpe_tunnel_t *t = 0;
496   vnet_main_t *vnm = ngm->vnet_main;
497   vnet_hw_interface_t *hi;
498   uword *p;
499   u32 hw_if_index = ~0;
500   u32 sw_if_index = ~0;
501   int rv;
502   vxlan4_gpe_tunnel_key_t key4, *key4_copy;
503   vxlan6_gpe_tunnel_key_t key6, *key6_copy;
504   u32 is_ip6 = a->is_ip6;
505
506   if (!is_ip6)
507     {
508       key4.local = a->local.ip4.as_u32;
509       key4.remote = a->remote.ip4.as_u32;
510       key4.vni = clib_host_to_net_u32 (a->vni << 8);
511       key4.pad = 0;
512
513       p = hash_get_mem (ngm->vxlan4_gpe_tunnel_by_key, &key4);
514     }
515   else
516     {
517       key6.local.as_u64[0] = a->local.ip6.as_u64[0];
518       key6.local.as_u64[1] = a->local.ip6.as_u64[1];
519       key6.remote.as_u64[0] = a->remote.ip6.as_u64[0];
520       key6.remote.as_u64[1] = a->remote.ip6.as_u64[1];
521       key6.vni = clib_host_to_net_u32 (a->vni << 8);
522
523       p = hash_get_mem (ngm->vxlan6_gpe_tunnel_by_key, &key6);
524     }
525
526   if (a->is_add)
527     {
528       l2input_main_t *l2im = &l2input_main;
529
530       /* adding a tunnel: tunnel must not already exist */
531       if (p)
532         return VNET_API_ERROR_TUNNEL_EXIST;
533
534       pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES);
535       memset (t, 0, sizeof (*t));
536
537       /* copy from arg structure */
538 #define _(x) t->x = a->x;
539       foreach_gpe_copy_field;
540       if (!a->is_ip6)
541         foreach_copy_ipv4
542         else
543         foreach_copy_ipv6
544 #undef _
545           if (!a->is_ip6)
546           t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4;
547
548       if (!a->is_ip6)
549         {
550           rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
551         }
552       else
553         {
554           rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
555         }
556
557       if (rv)
558         {
559           pool_put (ngm->tunnels, t);
560           return rv;
561         }
562
563       if (!is_ip6)
564         {
565           key4_copy = clib_mem_alloc (sizeof (*key4_copy));
566           clib_memcpy (key4_copy, &key4, sizeof (*key4_copy));
567           hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy,
568                         t - ngm->tunnels);
569         }
570       else
571         {
572           key6_copy = clib_mem_alloc (sizeof (*key6_copy));
573           clib_memcpy (key6_copy, &key6, sizeof (*key6_copy));
574           hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy,
575                         t - ngm->tunnels);
576         }
577
578       if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0)
579         {
580           vnet_interface_main_t *im = &vnm->interface_main;
581           hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices
582             [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) - 1];
583           _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1;
584
585           hi = vnet_get_hw_interface (vnm, hw_if_index);
586           hi->dev_instance = t - ngm->tunnels;
587           hi->hw_instance = hi->dev_instance;
588           /* clear old stats of freed tunnel before reuse */
589           sw_if_index = hi->sw_if_index;
590           vnet_interface_counter_lock (im);
591           vlib_zero_combined_counter
592             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX],
593              sw_if_index);
594           vlib_zero_combined_counter (&im->combined_sw_if_counters
595                                       [VNET_INTERFACE_COUNTER_RX],
596                                       sw_if_index);
597           vlib_zero_simple_counter (&im->sw_if_counters
598                                     [VNET_INTERFACE_COUNTER_DROP],
599                                     sw_if_index);
600           vnet_interface_counter_unlock (im);
601         }
602       else
603         {
604           hw_if_index = vnet_register_interface
605             (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels,
606              vxlan_gpe_hw_class.index, t - ngm->tunnels);
607           hi = vnet_get_hw_interface (vnm, hw_if_index);
608           hi->output_node_index = vxlan_gpe_encap_node.index;
609         }
610
611       t->hw_if_index = hw_if_index;
612       t->sw_if_index = sw_if_index = hi->sw_if_index;
613       vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index,
614                                ~0);
615       ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels;
616
617       /* setup l2 input config with l2 feature and bd 0 to drop packet */
618       vec_validate (l2im->configs, sw_if_index);
619       l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
620       l2im->configs[sw_if_index].bd_index = 0;
621
622       vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
623       si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN;
624       vnet_sw_interface_set_flags (vnm, hi->sw_if_index,
625                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
626       fib_node_init (&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL);
627       fib_prefix_t tun_remote_pfx;
628       u32 encap_index = vxlan_gpe_encap_node.index;
629       vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL;
630
631       fib_prefix_from_ip46_addr (&t->remote, &tun_remote_pfx);
632       if (!ip46_address_is_multicast (&t->remote))
633         {
634           /* Unicast tunnel -
635            * source the FIB entry for the tunnel's destination
636            * and become a child thereof. The tunnel will then get poked
637            * when the forwarding for the entry updates, and the tunnel can
638            * re-stack accordingly
639            */
640           vtep_addr_ref (&t->local);
641           t->fib_entry_index = fib_table_entry_special_add
642             (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR,
643              FIB_ENTRY_FLAG_NONE);
644           t->sibling_index = fib_entry_child_add
645             (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL,
646              t - ngm->tunnels);
647           vxlan_gpe_tunnel_restack_dpo (t);
648         }
649       else
650         {
651           /* Multicast tunnel -
652            * as the same mcast group can be used for mutiple mcast tunnels
653            * with different VNIs, create the output fib adjecency only if
654            * it does not already exist
655            */
656           fib_protocol_t fp = fib_ip_proto (is_ip6);
657
658           if (vtep_addr_ref (&t->remote) == 1)
659             {
660               fib_node_index_t mfei;
661               adj_index_t ai;
662               fib_route_path_t path = {
663                 .frp_proto = fib_proto_to_dpo (fp),
664                 .frp_addr = zero_addr,
665                 .frp_sw_if_index = 0xffffffff,
666                 .frp_fib_index = ~0,
667                 .frp_weight = 0,
668                 .frp_flags = FIB_ROUTE_PATH_LOCAL,
669               };
670               const mfib_prefix_t mpfx = {
671                 .fp_proto = fp,
672                 .fp_len = (is_ip6 ? 128 : 32),
673                 .fp_grp_addr = tun_remote_pfx.fp_addr,
674               };
675
676               /*
677                * Setup the (*,G) to receive traffic on the mcast group
678                *  - the forwarding interface is for-us
679                *  - the accepting interface is that from the API
680                */
681               mfib_table_entry_path_update (t->encap_fib_index,
682                                             &mpfx,
683                                             MFIB_SOURCE_VXLAN_GPE,
684                                             &path, MFIB_ITF_FLAG_FORWARD);
685
686               path.frp_sw_if_index = a->mcast_sw_if_index;
687               path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE;
688               mfei = mfib_table_entry_path_update (t->encap_fib_index,
689                                                    &mpfx,
690                                                    MFIB_SOURCE_VXLAN_GPE,
691                                                    &path,
692                                                    MFIB_ITF_FLAG_ACCEPT);
693
694               /*
695                * Create the mcast adjacency to send traffic to the group
696                */
697               ai = adj_mcast_add_or_lock (fp,
698                                           fib_proto_to_link (fp),
699                                           a->mcast_sw_if_index);
700
701               /*
702                * create a new end-point
703                */
704               mcast_shared_add (&t->remote, mfei, ai);
705             }
706
707           dpo_id_t dpo = DPO_INVALID;
708           mcast_shared_t ep = mcast_shared_get (&t->remote);
709
710           /* Stack shared mcast remote mac addr rewrite on encap */
711           dpo_set (&dpo, DPO_ADJACENCY_MCAST,
712                    fib_proto_to_dpo (fp), ep.mcast_adj_index);
713
714           dpo_stack_from_node (encap_index, &t->next_dpo, &dpo);
715           dpo_reset (&dpo);
716           flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER;
717         }
718
719       /* Set vxlan tunnel output node */
720       hi->output_node_index = encap_index;
721
722       vnet_get_sw_interface (vnet_get_main (), sw_if_index)->flood_class =
723         flood_class;
724     }
725   else
726     {
727       /* deleting a tunnel: tunnel must exist */
728       if (!p)
729         return VNET_API_ERROR_NO_SUCH_ENTRY;
730
731       t = pool_elt_at_index (ngm->tunnels, p[0]);
732
733       sw_if_index = t->sw_if_index;
734       vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
735       vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, t->sw_if_index);
736       si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN;
737       set_int_l2_mode (ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0,
738                        0);
739       vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index);
740
741       ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
742
743       if (!is_ip6)
744         hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64);
745       else
746         hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6);
747
748       if (!ip46_address_is_multicast (&t->remote))
749         {
750           vtep_addr_unref (&t->local);
751           fib_entry_child_remove (t->fib_entry_index, t->sibling_index);
752           fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR);
753         }
754       else if (vtep_addr_unref (&t->remote) == 0)
755         {
756           mcast_shared_remove (&t->remote);
757         }
758
759       fib_node_deinit (&t->node);
760       vec_free (t->rewrite);
761       pool_put (ngm->tunnels, t);
762     }
763
764   if (sw_if_indexp)
765     *sw_if_indexp = sw_if_index;
766
767   return 0;
768 }
769
770 static clib_error_t *
771 vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm,
772                                      unformat_input_t * input,
773                                      vlib_cli_command_t * cmd)
774 {
775   unformat_input_t _line_input, *line_input = &_line_input;
776   u8 is_add = 1;
777   ip46_address_t local, remote;
778   u8 local_set = 0;
779   u8 remote_set = 0;
780   u8 grp_set = 0;
781   u8 ipv4_set = 0;
782   u8 ipv6_set = 0;
783   u32 mcast_sw_if_index = ~0;
784   u32 encap_fib_index = 0;
785   u32 decap_fib_index = 0;
786   u8 protocol = VXLAN_GPE_PROTOCOL_IP4;
787   u32 vni;
788   u8 vni_set = 0;
789   int rv;
790   u32 tmp;
791   vnet_vxlan_gpe_add_del_tunnel_args_t _a, *a = &_a;
792   u32 sw_if_index;
793   clib_error_t *error = NULL;
794
795   /* Get a line of input. */
796   if (!unformat_user (input, unformat_line_input, line_input))
797     return 0;
798
799   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
800     {
801       if (unformat (line_input, "del"))
802         is_add = 0;
803       else if (unformat (line_input, "local %U",
804                          unformat_ip4_address, &local.ip4))
805         {
806           local_set = 1;
807           ipv4_set = 1;
808         }
809       else if (unformat (line_input, "remote %U",
810                          unformat_ip4_address, &remote.ip4))
811         {
812           remote_set = 1;
813           ipv4_set = 1;
814         }
815       else if (unformat (line_input, "local %U",
816                          unformat_ip6_address, &local.ip6))
817         {
818           local_set = 1;
819           ipv6_set = 1;
820         }
821       else if (unformat (line_input, "remote %U",
822                          unformat_ip6_address, &remote.ip6))
823         {
824           remote_set = 1;
825           ipv6_set = 1;
826         }
827       else if (unformat (line_input, "group %U %U",
828                          unformat_ip4_address, &remote.ip4,
829                          unformat_vnet_sw_interface,
830                          vnet_get_main (), &mcast_sw_if_index))
831         {
832           grp_set = remote_set = 1;
833           ipv4_set = 1;
834         }
835       else if (unformat (line_input, "group %U %U",
836                          unformat_ip6_address, &remote.ip6,
837                          unformat_vnet_sw_interface,
838                          vnet_get_main (), &mcast_sw_if_index))
839         {
840           grp_set = remote_set = 1;
841           ipv6_set = 1;
842         }
843       else if (unformat (line_input, "encap-vrf-id %d", &tmp))
844         {
845           if (ipv6_set)
846             encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
847           else
848             encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
849
850           if (encap_fib_index == ~0)
851             {
852               error =
853                 clib_error_return (0, "nonexistent encap fib id %d", tmp);
854               goto done;
855             }
856         }
857       else if (unformat (line_input, "decap-vrf-id %d", &tmp))
858         {
859           if (ipv6_set)
860             decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
861           else
862             decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
863
864           if (decap_fib_index == ~0)
865             {
866               error =
867                 clib_error_return (0, "nonexistent decap fib id %d", tmp);
868               goto done;
869             }
870         }
871       else if (unformat (line_input, "vni %d", &vni))
872         vni_set = 1;
873       else if (unformat (line_input, "next-ip4"))
874         protocol = VXLAN_GPE_PROTOCOL_IP4;
875       else if (unformat (line_input, "next-ip6"))
876         protocol = VXLAN_GPE_PROTOCOL_IP6;
877       else if (unformat (line_input, "next-ethernet"))
878         protocol = VXLAN_GPE_PROTOCOL_ETHERNET;
879       else if (unformat (line_input, "next-nsh"))
880         protocol = VXLAN_GPE_PROTOCOL_NSH;
881       else
882         {
883           error = clib_error_return (0, "parse error: '%U'",
884                                      format_unformat_error, line_input);
885           goto done;
886         }
887     }
888
889   if (local_set == 0)
890     {
891       error = clib_error_return (0, "tunnel local address not specified");
892       goto done;
893     }
894
895   if (remote_set == 0)
896     {
897       error = clib_error_return (0, "tunnel remote address not specified");
898       goto done;
899     }
900
901   if (grp_set && !ip46_address_is_multicast (&remote))
902     {
903       error = clib_error_return (0, "tunnel group address not multicast");
904       goto done;
905     }
906
907   if (grp_set == 0 && ip46_address_is_multicast (&remote))
908     {
909       error = clib_error_return (0, "remote address must be unicast");
910       goto done;
911     }
912
913   if (grp_set && mcast_sw_if_index == ~0)
914     {
915       error = clib_error_return (0, "tunnel nonexistent multicast device");
916       goto done;
917     }
918   if (ipv4_set && ipv6_set)
919     {
920       error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
921       goto done;
922     }
923
924   if ((ipv4_set && memcmp (&local.ip4, &remote.ip4, sizeof (local.ip4)) == 0)
925       || (ipv6_set
926           && memcmp (&local.ip6, &remote.ip6, sizeof (local.ip6)) == 0))
927     {
928       error = clib_error_return (0, "src and remote addresses are identical");
929       goto done;
930     }
931
932   if (vni_set == 0)
933     {
934       error = clib_error_return (0, "vni not specified");
935       goto done;
936     }
937
938   memset (a, 0, sizeof (*a));
939
940   a->is_add = is_add;
941   a->is_ip6 = ipv6_set;
942
943 #define _(x) a->x = x;
944   foreach_gpe_copy_field;
945   if (ipv4_set)
946     foreach_copy_ipv4
947     else
948     foreach_copy_ipv6
949 #undef _
950       rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index);
951
952   switch (rv)
953     {
954     case 0:
955       vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
956                        vnet_get_main (), sw_if_index);
957       break;
958     case VNET_API_ERROR_INVALID_DECAP_NEXT:
959       error = clib_error_return (0, "invalid decap-next...");
960       goto done;
961
962     case VNET_API_ERROR_TUNNEL_EXIST:
963       error = clib_error_return (0, "tunnel already exists...");
964       goto done;
965
966     case VNET_API_ERROR_NO_SUCH_ENTRY:
967       error = clib_error_return (0, "tunnel does not exist...");
968       goto done;
969
970     default:
971       error = clib_error_return
972         (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv);
973       goto done;
974     }
975
976 done:
977   unformat_free (line_input);
978
979   return error;
980 }
981
982 /*?
983  * Add or delete a VXLAN-GPE Tunnel.
984  *
985  * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs)
986  * to span multiple servers. This is done by building an L2 overlay on
987  * top of an L3 network underlay using VXLAN-GPE tunnels.
988  *
989  * This makes it possible for servers to be co-located in the same data
990  * center or be separated geographically as long as they are reachable
991  * through the underlay L3 network.
992  *
993  * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment.
994  *
995  * @cliexpar
996  * Example of how to create a VXLAN-GPE Tunnel:
997  * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 local 10.0.3.3 vni 13 encap-vrf-id 7}
998  * Example of how to delete a VXLAN Tunnel:
999  * @cliexcmd{create vxlan tunnel src 10.0.3.1 remote 10.0.3.3 vni 13 del}
1000  ?*/
1001 /* *INDENT-OFF* */
1002 VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = {
1003   .path = "create vxlan-gpe tunnel",
1004   .short_help =
1005   "create vxlan-gpe tunnel local <local-addr> "
1006   " {remote <remote-addr>|group <mcast-addr> <intf-name>}"
1007   " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]"
1008   " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n",
1009   .function = vxlan_gpe_add_del_tunnel_command_fn,
1010 };
1011 /* *INDENT-ON* */
1012
1013 /**
1014  * @brief CLI function for showing VXLAN GPE tunnels
1015  *
1016  * @param *vm
1017  * @param *input
1018  * @param *cmd
1019  *
1020  * @return error
1021  *
1022  */
1023 static clib_error_t *
1024 show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm,
1025                                   unformat_input_t * input,
1026                                   vlib_cli_command_t * cmd)
1027 {
1028   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1029   vxlan_gpe_tunnel_t *t;
1030
1031   if (pool_elts (ngm->tunnels) == 0)
1032     vlib_cli_output (vm, "No vxlan-gpe tunnels configured.");
1033
1034   /* *INDENT-OFF* */
1035   pool_foreach (t, ngm->tunnels,
1036   ({
1037     vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t);
1038   }));
1039   /* *INDENT-ON* */
1040
1041   return 0;
1042 }
1043
1044 /*?
1045  * Display all the VXLAN-GPE Tunnel entries.
1046  *
1047  * @cliexpar
1048  * Example of how to display the VXLAN-GPE Tunnel entries:
1049  * @cliexstart{show vxlan-gpe tunnel}
1050  * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2
1051  * @cliexend
1052  ?*/
1053 /* *INDENT-OFF* */
1054 VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = {
1055     .path = "show vxlan-gpe",
1056     .function = show_vxlan_gpe_tunnel_command_fn,
1057 };
1058 /* *INDENT-ON* */
1059
1060 void
1061 vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable)
1062 {
1063   if (is_ip6)
1064     vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass",
1065                                  sw_if_index, is_enable, 0, 0);
1066   else
1067     vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass",
1068                                  sw_if_index, is_enable, 0, 0);
1069 }
1070
1071
1072 static clib_error_t *
1073 set_ip_vxlan_gpe_bypass (u32 is_ip6,
1074                          unformat_input_t * input, vlib_cli_command_t * cmd)
1075 {
1076   unformat_input_t _line_input, *line_input = &_line_input;
1077   vnet_main_t *vnm = vnet_get_main ();
1078   clib_error_t *error = 0;
1079   u32 sw_if_index, is_enable;
1080
1081   sw_if_index = ~0;
1082   is_enable = 1;
1083
1084   if (!unformat_user (input, unformat_line_input, line_input))
1085     return 0;
1086
1087   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1088     {
1089       if (unformat_user
1090           (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1091         ;
1092       else if (unformat (line_input, "del"))
1093         is_enable = 0;
1094       else
1095         {
1096           error = unformat_parse_error (line_input);
1097           goto done;
1098         }
1099     }
1100
1101   if (~0 == sw_if_index)
1102     {
1103       error = clib_error_return (0, "unknown interface `%U'",
1104                                  format_unformat_error, line_input);
1105       goto done;
1106     }
1107
1108   vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable);
1109
1110 done:
1111   unformat_free (line_input);
1112
1113   return error;
1114 }
1115
1116 static clib_error_t *
1117 set_ip4_vxlan_gpe_bypass (vlib_main_t * vm,
1118                           unformat_input_t * input, vlib_cli_command_t * cmd)
1119 {
1120   return set_ip_vxlan_gpe_bypass (0, input, cmd);
1121 }
1122
1123 /*?
1124  * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface.
1125  * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks
1126  *  for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local,
1127  * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1128  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1129  *
1130  * @cliexpar
1131  * @parblock
1132  * Example of graph node before ip4-vxlan-gpe-bypass is enabled:
1133  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1134  *            Name                      Next                    Previous
1135  * ip4-vxlan-gpe-bypass                error-drop [0]
1136  *                                vxlan4-gpe-input [1]
1137  *                                 ip4-lookup [2]
1138  * @cliexend
1139  *
1140  * Example of how to enable ip4-vxlan-gpe-bypass on an interface:
1141  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0}
1142  *
1143  * Example of graph node after ip4-vxlan-gpe-bypass is enabled:
1144  * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass}
1145  *            Name                      Next                    Previous
1146  * ip4-vxlan-gpe-bypass                error-drop [0]               ip4-input
1147  *                                vxlan4-gpe-input [1]        ip4-input-no-checksum
1148  *                                 ip4-lookup [2]
1149  * @cliexend
1150  *
1151  * Example of how to display the feature enabed on an interface:
1152  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1153  * IP feature paths configured on GigabitEthernet2/0/0...
1154  * ...
1155  * ipv4 unicast:
1156  *   ip4-vxlan-gpe-bypass
1157  *   ip4-lookup
1158  * ...
1159  * @cliexend
1160  *
1161  * Example of how to disable ip4-vxlan-gpe-bypass on an interface:
1162  * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1163  * @endparblock
1164 ?*/
1165 /* *INDENT-OFF* */
1166 VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = {
1167   .path = "set interface ip vxlan-gpe-bypass",
1168   .function = set_ip4_vxlan_gpe_bypass,
1169   .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1170 };
1171 /* *INDENT-ON* */
1172
1173 static clib_error_t *
1174 set_ip6_vxlan_gpe_bypass (vlib_main_t * vm,
1175                           unformat_input_t * input, vlib_cli_command_t * cmd)
1176 {
1177   return set_ip_vxlan_gpe_bypass (1, input, cmd);
1178 }
1179
1180 /*?
1181  * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface.
1182  * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks
1183  *  for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local,
1184  * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will
1185  * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum.
1186  *
1187  * @cliexpar
1188  * @parblock
1189  * Example of graph node before ip6-vxlan-gpe-bypass is enabled:
1190  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1191  *            Name                      Next                    Previous
1192  * ip6-vxlan-gpe-bypass                error-drop [0]
1193  *                                vxlan6-gpe-input [1]
1194  *                                 ip6-lookup [2]
1195  * @cliexend
1196  *
1197  * Example of how to enable ip6-vxlan-gpe-bypass on an interface:
1198  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0}
1199  *
1200  * Example of graph node after ip6-vxlan-gpe-bypass is enabled:
1201  * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass}
1202  *            Name                      Next                    Previous
1203  * ip6-vxlan-gpe-bypass                error-drop [0]               ip6-input
1204  *                                vxlan6-gpe-input [1]        ip4-input-no-checksum
1205  *                                 ip6-lookup [2]
1206  * @cliexend
1207  *
1208  * Example of how to display the feature enabed on an interface:
1209  * @cliexstart{show ip interface features GigabitEthernet2/0/0}
1210  * IP feature paths configured on GigabitEthernet2/0/0...
1211  * ...
1212  * ipv6 unicast:
1213  *   ip6-vxlan-gpe-bypass
1214  *   ip6-lookup
1215  * ...
1216  * @cliexend
1217  *
1218  * Example of how to disable ip6-vxlan-gpe-bypass on an interface:
1219  * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del}
1220  * @endparblock
1221 ?*/
1222 /* *INDENT-OFF* */
1223 VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = {
1224   .path = "set interface ip6 vxlan-gpe-bypass",
1225   .function = set_ip6_vxlan_gpe_bypass,
1226   .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]",
1227 };
1228 /* *INDENT-ON* */
1229
1230 /* *INDENT-OFF* */
1231 VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) =
1232 {
1233   .arc_name = "ip4-unicast",
1234   .node_name = "ip4-vxlan-gpe-bypass",
1235   .runs_before = VNET_FEATURES ("ip4-lookup"),
1236 };
1237
1238 VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) =
1239 {
1240   .arc_name = "ip6-unicast",
1241   .node_name = "ip6-vxlan-gpe-bypass",
1242   .runs_before = VNET_FEATURES ("ip6-lookup"),
1243 };
1244 /* *INDENT-ON* */
1245
1246 /**
1247  * @brief Feature init function for VXLAN GPE
1248  *
1249  * @param *vm
1250  *
1251  * @return error
1252  *
1253  */
1254 clib_error_t *
1255 vxlan_gpe_init (vlib_main_t * vm)
1256 {
1257   vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
1258
1259   ngm->vnet_main = vnet_get_main ();
1260   ngm->vlib_main = vm;
1261
1262   ngm->vxlan4_gpe_tunnel_by_key
1263     = hash_create_mem (0, sizeof (vxlan4_gpe_tunnel_key_t), sizeof (uword));
1264
1265   ngm->vxlan6_gpe_tunnel_by_key
1266     = hash_create_mem (0, sizeof (vxlan6_gpe_tunnel_key_t), sizeof (uword));
1267
1268
1269   ngm->mcast_shared = hash_create_mem (0,
1270                                        sizeof (ip46_address_t),
1271                                        sizeof (mcast_shared_t));
1272   ngm->vtep6 = hash_create_mem (0, sizeof (ip6_address_t), sizeof (uword));
1273
1274   udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE,
1275                          vxlan4_gpe_input_node.index, 1 /* is_ip4 */ );
1276   udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE,
1277                          vxlan6_gpe_input_node.index, 0 /* is_ip4 */ );
1278
1279   /* Register the list of standard decap protocols supported */
1280   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4,
1281                                      VXLAN_GPE_INPUT_NEXT_IP4_INPUT);
1282   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6,
1283                                      VXLAN_GPE_INPUT_NEXT_IP6_INPUT);
1284   vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET,
1285                                      VXLAN_GPE_INPUT_NEXT_L2_INPUT);
1286
1287   fib_node_register_type (FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft);
1288
1289   return 0;
1290 }
1291
1292 VLIB_INIT_FUNCTION (vxlan_gpe_init);
1293
1294
1295 /*
1296  * fd.io coding-style-patch-verification: ON
1297  *
1298  * Local Variables:
1299  * eval: (c-set-style "gnu")
1300  * End:
1301  */