FD.io VPP  v16.09
Vector Packet Processing
vxlan.c
Go to the documentation of this file.
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 
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,
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 
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 *
89 {
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 
107  u32 sw_if_index,
108  u32 l3_type,
109  void * dst_address,
110  void * rewrite,
111  uword max_rewrite_bytes)
112 {
113  return 0;
114 }
115 
116 static u8 * format_vxlan_header_with_length (u8 * s, va_list * args)
117 {
118  u32 dev_instance = va_arg (*args, u32);
119  s = format (s, "unimplemented dev %u", dev_instance);
120  return s;
121 }
122 
123 VNET_HW_INTERFACE_CLASS (vxlan_hw_class) = {
124  .name = "VXLAN",
125  .format_header = format_vxlan_header_with_length,
126  .set_rewrite = dummy_set_rewrite,
127 };
128 
129 #define foreach_copy_field \
130 _(vni) \
131 _(encap_fib_index) \
132 _(decap_next_index)
133 
134 #define foreach_copy_ipv4 { \
135  _(src.ip4.as_u32) \
136  _(dst.ip4.as_u32) \
137 }
138 
139 #define foreach_copy_ipv6 { \
140  _(src.ip6.as_u64[0]) \
141  _(src.ip6.as_u64[1]) \
142  _(dst.ip6.as_u64[0]) \
143  _(dst.ip6.as_u64[1]) \
144 }
145 
147 {
148  u8 *rw = 0;
149  ip4_header_t * ip0;
150  ip4_vxlan_header_t * h0;
151  int len = sizeof (*h0);
152 
154 
155  h0 = (ip4_vxlan_header_t *) rw;
156 
157  /* Fixed portion of the (outer) ip4 header */
158  ip0 = &h0->ip4;
159  ip0->ip_version_and_header_length = 0x45;
160  ip0->ttl = 254;
161  ip0->protocol = IP_PROTOCOL_UDP;
162 
163  /* we fix up the ip4 header length and checksum after-the-fact */
164  ip0->src_address.as_u32 = t->src.ip4.as_u32;
165  ip0->dst_address.as_u32 = t->dst.ip4.as_u32;
166  ip0->checksum = ip4_header_checksum (ip0);
167 
168  /* UDP header, randomize src port on something, maybe? */
169  h0->udp.src_port = clib_host_to_net_u16 (4789);
170  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
171 
172  /* VXLAN header */
173  vnet_set_vni_and_flags(&h0->vxlan, t->vni);
174 
175  t->rewrite = rw;
176  return (0);
177 }
178 
180 {
181  u8 *rw = 0;
182  ip6_header_t * ip0;
183  ip6_vxlan_header_t * h0;
184  int len = sizeof (*h0);
185 
187 
188  h0 = (ip6_vxlan_header_t *) rw;
189 
190  /* Fixed portion of the (outer) ip6 header */
191  ip0 = &h0->ip6;
192  ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
193  ip0->hop_limit = 255;
194  ip0->protocol = IP_PROTOCOL_UDP;
195 
196  ip0->src_address.as_u64[0] = t->src.ip6.as_u64[0];
197  ip0->src_address.as_u64[1] = t->src.ip6.as_u64[1];
198  ip0->dst_address.as_u64[0] = t->dst.ip6.as_u64[0];
199  ip0->dst_address.as_u64[1] = t->dst.ip6.as_u64[1];
200 
201  /* UDP header, randomize src port on something, maybe? */
202  h0->udp.src_port = clib_host_to_net_u16 (4789);
203  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
204 
205  /* VXLAN header */
206  vnet_set_vni_and_flags(&h0->vxlan, t->vni);
207 
208  t->rewrite = rw;
209  return (0);
210 }
211 
214 {
215  vxlan_main_t * vxm = &vxlan_main;
216  vxlan_tunnel_t *t = 0;
217  vnet_main_t * vnm = vxm->vnet_main;
218  ip4_main_t * im4 = &ip4_main;
219  ip6_main_t * im6 = &ip6_main;
221  uword * p;
222  u32 hw_if_index = ~0;
223  u32 sw_if_index = ~0;
224  int rv;
225  vxlan4_tunnel_key_t key4;
226  vxlan6_tunnel_key_t key6;
227  l2output_main_t * l2om = &l2output_main;
228 
229  if (!a->is_ip6) {
230  key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
231  key4.vni = clib_host_to_net_u32 (a->vni << 8);
232 
233  p = hash_get (vxm->vxlan4_tunnel_by_key, key4.as_u64);
234  } else {
235  key6.src.as_u64[0] = a->dst.ip6.as_u64[0];
236  key6.src.as_u64[1] = a->dst.ip6.as_u64[1];
237  key6.vni = clib_host_to_net_u32 (a->vni << 8);
238 
239  p = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6);
240  }
241 
242  if (a->is_add)
243  {
244  /* adding a tunnel: tunnel must not already exist */
245  if (p)
246  return VNET_API_ERROR_TUNNEL_EXIST;
247 
248  if (a->decap_next_index == ~0)
249  a->decap_next_index = VXLAN_INPUT_NEXT_L2_INPUT;
250 
252  return VNET_API_ERROR_INVALID_DECAP_NEXT;
253 
255  memset (t, 0, sizeof (*t));
256 
257  /* copy from arg structure */
258 #define _(x) t->x = a->x;
260  if (!a->is_ip6) foreach_copy_ipv4
261  else foreach_copy_ipv6
262 #undef _
263 
264  /* copy the key */
265  if (a->is_ip6)
266  {
267  t->key6 = clib_mem_alloc (sizeof(vxlan6_tunnel_key_t));
268  clib_memcpy (t->key6, &key6, sizeof(key6));
269  }
270  else
271  {
272  t->key4 = 0; /* not yet used */
273  }
274 
275  if (!a->is_ip6) t->flags |= VXLAN_TUNNEL_IS_IPV4;
276 
277  if (!a->is_ip6) {
278  rv = vxlan4_rewrite (t);
279  } else {
280  rv = vxlan6_rewrite (t);
281  }
282 
283  if (rv)
284  {
285  pool_put (vxm->tunnels, t);
286  return rv;
287  }
288 
289  if (!a->is_ip6)
290  hash_set (vxm->vxlan4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
291  else
292  hash_set_mem (vxm->vxlan6_tunnel_by_key, t->key6, t - vxm->tunnels);
293 
295  {
297  hw_if_index = vxm->free_vxlan_tunnel_hw_if_indices
299  _vec_len (vxm->free_vxlan_tunnel_hw_if_indices) -= 1;
300 
301  hi = vnet_get_hw_interface (vnm, hw_if_index);
302  hi->dev_instance = t - vxm->tunnels;
303  hi->hw_instance = hi->dev_instance;
304 
305  /* clear old stats of freed tunnel before reuse */
306  sw_if_index = hi->sw_if_index;
313  (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
315  }
316  else
317  {
318  hw_if_index = vnet_register_interface
319  (vnm, vxlan_device_class.index, t - vxm->tunnels,
320  vxlan_hw_class.index, t - vxm->tunnels);
321  hi = vnet_get_hw_interface (vnm, hw_if_index);
323  }
324 
325  t->hw_if_index = hw_if_index;
326  t->sw_if_index = sw_if_index = hi->sw_if_index;
327 
329  vxm->tunnel_index_by_sw_if_index[sw_if_index] = t - vxm->tunnels;
330 
331  if (a->decap_next_index == VXLAN_INPUT_NEXT_L2_INPUT)
332  {
333  l2input_main_t * l2im = &l2input_main;
334  /* setup l2 input config with l2 feature and bd 0 to drop packet */
335  vec_validate (l2im->configs, sw_if_index);
336  l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
337  l2im->configs[sw_if_index].bd_index = 0;
338  }
339 
340  /*
341  * Directs the l2 output path to work out the interface
342  * output next-arc itself. Needed when recycling a tunnel.
343  */
345  sw_if_index, ~0);
347  = ~0;
348  vnet_sw_interface_set_flags (vnm, sw_if_index,
350  if (!a->is_ip6) {
351  vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
352  im4->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
353  } else {
354  vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
355  im6->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
356  }
357  }
358  else
359  {
360  /* deleting a tunnel: tunnel must exist */
361  if (!p)
362  return VNET_API_ERROR_NO_SUCH_ENTRY;
363 
364  t = pool_elt_at_index (vxm->tunnels, p[0]);
365 
366  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */);
367  /* make sure tunnel is removed from l2 bd or xconnect */
368  set_int_l2_mode(vxm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0);
370 
372 
373  /* Directs the l2 path to turf packets sent to this sw_if_index */
376 
377  if (!a->is_ip6)
378  hash_unset (vxm->vxlan4_tunnel_by_key, key4.as_u64);
379  else
380  {
382  clib_mem_free (t->key6);
383  }
384 
385  vec_free (t->rewrite);
386  pool_put (vxm->tunnels, t);
387  }
388 
389  if (sw_if_indexp)
390  *sw_if_indexp = sw_if_index;
391 
392  return 0;
393 }
394 
396 {
397  ip4_main_t * im = &ip4_main;
398  uword * p;
399 
400  p = hash_get (im->fib_index_by_table_id, fib_id);
401  if (!p)
402  return ~0;
403 
404  return p[0];
405 }
406 
408 {
409  ip6_main_t * im = &ip6_main;
410  uword * p;
411 
412  p = hash_get (im->fib_index_by_table_id, fib_id);
413  if (!p)
414  return ~0;
415 
416  return p[0];
417 }
418 
419 static uword unformat_decap_next (unformat_input_t * input, va_list * args)
420 {
421  u32 * result = va_arg (*args, u32 *);
422  u32 tmp;
423 
424  if (unformat (input, "l2"))
425  *result = VXLAN_INPUT_NEXT_L2_INPUT;
426  else if (unformat (input, "drop"))
427  *result = VXLAN_INPUT_NEXT_DROP;
428  else if (unformat (input, "ip4"))
429  *result = VXLAN_INPUT_NEXT_IP4_INPUT;
430  else if (unformat (input, "ip6"))
431  *result = VXLAN_INPUT_NEXT_IP6_INPUT;
432  else if (unformat (input, "%d", &tmp))
433  *result = tmp;
434  else
435  return 0;
436  return 1;
437 }
438 
439 static clib_error_t *
441  unformat_input_t * input,
442  vlib_cli_command_t * cmd)
443 {
444  unformat_input_t _line_input, * line_input = &_line_input;
445  ip46_address_t src, dst;
446  u8 is_add = 1;
447  u8 src_set = 0;
448  u8 dst_set = 0;
449  u8 ipv4_set = 0;
450  u8 ipv6_set = 0;
451  u32 encap_fib_index = 0;
452  u32 decap_next_index = ~0;
453  u32 vni = 0;
454  u32 tmp;
455  int rv;
456  vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a;
457  u32 sw_if_index;
458 
459  /* Get a line of input. */
460  if (! unformat_user (input, unformat_line_input, line_input))
461  return 0;
462 
463  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
464  if (unformat (line_input, "del"))
465  {
466  is_add = 0;
467  }
468  else if (unformat (line_input, "src %U",
469  unformat_ip4_address, &src.ip4))
470  {
471  src_set = 1;
472  ipv4_set = 1;
473  }
474  else if (unformat (line_input, "dst %U",
475  unformat_ip4_address, &dst.ip4))
476  {
477  dst_set = 1;
478  ipv4_set = 1;
479  }
480  else if (unformat (line_input, "src %U",
481  unformat_ip6_address, &src.ip6))
482  {
483  src_set = 1;
484  ipv6_set = 1;
485  }
486  else if (unformat (line_input, "dst %U",
487  unformat_ip6_address, &dst.ip6))
488  {
489  dst_set = 1;
490  ipv6_set = 1;
491  }
492  else if (unformat (line_input, "encap-vrf-id %d", &tmp))
493  {
494  if (ipv6_set)
495  encap_fib_index = fib6_index_from_fib_id (tmp);
496  else
497  encap_fib_index = fib4_index_from_fib_id (tmp);
498  if (encap_fib_index == ~0)
499  return clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
500  }
501  else if (unformat (line_input, "decap-next %U", unformat_decap_next,
502  &decap_next_index))
503  ;
504  else if (unformat (line_input, "vni %d", &vni))
505  {
506  if (vni >> 24)
507  return clib_error_return (0, "vni %d out of range", vni);
508  }
509  else
510  return clib_error_return (0, "parse error: '%U'",
511  format_unformat_error, line_input);
512  }
513 
514  unformat_free (line_input);
515 
516  if (src_set == 0)
517  return clib_error_return (0, "tunnel src address not specified");
518 
519  if (dst_set == 0)
520  return clib_error_return (0, "tunnel dst address not specified");
521 
522  if (ipv4_set && ipv6_set)
523  return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
524 
525  if ((ipv4_set && memcmp(&src.ip4, &dst.ip4, sizeof(src.ip4)) == 0) ||
526  (ipv6_set && memcmp(&src.ip6, &dst.ip6, sizeof(src.ip6)) == 0))
527  return clib_error_return (0, "src and dst addresses are identical");
528 
529  if (vni == 0)
530  return clib_error_return (0, "vni not specified");
531 
532  memset (a, 0, sizeof (*a));
533 
534  a->is_add = is_add;
535  a->is_ip6 = ipv6_set;
536 
537 #define _(x) a->x = x;
539  if (ipv4_set) foreach_copy_ipv4
540  else foreach_copy_ipv6
541 #undef _
542 
543  rv = vnet_vxlan_add_del_tunnel (a, &sw_if_index);
544 
545  switch(rv)
546  {
547  case 0:
548  if (is_add)
549  vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index);
550  break;
551  case VNET_API_ERROR_INVALID_DECAP_NEXT:
552  return clib_error_return (0, "invalid decap-next...");
553 
554  case VNET_API_ERROR_TUNNEL_EXIST:
555  return clib_error_return (0, "tunnel already exists...");
556 
557  case VNET_API_ERROR_NO_SUCH_ENTRY:
558  return clib_error_return (0, "tunnel does not exist...");
559 
560  default:
561  return clib_error_return
562  (0, "vnet_vxlan_add_del_tunnel returned %d", rv);
563  }
564 
565  return 0;
566 }
567 
568 /*?
569  * Add or delete a VXLAN Tunnel.
570  *
571  * VXLAN provides the features needed to allow L2 bridge domains (BDs)
572  * to span multiple servers. This is done by building an L2 overlay on
573  * top of an L3 network underlay using VXLAN tunnels.
574  *
575  * This makes it possible for servers to be co-located in the same data
576  * center or be separated geographically as long as they are reachable
577  * through the underlay L3 network.
578  *
579  * You can refer to this kind of L2 overlay bridge domain as a VXLAN
580  * (Virtual eXtensible VLAN) segment.
581  *
582  * @cliexpar
583  * Example of how to create a VXLAN Tunnel:
584  * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 encap-vrf-id 7 decap-next l2}
585  * Example of how to delete a VXLAN Tunnel:
586  * @cliexcmd{create vxlan tunnel src 10.0.3.1 dst 10.0.3.3 vni 13 del}
587  ?*/
588 /* *INDENT-OFF* */
589 VLIB_CLI_COMMAND (create_vxlan_tunnel_command, static) = {
590  .path = "create vxlan tunnel",
591  .short_help =
592  "create vxlan tunnel src <local-vtep-addr> dst <remote-vtep-addr> vni <nn>"
593  " [encap-vrf-id <nn>] [decap-next [l2|ip4|ip6]] [del]",
595 };
596 /* *INDENT-ON* */
597 
598 static clib_error_t *
600  unformat_input_t * input,
601  vlib_cli_command_t * cmd)
602 {
603  vxlan_main_t * vxm = &vxlan_main;
604  vxlan_tunnel_t * t;
605 
606  if (pool_elts (vxm->tunnels) == 0)
607  vlib_cli_output (vm, "No vxlan tunnels configured...");
608 
609  pool_foreach (t, vxm->tunnels,
610  ({
611  vlib_cli_output (vm, "%U", format_vxlan_tunnel, t);
612  }));
613 
614  return 0;
615 }
616 
617 /*?
618  * Display all the VXLAN Tunnel entries.
619  *
620  * @cliexpar
621  * Example of how to display the VXLAN Tunnel entries:
622  * @cliexstart{show vxlan tunnel}
623  * [0] 10.0.3.1 (src) 10.0.3.3 (dst) vni 13 encap_fib_index 1 decap_next l2
624  * @cliexend
625  ?*/
626 /* *INDENT-OFF* */
627 VLIB_CLI_COMMAND (show_vxlan_tunnel_command, static) = {
628  .path = "show vxlan tunnel",
629  .short_help = "show vxlan tunnel",
630  .function = show_vxlan_tunnel_command_fn,
631 };
632 /* *INDENT-ON* */
633 
634 
636 {
637  vxlan_main_t * vxm = &vxlan_main;
638 
639  vxm->vnet_main = vnet_get_main();
640  vxm->vlib_main = vm;
641 
642  /* initialize the ip6 hash */
644  sizeof(vxlan6_tunnel_key_t),
645  sizeof(uword));
646 
647  udp_register_dst_port (vm, UDP_DST_PORT_vxlan,
648  vxlan4_input_node.index, /* is_ip4 */ 1);
649  udp_register_dst_port (vm, UDP_DST_PORT_vxlan6,
650  vxlan6_input_node.index, /* is_ip4 */ 0);
651  return 0;
652 }
653 
format_function_t format_ip46_address
Definition: format.h:54
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
vmrglw vmrglh hi
#define hash_set(h, key, value)
Definition: hash.h:254
l2_input_config_t * configs
Definition: l2_input.h:66
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:513
#define hash_unset(h, key)
Definition: hash.h:260
ip4_address_t src_address
Definition: ip4_packet.h:138
vnet_interface_main_t interface_main
Definition: vnet.h:64
clib_error_t * vxlan_init(vlib_main_t *vm)
Definition: vxlan.c:635
vlib_node_registration_t vxlan4_input_node
(constructor) VLIB_REGISTER_NODE (vxlan4_input_node)
Definition: decap.c:22
static uword dummy_set_rewrite(vnet_main_t *vnm, u32 sw_if_index, u32 l3_type, void *dst_address, void *rewrite, uword max_rewrite_bytes)
Definition: vxlan.c:106
u64 as_u64[2]
Definition: ip6_packet.h:50
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
ip46_address_t dst
Definition: vxlan.h:72
static u32 fib4_index_from_fib_id(u32 fib_id)
Definition: vxlan.c:395
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
vxlan6_tunnel_key_t * key6
Definition: vxlan.h:89
#define hash_set_mem(h, key, value)
Definition: hash.h:274
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:123
static u32 fib6_index_from_fib_id(u32 fib_id)
Definition: vxlan.c:407
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:273
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:407
ip6_address_t src_address
Definition: ip6_packet.h:298
l2_output_next_nodes_st next_nodes
Definition: l2_output.h:76
format_function_t format_vnet_sw_if_index_name
static clib_error_t * show_vxlan_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan.c:599
#define foreach_copy_ipv6
Definition: vxlan.c:139
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
vnet_main_t * vnet_main
Definition: vxlan.h:135
VNET_DEVICE_CLASS(vxlan_device_class, static)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
ip4_address_t dst_address
Definition: ip4_packet.h:138
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:501
vlib_main_t * vlib_main
Definition: vxlan.h:134
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
#define clib_warning(format, args...)
Definition: error.h:59
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
static clib_error_t * vxlan_add_del_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: vxlan.c:440
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:650
u32 set_int_l2_mode(vlib_main_t *vm, vnet_main_t *vnet_main, u32 mode, u32 sw_if_index, u32 bd_index, u32 bvi, u32 shg, u32 xc_sw_if_index)
Set the subinterface to run in l2 or l3 mode.
Definition: l2_input.c:542
unformat_function_t unformat_ip4_address
Definition: format.h:68
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:626
#define hash_get(h, key)
Definition: hash.h:248
u8 * rewrite
Definition: vxlan.h:68
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread u16 counters, and the shared vlib_counter_t...
Definition: counter.h:321
#define hash_unset_mem(h, key)
Definition: hash.h:280
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:127
static clib_error_t * vxlan_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: vxlan.c:88
uword * vxlan4_tunnel_by_key
Definition: vxlan.h:124
#define foreach_copy_ipv4
Definition: vxlan.c:134
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:214
vxlan_main_t vxlan_main
Definition: vxlan.c:35
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:500
vlib_node_registration_t vxlan6_input_node
(constructor) VLIB_REGISTER_NODE (vxlan6_input_node)
Definition: decap.c:23
l2output_main_t l2output_main
Definition: l2_output.c:43
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
u8 * format_vxlan_encap_trace(u8 *s, va_list *args)
Definition: encap.c:51
unformat_function_t unformat_ip6_address
Definition: format.h:86
uword * fib_index_by_table_id
Definition: ip6.h:127
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
int vnet_vxlan_add_del_tunnel(vnet_vxlan_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: vxlan.c:213
u16 encap_fib_index
Definition: vxlan.h:81
u16 n_vectors
Definition: node.h:344
static uword dummy_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: vxlan.c:79
static int vxlan4_rewrite(vxlan_tunnel_t *t)
Definition: vxlan.c:146
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
#define clib_memcpy(a, b, c)
Definition: string.h:63
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:524
static void vnet_set_vni_and_flags(vxlan_header_t *h, u32 vni)
Definition: vxlan_packet.h:60
static uword unformat_decap_next(unformat_input_t *input, va_list *args)
Definition: vxlan.c:419
u32 decap_next_index
Definition: vxlan.h:78
static u8 * format_vxlan_header_with_length(u8 *s, va_list *args)
Definition: vxlan.c:116
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:516
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:415
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip6_main_t ip6_main
Definition: ip6_forward.c:2955
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:418
IPv4 main type.
Definition: ip4.h:114
static void clib_mem_free(void *p)
Definition: mem.h:154
uword * vxlan6_tunnel_by_key
Definition: vxlan.h:125
u32 sw_if_index
Definition: vxlan.h:85
vlib_node_registration_t vxlan_encap_node
(constructor) VLIB_REGISTER_NODE (vxlan_encap_node)
Definition: encap.c:544
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
Definition: counter.h:143
static void * clib_mem_alloc(uword size)
Definition: mem.h:107
u64 uword
Definition: types.h:112
#define foreach_copy_field
Definition: vxlan.c:129
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:285
static int vxlan6_rewrite(vxlan_tunnel_t *t)
Definition: vxlan.c:179
l2input_main_t l2input_main
Definition: l2_input.c:76
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
u16 hw_if_index
Definition: vxlan.h:84
u32 flags
Definition: vxlan.h:93
#define VXLAN_TUNNEL_IS_IPV4
Definition: vxlan.h:97
u32 * tunnel_index_by_sw_if_index
Definition: vxlan.h:131
#define hash_get_mem(h, key)
Definition: hash.h:268
static u8 * format_decap_next(u8 *s, va_list *args)
Definition: vxlan.c:37
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1578
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:521
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:461
vxlan4_tunnel_key_t * key4
Definition: vxlan.h:88
#define clib_error_return(e, args...)
Definition: error.h:111
VNET_HW_INTERFACE_CLASS(vxlan_hw_class)
u8 ip_version_and_header_length
Definition: ip4_packet.h:108
struct _unformat_input_t unformat_input_t
u32 flags
Definition: vhost-user.h:76
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:445
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
unformat_function_t unformat_line_input
Definition: format.h:281
u32 * fib_index_by_sw_if_index
Definition: ip6.h:123
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:194
vxlan_tunnel_t * tunnels
Definition: vxlan.h:121
u32 * free_vxlan_tunnel_hw_if_indices
Definition: vxlan.h:128
ip46_address_t src
Definition: vxlan.h:71
u8 * format_vxlan_tunnel(u8 *s, va_list *args)
Definition: vxlan.c:57
static u8 * format_vxlan_name(u8 *s, va_list *args)
Definition: vxlan.c:73
ip6_address_t dst_address
Definition: ip6_packet.h:298
#define MODE_L3
Definition: l2_input.h:215
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109