Fix VXLAN tunnel delete crash
[vpp.git] / vnet / vnet / vxlan / vxlan.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 #include <vnet/vxlan/vxlan.h>
16 #include <vnet/ip/format.h>
17
18 /**
19  * @file
20  * @brief VXLAN.
21  *
22  * VXLAN provides the features needed to allow L2 bridge domains (BDs)
23  * to span multiple servers. This is done by building an L2 overlay on
24  * top of an L3 network underlay using VXLAN tunnels.
25  *
26  * This makes it possible for servers to be co-located in the same data
27  * center or be separated geographically as long as they are reachable
28  * through the underlay L3 network.
29  *
30  * You can refer to this kind of L2 overlay bridge domain as a VXLAN
31  * (Virtual eXtensible VLAN) segment.
32  */
33
34
35 vxlan_main_t vxlan_main;
36
37 static u8 * format_decap_next (u8 * s, va_list * args)
38 {
39   u32 next_index = va_arg (*args, u32);
40
41   switch (next_index)
42     {
43     case VXLAN_INPUT_NEXT_DROP:
44       return format (s, "drop");
45     case VXLAN_INPUT_NEXT_L2_INPUT:
46       return format (s, "l2");
47     case VXLAN_INPUT_NEXT_IP4_INPUT:
48       return format (s, "ip4");
49     case VXLAN_INPUT_NEXT_IP6_INPUT:
50       return format (s, "ip6");
51     default:
52       return format (s, "unknown %d", next_index);
53     }
54   return s;
55 }
56
57 u8 * format_vxlan_tunnel (u8 * s, va_list * args)
58 {
59   vxlan_tunnel_t * t = va_arg (*args, vxlan_tunnel_t *);
60   vxlan_main_t * ngm = &vxlan_main;
61
62   s = format (s, 
63               "[%d] %U (src) %U (dst) vni %d encap_fib_index %d",
64               t - ngm->tunnels,
65               format_ip46_address, &t->src, IP46_TYPE_ANY,
66               format_ip46_address, &t->dst, IP46_TYPE_ANY,
67               t->vni,
68               t->encap_fib_index);
69   s = format (s, " decap_next %U\n", format_decap_next, t->decap_next_index);
70   return s;
71 }
72
73 static u8 * format_vxlan_name (u8 * s, va_list * args)
74 {
75   u32 dev_instance = va_arg (*args, u32);
76   return format (s, "vxlan_tunnel%d", dev_instance);
77 }
78
79 static uword dummy_interface_tx (vlib_main_t * vm,
80                                  vlib_node_runtime_t * node,
81                                  vlib_frame_t * frame)
82 {
83   clib_warning ("you shouldn't be here, leaking buffers...");
84   return frame->n_vectors;
85 }
86
87 static clib_error_t *
88 vxlan_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
89 {
90   if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
91     vnet_hw_interface_set_flags (vnm, hw_if_index, VNET_HW_INTERFACE_FLAG_LINK_UP);
92   else
93     vnet_hw_interface_set_flags (vnm, hw_if_index, 0);
94
95   return /* no error */ 0;
96 }
97
98 VNET_DEVICE_CLASS (vxlan_device_class,static) = {
99   .name = "VXLAN",
100   .format_device_name = format_vxlan_name,
101   .format_tx_trace = format_vxlan_encap_trace,
102   .tx_function = dummy_interface_tx,
103   .admin_up_down_function = vxlan_interface_admin_up_down,
104 };
105
106 static u8 * format_vxlan_header_with_length (u8 * s, va_list * args)
107 {
108   u32 dev_instance = va_arg (*args, u32);
109   s = format (s, "unimplemented dev %u", dev_instance);
110   return s;
111 }
112
113 VNET_HW_INTERFACE_CLASS (vxlan_hw_class) = {
114   .name = "VXLAN",
115   .format_header = format_vxlan_header_with_length,
116   .build_rewrite = default_build_rewrite,
117 };
118
119 #define foreach_copy_field                      \
120 _(vni)                                          \
121 _(encap_fib_index)                              \
122 _(decap_next_index)
123
124 #define foreach_copy_ipv4 {                     \
125   _(src.ip4.as_u32)                             \
126   _(dst.ip4.as_u32)                             \
127 }
128
129 #define foreach_copy_ipv6 {                     \
130   _(src.ip6.as_u64[0])                          \
131   _(src.ip6.as_u64[1])                          \
132   _(dst.ip6.as_u64[0])                          \
133   _(dst.ip6.as_u64[1])                          \
134 }
135
136 static int vxlan4_rewrite (vxlan_tunnel_t * t)
137 {
138   u8 *rw = 0;
139   ip4_header_t * ip0;
140   ip4_vxlan_header_t * h0;
141   int len = sizeof (*h0);
142
143   vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
144
145   h0 = (ip4_vxlan_header_t *) rw;
146
147   /* Fixed portion of the (outer) ip4 header */
148   ip0 = &h0->ip4;
149   ip0->ip_version_and_header_length = 0x45;
150   ip0->ttl = 254;
151   ip0->protocol = IP_PROTOCOL_UDP;
152
153   /* we fix up the ip4 header length and checksum after-the-fact */
154   ip0->src_address.as_u32 = t->src.ip4.as_u32;
155   ip0->dst_address.as_u32 = t->dst.ip4.as_u32;
156   ip0->checksum = ip4_header_checksum (ip0);
157
158   /* UDP header, randomize src port on something, maybe? */
159   h0->udp.src_port = clib_host_to_net_u16 (4789);
160   h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
161
162   /* VXLAN header */
163   vnet_set_vni_and_flags(&h0->vxlan, t->vni);
164
165   t->rewrite = rw;
166   return (0);
167 }
168
169 static int vxlan6_rewrite (vxlan_tunnel_t * t)
170 {
171   u8 *rw = 0;
172   ip6_header_t * ip0;
173   ip6_vxlan_header_t * h0;
174   int len = sizeof (*h0);
175
176   vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES);
177
178   h0 = (ip6_vxlan_header_t *) rw;
179
180   /* Fixed portion of the (outer) ip6 header */
181   ip0 = &h0->ip6;
182   ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
183   ip0->hop_limit = 255;
184   ip0->protocol = IP_PROTOCOL_UDP;
185
186   ip0->src_address.as_u64[0] = t->src.ip6.as_u64[0];
187   ip0->src_address.as_u64[1] = t->src.ip6.as_u64[1];
188   ip0->dst_address.as_u64[0] = t->dst.ip6.as_u64[0];
189   ip0->dst_address.as_u64[1] = t->dst.ip6.as_u64[1];
190
191   /* UDP header, randomize src port on something, maybe? */
192   h0->udp.src_port = clib_host_to_net_u16 (4789);
193   h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
194
195   /* VXLAN header */
196   vnet_set_vni_and_flags(&h0->vxlan, t->vni);
197
198   t->rewrite = rw;
199   return (0);
200 }
201
202 int vnet_vxlan_add_del_tunnel 
203 (vnet_vxlan_add_del_tunnel_args_t *a, u32 * sw_if_indexp)
204 {
205   vxlan_main_t * vxm = &vxlan_main;
206   vxlan_tunnel_t *t = 0;
207   vnet_main_t * vnm = vxm->vnet_main;
208   ip4_main_t * im4 = &ip4_main;
209   ip6_main_t * im6 = &ip6_main;
210   vnet_hw_interface_t * hi;
211   uword * p;
212   u32 hw_if_index = ~0;
213   u32 sw_if_index = ~0;
214   int rv;
215   vxlan4_tunnel_key_t key4;
216   vxlan6_tunnel_key_t key6;
217   l2output_main_t * l2om = &l2output_main;
218
219   if (!a->is_ip6) {
220     key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
221     key4.vni = clib_host_to_net_u32 (a->vni << 8);
222   
223     p = hash_get (vxm->vxlan4_tunnel_by_key, key4.as_u64);
224   } else {
225     key6.src.as_u64[0] = a->dst.ip6.as_u64[0];
226     key6.src.as_u64[1] = a->dst.ip6.as_u64[1];
227     key6.vni = clib_host_to_net_u32 (a->vni << 8);
228
229     p = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6);
230   }
231   
232   if (a->is_add)
233     {
234       /* adding a tunnel: tunnel must not already exist */
235       if (p)
236         return VNET_API_ERROR_TUNNEL_EXIST;
237
238       if (a->decap_next_index == ~0)
239           a->decap_next_index = VXLAN_INPUT_NEXT_L2_INPUT;
240
241       if (a->decap_next_index >= VXLAN_INPUT_N_NEXT)
242         return VNET_API_ERROR_INVALID_DECAP_NEXT;
243       
244       pool_get_aligned (vxm->tunnels, t, CLIB_CACHE_LINE_BYTES);
245       memset (t, 0, sizeof (*t));
246       
247       /* copy from arg structure */
248 #define _(x) t->x = a->x;
249       foreach_copy_field;
250       if (!a->is_ip6) foreach_copy_ipv4
251       else            foreach_copy_ipv6
252 #undef _
253       
254       /* copy the key */
255       if (a->is_ip6)
256         {
257           t->key6 = clib_mem_alloc (sizeof(vxlan6_tunnel_key_t));
258           clib_memcpy (t->key6, &key6, sizeof(key6));
259         }
260       else
261         {
262           t->key4 = 0; /* not yet used */
263         }
264
265       if (!a->is_ip6) t->flags |= VXLAN_TUNNEL_IS_IPV4;
266
267       if (!a->is_ip6) {
268         rv = vxlan4_rewrite (t);
269       } else {
270         rv = vxlan6_rewrite (t);
271       }
272
273       if (rv)
274         {
275           pool_put (vxm->tunnels, t);
276           return rv;
277         }
278
279       if (!a->is_ip6)
280         hash_set (vxm->vxlan4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
281       else
282         hash_set_mem (vxm->vxlan6_tunnel_by_key, t->key6, t - vxm->tunnels);
283       
284       if (vec_len (vxm->free_vxlan_tunnel_hw_if_indices) > 0)
285         {
286           vnet_interface_main_t * im = &vnm->interface_main;
287           hw_if_index = vxm->free_vxlan_tunnel_hw_if_indices
288             [vec_len (vxm->free_vxlan_tunnel_hw_if_indices)-1];
289           _vec_len (vxm->free_vxlan_tunnel_hw_if_indices) -= 1;
290           
291           hi = vnet_get_hw_interface (vnm, hw_if_index);
292           hi->dev_instance = t - vxm->tunnels;
293           hi->hw_instance = hi->dev_instance;
294
295           /* clear old stats of freed tunnel before reuse */
296           sw_if_index = hi->sw_if_index;
297           vnet_interface_counter_lock(im);
298           vlib_zero_combined_counter 
299             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX], sw_if_index);
300           vlib_zero_combined_counter 
301             (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_RX], sw_if_index);
302           vlib_zero_simple_counter 
303             (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
304           vnet_interface_counter_unlock(im);
305         }
306       else 
307         {
308           hw_if_index = vnet_register_interface
309             (vnm, vxlan_device_class.index, t - vxm->tunnels,
310              vxlan_hw_class.index, t - vxm->tunnels);
311           hi = vnet_get_hw_interface (vnm, hw_if_index);
312           hi->output_node_index = vxlan_encap_node.index;
313         }
314       
315       t->hw_if_index = hw_if_index;
316       t->sw_if_index = sw_if_index = hi->sw_if_index;
317       
318       vec_validate_init_empty (vxm->tunnel_index_by_sw_if_index, sw_if_index, ~0);
319       vxm->tunnel_index_by_sw_if_index[sw_if_index] = t - vxm->tunnels;
320
321       if (a->decap_next_index == VXLAN_INPUT_NEXT_L2_INPUT)
322         {
323           l2input_main_t * l2im = &l2input_main;
324           /* setup l2 input config with l2 feature and bd 0 to drop packet */
325           vec_validate (l2im->configs, sw_if_index);
326           l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
327           l2im->configs[sw_if_index].bd_index = 0;
328         }
329       
330       /* 
331        * Directs the l2 output path to work out the interface
332        * output next-arc itself. Needed when recycling a tunnel.
333        */
334       vec_validate_init_empty(l2om->next_nodes.output_node_index_vec, 
335                               sw_if_index, ~0);
336       l2om->next_nodes.output_node_index_vec[t->sw_if_index] 
337         = ~0;
338       vnet_sw_interface_set_flags (vnm, sw_if_index, 
339                                    VNET_SW_INTERFACE_FLAG_ADMIN_UP);
340       if (!a->is_ip6) {
341         vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
342         im4->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
343         ip4_sw_interface_enable_disable(sw_if_index, 1);
344       } else {
345         vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
346         im6->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
347         ip6_sw_interface_enable_disable(sw_if_index, 1);
348       }
349     }
350   else
351     {
352       /* deleting a tunnel: tunnel must exist */
353       if (!p) 
354         return VNET_API_ERROR_NO_SUCH_ENTRY;
355
356       t = pool_elt_at_index (vxm->tunnels, p[0]);
357
358       vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */);
359       /* make sure tunnel is removed from l2 bd or xconnect */
360       set_int_l2_mode(vxm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0);
361       vec_add1 (vxm->free_vxlan_tunnel_hw_if_indices, t->hw_if_index);
362
363       vxm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0;
364
365       /* Directs the l2 path to turf packets sent to this sw_if_index */
366       l2om->next_nodes.output_node_index_vec[t->sw_if_index] 
367         = L2OUTPUT_NEXT_DEL_TUNNEL;
368
369       if (!a->is_ip6)
370         {
371           hash_unset (vxm->vxlan4_tunnel_by_key, key4.as_u64);
372           ip4_sw_interface_enable_disable(t->sw_if_index, 1);
373         }
374       else
375         {
376           hash_unset_mem (vxm->vxlan6_tunnel_by_key, t->key6);
377           clib_mem_free (t->key6);
378           ip6_sw_interface_enable_disable(t->sw_if_index, 1);
379         }
380       vec_free (t->rewrite);
381       pool_put (vxm->tunnels, t);
382     }
383
384   if (sw_if_indexp)
385       *sw_if_indexp = sw_if_index;
386
387   return 0;
388 }
389
390 static u32 fib4_index_from_fib_id (u32 fib_id)
391 {
392   ip4_main_t * im = &ip4_main;
393   uword * p;
394
395   p = hash_get (im->fib_index_by_table_id, fib_id);
396   if (!p)
397     return ~0;
398
399   return p[0];
400 }
401
402 static u32 fib6_index_from_fib_id (u32 fib_id)
403 {
404   ip6_main_t * im = &ip6_main;
405   uword * p;
406
407   p = hash_get (im->fib_index_by_table_id, fib_id);
408   if (!p)
409     return ~0;
410
411   return p[0];
412 }
413
414 static uword unformat_decap_next (unformat_input_t * input, va_list * args)
415 {
416   u32 * result = va_arg (*args, u32 *);
417   u32 tmp;
418   
419   if (unformat (input, "l2"))
420     *result = VXLAN_INPUT_NEXT_L2_INPUT;
421   else if (unformat (input, "drop"))
422     *result = VXLAN_INPUT_NEXT_DROP;
423   else if (unformat (input, "ip4"))
424     *result = VXLAN_INPUT_NEXT_IP4_INPUT;
425   else if (unformat (input, "ip6"))
426     *result = VXLAN_INPUT_NEXT_IP6_INPUT;
427   else if (unformat (input, "%d", &tmp))
428     *result = tmp;
429   else
430     return 0;
431   return 1;
432 }
433
434 static clib_error_t *
435 vxlan_add_del_tunnel_command_fn (vlib_main_t * vm,
436                                    unformat_input_t * input,
437                                    vlib_cli_command_t * cmd)
438 {
439   unformat_input_t _line_input, * line_input = &_line_input;
440   ip46_address_t src, dst;
441   u8 is_add = 1;
442   u8 src_set = 0;
443   u8 dst_set = 0;
444   u8 ipv4_set = 0;
445   u8 ipv6_set = 0;
446   u32 encap_fib_index = 0;
447   u32 decap_next_index = ~0;
448   u32 vni = 0;
449   u32 tmp;
450   int rv;
451   vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a;
452   u32 sw_if_index;
453   
454   /* Get a line of input. */
455   if (! unformat_user (input, unformat_line_input, line_input))
456     return 0;
457
458   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
459     if (unformat (line_input, "del"))
460       {
461         is_add = 0;
462       }
463     else if (unformat (line_input, "src %U",
464                        unformat_ip4_address, &src.ip4))
465       {
466         src_set = 1;
467         ipv4_set = 1;
468       }
469     else if (unformat (line_input, "dst %U",
470                        unformat_ip4_address, &dst.ip4))
471       {
472         dst_set = 1;
473         ipv4_set = 1;
474       }
475     else if (unformat (line_input, "src %U", 
476                        unformat_ip6_address, &src.ip6))
477       {
478         src_set = 1;
479         ipv6_set = 1;
480       }
481     else if (unformat (line_input, "dst %U",
482                        unformat_ip6_address, &dst.ip6))
483       {
484         dst_set = 1;
485         ipv6_set = 1;
486       }
487     else if (unformat (line_input, "encap-vrf-id %d", &tmp))
488       {
489         if (ipv6_set)
490           encap_fib_index = fib6_index_from_fib_id (tmp);
491         else
492           encap_fib_index = fib4_index_from_fib_id (tmp);
493         if (encap_fib_index == ~0)
494           return clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
495       }
496     else if (unformat (line_input, "decap-next %U", unformat_decap_next, 
497                        &decap_next_index))
498       ;
499     else if (unformat (line_input, "vni %d", &vni))
500       {
501         if (vni >> 24)  
502           return clib_error_return (0, "vni %d out of range", vni);
503       }
504     else 
505       return clib_error_return (0, "parse error: '%U'", 
506                                 format_unformat_error, line_input);
507   }
508
509   unformat_free (line_input);
510
511   if (src_set == 0)
512     return clib_error_return (0, "tunnel src address not specified");
513
514   if (dst_set == 0)
515     return clib_error_return (0, "tunnel dst address not specified");
516
517   if (ipv4_set && ipv6_set)
518     return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
519
520   if ((ipv4_set && memcmp(&src.ip4, &dst.ip4, sizeof(src.ip4)) == 0) ||
521       (ipv6_set && memcmp(&src.ip6, &dst.ip6, sizeof(src.ip6)) == 0))
522     return clib_error_return (0, "src and dst addresses are identical");
523
524   if (vni == 0)
525     return clib_error_return (0, "vni not specified");
526
527   memset (a, 0, sizeof (*a));
528
529   a->is_add = is_add;
530   a->is_ip6 = ipv6_set;
531
532 #define _(x) a->x = x;
533   foreach_copy_field;
534   if (ipv4_set) foreach_copy_ipv4
535   else          foreach_copy_ipv6
536 #undef _
537   
538   rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
539
540   switch(rv)
541     {
542     case 0:
543       if (is_add)
544         vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
545       break;
546     case VNET_API_ERROR_INVALID_DECAP_NEXT:
547       return clib_error_return (0, "invalid decap-next...");
548
549     case VNET_API_ERROR_TUNNEL_EXIST:
550       return clib_error_return (0, "tunnel already exists...");
551
552     case VNET_API_ERROR_NO_SUCH_ENTRY:
553       return clib_error_return (0, "tunnel does not exist...");
554
555     default:
556       return clib_error_return 
557         (0, "vnet_vxlan_add_del_tunnel returned %d", rv);
558     }
559
560   return 0;
561 }
562
563 /*?
564  * Add or delete a VXLAN Tunnel.
565  *
566  * VXLAN provides the features needed to allow L2 bridge domains (BDs)
567  * to span multiple servers. This is done by building an L2 overlay on
568  * top of an L3 network underlay using VXLAN tunnels.
569  *
570  * This makes it possible for servers to be co-located in the same data
571  * center or be separated geographically as long as they are reachable
572  * through the underlay L3 network.
573  *
574  * You can refer to this kind of L2 overlay bridge domain as a VXLAN
575  * (Virtual eXtensible VLAN) segment.
576  *
577  * @cliexpar
578  * Example of how to create a VXLAN Tunnel:
579  * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 encap-vrf-id 7 decap-next l2}
580  * Example of how to delete a VXLAN Tunnel:
581  * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 del}
582  ?*/
583 /* *INDENT-OFF* */
584 VLIB_CLI_COMMAND (create_vxlan_tunnel_command, static) = {
585   .path = "create vxlan tunnel",
586   .short_help = 
587   "create vxlan tunnel src <local-vtep-addr> dst <remote-vtep-addr> vni <nn>" 
588   " [encap-vrf-id <nn>] [decap-next [l2|ip4|ip6]] [del]",
589   .function = vxlan_add_del_tunnel_command_fn,
590 };
591 /* *INDENT-ON* */
592
593 static clib_error_t *
594 show_vxlan_tunnel_command_fn (vlib_main_t * vm,
595                                 unformat_input_t * input,
596                                 vlib_cli_command_t * cmd)
597 {
598   vxlan_main_t * vxm = &vxlan_main;
599   vxlan_tunnel_t * t;
600   
601   if (pool_elts (vxm->tunnels) == 0)
602     vlib_cli_output (vm, "No vxlan tunnels configured...");
603
604   pool_foreach (t, vxm->tunnels,
605   ({
606     vlib_cli_output (vm, "%U", format_vxlan_tunnel, t);
607   }));
608   
609   return 0;
610 }
611
612 /*?
613  * Display all the VXLAN Tunnel entries.
614  *
615  * @cliexpar
616  * Example of how to display the VXLAN Tunnel entries:
617  * @cliexstart{show vxlan tunnel}
618  * [0] 10.0.3.1 (src) 10.0.3.3 (dst) vni 13 encap_fib_index 1 decap_next l2
619  * @cliexend
620  ?*/
621 /* *INDENT-OFF* */
622 VLIB_CLI_COMMAND (show_vxlan_tunnel_command, static) = {
623     .path = "show vxlan tunnel",
624     .short_help = "show vxlan tunnel",
625     .function = show_vxlan_tunnel_command_fn,
626 };
627 /* *INDENT-ON* */
628
629
630 clib_error_t *vxlan_init (vlib_main_t *vm)
631 {
632   vxlan_main_t * vxm = &vxlan_main;
633   
634   vxm->vnet_main = vnet_get_main();
635   vxm->vlib_main = vm;
636
637   /* initialize the ip6 hash */
638   vxm->vxlan6_tunnel_by_key = hash_create_mem(0,
639         sizeof(vxlan6_tunnel_key_t),
640         sizeof(uword));
641
642   udp_register_dst_port (vm, UDP_DST_PORT_vxlan, 
643                          vxlan4_input_node.index, /* is_ip4 */ 1);
644   udp_register_dst_port (vm, UDP_DST_PORT_vxlan6,
645                          vxlan6_input_node.index, /* is_ip4 */ 0);
646   return 0;
647 }
648
649 VLIB_INIT_FUNCTION(vxlan_init);