FD.io VPP  v16.06
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 
19 
20 static u8 * format_decap_next (u8 * s, va_list * args)
21 {
22  u32 next_index = va_arg (*args, u32);
23 
24  switch (next_index)
25  {
26  case VXLAN_INPUT_NEXT_DROP:
27  return format (s, "drop");
28  case VXLAN_INPUT_NEXT_L2_INPUT:
29  return format (s, "l2");
30  case VXLAN_INPUT_NEXT_IP4_INPUT:
31  return format (s, "ip4");
32  case VXLAN_INPUT_NEXT_IP6_INPUT:
33  return format (s, "ip6");
34  default:
35  return format (s, "unknown %d", next_index);
36  }
37  return s;
38 }
39 
40 u8 * format_vxlan_tunnel (u8 * s, va_list * args)
41 {
42  vxlan_tunnel_t * t = va_arg (*args, vxlan_tunnel_t *);
43  vxlan_main_t * ngm = &vxlan_main;
44 
45  s = format (s,
46  "[%d] %U (src) %U (dst) vni %d encap_fib_index %d",
47  t - ngm->tunnels,
50  t->vni,
51  t->encap_fib_index);
52  s = format (s, " decap_next %U\n", format_decap_next, t->decap_next_index);
53  return s;
54 }
55 
56 static u8 * format_vxlan_name (u8 * s, va_list * args)
57 {
58  u32 dev_instance = va_arg (*args, u32);
59  return format (s, "vxlan_tunnel%d", dev_instance);
60 }
61 
63  vlib_node_runtime_t * node,
64  vlib_frame_t * frame)
65 {
66  clib_warning ("you shouldn't be here, leaking buffers...");
67  return frame->n_vectors;
68 }
69 
70 static clib_error_t *
72 {
75  else
76  vnet_hw_interface_set_flags (vnm, hw_if_index, 0);
77 
78  return /* no error */ 0;
79 }
80 
81 VNET_DEVICE_CLASS (vxlan_device_class,static) = {
82  .name = "VXLAN",
83  .format_device_name = format_vxlan_name,
84  .format_tx_trace = format_vxlan_encap_trace,
85  .tx_function = dummy_interface_tx,
86  .admin_up_down_function = vxlan_interface_admin_up_down,
87 };
88 
90  u32 sw_if_index,
91  u32 l3_type,
92  void * dst_address,
93  void * rewrite,
94  uword max_rewrite_bytes)
95 {
96  return 0;
97 }
98 
99 static u8 * format_vxlan_header_with_length (u8 * s, va_list * args)
100 {
101  u32 dev_instance = va_arg (*args, u32);
102  s = format (s, "unimplemented dev %u", dev_instance);
103  return s;
104 }
105 
106 VNET_HW_INTERFACE_CLASS (vxlan_hw_class) = {
107  .name = "VXLAN",
108  .format_header = format_vxlan_header_with_length,
109  .set_rewrite = dummy_set_rewrite,
110 };
111 
112 #define foreach_copy_field \
113 _(vni) \
114 _(encap_fib_index) \
115 _(decap_next_index)
116 
117 #define foreach_copy_ipv4 { \
118  _(src.ip4.as_u32) \
119  _(dst.ip4.as_u32) \
120 }
121 
122 #define foreach_copy_ipv6 { \
123  _(src.ip6.as_u64[0]) \
124  _(src.ip6.as_u64[1]) \
125  _(dst.ip6.as_u64[0]) \
126  _(dst.ip6.as_u64[1]) \
127 }
128 
130 {
131  u8 *rw = 0;
132  ip4_header_t * ip0;
133  ip4_vxlan_header_t * h0;
134  int len = sizeof (*h0);
135 
137 
138  h0 = (ip4_vxlan_header_t *) rw;
139 
140  /* Fixed portion of the (outer) ip4 header */
141  ip0 = &h0->ip4;
142  ip0->ip_version_and_header_length = 0x45;
143  ip0->ttl = 254;
144  ip0->protocol = IP_PROTOCOL_UDP;
145 
146  /* we fix up the ip4 header length and checksum after-the-fact */
147  ip0->src_address.as_u32 = t->src.ip4.as_u32;
148  ip0->dst_address.as_u32 = t->dst.ip4.as_u32;
149  ip0->checksum = ip4_header_checksum (ip0);
150 
151  /* UDP header, randomize src port on something, maybe? */
152  h0->udp.src_port = clib_host_to_net_u16 (4789);
153  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
154 
155  /* VXLAN header */
156  vnet_set_vni_and_flags(&h0->vxlan, t->vni);
157 
158  t->rewrite = rw;
159  return (0);
160 }
161 
163 {
164  u8 *rw = 0;
165  ip6_header_t * ip0;
166  ip6_vxlan_header_t * h0;
167  int len = sizeof (*h0);
168 
170 
171  h0 = (ip6_vxlan_header_t *) rw;
172 
173  /* Fixed portion of the (outer) ip6 header */
174  ip0 = &h0->ip6;
175  ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
176  ip0->hop_limit = 255;
177  ip0->protocol = IP_PROTOCOL_UDP;
178 
179  ip0->src_address.as_u64[0] = t->src.ip6.as_u64[0];
180  ip0->src_address.as_u64[1] = t->src.ip6.as_u64[1];
181  ip0->dst_address.as_u64[0] = t->dst.ip6.as_u64[0];
182  ip0->dst_address.as_u64[1] = t->dst.ip6.as_u64[1];
183 
184  /* UDP header, randomize src port on something, maybe? */
185  h0->udp.src_port = clib_host_to_net_u16 (4789);
186  h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_vxlan);
187 
188  /* VXLAN header */
189  vnet_set_vni_and_flags(&h0->vxlan, t->vni);
190 
191  t->rewrite = rw;
192  return (0);
193 }
194 
197 {
198  vxlan_main_t * vxm = &vxlan_main;
199  vxlan_tunnel_t *t = 0;
200  vnet_main_t * vnm = vxm->vnet_main;
201  ip4_main_t * im4 = &ip4_main;
202  ip6_main_t * im6 = &ip6_main;
204  uword * p;
205  u32 hw_if_index = ~0;
206  u32 sw_if_index = ~0;
207  int rv;
208  vxlan4_tunnel_key_t key4;
209  vxlan6_tunnel_key_t key6;
210 
211  if (!a->is_ip6) {
212  key4.src = a->dst.ip4.as_u32; /* decap src in key is encap dst in config */
213  key4.vni = clib_host_to_net_u32 (a->vni << 8);
214 
215  p = hash_get (vxm->vxlan4_tunnel_by_key, key4.as_u64);
216  } else {
217  key6.src.as_u64[0] = a->dst.ip6.as_u64[0];
218  key6.src.as_u64[1] = a->dst.ip6.as_u64[1];
219  key6.vni = clib_host_to_net_u32 (a->vni << 8);
220 
221  p = hash_get_mem (vxm->vxlan6_tunnel_by_key, &key6);
222  }
223 
224  if (a->is_add)
225  {
226  /* adding a tunnel: tunnel must not already exist */
227  if (p)
228  return VNET_API_ERROR_TUNNEL_EXIST;
229 
230  if (a->decap_next_index == ~0)
231  a->decap_next_index = VXLAN_INPUT_NEXT_L2_INPUT;
232 
234  return VNET_API_ERROR_INVALID_DECAP_NEXT;
235 
237  memset (t, 0, sizeof (*t));
238 
239  /* copy from arg structure */
240 #define _(x) t->x = a->x;
242  if (!a->is_ip6) foreach_copy_ipv4
243  else foreach_copy_ipv6
244 #undef _
245 
246  /* copy the key */
247  if (a->is_ip6)
248  {
249  t->key6 = clib_mem_alloc (sizeof(vxlan6_tunnel_key_t));
250  clib_memcpy (t->key6, &key6, sizeof(key6));
251  }
252  else
253  {
254  t->key4 = 0; /* not yet used */
255  }
256 
257  if (!a->is_ip6) t->flags |= VXLAN_TUNNEL_IS_IPV4;
258 
259  if (!a->is_ip6) {
260  rv = vxlan4_rewrite (t);
261  } else {
262  rv = vxlan6_rewrite (t);
263  }
264 
265  if (rv)
266  {
267  pool_put (vxm->tunnels, t);
268  return rv;
269  }
270 
271  if (!a->is_ip6)
272  hash_set (vxm->vxlan4_tunnel_by_key, key4.as_u64, t - vxm->tunnels);
273  else
274  hash_set_mem (vxm->vxlan6_tunnel_by_key, t->key6, t - vxm->tunnels);
275 
277  {
279  hw_if_index = vxm->free_vxlan_tunnel_hw_if_indices
281  _vec_len (vxm->free_vxlan_tunnel_hw_if_indices) -= 1;
282 
283  hi = vnet_get_hw_interface (vnm, hw_if_index);
284  hi->dev_instance = t - vxm->tunnels;
285  hi->hw_instance = hi->dev_instance;
286 
287  /* clear old stats of freed tunnel before reuse */
288  sw_if_index = hi->sw_if_index;
295  (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index);
297  }
298  else
299  {
300  hw_if_index = vnet_register_interface
301  (vnm, vxlan_device_class.index, t - vxm->tunnels,
302  vxlan_hw_class.index, t - vxm->tunnels);
303  hi = vnet_get_hw_interface (vnm, hw_if_index);
305  }
306 
307  t->hw_if_index = hw_if_index;
308  t->sw_if_index = sw_if_index = hi->sw_if_index;
309 
311  vxm->tunnel_index_by_sw_if_index[sw_if_index] = t - vxm->tunnels;
312 
313  if (a->decap_next_index == VXLAN_INPUT_NEXT_L2_INPUT)
314  {
315  l2input_main_t * l2im = &l2input_main;
316  /* setup l2 input config with l2 feature and bd 0 to drop packet */
317  vec_validate (l2im->configs, sw_if_index);
318  l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP;
319  l2im->configs[sw_if_index].bd_index = 0;
320  }
321  vnet_sw_interface_set_flags (vnm, sw_if_index,
323  if (!a->is_ip6) {
324  vec_validate (im4->fib_index_by_sw_if_index, sw_if_index);
325  im4->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
326  } else {
327  vec_validate (im6->fib_index_by_sw_if_index, sw_if_index);
328  im6->fib_index_by_sw_if_index[sw_if_index] = t->encap_fib_index;
329  }
330  }
331  else
332  {
333  /* deleting a tunnel: tunnel must exist */
334  if (!p)
335  return VNET_API_ERROR_NO_SUCH_ENTRY;
336 
337  t = pool_elt_at_index (vxm->tunnels, p[0]);
338 
339  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */);
340  /* make sure tunnel is removed from l2 bd or xconnect */
341  set_int_l2_mode(vxm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0);
343 
345 
346  if (!a->is_ip6)
347  hash_unset (vxm->vxlan4_tunnel_by_key, key4.as_u64);
348  else
350 
351  vec_free (t->rewrite);
352  if (!a->is_ip6)
353  {
355  t->key4 = 0;
356  }
357  else
358  {
360  clib_mem_free (t->key6);
361  t->key6 = 0;
362  }
363 
364  pool_put (vxm->tunnels, t);
365  }
366 
367  if (sw_if_indexp)
368  *sw_if_indexp = sw_if_index;
369 
370  return 0;
371 }
372 
374 {
375  ip4_main_t * im = &ip4_main;
376  uword * p;
377 
378  p = hash_get (im->fib_index_by_table_id, fib_id);
379  if (!p)
380  return ~0;
381 
382  return p[0];
383 }
384 
386 {
387  ip6_main_t * im = &ip6_main;
388  uword * p;
389 
390  p = hash_get (im->fib_index_by_table_id, fib_id);
391  if (!p)
392  return ~0;
393 
394  return p[0];
395 }
396 
397 static uword unformat_decap_next (unformat_input_t * input, va_list * args)
398 {
399  u32 * result = va_arg (*args, u32 *);
400  u32 tmp;
401 
402  if (unformat (input, "l2"))
403  *result = VXLAN_INPUT_NEXT_L2_INPUT;
404  else if (unformat (input, "drop"))
405  *result = VXLAN_INPUT_NEXT_DROP;
406  else if (unformat (input, "ip4"))
407  *result = VXLAN_INPUT_NEXT_IP4_INPUT;
408  else if (unformat (input, "ip6"))
409  *result = VXLAN_INPUT_NEXT_IP6_INPUT;
410  else if (unformat (input, "%d", &tmp))
411  *result = tmp;
412  else
413  return 0;
414  return 1;
415 }
416 
417 static clib_error_t *
419  unformat_input_t * input,
420  vlib_cli_command_t * cmd)
421 {
422  unformat_input_t _line_input, * line_input = &_line_input;
423  ip46_address_t src, dst;
424  u8 is_add = 1;
425  u8 src_set = 0;
426  u8 dst_set = 0;
427  u8 ipv4_set = 0;
428  u8 ipv6_set = 0;
429  u32 encap_fib_index = 0;
430  u32 decap_next_index = ~0;
431  u32 vni = 0;
432  u32 tmp;
433  int rv;
434  vnet_vxlan_add_del_tunnel_args_t _a, * a = &_a;
435 
436  /* Get a line of input. */
437  if (! unformat_user (input, unformat_line_input, line_input))
438  return 0;
439 
440  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
441  if (unformat (line_input, "del"))
442  {
443  is_add = 0;
444  }
445  else if (unformat (line_input, "src %U",
446  unformat_ip4_address, &src.ip4))
447  {
448  src_set = 1;
449  ipv4_set = 1;
450  }
451  else if (unformat (line_input, "dst %U",
452  unformat_ip4_address, &dst.ip4))
453  {
454  dst_set = 1;
455  ipv4_set = 1;
456  }
457  else if (unformat (line_input, "src %U",
458  unformat_ip6_address, &src.ip6))
459  {
460  src_set = 1;
461  ipv6_set = 1;
462  }
463  else if (unformat (line_input, "dst %U",
464  unformat_ip6_address, &dst.ip6))
465  {
466  dst_set = 1;
467  ipv6_set = 1;
468  }
469  else if (unformat (line_input, "encap-vrf-id %d", &tmp))
470  {
471  if (ipv6_set)
472  encap_fib_index = fib6_index_from_fib_id (tmp);
473  else
474  encap_fib_index = fib4_index_from_fib_id (tmp);
475  if (encap_fib_index == ~0)
476  return clib_error_return (0, "nonexistent encap-vrf-id %d", tmp);
477  }
478  else if (unformat (line_input, "decap-next %U", unformat_decap_next,
479  &decap_next_index))
480  ;
481  else if (unformat (line_input, "vni %d", &vni))
482  {
483  if (vni >> 24)
484  return clib_error_return (0, "vni %d out of range", vni);
485  }
486  else
487  return clib_error_return (0, "parse error: '%U'",
488  format_unformat_error, line_input);
489  }
490 
491  unformat_free (line_input);
492 
493  if (src_set == 0)
494  return clib_error_return (0, "tunnel src address not specified");
495 
496  if (dst_set == 0)
497  return clib_error_return (0, "tunnel dst address not specified");
498 
499  if (ipv4_set && ipv6_set)
500  return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
501 
502  if ((ipv4_set && memcmp(&src.ip4, &dst.ip4, sizeof(src.ip4)) == 0) ||
503  (ipv6_set && memcmp(&src.ip6, &dst.ip6, sizeof(src.ip6)) == 0))
504  return clib_error_return (0, "src and dst addresses are identical");
505 
506  if (vni == 0)
507  return clib_error_return (0, "vni not specified");
508 
509  memset (a, 0, sizeof (*a));
510 
511  a->is_add = is_add;
512  a->is_ip6 = ipv6_set;
513 
514 #define _(x) a->x = x;
516  if (ipv4_set) foreach_copy_ipv4
517  else foreach_copy_ipv6
518 #undef _
519 
520  rv = vnet_vxlan_add_del_tunnel (a, 0 /* hw_if_indexp */);
521 
522  switch(rv)
523  {
524  case 0:
525  break;
526  case VNET_API_ERROR_INVALID_DECAP_NEXT:
527  return clib_error_return (0, "invalid decap-next...");
528 
529  case VNET_API_ERROR_TUNNEL_EXIST:
530  return clib_error_return (0, "tunnel already exists...");
531 
532  case VNET_API_ERROR_NO_SUCH_ENTRY:
533  return clib_error_return (0, "tunnel does not exist...");
534 
535  default:
536  return clib_error_return
537  (0, "vnet_vxlan_add_del_tunnel returned %d", rv);
538  }
539 
540  return 0;
541 }
542 
543 VLIB_CLI_COMMAND (create_vxlan_tunnel_command, static) = {
544  .path = "create vxlan tunnel",
545  .short_help =
546  "create vxlan tunnel src <local-vtep-addr> dst <remote-vtep-addr> vni <nn>"
547  " [encap-vrf-id <nn>] [decap-next [l2|ip4|ip6] [del]\n",
549 };
550 
551 static clib_error_t *
553  unformat_input_t * input,
554  vlib_cli_command_t * cmd)
555 {
556  vxlan_main_t * vxm = &vxlan_main;
557  vxlan_tunnel_t * t;
558 
559  if (pool_elts (vxm->tunnels) == 0)
560  vlib_cli_output (vm, "No vxlan tunnels configured...");
561 
562  pool_foreach (t, vxm->tunnels,
563  ({
564  vlib_cli_output (vm, "%U", format_vxlan_tunnel, t);
565  }));
566 
567  return 0;
568 }
569 
570 VLIB_CLI_COMMAND (show_vxlan_tunnel_command, static) = {
571  .path = "show vxlan tunnel",
572  .function = show_vxlan_tunnel_command_fn,
573 };
574 
575 
577 {
578  vxlan_main_t * vxm = &vxlan_main;
579  ip4_vxlan_header_t * hdr4;
580  ip4_header_t * ip4;
581  ip6_vxlan_header_t * hdr6;
582  ip6_header_t * ip6;
583 
584  vxm->vnet_main = vnet_get_main();
585  vxm->vlib_main = vm;
586 
587  /* initialize the ip6 hash */
589  sizeof(vxlan6_tunnel_key_t),
590  sizeof(uword));
591 
592  /* init dummy rewrite string for deleted vxlan tunnels */
593  _vec_len(vxlan4_dummy_rewrite) = sizeof(ip4_vxlan_header_t);
594  hdr4 = (ip4_vxlan_header_t *) vxlan4_dummy_rewrite;
595  ip4 = &hdr4->ip4;
596  /* minimal rewrite setup, see vxlan_rewite() above as reference */
597  ip4->ip_version_and_header_length = 0x45;
598  ip4->checksum = ip4_header_checksum (ip4);
599 
600  /* Same again for IPv6 */
601  _vec_len(vxlan6_dummy_rewrite) = sizeof(ip6_vxlan_header_t);
602  hdr6 = (ip6_vxlan_header_t *) vxlan6_dummy_rewrite;
603  ip6 = &hdr6->ip6;
604  /* minimal rewrite setup, see vxlan_rewite() above as reference */
605  ip6->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28);
606 
607  udp_register_dst_port (vm, UDP_DST_PORT_vxlan,
608  vxlan4_input_node.index, /* is_ip4 */ 1);
609  udp_register_dst_port (vm, UDP_DST_PORT_vxlan6,
610  vxlan6_input_node.index, /* is_ip4 */ 0);
611  return 0;
612 }
613 
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:394
vmrglw vmrglh hi
#define hash_set(h, key, value)
Definition: hash.h:237
l2_input_config_t * configs
Definition: l2_input.h:63
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:454
#define hash_unset(h, key)
Definition: hash.h:243
ip4_address_t src_address
Definition: ip4_packet.h:138
vnet_interface_main_t interface_main
Definition: vnet.h:62
clib_error_t * vxlan_init(vlib_main_t *vm)
Definition: vxlan.c:576
vlib_node_registration_t vxlan4_input_node
(constructor) VLIB_REGISTER_NODE (vxlan4_input_node)
Definition: decap.c:532
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:89
u64 as_u64[2]
Definition: ip6_packet.h:50
always_inline void clib_mem_free(void *p)
Definition: mem.h:149
always_inline void unformat_free(unformat_input_t *i)
Definition: format.h:160
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
ip46_address_t dst
Definition: vxlan.h:71
static u32 fib4_index_from_fib_id(u32 fib_id)
Definition: vxlan.c:373
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:480
vxlan6_tunnel_key_t * key6
Definition: vxlan.h:88
#define hash_set_mem(h, key, value)
Definition: hash.h:257
u32 * fib_index_by_sw_if_index
Definition: ip4.h:137
static u32 fib6_index_from_fib_id(u32 fib_id)
Definition: vxlan.c:385
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:241
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:405
ip6_address_t src_address
Definition: ip6_packet.h:293
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:552
#define foreach_copy_ipv6
Definition: vxlan.c:122
#define vxlan4_dummy_rewrite
Definition: vxlan.h:131
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
vnet_main_t * vnet_main
Definition: vxlan.h:141
VNET_DEVICE_CLASS(vxlan_device_class, static)
#define pool_foreach(VAR, POOL, BODY)
Definition: pool.h:328
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
ip4_address_t dst_address
Definition: ip4_packet.h:138
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:458
vlib_main_t * vlib_main
Definition: vxlan.h:140
always_inline uword pool_elts(void *v)
Definition: pool.h:97
#define clib_warning(format, args...)
Definition: error.h:59
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:953
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:418
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:583
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)
Definition: l2_input.c:509
unformat_function_t unformat_ip4_address
Definition: format.h:68
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:594
#define hash_get(h, key)
Definition: hash.h:231
u8 * rewrite
Definition: vxlan.h:67
#define pool_elt_at_index(p, i)
Definition: pool.h:346
#define hash_unset_mem(h, key)
Definition: hash.h:263
uword * fib_index_by_table_id
Definition: ip4.h:141
static clib_error_t * vxlan_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: vxlan.c:71
uword * vxlan4_tunnel_by_key
Definition: vxlan.h:123
#define foreach_copy_ipv4
Definition: vxlan.c:117
#define pool_put(P, E)
Definition: pool.h:200
vxlan_main_t vxlan_main
Definition: vxlan.c:18
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:457
vlib_node_registration_t vxlan6_input_node
(constructor) VLIB_REGISTER_NODE (vxlan6_input_node)
Definition: decap.c:553
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:538
u8 * format_vxlan_encap_trace(u8 *s, va_list *args)
Definition: encap.c:52
always_inline u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:194
unformat_function_t unformat_ip6_address
Definition: format.h:86
uword * fib_index_by_table_id
Definition: ip6.h:152
#define pool_get_aligned(P, E, A)
Definition: pool.h:155
int vnet_vxlan_add_del_tunnel(vnet_vxlan_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: vxlan.c:196
#define vxlan6_dummy_rewrite
Definition: vxlan.h:134
u16 encap_fib_index
Definition: vxlan.h:80
always_inline void * clib_mem_alloc(uword size)
Definition: mem.h:109
u16 n_vectors
Definition: node.h:307
static uword dummy_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: vxlan.c:62
static int vxlan4_rewrite(vxlan_tunnel_t *t)
Definition: vxlan.c:129
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:298
#define clib_memcpy(a, b, c)
Definition: string.h:63
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:478
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:397
u32 decap_next_index
Definition: vxlan.h:77
always_inline vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
static u8 * format_vxlan_header_with_length(u8 *s, va_list *args)
Definition: vxlan.c:99
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:472
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:373
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:87
ip6_main_t ip6_main
Definition: ip6_forward.c:2490
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:405
uword * vxlan6_tunnel_by_key
Definition: vxlan.h:124
u32 sw_if_index
Definition: vxlan.h:84
vlib_node_registration_t vxlan_encap_node
(constructor) VLIB_REGISTER_NODE (vxlan_encap_node)
Definition: encap.c:571
always_inline void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Definition: counter.h:277
u64 uword
Definition: types.h:112
#define foreach_copy_field
Definition: vxlan.c:112
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:280
static int vxlan6_rewrite(vxlan_tunnel_t *t)
Definition: vxlan.c:162
l2input_main_t l2input_main
Definition: l2_input.c:72
#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:83
u32 flags
Definition: vxlan.h:92
#define VXLAN_TUNNEL_IS_IPV4
Definition: vxlan.h:96
u32 * tunnel_index_by_sw_if_index
Definition: vxlan.h:137
#define hash_get_mem(h, key)
Definition: hash.h:251
static u8 * format_decap_next(u8 *s, va_list *args)
Definition: vxlan.c:20
always_inline void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Definition: counter.h:122
ip4_main_t ip4_main
Definition: ip4_forward.c:1394
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:462
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:374
vxlan4_tunnel_key_t * key4
Definition: vxlan.h:87
#define clib_error_return(e, args...)
Definition: error.h:112
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:73
#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:443
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
unformat_function_t unformat_line_input
Definition: format.h:279
u32 * fib_index_by_sw_if_index
Definition: ip6.h:148
vxlan_tunnel_t * tunnels
Definition: vxlan.h:120
u32 * free_vxlan_tunnel_hw_if_indices
Definition: vxlan.h:127
ip46_address_t src
Definition: vxlan.h:70
u8 * format_vxlan_tunnel(u8 *s, va_list *args)
Definition: vxlan.c:40
static u8 * format_vxlan_name(u8 *s, va_list *args)
Definition: vxlan.c:56
ip6_address_t dst_address
Definition: ip6_packet.h:293
#define MODE_L3
Definition: l2_input.h:208